step9_controller.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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. hosts: [],
  23. progress: '0',
  24. isStepCompleted: false,
  25. isSubmitDisabled: function () {
  26. var validStates = ['STARTED','START FAILED'];
  27. var controllerName = this.get('content.controllerName');
  28. if (controllerName == 'addHostController' || controllerName == 'addServiceController') {
  29. validStates.push('INSTALL FAILED');
  30. }
  31. return !validStates.contains(this.get('content.cluster.status'));
  32. }.property('content.cluster.status'),
  33. // links to previous steps are enabled iff install failed in installer
  34. togglePreviousSteps: function () {
  35. if ('INSTALL FAILED' === this.get('content.cluster.status') && this.get('content.controllerName') == 'installerController') {
  36. App.router.get('installerController').setStepsEnable();
  37. } else {
  38. App.router.get('installerController').setLowerStepsDisable(9);
  39. }
  40. }.observes('content.cluster.status', 'content.controllerName'),
  41. mockDataPrefix: '/data/wizard/deploy/5_hosts',
  42. pollDataCounter: 0,
  43. polledData: [],
  44. numPolls: 1,
  45. POLL_INTERVAL: 4000,
  46. visibleHosts: [],
  47. status: 'info',
  48. showRetry: function () {
  49. return this.get('content.cluster.status') == 'INSTALL FAILED';
  50. }.property('content.cluster.status'),
  51. categoryObject: Em.Object.extend({
  52. hostsCount: function () {
  53. var category = this;
  54. var hosts = this.get('controller.hosts').filter(function(_host) {
  55. if(category.get('hostStatus') == 'inProgress'){ // queued, pending, in_progress map to inProgress
  56. return (_host.get('status') !== 'success' && _host.get('status') !== 'failed' && _host.get('status') !== 'warning');
  57. }
  58. return (_host.get('status') == category.get('hostStatus'));
  59. }, this);
  60. return hosts.get('length');
  61. }.property('controller.hosts.@each.status'),
  62. label: function () {
  63. return "%@ (%@)".fmt(this.get('value'), this.get('hostsCount'));
  64. }.property('value', 'hostsCount')
  65. }),
  66. categories: function () {
  67. var self = this;
  68. self.categoryObject.reopen({
  69. controller: self,
  70. isActive: function(){
  71. return this.get('controller.category') == this;
  72. }.property('controller.category'),
  73. itemClass: function(){
  74. return this.get('isActive') ? 'active' : '';
  75. }.property('isActive')
  76. });
  77. var categories = [
  78. self.categoryObject.create({value: Em.I18n.t('common.all'), hostStatus:'all', hostsCount: function () {
  79. return this.get('controller.hosts.length');
  80. }.property('controller.hosts.length') }),
  81. self.categoryObject.create({value: Em.I18n.t('installer.step9.hosts.status.label.inProgress'), hostStatus: 'inProgress'}),
  82. self.categoryObject.create({value: Em.I18n.t('installer.step9.hosts.status.label.warning'), hostStatus: 'warning'}),
  83. self.categoryObject.create({value: Em.I18n.t('common.success'), hostStatus: 'success'}),
  84. self.categoryObject.create({value: Em.I18n.t('common.fail'), hostStatus: 'failed', last: true })
  85. ];
  86. this.set('category', categories.get('firstObject'));
  87. return categories;
  88. }.property(),
  89. category: false,
  90. hostStatusObserver: function(){
  91. Ember.run.once(this, 'hostStatusUpdates');
  92. }.observes('hosts.@each.status'),
  93. hostStatusUpdates: function () {
  94. this.updateVisibleHosts();
  95. this.updateStatus();
  96. },
  97. updateVisibleHosts: function () {
  98. var targetStatus = this.get('category.hostStatus');
  99. var visibleHosts = (targetStatus === 'all') ? this.get('hosts') : this.get('hosts').filter(function (_host) {
  100. if (targetStatus == 'inProgress') { // queued, pending, in_progress map to inProgress
  101. return (_host.get('status') !== 'success' && _host.get('status') !== 'failed' && _host.get('status') !== 'warning');
  102. }
  103. return (_host.get('status') == targetStatus);
  104. }, this);
  105. this.set('visibleHosts', visibleHosts);
  106. }.observes('category'),
  107. updateStatus: function () {
  108. var status = 'info';
  109. if (this.get('hosts').someProperty('status', 'failed')) {
  110. status = 'failed';
  111. } else if (this.get('hosts').someProperty('status', 'warning')) {
  112. if (this.isStepFailed()) {
  113. status = 'failed';
  114. } else {
  115. status = 'warning';
  116. }
  117. } else if (this.get('progress') == '100') {
  118. this.set('isStepCompleted', true);
  119. status = 'success';
  120. }
  121. this.set('status', status);
  122. }.observes('progress'),
  123. logTasksChangesCounter: 0,
  124. selectCategory: function(event){
  125. this.set('category', event.context);
  126. },
  127. getCategory: function(field, value){
  128. return this.get('categories').find(function(item){
  129. return item.get(field) == value;
  130. });
  131. },
  132. // content.cluster.status can be:
  133. // PENDING: set upon successful transition from step 1 to step 2
  134. // INSTALLED: set upon successful completion of install phase as well as successful invocation of start services API
  135. // STARTED: set up on successful completion of start phase
  136. // INSTALL FAILED: set up upon encountering a failure in install phase
  137. // START FAILED: set upon unsuccessful invocation of start services API and also upon encountering a failure
  138. // during start phase
  139. // content.cluster.isCompleted
  140. // set to false upon successful transition from step 1 to step 2
  141. // set to true upon successful start of services in this step
  142. // note: looks like this is the same thing as checking content.cluster.status == 'STARTED'
  143. // navigateStep is called by App.WizardStep9View's didInsertElement and "retry" from router.
  144. navigateStep: function () {
  145. if (App.testMode) {
  146. // this is for repeatedly testing out installs in test mode
  147. this.set('content.cluster.status', 'PENDING');
  148. this.set('content.cluster.isCompleted', false);
  149. this.set('content.cluster.requestId',1);
  150. }
  151. var clusterStatus = this.get('content.cluster.status');
  152. console.log('navigateStep: clusterStatus = ' + clusterStatus);
  153. if (this.get('content.cluster.isCompleted') === false) {
  154. // the cluster has not yet successfully installed and started
  155. if (clusterStatus === 'INSTALL FAILED') {
  156. this.loadStep();
  157. this.loadLogData(this.get('content.cluster.requestId'));
  158. this.set('isStepCompleted', true);
  159. } else if (clusterStatus === 'START FAILED') {
  160. this.loadStep();
  161. this.loadLogData(this.get('content.cluster.requestId'));
  162. // this.hosts.setEach('status', 'info');
  163. this.set('isStepCompleted', true);
  164. } else {
  165. // handle PENDING, INSTALLED
  166. this.loadStep();
  167. this.loadLogData(this.get('content.cluster.requestId'));
  168. this.startPolling();
  169. }
  170. } else {
  171. // handle STARTED
  172. // the cluster has successfully installed and started
  173. this.loadStep();
  174. this.loadLogData(this.get('content.cluster.requestId'));
  175. this.set('isStepCompleted', true);
  176. this.set('progress', '100');
  177. }
  178. },
  179. clearStep: function () {
  180. this.get('hosts').clear();
  181. this.set('status', 'info');
  182. this.set('progress', '0');
  183. this.set('isStepCompleted', false);
  184. this.set('numPolls', 1);
  185. },
  186. loadStep: function () {
  187. console.log("TRACE: Loading step9: Install, Start and Test");
  188. this.clearStep();
  189. this.loadHosts();
  190. },
  191. /**
  192. * reset status and message of all hosts when retry install
  193. */
  194. resetHostsForRetry: function(){
  195. var hosts = this.get('content.hosts');
  196. for (var name in hosts) {
  197. hosts[name].status = "pending";
  198. hosts[name].message = 'Waiting';
  199. }
  200. this.set('content.hosts', hosts);
  201. },
  202. loadHosts: function () {
  203. var hosts = this.get('content.hosts');
  204. for (var index in hosts) {
  205. if (hosts[index].bootStatus === 'REGISTERED') {
  206. var hostInfo = App.HostInfo.create({
  207. name: hosts[index].name,
  208. status: (hosts[index].status) ? hosts[index].status : 'info',
  209. tasks: [],
  210. logTasks: [],
  211. message: (hosts[index].message) ? hosts[index].message : 'Waiting',
  212. progress: 0
  213. });
  214. this.get('hosts').pushObject(hostInfo);
  215. }
  216. }
  217. },
  218. replacePolledData: function (polledData) {
  219. this.polledData.clear();
  220. this.set('polledData', polledData);
  221. },
  222. displayMessage: function (task) {
  223. var role = App.format.role(task.role);
  224. switch (task.command) {
  225. case 'INSTALL':
  226. switch (task.status) {
  227. case 'PENDING':
  228. return Em.I18n.t('installer.step9.serviceStatus.install.pending') + role;
  229. case 'QUEUED' :
  230. return Em.I18n.t('installer.step9.serviceStatus.install.queued') + role;
  231. case 'IN_PROGRESS':
  232. return Em.I18n.t('installer.step9.serviceStatus.install.inProgress') + role;
  233. case 'COMPLETED' :
  234. return Em.I18n.t('installer.step9.serviceStatus.install.completed') + role;
  235. case 'FAILED':
  236. return Em.I18n.t('installer.step9.serviceStatus.install.failed') + role;
  237. }
  238. case 'UNINSTALL':
  239. switch (task.status) {
  240. case 'PENDING':
  241. return Em.I18n.t('installer.step9.serviceStatus.uninstall.pending') + role;
  242. case 'QUEUED' :
  243. return Em.I18n.t('installer.step9.serviceStatus.uninstall.queued') + role;
  244. case 'IN_PROGRESS':
  245. return Em.I18n.t('installer.step9.serviceStatus.uninstall.inProgress') + role;
  246. case 'COMPLETED' :
  247. return Em.I18n.t('installer.step9.serviceStatus.uninstall.completed') + role;
  248. case 'FAILED':
  249. return Em.I18n.t('installer.step9.serviceStatus.uninstall.failed') + role;
  250. }
  251. case 'START' :
  252. switch (task.status) {
  253. case 'PENDING':
  254. return Em.I18n.t('installer.step9.serviceStatus.start.pending') + role;
  255. case 'QUEUED' :
  256. return Em.I18n.t('installer.step9.serviceStatus.start.queued') + role;
  257. case 'IN_PROGRESS':
  258. return Em.I18n.t('installer.step9.serviceStatus.start.inProgress') + role;
  259. case 'COMPLETED' :
  260. return role + Em.I18n.t('installer.step9.serviceStatus.start.completed');
  261. case 'FAILED':
  262. return role + Em.I18n.t('installer.step9.serviceStatus.start.failed');
  263. }
  264. case 'STOP' :
  265. switch (task.status) {
  266. case 'PENDING':
  267. return Em.I18n.t('installer.step9.serviceStatus.stop.pending') + role;
  268. case 'QUEUED' :
  269. return Em.I18n.t('installer.step9.serviceStatus.stop.queued') + role;
  270. case 'IN_PROGRESS':
  271. return Em.I18n.t('installer.step9.serviceStatus.stop.inProgress') + role;
  272. case 'COMPLETED' :
  273. return role + Em.I18n.t('installer.step9.serviceStatus.stop.completed');
  274. case 'FAILED':
  275. return role + Em.I18n.t('installer.step9.serviceStatus.stop.failed');
  276. }
  277. case 'EXECUTE' :
  278. case 'SERVICE_CHECK' :
  279. switch (task.status) {
  280. case 'PENDING':
  281. return Em.I18n.t('installer.step9.serviceStatus.execute.pending') + role;
  282. case 'QUEUED' :
  283. return Em.I18n.t('installer.step9.serviceStatus.execute.queued') + role;
  284. case 'IN_PROGRESS':
  285. return Em.I18n.t('installer.step9.serviceStatus.execute.inProgress') + role;
  286. case 'COMPLETED' :
  287. return role + Em.I18n.t('installer.step9.serviceStatus.execute.completed');
  288. case 'FAILED':
  289. return role + Em.I18n.t('installer.step9.serviceStatus.execute.failed');
  290. }
  291. case 'ABORT' :
  292. switch (task.status) {
  293. case 'PENDING':
  294. return Em.I18n.t('installer.step9.serviceStatus.abort.pending') + role;
  295. case 'QUEUED' :
  296. return Em.I18n.t('installer.step9.serviceStatus.abort.queued') + role;
  297. case 'IN_PROGRESS':
  298. return Em.I18n.t('installer.step9.serviceStatus.abort.inProgress') + role;
  299. case 'COMPLETED' :
  300. return role + Em.I18n.t('installer.step9.serviceStatus.abort.completed');
  301. case 'FAILED':
  302. return role + Em.I18n.t('installer.step9.serviceStatus.abort.failed');
  303. }
  304. }
  305. return '';
  306. },
  307. /**
  308. * run start/check services after installation phase
  309. */
  310. launchStartServices: function () {
  311. var data = {
  312. "RequestInfo": {
  313. "context": Em.I18n.t("requestInfo.startServices")
  314. },
  315. "Body": {
  316. "ServiceInfo": { "state": "STARTED" }
  317. }
  318. };
  319. var name = 'wizard.step9.installer.launch_start_services';
  320. if (this.get('content.controllerName') === 'addHostController') {
  321. var hostnames = [];
  322. for (var hostname in this.get('wizardController').getDBProperty('hosts')) {
  323. hostnames.push(hostname);
  324. }
  325. data = {
  326. "RequestInfo": {
  327. "context": Em.I18n.t("requestInfo.startHostComponents"),
  328. "query": "HostRoles/component_name.in(GANGLIA_MONITOR,HBASE_REGIONSERVER,DATANODE,TASKTRACKER,NODEMANAGER)&HostRoles/state=INSTALLED&HostRoles/host_name.in(" + hostnames.join(',') + ")"
  329. },
  330. "Body": {
  331. "HostRoles": { "state": "STARTED" }
  332. }
  333. };
  334. name = 'wizard.step9.add_host.launch_start_services';
  335. }
  336. data = JSON.stringify(data);
  337. if (App.testMode) {
  338. this.set('numPolls', 6);
  339. }
  340. App.ajax.send({
  341. name: name,
  342. sender: this,
  343. data: {
  344. data: data,
  345. cluster: this.get('content.cluster.name')
  346. },
  347. success: 'launchStartServicesSuccessCallback',
  348. error: 'launchStartServicesErrorCallback'
  349. });
  350. },
  351. launchStartServicesSuccessCallback: function (jsonData) {
  352. var clusterStatus = {};
  353. if (jsonData) {
  354. console.log("TRACE: Step9 -> In success function for the startService call");
  355. console.log("TRACE: Step9 -> value of the received data is: " + jsonData);
  356. var requestId = jsonData.Requests.id;
  357. console.log('requestId is: ' + requestId);
  358. clusterStatus = {
  359. status: 'INSTALLED',
  360. requestId: requestId,
  361. isStartError: false,
  362. isCompleted: false
  363. };
  364. this.hostHasClientsOnly(false);
  365. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  366. } else {
  367. console.log('ERROR: Error occurred in parsing JSON data');
  368. this.hostHasClientsOnly(true);
  369. clusterStatus = {
  370. status: 'STARTED',
  371. isStartError: false,
  372. isCompleted: true
  373. };
  374. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  375. this.set('status', 'success');
  376. this.set('progress', '100');
  377. this.set('isStepCompleted', true);
  378. }
  379. // We need to do recovery if there is a browser crash
  380. App.clusterStatus.setClusterStatus({
  381. clusterState: 'SERVICE_STARTING_3',
  382. wizardControllerName: this.get('content.controllerName'),
  383. localdb: App.db.data
  384. });
  385. if(jsonData) {
  386. this.startPolling();
  387. }
  388. },
  389. hostHasClientsOnly: function(jsonError) {
  390. this.get('hosts').forEach(function(host){
  391. var OnlyClients = true;
  392. var tasks = host.get('logTasks');
  393. tasks.forEach(function(task){
  394. var component = serviceComponents.findProperty('component_name',task.Tasks.role);
  395. if(!(component && component.isClient)) {
  396. OnlyClients = false;
  397. }
  398. });
  399. if (OnlyClients || jsonError) {
  400. host.set('status', 'success');
  401. host.set('progress', '100');
  402. }
  403. });
  404. },
  405. launchStartServicesErrorCallback: function () {
  406. console.log("ERROR");
  407. var clusterStatus = {
  408. status: 'START FAILED',
  409. isStartError: true,
  410. isCompleted: false
  411. };
  412. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  413. },
  414. // marks a host's status as "success" if all tasks are in COMPLETED state
  415. onSuccessPerHost: function (actions, contentHost) {
  416. if (actions.everyProperty('Tasks.status', 'COMPLETED') && this.get('content.cluster.status') === 'INSTALLED') {
  417. contentHost.set('status', 'success');
  418. }
  419. },
  420. // 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.
  421. // 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
  422. // to find which host FAILED occurred on, if any
  423. onErrorPerHost: function (actions, contentHost) {
  424. if (!actions) return;
  425. if (actions.someProperty('Tasks.status', 'FAILED') || actions.someProperty('Tasks.status', 'ABORTED') || actions.someProperty('Tasks.status', 'TIMEDOUT')) {
  426. contentHost.set('status', 'warning');
  427. }
  428. if ((this.get('content.cluster.status') === 'PENDING' && actions.someProperty('Tasks.status', 'FAILED')) || (this.isMasterFailed(actions))) {
  429. contentHost.set('status', 'failed');
  430. }
  431. },
  432. //return true if there is at least one FAILED task of master component install
  433. isMasterFailed: function(polledData) {
  434. var result = false;
  435. polledData.filterProperty('Tasks.command', 'INSTALL').filterProperty('Tasks.status', 'FAILED').mapProperty('Tasks.role').forEach (
  436. function (task) {
  437. if (!['DATANODE', 'TASKTRACKER', 'HBASE_REGIONSERVER', 'GANGLIA_MONITOR'].contains(task)) {
  438. result = true;
  439. }
  440. }
  441. );
  442. return result;
  443. },
  444. onInProgressPerHost: function (actions, contentHost) {
  445. var runningAction = actions.findProperty('Tasks.status', 'IN_PROGRESS');
  446. if (runningAction === undefined || runningAction === null) {
  447. runningAction = actions.findProperty('Tasks.status', 'QUEUED');
  448. }
  449. if (runningAction === undefined || runningAction === null) {
  450. runningAction = actions.findProperty('Tasks.status', 'PENDING');
  451. }
  452. if (runningAction !== null && runningAction !== undefined) {
  453. contentHost.set('status', 'in_progress');
  454. contentHost.set('message', this.displayMessage(runningAction.Tasks));
  455. }
  456. },
  457. /**
  458. * calculate progress of tasks per host
  459. * @param actions
  460. * @param contentHost
  461. * @return {Number}
  462. */
  463. progressPerHost: function (actions, contentHost) {
  464. var progress = 0;
  465. var actionsPerHost = actions.length;
  466. var completedActions = 0;
  467. var queuedActions = 0;
  468. var inProgressActions = 0;
  469. actions.forEach(function (action) {
  470. completedActions += +(['COMPLETED', 'FAILED', 'ABORTED', 'TIMEDOUT'].contains(action.Tasks.status));
  471. queuedActions += +(action.Tasks.status === 'QUEUED');
  472. inProgressActions += +(action.Tasks.status === 'IN_PROGRESS');
  473. }, this);
  474. /** for the install phase (PENDING), % completed per host goes up to 33%; floor(100 / 3)
  475. * for the start phase (INSTALLED), % completed starts from 34%
  476. * when task in queued state means it's completed on 9%
  477. * in progress - 35%
  478. * completed - 100%
  479. */
  480. switch (this.get('content.cluster.status')) {
  481. case 'PENDING':
  482. progress = actionsPerHost?(Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 33)):33;
  483. break;
  484. case 'INSTALLED':
  485. progress = actionsPerHost?(34 + Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 66)):100;
  486. break;
  487. default:
  488. progress = 100;
  489. break;
  490. }
  491. contentHost.set('progress', progress.toString());
  492. return progress;
  493. },
  494. isSuccess: function (polledData) {
  495. return polledData.everyProperty('Tasks.status', 'COMPLETED');
  496. },
  497. /**
  498. * return true if:
  499. * 1. any of the master/client components failed to install
  500. * OR
  501. * 2. at least 50% of the slave host components for the particular service component fails to install
  502. */
  503. isStepFailed: function () {
  504. var failed = false;
  505. var polledData = this.get('polledData');
  506. polledData.filterProperty('Tasks.command', 'INSTALL').mapProperty('Tasks.role').uniq().forEach(function (role) {
  507. if (failed) {
  508. return;
  509. }
  510. var actionsPerRole = polledData.filterProperty('Tasks.role', role);
  511. if (['DATANODE', 'TASKTRACKER', 'HBASE_REGIONSERVER', 'GANGLIA_MONITOR'].contains(role)) {
  512. // check slave components for success factor.
  513. // partial failure for slave components are allowed.
  514. var actionsFailed = actionsPerRole.filterProperty('Tasks.status', 'FAILED');
  515. var actionsAborted = actionsPerRole.filterProperty('Tasks.status', 'ABORTED');
  516. var actionsTimedOut = actionsPerRole.filterProperty('Tasks.status', 'TIMEDOUT');
  517. if ((((actionsFailed.length + actionsAborted.length + actionsTimedOut.length) / actionsPerRole.length) * 100) > 50) {
  518. failed = true;
  519. }
  520. } else if (actionsPerRole.someProperty('Tasks.status', 'FAILED') || actionsPerRole.someProperty('Tasks.status', 'ABORTED') ||
  521. actionsPerRole.someProperty('Tasks.status', 'TIMEDOUT')) {
  522. // check non-salve components (i.e., masters and clients). all of these must be successfully installed.
  523. failed = true;
  524. }
  525. }, this);
  526. return failed;
  527. },
  528. // makes a state transition
  529. // PENDING -> INSTALLED
  530. // PENDING -> INSTALL FAILED
  531. // INSTALLED -> STARTED
  532. // INSTALLED -> START_FAILED
  533. // returns true if polling should stop; false otherwise
  534. // polling from ui stops only when no action has 'PENDING', 'QUEUED' or 'IN_PROGRESS' status
  535. finishState: function (polledData) {
  536. if (this.get('content.cluster.status') === 'INSTALLED') {
  537. return this.finishStateInstalled(polledData);
  538. }
  539. else
  540. if (this.get('content.cluster.status') === 'PENDING') {
  541. return this.finishStatePending(polledData);
  542. }
  543. else
  544. if (this.get('content.cluster.status') === 'INSTALL FAILED' ||
  545. this.get('content.cluster.status') === 'START FAILED' ||
  546. this.get('content.cluster.status') === 'STARTED') {
  547. this.set('progress', '100');
  548. return true;
  549. }
  550. return false;
  551. },
  552. finishStateInstalled: function(polledData) {
  553. var clusterStatus = {};
  554. if (!polledData.someProperty('Tasks.status', 'PENDING') &&
  555. !polledData.someProperty('Tasks.status', 'QUEUED') &&
  556. !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  557. this.set('progress', '100');
  558. clusterStatus = {
  559. status: 'INSTALLED',
  560. requestId: this.get('content.cluster.requestId'),
  561. isCompleted: true
  562. };
  563. if (this.isSuccess(polledData)) {
  564. clusterStatus.status = 'STARTED';
  565. var serviceStartTime = new Date().getTime();
  566. clusterStatus.installTime = ((parseInt(serviceStartTime) - parseInt(this.get('content.cluster.installStartTime'))) / 60000).toFixed(2);
  567. } else {
  568. clusterStatus.status = 'START FAILED'; // 'START FAILED' implies to step10 that installation was successful but start failed
  569. }
  570. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  571. this.set('isStepCompleted', true);
  572. this.setTasksPerHost();
  573. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  574. return true;
  575. }
  576. return false;
  577. },
  578. finishStatePending: function(polledData) {
  579. var clusterStatus = {};
  580. if (!polledData.someProperty('Tasks.status', 'PENDING') &&
  581. !polledData.someProperty('Tasks.status', 'QUEUED') &&
  582. !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  583. clusterStatus = {
  584. status: 'PENDING',
  585. requestId: this.get('content.cluster.requestId'),
  586. isCompleted: false
  587. };
  588. if (this.get('status') === 'failed') {
  589. clusterStatus.status = 'INSTALL FAILED';
  590. this.set('progress', '100');
  591. this.get('hosts').forEach(function(host){
  592. host.get('status') != 'failed' ? host.set('message',Em.I18n.t('installer.step9.host.status.startAborted')) : null;
  593. host.set('progress','100');
  594. });
  595. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  596. this.set('isStepCompleted', true);
  597. } else {
  598. clusterStatus.status = 'INSTALLED';
  599. this.set('progress', '34');
  600. this.launchStartServices();
  601. }
  602. this.setTasksPerHost();
  603. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  604. return true;
  605. }
  606. return false;
  607. },
  608. setTasksPerHost: function () {
  609. var tasksData = this.get('polledData');
  610. this.get('hosts').forEach(function (_host) {
  611. var tasksPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
  612. if (tasksPerHost !== null && tasksPerHost !== undefined && tasksPerHost.length !== 0) {
  613. tasksPerHost.forEach(function (_taskPerHost) {
  614. _host.tasks.pushObject(_taskPerHost);
  615. }, this);
  616. }
  617. }, this);
  618. },
  619. // This is done at HostRole level.
  620. setLogTasksStatePerHost: function (tasksPerHost, host) {
  621. tasksPerHost.forEach(function (_task) {
  622. var task = host.logTasks.findProperty('Tasks.id', _task.Tasks.id);
  623. if (task) {
  624. task.Tasks.status = _task.Tasks.status;
  625. task.Tasks.exit_code = _task.Tasks.exit_code;
  626. } else {
  627. host.logTasks.pushObject(_task);
  628. }
  629. }, this);
  630. },
  631. parseHostInfo: function (polledData) {
  632. console.log('TRACE: Entering host info function');
  633. var self = this;
  634. var totalProgress = 0;
  635. var tasksData = polledData.tasks;
  636. console.log("The value of tasksData is: ", tasksData);
  637. if (!tasksData) {
  638. console.log("Step9: ERROR: NO tasks available to process");
  639. }
  640. var requestId = this.get('content.cluster.requestId');
  641. tasksData.setEach('Tasks.request_id', requestId);
  642. if(polledData.Requests && polledData.Requests.id && polledData.Requests.id!=requestId){
  643. // We don't want to use non-current requestId's tasks data to
  644. // determine the current install status.
  645. // Also, we don't want to keep polling if it is not the
  646. // current requestId.
  647. return false;
  648. }
  649. this.replacePolledData(tasksData);
  650. var tasksHostMap = {};
  651. tasksData.forEach(function(task){
  652. if(tasksHostMap[task.Tasks.host_name]) {
  653. tasksHostMap[task.Tasks.host_name].push(task);
  654. } else {
  655. tasksHostMap[task.Tasks.host_name] = [task];
  656. }
  657. });
  658. this.get('hosts').forEach(function (_host) {
  659. var actionsPerHost = tasksHostMap[_host.name] || []; // retrieved from polled Data
  660. if (actionsPerHost.length === 0) {
  661. if(this.get('content.cluster.status') === 'PENDING') {
  662. _host.set('progress', '33');
  663. _host.set('status', 'pending');
  664. }
  665. if(this.get('content.cluster.status') === 'INSTALLED' || this.get('content.cluster.status') === 'FAILED') {
  666. _host.set('progress', '100');
  667. _host.set('status', 'success');
  668. }
  669. console.log("INFO: No task is hosted on the host");
  670. }
  671. this.setLogTasksStatePerHost(actionsPerHost, _host);
  672. this.onSuccessPerHost(actionsPerHost, _host); // every action should be a success
  673. this.onErrorPerHost(actionsPerHost, _host); // any action should be a failure
  674. this.onInProgressPerHost(actionsPerHost, _host); // current running action for a host
  675. totalProgress += self.progressPerHost(actionsPerHost, _host);
  676. if (_host.get('progress') == '33' && _host.get('status') != 'failed' && _host.get('status') != 'warning') {
  677. _host.set('message', this.t('installer.step9.host.status.nothingToInstall'));
  678. _host.set('status', 'pending');
  679. }
  680. }, this);
  681. this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
  682. totalProgress = Math.floor(totalProgress / this.get('hosts.length'));
  683. this.set('progress', totalProgress.toString());
  684. console.log("INFO: right now the progress is: " + this.get('progress'));
  685. return this.finishState(tasksData);
  686. },
  687. startPolling: function () {
  688. this.set('isSubmitDisabled', true);
  689. this.doPolling();
  690. },
  691. getUrl: function (requestId) {
  692. var clusterName = this.get('content.cluster.name');
  693. var requestId = requestId || this.get('content.cluster.requestId');
  694. var url = App.apiPrefix + '/clusters/' + clusterName + '/requests/' + requestId + '?fields=tasks/Tasks/command,tasks/Tasks/exit_code,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status&minimal_response=true';
  695. console.log("URL for step9 is: " + url);
  696. return url;
  697. },
  698. loadLogData: function(requestId) {
  699. var url = this.getUrl(requestId);
  700. var requestsId = this.get('wizardController').getDBProperty('cluster').oldRequestsId;
  701. if (App.testMode) {
  702. this.POLL_INTERVAL = 1;
  703. }
  704. requestsId.forEach(function(requestId) {
  705. url = this.getUrl(requestId);
  706. if (App.testMode) {
  707. this.POLL_INTERVAL = 1;
  708. url = this.get('mockDataPrefix') + '/poll_' + this.numPolls + '.json';
  709. }
  710. this.getLogsByRequest(url, false);
  711. }, this);
  712. },
  713. /**
  714. * {Number}
  715. * <code>taskId</code> of current open task
  716. */
  717. currentOpenTaskId: 0,
  718. /**
  719. * {Number}
  720. * <code>requestId</code> of current open task
  721. */
  722. currentOpenTaskRequestId: 0,
  723. /**
  724. * {Object}
  725. * Log of current open task (loaded from server)
  726. * Fields: {
  727. * stdout: '',
  728. * stderr: ''
  729. * }
  730. */
  731. currentOpenTaskLog: null,
  732. /**
  733. * Load form server <code>stderr, stdout</code> of current open task
  734. */
  735. loadCurrentTaskLog: function() {
  736. var taskId = this.get('currentOpenTaskId');
  737. var requestId = this.get('currentOpenTaskRequestId');
  738. var clusterName = this.get('content.cluster.name');
  739. if (!taskId) {
  740. console.log('taskId is null.');
  741. return;
  742. }
  743. App.ajax.send({
  744. name: 'background_operations.get_by_task',
  745. sender: this,
  746. data: {
  747. 'taskId': taskId,
  748. 'requestId': requestId,
  749. 'clusterName': clusterName,
  750. 'sync': true
  751. },
  752. success: 'loadCurrentTaskLogSuccessCallback',
  753. error: 'loadCurrentTaskLogErrorCallback'
  754. });
  755. },
  756. loadCurrentTaskLogSuccessCallback: function(data) {
  757. this.set('currentOpenTaskLog', {
  758. stdout: data.Tasks.stdout,
  759. stderr: data.Tasks.stderr
  760. });
  761. var taskId = this.get('currentOpenTaskId');
  762. if (taskId) {
  763. var currentTask = this.get('polledData').findProperty('Tasks.id', taskId);
  764. var log = this.get('currentOpenTaskLog');
  765. if (currentTask && log) {
  766. currentTask.Tasks.stderr = data.Tasks.stderr;
  767. currentTask.Tasks.stdout = data.Tasks.stdout;
  768. this.updateHostLogTask(data.Tasks.host_name, data.Tasks.id, data.Tasks.stderr, data.Tasks.stdout);
  769. }
  770. }
  771. this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
  772. },
  773. loadCurrentTaskLogErrorCallback: function() {
  774. this.set('currentOpenTaskId', 0);
  775. this.set('currentOpenTaskRequestId', 0);
  776. },
  777. /**
  778. * Update log task for provided host
  779. * @param {String} hostName
  780. * @param {Number} taskId
  781. * @param {String} stderr
  782. * @param {String} stdout
  783. */
  784. updateHostLogTask: function(hostName, taskId, stderr, stdout) {
  785. var logTask = this.get('hosts').findProperty('name', hostName).get('logTasks').findProperty('Tasks.id', taskId);
  786. if (logTask) {
  787. logTask.Tasks.stderr = stderr;
  788. logTask.Tasks.stdout = stdout;
  789. }
  790. },
  791. // polling: whether to continue polling for status or not
  792. getLogsByRequest: function(url, polling){
  793. var self = this;
  794. $.ajax({
  795. type: 'GET',
  796. url: url,
  797. async: true,
  798. timeout: App.timeout,
  799. dataType: 'text',
  800. success: function (data) {
  801. var parsedData = jQuery.parseJSON(data);
  802. console.log("TRACE: In success function for the GET logs data");
  803. console.log("TRACE: Step9 -> The value is: ", parsedData);
  804. var result = self.parseHostInfo(parsedData);
  805. if (!polling) {
  806. return;
  807. }
  808. if (result !== true) {
  809. window.setTimeout(function () {
  810. if (self.get('currentOpenTaskId')) {
  811. self.loadCurrentTaskLog();
  812. }
  813. self.doPolling();
  814. }, self.POLL_INTERVAL);
  815. } else {
  816. self.stopPolling();
  817. }
  818. },
  819. error: function (request, ajaxOptions, error) {
  820. console.log("TRACE: STep9 -> In error function for the GET logs data");
  821. console.log("TRACE: STep9 -> value of the url is: " + url);
  822. console.log("TRACE: STep9 -> error code status is: " + request.status);
  823. self.stopPolling();
  824. },
  825. statusCode: require('data/statusCodes')
  826. }).retry({times: App.maxRetries, timeout: App.timeout}).then(null,
  827. function () {
  828. App.showReloadPopup();
  829. console.log('Install services all retries failed');
  830. }
  831. );
  832. },
  833. doPolling: function () {
  834. var url = this.getUrl();
  835. if (App.testMode) {
  836. this.numPolls++;
  837. url = this.get('mockDataPrefix') + '/poll_' + this.get('numPolls') + '.json';
  838. }
  839. this.getLogsByRequest(url, true);
  840. },
  841. stopPolling: function () {
  842. //TODO: uncomment following line after the hook up with the API call
  843. // this.set('isStepCompleted',true);
  844. },
  845. submit: function () {
  846. if (!this.get('isSubmitDisabled')) {
  847. App.router.send('next');
  848. }
  849. },
  850. back: function () {
  851. if (!this.get('isSubmitDisabled')) {
  852. App.router.send('back');
  853. }
  854. }
  855. });