step14_controller.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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.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. },
  196. beforeSend: 'onStopServiceBeforeSend',
  197. success: 'onStopServiceSuccess',
  198. error: 'onStopServiceError'
  199. });
  200. }, this);
  201. },
  202. onStopServiceBeforeSend: function () {
  203. this.setTasksStatus(0, 'PENDING');
  204. },
  205. onStopServiceSuccess: function (data) {
  206. if (data) {
  207. var requestId = data.Requests.id;
  208. this.get('currentRequestId').push(requestId);
  209. this.saveClusterStatus(this.get('currentRequestId'), 'PENDING');
  210. if ((this.get('isCohosted') && this.get('currentRequestId.length') == 2) || !this.get('isCohosted')) {
  211. this.getLogsByRequest();
  212. }
  213. } else {
  214. this.setTasksStatus(0, 'FAILED');
  215. }
  216. },
  217. onStopServiceError: function () {
  218. this.setTasksStatus(0, 'FAILED');
  219. },
  220. createMasterComponent: function () {
  221. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  222. var componentNames = [this.get('masterComponent.component_name')];
  223. if (this.get('isCohosted')) {
  224. this.set('queueTasksCompleted', 0);
  225. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  226. }
  227. componentNames.forEach(function (componentName) {
  228. if (App.testMode) {
  229. this.setTasksStatus(1, 'COMPLETED');
  230. } else {
  231. App.ajax.send({
  232. name: 'reassign.create_master',
  233. sender: this,
  234. data: {
  235. hostName: hostName,
  236. componentName: componentName
  237. },
  238. beforeSend: 'onCreateMasterComponentBeforeSend',
  239. success: 'onCreateMasterComponentSuccess',
  240. error: 'onCreateMasterComponentError'
  241. });
  242. }
  243. }, this);
  244. },
  245. onCreateMasterComponentBeforeSend: function () {
  246. this.setTasksStatus(1, 'PENDING');
  247. },
  248. onCreateMasterComponentSuccess: function () {
  249. this.setTasksStatus(1, 'COMPLETED');
  250. },
  251. onCreateMasterComponentError: function () {
  252. this.setTasksStatus(1, 'FAILED');
  253. },
  254. createConfigs: function () {
  255. if (this.get('service.serviceName') == 'GANGLIA' || App.testMode) {
  256. this.setTasksStatus(2, 'COMPLETED');
  257. } else {
  258. this.setTasksStatus(2, 'PENDING');
  259. this.loadGlobals();
  260. this.loadConfigs();
  261. this.set('newConfigsTag', 'version' + (new Date).getTime());
  262. var serviceName = this.get('service.serviceName');
  263. this.createConfigSite(this.createGlobalSiteObj());
  264. this.createConfigSite(this.createCoreSiteObj());
  265. if (serviceName == 'HDFS') {
  266. this.createConfigSite(this.createSiteObj('hdfs-site'));
  267. }
  268. if (serviceName == 'MAPREDUCE') {
  269. this.createConfigSite(this.createSiteObj('mapred-site'));
  270. }
  271. if (serviceName == 'HBASE') {
  272. this.createConfigSite(this.createSiteObj('hbase-site'));
  273. }
  274. if (serviceName == 'OOZIE') {
  275. this.createConfigSite(this.createSiteObj('oozie-site'));
  276. }
  277. if (serviceName == 'HIVE' || this.get('isCohosted')) {
  278. this.createConfigSite(this.createSiteObj('hive-site'));
  279. }
  280. if (serviceName == 'WEBHCAT' || this.get('isCohosted')) {
  281. this.createConfigSite(this.createSiteObj('webhcat-site'));
  282. }
  283. this.addObserver('createdConfigs.length', this, 'onCreateConfigsCompleted');
  284. this.onCreateConfigsCompleted();
  285. }
  286. },
  287. createConfigSite: function (configs) {
  288. configs.tag = this.get('newConfigsTag');
  289. App.ajax.send({
  290. name: 'reassign.create_configs',
  291. sender: this,
  292. data: {
  293. configs: configs
  294. },
  295. beforeSend: 'onCreateConfigsBeforeSend',
  296. success: 'onCreateConfigsSuccess',
  297. error: 'onCreateConfigsError'
  298. });
  299. },
  300. onCreateConfigsBeforeSend: function () {
  301. this.set('createdConfigsCount', this.get('createdConfigsCount') + 1);
  302. },
  303. onCreateConfigsSuccess: function (data, opts) {
  304. this.get('createdConfigs').pushObject(opts.configs.type);
  305. },
  306. onCreateConfigsError: function () {
  307. this.setTasksStatus(2, 'FAILED');
  308. },
  309. createdConfigsCount: 0,
  310. onCreateConfigsCompleted: function () {
  311. if (this.get('createdConfigs.length') == this.get('createdConfigsCount')) {
  312. this.setTasksStatus(2, 'COMPLETED');
  313. }
  314. },
  315. loadGlobals: function () {
  316. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  317. if (globals.someProperty('name', 'hive_database')) {
  318. //TODO: Hive host depends on the type of db selected. Change puppet variable name if postgres is not the default db
  319. var hiveDb = globals.findProperty('name', 'hive_database');
  320. if (hiveDb.value === 'New MySQL Database') {
  321. if (globals.someProperty('name', 'hive_ambari_host')) {
  322. globals.findProperty('name', 'hive_ambari_host').name = 'hive_mysql_hostname';
  323. }
  324. globals = globals.without(globals.findProperty('name', 'hive_existing_host'));
  325. globals = globals.without(globals.findProperty('name', 'hive_existing_database'));
  326. } else {
  327. globals.findProperty('name', 'hive_existing_host').name = 'hive_mysql_hostname';
  328. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  329. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  330. }
  331. }
  332. this.set('globals', globals);
  333. },
  334. loadConfigs: function () {
  335. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property').filterProperty('value');
  336. var uiConfigs = this.loadUiSideConfigs();
  337. this.set('configs', storedConfigs.concat(uiConfigs));
  338. },
  339. loadUiSideConfigs: function () {
  340. var uiConfig = [];
  341. var configs = this.get('configMapping').filterProperty('foreignKey', null);
  342. configs.forEach(function (_config) {
  343. var value = this.getGlobConfigValue(_config.templateName, _config.value, _config.name);
  344. uiConfig.pushObject({
  345. "id": "site property",
  346. "name": _config.name,
  347. "value": value,
  348. "filename": _config.filename
  349. });
  350. }, this);
  351. var dependentConfig = this.get('configMapping').filterProperty('foreignKey');
  352. dependentConfig.forEach(function (_config) {
  353. this.setConfigValue(uiConfig, _config);
  354. uiConfig.pushObject({
  355. "id": "site property",
  356. "name": _config.name,
  357. "value": _config.value,
  358. "filename": _config.filename
  359. });
  360. }, this);
  361. return uiConfig;
  362. },
  363. getGlobConfigValue: function (templateName, expression, name) {
  364. var express = expression.match(/<(.*?)>/g);
  365. var value = expression;
  366. if (express == null) {
  367. return expression;
  368. }
  369. express.forEach(function (_express) {
  370. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  371. if (this.get('globals').someProperty('name', templateName[index])) {
  372. var globValue = this.get('globals').findProperty('name', templateName[index]).value;
  373. // Hack for templeton.zookeeper.hosts
  374. 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
  375. if (name === "templeton.zookeeper.hosts" || name === 'hbase.zookeeper.quorum') {
  376. // globValue is an array of ZooKeeper Server hosts
  377. var zooKeeperPort = '2181';
  378. if (name === "templeton.zookeeper.hosts") {
  379. var zooKeeperServers = globValue.map(function (item) {
  380. return item + ':' + zooKeeperPort;
  381. }).join(',');
  382. value = value.replace(_express, zooKeeperServers);
  383. } else {
  384. value = value.replace(_express, globValue.join(','));
  385. }
  386. } else {
  387. value = value.replace(_express, globValue);
  388. }
  389. }
  390. } else {
  391. value = null;
  392. }
  393. }, this);
  394. return value;
  395. },
  396. /**
  397. * Set all site property that are derived from other site-properties
  398. */
  399. setConfigValue: function (uiConfig, config) {
  400. if (config.value == null) {
  401. return;
  402. }
  403. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  404. if (fkValue) {
  405. fkValue.forEach(function (_fkValue) {
  406. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  407. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  408. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  409. config.value = config.value.replace(_fkValue, globalValue);
  410. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  411. var globalValue;
  412. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  413. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  414. } else {
  415. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  416. }
  417. config.value = config.value.replace(_fkValue, globalValue);
  418. }
  419. }, this);
  420. }
  421. if (fkValue = config.name.match(/<(foreignKey.*?)>/g)) {
  422. fkValue.forEach(function (_fkValue) {
  423. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  424. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  425. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  426. config.name = config.name.replace(_fkValue, globalValue);
  427. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  428. var globalValue;
  429. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  430. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  431. } else {
  432. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  433. }
  434. config.name = config.name.replace(_fkValue, globalValue);
  435. }
  436. }, this);
  437. }
  438. //For properties in the configMapping file having foreignKey and templateName properties.
  439. var templateValue = config.value.match(/<(templateName.*?)>/g);
  440. if (templateValue) {
  441. templateValue.forEach(function (_value) {
  442. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  443. if (this.get('globals').someProperty('name', config.templateName[index])) {
  444. var globalValue = this.get('globals').findProperty('name', config.templateName[index]).value;
  445. config.value = config.value.replace(_value, globalValue);
  446. } else {
  447. config.value = null;
  448. }
  449. }, this);
  450. }
  451. },
  452. /**
  453. * Set property of the site variable
  454. */
  455. setSiteProperty: function (key, value, filename) {
  456. this.get('configs').pushObject({
  457. "id": "site property",
  458. "name": key,
  459. "value": value,
  460. "filename": filename
  461. });
  462. },
  463. createGlobalSiteObj: function () {
  464. var globalSiteProperties = {};
  465. //this.get('globals').filterProperty('domain', 'global').forEach(function (_globalSiteObj) {
  466. this.get('globals').forEach(function (_globalSiteObj) {
  467. // do not pass any globals whose name ends with _host or _hosts
  468. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  469. // append "m" to JVM memory options except for hadoop_heapsize
  470. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && _globalSiteObj.name !== 'hadoop_heapsize') {
  471. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  472. } else {
  473. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  474. }
  475. }
  476. }, this);
  477. return {"type": "global", "properties": globalSiteProperties};
  478. },
  479. createCoreSiteObj: function () {
  480. var serviceName = this.get('service.serviceName');
  481. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  482. var coreSiteProperties = {};
  483. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  484. var isOozieSelected = serviceName == 'OOZIE';
  485. var oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null;
  486. var isHiveSelected = serviceName == 'HIVE';
  487. var hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null;
  488. var isHcatSelected = serviceName == 'WEBHCAT';
  489. var hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null;
  490. coreSiteObj.forEach(function (_coreSiteObj) {
  491. 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'))) {
  492. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  493. }
  494. }, this);
  495. return {"type": "core-site", "properties": coreSiteProperties};
  496. },
  497. createSiteObj: function (name) {
  498. var fileName = name + '.xml';
  499. var configs = this.get('configs').filterProperty('filename', fileName);
  500. var properties = {};
  501. configs.forEach(function (_configProperty) {
  502. properties[_configProperty.name] = _configProperty.value;
  503. }, this);
  504. return {type: name, properties: properties};
  505. },
  506. applyConfigs: function () {
  507. if (this.get('service.serviceName') == 'GANGLIA' || App.testMode) {
  508. this.setTasksStatus(3, 'COMPLETED');
  509. } else {
  510. var serviceName = this.get('service.serviceName');
  511. App.ajax.send({
  512. name: 'reassign.check_configs',
  513. sender: this,
  514. data: {
  515. serviceName: serviceName
  516. },
  517. success: 'onCheckConfigsSuccess',
  518. error: 'onCheckConfigsError'
  519. });
  520. }
  521. },
  522. onCheckConfigsSuccess: function (configs) {
  523. var configTags = configs.ServiceInfo.desired_configs;
  524. if (!configTags) {
  525. this.setTasksStatus(0, 'FAILED');
  526. return;
  527. }
  528. for (var tag in configTags) {
  529. if (this.get('createdConfigs').contains(tag)) {
  530. configTags[tag] = this.get('newConfigsTag');
  531. }
  532. }
  533. var data = {config: configTags};
  534. var serviceName = this.get('service.serviceName');
  535. App.ajax.send({
  536. name: 'reassign.apply_configs',
  537. sender: this,
  538. data: {
  539. serviceName: serviceName,
  540. configs: data
  541. },
  542. beforeSend: 'onApplyConfigsBeforeSend',
  543. success: 'onApplyConfigsSuccess',
  544. error: 'onApplyConfigsError'
  545. });
  546. },
  547. onCheckConfigsError: function () {
  548. this.setTasksStatus(3, 'FAILED');
  549. },
  550. onApplyConfigsBeforeSend: function () {
  551. this.setTasksStatus(3, 'PENDING');
  552. },
  553. onApplyConfigsSuccess: function () {
  554. this.setTasksStatus(3, 'COMPLETED');
  555. },
  556. onApplyConfigsError: function () {
  557. this.setTasksStatus(3, 'FAILED');
  558. },
  559. putInMaintenanceMode: function () {
  560. if (App.testMode) {
  561. this.setTasksStatus(4, 'COMPLETED');
  562. } else {
  563. var hostName = this.get('content.reassign.host_id');
  564. var componentNames = [this.get('masterComponent.component_name')];
  565. if (this.get('isCohosted')) {
  566. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  567. this.set('queueTasksCompleted', 0);
  568. }
  569. componentNames.forEach(function (componentName) {
  570. App.ajax.send({
  571. name: 'reassign.maintenance_mode',
  572. sender: this,
  573. data: {
  574. hostName: hostName,
  575. componentName: componentName
  576. },
  577. beforeSend: 'onPutInMaintenanceModeBeforeSend',
  578. success: 'onPutInMaintenanceModeSuccess',
  579. error: 'onPutInMaintenanceModeError'
  580. });
  581. }, this);
  582. }
  583. },
  584. onPutInMaintenanceModeBeforeSend: function () {
  585. this.setTasksStatus(4, 'PENDING');
  586. },
  587. onPutInMaintenanceModeSuccess: function () {
  588. this.setTasksStatus(4, 'COMPLETED');
  589. },
  590. onPutInMaintenanceModeError: function () {
  591. this.setTasksStatus(4, 'FAILED');
  592. },
  593. installComponent: function () {
  594. this.set('currentRequestId', []);
  595. var componentNames = [this.get('masterComponent.component_name')];
  596. if (this.get('isCohosted')) {
  597. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  598. }
  599. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  600. componentNames.forEach(function (componentName) {
  601. App.ajax.send({
  602. name: 'reassign.install_component',
  603. sender: this,
  604. data: {
  605. hostName: hostName,
  606. componentName: componentName
  607. },
  608. beforeSend: 'onInstallComponentBeforeSend',
  609. success: 'onInstallComponentSuccess',
  610. error: 'onInstallComponentError'
  611. });
  612. }, this);
  613. },
  614. onInstallComponentBeforeSend: function () {
  615. this.setTasksStatus(5, 'PENDING');
  616. },
  617. onInstallComponentSuccess: function (data) {
  618. if (data) {
  619. var requestId = data.Requests.id;
  620. this.get('currentRequestId').push(requestId);
  621. this.saveClusterStatus(this.get('currentRequestId'), 'PENDING');
  622. if ((this.get('isCohosted') && this.get('currentRequestId.length') == 3) || !this.get('isCohosted')) {
  623. this.getLogsByRequest();
  624. }
  625. } else {
  626. this.setTasksStatus(5, 'FAILED');
  627. }
  628. },
  629. onInstallComponentError: function () {
  630. this.setTasksStatus(5, 'FAILED');
  631. },
  632. startComponents: function () {
  633. this.set('currentRequestId', []);
  634. var serviceNames = [this.get('masterComponent.service_id')];
  635. if (this.get('isCohosted')) {
  636. serviceNames = ['HIVE', 'WEBHCAT'];
  637. }
  638. serviceNames.forEach(function (serviceName) {
  639. App.ajax.send({
  640. name: 'reassign.start_components',
  641. sender: this,
  642. data: {
  643. serviceName: serviceName
  644. },
  645. beforeSend: 'onStartComponentsBeforeSend',
  646. success: 'onStartComponentsSuccess',
  647. error: 'onStartComponentsError'
  648. });
  649. }, this);
  650. },
  651. onStartComponentsBeforeSend: function () {
  652. this.setTasksStatus(6, 'PENDING');
  653. },
  654. onStartComponentsSuccess: function (data) {
  655. if (data) {
  656. var requestId = data.Requests.id;
  657. this.get('currentRequestId').push(requestId);
  658. this.saveClusterStatus(this.get('currentRequestId'), 'PENDING');
  659. if ((this.get('isCohosted') && this.get('currentRequestId.length') == 2) || !this.get('isCohosted')) {
  660. this.getLogsByRequest();
  661. }
  662. } else {
  663. this.setTasksStatus(6, 'FAILED');
  664. }
  665. },
  666. onStartComponentsError: function () {
  667. this.setTasksStatus(6, 'FAILED');
  668. },
  669. /**
  670. * Parse logs to define status of Start, Stop ot Install task
  671. * @param logs
  672. */
  673. parseLogs: function (logs) {
  674. var self = this;
  675. var task;
  676. var stopPolling = false;
  677. var polledData = [];
  678. logs.forEach(function (item) {
  679. polledData = polledData.concat(item.tasks);
  680. }, this);
  681. if (this.get('tasks')[0].status == 'COMPLETED') {
  682. task = this.get('tasks')[5].status == 'COMPLETED' ? 6 : 5;
  683. } else {
  684. task = 0;
  685. }
  686. if (!polledData.someProperty('Tasks.status', 'PENDING') && !polledData.someProperty('Tasks.status', 'QUEUED') && !polledData.someProperty('Tasks.status', 'IN_PROGRESS')) {
  687. if (polledData.someProperty('Tasks.status', 'FAILED')) {
  688. this.setTasksStatus(task, 'FAILED');
  689. } else {
  690. this.setTasksStatus(task, 'COMPLETED');
  691. }
  692. stopPolling = true;
  693. } else {
  694. if (polledData.length == 1) {
  695. this.get('tasks')[task].set('progress', 50);
  696. } else {
  697. var progress = polledData.filterProperty('Tasks.status', 'COMPLETED').length / polledData.length * 100;
  698. this.get('tasks')[task].set('progress', Math.round(progress));
  699. }
  700. this.setTasksStatus(task, 'IN_PROGRESS');
  701. }
  702. if (!stopPolling) {
  703. window.setTimeout(function () {
  704. self.getLogsByRequest()
  705. }, self.POLL_INTERVAL);
  706. }
  707. },
  708. POLL_INTERVAL: 4000,
  709. dataPollCounter: 1,
  710. getLogsByRequest: function () {
  711. this.set('logs', []);
  712. if (App.testMode) {
  713. var data = require('data/mock/step14PolledData/tasks_poll' + this.get('dataPollCounter'));
  714. this.set('dataPollCounter', this.get('dataPollCounter') + 1);
  715. if (this.get('dataPollCounter') == 6) {
  716. this.set('dataPollCounter', 1);
  717. }
  718. this.onGetLogsByRequestSuccess(data);
  719. } else {
  720. var requestIds = this.get('currentRequestId');
  721. requestIds.forEach(function (requestId) {
  722. App.ajax.send({
  723. name: 'reassign.get_logs',
  724. sender: this,
  725. data: {
  726. requestId: requestId
  727. },
  728. success: 'onGetLogsByRequestSuccess',
  729. error: 'onGetLogsByRequestError'
  730. });
  731. }, this);
  732. }
  733. },
  734. logs: [],
  735. onGetLogsByRequestSuccess: function (data) {
  736. this.get('logs').push(data);
  737. if (this.get('logs.length') == this.get('currentRequestId.length') || App.testMode) {
  738. this.parseLogs(this.get('logs'))
  739. }
  740. },
  741. onGetLogsByRequestError: function () {
  742. this.set('status', 'FAILED');
  743. },
  744. removeComponent: function () {
  745. if (App.testMode) {
  746. this.setTasksStatus(7, 'COMPLETED');
  747. } else {
  748. var hostName = this.get('content.reassign.host_id');
  749. var componentNames = [this.get('masterComponent.component_name')];
  750. if (this.get('isCohosted')) {
  751. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  752. this.set('queueTasksCompleted', 0);
  753. }
  754. componentNames.forEach(function (componentName) {
  755. App.ajax.send({
  756. name: 'reassign.remove_component',
  757. sender: this,
  758. data: {
  759. hostName: hostName,
  760. componentName: componentName
  761. },
  762. beforeSend: 'onRemoveComponentBeforeSend',
  763. success: 'onRemoveComponentSuccess',
  764. error: 'onRemoveComponentError'
  765. });
  766. }, this);
  767. }
  768. },
  769. onRemoveComponentBeforeSend: function () {
  770. this.setTasksStatus(7, 'PENDING');
  771. },
  772. onRemoveComponentSuccess: function () {
  773. this.setTasksStatus(7, 'COMPLETED');
  774. },
  775. onRemoveComponentError: function () {
  776. this.setTasksStatus(7, 'FAILED');
  777. },
  778. retry: function () {
  779. if (this.get('tasks')[5].status == 'FAILED') {
  780. this.installComponent();
  781. } else {
  782. this.startComponents();
  783. }
  784. this.set('showRetry', false);
  785. },
  786. abort: function () {
  787. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  788. var componentNames = [this.get('masterComponent.component_name')];
  789. if (this.get('isCohosted')) {
  790. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  791. this.set('queueTasksCompleted', 0);
  792. }
  793. componentNames.forEach(function (componentName) {
  794. App.ajax.send({
  795. name: 'reassign.maintenance_mode',
  796. sender: this,
  797. data: {
  798. hostName: hostName,
  799. componentName: componentName
  800. },
  801. success: 'onAbortMaintenance',
  802. error: 'onAbortError'
  803. });
  804. }, this);
  805. },
  806. onAbortMaintenance: function () {
  807. if (this.get('isCohosted') && this.get('queueTasksCompleted') < 2) {
  808. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  809. } else {
  810. var hostName = this.get('content.masterComponentHosts').findProperty('component', this.get('content.reassign.component_name')).hostName;
  811. var componentNames = [this.get('masterComponent.component_name')];
  812. if (this.get('isCohosted')) {
  813. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  814. this.set('queueTasksCompleted', 0);
  815. }
  816. componentNames.forEach(function (componentName) {
  817. App.ajax.send({
  818. name: 'reassign.remove_component',
  819. sender: this,
  820. data: {
  821. hostName: hostName,
  822. componentName: componentName
  823. },
  824. success: 'onAbortRemoveComponent',
  825. error: 'onAbortError'
  826. });
  827. }, this);
  828. }
  829. },
  830. onAbortRemoveComponent: function () {
  831. if (this.get('isCohosted') && this.get('queueTasksCompleted') < 2) {
  832. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  833. } else {
  834. var hostName = this.get('content.reassign.host_id');
  835. var componentNames = [this.get('masterComponent.component_name')];
  836. if (this.get('isCohosted')) {
  837. componentNames = ['HIVE_SERVER', 'WEBHCAT_SERVER', 'MYSQL_SERVER'];
  838. this.set('queueTasksCompleted', 0);
  839. }
  840. componentNames.forEach(function (componentName) {
  841. App.ajax.send({
  842. name: 'reassign.install_component',
  843. sender: this,
  844. data: {
  845. hostName: hostName,
  846. componentName: componentName
  847. },
  848. success: 'onAbortCompleted',
  849. error: 'onAbortError'
  850. });
  851. }, this);
  852. }
  853. },
  854. onAbortCompleted: function () {
  855. if (this.get('isCohosted') && this.get('queueTasksCompleted') < 2) {
  856. this.set('queueTasksCompleted', this.get('queueTasksCompleted') + 1);
  857. } else {
  858. App.clusterStatus.setClusterStatus({
  859. clusterName: this.get('content.cluster.name'),
  860. clusterState: 'REASSIGN_MASTER_ABORTED',
  861. wizardControllerName: this.get('content.controllerName'),
  862. localdb: App.db.data
  863. });
  864. App.router.send('back');
  865. }
  866. },
  867. onAbortError: function () {
  868. App.ModalPopup.show({
  869. header: Em.I18n.translations['common.error'],
  870. secondary: false,
  871. onPrimary: function () {
  872. this.hide();
  873. },
  874. bodyClass: Ember.View.extend({
  875. template: Ember.Handlebars.compile('<p>{{t installer.step14.abortError}}</p>')
  876. })
  877. });
  878. }
  879. })