step9_controller.js 26 KB

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