step9_controller.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. // We need to do recovery if there is a browser crash
  259. App.clusterStatus.set('value', {
  260. clusterState: 'SERVICE_STARTING_3',
  261. localdb: App.db.data
  262. });
  263. self.startPolling();
  264. },
  265. error: function () {
  266. console.log("ERROR");
  267. var clusterStatus = {
  268. status: 'START FAILED',
  269. isStartError: true,
  270. isCompleted: false
  271. };
  272. App.router.get(self.get('content.controllerName')).saveClusterStatus(clusterStatus);
  273. },
  274. statusCode: require('data/statusCodes')
  275. });
  276. },
  277. // marks a host's status as "success" if all tasks are in COMPLETED state
  278. onSuccessPerHost: function (actions, contentHost) {
  279. if (actions.everyProperty('Tasks.status', 'COMPLETED') && this.get('content.cluster.status') === 'INSTALLED') {
  280. contentHost.set('status', 'success');
  281. }
  282. },
  283. // marks a host's status as "warning" if at least one of the tasks is FAILED, ABORTED, or TIMEDOUT.
  284. onWarningPerHost: function (actions, contentHost) {
  285. if (actions.someProperty('Tasks.status', 'FAILED') || actions.someProperty('Tasks.status', 'ABORTED') || actions.someProperty('Tasks.status', 'TIMEDOUT')) {
  286. console.log('step9: In warning');
  287. contentHost.set('status', 'warning');
  288. this.set('status', 'warning');
  289. }
  290. },
  291. onInProgressPerHost: function (tasks, contentHost) {
  292. var runningAction = tasks.findProperty('Tasks.status', 'IN_PROGRESS');
  293. if (runningAction === undefined || runningAction === null) {
  294. runningAction = tasks.findProperty('Tasks.status', 'QUEUED');
  295. }
  296. if (runningAction === undefined || runningAction === null) {
  297. runningAction = tasks.findProperty('Tasks.status', 'PENDING');
  298. }
  299. if (runningAction !== null && runningAction !== undefined) {
  300. contentHost.set('message', this.displayMessage(runningAction.Tasks));
  301. }
  302. },
  303. progressPerHost: function (actions, contentHost) {
  304. var progress = 0;
  305. var actionsPerHost = actions.length;
  306. // TODO: consolidate to a single filter function for better performance
  307. var completedActions = actions.filterProperty('Tasks.status', 'COMPLETED').length
  308. + actions.filterProperty('Tasks.status', 'FAILED').length
  309. + actions.filterProperty('Tasks.status', 'ABORTED').length
  310. + actions.filterProperty('Tasks.status', 'TIMEDOUT').length;
  311. // for the install phase (PENDING), % completed per host goes up to 33%; floor(100 / 3)
  312. // for the start phase (INSTALLED), % completed starts from 34%
  313. switch (this.get('content.cluster.status')) {
  314. case 'PENDING':
  315. progress = Math.floor(((completedActions / actionsPerHost) * 100) / 3);
  316. break;
  317. case 'INSTALLED':
  318. progress = 34 + Math.floor(((completedActions / actionsPerHost) * 100 * 2) / 3);
  319. break;
  320. default:
  321. progress = 100;
  322. break;
  323. }
  324. console.log('INFO: progressPerHost is: ' + progress);
  325. contentHost.set('progress', progress.toString());
  326. return progress;
  327. },
  328. isSuccess: function (polledData) {
  329. return polledData.everyProperty('Tasks.status', 'COMPLETED');
  330. },
  331. // for DATANODE, TASKTRACKER, HBASE_REGIONSERVER, and GANGLIA_MONITOR, if more than 50% fail, then it's a fatal error;
  332. // otherwise, it's only a warning and installation/start can continue
  333. getSuccessFactor: function (role) {
  334. return ['DATANODE', 'TASKTRACKER', 'HBASE_REGIONSERVER', 'GANGLIA_MONITOR'].contains(role) ? 50 : 100;
  335. },
  336. isStepFailed: function (polledData) {
  337. var failed = false;
  338. polledData.forEach(function (_polledData) {
  339. var successFactor = this.getSuccessFactor(_polledData.Tasks.role);
  340. console.log("Step9: isStepFailed sf value: " + successFactor);
  341. var actionsPerRole = polledData.filterProperty('Tasks.role', _polledData.Tasks.role);
  342. var actionsFailed = actionsPerRole.filterProperty('Tasks.status', 'FAILED');
  343. var actionsAborted = actionsPerRole.filterProperty('Tasks.status', 'ABORTED');
  344. var actionsTimedOut = actionsPerRole.filterProperty('Tasks.status', 'TIMEDOUT');
  345. if ((((actionsFailed.length + actionsAborted.length + actionsTimedOut.length) / actionsPerRole.length) * 100) > (100 - successFactor)) {
  346. console.log('TRACE: Entering success factor and result is failed');
  347. failed = true;
  348. }
  349. }, this);
  350. return failed;
  351. },
  352. getFailedHostsForFailedRoles: function (polledData) {
  353. var hostArr = new Ember.Set();
  354. polledData.forEach(function (_polledData) {
  355. var successFactor = this.getSuccessFactor(_polledData.Tasks.role);
  356. var actionsPerRole = polledData.filterProperty('Tasks.role', _polledData.Tasks.role);
  357. var actionsFailed = actionsPerRole.filterProperty('Tasks.status', 'FAILED');
  358. var actionsAborted = actionsPerRole.filterProperty('Tasks.status', 'ABORTED');
  359. var actionsTimedOut = actionsPerRole.filterProperty('Tasks.status', 'TIMEDOUT');
  360. if ((((actionsFailed.length + actionsAborted.length + actionsTimedOut.length) / actionsPerRole.length) * 100) > (100 - successFactor)) {
  361. actionsFailed.forEach(function (_actionFailed) {
  362. hostArr.add(_actionFailed.Tasks.host_name);
  363. });
  364. actionsAborted.forEach(function (_actionFailed) {
  365. hostArr.add(_actionFailed.Tasks.host_name);
  366. });
  367. actionsTimedOut.forEach(function (_actionFailed) {
  368. hostArr.add(_actionFailed.Tasks.host_name);
  369. });
  370. }
  371. }, this);
  372. return hostArr;
  373. },
  374. setHostsStatus: function (hostNames, status) {
  375. hostNames.forEach(function (_hostName) {
  376. var host = this.hosts.findProperty('name', _hostName);
  377. if (host) {
  378. host.set('status', status).set('progress', '100');
  379. }
  380. }, this);
  381. },
  382. // makes a state transition
  383. // PENDING -> INSTALLED
  384. // PENDING -> INSTALL FAILED
  385. // INSTALLED -> STARTED
  386. // INSTALLED -> START_FAILED
  387. // returns true if polling should stop; false otherwise
  388. // polling from ui stops only when no action has 'PENDING', 'QUEUED' or 'IN_PROGRESS' status
  389. finishState: function (polledData) {
  390. var clusterStatus = {};
  391. var requestId = this.get('content.cluster.requestId');
  392. if (this.get('content.cluster.status') === 'INSTALLED') {
  393. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  394. this.set('progress', '100');
  395. clusterStatus = {
  396. status: 'INSTALLED',
  397. requestId: requestId,
  398. isCompleted: true
  399. };
  400. if (this.isSuccess(polledData)) {
  401. clusterStatus.status = 'STARTED';
  402. var serviceStartTime = new Date().getTime();
  403. var timeToStart = ((parseInt(serviceStartTime) - parseInt(this.get('content.cluster.installStartTime'))) / 60000).toFixed(2);
  404. clusterStatus.installTime = timeToStart;
  405. this.set('status', 'success');
  406. } else {
  407. if (this.isStepFailed(polledData)) {
  408. clusterStatus.status = 'START FAILED'; // 'START FAILED' implies to step10 that installation was successful but start failed
  409. this.set('status', 'failed');
  410. this.setHostsStatus(this.getFailedHostsForFailedRoles(polledData), 'failed');
  411. } else {
  412. clusterStatus.status = 'START FAILED';
  413. this.set('status', 'warning');
  414. }
  415. }
  416. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  417. this.set('isStepCompleted', true);
  418. this.setTasksPerHost();
  419. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  420. return true;
  421. }
  422. } else if (this.get('content.cluster.status') === 'PENDING') {
  423. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  424. clusterStatus = {
  425. status: 'PENDING',
  426. requestId: requestId,
  427. isCompleted: false
  428. }
  429. if (this.isStepFailed(polledData)) {
  430. console.log("In installation failure");
  431. clusterStatus.status = 'INSTALL FAILED';
  432. this.set('progress', '100');
  433. this.set('status', 'failed');
  434. this.setHostsStatus(this.getFailedHostsForFailedRoles(polledData), 'failed');
  435. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  436. this.set('isStepCompleted', true);
  437. } else {
  438. clusterStatus.status = 'INSTALLED';
  439. this.set('progress', '34');
  440. this.launchStartServices();
  441. }
  442. this.setTasksPerHost();
  443. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  444. return true;
  445. }
  446. } else if (this.get('content.cluster.status') === 'INSTALL FAILED') {
  447. this.set('progress', '100');
  448. this.set('status', 'failed');
  449. return true;
  450. } else if (this.get('content.cluster.status') === 'START FAILED') {
  451. this.set('progress', '100');
  452. this.set('status', 'failed');
  453. return true;
  454. } else if (this.get('content.cluster.status') === 'STARTED') {
  455. this.set('progress', '100');
  456. this.set('status', 'success');
  457. return true;
  458. }
  459. return false;
  460. },
  461. setTasksPerHost: function () {
  462. var tasksData = this.get('polledData');
  463. this.get('hosts').forEach(function (_host) {
  464. var tasksPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
  465. if (tasksPerHost.length === 0) {
  466. //alert('For testing with mockData follow the sequence: hit referesh,"mockData btn", "pollData btn", again "pollData btn"');
  467. //exit();
  468. }
  469. if (tasksPerHost !== null && tasksPerHost !== undefined && tasksPerHost.length !== 0) {
  470. tasksPerHost.forEach(function (_taskPerHost) {
  471. console.log('In step9 _taskPerHost function.');
  472. //if (_taskPerHost.Tasks.status !== 'PENDING' && _taskPerHost.Tasks.status !== 'QUEUED' && _taskPerHost.Tasks.status !== 'IN_PROGRESS') {
  473. _host.tasks.pushObject(_taskPerHost);
  474. //}
  475. }, this);
  476. }
  477. }, this);
  478. },
  479. // This is done at HostRole level.
  480. setLogTasksStatePerHost: function (tasksPerHost, host) {
  481. console.log('In step9 setTasksStatePerHost function.');
  482. tasksPerHost.forEach(function (_task) {
  483. console.log('In step9 _taskPerHost function.');
  484. //if (_task.Tasks.status !== 'PENDING' && _task.Tasks.status !== 'QUEUED') {
  485. var task = host.logTasks.findProperty('Tasks.id', _task.Tasks.id);
  486. if (task) {
  487. host.logTasks.removeObject(task);
  488. }
  489. host.logTasks.pushObject(_task);
  490. //}
  491. }, this);
  492. },
  493. parseHostInfo: function (polledData) {
  494. console.log('TRACE: Entering host info function');
  495. var self = this;
  496. var totalProgress = 0;
  497. /* if (this.get('content.cluster.status') === 'INSTALLED') {
  498. totalProgress = 34;
  499. } else {
  500. totalProgress = 0;
  501. } */
  502. var tasksData = polledData.tasks;
  503. console.log("The value of tasksData is: ", tasksData);
  504. if (!tasksData) {
  505. console.log("Step9: ERROR: NO tasks available to process");
  506. }
  507. var requestId = this.get('content.cluster.requestId');
  508. if(polledData.Requests && polledData.Requests.id && polledData.Requests.id!=requestId){
  509. // We dont want to use non-current requestId's tasks data to
  510. // determine the current install status.
  511. // Also, we dont want to keep polling if it is not the
  512. // current requestId.
  513. return false;
  514. }
  515. this.replacePolledData(tasksData);
  516. this.hosts.forEach(function (_host) {
  517. var actionsPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
  518. if (actionsPerHost.length === 0) {
  519. _host.set('message', this.t('installer.step9.host.status.nothingToInstall'));
  520. console.log("INFO: No task is hosted on the host");
  521. }
  522. if (actionsPerHost !== null && actionsPerHost !== undefined && actionsPerHost.length !== 0) {
  523. this.setLogTasksStatePerHost(actionsPerHost, _host);
  524. this.onSuccessPerHost(actionsPerHost, _host); // every action should be a success
  525. this.onWarningPerHost(actionsPerHost, _host); // any action should be a failure
  526. this.onInProgressPerHost(actionsPerHost, _host); // current running action for a host
  527. totalProgress += self.progressPerHost(actionsPerHost, _host);
  528. }
  529. }, this);
  530. totalProgress = Math.floor(totalProgress / this.hosts.length);
  531. this.set('progress', totalProgress.toString());
  532. console.log("INFO: right now the progress is: " + this.get('progress'));
  533. return this.finishState(tasksData);
  534. },
  535. startPolling: function () {
  536. this.set('isSubmitDisabled', true);
  537. this.doPolling();
  538. },
  539. numPolls: 0,
  540. getUrl: function (requestId) {
  541. var clusterName = this.get('content.cluster.name');
  542. var requestId = requestId || this.get('content.cluster.requestId');
  543. var url = App.apiPrefix + '/clusters/' + clusterName + '/requests/' + requestId + '?fields=tasks/*';
  544. console.log("URL for step9 is: " + url);
  545. return url;
  546. },
  547. POLL_INTERVAL: 4000,
  548. loadLogData: function(requestId) {
  549. var url = this.getUrl(requestId);
  550. var requestsId = App.db.getCluster().oldRequestsId;
  551. if (App.testMode) {
  552. this.POLL_INTERVAL = 1;
  553. this.numPolls++;
  554. }
  555. requestsId.forEach(function(requestId) {
  556. url = this.getUrl(requestId);
  557. if (App.testMode) {
  558. this.POLL_INTERVAL = 1;
  559. url = this.get('mockDataPrefix') + '/poll_' + this.numPolls + '.json';
  560. }
  561. this.getLogsByRequest(url, false);
  562. }, this);
  563. },
  564. // polling: whether to continue polling for status or not
  565. getLogsByRequest: function(url, polling){
  566. var self = this;
  567. $.ajax({
  568. type: 'GET',
  569. url: url,
  570. async: true,
  571. timeout: App.timeout,
  572. dataType: 'text',
  573. success: function (data) {
  574. console.log("TRACE: In success function for the GET logs data");
  575. console.log("TRACE: STep9 -> The value is: ", jQuery.parseJSON(data));
  576. var result = self.parseHostInfo(jQuery.parseJSON(data));
  577. if (!polling) {
  578. return;
  579. }
  580. if (result !== true) {
  581. window.setTimeout(function () {
  582. self.doPolling();
  583. }, self.POLL_INTERVAL);
  584. } else {
  585. self.stopPolling();
  586. }
  587. },
  588. error: function (request, ajaxOptions, error) {
  589. console.log("TRACE: STep9 -> In error function for the GET logs data");
  590. console.log("TRACE: STep9 -> value of the url is: " + url);
  591. console.log("TRACE: STep9 -> error code status is: " + request.status);
  592. self.stopPolling();
  593. },
  594. statusCode: require('data/statusCodes')
  595. }).retry({times: App.maxRetries, timeout: App.timeout}).then(null,
  596. function () {
  597. App.showReloadPopup();
  598. console.log('Install services all retries failed');
  599. }
  600. );
  601. },
  602. doPolling: function () {
  603. var url = this.getUrl();
  604. if (App.testMode) {
  605. this.numPolls++;
  606. url = this.get('mockDataPrefix') + '/poll_' + this.get('numPolls') + '.json';
  607. }
  608. this.getLogsByRequest(url, true);
  609. },
  610. stopPolling: function () {
  611. //TODO: uncomment following line after the hook up with the API call
  612. // this.set('isStepCompleted',true);
  613. },
  614. submit: function () {
  615. if (!this.get('isSubmitDisabled')) {
  616. App.router.send('next');
  617. }
  618. },
  619. back: function () {
  620. if (!this.get('isSubmitDisabled')) {
  621. App.router.send('back');
  622. }
  623. },
  624. mockBtn: function () {
  625. this.set('isSubmitDisabled', false);
  626. this.hosts.clear();
  627. var hostInfo = this.mockHostData;
  628. this.renderHosts(hostInfo);
  629. },
  630. pollBtn: function () {
  631. this.set('isSubmitDisabled', false);
  632. var data1 = require('data/mock/step9PolledData/pollData_1');
  633. var data2 = require('data/mock/step9PolledData/pollData_2');
  634. var data3 = require('data/mock/step9PolledData/pollData_3');
  635. var data4 = require('data/mock/step9PolledData/pollData_4');
  636. var data5 = require('data/mock/step9PolledData/pollData_5');
  637. var data6 = require('data/mock/step9PolledData/pollData_6');
  638. var data7 = require('data/mock/step9PolledData/pollData_7');
  639. var data8 = require('data/mock/step9PolledData/pollData_8');
  640. var data9 = require('data/mock/step9PolledData/pollData_9');
  641. console.log("TRACE: In pollBtn function data1");
  642. var counter = parseInt(this.get('pollDataCounter')) + 1;
  643. this.set('pollDataCounter', counter.toString());
  644. switch (this.get('pollDataCounter')) {
  645. case '1':
  646. this.parseHostInfo(data1);
  647. break;
  648. case '2':
  649. this.parseHostInfo(data2);
  650. break;
  651. case '3':
  652. this.parseHostInfo(data3);
  653. break;
  654. case '4':
  655. this.parseHostInfo(data4);
  656. break;
  657. case '5':
  658. this.parseHostInfo(data5);
  659. break;
  660. case '6':
  661. this.set('content.cluster.status', 'INSTALLED');
  662. this.parseHostInfo(data6);
  663. break;
  664. case '7':
  665. this.parseHostInfo(data7);
  666. break;
  667. case '8':
  668. this.parseHostInfo(data8);
  669. break;
  670. case '9':
  671. this.parseHostInfo(data9);
  672. break;
  673. default:
  674. break;
  675. }
  676. }
  677. });