configs.js 41 KB

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