step9_controller.js 26 KB

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