step9_controller.js 42 KB

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