step9_controller.js 25 KB

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