step9_controller.js 31 KB

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