config.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  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. var stringUtils = require('utils/string_utils');
  20. var serviceComponents = {};
  21. var configGroupsByTag = [];
  22. var globalPropertyToServicesMap = null;
  23. App.config = Em.Object.create({
  24. /**
  25. * XML characters which should be escaped in values
  26. * http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML
  27. */
  28. xmlEscapeMap: {
  29. "&": "&",
  30. "<": "&lt;",
  31. ">": "&gt;",
  32. '"': '&quot;',
  33. "'": '&apos;'
  34. },
  35. xmlUnEscapeMap: {
  36. "&amp;": "&",
  37. "&lt;": "<",
  38. "&gt;": ">",
  39. "&quot;": '"',
  40. "&apos;": "'"
  41. },
  42. CONFIG_GROUP_NAME_MAX_LENGTH: 40,
  43. /**
  44. * filename exceptions used to support substandard sitenames which don't have "xml" extension
  45. */
  46. filenameExceptions: ['zoo.cfg'],
  47. /**
  48. * Since values end up in XML files (core-sit.xml, etc.), certain
  49. * XML sensitive characters should be escaped. If not we will have
  50. * an invalid XML document, and services will fail to start.
  51. *
  52. * Special characters in XML are defined at
  53. * http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML
  54. */
  55. escapeXMLCharacters: function(value) {
  56. var self = this;
  57. // To prevent double/triple replacing '&gt;' to '&gt;gt;' to '&gt;gt;gt', we need
  58. // to first unescape all XML chars, and then escape them again.
  59. var newValue = String(value).replace(/(&amp;|&lt;|&gt;|&quot;|&apos;)/g, function (s) {
  60. return self.xmlUnEscapeMap[s];
  61. });
  62. return String(newValue).replace(/[&<>"']/g, function (s) {
  63. return self.xmlEscapeMap[s];
  64. });
  65. },
  66. preDefinedServiceConfigs: function () {
  67. var configs = this.get('preDefinedGlobalProperties');
  68. var services = [];
  69. $.extend(true, [], require('data/service_configs')).forEach(function (service) {
  70. service.configs = configs.filterProperty('serviceName', service.serviceName);
  71. services.push(service);
  72. });
  73. return services;
  74. }.property('preDefinedGlobalProperties'),
  75. configMapping: function () {
  76. if (App.get('isHadoop2Stack')) {
  77. return $.extend(true, [], require('data/HDP2/config_mapping'));
  78. }
  79. return $.extend(true, [], require('data/config_mapping'));
  80. }.property('App.isHadoop2Stack'),
  81. preDefinedGlobalProperties: function () {
  82. if (App.get('isHadoop2Stack')) {
  83. return $.extend(true, [], require('data/HDP2/global_properties').configProperties);
  84. }
  85. return $.extend(true, [], require('data/global_properties').configProperties);
  86. }.property('App.isHadoop2Stack'),
  87. preDefinedSiteProperties: function () {
  88. if (App.get('isHadoop2Stack')) {
  89. return $.extend(true, [], require('data/HDP2/site_properties').configProperties);
  90. }
  91. return $.extend(true, [], require('data/site_properties').configProperties);
  92. }.property('App.isHadoop2Stack'),
  93. preDefinedCustomConfigs: function () {
  94. if (App.get('isHadoop2Stack')) {
  95. return $.extend(true, [], require('data/HDP2/custom_configs'));
  96. }
  97. return $.extend(true, [], require('data/custom_configs'));
  98. }.property('App.isHadoop2Stack'),
  99. //categories which contain custom configs
  100. categoriesWithCustom: ['CapacityScheduler'],
  101. //configs with these filenames go to appropriate category not in Advanced
  102. customFileNames: function () {
  103. if (App.supports.capacitySchedulerUi) {
  104. if (App.get('isHadoop2Stack')) {
  105. return ['capacity-scheduler.xml'];
  106. }
  107. return ['capacity-scheduler.xml', 'mapred-queue-acls.xml'];
  108. } else {
  109. return [];
  110. }
  111. }.property('App.isHadoop2Stack'),
  112. /**
  113. * Function should be used post-install as precondition check should not be done only after installer wizard
  114. * @param siteNames
  115. * @returns {Array}
  116. */
  117. getBySitename: function (siteNames) {
  118. var computedConfigs = this.get('configMapping').computed();
  119. var siteProperties = [];
  120. if (typeof siteNames === "string") {
  121. siteProperties = computedConfigs.filterProperty('filename', siteNames);
  122. } else if (siteNames instanceof Array) {
  123. siteNames.forEach(function (_siteName) {
  124. siteProperties = siteProperties.concat(computedConfigs.filterProperty('filename', _siteName));
  125. }, this);
  126. }
  127. return siteProperties;
  128. },
  129. /**
  130. * Cache of loaded configurations. This is useful in not loading
  131. * same configuration multiple times. It is populated in multiple
  132. * places.
  133. *
  134. * Example:
  135. * {
  136. * 'global_version1': {...},
  137. * 'global_version2': {...},
  138. * 'hdfs-site_version3': {...},
  139. * }
  140. */
  141. loadedConfigurationsCache: {},
  142. /**
  143. * Array of global "service/desired_tag/actual_tag" strings which
  144. * indicate different configurations. We cache these so that
  145. * we dont have to recalculate if two tags are difference.
  146. */
  147. differentGlobalTagsCache: [],
  148. identifyCategory: function (config) {
  149. var category = null;
  150. var serviceConfigMetaData = this.get('preDefinedServiceConfigs').findProperty('serviceName', config.serviceName);
  151. if (serviceConfigMetaData) {
  152. serviceConfigMetaData.configCategories.forEach(function (_category) {
  153. if (_category.siteFileNames && Array.isArray(_category.siteFileNames) && _category.siteFileNames.contains(config.filename)) {
  154. category = _category;
  155. }
  156. });
  157. category = (category == null) ? serviceConfigMetaData.configCategories.findProperty('siteFileName', config.filename) : category;
  158. }
  159. return category;
  160. },
  161. /**
  162. * additional handling for special properties such as
  163. * checkbox and digital which values with 'm' at the end
  164. * @param config
  165. */
  166. handleSpecialProperties: function (config) {
  167. if (config.displayType === 'int' && /\d+m$/.test(config.value)) {
  168. config.value = config.value.slice(0, config.value.length - 1);
  169. config.defaultValue = config.value;
  170. }
  171. if (config.displayType === 'checkbox') {
  172. config.value = (config.value === 'true') ? config.defaultValue = true : config.defaultValue = false;
  173. }
  174. },
  175. /**
  176. * calculate config properties:
  177. * category, filename, isRequired, isUserProperty
  178. * @param config
  179. * @param isAdvanced
  180. * @param advancedConfigs
  181. */
  182. calculateConfigProperties: function (config, isAdvanced, advancedConfigs) {
  183. if (!isAdvanced || this.get('customFileNames').contains(config.filename)) {
  184. var categoryMetaData = this.identifyCategory(config);
  185. if (categoryMetaData != null) {
  186. config.category = categoryMetaData.get('name');
  187. if (!isAdvanced) config.isUserProperty = true;
  188. }
  189. } else {
  190. config.category = config.category ? config.category : 'Advanced';
  191. config.description = isAdvanced && advancedConfigs.findProperty('name', config.name).description;
  192. config.filename = isAdvanced && advancedConfigs.findProperty('name', config.name).filename;
  193. config.isRequired = true;
  194. }
  195. },
  196. capacitySchedulerFilter: function () {
  197. var yarnRegex = /^yarn\.scheduler\.capacity\.root\.(?!unfunded)([a-z]([\_\-a-z0-9]{0,50}))\.(acl_administer_jobs|acl_submit_jobs|state|user-limit-factor|maximum-capacity|capacity)$/i;
  198. var self = this;
  199. if (App.get('isHadoop2Stack')) {
  200. return function (_config) {
  201. return (yarnRegex.test(_config.name));
  202. }
  203. } else {
  204. return function (_config) {
  205. return (_config.name.indexOf('mapred.capacity-scheduler.queue.') !== -1) ||
  206. (/^mapred\.queue\.[a-z]([\_\-a-z0-9]{0,50})\.(acl-administer-jobs|acl-submit-job)$/i.test(_config.name));
  207. }
  208. }
  209. }.property('App.isHadoop2Stack'),
  210. /**
  211. * return:
  212. * configs,
  213. * globalConfigs,
  214. * mappingConfigs
  215. *
  216. * @param configGroups
  217. * @param advancedConfigs
  218. * @param tags
  219. * @param serviceName
  220. * @return {object}
  221. */
  222. mergePreDefinedWithLoaded: function (configGroups, advancedConfigs, tags, serviceName) {
  223. var configs = [];
  224. var globalConfigs = [];
  225. var preDefinedConfigs = this.get('preDefinedGlobalProperties').concat(this.get('preDefinedSiteProperties'));
  226. var mappingConfigs = [];
  227. var filenameExceptions = this.get('filenameExceptions');
  228. tags.forEach(function (_tag) {
  229. var isAdvanced = null;
  230. var properties = configGroups.filter(function (serviceConfigProperties) {
  231. return _tag.tagName === serviceConfigProperties.tag && _tag.siteName === serviceConfigProperties.type;
  232. });
  233. properties = (properties.length) ? properties.objectAt(0).properties : {};
  234. for (var index in properties) {
  235. var configsPropertyDef = preDefinedConfigs.findProperty('name', index) || null;
  236. var serviceConfigObj = App.ServiceConfig.create({
  237. name: index,
  238. value: properties[index],
  239. defaultValue: properties[index],
  240. filename: (filenameExceptions.contains(_tag.siteName)) ? _tag.siteName : _tag.siteName + ".xml",
  241. isUserProperty: false,
  242. isOverridable: true,
  243. serviceName: serviceName,
  244. belongsToService: []
  245. });
  246. if (configsPropertyDef) {
  247. this.setServiceConfigUiAttributes(serviceConfigObj, configsPropertyDef);
  248. }
  249. if (_tag.siteName === 'global') {
  250. if (configsPropertyDef) {
  251. if (configsPropertyDef.isRequiredByAgent === false) {
  252. continue;
  253. }
  254. this.handleSpecialProperties(serviceConfigObj);
  255. } else {
  256. serviceConfigObj.isVisible = false; // if the global property is not defined on ui metadata global_properties.js then it shouldn't be a part of errorCount
  257. }
  258. serviceConfigObj.id = 'puppet var';
  259. serviceConfigObj.displayName = configsPropertyDef ? configsPropertyDef.displayName : null;
  260. serviceConfigObj.options = configsPropertyDef ? configsPropertyDef.options : null;
  261. globalConfigs.push(serviceConfigObj);
  262. } else if (!this.getBySitename(serviceConfigObj.get('filename')).someProperty('name', index)) {
  263. isAdvanced = advancedConfigs.someProperty('name', index);
  264. serviceConfigObj.id = 'site property';
  265. if (!configsPropertyDef) {
  266. serviceConfigObj.displayType = stringUtils.isSingleLine(serviceConfigObj.value) ? 'advanced' : 'multiLine';
  267. }
  268. serviceConfigObj.displayName = configsPropertyDef ? configsPropertyDef.displayName : index;
  269. this.calculateConfigProperties(serviceConfigObj, isAdvanced, advancedConfigs);
  270. if(serviceConfigObj.get('displayType') == 'directories'
  271. && (serviceConfigObj.get('category') == 'DataNode'
  272. || serviceConfigObj.get('category') == 'NameNode')) {
  273. var dirs = serviceConfigObj.get('value').split(',').sort();
  274. serviceConfigObj.set('value', dirs.join(','));
  275. serviceConfigObj.set('defaultValue', dirs.join(','));
  276. }
  277. if(serviceConfigObj.get('displayType') == 'directory'
  278. && serviceConfigObj.get('category') == 'SNameNode') {
  279. var dirs = serviceConfigObj.get('value').split(',').sort();
  280. serviceConfigObj.set('value', dirs[0]);
  281. serviceConfigObj.set('defaultValue', dirs[0]);
  282. }
  283. if (serviceConfigObj.get('displayType') == 'masterHosts') {
  284. if (typeof(serviceConfigObj.get('value')) == 'string') {
  285. var value = serviceConfigObj.get('value').replace(/\[|]|'|&apos;/g, "").split(',');
  286. serviceConfigObj.set('value', value);
  287. }
  288. }
  289. configs.push(serviceConfigObj);
  290. } else {
  291. mappingConfigs.push(serviceConfigObj);
  292. }
  293. }
  294. }, this);
  295. return {
  296. configs: configs,
  297. globalConfigs: globalConfigs,
  298. mappingConfigs: mappingConfigs
  299. }
  300. },
  301. /**
  302. * @param serviceConfigObj : Object
  303. * @param configsPropertyDef : Object
  304. */
  305. setServiceConfigUiAttributes: function (serviceConfigObj, configsPropertyDef) {
  306. serviceConfigObj.displayType = configsPropertyDef.displayType;
  307. serviceConfigObj.isRequired = (configsPropertyDef.isRequired !== undefined) ? configsPropertyDef.isRequired : true;
  308. serviceConfigObj.isRequiredByAgent = (configsPropertyDef.isRequiredByAgent !== undefined) ? configsPropertyDef.isRequiredByAgent : true;
  309. serviceConfigObj.isReconfigurable = (configsPropertyDef.isReconfigurable !== undefined) ? configsPropertyDef.isReconfigurable : true;
  310. serviceConfigObj.isVisible = (configsPropertyDef.isVisible !== undefined) ? configsPropertyDef.isVisible : true;
  311. serviceConfigObj.unit = (configsPropertyDef.unit !== undefined) ? configsPropertyDef.unit : undefined;
  312. serviceConfigObj.description = (configsPropertyDef.description !== undefined) ? configsPropertyDef.description : undefined;
  313. serviceConfigObj.isOverridable = configsPropertyDef.isOverridable === undefined ? true : configsPropertyDef.isOverridable;
  314. serviceConfigObj.serviceName = configsPropertyDef ? configsPropertyDef.serviceName : null;
  315. serviceConfigObj.index = configsPropertyDef.index;
  316. serviceConfigObj.isSecureConfig = configsPropertyDef.isSecureConfig === undefined ? false : configsPropertyDef.isSecureConfig;
  317. serviceConfigObj.belongsToService = configsPropertyDef.belongsToService;
  318. serviceConfigObj.category = configsPropertyDef.category;
  319. },
  320. /**
  321. * synchronize order of config properties with order, that on UI side
  322. * @param configSet
  323. * @return {Object}
  324. */
  325. syncOrderWithPredefined: function (configSet) {
  326. var globalConfigs = configSet.globalConfigs,
  327. siteConfigs = configSet.configs,
  328. globalStart = [],
  329. siteStart = [];
  330. this.get('preDefinedGlobalProperties').mapProperty('name').forEach(function (name) {
  331. var _global = globalConfigs.findProperty('name', name);
  332. if (_global) {
  333. globalStart.push(_global);
  334. globalConfigs = globalConfigs.without(_global);
  335. }
  336. }, this);
  337. this.get('preDefinedSiteProperties').mapProperty('name').forEach(function (name) {
  338. var _site = siteConfigs.findProperty('name', name);
  339. if (_site) {
  340. siteStart.push(_site);
  341. siteConfigs = siteConfigs.without(_site);
  342. }
  343. }, this);
  344. var alphabeticalSort = function (a, b) {
  345. if (a.name < b.name) return -1;
  346. if (a.name > b.name) return 1;
  347. return 0;
  348. }
  349. return {
  350. globalConfigs: globalStart.concat(globalConfigs.sort(alphabeticalSort)),
  351. configs: siteStart.concat(siteConfigs.sort(alphabeticalSort)),
  352. mappingConfigs: configSet.mappingConfigs
  353. }
  354. },
  355. /**
  356. * merge stored configs with pre-defined
  357. * @param storedConfigs
  358. * @param advancedConfigs
  359. * @return {*}
  360. */
  361. mergePreDefinedWithStored: function (storedConfigs, advancedConfigs) {
  362. var mergedConfigs = [];
  363. var preDefinedConfigs = $.extend(true, [], this.get('preDefinedGlobalProperties').concat(this.get('preDefinedSiteProperties')));
  364. var preDefinedNames = [];
  365. var storedNames = [];
  366. var names = [];
  367. var categoryMetaData = null;
  368. storedConfigs = (storedConfigs) ? storedConfigs : [];
  369. preDefinedNames = preDefinedConfigs.mapProperty('name');
  370. storedNames = storedConfigs.mapProperty('name');
  371. names = preDefinedNames.concat(storedNames).uniq();
  372. names.forEach(function (name) {
  373. var stored = storedConfigs.findProperty('name', name);
  374. var preDefined = preDefinedConfigs.findProperty('name', name);
  375. var configData = {};
  376. var isAdvanced = advancedConfigs.someProperty('name', name);
  377. if (preDefined && stored) {
  378. configData = preDefined;
  379. configData.value = stored.value;
  380. configData.defaultValue = stored.defaultValue;
  381. configData.overrides = stored.overrides;
  382. configData.filename = stored.filename;
  383. configData.description = stored.description;
  384. configData.isRequiredByAgent = (configData.isRequiredByAgent !== undefined) ? configData.isRequiredByAgent : true;
  385. } else if (!preDefined && stored) {
  386. configData = {
  387. id: stored.id,
  388. name: stored.name,
  389. displayName: stored.name,
  390. serviceName: stored.serviceName,
  391. value: stored.value,
  392. defaultValue: stored.defaultValue,
  393. displayType: stringUtils.isSingleLine(stored.value) ? 'advanced' : 'multiLine',
  394. filename: stored.filename,
  395. category: 'Advanced',
  396. isUserProperty: stored.isUserProperty === true,
  397. isOverridable: true,
  398. overrides: stored.overrides,
  399. isRequired: true
  400. };
  401. this.calculateConfigProperties(configData, isAdvanced, advancedConfigs);
  402. } else if (preDefined && !stored) {
  403. configData = preDefined;
  404. configData.isRequiredByAgent = (configData.isRequiredByAgent !== undefined) ? configData.isRequiredByAgent : true;
  405. if (isAdvanced) {
  406. var advanced = advancedConfigs.findProperty('name', configData.name);
  407. configData.value = configData.displayType == "password" ? '' : advanced.value;
  408. configData.defaultValue = advanced.value;
  409. configData.filename = advanced.filename;
  410. configData.description = advanced.description;
  411. }
  412. }
  413. if (configData.displayType === 'checkbox') {
  414. configData.value = configData.defaultValue = configData.value === 'true'; // convert {String} value to {Boolean}
  415. }
  416. mergedConfigs.push(configData);
  417. }, this);
  418. return mergedConfigs;
  419. },
  420. /**
  421. * look over advanced configs and add missing configs to serviceConfigs
  422. * filter fetched configs by service if passed
  423. * @param serviceConfigs
  424. * @param advancedConfigs
  425. * @param serviceName
  426. */
  427. addAdvancedConfigs: function (serviceConfigs, advancedConfigs, serviceName) {
  428. var configsToVerifying = (serviceName) ? serviceConfigs.filterProperty('serviceName', serviceName) : serviceConfigs;
  429. advancedConfigs.forEach(function (_config) {
  430. var configCategory = 'Advanced';
  431. var categoryMetaData = null;
  432. if (_config) {
  433. if (this.get('configMapping').computed().someProperty('name', _config.name)) {
  434. } else if (!(configsToVerifying.someProperty('name', _config.name))) {
  435. if (this.get('customFileNames').contains(_config.filename)) {
  436. categoryMetaData = this.identifyCategory(_config);
  437. if (categoryMetaData != null) {
  438. configCategory = categoryMetaData.get('name');
  439. }
  440. }
  441. _config.id = "site property";
  442. _config.category = configCategory;
  443. _config.displayName = _config.name;
  444. _config.defaultValue = _config.value;
  445. // make all advanced configs optional and populated by default
  446. /*
  447. * if (/\${.*}/.test(_config.value) || (service.serviceName !==
  448. * 'OOZIE' && service.serviceName !== 'HBASE')) { _config.isRequired =
  449. * false; _config.value = ''; } else if
  450. * (/^\s+$/.test(_config.value)) { _config.isRequired = false; }
  451. */
  452. _config.isRequired = true;
  453. _config.displayType = stringUtils.isSingleLine(_config.value) ? 'advanced' : 'multiLine';
  454. serviceConfigs.push(_config);
  455. }
  456. }
  457. }, this);
  458. },
  459. /**
  460. * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
  461. */
  462. addCustomConfigs: function (configs) {
  463. var preDefinedCustomConfigs = $.extend(true, [], this.get('preDefinedCustomConfigs'));
  464. var stored = configs.filter(function (_config) {
  465. return this.get('categoriesWithCustom').contains(_config.category);
  466. }, this);
  467. if (App.supports.capacitySchedulerUi) {
  468. var queueProperties = stored.filter(this.get('capacitySchedulerFilter'));
  469. if (queueProperties.length) {
  470. queueProperties.setEach('isQueue', true);
  471. }
  472. }
  473. },
  474. miscConfigVisibleProperty: function (configs, serviceToShow) {
  475. configs.forEach(function (item) {
  476. item.set("isVisible", item.belongsToService.some(function (cur) {
  477. return serviceToShow.contains(cur)
  478. }));
  479. });
  480. return configs;
  481. },
  482. /**
  483. * render configs, distribute them by service
  484. * and wrap each in ServiceConfigProperty object
  485. * @param configs
  486. * @param storedConfigs
  487. * @param allInstalledServiceNames
  488. * @param selectedServiceNames
  489. * @param localDB
  490. * @return {Array}
  491. */
  492. renderConfigs: function (configs, storedConfigs, allInstalledServiceNames, selectedServiceNames, localDB) {
  493. var renderedServiceConfigs = [];
  494. var services = [];
  495. this.get('preDefinedServiceConfigs').forEach(function (serviceConfig) {
  496. if (allInstalledServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  497. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  498. if (selectedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  499. serviceConfig.showConfig = true;
  500. }
  501. services.push(serviceConfig);
  502. }
  503. });
  504. services.forEach(function (service) {
  505. var serviceConfig = {};
  506. var configsByService = [];
  507. var serviceConfigs = configs.filterProperty('serviceName', service.serviceName);
  508. serviceConfigs.forEach(function (_config) {
  509. var serviceConfigProperty = {};
  510. _config.isOverridable = (_config.isOverridable === undefined) ? true : _config.isOverridable;
  511. serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  512. this.updateHostOverrides(serviceConfigProperty, _config);
  513. if (!storedConfigs) {
  514. serviceConfigProperty.initialValue(localDB);
  515. }
  516. this.tweakDynamicDefaults(localDB, serviceConfigProperty, _config);
  517. serviceConfigProperty.validate();
  518. configsByService.pushObject(serviceConfigProperty);
  519. }, this);
  520. serviceConfig = this.createServiceConfig(service.serviceName);
  521. serviceConfig.set('showConfig', service.showConfig);
  522. // Use calculated default values for some configs
  523. var recommendedDefaults = {};
  524. if (!storedConfigs && service.defaultsProviders) {
  525. service.defaultsProviders.forEach(function (defaultsProvider) {
  526. var defaults = defaultsProvider.getDefaults(localDB);
  527. for (var name in defaults) {
  528. recommendedDefaults[name] = defaults[name];
  529. var config = configsByService.findProperty('name', name);
  530. if (config) {
  531. config.set('value', defaults[name]);
  532. config.set('defaultValue', defaults[name]);
  533. }
  534. }
  535. });
  536. }
  537. if (service.configsValidator) {
  538. service.configsValidator.set('recommendedDefaults', recommendedDefaults);
  539. var validators = service.configsValidator.get('configValidators');
  540. for (var validatorName in validators) {
  541. var c = configsByService.findProperty('name', validatorName);
  542. if (c) {
  543. c.set('serviceValidator', service.configsValidator);
  544. }
  545. }
  546. }
  547. serviceConfig.set('configs', configsByService);
  548. renderedServiceConfigs.push(serviceConfig);
  549. }, this);
  550. return renderedServiceConfigs;
  551. },
  552. /**
  553. Takes care of the "dynamic defaults" for the GLUSTERFS configs. Sets
  554. some of the config defaults to previously user-entered data.
  555. **/
  556. tweakDynamicDefaults: function (localDB, serviceConfigProperty, config) {
  557. var firstHost = null;
  558. for (var host in localDB.hosts) {
  559. firstHost = host;
  560. break;
  561. }
  562. try {
  563. if (typeof(config == "string") && config.defaultValue.indexOf("{firstHost}") >= 0) {
  564. serviceConfigProperty.set('value', serviceConfigProperty.value.replace(new RegExp("{firstHost}"), firstHost));
  565. serviceConfigProperty.set('defaultValue', serviceConfigProperty.defaultValue.replace(new RegExp("{firstHost}"), firstHost));
  566. }
  567. } catch (err) {
  568. // Nothing to worry about here, most likely trying indexOf on a non-string
  569. }
  570. },
  571. /**
  572. * create new child configs from overrides, attach them to parent config
  573. * override - value of config, related to particular host(s)
  574. * @param configProperty
  575. * @param storedConfigProperty
  576. */
  577. updateHostOverrides: function (configProperty, storedConfigProperty) {
  578. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  579. var overrides = [];
  580. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  581. // create new override with new value
  582. var newSCP = App.ServiceConfigProperty.create(configProperty);
  583. newSCP.set('value', overrideEntry.value);
  584. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  585. newSCP.set('parentSCP', configProperty);
  586. var hostsArray = Ember.A([]);
  587. overrideEntry.hosts.forEach(function (host) {
  588. hostsArray.push(host);
  589. });
  590. newSCP.set('selectedHostOptions', hostsArray);
  591. overrides.pushObject(newSCP);
  592. });
  593. configProperty.set('overrides', overrides);
  594. }
  595. },
  596. /**
  597. * create new ServiceConfig object by service name
  598. * @param serviceName
  599. */
  600. createServiceConfig: function (serviceName) {
  601. var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName);
  602. var serviceConfig = App.ServiceConfig.create({
  603. filename: preDefinedServiceConfig.filename,
  604. serviceName: preDefinedServiceConfig.serviceName,
  605. displayName: preDefinedServiceConfig.displayName,
  606. configCategories: preDefinedServiceConfig.configCategories,
  607. configs: [],
  608. configGroups: []
  609. });
  610. serviceConfig.configCategories.filterProperty('isCustomView', true).forEach(function (category) {
  611. switch (category.name) {
  612. case 'CapacityScheduler':
  613. if (App.supports.capacitySchedulerUi) {
  614. category.set('customView', App.ServiceConfigCapacityScheduler);
  615. } else {
  616. category.set('isCustomView', false);
  617. }
  618. break;
  619. }
  620. }, this);
  621. return serviceConfig;
  622. },
  623. /**
  624. * GETs all cluster level sites in one call.
  625. *
  626. * @return Array of all site configs
  627. */
  628. loadConfigsByTags: function (tags) {
  629. var urlParams = [];
  630. tags.forEach(function (_tag) {
  631. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  632. });
  633. var params = urlParams.join('|');
  634. App.ajax.send({
  635. name: 'config.on_site',
  636. sender: this,
  637. data: {
  638. params: params
  639. },
  640. success: 'loadConfigsByTagsSuccess'
  641. });
  642. return configGroupsByTag;
  643. },
  644. loadConfigsByTagsSuccess: function (data) {
  645. if (data.items) {
  646. configGroupsByTag = [];
  647. data.items.forEach(function (item) {
  648. this.loadedConfigurationsCache[item.type + "_" + item.tag] = item.properties;
  649. configGroupsByTag.push(item);
  650. }, this);
  651. }
  652. },
  653. /**
  654. * Generate serviceProperties save it to localDB
  655. * called form stepController step6WizardController
  656. *
  657. * @param serviceName
  658. * @return {*}
  659. */
  660. loadAdvancedConfig: function (serviceName) {
  661. App.ajax.send({
  662. name: 'config.advanced',
  663. sender: this,
  664. data: {
  665. serviceName: serviceName,
  666. stack2VersionUrl: App.get('stack2VersionURL'),
  667. stackVersion: App.get('currentStackVersionNumber')
  668. },
  669. success: 'loadAdvancedConfigSuccess'
  670. });
  671. return serviceComponents[serviceName];
  672. //TODO clean serviceComponents
  673. },
  674. loadAdvancedConfigSuccess: function (data, opt, params) {
  675. console.log("TRACE: In success function for the loadAdvancedConfig; url is ", opt.url);
  676. var properties = [];
  677. if (data.items.length) {
  678. data.items.forEach(function (item) {
  679. item = item.StackConfigurations;
  680. item.isVisible = item.type !== 'global.xml';
  681. var serviceName = item.service_name;
  682. var fileName = item.type;
  683. var isHDP2 = App.get('isHadoop2Stack');
  684. /**
  685. * Properties from mapred-queue-acls.xml are ignored unless App.supports.capacitySchedulerUi is true
  686. * Properties from capacity-scheduler.xml are ignored unless HDP stack version is 2.x or
  687. * HDP stack version is 1.x and App.supports.capacitySchedulerUi is true.
  688. */
  689. if ((fileName !== 'mapred-queue-acls.xml' || App.supports.capacitySchedulerUi) &&
  690. (fileName !== 'capacity-scheduler.xml' || isHDP2 || App.supports.capacitySchedulerUi)) {
  691. properties.push({
  692. serviceName: serviceName,
  693. name: item.property_name,
  694. value: item.property_value,
  695. description: item.property_description,
  696. isVisible: item.isVisible,
  697. filename: item.filename || fileName
  698. });
  699. }
  700. }, this);
  701. serviceComponents[data.items[0].StackConfigurations.service_name] = properties;
  702. }
  703. },
  704. /**
  705. * Determine the map which shows which services
  706. * each global property effects.
  707. *
  708. * @return {*}
  709. * Example:
  710. * {
  711. * 'hive_pid_dir': ['HIVE'],
  712. * ...
  713. * }
  714. */
  715. loadGlobalPropertyToServicesMap: function () {
  716. if (globalPropertyToServicesMap == null) {
  717. App.ajax.send({
  718. name: 'config.advanced.global',
  719. sender: this,
  720. data: {
  721. stack2VersionUrl: App.get('stack2VersionURL')
  722. },
  723. success: 'loadGlobalPropertyToServicesMapSuccess'
  724. });
  725. }
  726. return globalPropertyToServicesMap;
  727. },
  728. loadGlobalPropertyToServicesMapSuccess: function (data) {
  729. globalPropertyToServicesMap = {};
  730. if (data.items != null) {
  731. data.items.forEach(function (service) {
  732. service.configurations.forEach(function (config) {
  733. if ("global.xml" === config.StackConfigurations.type) {
  734. if (!(config.StackConfigurations.property_name in globalPropertyToServicesMap)) {
  735. globalPropertyToServicesMap[config.StackConfigurations.property_name] = [];
  736. }
  737. globalPropertyToServicesMap[config.StackConfigurations.property_name].push(service.StackServices.service_name);
  738. }
  739. });
  740. });
  741. }
  742. },
  743. /**
  744. * Hosts can override service configurations per property. This method GETs
  745. * the overriden configurations and sets only the changed properties into
  746. * the 'overrides' of serviceConfig.
  747. *
  748. *
  749. */
  750. loadServiceConfigHostsOverrides: function (serviceConfigs, loadedGroupToOverrideSiteToTagMap, configGroups) {
  751. var configKeyToConfigMap = {};
  752. serviceConfigs.forEach(function (item) {
  753. configKeyToConfigMap[item.name] = item;
  754. });
  755. var typeTagToGroupMap = {};
  756. var urlParams = [];
  757. for (var group in loadedGroupToOverrideSiteToTagMap) {
  758. var overrideTypeTags = loadedGroupToOverrideSiteToTagMap[group];
  759. for (var type in overrideTypeTags) {
  760. var tag = overrideTypeTags[type];
  761. typeTagToGroupMap[type + "///" + tag] = configGroups.findProperty('name', group);
  762. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  763. }
  764. }
  765. var params = urlParams.join('|');
  766. if (urlParams.length) {
  767. App.ajax.send({
  768. name: 'config.host_overrides',
  769. sender: this,
  770. data: {
  771. params: params,
  772. configKeyToConfigMap: configKeyToConfigMap,
  773. typeTagToGroupMap: typeTagToGroupMap
  774. },
  775. success: 'loadServiceConfigHostsOverridesSuccess'
  776. });
  777. }
  778. },
  779. loadServiceConfigHostsOverridesSuccess: function (data, opt, params) {
  780. console.debug("loadServiceConfigHostsOverrides: Data=", data);
  781. data.items.forEach(function (config) {
  782. App.config.loadedConfigurationsCache[config.type + "_" + config.tag] = config.properties;
  783. var group = params.typeTagToGroupMap[config.type + "///" + config.tag];
  784. var properties = config.properties;
  785. for (var prop in properties) {
  786. var serviceConfig = params.configKeyToConfigMap[prop];
  787. var hostOverrideValue = properties[prop];
  788. if (serviceConfig && serviceConfig.displayType === 'int') {
  789. if (/\d+m$/.test(hostOverrideValue)) {
  790. hostOverrideValue = hostOverrideValue.slice(0, hostOverrideValue.length - 1);
  791. }
  792. } else if (serviceConfig && serviceConfig.displayType === 'checkbox') {
  793. switch (hostOverrideValue) {
  794. case 'true':
  795. hostOverrideValue = true;
  796. break;
  797. case 'false':
  798. hostOverrideValue = false;
  799. break;
  800. }
  801. }
  802. if (serviceConfig) {
  803. // Value of this property is different for this host.
  804. var overrides = 'overrides';
  805. if (!(overrides in serviceConfig)) {
  806. serviceConfig.overrides = [];
  807. }
  808. if (!serviceConfig.overrides) {
  809. serviceConfig.set('overrides', []);
  810. }
  811. console.log("loadServiceConfigHostsOverrides(): [" + group + "] OVERRODE(" + serviceConfig.name + "): " + serviceConfig.value + " -> " + hostOverrideValue);
  812. serviceConfig.overrides.push({value: hostOverrideValue, group: group});
  813. }
  814. }
  815. });
  816. console.log("loadServiceConfigHostsOverrides(): Finished loading.");
  817. },
  818. /**
  819. * Set all site property that are derived from other site-properties
  820. */
  821. setConfigValue: function (mappedConfigs, allConfigs, config, globalConfigs) {
  822. var globalValue;
  823. if (config.value == null) {
  824. return;
  825. }
  826. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  827. var fkName = config.name.match(/<(foreignKey.*?)>/g);
  828. var templateValue = config.value.match(/<(templateName.*?)>/g);
  829. if (fkValue) {
  830. fkValue.forEach(function (_fkValue) {
  831. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  832. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  833. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  834. config.value = config.value.replace(_fkValue, globalValue);
  835. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  836. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  837. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  838. } else {
  839. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  840. }
  841. config.value = config.value.replace(_fkValue, globalValue);
  842. }
  843. }, this);
  844. }
  845. // config._name - formatted name from original config name
  846. if (fkName) {
  847. fkName.forEach(function (_fkName) {
  848. var index = parseInt(_fkName.match(/\[([\d]*)(?=\])/)[1]);
  849. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  850. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  851. config._name = config.name.replace(_fkName, globalValue);
  852. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  853. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  854. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  855. } else {
  856. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  857. }
  858. config._name = config.name.replace(_fkName, globalValue);
  859. }
  860. }, this);
  861. }
  862. //For properties in the configMapping file having foreignKey and templateName properties.
  863. if (templateValue) {
  864. templateValue.forEach(function (_value) {
  865. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  866. if (globalConfigs.someProperty('name', config.templateName[index])) {
  867. var globalValue = globalConfigs.findProperty('name', config.templateName[index]).value;
  868. config.value = config.value.replace(_value, globalValue);
  869. } else {
  870. config.value = null;
  871. }
  872. }, this);
  873. }
  874. },
  875. complexConfigs: [
  876. {
  877. "id": "site property",
  878. "name": "capacity-scheduler",
  879. "displayName": "Capacity Scheduler",
  880. "value": "",
  881. "defaultValue": "",
  882. "description": "Capacity Scheduler properties",
  883. "displayType": "custom",
  884. "isOverridable": true,
  885. "isRequired": true,
  886. "isVisible": true,
  887. "serviceName": "YARN",
  888. "filename": "capacity-scheduler.xml",
  889. "category": "CapacityScheduler"
  890. }
  891. ],
  892. /**
  893. * transform set of configs from file
  894. * into one config with textarea content:
  895. * name=value
  896. * @param configs
  897. * @param filename
  898. * @return {*}
  899. */
  900. fileConfigsIntoTextarea: function (configs, filename) {
  901. var fileConfigs = configs.filterProperty('filename', filename);
  902. var value = '';
  903. var defaultValue = '';
  904. var complexConfig = this.get('complexConfigs').findProperty('filename', filename);
  905. if (complexConfig) {
  906. fileConfigs.forEach(function (_config) {
  907. value += _config.name + '=' + _config.value + '\n';
  908. defaultValue += _config.name + '=' + _config.defaultValue + '\n';
  909. }, this);
  910. complexConfig.value = value;
  911. complexConfig.defaultValue = defaultValue;
  912. configs = configs.filter(function (_config) {
  913. return _config.filename !== filename;
  914. });
  915. configs.push(complexConfig);
  916. }
  917. return configs;
  918. },
  919. /**
  920. * transform one config with textarea content
  921. * into set of configs of file
  922. * @param configs
  923. * @param filename
  924. * @return {*}
  925. */
  926. textareaIntoFileConfigs: function (configs, filename) {
  927. var complexConfigName = this.get('complexConfigs').findProperty('filename', filename).name;
  928. var configsTextarea = configs.findProperty('name', complexConfigName);
  929. if (configsTextarea) {
  930. var properties = configsTextarea.get('value').replace(/( |\n)+/g, '\n').split('\n');
  931. properties.forEach(function (_property) {
  932. var name, value;
  933. if (_property) {
  934. _property = _property.split('=');
  935. name = _property[0];
  936. value = (_property[1]) ? _property[1] : "";
  937. configs.push(Em.Object.create({
  938. id: configsTextarea.get('id'),
  939. name: name,
  940. value: value,
  941. defaultValue: value,
  942. serviceName: configsTextarea.get('serviceName'),
  943. filename: filename
  944. }));
  945. }
  946. });
  947. return configs.without(configsTextarea);
  948. }
  949. console.log('ERROR: textarea config - ' + complexConfigName + ' is missing');
  950. return configs;
  951. },
  952. /**
  953. * trim trailing spaces for all properties.
  954. * trim both trailing and leading spaces for host displayType and hive/oozie datebases url.
  955. * for directory or directories displayType format string for further using.
  956. * for password and values with spaces only do nothing.
  957. * @param property
  958. * @returns {*}
  959. */
  960. trimProperty: function (property, isEmberObject) {
  961. var displayType = (isEmberObject) ? property.get('displayType') : property.displayType;
  962. var value = (isEmberObject) ? property.get('value') : property.value;
  963. var name = (isEmberObject) ? property.get('name') : property.name;
  964. var rez;
  965. switch (displayType) {
  966. case 'directories':
  967. case 'directory':
  968. rez = value.trim().split(/\s+/g).join(',');
  969. break;
  970. case 'host':
  971. rez = value.trim();
  972. break;
  973. case 'password':
  974. break;
  975. case 'advanced':
  976. if (name == 'javax.jdo.option.ConnectionURL' || name == 'oozie.service.JPAService.jdbc.url') {
  977. rez = value.trim();
  978. }
  979. default:
  980. rez = (typeof value == 'string') ? value.replace(/(\s+$)/g, '') : value;
  981. }
  982. return ((rez == '') || (rez == undefined)) ? value : rez;
  983. },
  984. OnNnHAHideSnn: function (ServiceConfig) {
  985. var configCategories = ServiceConfig.get('configCategories');
  986. var snCategory = configCategories.findProperty('name', 'SNameNode');
  987. var activeNn = App.HDFSService.find('HDFS').get('activeNameNode.hostName');
  988. if (snCategory && activeNn) {
  989. configCategories.removeObject(snCategory);
  990. }
  991. },
  992. /**
  993. * Launches a dialog where an existing config-group can be selected, or a new
  994. * one can be created. This is different than the config-group management
  995. * dialog where host membership can be managed.
  996. *
  997. * The callback will be passed the created/selected config-group in the form
  998. * of {id:2, name:'New hardware group'}. In the case of dialog being cancelled,
  999. * the callback is provided <code>null</code>
  1000. *
  1001. * @param callback Callback function which is invoked when dialog
  1002. * is closed, cancelled or OK is pressed.
  1003. */
  1004. saveGroupConfirmationPopup: function(groupName) {
  1005. App.ModalPopup.show({
  1006. header: Em.I18n.t('config.group.save.confirmation.header'),
  1007. secondary: Em.I18n.t('config.group.save.confirmation.manage.button'),
  1008. groupName: groupName,
  1009. bodyClass: Ember.View.extend({
  1010. templateName: require('templates/common/configs/saveConfigGroup')
  1011. }),
  1012. onSecondary: function() {
  1013. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups();
  1014. this.hide();
  1015. }
  1016. });
  1017. },
  1018. //Persist config groups created in step7 wizard controller
  1019. persistWizardStep7ConfigGroups: function () {
  1020. var installerController = App.router.get('installerController');
  1021. var step7Controller = App.router.get('wizardStep7Controller');
  1022. if (App.supports.hostOverridesInstaller) {
  1023. installerController.saveServiceConfigGroups(step7Controller);
  1024. App.clusterStatus.setClusterStatus({
  1025. localdb: App.db.data
  1026. });
  1027. }
  1028. },
  1029. launchConfigGroupSelectionCreationDialog : function(serviceId, configGroups, configProperty, callback, isInstaller) {
  1030. var self = this;
  1031. var availableConfigGroups = configGroups.slice();
  1032. // delete Config Groups, that already have selected property overridden
  1033. var alreadyOverriddenGroups = [];
  1034. if (configProperty.get('overrides')) {
  1035. alreadyOverriddenGroups = configProperty.get('overrides').mapProperty('group.name');
  1036. }
  1037. var result = [];
  1038. availableConfigGroups.forEach(function (group) {
  1039. if (!group.get('isDefault') && (!alreadyOverriddenGroups.length || !alreadyOverriddenGroups.contains(group.name))) {
  1040. result.push(group);
  1041. }
  1042. }, this);
  1043. availableConfigGroups = result;
  1044. var selectedConfigGroup = availableConfigGroups && availableConfigGroups.length > 0 ?
  1045. availableConfigGroups[0] : null;
  1046. var serviceName = App.Service.DisplayNames[serviceId];
  1047. App.ModalPopup.show({
  1048. classNames: [ 'sixty-percent-width-modal' ],
  1049. header: Em.I18n.t('config.group.selection.dialog.title').format(serviceName),
  1050. subTitle: Em.I18n.t('config.group.selection.dialog.subtitle').format(serviceName),
  1051. selectExistingGroupLabel: Em.I18n.t('config.group.selection.dialog.option.select').format(serviceName),
  1052. noGroups: Em.I18n.t('config.group.selection.dialog.no.groups').format(serviceName),
  1053. createNewGroupLabel: Em.I18n.t('config.group.selection.dialog.option.create').format(serviceName),
  1054. createNewGroupDescription: Em.I18n.t('config.group.selection.dialog.option.create.msg').format(serviceName),
  1055. warningMessage: '&nbsp;',
  1056. isWarning: false,
  1057. optionSelectConfigGroup: true,
  1058. optionCreateConfigGroup: function(){
  1059. return !this.get('optionSelectConfigGroup');
  1060. }.property('optionSelectConfigGroup'),
  1061. hasExistedGroups: function() {
  1062. return !!this.get('availableConfigGroups').length;
  1063. }.property('availableConfigGroups'),
  1064. availableConfigGroups: availableConfigGroups,
  1065. selectedConfigGroup: selectedConfigGroup,
  1066. newConfigGroupName: '',
  1067. enablePrimary: function () {
  1068. return this.get('optionSelectConfigGroup') || (this.get('newConfigGroupName').trim().length > 0 && !this.get('isWarning'));
  1069. }.property('newConfigGroupName', 'optionSelectConfigGroup', 'warningMessage'),
  1070. onPrimary: function () {
  1071. if (!this.get('enablePrimary')) {
  1072. return false;
  1073. }
  1074. if (this.get('optionSelectConfigGroup')) {
  1075. var selectedConfigGroup = this.get('selectedConfigGroup');
  1076. this.hide();
  1077. callback(selectedConfigGroup);
  1078. } else {
  1079. var newConfigGroupName = this.get('newConfigGroupName').trim();
  1080. var newConfigGroup = self.createNewConfigurationGroup(serviceId, newConfigGroupName, null, [], isInstaller);
  1081. if (newConfigGroup) {
  1082. newConfigGroup.set('parentConfigGroup', configGroups.findProperty('isDefault'));
  1083. configGroups.pushObject(newConfigGroup);
  1084. if (isInstaller) {
  1085. self.persistWizardStep7ConfigGroups();
  1086. } else {
  1087. self.saveGroupConfirmationPopup(newConfigGroupName);
  1088. }
  1089. this.hide();
  1090. callback(newConfigGroup);
  1091. }
  1092. }
  1093. },
  1094. onSecondary: function () {
  1095. this.hide();
  1096. callback(null);
  1097. },
  1098. doSelectConfigGroup: function (event) {
  1099. var configGroup = event.context;
  1100. console.log(configGroup);
  1101. this.set('selectedConfigGroup', configGroup);
  1102. },
  1103. validate: function () {
  1104. var msg = '&nbsp;';
  1105. var isWarning = false;
  1106. var optionSelect = this.get('optionSelectConfigGroup');
  1107. if (!optionSelect) {
  1108. var nn = this.get('newConfigGroupName');
  1109. if (nn && configGroups.mapProperty('name').contains(nn)) {
  1110. msg = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  1111. isWarning = true;
  1112. }
  1113. }
  1114. this.set('warningMessage', msg);
  1115. this.set('isWarning', isWarning);
  1116. }.observes('newConfigGroupName', 'optionSelectConfigGroup'),
  1117. bodyClass: Ember.View.extend({
  1118. templateName: require('templates/common/configs/selectCreateConfigGroup'),
  1119. controllerBinding: 'App.router.mainServiceInfoConfigsController',
  1120. selectConfigGroupRadioButton: Ember.Checkbox.extend({
  1121. tagName: 'input',
  1122. attributeBindings: ['type', 'checked', 'disabled'],
  1123. checked: function () {
  1124. return this.get('parentView.parentView.optionSelectConfigGroup');
  1125. }.property('parentView.parentView.optionSelectConfigGroup'),
  1126. type: 'radio',
  1127. disabled: false,
  1128. click: function () {
  1129. this.set('parentView.parentView.optionSelectConfigGroup', true);
  1130. },
  1131. didInsertElement: function () {
  1132. if (!this.get('parentView.parentView.hasExistedGroups')) {
  1133. this.set('disabled', true);
  1134. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1135. }
  1136. }
  1137. }),
  1138. createConfigGroupRadioButton: Ember.Checkbox.extend({
  1139. tagName: 'input',
  1140. attributeBindings: ['type', 'checked'],
  1141. checked: function () {
  1142. return !this.get('parentView.parentView.optionSelectConfigGroup');
  1143. }.property('parentView.parentView.optionSelectConfigGroup'),
  1144. type: 'radio',
  1145. click: function () {
  1146. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1147. }
  1148. })
  1149. })
  1150. });
  1151. },
  1152. /**
  1153. * launch dialog where can be assigned another group to host
  1154. * @param selectedGroup
  1155. * @param configGroups
  1156. * @param hostName
  1157. * @param callback
  1158. */
  1159. launchSwitchConfigGroupOfHostDialog: function (selectedGroup, configGroups, hostName, callback) {
  1160. var self = this;
  1161. App.ModalPopup.show({
  1162. header: Em.I18n.t('config.group.host.switch.dialog.title'),
  1163. configGroups: configGroups,
  1164. selectedConfigGroup: selectedGroup,
  1165. enablePrimary: function () {
  1166. return this.get('selectedConfigGroup.name') !== selectedGroup.get('name');
  1167. }.property('selectedConfigGroup'),
  1168. onPrimary: function () {
  1169. if (this.get('enablePrimary')) {
  1170. var newGroup = this.get('selectedConfigGroup');
  1171. selectedGroup.get('hosts').removeObject(hostName);
  1172. if (!selectedGroup.get('isDefault')) {
  1173. self.updateConfigurationGroup(selectedGroup, function(){}, function(){});
  1174. }
  1175. newGroup.get('hosts').pushObject(hostName);
  1176. callback(newGroup);
  1177. if (!newGroup.get('isDefault')) {
  1178. self.updateConfigurationGroup(newGroup, function(){}, function(){});
  1179. }
  1180. this.hide();
  1181. }
  1182. },
  1183. bodyClass: Ember.View.extend({
  1184. templateName: require('templates/utils/config_launch_switch_config_group_of_host')
  1185. })
  1186. });
  1187. },
  1188. /**
  1189. * Creates a new config-group for a service.
  1190. *
  1191. * @param serviceId Service for which this group has to be created
  1192. * @param configGroupName Name of the new config-group
  1193. * @param description Description of the new config-group
  1194. * @param hosts Hosts for the new config-group
  1195. * @param isInstaller Determines whether send data to server or not
  1196. * @param callback Callback function for Success or Error handling
  1197. * @return Returns the created config-group
  1198. */
  1199. createNewConfigurationGroup: function (serviceId, configGroupName, description, hosts, isInstaller, callback) {
  1200. var newConfigGroupData = App.ConfigGroup.create({
  1201. id: null,
  1202. name: configGroupName,
  1203. description: description || "New configuration group created on " + new Date().toDateString(),
  1204. isDefault: false,
  1205. parentConfigGroup: null,
  1206. service: App.Service.find().findProperty('serviceName', serviceId),
  1207. hosts: hosts || [],
  1208. configSiteTags: [],
  1209. properties: []
  1210. });
  1211. if (isInstaller) {
  1212. newConfigGroupData.set('service', Em.Object.create({id: serviceId}));
  1213. return newConfigGroupData;
  1214. }
  1215. var dataHosts = [];
  1216. newConfigGroupData.get('hosts').forEach(function (_host) {
  1217. dataHosts.push({
  1218. host_name: _host
  1219. });
  1220. }, this);
  1221. var sendData = {
  1222. name: 'config_groups.create',
  1223. data: {
  1224. 'group_name': configGroupName,
  1225. 'service_id': serviceId,
  1226. 'description': newConfigGroupData.description,
  1227. 'hosts': dataHosts
  1228. },
  1229. success: 'successFunction',
  1230. error: 'errorFunction',
  1231. successFunction: function (response) {
  1232. if (callback) {
  1233. callback();
  1234. } else {
  1235. newConfigGroupData.id = response.resources[0].ConfigGroup.id;
  1236. }
  1237. },
  1238. errorFunction: function (xhr, text, errorThrown) {
  1239. if (callback) {
  1240. callback(xhr, text, errorThrown);
  1241. } else {
  1242. newConfigGroupData = null;
  1243. }
  1244. console.error('Error in creating new Config Group');
  1245. }
  1246. };
  1247. sendData.sender = sendData;
  1248. App.ajax.send(sendData);
  1249. return newConfigGroupData;
  1250. },
  1251. /**
  1252. * PUTs the new configuration-group on the server.
  1253. * Changes possible here are the name, description and
  1254. * host memberships of the configuration-group.
  1255. *
  1256. * @param configGroup (App.ConfigGroup) Configuration group to update
  1257. */
  1258. updateConfigurationGroup: function (configGroup, successCallback, errorCallback) {
  1259. var putConfigGroup = {
  1260. ConfigGroup: {
  1261. group_name: configGroup.get('name'),
  1262. description: configGroup.get('description'),
  1263. tag: configGroup.get('service.id'),
  1264. hosts: [],
  1265. desired_configs: []
  1266. }
  1267. };
  1268. configGroup.get('hosts').forEach(function(h){
  1269. putConfigGroup.ConfigGroup.hosts.push({
  1270. host_name: h
  1271. });
  1272. });
  1273. configGroup.get('configSiteTags').forEach(function(cst){
  1274. putConfigGroup.ConfigGroup.desired_configs.push({
  1275. type: cst.get('site'),
  1276. tag: cst.get('tag')
  1277. });
  1278. });
  1279. var sendData = {
  1280. name: 'config_groups.update',
  1281. data: {
  1282. id: configGroup.get('id'),
  1283. data: putConfigGroup
  1284. },
  1285. success: 'successFunction',
  1286. error: 'errorFunction',
  1287. successFunction: function () {
  1288. if(successCallback) {
  1289. successCallback();
  1290. }
  1291. },
  1292. errorFunction: function (xhr, text, errorThrown) {
  1293. if(errorCallback) {
  1294. errorCallback(xhr, text, errorThrown);
  1295. }
  1296. }
  1297. };
  1298. sendData.sender = sendData;
  1299. App.ajax.send(sendData);
  1300. },
  1301. clearConfigurationGroupHosts: function (configGroup, successCallback, errorCallback) {
  1302. configGroup = jQuery.extend({}, configGroup);
  1303. configGroup.set('hosts', []);
  1304. this.updateConfigurationGroup(configGroup, successCallback, errorCallback);
  1305. },
  1306. deleteConfigGroup: function (configGroup, successCallback, errorCallback) {
  1307. var sendData = {
  1308. name: 'config_groups.delete_config_group',
  1309. sender: this,
  1310. data: {
  1311. id: configGroup.get('id')
  1312. },
  1313. success: 'successFunction',
  1314. error: 'errorFunction',
  1315. successFunction: function () {
  1316. if(successCallback) {
  1317. successCallback();
  1318. }
  1319. },
  1320. errorFunction: function (xhr, text, errorThrown) {
  1321. if(errorCallback) {
  1322. errorCallback(xhr, text, errorThrown);
  1323. }
  1324. }
  1325. };
  1326. sendData.sender = sendData;
  1327. App.ajax.send(sendData);
  1328. },
  1329. /**
  1330. * Gets all the configuration-groups for the given service.
  1331. *
  1332. * @param serviceId
  1333. * (string) ID of the service. Ex: HDFS
  1334. * @return Array of App.ConfigGroups
  1335. */
  1336. getConfigGroupsForService: function (serviceId) {
  1337. },
  1338. /**
  1339. * Gets all the configuration-groups for a host.
  1340. *
  1341. * @param hostName
  1342. * (string) host name used to register
  1343. * @return Array of App.ConfigGroups
  1344. */
  1345. getConfigGroupsForHost: function (hostName) {
  1346. }
  1347. });