step9_controller.js 41 KB

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