step9_controller.js 40 KB

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