step9_controller.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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. var serviceComponents = require('data/service_components');
  20. App.WizardStep9Controller = Em.Controller.extend({
  21. name: 'wizardStep9Controller',
  22. /**
  23. * Array of host Objects that are successfully registered on "Confirm Host Options" page
  24. * <code>
  25. * {
  26. * name: {String} host name.
  27. * status: {String} Current status of the host. This field is used in the step 9 view to set the css class of the
  28. * host progress bar and set the appropriate message. Possible values: info, warning, failed, heartbeat_lost and success
  29. * logTasks: {Array} Tasks that are scheduled on the host for the current request.
  30. * message: {String} Message to be shown in front of the host name.
  31. * progress: {Int} Progress of the tasks on the host. Amount of tasks completed for all the tasks scheduled on the host.
  32. * isNoTasksForInstall: {Boolean} Gets set when no task is scheduled for the host on install phase.
  33. * }
  34. * </code>
  35. */
  36. hosts: [],
  37. /*
  38. * Array of above hosts that should be made visible depending upon "Host State Filter" chosen <Possible filter values:
  39. * All, In Progress, Warning, Success and Fail>
  40. */
  41. visibleHosts: [],
  42. /**
  43. * overall progress of <Install,Start and Test> page shown as progress bar on the top of the page
  44. */
  45. progress: '0',
  46. /*
  47. * json file for the mock data to be used in mock mode
  48. */
  49. mockDataPrefix: '/data/wizard/deploy/5_hosts',
  50. /*
  51. * Current Request data polled from the API: api/v1/clusters/{clusterName}/requests/{RequestId}?fields=tasks/Tasks/command,
  52. * tasks/Tasks/exit_code,tasks/Tasks/start_time,tasks/Tasks/end_time,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,
  53. * tasks/Tasks/status&minimal_response=true
  54. */
  55. polledData: [],
  56. /*
  57. * This flag is only used in UI mock mode as a counter for number of polls.
  58. */
  59. numPolls: 1,
  60. // Interval in milliseconds between API calls While polling the request status for Install and, Start and Test tasks
  61. POLL_INTERVAL: 4000,
  62. /**
  63. * Array of objects
  64. * <code>
  65. * {
  66. * hostName: {String} Name of host that has stopped heartbeating to ambari-server
  67. * componentNames: {Sting} Name of all components that are on the host
  68. * }
  69. * </code>
  70. */
  71. hostsWithHeartbeatLost: [],
  72. // Flag is set in the start all services error callback function
  73. startCallFailed: false,
  74. /*
  75. * Status of the page. Possible values: <info, warning, failed and success>.
  76. * This property is used in the step-9 view for displaying the appropriate color of the overall progress bar and
  77. * the appropriate result message at the bottom of the page
  78. */
  79. status: 'info',
  80. /**
  81. * This computed property is used to determine if the Next button and back button on the page should be disabled. The property is
  82. * used in the template to grey out Next and Back buttons. Although clicking on the greyed out button do trigger the event and
  83. * calls submit and back function of the controller.
  84. */
  85. isSubmitDisabled: function () {
  86. var validStates = ['STARTED', 'START FAILED'];
  87. var controllerName = this.get('content.controllerName');
  88. if (controllerName == 'addHostController' || controllerName == 'addServiceController') {
  89. validStates.push('INSTALL FAILED');
  90. }
  91. return !validStates.contains(this.get('content.cluster.status'));
  92. }.property('content.cluster.status'),
  93. /**
  94. * This function is called when a click event happens on Next button of <Install, Start and Test> page
  95. */
  96. submit: function () {
  97. if (!this.get('isSubmitDisabled')) {
  98. App.router.send('next');
  99. }
  100. },
  101. /**
  102. * This function is called when a click event happens on back button of <Install, Start and Test> page
  103. */
  104. back: function () {
  105. if (!this.get('isSubmitDisabled')) {
  106. App.router.send('back');
  107. }
  108. },
  109. /**
  110. * Observer function: Enables previous steps link if install task failed in installer wizard.
  111. */
  112. togglePreviousSteps: function () {
  113. if ('INSTALL FAILED' === this.get('content.cluster.status') && this.get('content.controllerName') == 'installerController') {
  114. App.router.get('installerController').setStepsEnable();
  115. } else {
  116. App.router.get('installerController').setLowerStepsDisable(9);
  117. }
  118. }.observes('content.cluster.status', 'content.controllerName'),
  119. /*
  120. * Computed property to determine if the Retry button should be made visible on the page.
  121. */
  122. showRetry: function () {
  123. return this.get('content.cluster.status') == 'INSTALL FAILED';
  124. }.property('content.cluster.status'),
  125. /**
  126. * Ember Object with the controllerbinding as this controller. This object also contains
  127. * <code>
  128. * hostStatus: {String} A valid status of a host.
  129. * Used to filter hosts in that status.
  130. * hostsCount: {Int} Dynamic count of hosts displayed in the category label
  131. * label : {String} status and hosts in that status displayed which consists as a category on the page
  132. * isActive: {boolean} Gets set when the category is selected/clicked by the user
  133. * itemClass: {computed property} Binds the category link to active class when user clicks on the link
  134. * </code>
  135. */
  136. categoryObject: Em.Object.extend({
  137. hostsCount: function () {
  138. var category = this;
  139. var hosts = this.get('controller.hosts').filter(function (_host) {
  140. if (category.get('hostStatus') == 'inProgress') {
  141. return (_host.get('status') == 'info' || _host.get('status') == 'pending' || _host.get('status') == 'in_progress');
  142. } else if (category.get('hostStatus') == 'failed') {
  143. return (_host.get('status') == 'failed' || _host.get('status') == 'heartbeat_lost');
  144. } else {
  145. return (_host.get('status') == category.get('hostStatus'));
  146. }
  147. }, this);
  148. return hosts.get('length');
  149. }.property('controller.hosts.@each.status'),
  150. label: function () {
  151. return "%@ (%@)".fmt(this.get('value'), this.get('hostsCount'));
  152. }.property('value', 'hostsCount')
  153. }),
  154. /**
  155. * computed property creates the category objects on the load of the page and sets 'All' as the active category
  156. * @Returns: All created categories which are binded and iterated in the template
  157. */
  158. categories: function () {
  159. var self = this;
  160. self.categoryObject.reopen({
  161. controller: self,
  162. isActive: function () {
  163. return this.get('controller.category') == this;
  164. }.property('controller.category'),
  165. itemClass: function () {
  166. return this.get('isActive') ? 'active' : '';
  167. }.property('isActive')
  168. });
  169. var categories = [
  170. self.categoryObject.create({value: Em.I18n.t('common.all'), hostStatus: 'all', hostsCount: function () {
  171. return this.get('controller.hosts.length');
  172. }.property('controller.hosts.length') }),
  173. self.categoryObject.create({value: Em.I18n.t('installer.step9.hosts.status.label.inProgress'), hostStatus: 'inProgress'}),
  174. self.categoryObject.create({value: Em.I18n.t('installer.step9.hosts.status.label.warning'), hostStatus: 'warning'}),
  175. self.categoryObject.create({value: Em.I18n.t('common.success'), hostStatus: 'success'}),
  176. self.categoryObject.create({value: Em.I18n.t('common.fail'), hostStatus: 'failed', last: true })
  177. ];
  178. this.set('category', categories.get('firstObject'));
  179. return categories;
  180. }.property(),
  181. /**
  182. * Registered as an handlebar action in step-9 template. Invoked whenever click event occurs on a category label
  183. * @param event: {categoryObject}
  184. */
  185. selectCategory: function (event) {
  186. this.set('category', event.context);
  187. },
  188. /**
  189. * Present clicked/selected {categoryObject} on the page
  190. */
  191. category: false,
  192. /**
  193. * Observer function: Calls {hostStatusUpdates} function once with change in a host status from any registered hosts.
  194. */
  195. hostStatusObserver: function () {
  196. Ember.run.once(this, 'hostStatusUpdates');
  197. }.observes('hosts.@each.status'),
  198. /**
  199. * Updates the hosts mapping to the category selected and updates entire page status
  200. */
  201. hostStatusUpdates: function () {
  202. this.updateVisibleHosts();
  203. this.updateStatus();
  204. },
  205. /**
  206. * Observer function: Updates {visibleHosts Array} of this controller whenever category is changed
  207. */
  208. updateVisibleHosts: function () {
  209. var targetStatus = this.get('category.hostStatus');
  210. var visibleHosts = (targetStatus === 'all') ? this.get('hosts') : this.get('hosts').filter(function (_host) {
  211. if (targetStatus == 'inProgress') {
  212. return (_host.get('status') == 'info' || _host.get('status') == 'pending' || _host.get('status') == 'in_progress');
  213. } else if (targetStatus === 'failed') {
  214. return (_host.get('status') === 'failed' || _host.get('status') === 'heartbeat_lost');
  215. } else {
  216. return (_host.get('status') == targetStatus);
  217. }
  218. }, this);
  219. this.set('visibleHosts', visibleHosts);
  220. }.observes('category'),
  221. /**
  222. * A flag that gets set with installation failure.
  223. */
  224. installFailed: false,
  225. /**
  226. * Observer function: Updates {status} field of the controller.
  227. */
  228. updateStatus: function () {
  229. var status = 'info';
  230. if (this.get('hosts').someProperty('status', 'failed')
  231. || this.get('hosts').someProperty('status', 'heartbeat_lost')
  232. || this.get('startCallFailed')) {
  233. status = 'failed';
  234. } else if (this.get('hosts').someProperty('status', 'warning')) {
  235. if (this.isStepFailed()) {
  236. status = 'failed';
  237. } else {
  238. status = 'warning';
  239. }
  240. } else if (this.get('progress') == '100' && this.get('content.cluster.status') !== 'INSTALL FAILED') {
  241. status = 'success';
  242. }
  243. this.set('status', status);
  244. }.observes('progress'),
  245. /**
  246. * Incremental flag that triggers an event in step 9 view to change the tasks related data and icons of hosts.
  247. */
  248. logTasksChangesCounter: 0,
  249. /**
  250. * navigateStep is called by App.WizardStep9View's didInsertElement and "retry" from router.
  251. * content.cluster.status can be:
  252. * PENDING: set upon successful transition from step 1 to step 2
  253. * INSTALLED: set upon successful completion of install phase as well as successful invocation of start services API
  254. * STARTED: set up on successful completion of start phase
  255. * INSTALL FAILED: set up upon encountering a failure in install phase
  256. * START FAILED: set upon unsuccessful invocation of start services API and also upon encountering a failure
  257. * during start phase
  258. * content.cluster.isCompleted
  259. * set to false upon successful transition from step 1 to step 2
  260. * set to true upon successful start of services in this step
  261. * note: looks like this is the same thing as checking content.cluster.status == 'STARTED'
  262. */
  263. navigateStep: function () {
  264. if (App.testMode) {
  265. // this is for repeatedly testing out installs in test mode
  266. this.set('content.cluster.status', 'PENDING');
  267. this.set('content.cluster.isCompleted', false);
  268. this.set('content.cluster.requestId', 1);
  269. }
  270. var clusterStatus = this.get('content.cluster.status');
  271. console.log('navigateStep: clusterStatus = ' + clusterStatus);
  272. if (this.get('content.cluster.isCompleted') === false) {
  273. // the cluster has not yet successfully installed and started
  274. if (clusterStatus === 'INSTALL FAILED') {
  275. this.loadStep();
  276. this.loadLogData(this.get('content.cluster.requestId'));
  277. } else if (clusterStatus === 'START FAILED') {
  278. this.loadStep();
  279. this.loadLogData(this.get('content.cluster.requestId'));
  280. } else {
  281. // handle PENDING, INSTALLED
  282. this.loadStep();
  283. this.loadLogData(this.get('content.cluster.requestId'));
  284. this.startPolling();
  285. }
  286. } else {
  287. // handle STARTED
  288. // the cluster has successfully installed and started
  289. this.loadStep();
  290. this.loadLogData(this.get('content.cluster.requestId'));
  291. this.set('progress', '100');
  292. }
  293. },
  294. /**
  295. * This is called on initial page load, refreshes and retry event.
  296. * clears all in memory stale data for retry event.
  297. */
  298. clearStep: function () {
  299. this.get('hosts').clear();
  300. this.set('hostsWithHeartbeatLost', []);
  301. this.set('startCallFailed',false);
  302. this.set('status', 'info');
  303. this.set('progress', '0');
  304. this.set('numPolls', 1);
  305. },
  306. /**
  307. * This is called on initial page load, refreshes and retry event.
  308. */
  309. loadStep: function () {
  310. console.log("TRACE: Loading step9: Install, Start and Test");
  311. this.clearStep();
  312. this.loadHosts();
  313. },
  314. /**
  315. * Reset status and message of all hosts when retry install
  316. */
  317. resetHostsForRetry: function () {
  318. var hosts = this.get('content.hosts');
  319. for (var name in hosts) {
  320. hosts[name].status = "pending";
  321. hosts[name].message = 'Waiting';
  322. hosts[name].isNoTasksForInstall = false;
  323. }
  324. this.set('content.hosts', hosts);
  325. },
  326. /**
  327. * Sets the {hosts} array for the controller
  328. */
  329. loadHosts: function () {
  330. var hosts = this.get('content.hosts');
  331. for (var index in hosts) {
  332. if (hosts[index].bootStatus === 'REGISTERED') {
  333. var hostInfo = App.HostInfo.create({
  334. name: hosts[index].name,
  335. status: (hosts[index].status) ? hosts[index].status : 'info',
  336. logTasks: [],
  337. message: (hosts[index].message) ? hosts[index].message : 'Waiting',
  338. progress: 0,
  339. isNoTasksForInstall: false
  340. });
  341. this.get('hosts').pushObject(hostInfo);
  342. }
  343. }
  344. },
  345. /**
  346. *
  347. * @param polledData: sets the {polledData} object of the controller
  348. */
  349. replacePolledData: function (polledData) {
  350. this.polledData.clear();
  351. this.set('polledData', polledData);
  352. },
  353. /**
  354. *
  355. * @param task
  356. * @returns {String} The appropriate message for the host as per the running task.
  357. */
  358. displayMessage: function (task) {
  359. var role = App.format.role(task.role);
  360. switch (task.command) {
  361. case 'INSTALL':
  362. switch (task.status) {
  363. case 'PENDING':
  364. return Em.I18n.t('installer.step9.serviceStatus.install.pending') + role;
  365. case 'QUEUED' :
  366. return Em.I18n.t('installer.step9.serviceStatus.install.queued') + role;
  367. case 'IN_PROGRESS':
  368. return Em.I18n.t('installer.step9.serviceStatus.install.inProgress') + role;
  369. case 'COMPLETED' :
  370. return Em.I18n.t('installer.step9.serviceStatus.install.completed') + role;
  371. case 'FAILED':
  372. return Em.I18n.t('installer.step9.serviceStatus.install.failed') + role;
  373. }
  374. case 'UNINSTALL':
  375. switch (task.status) {
  376. case 'PENDING':
  377. return Em.I18n.t('installer.step9.serviceStatus.uninstall.pending') + role;
  378. case 'QUEUED' :
  379. return Em.I18n.t('installer.step9.serviceStatus.uninstall.queued') + role;
  380. case 'IN_PROGRESS':
  381. return Em.I18n.t('installer.step9.serviceStatus.uninstall.inProgress') + role;
  382. case 'COMPLETED' :
  383. return Em.I18n.t('installer.step9.serviceStatus.uninstall.completed') + role;
  384. case 'FAILED':
  385. return Em.I18n.t('installer.step9.serviceStatus.uninstall.failed') + role;
  386. }
  387. case 'START' :
  388. switch (task.status) {
  389. case 'PENDING':
  390. return Em.I18n.t('installer.step9.serviceStatus.start.pending') + role;
  391. case 'QUEUED' :
  392. return Em.I18n.t('installer.step9.serviceStatus.start.queued') + role;
  393. case 'IN_PROGRESS':
  394. return Em.I18n.t('installer.step9.serviceStatus.start.inProgress') + role;
  395. case 'COMPLETED' :
  396. return role + Em.I18n.t('installer.step9.serviceStatus.start.completed');
  397. case 'FAILED':
  398. return role + Em.I18n.t('installer.step9.serviceStatus.start.failed');
  399. }
  400. case 'STOP' :
  401. switch (task.status) {
  402. case 'PENDING':
  403. return Em.I18n.t('installer.step9.serviceStatus.stop.pending') + role;
  404. case 'QUEUED' :
  405. return Em.I18n.t('installer.step9.serviceStatus.stop.queued') + role;
  406. case 'IN_PROGRESS':
  407. return Em.I18n.t('installer.step9.serviceStatus.stop.inProgress') + role;
  408. case 'COMPLETED' :
  409. return role + Em.I18n.t('installer.step9.serviceStatus.stop.completed');
  410. case 'FAILED':
  411. return role + Em.I18n.t('installer.step9.serviceStatus.stop.failed');
  412. }
  413. case 'EXECUTE' :
  414. case 'SERVICE_CHECK' :
  415. switch (task.status) {
  416. case 'PENDING':
  417. return Em.I18n.t('installer.step9.serviceStatus.execute.pending') + role;
  418. case 'QUEUED' :
  419. return Em.I18n.t('installer.step9.serviceStatus.execute.queued') + role;
  420. case 'IN_PROGRESS':
  421. return Em.I18n.t('installer.step9.serviceStatus.execute.inProgress') + role;
  422. case 'COMPLETED' :
  423. return role + Em.I18n.t('installer.step9.serviceStatus.execute.completed');
  424. case 'FAILED':
  425. return role + Em.I18n.t('installer.step9.serviceStatus.execute.failed');
  426. }
  427. case 'ABORT' :
  428. switch (task.status) {
  429. case 'PENDING':
  430. return Em.I18n.t('installer.step9.serviceStatus.abort.pending') + role;
  431. case 'QUEUED' :
  432. return Em.I18n.t('installer.step9.serviceStatus.abort.queued') + role;
  433. case 'IN_PROGRESS':
  434. return Em.I18n.t('installer.step9.serviceStatus.abort.inProgress') + role;
  435. case 'COMPLETED' :
  436. return role + Em.I18n.t('installer.step9.serviceStatus.abort.completed');
  437. case 'FAILED':
  438. return role + Em.I18n.t('installer.step9.serviceStatus.abort.failed');
  439. }
  440. }
  441. return '';
  442. },
  443. /**
  444. * Run start/check services after installation phase.
  445. * Does Ajax call to start all services
  446. */
  447. launchStartServices: function () {
  448. var data = {
  449. "RequestInfo": {
  450. "context": Em.I18n.t("requestInfo.startServices")
  451. },
  452. "Body": {
  453. "ServiceInfo": { "state": "STARTED" }
  454. }
  455. };
  456. var name = 'wizard.step9.installer.launch_start_services';
  457. if (this.get('content.controllerName') === 'addHostController') {
  458. var hostnames = [];
  459. for (var hostname in this.get('wizardController').getDBProperty('hosts')) {
  460. hostnames.push(hostname);
  461. }
  462. data = {
  463. "RequestInfo": {
  464. "context": Em.I18n.t("requestInfo.startHostComponents"),
  465. "query": "HostRoles/component_name.in(" + App.get('components.slaves').join(',') + ")&HostRoles/state=INSTALLED&HostRoles/host_name.in(" + hostnames.join(',') + ")"
  466. },
  467. "Body": {
  468. "HostRoles": { "state": "STARTED" }
  469. }
  470. };
  471. name = 'wizard.step9.add_host.launch_start_services';
  472. }
  473. data = JSON.stringify(data);
  474. if (App.testMode) {
  475. this.set('numPolls', 6);
  476. }
  477. App.ajax.send({
  478. name: name,
  479. sender: this,
  480. data: {
  481. data: data,
  482. cluster: this.get('content.cluster.name')
  483. },
  484. success: 'launchStartServicesSuccessCallback',
  485. error: 'launchStartServicesErrorCallback'
  486. });
  487. },
  488. /**
  489. * Success callback function for start services task.
  490. * @param jsonData: {json object} Contains Request id to poll.
  491. */
  492. launchStartServicesSuccessCallback: function (jsonData) {
  493. var clusterStatus = {};
  494. if (jsonData) {
  495. console.log("TRACE: Step9 -> In success function for the startService call");
  496. console.log("TRACE: Step9 -> value of the received data is: " + jsonData);
  497. var requestId = jsonData.Requests.id;
  498. console.log('requestId is: ' + requestId);
  499. clusterStatus = {
  500. status: 'INSTALLED',
  501. requestId: requestId,
  502. isStartError: false,
  503. isCompleted: false
  504. };
  505. this.hostHasClientsOnly(false);
  506. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  507. } else {
  508. console.log('ERROR: Error occurred in parsing JSON data');
  509. this.hostHasClientsOnly(true);
  510. clusterStatus = {
  511. status: 'STARTED',
  512. isStartError: false,
  513. isCompleted: true
  514. };
  515. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  516. this.set('status', 'success');
  517. this.set('progress', '100');
  518. }
  519. // We need to do recovery if there is a browser crash
  520. App.clusterStatus.setClusterStatus({
  521. clusterState: 'SERVICE_STARTING_3',
  522. wizardControllerName: this.get('content.controllerName'),
  523. localdb: App.db.data
  524. });
  525. if (jsonData) {
  526. this.startPolling();
  527. }
  528. },
  529. /**
  530. * This function will be called for Add host wizard only.
  531. * @param jsonError: {boolean} Boolean is true when API to start services returns 200 ok and no json data
  532. */
  533. hostHasClientsOnly: function (jsonError) {
  534. this.get('hosts').forEach(function (host) {
  535. var OnlyClients = true;
  536. var tasks = host.get('logTasks');
  537. tasks.forEach(function (task) {
  538. var component = serviceComponents.findProperty('component_name', task.Tasks.role);
  539. if (!(component && component.isClient)) {
  540. OnlyClients = false;
  541. }
  542. });
  543. if (OnlyClients || jsonError) {
  544. host.set('status', 'success');
  545. host.set('progress', '100');
  546. }
  547. });
  548. },
  549. /**
  550. * Error callback function for start services task.
  551. */
  552. launchStartServicesErrorCallback: function (jqXHR) {
  553. console.log("ERROR");
  554. this.set('startCallFailed',true);
  555. var clusterStatus = {
  556. status: 'INSTALL FAILED',
  557. isStartError: false,
  558. isCompleted: false
  559. };
  560. if (App.testMode) {
  561. this.set('content.cluster', clusterStatus);
  562. } else {
  563. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  564. }
  565. this.get('hosts').forEach(function (host) {
  566. host.set('progress', '100');
  567. });
  568. this.set('progress','100');
  569. var params = {
  570. cluster: this.get('content.cluster.name')
  571. };
  572. if (this.get('content.controllerName') === 'addHostController') {
  573. params.name = 'wizard.step9.add_host.launch_start_services';
  574. } else {
  575. params.name = 'wizard.step9.installer.launch_start_services';
  576. }
  577. var opt = App.formatRequest.call(App.urls[params.name], params);
  578. App.ajax.defaultErrorHandler(jqXHR,opt.url,opt.type);
  579. },
  580. /**
  581. * marks a host's status as "success" if all tasks are in COMPLETED state
  582. */
  583. onSuccessPerHost: function (actions, contentHost) {
  584. if (actions.everyProperty('Tasks.status', 'COMPLETED') && this.get('content.cluster.status') === 'INSTALLED') {
  585. contentHost.set('status', 'success');
  586. }
  587. },
  588. /**
  589. * 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.
  590. * note that if the master failed to install because of ABORTED or TIMEDOUT, we don't mark it as failed, because this would mark all hosts as "failed" and makes it difficult for the user
  591. * to find which host FAILED occurred on, if any
  592. * @param actions {Array} of tasks retrieved from polled data
  593. * @param contentHost {Object} A host object
  594. */
  595. onErrorPerHost: function (actions, contentHost) {
  596. if (!actions) return;
  597. if (actions.someProperty('Tasks.status', 'FAILED') || actions.someProperty('Tasks.status', 'ABORTED') || actions.someProperty('Tasks.status', 'TIMEDOUT')) {
  598. contentHost.set('status', 'warning');
  599. }
  600. if ((this.get('content.cluster.status') === 'PENDING' && actions.someProperty('Tasks.status', 'FAILED')) || (this.isMasterFailed(actions))) {
  601. contentHost.get('status') !== 'heartbeat_lost' ? contentHost.set('status', 'failed') : '';
  602. }
  603. },
  604. /**
  605. *
  606. * @param polledData : Json data polled from API.
  607. * @returns {boolean} true if there is at least one FAILED task of master component install
  608. */
  609. isMasterFailed: function (polledData) {
  610. var result = false;
  611. polledData.filterProperty('Tasks.command', 'INSTALL').filterProperty('Tasks.status', 'FAILED').mapProperty('Tasks.role').forEach(
  612. function (role) {
  613. if (!App.get('components.slaves').contains(role)) {
  614. result = true;
  615. }
  616. }
  617. );
  618. return result;
  619. },
  620. /**
  621. * Mark a host status as in_progress if the any task on the host if either in IN_PROGRESS, QUEUED or PENDONG state.
  622. * @param actions {Array} of tasks retrieved from polled data
  623. * @param contentHost {Object} A host object
  624. */
  625. onInProgressPerHost: function (actions, contentHost) {
  626. var runningAction = actions.findProperty('Tasks.status', 'IN_PROGRESS');
  627. if (runningAction === undefined || runningAction === null) {
  628. runningAction = actions.findProperty('Tasks.status', 'QUEUED');
  629. }
  630. if (runningAction === undefined || runningAction === null) {
  631. runningAction = actions.findProperty('Tasks.status', 'PENDING');
  632. }
  633. if (runningAction !== null && runningAction !== undefined) {
  634. contentHost.set('status', 'in_progress');
  635. contentHost.set('message', this.displayMessage(runningAction.Tasks));
  636. }
  637. },
  638. /**
  639. * calculate progress of tasks per host
  640. * @param actions
  641. * @param contentHost
  642. * @return {Number}
  643. */
  644. progressPerHost: function (actions, contentHost) {
  645. var progress = 0;
  646. var actionsPerHost = actions.length;
  647. var completedActions = 0;
  648. var queuedActions = 0;
  649. var inProgressActions = 0;
  650. actions.forEach(function (action) {
  651. completedActions += +(['COMPLETED', 'FAILED', 'ABORTED', 'TIMEDOUT'].contains(action.Tasks.status));
  652. queuedActions += +(action.Tasks.status === 'QUEUED');
  653. inProgressActions += +(action.Tasks.status === 'IN_PROGRESS');
  654. }, this);
  655. /** for the install phase (PENDING), % completed per host goes up to 33%; floor(100 / 3)
  656. * for the start phase (INSTALLED), % completed starts from 34%
  657. * when task in queued state means it's completed on 9%
  658. * in progress - 35%
  659. * completed - 100%
  660. */
  661. switch (this.get('content.cluster.status')) {
  662. case 'PENDING':
  663. progress = actionsPerHost ? (Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 33)) : 33;
  664. break;
  665. case 'INSTALLED':
  666. progress = actionsPerHost ? (34 + Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 66)) : 100;
  667. break;
  668. default:
  669. progress = 100;
  670. break;
  671. }
  672. contentHost.set('progress', progress.toString());
  673. return progress;
  674. },
  675. /**
  676. *
  677. * @param polledData : Josn data retrieved from API
  678. * @returns {Boolean} : Has step completed successfully
  679. */
  680. isSuccess: function (polledData) {
  681. return polledData.everyProperty('Tasks.status', 'COMPLETED');
  682. },
  683. /**
  684. * return true if:
  685. * 1. any of the master/client components failed to install
  686. * OR
  687. * 2. at least 50% of the slave host components for the particular service component fails to install
  688. */
  689. isStepFailed: function () {
  690. var failed = false;
  691. var polledData = this.get('polledData');
  692. polledData.filterProperty('Tasks.command', 'INSTALL').mapProperty('Tasks.role').uniq().forEach(function (role) {
  693. if (failed) {
  694. return;
  695. }
  696. var actionsPerRole = polledData.filterProperty('Tasks.role', role);
  697. if (App.get('components.slaves').contains(role)) {
  698. // check slave components for success factor.
  699. // partial failure for slave components are allowed.
  700. var actionsFailed = actionsPerRole.filterProperty('Tasks.status', 'FAILED');
  701. var actionsAborted = actionsPerRole.filterProperty('Tasks.status', 'ABORTED');
  702. var actionsTimedOut = actionsPerRole.filterProperty('Tasks.status', 'TIMEDOUT');
  703. if ((((actionsFailed.length + actionsAborted.length + actionsTimedOut.length) / actionsPerRole.length) * 100) > 50) {
  704. failed = true;
  705. }
  706. } else if (actionsPerRole.someProperty('Tasks.status', 'FAILED') || actionsPerRole.someProperty('Tasks.status', 'ABORTED') ||
  707. actionsPerRole.someProperty('Tasks.status', 'TIMEDOUT')) {
  708. // check non-salve components (i.e., masters and clients). all of these must be successfully installed.
  709. failed = true;
  710. }
  711. }, this);
  712. return failed;
  713. },
  714. /**
  715. * polling from ui stops only when no action has 'PENDING', 'QUEUED' or 'IN_PROGRESS' status
  716. * Makes a state transition
  717. * PENDING -> INSTALLED
  718. * PENDING -> INSTALL FAILED
  719. * INSTALLED -> STARTED
  720. * INSTALLED -> START_FAILED
  721. * @param polledData json data retrieved from API
  722. * @returns {Boolean} true if polling should stop; false otherwise
  723. */
  724. finishState: function (polledData) {
  725. if (this.get('content.cluster.status') === 'INSTALLED') {
  726. return this.isServicesStarted(polledData);
  727. } else if (this.get('content.cluster.status') === 'PENDING') {
  728. return this.isServicesInstalled(polledData);
  729. } else if (this.get('content.cluster.status') === 'INSTALL FAILED' || this.get('content.cluster.status') === 'START FAILED'
  730. || this.get('content.cluster.status') === 'STARTED') {
  731. this.set('progress', '100');
  732. return true;
  733. }
  734. return false;
  735. },
  736. /**
  737. * @param polledData Josn data retrieved from API
  738. * @returns {boolean} Has "Start All Services" request completed successfully
  739. */
  740. isServicesStarted: function (polledData) {
  741. var clusterStatus = {};
  742. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  743. this.set('progress', '100');
  744. clusterStatus = {
  745. status: 'INSTALLED',
  746. requestId: this.get('content.cluster.requestId'),
  747. isCompleted: true
  748. };
  749. if (this.isSuccess(polledData)) {
  750. clusterStatus.status = 'STARTED';
  751. var serviceStartTime = App.dateTime();
  752. clusterStatus.installTime = ((parseInt(serviceStartTime) - parseInt(this.get('content.cluster.installStartTime'))) / 60000).toFixed(2);
  753. } else {
  754. clusterStatus.status = 'START FAILED'; // 'START FAILED' implies to step10 that installation was successful but start failed
  755. }
  756. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  757. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  758. return true;
  759. }
  760. return false;
  761. },
  762. /**
  763. * @param polledData Josn data retrieved from API
  764. * @returns {boolean} Has "Install All Services" request completed successfully
  765. */
  766. isServicesInstalled: function (polledData) {
  767. var clusterStatus = {};
  768. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  769. clusterStatus = {
  770. status: 'PENDING',
  771. requestId: this.get('content.cluster.requestId'),
  772. isCompleted: false
  773. };
  774. if (this.get('status') === 'failed') {
  775. clusterStatus.status = 'INSTALL FAILED';
  776. this.set('progress', '100');
  777. this.get('hosts').forEach(function (host) {
  778. if (host.get('status') !== 'failed' && host.get('status') !== 'warning') {
  779. this.isAllComponentsInstalled();
  780. }
  781. host.set('progress', '100');
  782. }, this);
  783. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  784. } else {
  785. this.set('progress', '34');
  786. if (this.get('content.controllerName') === 'installerController') {
  787. this.isAllComponentsInstalled();
  788. } else {
  789. this.launchStartServices();
  790. }
  791. }
  792. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  793. return true;
  794. }
  795. return false;
  796. },
  797. /**
  798. * This is done at HostRole level.
  799. * @param tasksPerHost {Array}
  800. * @param host {Object}
  801. */
  802. setLogTasksStatePerHost: function (tasksPerHost, host) {
  803. tasksPerHost.forEach(function (_task) {
  804. var task = host.logTasks.findProperty('Tasks.id', _task.Tasks.id);
  805. if (task) {
  806. task.Tasks.status = _task.Tasks.status;
  807. task.Tasks.exit_code = _task.Tasks.exit_code;
  808. } else {
  809. host.logTasks.pushObject(_task);
  810. }
  811. }, this);
  812. },
  813. /**
  814. * Parses the Json data retrieved from API and sets the task on the host of {hosts} array binded to template
  815. * @param polledData Json data retrieved from API
  816. * @returns {Boolean} True if stage transition is completed.
  817. * On true, polling will be stopped.
  818. */
  819. parseHostInfo: function (polledData) {
  820. console.log('TRACE: Entering host info function');
  821. var self = this;
  822. var totalProgress = 0;
  823. var tasksData = polledData.tasks;
  824. console.log("The value of tasksData is: ", tasksData);
  825. if (!tasksData) {
  826. console.log("Step9: ERROR: NO tasks available to process");
  827. }
  828. var requestId = this.get('content.cluster.requestId');
  829. tasksData.setEach('Tasks.request_id', requestId);
  830. if (polledData.Requests && polledData.Requests.id && polledData.Requests.id != requestId) {
  831. // We don't want to use non-current requestId's tasks data to
  832. // determine the current install status.
  833. // Also, we don't want to keep polling if it is not the
  834. // current requestId.
  835. return false;
  836. }
  837. this.replacePolledData(tasksData);
  838. var tasksHostMap = {};
  839. tasksData.forEach(function (task) {
  840. if (tasksHostMap[task.Tasks.host_name]) {
  841. tasksHostMap[task.Tasks.host_name].push(task);
  842. } else {
  843. tasksHostMap[task.Tasks.host_name] = [task];
  844. }
  845. });
  846. this.get('hosts').forEach(function (_host) {
  847. var actionsPerHost = tasksHostMap[_host.name] || []; // retrieved from polled Data
  848. if (actionsPerHost.length === 0) {
  849. if (this.get('content.cluster.status') === 'PENDING' || this.get('content.cluster.status') === 'INSTALL FAILED') {
  850. _host.set('progress', '33');
  851. _host.set('isNoTasksForInstall', true);
  852. _host.set('status', 'pending');
  853. }
  854. if (this.get('content.cluster.status') === 'INSTALLED' || this.get('content.cluster.status') === 'FAILED') {
  855. _host.set('progress', '100');
  856. _host.set('status', 'success');
  857. }
  858. console.log("INFO: No task is hosted on the host");
  859. } else {
  860. _host.set('isNoTasksForInstall', false);
  861. }
  862. this.setLogTasksStatePerHost(actionsPerHost, _host);
  863. this.onSuccessPerHost(actionsPerHost, _host); // every action should be a success
  864. this.onErrorPerHost(actionsPerHost, _host); // any action should be a failure
  865. this.onInProgressPerHost(actionsPerHost, _host); // current running action for a host
  866. totalProgress += self.progressPerHost(actionsPerHost, _host);
  867. if (_host.get('progress') == '33' && _host.get('status') != 'failed' && _host.get('status') != 'warning') {
  868. _host.set('message', this.t('installer.step9.host.status.nothingToInstall'));
  869. _host.set('status', 'pending');
  870. }
  871. }, this);
  872. this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
  873. totalProgress = Math.floor(totalProgress / this.get('hosts.length'));
  874. this.set('progress', totalProgress.toString());
  875. console.log("INFO: right now the progress is: " + this.get('progress'));
  876. return this.finishState(tasksData);
  877. },
  878. /**
  879. * starts polling to the API.
  880. */
  881. startPolling: function () {
  882. this.set('isSubmitDisabled', true);
  883. this.doPolling();
  884. },
  885. /**
  886. *
  887. * @param requestId {Int} Request Id received on triggering install/start command successfully
  888. * @returns {string} URL to poll to track the result of the triggered command
  889. */
  890. getUrl: function (requestId) {
  891. var clusterName = this.get('content.cluster.name');
  892. var requestId = requestId || this.get('content.cluster.requestId');
  893. var url = App.apiPrefix + '/clusters/' + clusterName + '/requests/' + requestId + '?fields=tasks/Tasks/command,tasks/Tasks/exit_code,tasks/Tasks/start_time,tasks/Tasks/end_time,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status&minimal_response=true';
  894. console.log("URL for step9 is: " + url);
  895. return url;
  896. },
  897. /**
  898. * This function calls API just once to fetch log data of all tasks.
  899. * @param requestId {Int} Request Id received on triggering install/start command successfully
  900. */
  901. loadLogData: function (requestId) {
  902. var url = this.getUrl(requestId);
  903. var requestsId = this.get('wizardController').getDBProperty('cluster').oldRequestsId;
  904. if (App.testMode) {
  905. this.POLL_INTERVAL = 1;
  906. }
  907. requestsId.forEach(function (requestId) {
  908. url = this.getUrl(requestId);
  909. if (App.testMode) {
  910. this.POLL_INTERVAL = 1;
  911. url = this.get('mockDataPrefix') + '/poll_' + this.numPolls + '.json';
  912. }
  913. this.getLogsByRequest(url, false);
  914. }, this);
  915. },
  916. /**
  917. * {Number}
  918. * <code>taskId</code> of current open task
  919. */
  920. currentOpenTaskId: 0,
  921. /**
  922. * {Number}
  923. * <code>requestId</code> of current open task
  924. */
  925. currentOpenTaskRequestId: 0,
  926. /**
  927. * Load form server <code>stderr, stdout</code> of current open task
  928. */
  929. loadCurrentTaskLog: function () {
  930. var taskId = this.get('currentOpenTaskId');
  931. var requestId = this.get('currentOpenTaskRequestId');
  932. var clusterName = this.get('content.cluster.name');
  933. if (!taskId) {
  934. console.log('taskId is null.');
  935. return;
  936. }
  937. App.ajax.send({
  938. name: 'background_operations.get_by_task',
  939. sender: this,
  940. data: {
  941. 'taskId': taskId,
  942. 'requestId': requestId,
  943. 'clusterName': clusterName,
  944. 'sync': true
  945. },
  946. success: 'loadCurrentTaskLogSuccessCallback',
  947. error: 'loadCurrentTaskLogErrorCallback'
  948. });
  949. },
  950. /**
  951. * success callback function for getting log data of the opened task
  952. * @param data json object
  953. */
  954. loadCurrentTaskLogSuccessCallback: function (data) {
  955. var taskId = this.get('currentOpenTaskId');
  956. if (taskId) {
  957. var currentTask = this.get('hosts').findProperty('name', data.Tasks.host_name).get('logTasks').findProperty('Tasks.id', data.Tasks.id);
  958. if (currentTask) {
  959. currentTask.Tasks.stderr = data.Tasks.stderr;
  960. currentTask.Tasks.stdout = data.Tasks.stdout;
  961. }
  962. }
  963. this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
  964. },
  965. /**
  966. * Error callback function for getting log data of the opened task
  967. */
  968. loadCurrentTaskLogErrorCallback: function () {
  969. this.set('currentOpenTaskId', 0);
  970. },
  971. /**
  972. * Function polls the API to retrieve data for the request.
  973. * @param url {string} url to poll
  974. * @param polling {Boolean} whether to continue polling for status or not
  975. */
  976. getLogsByRequest: function (url, polling) {
  977. var self = this;
  978. $.ajax({
  979. type: 'GET',
  980. url: url,
  981. async: true,
  982. timeout: App.timeout,
  983. dataType: 'text',
  984. success: function (data) {
  985. var parsedData = jQuery.parseJSON(data);
  986. console.log("TRACE: In success function for the GET logs data");
  987. console.log("TRACE: Step9 -> The value is: ", parsedData);
  988. var result = self.parseHostInfo(parsedData);
  989. if (!polling) {
  990. if (self.get('content.cluster.status') === 'INSTALL FAILED') {
  991. self.isAllComponentsInstalled();
  992. }
  993. return;
  994. }
  995. if (result !== true) {
  996. window.setTimeout(function () {
  997. if (self.get('currentOpenTaskId')) {
  998. self.loadCurrentTaskLog();
  999. }
  1000. self.doPolling();
  1001. }, self.POLL_INTERVAL);
  1002. }
  1003. },
  1004. error: function (request, ajaxOptions, error) {
  1005. console.log("TRACE: STep9 -> In error function for the GET logs data");
  1006. console.log("TRACE: STep9 -> value of the url is: " + url);
  1007. console.log("TRACE: STep9 -> error code status is: " + request.status);
  1008. },
  1009. statusCode: require('data/statusCodes')
  1010. }).retry({times: App.maxRetries, timeout: App.timeout}).then(null,
  1011. function () {
  1012. App.showReloadPopup();
  1013. console.log('Install services all retries failed');
  1014. }
  1015. );
  1016. },
  1017. /**
  1018. * Delegates the function call to {getLogsByRequest} with appropriate params
  1019. */
  1020. doPolling: function () {
  1021. var url = this.getUrl();
  1022. if (App.testMode) {
  1023. this.numPolls++;
  1024. url = this.get('mockDataPrefix') + '/poll_' + this.get('numPolls') + '.json';
  1025. }
  1026. this.getLogsByRequest(url, true);
  1027. },
  1028. /**
  1029. * Check that all components are in INSTALLED state before issuing start command
  1030. */
  1031. isAllComponentsInstalled: function () {
  1032. if (this.get('content.controllerName') !== 'installerController') {
  1033. return;
  1034. }
  1035. var name = 'wizard.step9.installer.get_host_status';
  1036. App.ajax.send({
  1037. name: name,
  1038. sender: this,
  1039. data: {
  1040. cluster: this.get('content.cluster.name')
  1041. },
  1042. success: 'isAllComponentsInstalledSuccessCallback',
  1043. error: 'isAllComponentsInstalledErrorCallback'
  1044. });
  1045. },
  1046. /**
  1047. * Success callback function for API checking host state and host_components state.
  1048. * @param jsonData {Object}
  1049. */
  1050. isAllComponentsInstalledSuccessCallback: function (jsonData) {
  1051. var clusterStatus = {
  1052. status: 'INSTALL FAILED',
  1053. isStartError: true,
  1054. isCompleted: false
  1055. };
  1056. var hostsWithHeartbeatLost = [];
  1057. var hostComponents = jsonData.items.mapProperty('host_components');
  1058. jsonData.items.filterProperty('Hosts.host_state', 'HEARTBEAT_LOST').forEach(function (host) {
  1059. var hostComponentObj = {hostName: host.Hosts.host_name};
  1060. var componentArr = [];
  1061. host.host_components.forEach(function (_hostComponent) {
  1062. var componentName = App.format.role(_hostComponent.HostRoles.component_name);
  1063. componentArr.pushObject(componentName);
  1064. }, this);
  1065. hostComponentObj.componentNames = this.getComponentMessage(componentArr);
  1066. hostsWithHeartbeatLost.pushObject(hostComponentObj);
  1067. }, this);
  1068. this.set('hostsWithHeartbeatLost', hostsWithHeartbeatLost);
  1069. if (hostsWithHeartbeatLost.length) {
  1070. this.get('hosts').forEach(function (host) {
  1071. if (hostsWithHeartbeatLost.someProperty(('hostName'), host.get('name'))) {
  1072. host.set('status', 'heartbeat_lost');
  1073. } else if (host.get('status') !== 'failed' && host.get('status') !== 'warning') {
  1074. host.set('message', Em.I18n.t('installer.step9.host.status.startAborted'));
  1075. }
  1076. host.set('progress', '100');
  1077. });
  1078. this.set('progress', '100');
  1079. if (!App.testMode) {
  1080. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  1081. }
  1082. } else if (this.get('content.cluster.status') === 'PENDING') {
  1083. this.launchStartServices();
  1084. }
  1085. },
  1086. /**
  1087. * Error callback function for API checking host state and host_components state
  1088. */
  1089. isAllComponentsInstalledErrorCallback: function () {
  1090. console.log("ERROR");
  1091. var clusterStatus = {
  1092. status: 'INSTALL FAILED',
  1093. isStartError: true,
  1094. isCompleted: false
  1095. };
  1096. this.set('progress', '100');
  1097. this.get('hosts').forEach(function (host) {
  1098. if (host.get('status') !== 'failed' && host.get('status') !== 'warning') {
  1099. host.set('message', Em.I18n.t('installer.step9.host.status.startAborted'));
  1100. host.set('progress', '100');
  1101. }
  1102. });
  1103. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  1104. },
  1105. /**
  1106. * @param componentArr {Array} Array of components
  1107. * @returns {String} Formatted string of components to display on the UI.
  1108. */
  1109. getComponentMessage: function (componentArr) {
  1110. var label;
  1111. componentArr.forEach(function (_component) {
  1112. if (_component === componentArr[0]) {
  1113. label = _component;
  1114. } else if (_component !== componentArr[componentArr.length - 1]) { // [clients.length - 1]
  1115. label = label + ' ' + _component;
  1116. if (_component !== componentArr[componentArr.length - 2]) {
  1117. label = label + ',';
  1118. }
  1119. } else {
  1120. label = label + ' ' + Em.I18n.t('and') + ' ' + _component;
  1121. }
  1122. }, this);
  1123. return label;
  1124. }
  1125. });