configs.js 37 KB

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