step9_controller.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.WizardStep9Controller = Em.Controller.extend({
  20. name: 'wizardStep9Controller',
  21. hosts: [],
  22. progress: '0',
  23. isStepCompleted: false,
  24. isSubmitDisabled: function () {
  25. // return !this.get('isStepCompleted');
  26. return !['STARTED','START FAILED'].contains(this.get('content.cluster.status'));
  27. }.property('content.cluster.status'),
  28. mockHostData: require('data/mock/step9_hosts'),
  29. mockDataPrefix: '/data/wizard/deploy/5_hosts',
  30. pollDataCounter: 0,
  31. polledData: [],
  32. status: function () {
  33. if(this.get('progress') != '100') {
  34. return 'info';
  35. }
  36. if (this.hosts.someProperty('status', 'failed')) {
  37. return 'failed';
  38. } else if (this.hosts.someProperty('status', 'warning')) {
  39. return 'warning';
  40. }
  41. return 'success';
  42. }.property('hosts.@each.status', 'progress'),
  43. showRetry: function () {
  44. return this.get('content.cluster.status') == 'INSTALL FAILED';
  45. }.property('content.cluster.status'),
  46. // content.cluster.status can be:
  47. // PENDING: set upon successful transition from step 1 to step 2
  48. // INSTALLED: set upon successful completion of install phase as well as successful invocation of start services API
  49. // STARTED: set up on successful completion of start phase
  50. // INSTALL FAILED: set up upon encountering a failure in install phase
  51. // START FAILED: set upon unsuccessful invocation of start services API and also upon encountering a failure
  52. // during start phase
  53. // content.cluster.isCompleted
  54. // set to false upon successful transition from step 1 to step 2
  55. // set to true upon successful start of services in this step
  56. // note: looks like this is the same thing as checking content.cluster.status == 'STARTED'
  57. // navigateStep is called by App.WizardStep9View's didInsertElement and "retry" from router.
  58. navigateStep: function () {
  59. if (App.testMode) {
  60. // this is for repeatedly testing out installs in test mode
  61. this.set('content.cluster.status', 'PENDING');
  62. this.set('content.cluster.isCompleted', false);
  63. }
  64. var clusterStatus = this.get('content.cluster.status');
  65. console.log('navigateStep: clusterStatus = ' + clusterStatus);
  66. if (this.get('content.cluster.isCompleted') === false) {
  67. // the cluster has not yet successfully installed and started
  68. if (clusterStatus === 'INSTALL FAILED') {
  69. this.loadStep();
  70. this.loadLogData(this.get('content.cluster.requestId'));
  71. this.set('content.cluster.isStepCompleted', true);
  72. } else if (clusterStatus === 'START FAILED') {
  73. this.loadStep();
  74. this.loadLogData(this.get('content.cluster.requestId'));
  75. // this.hosts.setEach('status', 'info');
  76. this.set('isStepCompleted', true);
  77. } else {
  78. // handle PENDING, INSTALLED
  79. this.loadStep();
  80. this.loadLogData(this.get('content.cluster.requestId'));
  81. this.startPolling();
  82. }
  83. } else {
  84. // handle STARTED
  85. // the cluster has successfully installed and started
  86. this.loadStep();
  87. this.loadLogData(this.get('content.cluster.requestId'));
  88. this.set('isStepCompleted', true);
  89. this.set('progress', '100');
  90. }
  91. },
  92. clearStep: function () {
  93. this.hosts.clear();
  94. this.set('status', 'info');
  95. this.set('progress', '0');
  96. this.set('isStepCompleted', false);
  97. this.numPolls = 0;
  98. },
  99. loadStep: function () {
  100. console.log("TRACE: Loading step9: Install, Start and Test");
  101. this.clearStep();
  102. this.renderHosts(this.loadHosts());
  103. },
  104. loadHosts: function () {
  105. var hostInfo = this.get('content.hosts');
  106. var hosts = new Ember.Set();
  107. for (var index in hostInfo) {
  108. var obj = Em.Object.create(hostInfo[index]);
  109. obj.message = '';
  110. obj.progress = 0;
  111. obj.status = 'info';
  112. obj.tasks = [];
  113. obj.logTasks = [];
  114. hosts.add(obj);
  115. console.log("TRACE: host name is: " + hostInfo[index].name);
  116. }
  117. return hosts.filterProperty('bootStatus', 'REGISTERED');
  118. },
  119. // sets this.hosts, where each element corresponds to a status and progress info on a host
  120. renderHosts: function (hostsInfo) {
  121. hostsInfo.forEach(function (_hostInfo) {
  122. var hostInfo = App.HostInfo.create({
  123. name: _hostInfo.name,
  124. status: _hostInfo.status,
  125. tasks: _hostInfo.tasks,
  126. logTasks: _hostInfo.logTasks,
  127. message: _hostInfo.message,
  128. progress: _hostInfo.progress
  129. });
  130. console.log('pushing ' + hostInfo.name);
  131. this.hosts.pushObject(hostInfo);
  132. }, this);
  133. },
  134. replacePolledData: function (polledData) {
  135. this.polledData.clear();
  136. this.set('polledData', polledData);
  137. },
  138. displayMessage: function (task) {
  139. var role = App.format.role(task.role);
  140. console.log("In display message with task command value: " + task.command);
  141. switch (task.command) {
  142. case 'INSTALL':
  143. switch (task.status) {
  144. case 'PENDING':
  145. return 'Preparing to install ' + role;
  146. case 'QUEUED' :
  147. return 'Waiting to install ' + role;
  148. case 'IN_PROGRESS':
  149. return 'Installing ' + role;
  150. case 'COMPLETED' :
  151. return 'Successfully installed ' + role;
  152. case 'FAILED':
  153. return 'Failed to install ' + role;
  154. }
  155. case 'UNINSTALL':
  156. switch (task.status) {
  157. case 'PENDING':
  158. return 'Preparing to uninstall ' + role;
  159. case 'QUEUED' :
  160. return 'Waiting to uninstall ' + role;
  161. case 'IN_PROGRESS':
  162. return 'Uninstalling ' + role;
  163. case 'COMPLETED' :
  164. return 'Successfully uninstalled ' + role;
  165. case 'FAILED':
  166. return 'Failed to uninstall ' + role;
  167. }
  168. case 'START' :
  169. switch (task.status) {
  170. case 'PENDING':
  171. return 'Preparing to start ' + role;
  172. case 'QUEUED' :
  173. return 'Waiting to start ' + role;
  174. case 'IN_PROGRESS':
  175. return 'Starting ' + role;
  176. case 'COMPLETED' :
  177. return role + ' started successfully';
  178. case 'FAILED':
  179. return role + ' failed to start';
  180. }
  181. case 'STOP' :
  182. switch (task.status) {
  183. case 'PENDING':
  184. return 'Preparing to stop ' + role;
  185. case 'QUEUED' :
  186. return 'Waiting to stop ' + role;
  187. case 'IN_PROGRESS':
  188. return 'Stopping ' + role;
  189. case 'COMPLETED' :
  190. return role + ' stopped successfully';
  191. case 'FAILED':
  192. return role + ' failed to stop';
  193. }
  194. case 'EXECUTE' :
  195. switch (task.status) {
  196. case 'PENDING':
  197. return 'Preparing to execute ' + role;
  198. case 'QUEUED' :
  199. return 'Waiting to execute ' + role;
  200. case 'IN_PROGRESS':
  201. return 'Executing ' + role;
  202. case 'COMPLETED' :
  203. return role + ' executed successfully';
  204. case 'FAILED':
  205. return role + ' failed to execute';
  206. }
  207. case 'ABORT' :
  208. switch (task.status) {
  209. case 'PENDING':
  210. return 'Preparing to abort ' + role;
  211. case 'QUEUED' :
  212. return 'Waiting to abort ' + role;
  213. case 'IN_PROGRESS':
  214. return 'Aborting ' + role;
  215. case 'COMPLETED' :
  216. return role + ' aborted successfully';
  217. case 'FAILED':
  218. return role + ' failed to abort';
  219. }
  220. }
  221. },
  222. launchStartServices: function () {
  223. var self = this;
  224. var clusterName = this.get('content.cluster.name');
  225. var url = App.apiPrefix + '/clusters/' + clusterName + '/services?ServiceInfo/state=INSTALLED';
  226. var data = '{"ServiceInfo": {"state": "STARTED"}}';
  227. var method = 'PUT';
  228. if (this.get('content.controllerName') === 'addHostController') {
  229. url = App.apiPrefix + '/clusters/' + clusterName + '/host_components?HostRoles/component_name=GANGLIA_MONITOR|HostRoles/component_name=HBASE_REGIONSERVER|HostRoles/component_name=DATANODE|HostRoles/component_name=TASKTRACKER&HostRoles/state=INSTALLED';
  230. data = '{"HostRoles": {"state": "STARTED"}}';
  231. }
  232. if (App.testMode) {
  233. url = this.get('mockDataPrefix') + '/poll_6.json';
  234. method = 'GET';
  235. this.numPolls = 6;
  236. }
  237. $.ajax({
  238. type: method,
  239. url: url,
  240. async: false,
  241. data: data,
  242. dataType: 'text',
  243. timeout: App.timeout,
  244. success: function (data) {
  245. var jsonData = jQuery.parseJSON(data);
  246. console.log("TRACE: Step9 -> In success function for the startService call");
  247. console.log("TRACE: Step9 -> value of the url is: " + url);
  248. console.log("TRACE: Step9 -> value of the received data is: " + jsonData);
  249. var requestId = jsonData.Requests.id;
  250. console.log('requestId is: ' + requestId);
  251. var clusterStatus = {
  252. status: 'INSTALLED',
  253. requestId: requestId,
  254. isStartError: false,
  255. isCompleted: false
  256. };
  257. App.router.get(self.get('content.controllerName')).saveClusterStatus(clusterStatus);
  258. self.startPolling();
  259. },
  260. error: function () {
  261. console.log("ERROR");
  262. var clusterStatus = {
  263. status: 'START FAILED',
  264. isStartError: true,
  265. isCompleted: false
  266. };
  267. App.router.get(self.get('content.controllerName')).saveClusterStatus(clusterStatus);
  268. },
  269. statusCode: require('data/statusCodes')
  270. });
  271. },
  272. // marks a host's status as "success" if all tasks are in COMPLETED state
  273. onSuccessPerHost: function (actions, contentHost) {
  274. if (actions.everyProperty('Tasks.status', 'COMPLETED') && this.get('content.cluster.status') === 'INSTALLED') {
  275. contentHost.set('status', 'success');
  276. }
  277. },
  278. // marks a host's status as "warning" if at least one of the tasks is FAILED, ABORTED, or TIMEDOUT.
  279. onWarningPerHost: function (actions, contentHost) {
  280. if (actions.someProperty('Tasks.status', 'FAILED') || actions.someProperty('Tasks.status', 'ABORTED') || actions.someProperty('Tasks.status', 'TIMEDOUT')) {
  281. console.log('step9: In warning');
  282. contentHost.set('status', 'warning');
  283. this.set('status', 'warning');
  284. }
  285. },
  286. onInProgressPerHost: function (tasks, contentHost) {
  287. var runningAction = tasks.findProperty('Tasks.status', 'IN_PROGRESS');
  288. if (runningAction === undefined || runningAction === null) {
  289. runningAction = tasks.findProperty('Tasks.status', 'QUEUED');
  290. }
  291. if (runningAction === undefined || runningAction === null) {
  292. runningAction = tasks.findProperty('Tasks.status', 'PENDING');
  293. }
  294. if (runningAction !== null && runningAction !== undefined) {
  295. contentHost.set('message', this.displayMessage(runningAction.Tasks));
  296. }
  297. },
  298. progressPerHost: function (actions, contentHost) {
  299. var progress = 0;
  300. var actionsPerHost = actions.length;
  301. // TODO: consolidate to a single filter function for better performance
  302. var completedActions = actions.filterProperty('Tasks.status', 'COMPLETED').length
  303. + actions.filterProperty('Tasks.status', 'FAILED').length
  304. + actions.filterProperty('Tasks.status', 'ABORTED').length
  305. + actions.filterProperty('Tasks.status', 'TIMEDOUT').length;
  306. // for the install phase (PENDING), % completed per host goes up to 33%; floor(100 / 3)
  307. // for the start phase (INSTALLED), % completed starts from 34%
  308. switch (this.get('content.cluster.status')) {
  309. case 'PENDING':
  310. progress = Math.floor(((completedActions / actionsPerHost) * 100) / 3);
  311. break;
  312. case 'INSTALLED':
  313. progress = 34 + Math.floor(((completedActions / actionsPerHost) * 100 * 2) / 3);
  314. break;
  315. default:
  316. progress = 100;
  317. break;
  318. }
  319. console.log('INFO: progressPerHost is: ' + progress);
  320. contentHost.set('progress', progress.toString());
  321. return progress;
  322. },
  323. isSuccess: function (polledData) {
  324. return polledData.everyProperty('Tasks.status', 'COMPLETED');
  325. },
  326. // for DATANODE, TASKTRACKER, HBASE_REGIONSERVER, and GANGLIA_MONITOR, if more than 50% fail, then it's a fatal error;
  327. // otherwise, it's only a warning and installation/start can continue
  328. getSuccessFactor: function (role) {
  329. return ['DATANODE', 'TASKTRACKER', 'HBASE_REGIONSERVER', 'GANGLIA_MONITOR'].contains(role) ? 50 : 100;
  330. },
  331. isStepFailed: function (polledData) {
  332. var failed = false;
  333. polledData.forEach(function (_polledData) {
  334. var successFactor = this.getSuccessFactor(_polledData.Tasks.role);
  335. console.log("Step9: isStepFailed sf value: " + successFactor);
  336. var actionsPerRole = polledData.filterProperty('Tasks.role', _polledData.Tasks.role);
  337. var actionsFailed = actionsPerRole.filterProperty('Tasks.status', 'FAILED');
  338. var actionsAborted = actionsPerRole.filterProperty('Tasks.status', 'ABORTED');
  339. var actionsTimedOut = actionsPerRole.filterProperty('Tasks.status', 'TIMEDOUT');
  340. if ((((actionsFailed.length + actionsAborted.length + actionsTimedOut.length) / actionsPerRole.length) * 100) > (100 - successFactor)) {
  341. console.log('TRACE: Entering success factor and result is failed');
  342. failed = true;
  343. }
  344. }, this);
  345. return failed;
  346. },
  347. getFailedHostsForFailedRoles: function (polledData) {
  348. var hostArr = new Ember.Set();
  349. polledData.forEach(function (_polledData) {
  350. var successFactor = this.getSuccessFactor(_polledData.Tasks.role);
  351. var actionsPerRole = polledData.filterProperty('Tasks.role', _polledData.Tasks.role);
  352. var actionsFailed = actionsPerRole.filterProperty('Tasks.status', 'FAILED');
  353. var actionsAborted = actionsPerRole.filterProperty('Tasks.status', 'ABORTED');
  354. var actionsTimedOut = actionsPerRole.filterProperty('Tasks.status', 'TIMEDOUT');
  355. if ((((actionsFailed.length + actionsAborted.length + actionsTimedOut.length) / actionsPerRole.length) * 100) > (100 - successFactor)) {
  356. actionsFailed.forEach(function (_actionFailed) {
  357. hostArr.add(_actionFailed.Tasks.host_name);
  358. });
  359. actionsAborted.forEach(function (_actionFailed) {
  360. hostArr.add(_actionFailed.Tasks.host_name);
  361. });
  362. actionsTimedOut.forEach(function (_actionFailed) {
  363. hostArr.add(_actionFailed.Tasks.host_name);
  364. });
  365. }
  366. }, this);
  367. return hostArr;
  368. },
  369. setHostsStatus: function (hostNames, status) {
  370. hostNames.forEach(function (_hostName) {
  371. var host = this.hosts.findProperty('name', _hostName);
  372. if (host) {
  373. host.set('status', status).set('progress', '100');
  374. }
  375. }, this);
  376. },
  377. // makes a state transition
  378. // PENDING -> INSTALLED
  379. // PENDING -> INSTALL FAILED
  380. // INSTALLED -> STARTED
  381. // INSTALLED -> START_FAILED
  382. // returns true if polling should stop; false otherwise
  383. // polling from ui stops only when no action has 'PENDING', 'QUEUED' or 'IN_PROGRESS' status
  384. finishState: function (polledData) {
  385. var clusterStatus = {};
  386. var requestId = this.get('content.cluster.requestId');
  387. if (this.get('content.cluster.status') === 'INSTALLED') {
  388. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  389. this.set('progress', '100');
  390. clusterStatus = {
  391. status: 'INSTALLED',
  392. requestId: requestId,
  393. isCompleted: true
  394. };
  395. if (this.isSuccess(polledData)) {
  396. clusterStatus.status = 'STARTED';
  397. var serviceStartTime = new Date().getTime();
  398. var timeToStart = ((parseInt(serviceStartTime) - parseInt(this.get('content.cluster.installStartTime'))) / 60000).toFixed(2);
  399. clusterStatus.installTime = timeToStart;
  400. this.set('status', 'success');
  401. } else {
  402. if (this.isStepFailed(polledData)) {
  403. clusterStatus.status = 'START FAILED'; // 'START FAILED' implies to step10 that installation was successful but start failed
  404. this.set('status', 'failed');
  405. this.setHostsStatus(this.getFailedHostsForFailedRoles(polledData), 'failed');
  406. } else {
  407. clusterStatus.status = 'START FAILED';
  408. this.set('status', 'warning');
  409. }
  410. }
  411. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  412. this.set('isStepCompleted', true);
  413. this.setTasksPerHost();
  414. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  415. return true;
  416. }
  417. } else if (this.get('content.cluster.status') === 'PENDING') {
  418. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  419. clusterStatus = {
  420. status: 'PENDING',
  421. requestId: requestId,
  422. isCompleted: false
  423. }
  424. if (this.isStepFailed(polledData)) {
  425. console.log("In installation failure");
  426. clusterStatus.status = 'INSTALL FAILED';
  427. this.set('progress', '100');
  428. this.set('status', 'failed');
  429. this.setHostsStatus(this.getFailedHostsForFailedRoles(polledData), 'failed');
  430. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  431. this.set('isStepCompleted', true);
  432. } else {
  433. clusterStatus.status = 'INSTALLED';
  434. this.set('progress', '34');
  435. this.launchStartServices();
  436. }
  437. this.setTasksPerHost();
  438. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  439. return true;
  440. }
  441. } else if (this.get('content.cluster.status') === 'INSTALL FAILED') {
  442. this.set('progress', '100');
  443. this.set('status', 'failed');
  444. return true;
  445. } else if (this.get('content.cluster.status') === 'START FAILED') {
  446. this.set('progress', '100');
  447. this.set('status', 'failed');
  448. return true;
  449. } else if (this.get('content.cluster.status') === 'STARTED') {
  450. this.set('progress', '100');
  451. this.set('status', 'success');
  452. return true;
  453. }
  454. return false;
  455. },
  456. setTasksPerHost: function () {
  457. var tasksData = this.get('polledData');
  458. this.get('hosts').forEach(function (_host) {
  459. var tasksPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
  460. if (tasksPerHost.length === 0) {
  461. //alert('For testing with mockData follow the sequence: hit referesh,"mockData btn", "pollData btn", again "pollData btn"');
  462. //exit();
  463. }
  464. if (tasksPerHost !== null && tasksPerHost !== undefined && tasksPerHost.length !== 0) {
  465. tasksPerHost.forEach(function (_taskPerHost) {
  466. console.log('In step9 _taskPerHost function.');
  467. //if (_taskPerHost.Tasks.status !== 'PENDING' && _taskPerHost.Tasks.status !== 'QUEUED' && _taskPerHost.Tasks.status !== 'IN_PROGRESS') {
  468. _host.tasks.pushObject(_taskPerHost);
  469. //}
  470. }, this);
  471. }
  472. }, this);
  473. },
  474. // This is done at HostRole level.
  475. setLogTasksStatePerHost: function (tasksPerHost, host) {
  476. console.log('In step9 setTasksStatePerHost function.');
  477. tasksPerHost.forEach(function (_task) {
  478. console.log('In step9 _taskPerHost function.');
  479. //if (_task.Tasks.status !== 'PENDING' && _task.Tasks.status !== 'QUEUED') {
  480. var task = host.logTasks.findProperty('Tasks.id', _task.Tasks.id);
  481. if (task) {
  482. host.logTasks.removeObject(task);
  483. }
  484. host.logTasks.pushObject(_task);
  485. //}
  486. }, this);
  487. },
  488. parseHostInfo: function (polledData) {
  489. console.log('TRACE: Entering host info function');
  490. var self = this;
  491. var totalProgress = 0;
  492. /* if (this.get('content.cluster.status') === 'INSTALLED') {
  493. totalProgress = 34;
  494. } else {
  495. totalProgress = 0;
  496. } */
  497. var tasksData = polledData.tasks;
  498. console.log("The value of tasksData is: ", tasksData);
  499. if (!tasksData) {
  500. console.log("Step9: ERROR: NO tasks available to process");
  501. }
  502. var requestId = this.get('content.cluster.requestId');
  503. if(polledData.Requests && polledData.Requests.id && polledData.Requests.id!=requestId){
  504. // We dont want to use non-current requestId's tasks data to
  505. // determine the current install status.
  506. // Also, we dont want to keep polling if it is not the
  507. // current requestId.
  508. return false;
  509. }
  510. this.replacePolledData(tasksData);
  511. this.hosts.forEach(function (_host) {
  512. var actionsPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
  513. if (actionsPerHost.length === 0) {
  514. _host.set('message', this.t('installer.step9.host.status.nothingToInstall'));
  515. console.log("INFO: No task is hosted on the host");
  516. }
  517. if (actionsPerHost !== null && actionsPerHost !== undefined && actionsPerHost.length !== 0) {
  518. this.setLogTasksStatePerHost(actionsPerHost, _host);
  519. this.onSuccessPerHost(actionsPerHost, _host); // every action should be a success
  520. this.onWarningPerHost(actionsPerHost, _host); // any action should be a failure
  521. this.onInProgressPerHost(actionsPerHost, _host); // current running action for a host
  522. totalProgress += self.progressPerHost(actionsPerHost, _host);
  523. }
  524. }, this);
  525. totalProgress = Math.floor(totalProgress / this.hosts.length);
  526. this.set('progress', totalProgress.toString());
  527. console.log("INFO: right now the progress is: " + this.get('progress'));
  528. return this.finishState(tasksData);
  529. },
  530. startPolling: function () {
  531. this.set('isSubmitDisabled', true);
  532. this.doPolling();
  533. },
  534. numPolls: 0,
  535. getUrl: function (requestId) {
  536. var clusterName = this.get('content.cluster.name');
  537. var requestId = requestId || this.get('content.cluster.requestId');
  538. var url = App.apiPrefix + '/clusters/' + clusterName + '/requests/' + requestId + '?fields=tasks/*';
  539. console.log("URL for step9 is: " + url);
  540. return url;
  541. },
  542. POLL_INTERVAL: 4000,
  543. loadLogData: function(requestId) {
  544. var url = this.getUrl(requestId);
  545. var requestsId = App.db.getCluster().oldRequestsId;
  546. if (App.testMode) {
  547. this.POLL_INTERVAL = 1;
  548. this.numPolls++;
  549. }
  550. requestsId.forEach(function(requestId) {
  551. url = this.getUrl(requestId);
  552. if (App.testMode) {
  553. this.POLL_INTERVAL = 1;
  554. url = this.get('mockDataPrefix') + '/poll_' + this.numPolls + '.json';
  555. }
  556. this.getLogsByRequest(url, false);
  557. }, this);
  558. },
  559. // polling: whether to continue polling for status or not
  560. getLogsByRequest: function(url, polling){
  561. var self = this;
  562. $.ajax({
  563. type: 'GET',
  564. url: url,
  565. async: true,
  566. timeout: App.timeout,
  567. dataType: 'text',
  568. success: function (data) {
  569. console.log("TRACE: In success function for the GET logs data");
  570. console.log("TRACE: STep9 -> The value is: ", jQuery.parseJSON(data));
  571. var result = self.parseHostInfo(jQuery.parseJSON(data));
  572. if (!polling) {
  573. return;
  574. }
  575. if (result !== true) {
  576. window.setTimeout(function () {
  577. self.doPolling();
  578. }, self.POLL_INTERVAL);
  579. } else {
  580. self.stopPolling();
  581. }
  582. },
  583. error: function (request, ajaxOptions, error) {
  584. console.log("TRACE: STep9 -> In error function for the GET logs data");
  585. console.log("TRACE: STep9 -> value of the url is: " + url);
  586. console.log("TRACE: STep9 -> error code status is: " + request.status);
  587. self.stopPolling();
  588. },
  589. statusCode: require('data/statusCodes')
  590. }).retry({times: App.maxRetries, timeout: App.timeout}).then(null,
  591. function () {
  592. App.showReloadPopup();
  593. console.log('Install services all retries failed');
  594. }
  595. );
  596. },
  597. doPolling: function () {
  598. var url = this.getUrl();
  599. if (App.testMode) {
  600. this.numPolls++;
  601. url = this.get('mockDataPrefix') + '/poll_' + this.get('numPolls') + '.json';
  602. }
  603. this.getLogsByRequest(url, true);
  604. },
  605. stopPolling: function () {
  606. //TODO: uncomment following line after the hook up with the API call
  607. // this.set('isStepCompleted',true);
  608. },
  609. submit: function () {
  610. if (!this.get('isSubmitDisabled')) {
  611. App.router.send('next');
  612. }
  613. },
  614. back: function () {
  615. if (!this.get('isSubmitDisabled')) {
  616. App.router.send('back');
  617. }
  618. },
  619. mockBtn: function () {
  620. this.set('isSubmitDisabled', false);
  621. this.hosts.clear();
  622. var hostInfo = this.mockHostData;
  623. this.renderHosts(hostInfo);
  624. },
  625. pollBtn: function () {
  626. this.set('isSubmitDisabled', false);
  627. var data1 = require('data/mock/step9PolledData/pollData_1');
  628. var data2 = require('data/mock/step9PolledData/pollData_2');
  629. var data3 = require('data/mock/step9PolledData/pollData_3');
  630. var data4 = require('data/mock/step9PolledData/pollData_4');
  631. var data5 = require('data/mock/step9PolledData/pollData_5');
  632. var data6 = require('data/mock/step9PolledData/pollData_6');
  633. var data7 = require('data/mock/step9PolledData/pollData_7');
  634. var data8 = require('data/mock/step9PolledData/pollData_8');
  635. var data9 = require('data/mock/step9PolledData/pollData_9');
  636. console.log("TRACE: In pollBtn function data1");
  637. var counter = parseInt(this.get('pollDataCounter')) + 1;
  638. this.set('pollDataCounter', counter.toString());
  639. switch (this.get('pollDataCounter')) {
  640. case '1':
  641. this.parseHostInfo(data1);
  642. break;
  643. case '2':
  644. this.parseHostInfo(data2);
  645. break;
  646. case '3':
  647. this.parseHostInfo(data3);
  648. break;
  649. case '4':
  650. this.parseHostInfo(data4);
  651. break;
  652. case '5':
  653. this.parseHostInfo(data5);
  654. break;
  655. case '6':
  656. this.set('content.cluster.status', 'INSTALLED');
  657. this.parseHostInfo(data6);
  658. break;
  659. case '7':
  660. this.parseHostInfo(data7);
  661. break;
  662. case '8':
  663. this.parseHostInfo(data8);
  664. break;
  665. case '9':
  666. this.parseHostInfo(data9);
  667. break;
  668. default:
  669. break;
  670. }
  671. }
  672. });