step9_controller.js 32 KB

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