step9_controller.js 26 KB

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