step9_controller.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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. }
  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. this.get('hosts').pushObject(hostInfo);
  223. }, this);
  224. },
  225. replacePolledData: function (polledData) {
  226. this.polledData.clear();
  227. this.set('polledData', polledData);
  228. },
  229. displayMessage: function (task) {
  230. var role = App.format.role(task.role);
  231. switch (task.command) {
  232. case 'INSTALL':
  233. switch (task.status) {
  234. case 'PENDING':
  235. return Em.I18n.t('installer.step9.serviceStatus.install.pending') + role;
  236. case 'QUEUED' :
  237. return Em.I18n.t('installer.step9.serviceStatus.install.queued') + role;
  238. case 'IN_PROGRESS':
  239. return Em.I18n.t('installer.step9.serviceStatus.install.inProgress') + role;
  240. case 'COMPLETED' :
  241. return Em.I18n.t('installer.step9.serviceStatus.install.completed') + role;
  242. case 'FAILED':
  243. return Em.I18n.t('installer.step9.serviceStatus.install.failed') + role;
  244. }
  245. case 'UNINSTALL':
  246. switch (task.status) {
  247. case 'PENDING':
  248. return Em.I18n.t('installer.step9.serviceStatus.uninstall.pending') + role;
  249. case 'QUEUED' :
  250. return Em.I18n.t('installer.step9.serviceStatus.uninstall.queued') + role;
  251. case 'IN_PROGRESS':
  252. return Em.I18n.t('installer.step9.serviceStatus.uninstall.inProgress') + role;
  253. case 'COMPLETED' :
  254. return Em.I18n.t('installer.step9.serviceStatus.uninstall.completed') + role;
  255. case 'FAILED':
  256. return Em.I18n.t('installer.step9.serviceStatus.uninstall.failed') + role;
  257. }
  258. case 'START' :
  259. switch (task.status) {
  260. case 'PENDING':
  261. return Em.I18n.t('installer.step9.serviceStatus.start.pending') + role;
  262. case 'QUEUED' :
  263. return Em.I18n.t('installer.step9.serviceStatus.start.queued') + role;
  264. case 'IN_PROGRESS':
  265. return Em.I18n.t('installer.step9.serviceStatus.start.inProgress') + role;
  266. case 'COMPLETED' :
  267. return role + Em.I18n.t('installer.step9.serviceStatus.start.completed');
  268. case 'FAILED':
  269. return role + Em.I18n.t('installer.step9.serviceStatus.start.failed');
  270. }
  271. case 'STOP' :
  272. switch (task.status) {
  273. case 'PENDING':
  274. return Em.I18n.t('installer.step9.serviceStatus.stop.pending') + role;
  275. case 'QUEUED' :
  276. return Em.I18n.t('installer.step9.serviceStatus.stop.queued') + role;
  277. case 'IN_PROGRESS':
  278. return Em.I18n.t('installer.step9.serviceStatus.stop.inProgress') + role;
  279. case 'COMPLETED' :
  280. return role + Em.I18n.t('installer.step9.serviceStatus.stop.completed');
  281. case 'FAILED':
  282. return role + Em.I18n.t('installer.step9.serviceStatus.stop.failed');
  283. }
  284. case 'EXECUTE' :
  285. case 'SERVICE_CHECK' :
  286. switch (task.status) {
  287. case 'PENDING':
  288. return Em.I18n.t('installer.step9.serviceStatus.execute.pending') + role;
  289. case 'QUEUED' :
  290. return Em.I18n.t('installer.step9.serviceStatus.execute.queued') + role;
  291. case 'IN_PROGRESS':
  292. return Em.I18n.t('installer.step9.serviceStatus.execute.inProgress') + role;
  293. case 'COMPLETED' :
  294. return role + Em.I18n.t('installer.step9.serviceStatus.execute.completed');
  295. case 'FAILED':
  296. return role + Em.I18n.t('installer.step9.serviceStatus.execute.failed');
  297. }
  298. case 'ABORT' :
  299. switch (task.status) {
  300. case 'PENDING':
  301. return Em.I18n.t('installer.step9.serviceStatus.abort.pending') + role;
  302. case 'QUEUED' :
  303. return Em.I18n.t('installer.step9.serviceStatus.abort.queued') + role;
  304. case 'IN_PROGRESS':
  305. return Em.I18n.t('installer.step9.serviceStatus.abort.inProgress') + role;
  306. case 'COMPLETED' :
  307. return role + Em.I18n.t('installer.step9.serviceStatus.abort.completed');
  308. case 'FAILED':
  309. return role + Em.I18n.t('installer.step9.serviceStatus.abort.failed');
  310. }
  311. }
  312. return '';
  313. },
  314. /**
  315. * run start/check services after installation phase
  316. */
  317. launchStartServices: function () {
  318. var data = {
  319. "RequestInfo": {
  320. "context": Em.I18n.t("requestInfo.startServices")
  321. },
  322. "Body": {
  323. "ServiceInfo": { "state": "STARTED" }
  324. }
  325. };
  326. var name = 'wizard.step9.installer.launch_start_services';
  327. if (this.get('content.controllerName') === 'addHostController') {
  328. var hostnames = [];
  329. for (var hostname in this.get('wizardController').getDBProperty('hosts')) {
  330. hostnames.push(hostname);
  331. }
  332. data = {
  333. "RequestInfo": {
  334. "context": Em.I18n.t("requestInfo.startHostComponents"),
  335. "query": "HostRoles/component_name.in(GANGLIA_MONITOR,HBASE_REGIONSERVER,DATANODE,TASKTRACKER,NODEMANAGER)&HostRoles/state=INSTALLED&HostRoles/host_name.in(" + hostnames.join(',') + ")"
  336. },
  337. "Body": {
  338. "HostRoles": { "state": "STARTED" }
  339. }
  340. };
  341. name = 'wizard.step9.add_host.launch_start_services';
  342. }
  343. data = JSON.stringify(data);
  344. if (App.testMode) {
  345. this.set('numPolls', 6);
  346. }
  347. App.ajax.send({
  348. name: name,
  349. sender: this,
  350. data: {
  351. data: data,
  352. cluster: this.get('content.cluster.name')
  353. },
  354. success: 'launchStartServicesSuccessCallback',
  355. error: 'launchStartServicesErrorCallback'
  356. });
  357. },
  358. launchStartServicesSuccessCallback: function (jsonData) {
  359. var clusterStatus = {};
  360. if (jsonData) {
  361. console.log("TRACE: Step9 -> In success function for the startService call");
  362. console.log("TRACE: Step9 -> value of the received data is: " + jsonData);
  363. var requestId = jsonData.Requests.id;
  364. console.log('requestId is: ' + requestId);
  365. clusterStatus = {
  366. status: 'INSTALLED',
  367. requestId: requestId,
  368. isStartError: false,
  369. isCompleted: false
  370. };
  371. this.hostHasClientsOnly(false);
  372. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  373. } else {
  374. console.log('ERROR: Error occurred in parsing JSON data');
  375. this.hostHasClientsOnly(true);
  376. clusterStatus = {
  377. status: 'STARTED',
  378. isStartError: false,
  379. isCompleted: true
  380. };
  381. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  382. this.set('status', 'success');
  383. this.set('progress', '100');
  384. this.set('isStepCompleted', true);
  385. }
  386. // We need to do recovery if there is a browser crash
  387. App.clusterStatus.setClusterStatus({
  388. clusterState: 'SERVICE_STARTING_3',
  389. wizardControllerName: this.get('content.controllerName'),
  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('status', 'in_progress');
  463. contentHost.set('message', this.displayMessage(runningAction.Tasks));
  464. }
  465. },
  466. /**
  467. * calculate progress of tasks per host
  468. * @param actions
  469. * @param contentHost
  470. * @return {Number}
  471. */
  472. progressPerHost: function (actions, contentHost) {
  473. var progress = 0;
  474. var actionsPerHost = actions.length;
  475. // TODO: consolidate to a single filter function for better performance
  476. var completedActions = actions.filterProperty('Tasks.status', 'COMPLETED').length
  477. + actions.filterProperty('Tasks.status', 'FAILED').length
  478. + actions.filterProperty('Tasks.status', 'ABORTED').length
  479. + actions.filterProperty('Tasks.status', 'TIMEDOUT').length;
  480. var queuedActions = actions.filterProperty('Tasks.status', 'QUEUED').length;
  481. var inProgressActions = actions.filterProperty('Tasks.status', 'IN_PROGRESS').length;
  482. /** for the install phase (PENDING), % completed per host goes up to 33%; floor(100 / 3)
  483. * for the start phase (INSTALLED), % completed starts from 34%
  484. * when task in queued state means it's completed on 9%
  485. * in progress - 35%
  486. * completed - 100%
  487. */
  488. switch (this.get('content.cluster.status')) {
  489. case 'PENDING':
  490. progress = actionsPerHost?(Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 33)):33;
  491. break;
  492. case 'INSTALLED':
  493. progress = actionsPerHost?(34 + Math.ceil(((queuedActions * 0.09) + (inProgressActions * 0.35) + completedActions ) / actionsPerHost * 66)):100;
  494. break;
  495. default:
  496. progress = 100;
  497. break;
  498. }
  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').forEach(function(host){
  601. host.get('status') != 'failed' ? host.set('message',Em.I18n.t('installer.step9.host.status.startAborted')) : null;
  602. host.set('progress','100');
  603. });
  604. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  605. this.set('isStepCompleted', true);
  606. } else {
  607. clusterStatus.status = 'INSTALLED';
  608. this.set('progress', '34');
  609. this.launchStartServices();
  610. }
  611. this.setTasksPerHost();
  612. App.router.get(this.get('content.controllerName')).saveInstalledHosts(this);
  613. return true;
  614. }
  615. return false;
  616. },
  617. setTasksPerHost: function () {
  618. var tasksData = this.get('polledData');
  619. this.get('hosts').forEach(function (_host) {
  620. var tasksPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
  621. if (tasksPerHost !== null && tasksPerHost !== undefined && tasksPerHost.length !== 0) {
  622. tasksPerHost.forEach(function (_taskPerHost) {
  623. _host.tasks.pushObject(_taskPerHost);
  624. }, this);
  625. }
  626. }, this);
  627. },
  628. // This is done at HostRole level.
  629. setLogTasksStatePerHost: function (tasksPerHost, host) {
  630. if (!tasksPerHost) return;
  631. tasksPerHost.forEach(function (_task) {
  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. tasksData.setEach('Tasks.stderr', '');
  658. tasksData.setEach('Tasks.stdout', '');
  659. if (this.get('currentOpenTaskId')) {
  660. var currentTask = tasksData.findProperty('Tasks.id', this.get('currentOpenTaskId'));
  661. var log = this.get('currentOpenTaskLog');
  662. if (currentTask && log) {
  663. currentTask.Tasks.stderr = log.stderr;
  664. currentTask.Tasks.stdout = log.stdout;
  665. }
  666. }
  667. this.replacePolledData(tasksData);
  668. this.get('hosts').forEach(function (_host) {
  669. var actionsPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data
  670. if (actionsPerHost.length === 0) {
  671. if(this.get('content.cluster.status') === 'PENDING') {
  672. _host.set('progress', '33');
  673. _host.set('status', 'pending');
  674. }
  675. if(this.get('content.cluster.status') === 'INSTALLED' || this.get('content.cluster.status') === 'FAILED') {
  676. _host.set('progress', '100');
  677. _host.set('status', 'success');
  678. }
  679. console.log("INFO: No task is hosted on the host");
  680. }
  681. this.setLogTasksStatePerHost(actionsPerHost, _host);
  682. this.onSuccessPerHost(actionsPerHost, _host); // every action should be a success
  683. this.onErrorPerHost(actionsPerHost, _host); // any action should be a failure
  684. this.onInProgressPerHost(actionsPerHost, _host); // current running action for a host
  685. totalProgress += self.progressPerHost(actionsPerHost, _host);
  686. if (_host.get('progress') == '33' && _host.get('status') != 'failed' && _host.get('status') != 'warning') {
  687. _host.set('message', this.t('installer.step9.host.status.nothingToInstall'));
  688. _host.set('status', 'pending');
  689. }
  690. }, this);
  691. totalProgress = Math.floor(totalProgress / this.get('hosts.length'));
  692. this.set('progress', totalProgress.toString());
  693. console.log("INFO: right now the progress is: " + this.get('progress'));
  694. return this.finishState(tasksData);
  695. },
  696. startPolling: function () {
  697. this.set('isSubmitDisabled', true);
  698. this.doPolling();
  699. },
  700. getUrl: function (requestId) {
  701. var clusterName = this.get('content.cluster.name');
  702. var requestId = requestId || this.get('content.cluster.requestId');
  703. 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';
  704. console.log("URL for step9 is: " + url);
  705. return url;
  706. },
  707. loadLogData: function(requestId) {
  708. var url = this.getUrl(requestId);
  709. var requestsId = this.get('wizardController').getDBProperty('cluster').oldRequestsId;
  710. if (App.testMode) {
  711. this.POLL_INTERVAL = 1;
  712. }
  713. requestsId.forEach(function(requestId) {
  714. url = this.getUrl(requestId);
  715. if (App.testMode) {
  716. this.POLL_INTERVAL = 1;
  717. url = this.get('mockDataPrefix') + '/poll_' + this.numPolls + '.json';
  718. }
  719. this.getLogsByRequest(url, false);
  720. }, this);
  721. },
  722. /**
  723. * {Number}
  724. * <code>taskId</code> of current open task
  725. */
  726. currentOpenTaskId: 0,
  727. /**
  728. * {Number}
  729. * <code>requestId</code> of current open task
  730. */
  731. currentOpenTaskRequestId: 0,
  732. /**
  733. * {Object}
  734. * Log of current open task (loaded from server)
  735. * Fields: {
  736. * stdout: '',
  737. * stderr: ''
  738. * }
  739. */
  740. currentOpenTaskLog: null,
  741. /**
  742. * Load form server <code>stderr, stdout</code> of current open task
  743. */
  744. loadCurrentTaskLog: function() {
  745. var taskId = this.get('currentOpenTaskId');
  746. var requestId = this.get('currentOpenTaskRequestId');
  747. var clusterName = this.get('content.cluster.name');
  748. if (!taskId) {
  749. console.log('taskId is null.');
  750. return;
  751. }
  752. App.ajax.send({
  753. name: 'background_operations.get_by_task',
  754. sender: this,
  755. data: {
  756. 'taskId': taskId,
  757. 'requestId': requestId,
  758. 'clusterName': clusterName,
  759. 'sync': true
  760. },
  761. success: 'loadCurrentTaskLogSuccessCallback',
  762. error: 'loadCurrentTaskLogErrorCallback'
  763. });
  764. },
  765. loadCurrentTaskLogSuccessCallback: function(data) {
  766. this.set('currentOpenTaskLog', {
  767. stdout: data.Tasks.stdout,
  768. stderr: data.Tasks.stderr
  769. });
  770. var taskId = this.get('currentOpenTaskId');
  771. if (taskId) {
  772. var currentTask = this.get('polledData').findProperty('Tasks.id', taskId);
  773. var log = this.get('currentOpenTaskLog');
  774. if (currentTask && log) {
  775. currentTask.Tasks.stderr = data.Tasks.stderr;
  776. currentTask.Tasks.stdout = data.Tasks.stdout;
  777. this.updateHostLogTask(data.Tasks.host_name, data.Tasks.id, data.Tasks.stderr, data.Tasks.stdout);
  778. }
  779. }
  780. this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1);
  781. },
  782. loadCurrentTaskLogErrorCallback: function() {
  783. this.set('currentOpenTaskId', 0);
  784. this.set('currentOpenTaskRequestId', 0);
  785. },
  786. /**
  787. * Update log task for provided host
  788. * @param {String} hostName
  789. * @param {Number} taskId
  790. * @param {String} stderr
  791. * @param {String} stdout
  792. */
  793. updateHostLogTask: function(hostName, taskId, stderr, stdout) {
  794. var logTask = this.get('hosts').findProperty('name', hostName).get('logTasks').findProperty('Tasks.id', taskId);
  795. if (logTask) {
  796. logTask.Tasks.stderr = stderr;
  797. logTask.Tasks.stdout = stdout;
  798. }
  799. },
  800. // polling: whether to continue polling for status or not
  801. getLogsByRequest: function(url, polling){
  802. var self = this;
  803. $.ajax({
  804. type: 'GET',
  805. url: url,
  806. async: true,
  807. timeout: App.timeout,
  808. dataType: 'text',
  809. success: function (data) {
  810. var parsedData = jQuery.parseJSON(data);
  811. console.log("TRACE: In success function for the GET logs data");
  812. console.log("TRACE: Step9 -> The value is: ", parsedData);
  813. var result = self.parseHostInfo(parsedData);
  814. if (!polling) {
  815. return;
  816. }
  817. if (result !== true) {
  818. window.setTimeout(function () {
  819. if (self.get('currentOpenTaskId')) {
  820. self.loadCurrentTaskLog();
  821. }
  822. self.doPolling();
  823. }, self.POLL_INTERVAL);
  824. } else {
  825. self.stopPolling();
  826. }
  827. },
  828. error: function (request, ajaxOptions, error) {
  829. console.log("TRACE: STep9 -> In error function for the GET logs data");
  830. console.log("TRACE: STep9 -> value of the url is: " + url);
  831. console.log("TRACE: STep9 -> error code status is: " + request.status);
  832. self.stopPolling();
  833. },
  834. statusCode: require('data/statusCodes')
  835. }).retry({times: App.maxRetries, timeout: App.timeout}).then(null,
  836. function () {
  837. App.showReloadPopup();
  838. console.log('Install services all retries failed');
  839. }
  840. );
  841. },
  842. doPolling: function () {
  843. var url = this.getUrl();
  844. if (App.testMode) {
  845. this.numPolls++;
  846. url = this.get('mockDataPrefix') + '/poll_' + this.get('numPolls') + '.json';
  847. }
  848. this.getLogsByRequest(url, true);
  849. },
  850. stopPolling: function () {
  851. //TODO: uncomment following line after the hook up with the API call
  852. // this.set('isStepCompleted',true);
  853. },
  854. submit: function () {
  855. if (!this.get('isSubmitDisabled')) {
  856. App.router.send('next');
  857. }
  858. },
  859. back: function () {
  860. if (!this.get('isSubmitDisabled')) {
  861. App.router.send('back');
  862. }
  863. }
  864. });