step9_controller.js 42 KB

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