step9_controller.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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. //flag identify whether get all hosts or only NewHosts(newly added) hosts
  268. var getOnlyNewHosts = (this.get('content.controllerName') !== 'addServiceController');
  269. for (var index in hosts) {
  270. if (hosts[index].bootStatus === 'REGISTERED' && (!getOnlyNewHosts || !hosts[index].isInstalled)) {
  271. var hostInfo = App.HostInfo.create({
  272. name: hosts[index].name,
  273. status: (hosts[index].status) ? hosts[index].status : 'info',
  274. logTasks: [],
  275. message: (hosts[index].message) ? hosts[index].message : 'Waiting',
  276. progress: 0,
  277. isNoTasksForInstall: false
  278. });
  279. this.get('hosts').pushObject(hostInfo);
  280. }
  281. }
  282. },
  283. /**
  284. * Set new polled data
  285. * @param polledData sets the <code>polledData</code> object of the controller
  286. * @method replacePolledData
  287. */
  288. replacePolledData: function (polledData) {
  289. this.get('polledData').clear();
  290. this.set('polledData', polledData);
  291. },
  292. /**
  293. * Get the appropriate message for the host as per the running task
  294. * @param {object} task
  295. * @returns {String}
  296. * @method displayMessage
  297. */
  298. displayMessage: function (task) {
  299. var role = App.format.role(task.role);
  300. /* istanbul ignore next */
  301. switch (task.command) {
  302. case 'INSTALL':
  303. switch (task.status) {
  304. case 'PENDING':
  305. return Em.I18n.t('installer.step9.serviceStatus.install.pending') + role;
  306. case 'QUEUED' :
  307. return Em.I18n.t('installer.step9.serviceStatus.install.queued') + role;
  308. case 'IN_PROGRESS':
  309. return Em.I18n.t('installer.step9.serviceStatus.install.inProgress') + role;
  310. case 'COMPLETED' :
  311. return Em.I18n.t('installer.step9.serviceStatus.install.completed') + role;
  312. case 'FAILED':
  313. return Em.I18n.t('installer.step9.serviceStatus.install.failed') + role;
  314. }
  315. break;
  316. case 'UNINSTALL':
  317. switch (task.status) {
  318. case 'PENDING':
  319. return Em.I18n.t('installer.step9.serviceStatus.uninstall.pending') + role;
  320. case 'QUEUED' :
  321. return Em.I18n.t('installer.step9.serviceStatus.uninstall.queued') + role;
  322. case 'IN_PROGRESS':
  323. return Em.I18n.t('installer.step9.serviceStatus.uninstall.inProgress') + role;
  324. case 'COMPLETED' :
  325. return Em.I18n.t('installer.step9.serviceStatus.uninstall.completed') + role;
  326. case 'FAILED':
  327. return Em.I18n.t('installer.step9.serviceStatus.uninstall.failed') + role;
  328. }
  329. break;
  330. case 'START' :
  331. switch (task.status) {
  332. case 'PENDING':
  333. return Em.I18n.t('installer.step9.serviceStatus.start.pending') + role;
  334. case 'QUEUED' :
  335. return Em.I18n.t('installer.step9.serviceStatus.start.queued') + role;
  336. case 'IN_PROGRESS':
  337. return Em.I18n.t('installer.step9.serviceStatus.start.inProgress') + role;
  338. case 'COMPLETED' :
  339. return role + Em.I18n.t('installer.step9.serviceStatus.start.completed');
  340. case 'FAILED':
  341. return role + Em.I18n.t('installer.step9.serviceStatus.start.failed');
  342. }
  343. break;
  344. case 'STOP' :
  345. switch (task.status) {
  346. case 'PENDING':
  347. return Em.I18n.t('installer.step9.serviceStatus.stop.pending') + role;
  348. case 'QUEUED' :
  349. return Em.I18n.t('installer.step9.serviceStatus.stop.queued') + role;
  350. case 'IN_PROGRESS':
  351. return Em.I18n.t('installer.step9.serviceStatus.stop.inProgress') + role;
  352. case 'COMPLETED' :
  353. return role + Em.I18n.t('installer.step9.serviceStatus.stop.completed');
  354. case 'FAILED':
  355. return role + Em.I18n.t('installer.step9.serviceStatus.stop.failed');
  356. }
  357. break;
  358. case 'EXECUTE' :
  359. case 'SERVICE_CHECK' :
  360. switch (task.status) {
  361. case 'PENDING':
  362. return Em.I18n.t('installer.step9.serviceStatus.execute.pending') + role;
  363. case 'QUEUED' :
  364. return Em.I18n.t('installer.step9.serviceStatus.execute.queued') + role;
  365. case 'IN_PROGRESS':
  366. return Em.I18n.t('installer.step9.serviceStatus.execute.inProgress') + role;
  367. case 'COMPLETED' :
  368. return role + Em.I18n.t('installer.step9.serviceStatus.execute.completed');
  369. case 'FAILED':
  370. return role + Em.I18n.t('installer.step9.serviceStatus.execute.failed');
  371. }
  372. break;
  373. case 'ABORT' :
  374. switch (task.status) {
  375. case 'PENDING':
  376. return Em.I18n.t('installer.step9.serviceStatus.abort.pending') + role;
  377. case 'QUEUED' :
  378. return Em.I18n.t('installer.step9.serviceStatus.abort.queued') + role;
  379. case 'IN_PROGRESS':
  380. return Em.I18n.t('installer.step9.serviceStatus.abort.inProgress') + role;
  381. case 'COMPLETED' :
  382. return role + Em.I18n.t('installer.step9.serviceStatus.abort.completed');
  383. case 'FAILED':
  384. return role + Em.I18n.t('installer.step9.serviceStatus.abort.failed');
  385. }
  386. }
  387. return '';
  388. },
  389. /**
  390. * Run start/check services after installation phase.
  391. * Does Ajax call to start all services
  392. * @return {$.ajax|null}
  393. * @method launchStartServices
  394. */
  395. launchStartServices: function () {
  396. var data = {};
  397. var name = '';
  398. var servicesList = [];
  399. if (this.get('content.controllerName') === 'addHostController') {
  400. name = 'wizard.step9.add_host.launch_start_services';
  401. var hostnames = [];
  402. for (var hostname in this.get('wizardController').getDBProperty('hosts')) {
  403. if(this.get('hosts').findProperty('name', hostname)){
  404. hostnames.push(hostname);
  405. }
  406. }
  407. data = {
  408. "RequestInfo": {
  409. "context": Em.I18n.t("requestInfo.startHostComponents"),
  410. "query": "HostRoles/component_name.in(" + App.get('components.slaves').join(',') + ")&HostRoles/state=INSTALLED&HostRoles/host_name.in(" + hostnames.join(',') + ")"
  411. },
  412. "Body": {
  413. "HostRoles": { "state": "STARTED" }
  414. }
  415. };
  416. } else if (this.get('content.controllerName') === 'addServiceController') {
  417. servicesList = this.get('content.services').filterProperty('isSelected', true).filterProperty('isDisabled', false).mapProperty('serviceName');
  418. name = 'wizard.step9.add_service.launch_start_services';
  419. data = {
  420. "RequestInfo": {
  421. "context": Em.I18n.t("requestInfo.startAddedServices")
  422. },
  423. "Body": {
  424. "ServiceInfo": { "state": "STARTED" }
  425. }
  426. };
  427. } else {
  428. name = 'wizard.step9.installer.launch_start_services';
  429. data = {
  430. "RequestInfo": {
  431. "context": Em.I18n.t("requestInfo.startServices")
  432. },
  433. "Body": {
  434. "ServiceInfo": { "state": "STARTED" }
  435. }
  436. };
  437. }
  438. data = JSON.stringify(data);
  439. if (App.testMode) {
  440. this.set('numPolls', 6);
  441. }
  442. return App.ajax.send({
  443. name: name,
  444. sender: this,
  445. data: {
  446. data: data,
  447. cluster: this.get('content.cluster.name'),
  448. servicesList: servicesList // used only for Add Service wizard
  449. },
  450. success: 'launchStartServicesSuccessCallback',
  451. error: 'launchStartServicesErrorCallback'
  452. });
  453. },
  454. /**
  455. * Success callback function for start services task.
  456. * @param {object} jsonData Contains Request id to poll.
  457. * @method launchStartServicesSuccessCallback
  458. */
  459. launchStartServicesSuccessCallback: function (jsonData) {
  460. var clusterStatus = {};
  461. if (jsonData) {
  462. console.log("TRACE: Step9 -> In success function for the startService call");
  463. console.log("TRACE: Step9 -> value of the received data is: " + jsonData);
  464. var requestId = jsonData.Requests.id;
  465. console.log('requestId is: ' + requestId);
  466. clusterStatus = {
  467. status: 'INSTALLED',
  468. requestId: requestId,
  469. isStartError: false,
  470. isCompleted: false
  471. };
  472. this.hostHasClientsOnly(false);
  473. this.saveClusterStatus(clusterStatus);
  474. }
  475. else {
  476. console.log('ERROR: Error occurred in parsing JSON data');
  477. this.hostHasClientsOnly(true);
  478. clusterStatus = {
  479. status: 'STARTED',
  480. isStartError: false,
  481. isCompleted: true
  482. };
  483. this.saveClusterStatus(clusterStatus);
  484. this.set('status', 'success');
  485. this.set('progress', '100');
  486. }
  487. // We need to do recovery if there is a browser crash
  488. App.clusterStatus.setClusterStatus({
  489. clusterState: 'SERVICE_STARTING_3',
  490. wizardControllerName: this.get('content.controllerName'),
  491. localdb: App.db.data
  492. });
  493. if (jsonData) {
  494. this.startPolling();
  495. }
  496. },
  497. /**
  498. * This function will be called for Add host wizard only.
  499. * @param {bool} jsonError Boolean is true when API to start services returns 200 ok and no json data
  500. * @method hostHasClientsOnly
  501. */
  502. hostHasClientsOnly: function (jsonError) {
  503. this.get('hosts').forEach(function (host) {
  504. var OnlyClients = true;
  505. var tasks = host.get('logTasks');
  506. tasks.forEach(function (task) {
  507. var component = App.StackServiceComponent.find().findProperty('componentName', task.Tasks.role);
  508. if (!(component && component.get('isClient'))) {
  509. OnlyClients = false;
  510. }
  511. });
  512. if (OnlyClients || jsonError) {
  513. host.set('status', 'success');
  514. host.set('progress', '100');
  515. }
  516. });
  517. },
  518. /**
  519. * Error callback function for start services task.
  520. * @param {object} jqXHR
  521. * @param {object} ajaxOptions
  522. * @param {string} error
  523. * @param {object} opt
  524. * @method launchStartServicesErrorCallback
  525. */
  526. launchStartServicesErrorCallback: function (jqXHR, ajaxOptions, error, opt) {
  527. console.log("ERROR");
  528. this.set('startCallFailed', true);
  529. var clusterStatus = {
  530. status: 'INSTALL FAILED',
  531. isStartError: false,
  532. isCompleted: false
  533. };
  534. this.saveClusterStatus(clusterStatus);
  535. this.get('hosts').forEach(function (host) {
  536. host.set('progress', '100');
  537. });
  538. this.set('progress', '100');
  539. App.ajax.defaultErrorHandler(jqXHR, opt.url, opt.method, jqXHR.status);
  540. },
  541. /**
  542. * Marks a host's status as "success" if all tasks are in COMPLETED state
  543. * @method onSuccessPerHost
  544. */
  545. onSuccessPerHost: function (actions, contentHost) {
  546. if (actions.everyProperty('Tasks.status', 'COMPLETED') && this.get('content.cluster.status') === 'INSTALLED') {
  547. contentHost.set('status', 'success');
  548. }
  549. },
  550. /**
  551. * 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.
  552. * 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
  553. * to find which host FAILED occurred on, if any
  554. * @param actions {Array} of tasks retrieved from polled data
  555. * @param contentHost {Object} A host object
  556. * @method onErrorPerHost
  557. */
  558. onErrorPerHost: function (actions, contentHost) {
  559. if (!actions) return;
  560. if (actions.someProperty('Tasks.status', 'FAILED') || actions.someProperty('Tasks.status', 'ABORTED') || actions.someProperty('Tasks.status', 'TIMEDOUT')) {
  561. contentHost.set('status', 'warning');
  562. }
  563. if ((this.get('content.cluster.status') === 'PENDING' && actions.someProperty('Tasks.status', 'FAILED')) || (this.isMasterFailed(actions))) {
  564. contentHost.get('status') !== 'heartbeat_lost' ? contentHost.set('status', 'failed') : '';
  565. }
  566. },
  567. /**
  568. * Check if some master component is failed
  569. * @param {object} polledData data polled from API.
  570. * @returns {bool} true if there is at least one FAILED task of master component install
  571. * @method isMasterFailed
  572. */
  573. isMasterFailed: function (polledData) {
  574. var result = false;
  575. polledData.filterProperty('Tasks.command', 'INSTALL').filterProperty('Tasks.status', 'FAILED').mapProperty('Tasks.role').forEach(
  576. function (role) {
  577. if (!App.get('components.slaves').contains(role)) {
  578. result = true;
  579. }
  580. }
  581. );
  582. return result;
  583. },
  584. /**
  585. * Mark a host status as in_progress if the any task on the host if either in IN_PROGRESS, QUEUED or PENDONG state.
  586. * @param actions {Array} of tasks retrieved from polled data
  587. * @param contentHost {Object} A host object
  588. * @method onInProgressPerHost
  589. */
  590. onInProgressPerHost: function (actions, contentHost) {
  591. var runningAction = actions.findProperty('Tasks.status', 'IN_PROGRESS');
  592. if (runningAction === undefined || runningAction === null) {
  593. runningAction = actions.findProperty('Tasks.status', 'QUEUED');
  594. }
  595. if (runningAction === undefined || runningAction === null) {
  596. runningAction = actions.findProperty('Tasks.status', 'PENDING');
  597. }
  598. if (runningAction !== null && runningAction !== undefined) {
  599. contentHost.set('status', 'in_progress');
  600. contentHost.set('message', this.displayMessage(runningAction.Tasks));
  601. }
  602. },
  603. /**
  604. * Calculate progress of tasks per host
  605. * @param {object} actions
  606. * @param {object} contentHost
  607. * @return {Number}
  608. * @method progressPerHost
  609. */
  610. progressPerHost: function (actions, contentHost) {
  611. var progress = 0;
  612. var actionsPerHost = actions.length;
  613. var completedActions = 0;
  614. var queuedActions = 0;
  615. var inProgressActions = 0;
  616. actions.forEach(function (action) {
  617. completedActions += +(['COMPLETED', 'FAILED', 'ABORTED', 'TIMEDOUT'].contains(action.Tasks.status));
  618. queuedActions += +(action.Tasks.status === 'QUEUED');
  619. inProgressActions += +(action.Tasks.status === 'IN_PROGRESS');
  620. }, this);
  621. /** for the install phase (PENDING), % completed per host goes up to 33%; floor(100 / 3)
  622. * for the start phase (INSTALLED), % completed starts from 34%
  623. * when task in queued state means it's completed on 9%
  624. * in progress - 35%
  625. * completed - 100%
  626. */
  627. switch (this.get('content.cluster.status')) {
  628. case 'PENDING':
  629. progress = actionsPerHost ? (Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 33)) : 33;
  630. break;
  631. case 'INSTALLED':
  632. progress = actionsPerHost ? (34 + Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 66)) : 100;
  633. break;
  634. default:
  635. progress = 100;
  636. break;
  637. }
  638. contentHost.set('progress', progress.toString());
  639. return progress;
  640. },
  641. /**
  642. * Check if step completed successfully
  643. * @param {object} polledData data retrieved from API
  644. * @returns {bool}
  645. * @method isSuccess
  646. */
  647. isSuccess: function (polledData) {
  648. return polledData.everyProperty('Tasks.status', 'COMPLETED');
  649. },
  650. /**
  651. * Check if step is failed
  652. * Return true if:
  653. * 1. any of the master/client components failed to install
  654. * OR
  655. * 2. at least 50% of the slave host components for the particular service component fails to install
  656. * @method isStepFailed
  657. */
  658. isStepFailed: function () {
  659. var failed = false;
  660. var polledData = this.get('polledData');
  661. polledData.filterProperty('Tasks.command', 'INSTALL').mapProperty('Tasks.role').uniq().forEach(function (role) {
  662. if (failed) {
  663. return;
  664. }
  665. var actionsPerRole = polledData.filterProperty('Tasks.role', role);
  666. if (App.get('components.slaves').contains(role)) {
  667. // check slave components for success factor.
  668. // partial failure for slave components are allowed.
  669. var actionsFailed = actionsPerRole.filterProperty('Tasks.status', 'FAILED');
  670. var actionsAborted = actionsPerRole.filterProperty('Tasks.status', 'ABORTED');
  671. var actionsTimedOut = actionsPerRole.filterProperty('Tasks.status', 'TIMEDOUT');
  672. if ((((actionsFailed.length + actionsAborted.length + actionsTimedOut.length) / actionsPerRole.length) * 100) > 50) {
  673. failed = true;
  674. }
  675. } else if (actionsPerRole.someProperty('Tasks.status', 'FAILED') || actionsPerRole.someProperty('Tasks.status', 'ABORTED') ||
  676. actionsPerRole.someProperty('Tasks.status', 'TIMEDOUT')) {
  677. // check non-salve components (i.e., masters and clients). all of these must be successfully installed.
  678. failed = true;
  679. }
  680. }, this);
  681. return failed;
  682. },
  683. /**
  684. * polling from ui stops only when no action has 'PENDING', 'QUEUED' or 'IN_PROGRESS' status
  685. * Makes a state transition
  686. * PENDING -> INSTALLED
  687. * PENDING -> INSTALL FAILED
  688. * INSTALLED -> STARTED
  689. * INSTALLED -> START_FAILED
  690. * @param polledData json data retrieved from API
  691. * @returns {bool} true if polling should stop; false otherwise
  692. * @method finishState
  693. */
  694. finishState: function (polledData) {
  695. if (this.get('content.cluster.status') === 'INSTALLED') {
  696. return this.isServicesStarted(polledData);
  697. } else if (this.get('content.cluster.status') === 'PENDING') {
  698. return this.isServicesInstalled(polledData);
  699. } else if (this.get('content.cluster.status') === 'INSTALL FAILED' || this.get('content.cluster.status') === 'START FAILED'
  700. || this.get('content.cluster.status') === 'STARTED') {
  701. this.set('progress', '100');
  702. return true;
  703. }
  704. return false;
  705. },
  706. /**
  707. * @param polledData Josn data retrieved from API
  708. * @returns {bool} Has "Start All Services" request completed successfully
  709. * @method isServicesStarted
  710. */
  711. isServicesStarted: function (polledData) {
  712. var clusterStatus = {};
  713. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  714. this.set('progress', '100');
  715. clusterStatus = {
  716. status: 'INSTALLED',
  717. requestId: this.get('content.cluster.requestId'),
  718. isCompleted: true
  719. };
  720. if (this.isSuccess(polledData)) {
  721. clusterStatus.status = 'STARTED';
  722. var serviceStartTime = App.dateTime();
  723. clusterStatus.installTime = ((parseInt(serviceStartTime) - parseInt(this.get('content.cluster.installStartTime'))) / 60000).toFixed(2);
  724. }
  725. else {
  726. clusterStatus.status = 'START FAILED'; // 'START FAILED' implies to step10 that installation was successful but start failed
  727. }
  728. this.saveClusterStatus(clusterStatus);
  729. this.saveInstalledHosts(this);
  730. return true;
  731. }
  732. return false;
  733. },
  734. /**
  735. * @param polledData Josn data retrieved from API
  736. * @returns {bool} Has "Install All Services" request completed successfully
  737. * @method isServicesInstalled
  738. */
  739. isServicesInstalled: function (polledData) {
  740. var clusterStatus = {};
  741. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  742. clusterStatus = {
  743. status: 'PENDING',
  744. requestId: this.get('content.cluster.requestId'),
  745. isCompleted: false
  746. };
  747. if (this.get('status') === 'failed') {
  748. clusterStatus.status = 'INSTALL FAILED';
  749. this.saveClusterStatus(clusterStatus);
  750. this.set('progress', '100');
  751. this.get('hosts').forEach(function (host) {
  752. host.set('progress', '100');
  753. });
  754. this.isAllComponentsInstalled();
  755. } else {
  756. this.set('progress', '34');
  757. if (this.get('content.controllerName') === 'installerController') {
  758. this.isAllComponentsInstalled();
  759. } else {
  760. this.launchStartServices();
  761. }
  762. }
  763. this.saveInstalledHosts(this);
  764. return true;
  765. }
  766. return false;
  767. },
  768. /**
  769. * This is done at HostRole level.
  770. * @param {Ember.Enumerable} tasksPerHost
  771. * @param {Object} host
  772. * @method setLogTasksStatePerHost
  773. */
  774. setLogTasksStatePerHost: function (tasksPerHost, host) {
  775. tasksPerHost.forEach(function (_task) {
  776. var task = host.logTasks.findProperty('Tasks.id', _task.Tasks.id);
  777. if (task) {
  778. task.Tasks.status = _task.Tasks.status;
  779. task.Tasks.start_time = _task.Tasks.start_time;
  780. task.Tasks.end_time = _task.Tasks.end_time;
  781. task.Tasks.exit_code = _task.Tasks.exit_code;
  782. } else {
  783. host.logTasks.pushObject(_task);
  784. }
  785. }, this);
  786. },
  787. /**
  788. * Parses the Json data retrieved from API and sets the task on the host of {hosts} array binded to template
  789. * @param polledData Json data retrieved from API
  790. * @returns {bool} True if stage transition is completed.
  791. * On true, polling will be stopped.
  792. * @method parseHostInfo
  793. */
  794. parseHostInfo: function (polledData) {
  795. console.log('TRACE: Entering host info function');
  796. var self = this;
  797. var totalProgress = 0;
  798. var tasksData = polledData.tasks;
  799. console.log("The value of tasksData is: ", tasksData);
  800. var requestId = this.get('content.cluster.requestId');
  801. tasksData.setEach('Tasks.request_id', requestId);
  802. if (polledData.Requests && polledData.Requests.id && polledData.Requests.id != requestId) {
  803. // We don't want to use non-current requestId's tasks data to
  804. // determine the current install status.
  805. // Also, we don't want to keep polling if it is not the
  806. // current requestId.
  807. return false;
  808. }
  809. this.replacePolledData(tasksData);
  810. var tasksHostMap = {};
  811. tasksData.forEach(function (task) {
  812. if (tasksHostMap[task.Tasks.host_name]) {
  813. tasksHostMap[task.Tasks.host_name].push(task);
  814. } else {
  815. tasksHostMap[task.Tasks.host_name] = [task];
  816. }
  817. });
  818. this.get('hosts').forEach(function (_host) {
  819. var actionsPerHost = tasksHostMap[_host.name] || []; // retrieved from polled Data
  820. if (actionsPerHost.length === 0) {
  821. if (this.get('content.cluster.status') === 'PENDING' || this.get('content.cluster.status') === 'INSTALL FAILED') {
  822. _host.set('progress', '33');
  823. _host.set('isNoTasksForInstall', true);
  824. _host.set('status', 'pending');
  825. }
  826. if (this.get('content.cluster.status') === 'INSTALLED' || this.get('content.cluster.status') === 'FAILED') {
  827. _host.set('progress', '100');
  828. _host.set('status', 'success');
  829. }
  830. console.log("INFO: No task is hosted on the host");
  831. } else {
  832. _host.set('isNoTasksForInstall', false);
  833. }
  834. this.setLogTasksStatePerHost(actionsPerHost, _host);
  835. this.onSuccessPerHost(actionsPerHost, _host); // every action should be a success
  836. this.onErrorPerHost(actionsPerHost, _host); // any action should be a failure
  837. this.onInProgressPerHost(actionsPerHost, _host); // current running action for a host
  838. totalProgress += self.progressPerHost(actionsPerHost, _host);
  839. if (_host.get('progress') == '33' && _host.get('status') != 'failed' && _host.get('status') != 'warning') {
  840. _host.set('message', this.t('installer.step9.host.status.nothingToInstall'));
  841. _host.set('status', 'pending');
  842. }
  843. }, this);
  844. this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
  845. totalProgress = Math.floor(totalProgress / this.get('hosts.length'));
  846. this.set('progress', totalProgress.toString());
  847. console.log("INFO: right now the progress is: " + this.get('progress'));
  848. return this.finishState(tasksData);
  849. },
  850. /**
  851. * Starts polling to the API
  852. * @method startPolling
  853. */
  854. startPolling: function () {
  855. this.set('isSubmitDisabled', true);
  856. this.doPolling();
  857. },
  858. /**
  859. * This function calls API just once to fetch log data of all tasks.
  860. * @method loadLogData
  861. */
  862. loadLogData: function (startPolling) {
  863. var requestsId = this.get('wizardController').getDBProperty('cluster').oldRequestsId;
  864. if (App.testMode) {
  865. this.set('POLL_INTERVAL', 1);
  866. }
  867. this.getLogsByRequest(!!startPolling, requestsId[requestsId.length-1]);
  868. },
  869. /**
  870. * Load form server <code>stderr, stdout</code> of current open task
  871. * @method loadCurrentTaskLog
  872. */
  873. loadCurrentTaskLog: function () {
  874. var taskId = this.get('currentOpenTaskId');
  875. var requestId = this.get('currentOpenTaskRequestId');
  876. var clusterName = this.get('content.cluster.name');
  877. if (!taskId) {
  878. console.log('taskId is null.');
  879. return;
  880. }
  881. App.ajax.send({
  882. name: 'background_operations.get_by_task',
  883. sender: this,
  884. data: {
  885. 'taskId': taskId,
  886. 'requestId': requestId,
  887. 'clusterName': clusterName
  888. },
  889. success: 'loadCurrentTaskLogSuccessCallback',
  890. error: 'loadCurrentTaskLogErrorCallback'
  891. });
  892. },
  893. /**
  894. * success callback function for getting log data of the opened task
  895. * @param {object} data
  896. * @method loadCurrentTaskLogSuccessCallback
  897. */
  898. loadCurrentTaskLogSuccessCallback: function (data) {
  899. var taskId = this.get('currentOpenTaskId');
  900. if (taskId) {
  901. var host = this.get('hosts').findProperty('name', data.Tasks.host_name);
  902. if (host) {
  903. var currentTask = host.get('logTasks').findProperty('Tasks.id', data.Tasks.id);
  904. if (currentTask) {
  905. currentTask.Tasks.stderr = data.Tasks.stderr;
  906. currentTask.Tasks.stdout = data.Tasks.stdout;
  907. }
  908. }
  909. }
  910. this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
  911. },
  912. /**
  913. * Error callback function for getting log data of the opened task
  914. * @method loadCurrentTaskLogErrorCallback
  915. */
  916. loadCurrentTaskLogErrorCallback: function () {
  917. this.set('currentOpenTaskId', 0);
  918. },
  919. /**
  920. * Function polls the API to retrieve data for the request.
  921. * @param {bool} polling whether to continue polling for status or not
  922. * @param {number} requestId
  923. * @method getLogsByRequest
  924. * @return {$.ajax|null}
  925. */
  926. getLogsByRequest: function (polling, requestId) {
  927. return App.ajax.send({
  928. name: 'wizard.step9.load_log',
  929. sender: this,
  930. data: {
  931. polling: polling,
  932. cluster: this.get('content.cluster.name'),
  933. requestId: requestId,
  934. numPolls: this.get('numPolls')
  935. },
  936. success: 'getLogsByRequestSuccessCallback',
  937. error: 'getLogsByRequestErrorCallback'
  938. }).retry({times: App.maxRetries, timeout: 3000}).then(null,
  939. function () {
  940. App.showReloadPopup();
  941. console.log('Install services all retries failed');
  942. }
  943. );
  944. },
  945. /**
  946. * Success callback for get log by request
  947. * @param {object} data
  948. * @param {object} opt
  949. * @param {object} params
  950. * @method getLogsByRequestSuccessCallback
  951. */
  952. getLogsByRequestSuccessCallback: function (data, opt, params) {
  953. var self = this;
  954. var parsedData = jQuery.parseJSON(data);
  955. console.log("TRACE: In success function for the GET logs data");
  956. console.log("TRACE: Step9 -> The value is: ", parsedData);
  957. var result = this.parseHostInfo(parsedData);
  958. if (!params.polling) {
  959. if (this.get('content.cluster.status') === 'INSTALL FAILED') {
  960. this.isAllComponentsInstalled();
  961. }
  962. return;
  963. }
  964. if (result !== true) {
  965. window.setTimeout(function () {
  966. if (self.get('currentOpenTaskId')) {
  967. self.loadCurrentTaskLog();
  968. }
  969. self.doPolling();
  970. }, this.get('POLL_INTERVAL'));
  971. }
  972. },
  973. /**
  974. * Error-callback for get log by request
  975. * @method getLogsByRequestErrorCallback
  976. */
  977. getLogsByRequestErrorCallback: function () {
  978. this.loadLogData(true);
  979. },
  980. /**
  981. * Delegates the function call to {getLogsByRequest} with appropriate params
  982. * @method doPolling
  983. */
  984. doPolling: function () {
  985. var requestId = this.get('content.cluster.requestId');
  986. if (App.testMode) {
  987. this.incrementProperty('numPolls');
  988. }
  989. this.getLogsByRequest(true, requestId);
  990. },
  991. /**
  992. * Check that all components are in INSTALLED state before issuing start command
  993. * @method isAllComponentsInstalled
  994. * @return {$.ajax|null}
  995. */
  996. isAllComponentsInstalled: function () {
  997. if (this.get('content.controllerName') !== 'installerController') {
  998. return null;
  999. }
  1000. var name = 'wizard.step9.installer.get_host_status';
  1001. return App.ajax.send({
  1002. name: name,
  1003. sender: this,
  1004. data: {
  1005. cluster: this.get('content.cluster.name')
  1006. },
  1007. success: 'isAllComponentsInstalledSuccessCallback',
  1008. error: 'isAllComponentsInstalledErrorCallback'
  1009. });
  1010. },
  1011. /**
  1012. * Success callback function for API checking host state and host_components state.
  1013. * @param {Object} jsonData
  1014. * @method isAllComponentsInstalledSuccessCallback
  1015. */
  1016. isAllComponentsInstalledSuccessCallback: function (jsonData) {
  1017. var clusterStatus = {
  1018. status: 'INSTALL FAILED',
  1019. isStartError: true,
  1020. isCompleted: false
  1021. };
  1022. var hostsWithHeartbeatLost = [];
  1023. jsonData.items.filterProperty('Hosts.host_state', 'HEARTBEAT_LOST').forEach(function (host) {
  1024. var hostComponentObj = {hostName: host.Hosts.host_name};
  1025. var componentArr = [];
  1026. host.host_components.forEach(function (_hostComponent) {
  1027. var componentName = App.format.role(_hostComponent.HostRoles.component_name);
  1028. componentArr.pushObject(componentName);
  1029. }, this);
  1030. hostComponentObj.componentNames = this.getComponentMessage(componentArr);
  1031. hostsWithHeartbeatLost.pushObject(hostComponentObj);
  1032. }, this);
  1033. this.set('hostsWithHeartbeatLost', hostsWithHeartbeatLost);
  1034. if (hostsWithHeartbeatLost.length) {
  1035. this.get('hosts').forEach(function (host) {
  1036. if (hostsWithHeartbeatLost.someProperty(('hostName'), host.get('name'))) {
  1037. host.set('status', 'heartbeat_lost');
  1038. } else if (host.get('status') !== 'failed' && host.get('status') !== 'warning') {
  1039. host.set('message', Em.I18n.t('installer.step9.host.status.startAborted'));
  1040. }
  1041. host.set('progress', '100');
  1042. });
  1043. this.set('progress', '100');
  1044. this.saveClusterStatus(clusterStatus);
  1045. } else if (this.get('content.cluster.status') === 'PENDING') {
  1046. this.launchStartServices();
  1047. }
  1048. },
  1049. /**
  1050. * Error callback function for API checking host state and host_components state
  1051. * @method isAllComponentsInstalledErrorCallback
  1052. */
  1053. isAllComponentsInstalledErrorCallback: function () {
  1054. var clusterStatus = {
  1055. status: 'INSTALL FAILED',
  1056. isStartError: true,
  1057. isCompleted: false
  1058. };
  1059. this.set('progress', '100');
  1060. this.get('hosts').forEach(function (host) {
  1061. if (host.get('status') !== 'failed' && host.get('status') !== 'warning') {
  1062. host.set('message', Em.I18n.t('installer.step9.host.status.startAborted'));
  1063. host.set('progress', '100');
  1064. }
  1065. });
  1066. this.saveClusterStatus(clusterStatus);
  1067. },
  1068. /**
  1069. * Get formatted string of components to display on the UI
  1070. * @param componentArr {Array} Array of components
  1071. * @returns {String}
  1072. * @method getComponentMessage
  1073. */
  1074. getComponentMessage: function (componentArr) {
  1075. var label = '';
  1076. componentArr.forEach(function (_component) {
  1077. if (componentArr.length === 1) {
  1078. label = _component;
  1079. }
  1080. else {
  1081. if (_component !== componentArr[componentArr.length - 1]) { // [clients.length - 1]
  1082. label = label + ' ' + _component;
  1083. if (_component !== componentArr[componentArr.length - 2]) {
  1084. label = label + ',';
  1085. }
  1086. }
  1087. else {
  1088. label = label + ' ' + Em.I18n.t('and') + ' ' + _component;
  1089. }
  1090. }
  1091. }, this);
  1092. return label.trim();
  1093. },
  1094. /**
  1095. * save cluster status in the parentController and localdb
  1096. * @param {object} clusterStatus
  1097. * @method saveClusterStatus
  1098. */
  1099. saveClusterStatus: function (clusterStatus) {
  1100. if (!App.testMode) {
  1101. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  1102. }
  1103. else {
  1104. this.set('content.cluster', clusterStatus);
  1105. }
  1106. },
  1107. /**
  1108. * save cluster status in the parentController and localdb
  1109. * @param {object} context
  1110. * @method saveInstalledHosts
  1111. */
  1112. saveInstalledHosts: function (context) {
  1113. if (!App.testMode) {
  1114. App.router.get(this.get('content.controllerName')).saveInstalledHosts(context);
  1115. }
  1116. }
  1117. });