step14_controller.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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.WizardStep14Controller = 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.step14.task' + i).format(service) + ' ' + status);
  59. } else {
  60. this.get('tasks')[i].set('message', Em.I18n.t('installer.step14.task' + i).format(master) + ' ' + status);
  61. }
  62. }
  63. },
  64. configs: [],
  65. globals: [],
  66. configMapping: require('data/config_mapping').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.get('tasks')[1].status == 'INITIALIZE') {
  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 startIndex = (task == 4) ? 0 : 1;
  161. var tempArr = this.get('tasks').mapProperty('status').slice(startIndex, task).uniq();
  162. return tempArr.length == 1 && tempArr[0] == 'COMPLETED';
  163. },
  164. queueTasksCompleted: 0,
  165. /**
  166. * Change status of the task
  167. * @param task
  168. * @param status
  169. */
  170. setTasksStatus: function (task, status) {
  171. if (status == 'COMPLETED' && this.get('isCohosted') && [1, 4, 7].contains(task) && this.get('queueTasksCompleted') < 2) {
  172. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  173. } else {
  174. this.get('tasks')[task].set('status', status);
  175. }
  176. },
  177. saveClusterStatus: function (requestId, status) {
  178. var clusterStatus = {
  179. status: status,
  180. requestId: requestId
  181. };
  182. App.router.get(this.get('content.controllerName')).saveClusterStatus(clusterStatus);
  183. },
  184. stopService: function () {
  185. this.set('currentRequestId', []);
  186. var serviceNames = [this.get('masterComponent.service_id')];
  187. if (this.get('isCohosted')) {
  188. serviceNames = ['HIVE', 'WEBHCAT'];
  189. }
  190. serviceNames.forEach(function (serviceName) {
  191. App.ajax.send({
  192. name: 'reassign.stop_service',
  193. sender: this,
  194. data: {
  195. serviceName: serviceName
  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. this.setConfigValue(uiConfig, _config);
  355. uiConfig.pushObject({
  356. "id": "site property",
  357. "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 all site property that are derived from other site-properties
  399. */
  400. setConfigValue: function (uiConfig, config) {
  401. if (config.value == null) {
  402. return;
  403. }
  404. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  405. if (fkValue) {
  406. fkValue.forEach(function (_fkValue) {
  407. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  408. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  409. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  410. config.value = config.value.replace(_fkValue, globalValue);
  411. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  412. var globalValue;
  413. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  414. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  415. } else {
  416. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  417. }
  418. config.value = config.value.replace(_fkValue, globalValue);
  419. }
  420. }, this);
  421. }
  422. if (fkValue = config.name.match(/<(foreignKey.*?)>/g)) {
  423. fkValue.forEach(function (_fkValue) {
  424. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  425. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  426. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  427. config.name = config.name.replace(_fkValue, globalValue);
  428. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  429. var globalValue;
  430. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  431. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  432. } else {
  433. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  434. }
  435. config.name = config.name.replace(_fkValue, globalValue);
  436. }
  437. }, this);
  438. }
  439. //For properties in the configMapping file having foreignKey and templateName properties.
  440. var templateValue = config.value.match(/<(templateName.*?)>/g);
  441. if (templateValue) {
  442. templateValue.forEach(function (_value) {
  443. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  444. if (this.get('globals').someProperty('name', config.templateName[index])) {
  445. var globalValue = this.get('globals').findProperty('name', config.templateName[index]).value;
  446. config.value = config.value.replace(_value, globalValue);
  447. } else {
  448. config.value = null;
  449. }
  450. }, this);
  451. }
  452. },
  453. /**
  454. * Set property of the site variable
  455. */
  456. setSiteProperty: function (key, value, filename) {
  457. this.get('configs').pushObject({
  458. "id": "site property",
  459. "name": key,
  460. "value": value,
  461. "filename": filename
  462. });
  463. },
  464. createGlobalSiteObj: function () {
  465. var globalSiteProperties = {};
  466. //this.get('globals').filterProperty('domain', 'global').forEach(function (_globalSiteObj) {
  467. this.get('globals').forEach(function (_globalSiteObj) {
  468. // do not pass any globals whose name ends with _host or _hosts
  469. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  470. // append "m" to JVM memory options except for hadoop_heapsize
  471. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && _globalSiteObj.name !== 'hadoop_heapsize') {
  472. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  473. } else {
  474. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  475. }
  476. }
  477. }, this);
  478. return {"type": "global", "properties": globalSiteProperties};
  479. },
  480. createCoreSiteObj: function () {
  481. var serviceName = this.get('service.serviceName');
  482. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  483. var coreSiteProperties = {};
  484. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  485. var isOozieSelected = serviceName == 'OOZIE';
  486. var oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null;
  487. var isHiveSelected = serviceName == 'HIVE';
  488. var hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null;
  489. var isHcatSelected = serviceName == 'WEBHCAT';
  490. var hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null;
  491. coreSiteObj.forEach(function (_coreSiteObj) {
  492. 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'))) {
  493. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  494. }
  495. }, this);
  496. return {"type": "core-site", "properties": coreSiteProperties};
  497. },
  498. createSiteObj: function (name) {
  499. var fileName = name + '.xml';
  500. var configs = this.get('configs').filterProperty('filename', fileName);
  501. var properties = {};
  502. configs.forEach(function (_configProperty) {
  503. properties[_configProperty.name] = _configProperty.value;
  504. }, this);
  505. return {type: name, properties: properties};
  506. },
  507. applyConfigs: function () {
  508. if (this.get('service.serviceName') == 'GANGLIA' || App.testMode) {
  509. this.setTasksStatus(3, 'COMPLETED');
  510. } else {
  511. var serviceName = this.get('service.serviceName');
  512. App.ajax.send({
  513. name: 'reassign.check_configs',
  514. sender: this,
  515. data: {
  516. serviceName: serviceName
  517. },
  518. success: 'onCheckConfigsSuccess',
  519. error: 'onCheckConfigsError'
  520. });
  521. }
  522. },
  523. onCheckConfigsSuccess: function (configs) {
  524. var configTags = configs.ServiceInfo.desired_configs;
  525. if (!configTags) {
  526. this.setTasksStatus(0, 'FAILED');
  527. return;
  528. }
  529. for (var tag in configTags) {
  530. if (this.get('createdConfigs').contains(tag)) {
  531. configTags[tag] = this.get('newConfigsTag');
  532. }
  533. }
  534. var data = {config: configTags};
  535. var serviceName = this.get('service.serviceName');
  536. App.ajax.send({
  537. name: 'reassign.apply_configs',
  538. sender: this,
  539. data: {
  540. serviceName: serviceName,
  541. configs: data
  542. },
  543. beforeSend: 'onApplyConfigsBeforeSend',
  544. success: 'onApplyConfigsSuccess',
  545. error: 'onApplyConfigsError'
  546. });
  547. },
  548. onCheckConfigsError: function () {
  549. this.setTasksStatus(3, 'FAILED');
  550. },
  551. onApplyConfigsBeforeSend: function () {
  552. this.setTasksStatus(3, 'PENDING');
  553. },
  554. onApplyConfigsSuccess: function () {
  555. this.setTasksStatus(3, 'COMPLETED');
  556. },
  557. onApplyConfigsError: function () {
  558. this.setTasksStatus(3, 'FAILED');
  559. },
  560. putInMaintenanceMode: function () {
  561. if (App.testMode) {
  562. this.setTasksStatus(4, 'COMPLETED');
  563. } else {
  564. var hostName = this.get('content.reassign.host_id');
  565. var componentNames = [this.get('masterComponent.component_name')];
  566. if (this.get('isCohosted')) {
  567. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  568. this.set('queueTasksCompleted', 0);
  569. }
  570. componentNames.forEach(function (componentName) {
  571. App.ajax.send({
  572. name: 'reassign.maintenance_mode',
  573. sender: this,
  574. data: {
  575. hostName: hostName,
  576. componentName: componentName
  577. },
  578. beforeSend: 'onPutInMaintenanceModeBeforeSend',
  579. success: 'onPutInMaintenanceModeSuccess',
  580. error: 'onPutInMaintenanceModeError'
  581. });
  582. }, this);
  583. }
  584. },
  585. onPutInMaintenanceModeBeforeSend: function () {
  586. this.setTasksStatus(4, 'PENDING');
  587. },
  588. onPutInMaintenanceModeSuccess: function () {
  589. this.setTasksStatus(4, 'COMPLETED');
  590. },
  591. onPutInMaintenanceModeError: function () {
  592. this.setTasksStatus(4, 'FAILED');
  593. },
  594. installComponent: function () {
  595. this.set('currentRequestId', []);
  596. var componentNames = [this.get('masterComponent.component_name')];
  597. if (this.get('isCohosted')) {
  598. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  599. }
  600. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  601. componentNames.forEach(function (componentName) {
  602. App.ajax.send({
  603. name: 'reassign.install_component',
  604. sender: this,
  605. data: {
  606. hostName: hostName,
  607. componentName: componentName
  608. },
  609. beforeSend: 'onInstallComponentBeforeSend',
  610. success: 'onInstallComponentSuccess',
  611. error: 'onInstallComponentError'
  612. });
  613. }, this);
  614. },
  615. onInstallComponentBeforeSend: function () {
  616. this.setTasksStatus(5, 'PENDING');
  617. },
  618. onInstallComponentSuccess: function (data) {
  619. if (data) {
  620. var requestId = data.Requests.id;
  621. this.get('currentRequestId').push(requestId);
  622. this.saveClusterStatus(this.get('currentRequestId'), 'PENDING');
  623. if ((this.get('isCohosted') && this.get('currentRequestId.length') == 3) || !this.get('isCohosted')) {
  624. this.getLogsByRequest();
  625. }
  626. } else {
  627. this.setTasksStatus(5, 'FAILED');
  628. }
  629. },
  630. onInstallComponentError: function () {
  631. this.setTasksStatus(5, 'FAILED');
  632. },
  633. startComponents: function () {
  634. this.set('currentRequestId', []);
  635. var serviceNames = [this.get('masterComponent.service_id')];
  636. if (this.get('isCohosted')) {
  637. serviceNames = ['HIVE', 'WEBHCAT'];
  638. }
  639. serviceNames.forEach(function (serviceName) {
  640. App.ajax.send({
  641. name: 'reassign.start_components',
  642. sender: this,
  643. data: {
  644. serviceName: serviceName
  645. },
  646. beforeSend: 'onStartComponentsBeforeSend',
  647. success: 'onStartComponentsSuccess',
  648. error: 'onStartComponentsError'
  649. });
  650. }, this);
  651. },
  652. onStartComponentsBeforeSend: function () {
  653. this.setTasksStatus(6, 'PENDING');
  654. },
  655. onStartComponentsSuccess: function (data) {
  656. if (data) {
  657. var requestId = data.Requests.id;
  658. this.get('currentRequestId').push(requestId);
  659. this.saveClusterStatus(this.get('currentRequestId'), 'PENDING');
  660. if ((this.get('isCohosted') && this.get('currentRequestId.length') == 2) || !this.get('isCohosted')) {
  661. this.getLogsByRequest();
  662. }
  663. } else {
  664. this.setTasksStatus(6, 'FAILED');
  665. }
  666. },
  667. onStartComponentsError: function () {
  668. this.setTasksStatus(6, 'FAILED');
  669. },
  670. /**
  671. * Parse logs to define status of Start, Stop ot Install task
  672. * @param logs
  673. */
  674. parseLogs: function (logs) {
  675. var self = this;
  676. var task;
  677. var stopPolling = false;
  678. var polledData = [];
  679. logs.forEach(function (item) {
  680. polledData = polledData.concat(item.tasks);
  681. }, this);
  682. if (this.get('tasks')[0].status == 'COMPLETED') {
  683. task = this.get('tasks')[5].status == 'COMPLETED' ? 6 : 5;
  684. } else {
  685. task = 0;
  686. }
  687. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  688. if (polledData.someProperty('Tasks.status', 'FAILED')) {
  689. this.setTasksStatus(task, 'FAILED');
  690. } else {
  691. this.setTasksStatus(task, 'COMPLETED');
  692. }
  693. stopPolling = true;
  694. } else if (polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  695. if (task == 5) {
  696. this.get('tasks')[5].set('progress', 50);
  697. } else {
  698. var progress = polledData.filterProperty('Tasks.status', 'COMPLETED').length / polledData.length * 100;
  699. this.get('tasks')[task].set('progress', Math.round(progress));
  700. }
  701. this.setTasksStatus(task, 'IN_PROGRESS');
  702. }
  703. if (!stopPolling) {
  704. window.setTimeout(function () {
  705. self.getLogsByRequest()
  706. }, self.POLL_INTERVAL);
  707. }
  708. },
  709. POLL_INTERVAL: 4000,
  710. dataPollCounter: 1,
  711. getLogsByRequest: function () {
  712. this.set('logs', []);
  713. if (App.testMode) {
  714. var data = require('data/mock/step14PolledData/tasks_poll' + this.get('dataPollCounter'));
  715. this.set('dataPollCounter', this.get('dataPollCounter') + 1);
  716. if (this.get('dataPollCounter') == 6) {
  717. this.set('dataPollCounter', 1);
  718. }
  719. this.onGetLogsByRequestSuccess(data);
  720. } else {
  721. var requestIds = this.get('currentRequestId');
  722. requestIds.forEach(function (requestId) {
  723. App.ajax.send({
  724. name: 'reassign.get_logs',
  725. sender: this,
  726. data: {
  727. requestId: requestId
  728. },
  729. success: 'onGetLogsByRequestSuccess',
  730. error: 'onGetLogsByRequestError'
  731. });
  732. }, this);
  733. }
  734. },
  735. logs: [],
  736. onGetLogsByRequestSuccess: function (data) {
  737. this.get('logs').push(data);
  738. if (this.get('logs.length') == this.get('currentRequestId.length') || App.testMode) {
  739. this.parseLogs(this.get('logs'))
  740. }
  741. },
  742. onGetLogsByRequestError: function () {
  743. this.set('status', 'FAILED');
  744. },
  745. removeComponent: function () {
  746. if (App.testMode) {
  747. this.setTasksStatus(7, 'COMPLETED');
  748. } else {
  749. var hostName = this.get('content.reassign.host_id');
  750. var componentNames = [this.get('masterComponent.component_name')];
  751. if (this.get('isCohosted')) {
  752. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  753. this.set('queueTasksCompleted', 0);
  754. }
  755. componentNames.forEach(function (componentName) {
  756. App.ajax.send({
  757. name: 'reassign.remove_component',
  758. sender: this,
  759. data: {
  760. hostName: hostName,
  761. componentName: componentName
  762. },
  763. beforeSend: 'onRemoveComponentBeforeSend',
  764. success: 'onRemoveComponentSuccess',
  765. error: 'onRemoveComponentError'
  766. });
  767. }, this);
  768. }
  769. },
  770. onRemoveComponentBeforeSend: function () {
  771. this.setTasksStatus(7, 'PENDING');
  772. },
  773. onRemoveComponentSuccess: function () {
  774. this.setTasksStatus(7, 'COMPLETED');
  775. },
  776. onRemoveComponentError: function () {
  777. this.setTasksStatus(7, 'FAILED');
  778. },
  779. retry: function () {
  780. if (this.get('tasks')[5].status == 'FAILED') {
  781. this.installComponent();
  782. } else {
  783. this.startComponents();
  784. }
  785. this.set('showRetry', false);
  786. },
  787. abort: function () {
  788. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  789. var componentNames = [this.get('masterComponent.component_name')];
  790. if (this.get('isCohosted')) {
  791. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  792. this.set('queueTasksCompleted', 0);
  793. }
  794. componentNames.forEach(function (componentName) {
  795. App.ajax.send({
  796. name: 'reassign.maintenance_mode',
  797. sender: this,
  798. data: {
  799. hostName: hostName,
  800. componentName: componentName
  801. },
  802. success: 'onAbortMaintenance',
  803. error: 'onAbortError'
  804. });
  805. }, this);
  806. },
  807. onAbortMaintenance: function () {
  808. if (this.get('isCohosted') && this.get('queueTasksCompleted') < 2) {
  809. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  810. } else {
  811. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  812. var componentNames = [this.get('masterComponent.component_name')];
  813. if (this.get('isCohosted')) {
  814. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  815. this.set('queueTasksCompleted', 0);
  816. }
  817. componentNames.forEach(function (componentName) {
  818. App.ajax.send({
  819. name: 'reassign.remove_component',
  820. sender: this,
  821. data: {
  822. hostName: hostName,
  823. componentName: componentName
  824. },
  825. success: 'onAbortRemoveComponent',
  826. error: 'onAbortError'
  827. });
  828. }, this);
  829. }
  830. },
  831. onAbortRemoveComponent: function () {
  832. if (this.get('isCohosted') && this.get('queueTasksCompleted') < 2) {
  833. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  834. } else {
  835. var hostName = this.get('content.reassign.host_id');
  836. var componentNames = [this.get('masterComponent.component_name')];
  837. if (this.get('isCohosted')) {
  838. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  839. this.set('queueTasksCompleted', 0);
  840. }
  841. componentNames.forEach(function (componentName) {
  842. App.ajax.send({
  843. name: 'reassign.install_component',
  844. sender: this,
  845. data: {
  846. hostName: hostName,
  847. componentName: componentName
  848. },
  849. success: 'onAbortCompleted',
  850. error: 'onAbortError'
  851. });
  852. }, this);
  853. }
  854. },
  855. onAbortCompleted: function () {
  856. if (this.get('isCohosted') && this.get('queueTasksCompleted') < 2) {
  857. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  858. } else {
  859. App.clusterStatus.setClusterStatus({
  860. clusterName: this.get('content.cluster.name'),
  861. clusterState: 'REASSIGN_MASTER_ABORTED',
  862. wizardControllerName: this.get('content.controllerName'),
  863. localdb: App.db.data
  864. });
  865. App.router.send('back');
  866. }
  867. },
  868. onAbortError: function () {
  869. App.ModalPopup.show({
  870. header: Em.I18n.translations['common.error'],
  871. secondary: false,
  872. onPrimary: function () {
  873. this.hide();
  874. },
  875. bodyClass: Ember.View.extend({
  876. template: Ember.Handlebars.compile('<p>{{t installer.step14.abortError}}</p>')
  877. })
  878. });
  879. }
  880. })