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