step13_controller.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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. App.WizardStep13Controller = Em.Controller.extend({
  20. status: 'IN_PROGRESS',
  21. onStatusChange: function () {
  22. if (this.get('tasks').someProperty('status', 'FAILED')) {
  23. this.set('status', 'FAILED');
  24. if (this.get('tasks')[5].status == 'FAILED' || this.get('tasks')[6].status == 'FAILED') {
  25. this.set('showRetry', true);
  26. }
  27. } else if (this.get('tasks').everyProperty('status', 'COMPLETED')) {
  28. this.set('status', 'COMPLETED');
  29. this.set('isSubmitDisabled', false);
  30. } else {
  31. this.set('status', 'IN_PROGRESS')
  32. }
  33. var statuses = this.get('tasks').mapProperty('status');
  34. App.router.get(this.get('content.controllerName')).saveTasksStatuses(statuses);
  35. App.clusterStatus.setClusterStatus({
  36. clusterName: this.get('content.cluster.name'),
  37. clusterState: 'REASSIGN_MASTER_INSTALLING',
  38. wizardControllerName: this.get('content.controllerName'),
  39. localdb: App.db.data
  40. });
  41. this.setTasksMessages();
  42. this.navigateStep();
  43. },
  44. tasks: [],
  45. /**
  46. * Set messages for tasks depending on their status
  47. */
  48. setTasksMessages: function () {
  49. var service = this.get('service.displayName');
  50. var master = this.get('masterComponent.display_name');
  51. if (this.get('isCohosted')) {
  52. service = 'Hive, WebHCat';
  53. master = Em.I18n.t('installer.step5.hiveGroup');
  54. }
  55. for (i = 0; i < this.get('tasks').length; i++) {
  56. var status = this.get('tasks')[i].status.toLowerCase().replace('initialize', 'pending').replace('_', ' ');
  57. if (i == 0 || i == 6) {
  58. this.get('tasks')[i].set('message', Em.I18n.t('installer.step13.task' + i).format(service) + ' ' + status);
  59. } else {
  60. this.get('tasks')[i].set('message', Em.I18n.t('installer.step13.task' + i).format(master) + ' ' + status);
  61. }
  62. }
  63. },
  64. configs: [],
  65. globals: [],
  66. configMapping: App.config.get('configMapping').all(),
  67. newConfigsTag: null,
  68. createdConfigs: [],
  69. currentRequestId: [],
  70. isSubmitDisabled: true,
  71. showRetry: false,
  72. service: function () {
  73. return App.Service.find().findProperty('serviceName', this.get('masterComponent.service_id'));
  74. }.property('masterComponent'),
  75. masterComponent: function () {
  76. return this.get('content.reassign');
  77. }.property('content.reassign'),
  78. isCohosted: function () {
  79. return this.get('masterComponent.component_name') == 'HIVE_SERVER';
  80. }.property('masterComponent'),
  81. loadStep: function () {
  82. this.clearStep();
  83. this.loadTasks();
  84. this.addObserver('tasks.@each.status', this, 'onStatusChange');
  85. this.onStatusChange();
  86. },
  87. clearStep: function () {
  88. this.removeObserver('tasks.@each.status', this, 'onStatusChange');
  89. this.removeObserver('createdConfigs.length', this, 'onCreateConfigsCompleted');
  90. var tasks = [];
  91. for (var i = 0; i < 8; i++) {
  92. tasks.pushObject(Ember.Object.create({
  93. status: 'INITIALIZE',
  94. logs: '',
  95. message: '',
  96. progress: 0
  97. }));
  98. }
  99. this.set('tasks', tasks);
  100. this.set('createdConfigsCount', 0);
  101. this.set('queueTasksCompleted', 0);
  102. this.set('dataPollCounter', 1);
  103. this.set('showRetry', false);
  104. this.set('isSubmitDisabled', true);
  105. this.get('configs').clear();
  106. this.get('globals').clear();
  107. this.get('createdConfigs').clear();
  108. },
  109. loadTasks: function () {
  110. var statuses = this.get('content.tasksStatuses');
  111. if (statuses) {
  112. statuses.forEach(function (status, index) {
  113. this.get('tasks')[index].status = status;
  114. }, this)
  115. }
  116. var statusesForRequestId = ['PENDING', 'QUEUED', 'IN_PROGRESS'];
  117. if (statusesForRequestId.contains(statuses[0]) || statusesForRequestId.contains(statuses[5]) || statusesForRequestId.contains(statuses[6])) {
  118. this.set('currentRequestId', this.get('content.cluster.requestId'));
  119. this.getLogsByRequest();
  120. }
  121. },
  122. /**
  123. * Run tasks in proper way
  124. */
  125. navigateStep: function () {
  126. if (this.get('tasks')[0].status == 'INITIALIZE') {
  127. this.stopService();
  128. }
  129. else if (this.taskIsReady(1)) {
  130. this.createMasterComponent();
  131. }
  132. else if (this.taskIsReady(2)) {
  133. this.createConfigs();
  134. }
  135. else if (this.taskIsReady(3)) {
  136. this.applyConfigs();
  137. }
  138. else if (this.taskIsReady(4)) {
  139. this.putInMaintenanceMode();
  140. }
  141. else if (this.taskIsReady(5)) {
  142. this.installComponent();
  143. }
  144. else if (this.taskIsReady(6)) {
  145. this.startComponents();
  146. }
  147. else if (this.taskIsReady(7)) {
  148. this.removeComponent();
  149. }
  150. },
  151. /**
  152. * Determine preparedness to run task
  153. * @param task
  154. * @return {Boolean}
  155. */
  156. taskIsReady: function (task) {
  157. if (this.get('tasks')[task].status != 'INITIALIZE') {
  158. return false;
  159. }
  160. var tempArr = this.get('tasks').mapProperty('status').slice(0, task).uniq();
  161. return tempArr.length == 1 && tempArr[0] == 'COMPLETED';
  162. },
  163. queueTasksCompleted: 0,
  164. /**
  165. * Change status of the task
  166. * @param task
  167. * @param status
  168. */
  169. setTasksStatus: function (task, status) {
  170. if (status == 'COMPLETED' && this.get('isCohosted') && [1, 4, 7].contains(task) && this.get('queueTasksCompleted') < 2) {
  171. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  172. } else {
  173. this.get('tasks')[task].set('status', status);
  174. }
  175. },
  176. saveClusterStatus: function (requestId, status) {
  177. var clusterStatus = {
  178. status: status,
  179. requestId: requestId
  180. };
  181. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  182. },
  183. stopService: function () {
  184. this.set('currentRequestId', []);
  185. var serviceNames = [this.get('masterComponent.service_id')];
  186. if (this.get('isCohosted')) {
  187. serviceNames = ['HIVE', 'WEBHCAT'];
  188. }
  189. serviceNames.forEach(function (serviceName) {
  190. App.ajax.send({
  191. name: 'reassign.stop_service',
  192. sender: this,
  193. data: {
  194. serviceName: serviceName,
  195. displayName: App.Service.find().findProperty('serviceName', serviceName).get('displayName')
  196. },
  197. beforeSend: 'onStopServiceBeforeSend',
  198. success: 'onStopServiceSuccess',
  199. error: 'onStopServiceError'
  200. });
  201. }, this);
  202. },
  203. onStopServiceBeforeSend: function () {
  204. this.setTasksStatus(0, 'PENDING');
  205. },
  206. onStopServiceSuccess: function (data) {
  207. if (data) {
  208. var requestId = data.Requests.id;
  209. this.get('currentRequestId').push(requestId);
  210. this.saveClusterStatus(this.get('currentRequestId'), 'PENDING');
  211. if ((this.get('isCohosted') && this.get('currentRequestId.length') == 2) || !this.get('isCohosted')) {
  212. this.getLogsByRequest();
  213. }
  214. } else {
  215. this.setTasksStatus(0, 'FAILED');
  216. }
  217. },
  218. onStopServiceError: function () {
  219. this.setTasksStatus(0, 'FAILED');
  220. },
  221. createMasterComponent: function () {
  222. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  223. var componentNames = [this.get('masterComponent.component_name')];
  224. if (this.get('isCohosted')) {
  225. this.set('queueTasksCompleted', 0);
  226. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  227. }
  228. componentNames.forEach(function (componentName) {
  229. if (App.testMode) {
  230. this.setTasksStatus(1, 'COMPLETED');
  231. } else {
  232. App.ajax.send({
  233. name: 'reassign.create_master',
  234. sender: this,
  235. data: {
  236. hostName: hostName,
  237. componentName: componentName
  238. },
  239. beforeSend: 'onCreateMasterComponentBeforeSend',
  240. success: 'onCreateMasterComponentSuccess',
  241. error: 'onCreateMasterComponentError'
  242. });
  243. }
  244. }, this);
  245. },
  246. onCreateMasterComponentBeforeSend: function () {
  247. this.setTasksStatus(1, 'PENDING');
  248. },
  249. onCreateMasterComponentSuccess: function () {
  250. this.setTasksStatus(1, 'COMPLETED');
  251. },
  252. onCreateMasterComponentError: function () {
  253. this.setTasksStatus(1, 'FAILED');
  254. },
  255. createConfigs: function () {
  256. if (this.get('service.serviceName') == 'GANGLIA' || App.testMode) {
  257. this.setTasksStatus(2, 'COMPLETED');
  258. } else {
  259. this.setTasksStatus(2, 'PENDING');
  260. this.loadGlobals();
  261. this.loadConfigs();
  262. this.set('newConfigsTag', 'version' + (new Date).getTime());
  263. var serviceName = this.get('service.serviceName');
  264. this.createConfigSite(this.createGlobalSiteObj());
  265. this.createConfigSite(this.createCoreSiteObj());
  266. if (serviceName == 'HDFS') {
  267. this.createConfigSite(this.createSiteObj('hdfs-site'));
  268. }
  269. if (serviceName == 'MAPREDUCE') {
  270. this.createConfigSite(this.createSiteObj('mapred-site'));
  271. }
  272. if (serviceName == 'HBASE') {
  273. this.createConfigSite(this.createSiteObj('hbase-site'));
  274. }
  275. if (serviceName == 'OOZIE') {
  276. this.createConfigSite(this.createSiteObj('oozie-site'));
  277. }
  278. if (serviceName == 'HIVE' || this.get('isCohosted')) {
  279. this.createConfigSite(this.createSiteObj('hive-site'));
  280. }
  281. if (serviceName == 'WEBHCAT' || this.get('isCohosted')) {
  282. this.createConfigSite(this.createSiteObj('webhcat-site'));
  283. }
  284. this.addObserver('createdConfigs.length', this, 'onCreateConfigsCompleted');
  285. this.onCreateConfigsCompleted();
  286. }
  287. },
  288. createConfigSite: function (configs) {
  289. configs.tag = this.get('newConfigsTag');
  290. App.ajax.send({
  291. name: 'reassign.create_configs',
  292. sender: this,
  293. data: {
  294. configs: configs
  295. },
  296. beforeSend: 'onCreateConfigsBeforeSend',
  297. success: 'onCreateConfigsSuccess',
  298. error: 'onCreateConfigsError'
  299. });
  300. },
  301. onCreateConfigsBeforeSend: function () {
  302. this.set('createdConfigsCount', this.get('createdConfigsCount') + 1);
  303. },
  304. onCreateConfigsSuccess: function (data, opts) {
  305. this.get('createdConfigs').pushObject(opts.configs.type);
  306. },
  307. onCreateConfigsError: function () {
  308. this.setTasksStatus(2, 'FAILED');
  309. },
  310. createdConfigsCount: 0,
  311. onCreateConfigsCompleted: function () {
  312. if (this.get('createdConfigs.length') == this.get('createdConfigsCount')) {
  313. this.setTasksStatus(2, 'COMPLETED');
  314. }
  315. },
  316. loadGlobals: function () {
  317. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  318. if (globals.someProperty('name', 'hive_database')) {
  319. //TODO: Hive host depends on the type of db selected. Change puppet variable name if postgres is not the default db
  320. var hiveDb = globals.findProperty('name', 'hive_database');
  321. if (hiveDb.value === 'New MySQL Database') {
  322. if (globals.someProperty('name', 'hive_ambari_host')) {
  323. globals.findProperty('name', 'hive_ambari_host').name = 'hive_mysql_hostname';
  324. }
  325. globals = globals.without(globals.findProperty('name', 'hive_existing_host'));
  326. globals = globals.without(globals.findProperty('name', 'hive_existing_database'));
  327. } else {
  328. globals.findProperty('name', 'hive_existing_host').name = 'hive_mysql_hostname';
  329. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  330. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  331. }
  332. }
  333. this.set('globals', globals);
  334. },
  335. loadConfigs: function () {
  336. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property').filterProperty('value');
  337. var uiConfigs = this.loadUiSideConfigs();
  338. this.set('configs', storedConfigs.concat(uiConfigs));
  339. },
  340. loadUiSideConfigs: function () {
  341. var uiConfig = [];
  342. var configs = this.get('configMapping').filterProperty('foreignKey', null);
  343. configs.forEach(function (_config) {
  344. var value = this.getGlobConfigValue(_config.templateName, _config.value, _config.name);
  345. uiConfig.pushObject({
  346. "id": "site property",
  347. "name": _config.name,
  348. "value": value,
  349. "filename": _config.filename
  350. });
  351. }, this);
  352. var dependentConfig = this.get('configMapping').filterProperty('foreignKey');
  353. dependentConfig.forEach(function (_config) {
  354. App.config.setConfigValue(uiConfig, this.get('content.serviceConfigProperties'), _config, this.get('globals'));
  355. uiConfig.pushObject({
  356. "id": "site property",
  357. "name": _config._name || _config.name,
  358. "value": _config.value,
  359. "filename": _config.filename
  360. });
  361. }, this);
  362. return uiConfig;
  363. },
  364. getGlobConfigValue: function (templateName, expression, name) {
  365. var express = expression.match(/<(.*?)>/g);
  366. var value = expression;
  367. if (express == null) {
  368. return expression;
  369. }
  370. express.forEach(function (_express) {
  371. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  372. if (this.get('globals').someProperty('name', templateName[index])) {
  373. var globValue = this.get('globals').findProperty('name', templateName[index]).value;
  374. // Hack for templeton.zookeeper.hosts
  375. if (value !== null) { // if the property depends on more than one template name like <templateName[0]>/<templateName[1]> then don't proceed to the next if the prior is null or not found in the global configs
  376. if (name === "templeton.zookeeper.hosts" || name === 'hbase.zookeeper.quorum') {
  377. // globValue is an array of ZooKeeper Server hosts
  378. var zooKeeperPort = '2181';
  379. if (name === "templeton.zookeeper.hosts") {
  380. var zooKeeperServers = globValue.map(function (item) {
  381. return item + ':' + zooKeeperPort;
  382. }).join(',');
  383. value = value.replace(_express, zooKeeperServers);
  384. } else {
  385. value = value.replace(_express, globValue.join(','));
  386. }
  387. } else {
  388. value = value.replace(_express, globValue);
  389. }
  390. }
  391. } else {
  392. value = null;
  393. }
  394. }, this);
  395. return value;
  396. },
  397. /**
  398. * Set property of the site variable
  399. */
  400. setSiteProperty: function (key, value, filename) {
  401. this.get('configs').pushObject({
  402. "id": "site property",
  403. "name": key,
  404. "value": value,
  405. "filename": filename
  406. });
  407. },
  408. createGlobalSiteObj: function () {
  409. var globalSiteProperties = {};
  410. //this.get('globals').filterProperty('domain', 'global').forEach(function (_globalSiteObj) {
  411. this.get('globals').forEach(function (_globalSiteObj) {
  412. // do not pass any globals whose name ends with _host or _hosts
  413. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  414. // append "m" to JVM memory options except for hadoop_heapsize
  415. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && _globalSiteObj.name !== 'hadoop_heapsize') {
  416. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  417. } else {
  418. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  419. }
  420. }
  421. }, this);
  422. return {"type": "global", "properties": globalSiteProperties};
  423. },
  424. createCoreSiteObj: function () {
  425. var serviceName = this.get('service.serviceName');
  426. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  427. var coreSiteProperties = {};
  428. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  429. var isOozieSelected = serviceName == 'OOZIE';
  430. var oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null;
  431. var isHiveSelected = serviceName == 'HIVE';
  432. var hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null;
  433. var isHcatSelected = serviceName == 'WEBHCAT';
  434. var hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null;
  435. coreSiteObj.forEach(function (_coreSiteObj) {
  436. if ((isOozieSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.groups')) && (isHiveSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.groups')) && (isHcatSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.groups'))) {
  437. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  438. }
  439. }, this);
  440. return {"type": "core-site", "properties": coreSiteProperties};
  441. },
  442. createSiteObj: function (name) {
  443. var fileName = name + '.xml';
  444. var configs = this.get('configs').filterProperty('filename', fileName);
  445. var properties = {};
  446. configs.forEach(function (_configProperty) {
  447. properties[_configProperty.name] = _configProperty.value;
  448. }, this);
  449. return {type: name, properties: properties};
  450. },
  451. applyConfigs: function () {
  452. if (this.get('service.serviceName') == 'GANGLIA' || App.testMode) {
  453. this.setTasksStatus(3, 'COMPLETED');
  454. } else {
  455. var serviceName = this.get('service.serviceName');
  456. App.ajax.send({
  457. name: 'reassign.check_configs',
  458. sender: this,
  459. data: {
  460. serviceName: serviceName
  461. },
  462. success: 'onCheckConfigsSuccess',
  463. error: 'onCheckConfigsError'
  464. });
  465. }
  466. },
  467. onCheckConfigsSuccess: function (configs) {
  468. var configTags = configs.ServiceInfo.desired_configs;
  469. if (!configTags) {
  470. this.setTasksStatus(0, 'FAILED');
  471. return;
  472. }
  473. for (var tag in configTags) {
  474. if (this.get('createdConfigs').contains(tag)) {
  475. configTags[tag] = this.get('newConfigsTag');
  476. }
  477. }
  478. var data = {config: configTags};
  479. var serviceName = this.get('service.serviceName');
  480. App.ajax.send({
  481. name: 'reassign.apply_configs',
  482. sender: this,
  483. data: {
  484. serviceName: serviceName,
  485. configs: data
  486. },
  487. beforeSend: 'onApplyConfigsBeforeSend',
  488. success: 'onApplyConfigsSuccess',
  489. error: 'onApplyConfigsError'
  490. });
  491. },
  492. onCheckConfigsError: function () {
  493. this.setTasksStatus(3, 'FAILED');
  494. },
  495. onApplyConfigsBeforeSend: function () {
  496. this.setTasksStatus(3, 'PENDING');
  497. },
  498. onApplyConfigsSuccess: function () {
  499. this.setTasksStatus(3, 'COMPLETED');
  500. },
  501. onApplyConfigsError: function () {
  502. this.setTasksStatus(3, 'FAILED');
  503. },
  504. putInMaintenanceMode: function () {
  505. if (App.testMode) {
  506. this.setTasksStatus(4, 'COMPLETED');
  507. } else {
  508. var hostName = this.get('content.reassign.host_id');
  509. var componentNames = [this.get('masterComponent.component_name')];
  510. if (this.get('isCohosted')) {
  511. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  512. this.set('queueTasksCompleted', 0);
  513. }
  514. componentNames.forEach(function (componentName) {
  515. App.ajax.send({
  516. name: 'reassign.maintenance_mode',
  517. sender: this,
  518. data: {
  519. hostName: hostName,
  520. componentName: componentName
  521. },
  522. beforeSend: 'onPutInMaintenanceModeBeforeSend',
  523. success: 'onPutInMaintenanceModeSuccess',
  524. error: 'onPutInMaintenanceModeError'
  525. });
  526. }, this);
  527. }
  528. },
  529. onPutInMaintenanceModeBeforeSend: function () {
  530. this.setTasksStatus(4, 'PENDING');
  531. },
  532. onPutInMaintenanceModeSuccess: function () {
  533. this.setTasksStatus(4, 'COMPLETED');
  534. },
  535. onPutInMaintenanceModeError: function () {
  536. this.setTasksStatus(4, 'FAILED');
  537. },
  538. installComponent: function () {
  539. this.set('currentRequestId', []);
  540. var componentNames = [this.get('masterComponent.component_name')];
  541. if (this.get('isCohosted')) {
  542. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  543. }
  544. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  545. componentNames.forEach(function (componentName) {
  546. App.ajax.send({
  547. name: 'reassign.install_component',
  548. sender: this,
  549. data: {
  550. hostName: hostName,
  551. componentName: componentName,
  552. displayName: App.format.role(componentName)
  553. },
  554. beforeSend: 'onInstallComponentBeforeSend',
  555. success: 'onInstallComponentSuccess',
  556. error: 'onInstallComponentError'
  557. });
  558. }, this);
  559. },
  560. onInstallComponentBeforeSend: function () {
  561. this.setTasksStatus(5, 'PENDING');
  562. },
  563. onInstallComponentSuccess: function (data) {
  564. if (data) {
  565. var requestId = data.Requests.id;
  566. this.get('currentRequestId').push(requestId);
  567. this.saveClusterStatus(this.get('currentRequestId'), 'PENDING');
  568. if ((this.get('isCohosted') && this.get('currentRequestId.length') == 3) || !this.get('isCohosted')) {
  569. this.getLogsByRequest();
  570. }
  571. } else {
  572. this.setTasksStatus(5, 'FAILED');
  573. }
  574. },
  575. onInstallComponentError: function () {
  576. this.setTasksStatus(5, 'FAILED');
  577. },
  578. startComponents: function () {
  579. this.set('currentRequestId', []);
  580. var serviceNames = [this.get('masterComponent.service_id')];
  581. if (this.get('isCohosted')) {
  582. serviceNames = ['HIVE', 'WEBHCAT'];
  583. }
  584. serviceNames.forEach(function (serviceName) {
  585. App.ajax.send({
  586. name: 'reassign.start_components',
  587. sender: this,
  588. data: {
  589. serviceName: serviceName,
  590. displayName: App.Service.find().findProperty('serviceName', serviceName).get('displayName')
  591. },
  592. beforeSend: 'onStartComponentsBeforeSend',
  593. success: 'onStartComponentsSuccess',
  594. error: 'onStartComponentsError'
  595. });
  596. }, this);
  597. },
  598. onStartComponentsBeforeSend: function () {
  599. this.setTasksStatus(6, 'PENDING');
  600. },
  601. onStartComponentsSuccess: function (data) {
  602. if (data) {
  603. var requestId = data.Requests.id;
  604. this.get('currentRequestId').push(requestId);
  605. this.saveClusterStatus(this.get('currentRequestId'), 'PENDING');
  606. if ((this.get('isCohosted') && this.get('currentRequestId.length') == 2) || !this.get('isCohosted')) {
  607. this.getLogsByRequest();
  608. }
  609. } else {
  610. this.setTasksStatus(6, 'FAILED');
  611. }
  612. },
  613. onStartComponentsError: function () {
  614. this.setTasksStatus(6, 'FAILED');
  615. },
  616. /**
  617. * Parse logs to define status of Start, Stop ot Install task
  618. * @param logs
  619. */
  620. parseLogs: function (logs) {
  621. var self = this;
  622. var task;
  623. var stopPolling = false;
  624. var polledData = [];
  625. logs.forEach(function (item) {
  626. polledData = polledData.concat(item.tasks);
  627. }, this);
  628. if (this.get('tasks')[0].status == 'COMPLETED') {
  629. task = this.get('tasks')[5].status == 'COMPLETED' ? 6 : 5;
  630. } else {
  631. task = 0;
  632. }
  633. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  634. if (polledData.someProperty('Tasks.status', 'FAILED')) {
  635. this.setTasksStatus(task, 'FAILED');
  636. } else {
  637. this.setTasksStatus(task, 'COMPLETED');
  638. }
  639. stopPolling = true;
  640. } else {
  641. if (polledData.length == 1) {
  642. this.get('tasks')[task].set('progress', 50);
  643. } else {
  644. var progress = polledData.filterProperty('Tasks.status', 'COMPLETED').length / polledData.length * 100;
  645. this.get('tasks')[task].set('progress', Math.round(progress));
  646. }
  647. this.setTasksStatus(task, 'IN_PROGRESS');
  648. }
  649. if (!stopPolling) {
  650. window.setTimeout(function () {
  651. self.getLogsByRequest()
  652. }, self.POLL_INTERVAL);
  653. }
  654. },
  655. POLL_INTERVAL: 4000,
  656. dataPollCounter: 0,
  657. getLogsByRequest: function () {
  658. this.set('logs', []);
  659. var requestIds = this.get('currentRequestId');
  660. if (this.get('dataPollCounter') == 5) {
  661. this.set('dataPollCounter', 0);
  662. }
  663. this.set('dataPollCounter', this.get('dataPollCounter') + 1);
  664. requestIds.forEach(function (requestId) {
  665. App.ajax.send({
  666. name: 'reassign.get_logs',
  667. sender: this,
  668. data: {
  669. requestId: requestId,
  670. pollCounter: this.get('dataPollCounter')
  671. },
  672. success: 'onGetLogsByRequestSuccess',
  673. error: 'onGetLogsByRequestError'
  674. });
  675. }, this);
  676. },
  677. logs: [],
  678. onGetLogsByRequestSuccess: function (data) {
  679. this.get('logs').push(data);
  680. if (this.get('logs.length') == this.get('currentRequestId.length')) {
  681. this.parseLogs(this.get('logs'))
  682. }
  683. },
  684. onGetLogsByRequestError: function () {
  685. this.set('status', 'FAILED');
  686. },
  687. removeComponent: function () {
  688. if (App.testMode) {
  689. this.setTasksStatus(7, 'COMPLETED');
  690. } else {
  691. var hostName = this.get('content.reassign.host_id');
  692. var componentNames = [this.get('masterComponent.component_name')];
  693. if (this.get('isCohosted')) {
  694. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  695. this.set('queueTasksCompleted', 0);
  696. }
  697. componentNames.forEach(function (componentName) {
  698. App.ajax.send({
  699. name: 'reassign.remove_component',
  700. sender: this,
  701. data: {
  702. hostName: hostName,
  703. componentName: componentName
  704. },
  705. beforeSend: 'onRemoveComponentBeforeSend',
  706. success: 'onRemoveComponentSuccess',
  707. error: 'onRemoveComponentError'
  708. });
  709. }, this);
  710. }
  711. },
  712. onRemoveComponentBeforeSend: function () {
  713. this.setTasksStatus(7, 'PENDING');
  714. },
  715. onRemoveComponentSuccess: function () {
  716. this.setTasksStatus(7, 'COMPLETED');
  717. },
  718. onRemoveComponentError: function () {
  719. this.setTasksStatus(7, 'FAILED');
  720. },
  721. retry: function () {
  722. if (this.get('tasks')[5].status == 'FAILED') {
  723. this.installComponent();
  724. } else {
  725. this.startComponents();
  726. }
  727. this.set('showRetry', false);
  728. },
  729. abort: function () {
  730. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  731. var componentNames = [this.get('masterComponent.component_name')];
  732. if (this.get('isCohosted')) {
  733. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  734. this.set('queueTasksCompleted', 0);
  735. }
  736. componentNames.forEach(function (componentName) {
  737. App.ajax.send({
  738. name: 'reassign.maintenance_mode',
  739. sender: this,
  740. data: {
  741. hostName: hostName,
  742. componentName: componentName
  743. },
  744. success: 'onAbortMaintenance',
  745. error: 'onAbortError'
  746. });
  747. }, this);
  748. },
  749. onAbortMaintenance: function () {
  750. if (this.get('isCohosted') && this.get('queueTasksCompleted') < 2) {
  751. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  752. } else {
  753. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  754. var componentNames = [this.get('masterComponent.component_name')];
  755. if (this.get('isCohosted')) {
  756. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  757. this.set('queueTasksCompleted', 0);
  758. }
  759. componentNames.forEach(function (componentName) {
  760. App.ajax.send({
  761. name: 'reassign.remove_component',
  762. sender: this,
  763. data: {
  764. hostName: hostName,
  765. componentName: componentName
  766. },
  767. success: 'onAbortRemoveComponent',
  768. error: 'onAbortError'
  769. });
  770. }, this);
  771. }
  772. },
  773. onAbortRemoveComponent: function () {
  774. if (this.get('isCohosted') && this.get('queueTasksCompleted') < 2) {
  775. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  776. } else {
  777. var hostName = this.get('content.reassign.host_id');
  778. var componentNames = [this.get('masterComponent.component_name')];
  779. if (this.get('isCohosted')) {
  780. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  781. this.set('queueTasksCompleted', 0);
  782. }
  783. componentNames.forEach(function (componentName) {
  784. App.ajax.send({
  785. name: 'reassign.install_component',
  786. sender: this,
  787. data: {
  788. hostName: hostName,
  789. componentName: componentName
  790. },
  791. success: 'onAbortCompleted',
  792. error: 'onAbortError'
  793. });
  794. }, this);
  795. }
  796. },
  797. onAbortCompleted: function () {
  798. if (this.get('isCohosted') && this.get('queueTasksCompleted') < 2) {
  799. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  800. } else {
  801. App.clusterStatus.setClusterStatus({
  802. clusterName: this.get('content.cluster.name'),
  803. clusterState: 'REASSIGN_MASTER_ABORTED',
  804. wizardControllerName: this.get('content.controllerName'),
  805. localdb: App.db.data
  806. });
  807. App.router.send('back');
  808. }
  809. },
  810. onAbortError: function () {
  811. App.ModalPopup.show({
  812. header: Em.I18n.translations['common.error'],
  813. secondary: false,
  814. onPrimary: function () {
  815. this.hide();
  816. },
  817. bodyClass: Ember.View.extend({
  818. template: Ember.Handlebars.compile('<p>{{t installer.step13.abortError}}</p>')
  819. })
  820. });
  821. }
  822. })