step9_controller.js 41 KB

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