configs.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  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. require('controllers/wizard/slave_component_groups_controller');
  20. App.MainServiceInfoConfigsController = Em.Controller.extend({
  21. name: 'mainServiceInfoConfigsController',
  22. stepConfigs: [], //contains all field properties that are viewed in this service
  23. selectedService: null,
  24. serviceConfigTags: null,
  25. globalConfigs: [],
  26. uiConfigs: [],
  27. isApplyingChanges: false,
  28. serviceConfigs: require('data/service_configs'),
  29. configs: require('data/config_properties').configProperties,
  30. configMapping: require('data/config_mapping'),
  31. customConfigs: require('data/custom_configs'),
  32. isSubmitDisabled: function () {
  33. return (!(this.stepConfigs.everyProperty('errorCount', 0)) || this.get('isApplyingChanges'));
  34. }.property('stepConfigs.@each.errorCount', 'isApplyingChanges'),
  35. slaveComponentHosts: function () {
  36. if (!this.get('content')) {
  37. return;
  38. }
  39. console.log('slaveComponentHosts', App.db.getSlaveComponentHosts());
  40. return App.db.getSlaveComponentHosts();
  41. }.property('content'),
  42. clearStep: function () {
  43. this.get('stepConfigs').clear();
  44. this.get('globalConfigs').clear();
  45. if (this.get('serviceConfigTags')) {
  46. this.set('serviceConfigTags', null);
  47. }
  48. },
  49. serviceConfigProperties: function () {
  50. return App.db.getServiceConfigProperties();
  51. }.property('content'),
  52. /**
  53. * On load function
  54. */
  55. loadStep: function () {
  56. console.log("TRACE: Loading configure for service");
  57. this.clearStep();
  58. //STEP 1: set the present state of the service Properties. State depends on array of: unique combination of type(ex. core-site) and tag (ex. version01) derived from serviceInfo desired_state
  59. this.setServciceConfigs();
  60. //STEP 2: Create an array of objects defining tagnames to be polled and new tagnames to be set after submit
  61. this.setServiceTagNames();
  62. //STEP 3: Set globalConfigs and Get an array of serviceProperty objects
  63. var serviceConfigs = this.getSitesConfigProperties();
  64. //STEP 4: Remove properties mentioned in configMapping from serviceConfig
  65. this.get('configMapping').forEach(function (_configs) {
  66. }, this)
  67. //STEP 5: Add the advanced configs to the serviceConfigs property
  68. var advancedConfig = App.router.get('installerController').loadAdvancedConfig(this.get('content.serviceName')) || [];
  69. var service = this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'));
  70. advancedConfig.forEach(function (_config) {
  71. if (service) {
  72. if (!this.get('configMapping').someProperty('name', _config.name)) {
  73. if (service.configs.someProperty('name', _config.name)) {
  74. service.configs.findProperty('name', _config.name).description = _config.description;
  75. } else {
  76. _config.id = "site property";
  77. _config.category = 'Advanced';
  78. _config.displayName = _config.name;
  79. _config.defaultValue = _config.value;
  80. if (/\${.*}/.test(_config.value) || (service.serviceName !== 'OOZIE' && service.serviceName !== 'HBASE')) {
  81. _config.isRequired = false;
  82. _config.value = '';
  83. } else if (/^\s+$/.test(_config.value)) {
  84. _config.isRequired = false;
  85. }
  86. _config.isVisible = true;
  87. _config.displayType = 'advanced';
  88. service.configs.pushObject(_config);
  89. }
  90. }
  91. }
  92. }, this);
  93. this.loadCustomConfig();
  94. this.renderServiceConfigs(this.get('serviceConfigs'));
  95. console.log('---------------------------------------');
  96. },
  97. /**
  98. * Get configuration for the *-site.xml
  99. */
  100. setServciceConfigs: function () {
  101. var self = this;
  102. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/services/' + this.get('content.serviceName');
  103. $.ajax({
  104. type: 'GET',
  105. url: url,
  106. async: false,
  107. timeout: 10000,
  108. dataType: 'text',
  109. success: function (data) {
  110. console.log("TRACE: In success function for the GET getServciceConfigs call");
  111. console.log("TRACE: The url is: " + url);
  112. var jsonData = jQuery.parseJSON(data);
  113. self.set('serviceConfigTags', jQuery.parseJSON(jsonData.ServiceInfo.desired_configs));
  114. },
  115. error: function (request, ajaxOptions, error) {
  116. console.log("TRACE: In error function for the getServciceConfigs call");
  117. console.log("TRACE: value of the url is: " + url);
  118. console.log("TRACE: error code status is: " + request.status);
  119. },
  120. statusCode: require('data/statusCodes')
  121. });
  122. },
  123. /**
  124. * set tagnames for configuration of the *-site.xml
  125. */
  126. setServiceTagNames: function () {
  127. console.log("TRACE: In setServiceTagNames function:");
  128. var newServiceConfigTags = [];
  129. var serviceConfigTags = this.get('serviceConfigTags');
  130. var time = new Date().getMilliseconds();
  131. console.log("The value of time is: " + time);
  132. for (var index in serviceConfigTags) {
  133. console.log("The value of serviceConfigTags[index]: " + serviceConfigTags[index]);
  134. newServiceConfigTags.pushObject({
  135. siteName: index,
  136. tagName: serviceConfigTags[index],
  137. newTagName: serviceConfigTags[index] + time
  138. }, this);
  139. }
  140. this.set('serviceConfigTags', newServiceConfigTags);
  141. },
  142. /**
  143. * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
  144. */
  145. loadCustomConfig: function () {
  146. var serviceConfig = this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'));
  147. var customConfig = this.get('customConfigs').findProperty('serviceName', this.get('content.serviceName'));
  148. serviceConfig.configs.pushObject(customConfig);
  149. },
  150. /**
  151. * load the configs from the server
  152. */
  153. getSitesConfigProperties: function () {
  154. var serviceConfigs = [];
  155. var globalConfigs = [];
  156. var localServiceConfigs = this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'));
  157. this.get('serviceConfigTags').forEach(function (_tag) {
  158. var properties = this.getSiteConfigProperties(_tag.siteName, _tag.tagName);
  159. for (var index in properties) {
  160. var serviceConfigObj = {
  161. name: index,
  162. value: properties[index],
  163. defaultValue: properties[index],
  164. filename: _tag.siteName + ".xml",
  165. isVisible: true,
  166. isRequired: true
  167. };
  168. if (_tag.siteName === 'global') {
  169. if (localServiceConfigs.configs.someProperty('name', index)) {
  170. var item = localServiceConfigs.configs.findProperty('name', index);
  171. item.value = properties[index];
  172. item.defaultValue = properties[index];
  173. if (item.displayType === 'int') {
  174. if (/\d+m$/.test(item.value)) {
  175. item.value = item.value.slice(0, item.value.length - 1);
  176. item.defaultValue = item.value;
  177. }
  178. }
  179. if (item.displayType === 'checkbox') {
  180. switch (item.value) {
  181. case 'true' :
  182. item.value = true;
  183. break;
  184. case 'false' :
  185. item.value = false;
  186. break;
  187. }
  188. }
  189. }
  190. serviceConfigObj.id = 'puppet var';
  191. serviceConfigObj.serviceName = this.get('configs').someProperty('name', index) ? this.get('configs').findProperty('name', index).serviceName : null;
  192. serviceConfigObj.category = this.get('configs').someProperty('name', index) ? this.get('configs').findProperty('name', index).category : null;
  193. globalConfigs.pushObject(serviceConfigObj);
  194. } else if (!this.get('configMapping').someProperty('name', index)) {
  195. if (_tag.siteName !== localServiceConfigs.filename) {
  196. serviceConfigObj.isVisible = false;
  197. }
  198. serviceConfigObj.id = 'site property';
  199. serviceConfigObj.serviceName = this.get('content.serviceName');
  200. serviceConfigObj.category = 'Advanced';
  201. serviceConfigObj.displayName = index;
  202. serviceConfigObj.displayType = 'advanced';
  203. localServiceConfigs.configs.pushObject(serviceConfigObj);
  204. }
  205. serviceConfigs.pushObject(serviceConfigObj);
  206. }
  207. }, this);
  208. this.set('globalConfigs', globalConfigs);
  209. return serviceConfigs;
  210. },
  211. getSiteConfigProperties: function (sitename, tagname) {
  212. var self = this;
  213. var properties = {};
  214. var url = App.apiPrefix + '/clusters/' + App.router.getClusterName() + '/configurations/?type=' + sitename + '&tag=' + tagname;
  215. $.ajax({
  216. type: 'GET',
  217. url: url,
  218. async: false,
  219. timeout: 10000,
  220. dataType: 'json',
  221. success: function (data) {
  222. console.log("TRACE: In success function for the GET getSiteConfigProperties call");
  223. console.log("TRACE: The url is: " + url);
  224. properties = data.items.findProperty('tag', tagname).properties;
  225. console.log("The value of config properties is: " + properties);
  226. },
  227. error: function (request, ajaxOptions, error) {
  228. console.log("TRACE: In error function for the getServciceConfigs call");
  229. console.log("TRACE: value of the url is: " + url);
  230. console.log("TRACE: error code status is: " + request.status);
  231. },
  232. statusCode: require('data/statusCodes')
  233. });
  234. return properties;
  235. },
  236. /**
  237. * Render configs for active services
  238. * @param serviceConfigs
  239. */
  240. renderServiceConfigs: function (serviceConfigs) {
  241. serviceConfigs.forEach(function (_serviceConfig) {
  242. var serviceConfig = App.ServiceConfig.create({
  243. filename: _serviceConfig.filename,
  244. serviceName: _serviceConfig.serviceName,
  245. displayName: _serviceConfig.displayName,
  246. configCategories: _serviceConfig.configCategories,
  247. configs: []
  248. });
  249. if (this.get('content.serviceName') && this.get('content.serviceName').toUpperCase() === serviceConfig.serviceName) {
  250. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  251. console.log('pushing ' + serviceConfig.serviceName);
  252. this.get('stepConfigs').pushObject(serviceConfig);
  253. } else {
  254. console.log('skipping ' + serviceConfig.serviceName);
  255. }
  256. }, this);
  257. this.set('selectedService', this.get('stepConfigs').objectAt(0));
  258. },
  259. /**
  260. * Load child components to service config object
  261. * @param _componentConfig
  262. * @param componentConfig
  263. */
  264. loadComponentConfigs: function (_componentConfig, componentConfig) {debugger;
  265. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  266. console.log("config", _serviceConfigProperty);
  267. if(!_serviceConfigProperty) return;
  268. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  269. serviceConfigProperty.serviceConfig = componentConfig;
  270. this.initialValue(serviceConfigProperty);
  271. componentConfig.configs.pushObject(serviceConfigProperty);
  272. serviceConfigProperty.validate();
  273. console.log("config result", serviceConfigProperty);
  274. }, this);
  275. console.log("+++++++++++++++++++++++++++++++++++++++++");
  276. },
  277. restartServicePopup: function (event) {
  278. console.log("Enered the entry pointttt");
  279. var self = this;
  280. var result;
  281. console.log('I am over hererererere: ' + this.get('content.healthStatus'));
  282. if (this.get('isApplyingChanges') === true) {
  283. return;
  284. }
  285. App.ModalPopup.show({
  286. header: 'Restart ' + self.get('content.serviceName'),
  287. primary: 'Restart',
  288. onPrimary: function () {
  289. self.restartService();
  290. this.hide();
  291. },
  292. onSecondary: function () {
  293. this.hide();
  294. },
  295. bodyClass: Ember.View.extend({
  296. template: Ember.Handlebars.compile(['<p>Restart the service</p>'].join('\n'))
  297. })
  298. });
  299. },
  300. restartService: function () {
  301. console.log("In restart servicesssss");
  302. this.set('isApplyingChanges', true);
  303. this.get('serviceConfigTags').forEach(function (_tag) {
  304. _tag.newTagName = _tag.newTagName + new Date().getMilliseconds();
  305. }, this);
  306. //Step 1: Stop the service
  307. if (this.stopService()) {
  308. this.doPolling('stop', function () {
  309. this.applyConfigurations();
  310. }, function () {
  311. this.failuresInStop();
  312. });
  313. } else {
  314. this.failuresInStop();
  315. }
  316. },
  317. failuresInStop: function () {
  318. console.log("Step 1 faliure");
  319. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Failed to stop the service');
  320. this.set('isApplyingChanges', false);
  321. },
  322. applyConfigurations: function () {
  323. if (App.testMode === true) {
  324. result = true
  325. } else {
  326. var result = this.saveServiceConfigProperties();
  327. }
  328. if (result === false) {
  329. console.log("Step2 failure");
  330. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Failed to apply configs. Start the service again with last configurations', this.startServiceWrapper);
  331. } else {
  332. if (this.startService()) {
  333. this.doPolling('start', function () {
  334. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Restarted the service successfully with new configurations');
  335. this.set('isApplyingChanges', false);
  336. }, function () {
  337. // this.rollBackPopup('Configs applied but failures encountered during starting/checking service. Do you want to rollback to the last service configuration and restart the service.');
  338. console.log("Configs applied but failures encountered during starting/checking service.");
  339. });
  340. } else {
  341. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Failed to start the service');
  342. this.set('isApplyingChanges', false);
  343. }
  344. console.log("Error in start service API");
  345. }
  346. },
  347. startServiceWrapper: function () {
  348. if (this.startService()) {
  349. this.doPolling('start', function () {
  350. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Started the service with the last known configuration.');
  351. this.set('isApplyingChanges', false);
  352. }, function () {
  353. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Started the service with the last known configuration.');
  354. this.set('isApplyingChanges', false);
  355. });
  356. } else {
  357. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Started the service with the last known configuration.');
  358. this.set('isApplyingChanges', false);
  359. }
  360. },
  361. rollBack: function () {
  362. var result;
  363. //STEP 1: Apply the last known configuration
  364. result = this.applyCreatedConfToService('previous');
  365. //CASE 1: failure for rollback
  366. if (result === false) {
  367. console.log("rollback1 faliure");
  368. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Failed to rolled back to the last known configuration');
  369. } else {
  370. //STEP 2: start the service
  371. if (this.startService()) {
  372. this.doPolling('start', function () {
  373. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Successfully rolled back to the last known configuration');
  374. this.set('isApplyingChanges', false);
  375. }, function () {
  376. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Rolled back to the last configuration but failed to start the service with the rolled back configuration');
  377. this.set('isApplyingChanges', false);
  378. });
  379. } else {
  380. this.msgPopup('Restart ' + this.get('content.serviceName'), 'Rolled back to the last configuration but failed to start the service with the rolled back configuration');
  381. this.set('isApplyingChanges', false);
  382. }
  383. }
  384. },
  385. startService: function () {
  386. var self = this;
  387. var clusterName = App.router.getClusterName();
  388. var url = App.apiPrefix + '/clusters/' + clusterName + '/services/' + this.get('content.serviceName');
  389. var method = (App.testMode) ? 'GET' : 'PUT';
  390. var data = '{"ServiceInfo": {"state": "STARTED"}}';
  391. var result;
  392. $.ajax({
  393. type: method,
  394. url: url,
  395. data: data,
  396. async: false,
  397. dataType: 'text',
  398. timeout: 5000,
  399. success: function (data) {
  400. var jsonData = jQuery.parseJSON(data);
  401. console.log("TRACE: In success function for the startService call");
  402. console.log("TRACE: value of the url is: " + url);
  403. result = true;
  404. },
  405. error: function (request, ajaxOptions, error) {
  406. console.log("TRACE: In error function for the startService call");
  407. console.log("TRACE: value of the url is: " + url);
  408. console.log("TRACE: error code status is: " + request.status);
  409. result = (App.testMode) ? true : false;
  410. },
  411. statusCode: require('data/statusCodes')
  412. });
  413. return result;
  414. },
  415. msgPopup: function (header, message, callback) {
  416. var self = this;
  417. var result;
  418. App.ModalPopup.show({
  419. header: 'Restart ' + self.get('content.serviceName'),
  420. secondary: false,
  421. onPrimary: function () {
  422. if (callback !== undefined) {
  423. callback();
  424. }
  425. this.hide();
  426. },
  427. bodyClass: Ember.View.extend({
  428. template: Ember.Handlebars.compile(['<p>{{view.message}}</p>'].join('\n')),
  429. message: message
  430. })
  431. });
  432. },
  433. rollBackPopup: function (message) {
  434. var self = this;
  435. var result;
  436. App.ModalPopup.show({
  437. header: 'Restart ' + self.get('content.serviceName'),
  438. primary: 'Yes',
  439. secondary: 'No',
  440. onPrimary: function () {
  441. self.rollBack();
  442. this.hide();
  443. },
  444. bodyClass: Ember.View.extend({
  445. template: Ember.Handlebars.compile(['<p>{{view.message}}</p>'].join('\n')),
  446. message: message
  447. })
  448. });
  449. },
  450. stopService: function () {
  451. var self = this;
  452. var clusterName = App.router.getClusterName();
  453. var url = App.apiPrefix + '/clusters/' + clusterName + '/services/' + this.get('content.serviceName');
  454. var method = (App.testMode) ? 'GET' : 'PUT';
  455. var data = '{"ServiceInfo": {"state": "INSTALLED"}}';
  456. var result;
  457. $.ajax({
  458. type: method,
  459. url: url,
  460. data: data,
  461. async: false,
  462. dataType: 'text',
  463. timeout: 5000,
  464. success: function (data) {
  465. var jsonData = jQuery.parseJSON(data);
  466. console.log("TRACE: In success function for the stopService call");
  467. console.log("TRACE: value of the url is: " + url);
  468. result = true;
  469. },
  470. error: function (request, ajaxOptions, error) {
  471. console.log("TRACE: STep8 -> In error function for the stopService call");
  472. console.log("TRACE: STep8 -> value of the url is: " + url);
  473. console.log("TRACE: STep8 -> error code status is: " + request.status);
  474. result = (App.testMode) ? true : false;
  475. },
  476. statusCode: require('data/statusCodes')
  477. });
  478. return result;
  479. },
  480. /**
  481. * Save config properties
  482. */
  483. saveServiceConfigProperties: function () {
  484. var result = false;
  485. var configs = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName')).get('configs');
  486. this.saveGlobalConfigs(configs);
  487. this.saveSiteConfigs(configs);
  488. this.setCustomConfigs();
  489. var result = this.createConfigurations();
  490. if (result === true) {
  491. result = this.applyCreatedConfToService('new');
  492. }
  493. console.log("The result from applyCreatdConfToService is: " + result);
  494. return result;
  495. },
  496. saveGlobalConfigs: function (configs) {
  497. var globalConfigs = this.get('globalConfigs');
  498. configs.filterProperty('id', 'puppet var').forEach(function (_config) {
  499. if (globalConfigs.someProperty('name', _config.name)) {
  500. globalConfigs.findProperty('name', _config.name).value = _config.value;
  501. } else {
  502. globalConfigs.pushObject({
  503. name: _config.name,
  504. value: _config.value
  505. });
  506. }
  507. }, this);
  508. this.set('globalConfigs', globalConfigs);
  509. },
  510. saveSiteConfigs: function (configs) {
  511. var storedConfigs = this.get('stepConfigs').filterProperty('id', 'site property').filterProperty('value');
  512. var uiConfigs = this.loadUiSideConfigs();
  513. this.set('uiConfigs', storedConfigs.concat(uiConfigs));
  514. },
  515. loadUiSideConfigs: function () {
  516. var uiConfig = [];
  517. var configs = this.get('configMapping').filterProperty('foreignKey', null);
  518. configs.forEach(function (_config) {
  519. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  520. uiConfig.pushObject({
  521. "id": "site property",
  522. "name": _config.name,
  523. "value": value,
  524. "filename": _config.filename
  525. });
  526. }, this);
  527. var dependentConfig = this.get('configMapping').filterProperty('foreignKey');
  528. dependentConfig.forEach(function (_config) {
  529. this.setConfigValue(uiConfig, _config);
  530. uiConfig.pushObject({
  531. "id": "site property",
  532. "name": _config.name,
  533. "value": _config.value,
  534. "filename": _config.filename
  535. });
  536. }, this);
  537. return uiConfig;
  538. },
  539. /**
  540. * Set all site property that are derived from other puppet-variable
  541. */
  542. getGlobConfigValue: function (templateName, expression) {
  543. var express = expression.match(/<(.*?)>/g);
  544. var value = expression;
  545. if (express == null) {
  546. return expression;
  547. }
  548. express.forEach(function (_express) {
  549. //console.log("The value of template is: " + _express);
  550. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  551. if (this.get('globalConfigs').someProperty('name', templateName[index])) {
  552. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  553. var globValue = this.get('globalConfigs').findProperty('name', templateName[index]).value;
  554. value = value.replace(_express, globValue);
  555. } else {
  556. /*
  557. console.log("ERROR: The variable name is: " + templateName[index]);
  558. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  559. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  560. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  561. */
  562. value = null;
  563. }
  564. }, this);
  565. return value;
  566. },
  567. /**
  568. * Set all site property that are derived from other site-properties
  569. */
  570. setConfigValue: function (uiConfig, config) {
  571. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  572. if (fkValue) {
  573. fkValue.forEach(function (_fkValue) {
  574. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  575. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  576. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  577. config.value = config.value.replace(_fkValue, globalValue);
  578. } else if (this.get('stepConfigs').someProperty('name', config.foreignKey[index])) {
  579. var globalValue;
  580. if (this.get('stepConfigs').findProperty('name', config.foreignKey[index]).value === '') {
  581. globalValue = this.get('stepConfigs').findProperty('name', config.foreignKey[index]).defaultValue;
  582. } else {
  583. globalValue = this.get('stepConfigs').findProperty('name', config.foreignKey[index]).value;
  584. }
  585. config.value = config.value.replace(_fkValue, globalValue);
  586. }
  587. }, this);
  588. }
  589. if (fkValue = config.name.match(/<(foreignKey.*?)>/g)) {
  590. fkValue.forEach(function (_fkValue) {
  591. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  592. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  593. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  594. config.name = config.name.replace(_fkValue, globalValue);
  595. } else if (this.get('stepConfigs').someProperty('name', config.foreignKey[index])) {
  596. var globalValue;
  597. if (this.get('stepConfigs').findProperty('name', config.foreignKey[index]).value === '') {
  598. globalValue = this.get('stepConfigs').findProperty('name', config.foreignKey[index]).defaultValue;
  599. } else {
  600. globalValue = this.get('stepConfigs').findProperty('name', config.foreignKey[index]).value;
  601. }
  602. config.name = config.name.replace(_fkValue, globalValue);
  603. }
  604. }, this);
  605. }
  606. //For properties in the configMapping file having foreignKey and templateName properties.
  607. var templateValue = config.value.match(/<(templateName.*?)>/g);
  608. if (templateValue) {
  609. templateValue.forEach(function (_value) {
  610. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  611. if (this.get('globalConfigs').someProperty('name', config.templateName[index])) {
  612. var globalValue = this.get('globalConfigs').findProperty('name', config.templateName[index]).value;
  613. config.value = config.value.replace(_value, globalValue);
  614. }
  615. }, this);
  616. }
  617. },
  618. createConfigurations: function () {
  619. var result = true;
  620. var serviceConfigTags = this.get('serviceConfigTags');
  621. serviceConfigTags.forEach(function (_serviceTags) {
  622. if (_serviceTags.siteName === 'global') {
  623. console.log("TRACE: Inside globalssss");
  624. result = this.createConfigSite(this.createGlobalSiteObj(_serviceTags.newTagName));
  625. } else if (_serviceTags.siteName === 'core-site') {
  626. console.log("TRACE: Inside core-site");
  627. result = this.createConfigSite(this.createCoreSiteObj(_serviceTags.newTagName));
  628. } else {
  629. result = this.createConfigSite(this.createSiteObj(_serviceTags.siteName, _serviceTags.newTagName));
  630. }
  631. if (result === false) {
  632. return false;
  633. }
  634. }, this);
  635. return true;
  636. },
  637. createConfigSite: function (data) {
  638. var result;
  639. var realData = data;
  640. console.log("Inside createConfigSite");
  641. var clusterName = App.router.getClusterName();
  642. var url = App.apiPrefix + '/clusters/' + clusterName + '/configurations';
  643. $.ajax({
  644. type: 'POST',
  645. url: url,
  646. data: JSON.stringify(data),
  647. async: false,
  648. dataType: 'text',
  649. timeout: 5000,
  650. success: function (data) {
  651. var jsonData = jQuery.parseJSON(data);
  652. result = true;
  653. console.log("TRACE: In success function for the createConfigSite");
  654. console.log("TRACE: value of the url is: " + url);
  655. console.log("TRACE: value of the received data is: " + jsonData);
  656. },
  657. error: function (request, ajaxOptions, error) {
  658. result = false;
  659. console.log('TRACE: In Error ');
  660. console.log("The original data was: " + JSON.stringify(realData));
  661. console.log('TRACE: Error message is: ' + request.responseText);
  662. console.log("TRACE: value of the url is: " + url);
  663. },
  664. statusCode: require('data/statusCodes')
  665. });
  666. console.log("Exiting createConfigSite");
  667. console.log("Value of result is: " + result);
  668. return result;
  669. },
  670. createGlobalSiteObj: function (tagName) {
  671. var globalSiteProperties = {};
  672. this.get('globalConfigs').forEach(function (_globalSiteObj) {
  673. // do not pass any globalConfigs whose name ends with _host or _hosts
  674. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  675. // append "m" to JVM memory options
  676. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name)) {
  677. _globalSiteObj.value += "m";
  678. }
  679. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  680. //console.log("TRACE: name of the global property is: " + _globalSiteObj.name);
  681. //console.log("TRACE: value of the global property is: " + _globalSiteObj.value);
  682. }
  683. }, this);
  684. return {"type": "global", "tag": tagName, "properties": globalSiteProperties};
  685. },
  686. createCoreSiteObj: function (tagName) {
  687. var coreSiteObj = this.get('uiConfigs').filterProperty('filename', 'core-site.xml');
  688. var coreSiteProperties = {};
  689. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  690. var isOozieSelected = (this.get('content.serviceName') === 'OOZIE');
  691. coreSiteObj.forEach(function (_coreSiteObj) {
  692. if (isOozieSelected || _coreSiteObj.name != 'hadoop.proxyuser.oozie.hosts') {
  693. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  694. }
  695. //console.log("TRACE: name of the property is: " + _coreSiteObj.name);
  696. //console.log("TRACE: value of the property is: " + _coreSiteObj.value);
  697. }, this);
  698. return {"type": "core-site", "tag": tagName, "properties": coreSiteProperties};
  699. },
  700. createSiteObj: function (siteName, tagName) {
  701. var siteObj = this.get('uiConfigs').filterProperty('filename', siteName + ".xml");
  702. var siteProperties = {};
  703. siteObj.forEach(function (_siteObj) {
  704. siteProperties[_siteObj.name] = _siteObj.value;
  705. }, this);
  706. return {"type": siteName, "tag": tagName, "properties": siteProperties};
  707. },
  708. applyCreatedConfToService: function (configStatus) {
  709. var result;
  710. var clusterName = App.router.getClusterName();
  711. var url = App.apiPrefix + '/clusters/' + clusterName + '/services/' + this.get('content.serviceName');
  712. var data = this.getConfigForService(configStatus);
  713. var realData = data;
  714. $.ajax({
  715. type: 'PUT',
  716. url: url,
  717. async: false,
  718. dataType: 'text',
  719. data: JSON.stringify(data),
  720. timeout: 5000,
  721. success: function (data) {
  722. var jsonData = jQuery.parseJSON(data);
  723. console.log("TRACE: In success function for the applyCreatedConfToService call");
  724. console.log("TRACE: value of the url is: " + url);
  725. result = true;
  726. },
  727. error: function (request, ajaxOptions, error) {
  728. console.log('Error: In Error of apply');
  729. console.log("The original data was: " + JSON.stringify(realData));
  730. console.log('Error: Error message is: ' + request.responseText);
  731. result = false;
  732. },
  733. statusCode: require('data/statusCodes')
  734. });
  735. console.log("Exiting applyCreatedConfToService");
  736. console.log("Value of result is: " + result);
  737. return result;
  738. },
  739. getConfigForService: function (config) {
  740. var data = {config: {}};
  741. this.get('serviceConfigTags').forEach(function (_serviceTag) {
  742. if (config === 'new')
  743. data.config[_serviceTag.siteName] = _serviceTag.newTagName;
  744. else if (config = 'previous') {
  745. data.config[_serviceTag.siteName] = _serviceTag.tagName;
  746. }
  747. }, this);
  748. return data;
  749. },
  750. setCustomConfigs: function () {
  751. var site = this.get('stepConfigs').filterProperty('id', 'conf-site');
  752. site.forEach(function (_site) {
  753. var keyValue = _site.value.split(/\n+/);
  754. if (keyValue) {
  755. keyValue.forEach(function (_keyValue) {
  756. console.log("The value of the keyValue is: " + _keyValue.trim());
  757. _keyValue = _keyValue.trim();
  758. var key = _keyValue.match(/(.+)=/);
  759. var value = _keyValue.match(/=(.*)/);
  760. if (key) {
  761. this.setSiteProperty(key[1], value[1], _site.filename);
  762. }
  763. }, this);
  764. }
  765. }, this);
  766. },
  767. /**
  768. * Set property of the site variable
  769. */
  770. setSiteProperty: function (key, value, filename) {
  771. if (this.get('uiConfigs').someProperty('name', key)) {
  772. this.get('uiConfigs').findProperty('name', key).value = value;
  773. } else {
  774. this.get('uiConfigs').pushObject({
  775. "id": "site property",
  776. "name": key,
  777. "value": value,
  778. "filename": filename
  779. });
  780. }
  781. },
  782. getUrl: function (testUrl, url) {
  783. return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + App.router.getClusterName() + url;
  784. },
  785. doPolling: function (desiredStatus, successCallback, errCallback) {
  786. var POLL_INTERVAL = 4000;
  787. var self = this;
  788. var result = true;
  789. var servicesUrl1;
  790. if (desiredStatus === 'stop') {
  791. servicesUrl1 = this.getUrl('/data/dashboard/mapreduce/mapreduce_stop.json', '/services?ServiceInfo/service_name=' + this.get('content.serviceName') + '&fields=components/host_components/*');
  792. } else if (desiredStatus === 'start') {
  793. servicesUrl1 = this.getUrl('/data/dashboard/mapreduce/mapreduce_start.json', '/services?ServiceInfo/service_name=' + this.get('content.serviceName') + '&fields=components/host_components/*');
  794. }
  795. App.HttpClient.get(servicesUrl1, App.servicesMapper, {
  796. complete: function () {
  797. var status;
  798. if (result === false) {
  799. return;
  800. }
  801. if (desiredStatus === 'stop') {
  802. status = self.get('content.isStopped');
  803. if (self.get('content.components').someProperty('workStatus', 'STOP_FAILED')) {
  804. // if (!self.stopService()) {
  805. // return;
  806. //}
  807. }
  808. } else if (desiredStatus === 'start') {
  809. status = self.get('content.isStarted');
  810. if (self.get('content.components').someProperty('workStatus', 'START_FAILED')) {
  811. //if (!self.startService()) {
  812. // return;
  813. //}
  814. }
  815. }
  816. if (status !== true) {
  817. window.setTimeout(function () {
  818. self.doPolling(desiredStatus, successCallback, errCallback);
  819. }, POLL_INTERVAL);
  820. } else if (status === true) {
  821. successCallback.apply(self);
  822. }
  823. },
  824. error: function (jqXHR, textStatus) {
  825. errCallback.apply(self);
  826. result = false;
  827. }
  828. });
  829. return result;
  830. },
  831. initialValue: function (config) {
  832. switch (config.name) {
  833. case 'namenode_host':
  834. config.set('id', 'puppet var');
  835. config.set('value', this.get('content.components').findProperty('componentName', 'NAMENODE').get('host.hostName'));
  836. break;
  837. case 'snamenode_host':
  838. config.set('id', 'puppet var');
  839. config.set('value', this.get('content.components').findProperty('componentName', 'SECONDARY_NAMENODE').get('host.hostName'));
  840. break;
  841. case 'jobtracker_host':
  842. config.set('id', 'puppet var');
  843. config.set('value', this.get('content.components').findProperty('componentName', 'JOBTRACKER').get('host.hostName'));
  844. break;
  845. case 'hbasemaster_host':
  846. config.set('id', 'puppet var');
  847. config.set('value', this.get('content.components').findProperty('componentName', 'HBASE_MASTER').get('host.hostName'));
  848. break;
  849. case 'hivemetastore_host':
  850. config.set('id', 'puppet var');
  851. config.set('value', this.get('content.components').findProperty('componentName', 'HIVE_SERVER').get('host.hostName'));
  852. break;
  853. case 'hive_ambari_host':
  854. config.set('id', 'puppet var');
  855. config.set('value', this.get('content.components').findProperty('componentName', 'HIVE_SERVER').get('host.hostName'));
  856. break;
  857. case 'oozieserver_host':
  858. config.set('id', 'puppet var');
  859. config.set('value', this.get('content.components').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName'));
  860. break;
  861. case 'oozie_ambari_host':
  862. config.set('id', 'puppet var');
  863. config.set('value', this.get('content.components').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName'));
  864. break;
  865. case 'zookeeperserver_hosts':
  866. config.set('id', 'puppet var');
  867. config.set('value', this.get('content.components').findProperty('componentName', 'ZOOKEEPER_SERVER').get('host.hostName'));
  868. break;
  869. }
  870. }
  871. });
  872. App.MainServiceSlaveComponentGroupsController = App.SlaveComponentGroupsController.extend({
  873. name: 'mainServiceSlaveComponentGroupsController',
  874. contentBinding: 'App.router.mainServiceInfoConfigsController.slaveComponentHosts',
  875. serviceBinding: 'App.router.mainServiceInfoConfigsController.selectedService',
  876. selectedComponentName: function () {
  877. switch (App.router.get('mainServiceInfoConfigsController.selectedService.serviceName')) {
  878. case 'HDFS':
  879. return 'DATANODE';
  880. case 'MAPREDUCE':
  881. return 'TASKTRACKER';
  882. case 'HBASE':
  883. return 'HBASE_REGIONSERVER';
  884. default:
  885. return null;
  886. }
  887. }.property('App.router.mainServiceInfoConfigsController.selectedService')
  888. });