configs.js 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863
  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. isHostsConfigsPage: false,
  23. dataIsLoaded: false,
  24. stepConfigs: [], //contains all field properties that are viewed in this service
  25. selectedService: null,
  26. serviceConfigTags: null,
  27. selectedConfigGroup: null,
  28. configGroups: [],
  29. globalConfigs: [],
  30. uiConfigs: [],
  31. customConfig: [],
  32. serviceConfigsData: require('data/service_configs'),
  33. isApplyingChanges: false,
  34. // contain Service Config Property, when user proceed from Select Config Group dialog
  35. overrideToAdd: null,
  36. allConfigGroupsNames: [],
  37. serviceConfigs: function () {
  38. return App.config.get('preDefinedServiceConfigs');
  39. }.property('App.config.preDefinedServiceConfigs'),
  40. customConfigs: function () {
  41. return App.config.get('preDefinedCustomConfigs');
  42. }.property('App.config.preDefinedCustomConfigs'),
  43. configMapping: function () {
  44. return App.config.get('configMapping');
  45. }.property('App.config.configMapping'),
  46. configs: function () {
  47. return App.config.get('preDefinedGlobalProperties');
  48. }.property('App.config.preDefinedGlobalProperties'),
  49. secureConfigs: function () {
  50. if (App.get('isHadoop2Stack')) {
  51. return require('data/HDP2/secure_mapping');
  52. } else {
  53. return require('data/secure_mapping');
  54. }
  55. }.property('App.isHadoop2Stack'),
  56. /**
  57. * During page load time, we get the host overrides from the server.
  58. * The current host -> site:tag map is stored below. This will be
  59. * useful during save, so that removals can also be determined.
  60. *
  61. * Example:
  62. * {
  63. * 'hostname1':{
  64. * 'global': 'version1',
  65. * 'core-site': 'version1',
  66. * 'hdfs-site', 'tag3187261938'
  67. * }
  68. * }
  69. *
  70. * @see savedHostToOverrideSiteToTagMap
  71. */
  72. loadedGroupToOverrideSiteToTagMap: {},
  73. /**
  74. * During page load time the cluster level site to tag
  75. * mapping is stored here.
  76. *
  77. * Example:
  78. * {
  79. * 'global': 'version1',
  80. * 'hdfs-site': 'version1',
  81. * 'core-site': 'version1'
  82. * }
  83. */
  84. loadedClusterSiteToTagMap: {},
  85. /**
  86. * During page save time, we set the host overrides to the server.
  87. * The new host -> site:tag map is stored below. This will be
  88. * useful during save, to update the host's host components. Also,
  89. * it will be useful in deletion of overrides.
  90. *
  91. * Example:
  92. * {
  93. * 'hostname1': {
  94. * 'global': {
  95. * 'tagName': 'tag3187261938_hostname1',
  96. * 'map': {
  97. * 'hadoop_heapsize': '2048m'
  98. * }
  99. * }
  100. * }
  101. * }
  102. *
  103. * @see loadedHostToOverrideSiteToTagMap
  104. */
  105. savedHostToOverrideSiteToTagMap: {},
  106. /**
  107. * Holds the actual base service-config server data uploaded.
  108. * This is used by the host-override mechanism to update host
  109. * specific values.
  110. */
  111. savedSiteNameToServerServiceConfigDataMap: {},
  112. isSubmitDisabled: function () {
  113. return (!(this.stepConfigs.everyProperty('errorCount', 0)) || this.get('isApplyingChanges'));
  114. }.property('stepConfigs.@each.errorCount', 'isApplyingChanges'),
  115. slaveComponentGroups: null,
  116. /**
  117. * Filter text will be located here
  118. */
  119. filter: '',
  120. /**
  121. * Dropdown menu items in filter combobox
  122. */
  123. filterColumns: function () {
  124. var result = [];
  125. for (var i = 1; i < 2; i++) {
  126. result.push(Ember.Object.create({
  127. name: this.t('common.combobox.dropdown.' + i),
  128. selected: false
  129. }));
  130. }
  131. return result;
  132. }.property(),
  133. /**
  134. * clear and set properties to default value
  135. */
  136. clearStep: function () {
  137. this.set('dataIsLoaded', false);
  138. this.set('filter', '');
  139. this.get('filterColumns').setEach('selected', false);
  140. this.get('stepConfigs').clear();
  141. this.get('globalConfigs').clear();
  142. this.get('uiConfigs').clear();
  143. this.get('customConfig').clear();
  144. this.set('loadedGroupToOverrideSiteToTagMap', {});
  145. this.set('savedHostToOverrideSiteToTagMap', {});
  146. this.set('savedSiteNameToServerServiceConfigDataMap', {});
  147. if (this.get('serviceConfigTags')) {
  148. this.set('serviceConfigTags', null);
  149. }
  150. },
  151. serviceConfigProperties: function () {
  152. return App.db.getServiceConfigProperties();
  153. }.property('content'),
  154. /**
  155. * On load function
  156. */
  157. loadStep: function () {
  158. console.log("TRACE: Loading configure for service");
  159. this.clearStep();
  160. this.loadServiceConfigs();
  161. },
  162. /**
  163. * Loads the actual configuration of all host components.
  164. * This helps in determining which services need a restart, and also
  165. * in showing which properties are actually applied or not.
  166. * This method also compares the actual_configs with the desired_configs
  167. * and builds a diff structure.
  168. *
  169. * Internally it calculates an array of host-components which need restart.
  170. * Example:
  171. * [
  172. * {
  173. * componentName: 'DATANODE',
  174. * serviceName: 'HDFS',
  175. * host: 'host.name',
  176. * type: 'core-site',
  177. * desiredConfigTags: {tag:'version1'},
  178. * actualConfigTags: {tag:'version4'. host_override:'version2'}
  179. * },
  180. * ...
  181. * ]
  182. *
  183. * From there it return the following restart-data for this service.
  184. * It represents the hosts, whose components need restart, and the
  185. * properties which require restart.
  186. *
  187. * {
  188. * hostAndHostComponents: {
  189. * 'hostname1': {
  190. * 'DATANODE': {
  191. * 'property1': 'value1',
  192. * 'property2': 'value2'
  193. * },
  194. * 'TASKTRACKER': {
  195. * 'prop1': 'val1'
  196. * }
  197. * },
  198. * 'hostname6': {
  199. * 'ZOOKEEPER': {
  200. * 'property1': 'value3'
  201. * }
  202. * }
  203. * },
  204. * propertyToHostAndComponent: {
  205. * 'property1': {
  206. * 'hostname1': ['DATANODE'],
  207. * 'hostname6': ['ZOOKEEPER']
  208. * },
  209. * 'property2': {
  210. * 'hostname1': ['DATANODE']
  211. * },
  212. * 'prop1': {
  213. * 'hostname1': ['TASKTRACKER']
  214. * }
  215. * }
  216. * }
  217. */
  218. loadActualConfigsAndCalculateRestarts: function () {
  219. var currentService = this.get('content.serviceName');
  220. var restartData = {
  221. hostAndHostComponents: {},
  222. propertyToHostAndComponent: {}
  223. };
  224. var self = this;
  225. console.log("loadActualConfigsAndCalculateRestarts(): Restart data = ", restartData);
  226. return restartData;
  227. },
  228. /**
  229. * Loads service configurations
  230. */
  231. loadServiceConfigs: function () {
  232. App.ajax.send({
  233. name: 'config.tags_and_groups',
  234. sender: this,
  235. data: {
  236. serviceName: this.get('content.serviceName'),
  237. serviceConfigsDef: this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'))
  238. },
  239. success: 'loadServiceTagsSuccess'
  240. });
  241. },
  242. loadServiceTagsSuccess: function (data, opt, params) {
  243. var serviceConfigsDef = params.serviceConfigsDef;
  244. var serviceName = this.get('content.serviceName');
  245. console.debug("loadServiceConfigs(): data=", data);
  246. // Create default configuration group
  247. var defaultConfigGroupHosts = App.Host.find().mapProperty('hostName');
  248. var selectedConfigGroup;
  249. var allConfigGroupsNames = ['Default'];
  250. var siteToTagMap = {};
  251. for (var site in data.Clusters.desired_configs) {
  252. if (serviceConfigsDef.sites.indexOf(site) > -1) {
  253. siteToTagMap[site] = data.Clusters.desired_configs[site].tag;
  254. }
  255. }
  256. this.loadedClusterSiteToTagMap = siteToTagMap;
  257. //parse loaded config groups
  258. if (App.supports.hostOverrides) {
  259. var configGroups = [];
  260. if (data.config_groups.length) {
  261. data.config_groups.forEach(function (item) {
  262. item = item.ConfigGroup;
  263. allConfigGroupsNames.push(item.group_name);
  264. if (item.tag === this.get('content.serviceName')) {
  265. var groupHosts = item.hosts.mapProperty('host_name');
  266. var newConfigGroup = App.ConfigGroup.create({
  267. id: item.id,
  268. name: item.group_name,
  269. description: item.description,
  270. isDefault: false,
  271. parentConfigGroup: null,
  272. service: App.Service.find().findProperty('serviceName', item.tag),
  273. hosts: groupHosts,
  274. configSiteTags: []
  275. });
  276. groupHosts.forEach(function (host) {
  277. defaultConfigGroupHosts = defaultConfigGroupHosts.without(host);
  278. }, this);
  279. item.desired_configs.forEach(function (config) {
  280. newConfigGroup.configSiteTags.push(App.ConfigSiteTag.create({
  281. site: config.type,
  282. tag: config.tag
  283. }));
  284. }, this);
  285. // select default selected group for hosts page
  286. if (!selectedConfigGroup && this.get('isHostsConfigsPage') && newConfigGroup.get('hosts').contains(this.get('host.hostName')) && this.get('content.serviceName') === item.tag) {
  287. selectedConfigGroup = newConfigGroup;
  288. }
  289. configGroups.push(newConfigGroup);
  290. }
  291. }, this);
  292. this.set('allConfigGroupsNames', allConfigGroupsNames);
  293. }
  294. this.set('configGroups', configGroups);
  295. }
  296. var defaultConfigGroup = App.ConfigGroup.create({
  297. name: "Default",
  298. description: "Default cluster level " + serviceName + " configuration",
  299. isDefault: true,
  300. hosts: defaultConfigGroupHosts,
  301. parentConfigGroup: null,
  302. service: this.get('content'),
  303. configSiteTags: []
  304. });
  305. if (!selectedConfigGroup) {
  306. selectedConfigGroup = defaultConfigGroup;
  307. }
  308. this.get('configGroups').push(defaultConfigGroup);
  309. this.get('configGroups').sort(function(configGroup){
  310. if(configGroup.isDefault){
  311. return false;
  312. }
  313. return true;
  314. });
  315. this.set('selectedConfigGroup', selectedConfigGroup);
  316. },
  317. onConfigGroupChange: function () {
  318. this.get('stepConfigs').clear();
  319. var selectedConfigGroup = this.get('selectedConfigGroup');
  320. var serviceName = this.get('content.serviceName');
  321. //STEP 1: handle tags from JSON data for host overrides
  322. this.loadedGroupToOverrideSiteToTagMap = {};
  323. if (App.supports.hostOverrides) {
  324. var configGroupsWithOverrides = selectedConfigGroup.get('isDefault') && !this.get('isHostsConfigsPage') ? this.get('configGroups') : [selectedConfigGroup];
  325. configGroupsWithOverrides.forEach(function (item) {
  326. var groupName = item.get('name');
  327. this.loadedGroupToOverrideSiteToTagMap[groupName] = {};
  328. item.get('configSiteTags').forEach(function (siteTag) {
  329. var site = siteTag.get('site');
  330. var tag = siteTag.get('tag');
  331. this.loadedGroupToOverrideSiteToTagMap[groupName][site] = tag;
  332. }, this);
  333. }, this);
  334. }
  335. //STEP 2: Create an array of objects defining tag names to be polled and new tag names to be set after submit
  336. this.setServiceConfigTags(this.loadedClusterSiteToTagMap);
  337. //STEP 3: Load advanced configs from server
  338. var advancedConfigs = App.config.loadAdvancedConfig(serviceName) || [];
  339. //STEP 4: Load on-site config by service from server
  340. var configGroups = App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags'));
  341. //STEP 5: Merge global and on-site configs with pre-defined
  342. var configSet = App.config.mergePreDefinedWithLoaded(configGroups, advancedConfigs, this.get('serviceConfigTags'), serviceName);
  343. configSet = App.config.syncOrderWithPredefined(configSet);
  344. //var serviceConfigs = this.getSitesConfigProperties(advancedConfigs);
  345. var configs = configSet.configs;
  346. //put global configs into globalConfigs to save them separately
  347. this.set('globalConfigs', configSet.globalConfigs);
  348. //STEP 6: add advanced configs
  349. //App.config.addAdvancedConfigs(configs, advancedConfigs, serviceName);
  350. //STEP 7: add custom configs
  351. App.config.addCustomConfigs(configs);
  352. //put properties from capacity-scheduler.xml into one config with textarea view
  353. if (this.get('content.serviceName') === 'YARN' && !App.supports.capacitySchedulerUi) {
  354. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  355. }
  356. //STEP 8: add configs as names of host components
  357. this.addHostNamesToGlobalConfig();
  358. var allConfigs = this.get('globalConfigs').concat(configs);
  359. //STEP 9: Load and add host override configs
  360. this.loadServiceConfigHostsOverrides(allConfigs, this.loadedGroupToOverrideSiteToTagMap, this.get('configGroups'));
  361. var restartData = this.loadActualConfigsAndCalculateRestarts();
  362. //STEP 10: creation of serviceConfig object which contains configs for current service
  363. var serviceConfig = App.config.createServiceConfig(serviceName);
  364. //STEP11: Make SecondaryNameNode invisible on enabling namenode HA
  365. if (serviceConfig.get('serviceName') === 'HDFS') {
  366. App.config.OnNnHAHideSnn(serviceConfig);
  367. }
  368. this.checkForRestart(serviceConfig, restartData);
  369. if (serviceName || serviceConfig.serviceName === 'MISC') {
  370. //STEP 11: render configs and wrap each in ServiceConfigProperty object
  371. this.loadComponentConfigs(allConfigs, serviceConfig, restartData);
  372. this.get('stepConfigs').pushObject(serviceConfig);
  373. }
  374. this.set('selectedService', this.get('stepConfigs').objectAt(0));
  375. this.checkForSecureConfig(this.get('selectedService'));
  376. this.set('dataIsLoaded', true);
  377. }.observes('selectedConfigGroup'),
  378. loadServiceConfigHostsOverrides: function (allConfigs, loadedGroupToOverrideSiteToTagMap, configGroups) {
  379. App.config.loadServiceConfigHostsOverrides(allConfigs, loadedGroupToOverrideSiteToTagMap, configGroups);
  380. },
  381. /**
  382. * Changes format from Object to Array
  383. *
  384. * {
  385. * 'core-site': 'version1',
  386. * 'hdfs-site': 'version1',
  387. * 'global': 'version2',
  388. * ...
  389. * }
  390. *
  391. * to
  392. *
  393. * [
  394. * {
  395. * siteName: 'core-site',
  396. * tagName: 'version1',
  397. * newTageName: null
  398. * },
  399. * ...
  400. * ]
  401. *
  402. * set tagnames for configuration of the *-site.xml
  403. */
  404. setServiceConfigTags: function (desiredConfigsSiteTags) {
  405. console.debug("setServiceConfigTags(): Trying to set ", desiredConfigsSiteTags);
  406. var newServiceConfigTags = [];
  407. for (var index in desiredConfigsSiteTags) {
  408. newServiceConfigTags.pushObject({
  409. siteName: index,
  410. tagName: desiredConfigsSiteTags[index],
  411. newTagName: null
  412. }, this);
  413. }
  414. console.debug("setServiceConfigTags(): Setting 'serviceConfigTags' to ", newServiceConfigTags);
  415. this.set('serviceConfigTags', newServiceConfigTags);
  416. },
  417. /**
  418. * check whether host component must be restarted
  419. * @param serviceConfig
  420. * @param restartData
  421. */
  422. checkForRestart: function (serviceConfig, restartData) {
  423. var hostsCount = 0;
  424. var hostComponentCount = 0;
  425. var restartHosts = Ember.A([]);
  426. if (restartData != null && restartData.hostAndHostComponents != null && !jQuery.isEmptyObject(restartData.hostAndHostComponents)) {
  427. serviceConfig.set('restartRequired', true);
  428. for (var host in restartData.hostAndHostComponents) {
  429. hostsCount++;
  430. var componentsArray = Ember.A([]);
  431. for (var component in restartData.hostAndHostComponents[host]) {
  432. componentsArray.push(Ember.Object.create({name: App.format.role(component)}));
  433. hostComponentCount++;
  434. }
  435. var hostObj = App.Host.find(host);
  436. restartHosts.push(Ember.Object.create({hostData: hostObj, components: componentsArray}))
  437. }
  438. serviceConfig.set('restartRequiredHostsAndComponents', restartHosts);
  439. serviceConfig.set('restartRequiredMessage', 'Service needs ' + hostComponentCount + ' components on ' + hostsCount + ' hosts to be restarted.')
  440. }
  441. },
  442. /**
  443. * check whether the config property is a security related knob
  444. * @param serviceConfig
  445. */
  446. checkForSecureConfig: function (serviceConfig) {
  447. serviceConfig.get('configs').forEach(function (_config) {
  448. this.get('secureConfigs').forEach(function (_secureConfig) {
  449. if (_config.get('name') === _secureConfig.name) {
  450. _config.set('isSecureConfig', true);
  451. }
  452. }, this)
  453. }, this)
  454. },
  455. /**
  456. * Get info about hosts and host components to configDefaultsProviders
  457. * @returns {{masterComponentHosts: Array, slaveComponentHosts: Array, hosts: {}}}
  458. */
  459. getInfoForDefaults: function() {
  460. var slaveComponentHosts = [];
  461. var slaves = App.HostComponent.find().filterProperty('isSlave', true).map(function(item) {
  462. return Em.Object.create({
  463. host: item.get('host.hostName'),
  464. componentName: item.get('componentName')
  465. });
  466. });
  467. slaves.forEach(function(slave) {
  468. var s = slaveComponentHosts.findProperty('componentName', slave.componentName);
  469. if (s) {
  470. s.hosts.push({hostName: slave.host});
  471. }
  472. else {
  473. slaveComponentHosts.push({
  474. componentName: slave.get('componentName'),
  475. hosts: [{hostName: slave.host}]
  476. });
  477. }
  478. });
  479. var masterComponentHosts = App.HostComponent.find().filterProperty('isMaster', true).map(function(item) {
  480. return {
  481. component: item.get('componentName'),
  482. serviceId: item.get('service.serviceName'),
  483. host: item.get('host.hostName')
  484. }
  485. });
  486. var hosts = {};
  487. App.Host.find().map(function(host) {
  488. hosts[host.get('hostName')] = {
  489. name: host.get('hostName'),
  490. cpu: host.get('cpu'),
  491. memory: host.get('memory'),
  492. disk_info: host.get('diskInfo')
  493. };
  494. });
  495. return {
  496. masterComponentHosts: masterComponentHosts,
  497. slaveComponentHosts: slaveComponentHosts,
  498. hosts: hosts
  499. };
  500. },
  501. /**
  502. * Load child components to service config object
  503. * @param configs
  504. * @param componentConfig
  505. * @param restartData
  506. */
  507. loadComponentConfigs: function (configs, componentConfig, restartData) {
  508. var localDB = this.getInfoForDefaults();
  509. var recommendedDefaults = {};
  510. var s = this.get('serviceConfigsData').findProperty('serviceName', this.get('content.serviceName'));
  511. var defaultGroupSelected = this.get('selectedConfigGroup.isDefault');
  512. var defaults = [];
  513. if (s.defaultsProviders) {
  514. s.defaultsProviders.forEach(function(defaultsProvider) {
  515. var d = defaultsProvider.getDefaults(localDB);
  516. defaults.push(d);
  517. for (var name in d) {
  518. recommendedDefaults[name] = d[name];
  519. }
  520. });
  521. }
  522. if (s.configsValidator) {
  523. s.configsValidator.set('recommendedDefaults', recommendedDefaults);
  524. }
  525. configs.forEach(function (_serviceConfigProperty) {
  526. console.log("config", _serviceConfigProperty);
  527. if (!_serviceConfigProperty) return;
  528. var overrides = _serviceConfigProperty.overrides;
  529. // we will populate the override properties below
  530. _serviceConfigProperty.overrides = null;
  531. if (_serviceConfigProperty.isOverridable === undefined) {
  532. _serviceConfigProperty.isOverridable = true;
  533. }
  534. if (_serviceConfigProperty.displayType === 'checkbox') {
  535. switch (_serviceConfigProperty.value) {
  536. case 'true':
  537. _serviceConfigProperty.value = true;
  538. _serviceConfigProperty.defaultValue = true;
  539. break;
  540. case 'false':
  541. _serviceConfigProperty.value = false;
  542. _serviceConfigProperty.defaultValue = false;
  543. break;
  544. }
  545. }
  546. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  547. var propertyName = serviceConfigProperty.get('name');
  548. if (restartData != null && propertyName in restartData.propertyToHostAndComponent) {
  549. serviceConfigProperty.set('isRestartRequired', true);
  550. var message = '<ul>';
  551. for (var host in restartData.propertyToHostAndComponent[propertyName]) {
  552. var appHost = App.Host.find(host);
  553. message += "<li>" + appHost.get('publicHostName');
  554. message += "<ul>";
  555. restartData.propertyToHostAndComponent[propertyName][host].forEach(function (comp) {
  556. message += "<li>" + App.format.role(comp) + "</li>"
  557. });
  558. message += "</ul></li>";
  559. }
  560. message += "</ul>";
  561. serviceConfigProperty.set('restartRequiredMessage', message);
  562. }
  563. if (serviceConfigProperty.get('serviceName') === this.get('content.serviceName')) {
  564. // Do not reset values when reconfiguring.
  565. // This might be useful to setting better descriptions
  566. // or default values sometime in the future.
  567. // defaults.forEach(function(defaults) {
  568. // for(var name in defaults) {
  569. // if (serviceConfigProperty.name == name) {
  570. // serviceConfigProperty.set('value', defaults[name]);
  571. // serviceConfigProperty.set('defaultValue', defaults[name]);
  572. // }
  573. // }
  574. // });
  575. if (s.configsValidator) {
  576. var validators = s.configsValidator.get('configValidators');
  577. for (var validatorName in validators) {
  578. if (serviceConfigProperty.name == validatorName) {
  579. serviceConfigProperty.set('serviceValidator', s.configsValidator);
  580. }
  581. }
  582. }
  583. console.log("config result", serviceConfigProperty);
  584. } else {
  585. serviceConfigProperty.set('isVisible', false);
  586. }
  587. if (overrides != null) {
  588. overrides.forEach(function (override) {
  589. var newSCP = App.ServiceConfigProperty.create(_serviceConfigProperty);
  590. newSCP.set('value', override.value);
  591. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  592. newSCP.set('parentSCP', serviceConfigProperty);
  593. if (App.supports.hostOverrides && defaultGroupSelected) {
  594. newSCP.set('group', override.group);
  595. newSCP.set('isEditable', false);
  596. }
  597. var parentOverridesArray = serviceConfigProperty.get('overrides');
  598. if (parentOverridesArray == null) {
  599. parentOverridesArray = Ember.A([]);
  600. serviceConfigProperty.set('overrides', parentOverridesArray);
  601. }
  602. parentOverridesArray.pushObject(newSCP);
  603. console.debug("createOverrideProperty(): Added:", newSCP, " to main-property:", serviceConfigProperty)
  604. }, this)
  605. }
  606. if (App.get('isAdmin')) {
  607. if(defaultGroupSelected && !this.get('isHostsConfigsPage')){
  608. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  609. }else{
  610. serviceConfigProperty.set('isEditable', false);
  611. }
  612. } else {
  613. serviceConfigProperty.set('isEditable', false);
  614. }
  615. componentConfig.configs.pushObject(serviceConfigProperty);
  616. serviceConfigProperty.validate();
  617. }, this);
  618. var overrideToAdd = this.get('overrideToAdd');
  619. if (overrideToAdd) {
  620. overrideToAdd = componentConfig.configs.findProperty('name', overrideToAdd.name);
  621. if (overrideToAdd) {
  622. this.addOverrideProperty(overrideToAdd);
  623. this.set('overrideToAdd', null);
  624. }
  625. }
  626. },
  627. /**
  628. * Determines which host components are running on each host.
  629. * @param status 'running' or 'unknown'
  630. * @return Returned in the following format:
  631. * {
  632. * runningHosts: {
  633. * 'hostname1': 'NameNode, DataNode, JobTracker',
  634. * 'hostname2': 'DataNode',
  635. * },
  636. * runningComponentCount: 5
  637. * }
  638. */
  639. getHostComponentsByStatus: function (services, status) {
  640. var hosts = [];
  641. var componentCount = 0;
  642. var hostToIndexMap = {};
  643. services.forEach(function (service) {
  644. var hostComponents = (status == App.HostComponentStatus.started) ? service.get('runningHostComponents') : service.get('unknownHostComponents');
  645. if (hostComponents != null) {
  646. hostComponents.forEach(function (hc) {
  647. var hostName = hc.get('host.publicHostName');
  648. var componentName = hc.get('displayName');
  649. componentCount++;
  650. if (!(hostName in hostToIndexMap)) {
  651. hosts.push({
  652. name: hostName,
  653. components: ""
  654. });
  655. hostToIndexMap[hostName] = hosts.length - 1;
  656. }
  657. var hostObj = hosts[hostToIndexMap[hostName]];
  658. if (hostObj.components.length > 0)
  659. hostObj.components += ", " + componentName;
  660. else
  661. hostObj.components += componentName;
  662. });
  663. hosts.sort(function (a, b) {
  664. return a.name.localeCompare(b.name);
  665. });
  666. }
  667. });
  668. return {
  669. hosts: hosts,
  670. componentCount: componentCount
  671. };
  672. },
  673. /**
  674. * open popup with appropriate message
  675. */
  676. restartServicePopup: function (event) {
  677. if (this.get("isSubmitDisabled")) {
  678. return;
  679. }
  680. var header;
  681. var message;
  682. var messageClass;
  683. var hasUnknown = false;
  684. var value;
  685. var flag = false;
  686. var runningHosts = null;
  687. var runningComponentCount = 0;
  688. var unknownHosts = null;
  689. var unknownComponentCount = 0;
  690. var dfd = $.Deferred();
  691. var self = this;
  692. var serviceName = this.get('content.serviceName');
  693. var displayName = this.get('content.displayName');
  694. if (App.supports.hostOverrides ||
  695. (serviceName !== 'HDFS' && this.get('content.isStopped') === true) ||
  696. ((serviceName === 'HDFS') && this.get('content.isStopped') === true && (!App.Service.find().someProperty('id', 'MAPREDUCE') || App.Service.find('MAPREDUCE').get('isStopped')))) {
  697. // warn the user if any service directories are being changed
  698. var dirChanged = false;
  699. if (serviceName === 'HDFS') {
  700. var hdfsConfigs = self.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs');
  701. if (App.get('isHadoop2Stack')) {
  702. if (
  703. hdfsConfigs.findProperty('name', 'dfs.namenode.name.dir').get('isNotDefaultValue') ||
  704. hdfsConfigs.findProperty('name', 'dfs.namenode.checkpoint.dir').get('isNotDefaultValue') ||
  705. hdfsConfigs.findProperty('name', 'dfs.datanode.data.dir').get('isNotDefaultValue')
  706. ) {
  707. dirChanged = true;
  708. }
  709. } else {
  710. if (
  711. hdfsConfigs.findProperty('name', 'dfs.name.dir').get('isNotDefaultValue') ||
  712. hdfsConfigs.findProperty('name', 'fs.checkpoint.dir').get('isNotDefaultValue') ||
  713. hdfsConfigs.findProperty('name', 'dfs.data.dir').get('isNotDefaultValue')
  714. ) {
  715. dirChanged = true;
  716. }
  717. }
  718. } else if (serviceName === 'MAPREDUCE') {
  719. var mapredConfigs = self.get('stepConfigs').findProperty('serviceName', 'MAPREDUCE').get('configs');
  720. if (
  721. mapredConfigs.findProperty('name', 'mapred.local.dir').get('isNotDefaultValue') ||
  722. mapredConfigs.findProperty('name', 'mapred.system.dir').get('isNotDefaultValue')
  723. ) {
  724. dirChanged = true;
  725. }
  726. }
  727. if (dirChanged) {
  728. App.showConfirmationPopup(function () {
  729. dfd.resolve();
  730. }, Em.I18n.t('services.service.config.confirmDirectoryChange').format(displayName));
  731. } else {
  732. dfd.resolve();
  733. }
  734. dfd.done(function () {
  735. var result = self.saveServiceConfigProperties();
  736. App.router.get('clusterController').updateClusterData();
  737. App.router.get('updateController').updateComponentConfig(function(){});
  738. flag = result.flag;
  739. if (result.flag === true) {
  740. header = Em.I18n.t('services.service.config.saved');
  741. message = Em.I18n.t('services.service.config.saved.message');
  742. messageClass = 'alert alert-success';
  743. // warn the user if any of the components are in UNKNOWN state
  744. var uhc;
  745. if (self.get('content.serviceName') !== 'HDFS' || (self.get('content.serviceName') === 'HDFS' && !App.Service.find().someProperty('id', 'MAPREDUCE'))) {
  746. uhc = self.getHostComponentsByStatus([self.get('content')], App.HostComponentStatus.unknown);
  747. } else {
  748. uhc = self.getHostComponentsByStatus([self.get('content'), App.Service.find('MAPREDUCE')], App.HostComponentStatus.unknown);
  749. }
  750. unknownHosts = uhc.hosts;
  751. unknownComponentCount = uhc.componentCount;
  752. } else {
  753. header = Em.I18n.t('common.failure');
  754. message = result.message;
  755. messageClass = 'alert alert-error';
  756. value = result.value;
  757. }
  758. });
  759. } else {
  760. var rhc;
  761. if (this.get('content.serviceName') !== 'HDFS' || (this.get('content.serviceName') === 'HDFS' && !App.Service.find().someProperty('id', 'MAPREDUCE'))) {
  762. rhc = this.getHostComponentsByStatus([this.get('content')], App.HostComponentStatus.started);
  763. header = Em.I18n.t('services.service.config.notSaved');
  764. message = Em.I18n.t('services.service.config.msgServiceStop');
  765. } else {
  766. rhc = this.getHostComponentsByStatus([this.get('content'), App.Service.find('MAPREDUCE')], App.HostComponentStatus.started);
  767. header = Em.I18n.t('services.service.config.notSaved');
  768. message = Em.I18n.t('services.service.config.msgHDFSMapRServiceStop');
  769. }
  770. messageClass = 'alert alert-error';
  771. runningHosts = rhc.hosts;
  772. runningComponentCount = rhc.componentCount;
  773. dfd.resolve();
  774. }
  775. dfd.done(function () {
  776. App.ModalPopup.show({
  777. header: header,
  778. primary: Em.I18n.t('ok'),
  779. secondary: null,
  780. onPrimary: function () {
  781. this.hide();
  782. if (flag) {
  783. self.loadStep();
  784. }
  785. },
  786. bodyClass: Ember.View.extend({
  787. flag: flag,
  788. message: message,
  789. messageClass: messageClass,
  790. runningHosts: runningHosts,
  791. runningComponentCount: runningComponentCount,
  792. unknownHosts: unknownHosts,
  793. unknownComponentCount: unknownComponentCount,
  794. siteProperties: value,
  795. getDisplayMessage: function () {
  796. var displayMsg = [];
  797. var siteProperties = this.get('siteProperties');
  798. if (siteProperties) {
  799. siteProperties.forEach(function (_siteProperty) {
  800. var displayProperty = _siteProperty.siteProperty;
  801. var displayNames = _siteProperty.displayNames;
  802. /////////
  803. if (displayNames && displayNames.length) {
  804. if (displayNames.length === 1) {
  805. displayMsg.push(displayProperty + Em.I18n.t('as') + displayNames[0]);
  806. } else {
  807. var name;
  808. displayNames.forEach(function (_name, index) {
  809. if (index === 0) {
  810. name = _name;
  811. } else if (index === siteProperties.length - 1) {
  812. name = name + Em.I18n.t('and') + _name;
  813. } else {
  814. name = name + ', ' + _name;
  815. }
  816. }, this);
  817. displayMsg.push(displayProperty + Em.I18n.t('as') + name);
  818. }
  819. } else {
  820. displayMsg.push(displayProperty);
  821. }
  822. }, this);
  823. }
  824. return displayMsg;
  825. }.property('siteProperties'),
  826. runningHostsMessage: function () {
  827. return Em.I18n.t('services.service.config.stopService.runningHostComponents').format(this.get('runningComponentCount'), this.get('runningHosts.length'));
  828. }.property('runningComponentCount', 'runningHosts.length'),
  829. unknownHostsMessage: function () {
  830. return Em.I18n.t('services.service.config.stopService.unknownHostComponents').format(this.get('unknownComponentCount'), this.get('unknownHosts.length'));
  831. }.property('unknownComponentCount', 'unknownHosts.length'),
  832. templateName: require('templates/main/service/info/configs_save_popup')
  833. })
  834. })
  835. });
  836. },
  837. /**
  838. * Save config properties
  839. */
  840. saveServiceConfigProperties: function () {
  841. var result = {
  842. flag: false,
  843. message: null,
  844. value: null
  845. };
  846. var selectedConfigGroup = this.get('selectedConfigGroup');
  847. var configs = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName')).get('configs');
  848. if (selectedConfigGroup.get('isDefault')) {
  849. this.saveGlobalConfigs(configs);
  850. if (this.get('content.serviceName') === 'YARN' && !App.supports.capacitySchedulerUi) {
  851. configs = App.config.textareaIntoFileConfigs(configs, 'capacity-scheduler.xml');
  852. }
  853. this.saveSiteConfigs(configs);
  854. /**
  855. * First we put cluster configurations, which automatically creates /configurations
  856. * resources. Next we update host level overrides.
  857. */
  858. result.flag = this.doPUTClusterConfigurations();
  859. } else {
  860. var overridenConfigs = [];
  861. var groupHosts = [];
  862. configs.filterProperty('isOverridden', true).forEach(function (config) {
  863. overridenConfigs = overridenConfigs.concat(config.get('overrides'));
  864. });
  865. this.formatConfigValues(overridenConfigs);
  866. selectedConfigGroup.get('hosts').forEach(function(hostName){
  867. groupHosts.push({"host_name": hostName});
  868. });
  869. this.putConfigGroupChanges({
  870. ConfigGroup: {
  871. "id": selectedConfigGroup.get('id'),
  872. "cluster_name": App.get('clusterName'),
  873. "group_name": selectedConfigGroup.get('name'),
  874. "tag": selectedConfigGroup.get('service.id'),
  875. "description": selectedConfigGroup.get('description'),
  876. "hosts": groupHosts,
  877. "desired_configs": this.buildGroupDesiredConfigs(overridenConfigs)
  878. }
  879. });
  880. result.flag = this.get('isPutConfigGroupChangesSuccess');
  881. }
  882. if (!result.flag) {
  883. result.message = Em.I18n.t('services.service.config.failSaveConfig');
  884. } else {
  885. if (!result.flag) {
  886. result.message = Em.I18n.t('services.service.config.failSaveConfigHostOverrides');
  887. }
  888. }
  889. console.log("The result from applyCreatdConfToService is: " + result);
  890. return result;
  891. },
  892. /**
  893. * construct desired_configs for config groups from overriden properties
  894. * @param configs
  895. * @return {Array}
  896. */
  897. buildGroupDesiredConfigs: function (configs) {
  898. var sites = [];
  899. var time = (new Date).getTime();
  900. configs.forEach(function (config) {
  901. var type = config.get('filename').replace('.xml', '');
  902. var site = sites.findProperty('type', type);
  903. if (site) {
  904. site.properties.push({
  905. name: config.get('name'),
  906. value: config.get('value')
  907. });
  908. } else {
  909. site = {
  910. type: type,
  911. tag: 'version' + time,
  912. properties: [{
  913. name: config.get('name'),
  914. value: config.get('value')
  915. }]
  916. };
  917. sites.push(site);
  918. }
  919. });
  920. sites.forEach(function(site){
  921. if(site.type === 'global') {
  922. site.properties = this.createGlobalSiteObj(site.tag, site.properties).properties;
  923. } else {
  924. site.properties = this.createSiteObj(site.type, site.tag, site.properties).properties;
  925. }
  926. }, this);
  927. return sites;
  928. },
  929. /**
  930. * persist properties of config groups to server
  931. * @param data
  932. */
  933. putConfigGroupChanges: function (data) {
  934. App.ajax.send({
  935. name: 'config_groups.update_config_group',
  936. sender: this,
  937. data: {
  938. id: data.ConfigGroup.id,
  939. configGroup: data
  940. },
  941. success: "putConfigGroupChangesSuccess"
  942. });
  943. },
  944. isPutConfigGroupChangesSuccess: false,
  945. putConfigGroupChangesSuccess: function () {
  946. this.set('isPutConfigGroupChangesSuccess', true);
  947. },
  948. /**
  949. * save new or change exist configs in global configs
  950. * @param configs
  951. */
  952. saveGlobalConfigs: function (configs) {
  953. var globalConfigs = this.get('globalConfigs');
  954. configs.filterProperty('id', 'puppet var').forEach(function (uiConfigProperty) {
  955. uiConfigProperty.set('value', App.config.trimProperty(uiConfigProperty));
  956. if (globalConfigs.someProperty('name', uiConfigProperty.name)) {
  957. var modelGlobalConfig = globalConfigs.findProperty('name', uiConfigProperty.name);
  958. modelGlobalConfig.value = uiConfigProperty.value;
  959. } else {
  960. globalConfigs.pushObject({
  961. name: uiConfigProperty.name,
  962. value: uiConfigProperty.value
  963. });
  964. }
  965. }, this);
  966. this.setHiveHostName(globalConfigs);
  967. this.setOozieHostName(globalConfigs);
  968. this.set('globalConfigs', globalConfigs);
  969. },
  970. /**
  971. * set hive hostnames in global configs
  972. * @param globals
  973. */
  974. setHiveHostName: function (globals) {
  975. if (globals.someProperty('name', 'hive_database')) {
  976. var hiveDb = globals.findProperty('name', 'hive_database');
  977. if (hiveDb.value === 'New MySQL Database') {
  978. var ambariHost = globals.findProperty('name', 'hive_ambari_host');
  979. if (ambariHost) {
  980. ambariHost.name = 'hive_hostname';
  981. }
  982. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_host'));
  983. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_database'));
  984. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_host'));
  985. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_database'));
  986. } else if (hiveDb.value === 'Existing MySQL Database') {
  987. var existingMySqlHost = globals.findProperty('name', 'hive_existing_mysql_host');
  988. if (existingMySqlHost) {
  989. existingMySqlHost.name = 'hive_hostname';
  990. }
  991. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  992. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  993. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_host'));
  994. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_database'));
  995. } else { //existing oracle database
  996. var existingOracleHost = globals.findProperty('name', 'hive_existing_oracle_host');
  997. if (existingOracleHost) {
  998. existingOracleHost.name = 'hive_hostname';
  999. }
  1000. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  1001. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  1002. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_host'));
  1003. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_database'));
  1004. }
  1005. }
  1006. },
  1007. /**
  1008. * set oozie hostnames in global configs
  1009. * @param globals
  1010. */
  1011. setOozieHostName: function (globals) {
  1012. if (globals.someProperty('name', 'oozie_database')) {
  1013. var oozieDb = globals.findProperty('name', 'oozie_database');
  1014. if (oozieDb.value === 'New Derby Database') {
  1015. globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
  1016. globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
  1017. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
  1018. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
  1019. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
  1020. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
  1021. } else if (oozieDb.value === 'New MySQL Database') {
  1022. var ambariHost = globals.findProperty('name', 'oozie_ambari_host');
  1023. if (ambariHost) {
  1024. ambariHost.name = 'oozie_hostname';
  1025. }
  1026. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
  1027. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
  1028. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
  1029. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
  1030. globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
  1031. } else if (oozieDb.value === 'Existing MySQL Database') {
  1032. var existingMySqlHost = globals.findProperty('name', 'oozie_existing_mysql_host');
  1033. if (existingMySqlHost) {
  1034. existingMySqlHost.name = 'oozie_hostname';
  1035. }
  1036. globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
  1037. globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
  1038. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
  1039. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
  1040. globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
  1041. } else { //existing oracle database
  1042. var existingOracleHost = globals.findProperty('name', 'oozie_existing_oracle_host');
  1043. if (existingOracleHost) {
  1044. existingOracleHost.name = 'oozie_hostname';
  1045. }
  1046. globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
  1047. globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
  1048. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
  1049. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
  1050. globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
  1051. }
  1052. }
  1053. },
  1054. /**
  1055. * save site configs
  1056. * @param configs
  1057. */
  1058. saveSiteConfigs: function (configs) {
  1059. //storedConfigs contains custom configs as well
  1060. var serviceConfigProperties = configs.filterProperty('id', 'site property');
  1061. this.formatConfigValues(serviceConfigProperties);
  1062. var storedConfigs = serviceConfigProperties.filterProperty('value');
  1063. var allUiConfigs = this.loadUiSideConfigs(this.get('configMapping').all());
  1064. this.set('uiConfigs', storedConfigs.concat(allUiConfigs));
  1065. },
  1066. formatConfigValues: function(serviceConfigProperties){
  1067. serviceConfigProperties.forEach(function (_config) {
  1068. if (typeof _config.get('value') === "boolean") _config.set('value', _config.value.toString());
  1069. _config.set('value', App.config.trimProperty(_config), true);
  1070. });
  1071. },
  1072. /**
  1073. * return configs from the UI side
  1074. * @param configMapping array with configs
  1075. * @return {Array}
  1076. */
  1077. loadUiSideConfigs: function (configMapping) {
  1078. var uiConfig = [];
  1079. var configs = configMapping.filterProperty('foreignKey', null);
  1080. this.addDynamicProperties(configs);
  1081. configs.forEach(function (_config) {
  1082. var valueWithOverrides = this.getGlobConfigValueWithOverrides(_config.templateName, _config.value, _config.name);
  1083. if (valueWithOverrides !== null) {
  1084. uiConfig.pushObject({
  1085. "id": "site property",
  1086. "name": _config.name,
  1087. "value": valueWithOverrides.value,
  1088. "filename": _config.filename,
  1089. "overrides": valueWithOverrides.overrides
  1090. });
  1091. }
  1092. }, this);
  1093. return uiConfig;
  1094. },
  1095. addDynamicProperties: function (configs) {
  1096. var allConfigs = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName')).get('configs');
  1097. var templetonHiveProperty = allConfigs.someProperty('name', 'templeton.hive.properties');
  1098. if (!templetonHiveProperty && this.get('content.serviceName') === 'WEBHCAT') {
  1099. configs.pushObject({
  1100. "name": "templeton.hive.properties",
  1101. "templateName": ["hivemetastore_host"],
  1102. "foreignKey": null,
  1103. "value": "hive.metastore.local=false,hive.metastore.uris=thrift://<templateName[0]>:9083,hive.metastore.sasl.enabled=yes,hive.metastore.execute.setugi=true,hive.metastore.warehouse.dir=/apps/hive/warehouse",
  1104. "filename": "webhcat-site.xml"
  1105. });
  1106. }
  1107. },
  1108. /**
  1109. * return global config value
  1110. * @param templateName
  1111. * @param expression
  1112. * @param name
  1113. * @return {
  1114. * value: '...',
  1115. * overrides: {
  1116. * 'value1': [h1, h2],
  1117. * 'value2': [h3]
  1118. * }
  1119. * }
  1120. */
  1121. getGlobConfigValueWithOverrides: function (templateName, expression, name) {
  1122. var express = expression.match(/<(.*?)>/g);
  1123. var value = expression;
  1124. if (express == null) {
  1125. return { value: expression, overrides: {}}; // if site property do not map any global property then return the value
  1126. }
  1127. var overrideHostToValue = {};
  1128. express.forEach(function (_express) {
  1129. //console.log("The value of template is: " + _express);
  1130. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  1131. if (this.get('globalConfigs').someProperty('name', templateName[index])) {
  1132. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  1133. var globalObj = this.get('globalConfigs').findProperty('name', templateName[index]);
  1134. var globValue = globalObj.value;
  1135. // Hack for templeton.zookeeper.hosts
  1136. var preReplaceValue = null;
  1137. 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
  1138. preReplaceValue = value;
  1139. value = this._replaceConfigValues(name, _express, value, globValue);
  1140. }
  1141. if (globalObj.overrides != null) {
  1142. for (var ov in globalObj.overrides) {
  1143. var hostsArray = globalObj.overrides[ov];
  1144. hostsArray.forEach(function (host) {
  1145. if (!(host in overrideHostToValue)) {
  1146. overrideHostToValue[host] = this._replaceConfigValues(name, _express, preReplaceValue, ov);
  1147. } else {
  1148. overrideHostToValue[host] = this._replaceConfigValues(name, _express, overrideHostToValue[host], ov);
  1149. }
  1150. }, this);
  1151. }
  1152. }
  1153. } else {
  1154. /*
  1155. console.log("ERROR: The variable name is: " + templateName[index]);
  1156. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  1157. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  1158. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  1159. */
  1160. value = null;
  1161. }
  1162. }, this);
  1163. var valueWithOverrides = {
  1164. value: value,
  1165. overrides: {}
  1166. };
  1167. if (!jQuery.isEmptyObject(overrideHostToValue)) {
  1168. for (var host in overrideHostToValue) {
  1169. var hostVal = overrideHostToValue[host];
  1170. if (!(hostVal in valueWithOverrides.overrides)) {
  1171. valueWithOverrides.overrides[hostVal] = [];
  1172. }
  1173. valueWithOverrides.overrides[hostVal].push(host);
  1174. }
  1175. }
  1176. return valueWithOverrides;
  1177. },
  1178. _replaceConfigValues: function (name, express, value, globValue) {
  1179. if (name === "templeton.zookeeper.hosts" || name === 'hbase.zookeeper.quorum') {
  1180. var zooKeeperPort = '2181';
  1181. if (typeof globValue === 'string') {
  1182. var temp = [];
  1183. temp.push(globValue);
  1184. globValue = temp;
  1185. }
  1186. if (name === "templeton.zookeeper.hosts") {
  1187. var temp = [];
  1188. globValue.forEach(function (_host, index) {
  1189. temp.push(globValue[index] + ':' + zooKeeperPort);
  1190. }, this);
  1191. globValue = temp;
  1192. }
  1193. value = value.replace(express, globValue.toString());
  1194. } else {
  1195. value = value.replace(express, globValue);
  1196. }
  1197. return value;
  1198. },
  1199. /**
  1200. * Saves cluster level configurations for all necessary sites.
  1201. * PUT calls are made to /api/v1/clusters/clusterName for each site.
  1202. *
  1203. * @return {Boolean}
  1204. */
  1205. doPUTClusterConfigurations: function () {
  1206. var result = true;
  1207. var serviceConfigTags = this.get('serviceConfigTags');
  1208. this.setNewTagNames(serviceConfigTags);
  1209. var siteNameToServerDataMap = {};
  1210. var configController = App.router.get('configurationController');
  1211. serviceConfigTags.forEach(function (_serviceTags) {
  1212. if (_serviceTags.siteName === 'global') {
  1213. console.log("TRACE: Inside global");
  1214. var serverGlobalConfigs = this.createGlobalSiteObj(_serviceTags.newTagName, this.get('globalConfigs'));
  1215. siteNameToServerDataMap['global'] = serverGlobalConfigs;
  1216. var loadedProperties = configController.getConfigsByTags([{siteName: 'global', tagName: this.loadedClusterSiteToTagMap['global']}]);
  1217. if (loadedProperties && loadedProperties[0]) {
  1218. loadedProperties = loadedProperties[0].properties;
  1219. }
  1220. if (this.isConfigChanged(loadedProperties, serverGlobalConfigs.properties)) {
  1221. result = result && this.doPUTClusterConfigurationSite(serverGlobalConfigs);
  1222. }
  1223. } else if (_serviceTags.siteName === 'core-site') {
  1224. console.log("TRACE: Inside core-site");
  1225. if (this.get('content.serviceName') === 'HDFS' || this.get('content.serviceName') === 'HCFS') {
  1226. var coreSiteConfigs = this.createCoreSiteObj(_serviceTags.newTagName);
  1227. siteNameToServerDataMap['core-site'] = coreSiteConfigs;
  1228. var loadedProperties = configController.getConfigsByTags([{siteName: 'core-site', tagName: this.loadedClusterSiteToTagMap['core-site']}]);
  1229. if (loadedProperties && loadedProperties[0]) {
  1230. loadedProperties = loadedProperties[0].properties;
  1231. }
  1232. if (this.isConfigChanged(loadedProperties, coreSiteConfigs.properties)) {
  1233. result = result && this.doPUTClusterConfigurationSite(coreSiteConfigs);
  1234. }
  1235. }
  1236. } else {
  1237. var siteConfigs = this.get('uiConfigs').filterProperty('filename', _serviceTags.siteName + '.xml');
  1238. var serverConfigs = this.createSiteObj(_serviceTags.siteName, _serviceTags.newTagName, siteConfigs);
  1239. siteNameToServerDataMap[_serviceTags.siteName] = serverConfigs;
  1240. var loadedProperties = configController.getConfigsByTags([{siteName: _serviceTags.siteName, tagName: this.loadedClusterSiteToTagMap[_serviceTags.siteName]}]);
  1241. if (loadedProperties && loadedProperties[0]) {
  1242. loadedProperties = loadedProperties[0].properties;
  1243. }
  1244. if (this.isConfigChanged(loadedProperties, serverConfigs.properties)) {
  1245. result = result && this.doPUTClusterConfigurationSite(serverConfigs);
  1246. }
  1247. }
  1248. }, this);
  1249. this.savedSiteNameToServerServiceConfigDataMap = siteNameToServerDataMap;
  1250. return result;
  1251. },
  1252. /**
  1253. * Compares the loaded config values with the saving config values.
  1254. */
  1255. isConfigChanged: function (loadedConfig, savingConfig) {
  1256. var changed = false;
  1257. if (loadedConfig != null && savingConfig != null) {
  1258. var seenLoadKeys = [];
  1259. for (var loadKey in loadedConfig) {
  1260. seenLoadKeys.push(loadKey);
  1261. var loadValue = loadedConfig[loadKey];
  1262. var saveValue = savingConfig[loadKey];
  1263. if ("boolean" == typeof(saveValue)) {
  1264. saveValue = saveValue.toString();
  1265. }
  1266. if (saveValue == null) {
  1267. saveValue = "null";
  1268. }
  1269. if (loadValue !== saveValue) {
  1270. changed = true;
  1271. break;
  1272. }
  1273. }
  1274. for (var saveKey in savingConfig) {
  1275. if (seenLoadKeys.indexOf(saveKey) < 0) {
  1276. changed = true;
  1277. break;
  1278. }
  1279. }
  1280. }
  1281. return changed;
  1282. },
  1283. /**
  1284. * Saves configuration of a particular site. The provided data
  1285. * contains the site name and tag to be used.
  1286. */
  1287. doPUTClusterConfigurationSite: function (data) {
  1288. var result;
  1289. var url = this.getUrl('', '');
  1290. var clusterData = {
  1291. Clusters: {
  1292. desired_config: data
  1293. }
  1294. };
  1295. console.log("applyClusterConfigurationToSite(): PUTting data:", clusterData);
  1296. $.ajax({
  1297. type: 'PUT',
  1298. url: url,
  1299. async: false,
  1300. dataType: 'text',
  1301. data: JSON.stringify(clusterData),
  1302. timeout: 5000,
  1303. success: function (data) {
  1304. console.log("applyClusterConfigurationToSite(): In success for data:", data);
  1305. result = true;
  1306. },
  1307. error: function (request, ajaxOptions, error) {
  1308. console.log('applyClusterConfigurationToSite(): ERROR:', request.responseText, ", error=", error);
  1309. result = false;
  1310. },
  1311. statusCode: require('data/statusCodes')
  1312. });
  1313. console.log("applyClusterConfigurationToSite(): Exiting with result=" + result);
  1314. return result;
  1315. },
  1316. /**
  1317. * Creates host level overrides for service configuration.
  1318. *
  1319. */
  1320. doPUTHostOverridesConfigurationSites: function () {
  1321. var singlePUTHostData = [];
  1322. var savedHostSiteArray = [];
  1323. for (var host in this.savedHostToOverrideSiteToTagMap) {
  1324. for (var siteName in this.savedHostToOverrideSiteToTagMap[host]) {
  1325. var tagName = this.savedHostToOverrideSiteToTagMap[host][siteName].tagName;
  1326. var map = this.savedHostToOverrideSiteToTagMap[host][siteName].map;
  1327. savedHostSiteArray.push(host + "///" + siteName);
  1328. singlePUTHostData.push({
  1329. RequestInfo: {
  1330. query: 'Hosts/host_name=' + host
  1331. },
  1332. Body: {
  1333. Hosts: {
  1334. desired_config: {
  1335. type: siteName,
  1336. tag: tagName,
  1337. properties: map
  1338. }
  1339. }
  1340. }
  1341. });
  1342. }
  1343. }
  1344. // Now cleanup removed overrides
  1345. for (var loadedHost in this.loadedGroupToOverrideSiteToTagMap) {
  1346. for (var loadedSiteName in this.loadedGroupToOverrideSiteToTagMap[loadedHost]) {
  1347. if (!(savedHostSiteArray.contains(loadedHost + "///" + loadedSiteName))) {
  1348. // This host-site combination was loaded, but not saved.
  1349. // Meaning it is not needed anymore. Hence send a DELETE command.
  1350. singlePUTHostData.push({
  1351. RequestInfo: {
  1352. query: 'Hosts/host_name=' + loadedHost
  1353. },
  1354. Body: {
  1355. Hosts: {
  1356. desired_config: {
  1357. type: loadedSiteName,
  1358. tag: this.loadedGroupToOverrideSiteToTagMap[loadedHost][loadedSiteName],
  1359. selected: false
  1360. }
  1361. }
  1362. }
  1363. });
  1364. }
  1365. }
  1366. }
  1367. console.debug("createHostOverrideConfigSites(): PUTting host-overrides. Data=", singlePUTHostData);
  1368. if (singlePUTHostData.length > 0) {
  1369. var url = this.getUrl('', '/hosts');
  1370. var hostOverrideResult = true;
  1371. $.ajax({
  1372. type: 'PUT',
  1373. url: url,
  1374. data: JSON.stringify(singlePUTHostData),
  1375. async: false,
  1376. dataType: 'text',
  1377. timeout: 5000,
  1378. success: function (data) {
  1379. var jsonData = jQuery.parseJSON(data);
  1380. hostOverrideResult = true;
  1381. console.log("createHostOverrideConfigSites(): SUCCESS:", url, ". RESPONSE:", jsonData);
  1382. },
  1383. error: function (request, ajaxOptions, error) {
  1384. hostOverrideResult = false;
  1385. console.log("createHostOverrideConfigSites(): ERROR:", url, ". RESPONSE:", request.responseText);
  1386. },
  1387. statusCode: require('data/statusCodes')
  1388. });
  1389. return hostOverrideResult;
  1390. }
  1391. return true;
  1392. },
  1393. /**
  1394. * add newTagName property to each config in serviceConfigs
  1395. * @param serviceConfigs
  1396. */
  1397. setNewTagNames: function (serviceConfigs) {
  1398. var time = (new Date).getTime();
  1399. serviceConfigs.forEach(function (_serviceConfigs) {
  1400. _serviceConfigs.newTagName = 'version' + time;
  1401. }, this);
  1402. },
  1403. /**
  1404. * create global site object
  1405. * @param tagName
  1406. * @return {Object}
  1407. */
  1408. createGlobalSiteObj: function (tagName, globalConfigs) {
  1409. var heapsizeException = ['hadoop_heapsize', 'yarn_heapsize', 'nodemanager_heapsize', 'resourcemanager_heapsize'];
  1410. var globalSiteProperties = {};
  1411. globalConfigs.forEach(function (_globalSiteObj) {
  1412. // do not pass any globalConfigs whose name ends with _host or _hosts
  1413. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  1414. // append "m" to JVM memory options except for hadoop_heapsize
  1415. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && !heapsizeException.contains(_globalSiteObj.name)) {
  1416. _globalSiteObj.value += "m";
  1417. }
  1418. globalSiteProperties[_globalSiteObj.name] = App.config.escapeXMLCharacters(_globalSiteObj.value);
  1419. //this.recordHostOverride(_globalSiteObj, 'global', tagName, this);
  1420. //console.log("TRACE: name of the global property is: " + _globalSiteObj.name);
  1421. //console.log("TRACE: value of the global property is: " + _globalSiteObj.value);
  1422. }
  1423. }, this);
  1424. return {"type": "global", "tag": tagName, "properties": globalSiteProperties};
  1425. },
  1426. recordHostOverride: function (serviceConfigObj, siteName, tagName, self) {
  1427. var overrides = null;
  1428. var name = '';
  1429. if ('get' in serviceConfigObj) {
  1430. overrides = serviceConfigObj.get('overrides');
  1431. name = serviceConfigObj.get('name');
  1432. } else {
  1433. overrides = serviceConfigObj.overrides;
  1434. name = serviceConfigObj.name;
  1435. }
  1436. if(overrides){
  1437. if('get' in overrides) {
  1438. overrides.forEach(function (override) {
  1439. override.get('selectedHostOptions').forEach(function (host) {
  1440. var value = override.get('value');
  1441. self._recordHostOverride(value, host, name, siteName, tagName, self);
  1442. });
  1443. });
  1444. } else {
  1445. for (var value in overrides) {
  1446. overrides[value].forEach(function (host) {
  1447. self._recordHostOverride(value, host, name, siteName, tagName, self);
  1448. });
  1449. }
  1450. }
  1451. }
  1452. },
  1453. /**
  1454. * Records all the host overrides per site/tag
  1455. */
  1456. _recordHostOverride: function(value, host, serviceConfigObjName, siteName, tagName, self) {
  1457. if (!(host in self.savedHostToOverrideSiteToTagMap)) {
  1458. self.savedHostToOverrideSiteToTagMap[host] = {};
  1459. }
  1460. if (!(siteName in self.savedHostToOverrideSiteToTagMap[host])) {
  1461. self.savedHostToOverrideSiteToTagMap[host][siteName] = {};
  1462. self.savedHostToOverrideSiteToTagMap[host][siteName].map = {};
  1463. }
  1464. var finalTag = tagName + '_' + host;
  1465. console.log("recordHostOverride(): Saving host override for host=" + host + ", site=" + siteName + ", tag=" + finalTag + ", (key,value)=(" + serviceConfigObjName + "," + value + ")");
  1466. self.savedHostToOverrideSiteToTagMap[host][siteName].tagName = finalTag;
  1467. self.savedHostToOverrideSiteToTagMap[host][siteName].map[serviceConfigObjName] = value;
  1468. },
  1469. /**
  1470. * create core site object
  1471. * @param tagName
  1472. * @return {Object}
  1473. */
  1474. createCoreSiteObj: function (tagName) {
  1475. var coreSiteObj = this.get('uiConfigs').filterProperty('filename', 'core-site.xml');
  1476. var coreSiteProperties = {};
  1477. coreSiteObj.forEach(function (_coreSiteObj) {
  1478. coreSiteProperties[_coreSiteObj.name] = App.config.escapeXMLCharacters(_coreSiteObj.value);
  1479. //this.recordHostOverride(_coreSiteObj, 'core-site', tagName, this);
  1480. }, this);
  1481. return {"type": "core-site", "tag": tagName, "properties": coreSiteProperties};
  1482. },
  1483. /**
  1484. * create site object
  1485. * @param siteName
  1486. * @param tagName
  1487. * @return {Object}
  1488. */
  1489. createSiteObj: function (siteName, tagName, siteObj) {
  1490. var siteProperties = {};
  1491. siteObj.forEach(function (_siteObj) {
  1492. siteProperties[_siteObj.name] = App.config.escapeXMLCharacters(_siteObj.value);
  1493. //this.recordHostOverride(_siteObj, siteName, tagName, this);
  1494. }, this);
  1495. return {"type": siteName, "tag": tagName, "properties": siteProperties};
  1496. },
  1497. /**
  1498. * Set display names of the property from the puppet/global names
  1499. * @param: displayNames: a field to be set with displayNames
  1500. * @param names: array of property puppet/global names
  1501. */
  1502. setPropertyDisplayNames: function (displayNames, names) {
  1503. var stepConfigs = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName')).configs;
  1504. names.forEach(function (_name, index) {
  1505. if (stepConfigs.someProperty('name', _name)) {
  1506. displayNames.push(stepConfigs.findProperty('name', _name).displayName);
  1507. }
  1508. }, this);
  1509. },
  1510. /**
  1511. * Set property of the site variable
  1512. */
  1513. setSiteProperty: function (key, value, filename) {
  1514. if (filename === 'core-site.xml' && this.get('uiConfigs').filterProperty('filename', 'core-site.xml').someProperty('name', key)) {
  1515. this.get('uiConfigs').filterProperty('filename', 'core-site.xml').findProperty('name', key).value = value;
  1516. return;
  1517. }
  1518. this.get('uiConfigs').pushObject({
  1519. "id": "site property",
  1520. "name": key,
  1521. "value": value,
  1522. "filename": filename
  1523. });
  1524. },
  1525. /**
  1526. * return either specific url for request if testMode is false or testUrl
  1527. * @param testUrl
  1528. * @param url
  1529. * @return {*}
  1530. */
  1531. getUrl: function (testUrl, url) {
  1532. return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + App.router.getClusterName() + url;
  1533. },
  1534. /**
  1535. * Adds host name of master component to global config;
  1536. */
  1537. addHostNamesToGlobalConfig: function () {
  1538. var serviceName = this.get('content.serviceName');
  1539. var globalConfigs = this.get('globalConfigs');
  1540. var serviceConfigs = this.get('serviceConfigs').findProperty('serviceName', serviceName).configs;
  1541. //namenode_host is required to derive "fs.default.name" a property of core-site
  1542. var nameNodeHost = this.get('serviceConfigs').findProperty('serviceName', 'HDFS').configs.findProperty('name', 'namenode_host');
  1543. try {
  1544. nameNodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').filterProperty('componentName', 'NAMENODE').mapProperty('host.hostName');
  1545. globalConfigs.push(nameNodeHost);
  1546. } catch (err) {
  1547. console.log("No NameNode Host available. This is expected if you're using HCFS rather than HDFS.");
  1548. }
  1549. //zooKeeperserver_host
  1550. var zooKeperHost = this.get('serviceConfigs').findProperty('serviceName', 'ZOOKEEPER').configs.findProperty('name', 'zookeeperserver_hosts');
  1551. if (serviceName === 'ZOOKEEPER' || serviceName === 'HBASE' || serviceName === 'WEBHCAT') {
  1552. zooKeperHost.defaultValue = App.Service.find('ZOOKEEPER').get('hostComponents').filterProperty('componentName', 'ZOOKEEPER_SERVER').mapProperty('host.hostName');
  1553. globalConfigs.push(zooKeperHost);
  1554. }
  1555. switch (serviceName) {
  1556. case 'HDFS':
  1557. if (this.get('content.hostComponents').findProperty('componentName', 'SECONDARY_NAMENODE') && this.get('content.hostComponents').findProperty('componentName', 'SECONDARY_NAMENODE').get('workStatus') != 'MAINTENANCE') {
  1558. var sNameNodeHost = serviceConfigs.findProperty('name', 'snamenode_host');
  1559. sNameNodeHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'SECONDARY_NAMENODE').get('host.hostName');
  1560. globalConfigs.push(sNameNodeHost);
  1561. }
  1562. break;
  1563. case 'MAPREDUCE':
  1564. var jobTrackerHost = serviceConfigs.findProperty('name', 'jobtracker_host');
  1565. jobTrackerHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'JOBTRACKER').get('host.hostName');
  1566. globalConfigs.push(jobTrackerHost);
  1567. break;
  1568. case 'MAPREDUCE2':
  1569. var historyServerHost = serviceConfigs.findProperty('name', 'hs_host');
  1570. historyServerHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'HISTORYSERVER').get('host.hostName');
  1571. globalConfigs.push(historyServerHost);
  1572. break;
  1573. case 'YARN':
  1574. var resourceManagerHost = serviceConfigs.findProperty('name', 'rm_host');
  1575. resourceManagerHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'RESOURCEMANAGER').get('host.hostName');
  1576. globalConfigs.push(resourceManagerHost);
  1577. //yarn.log.server.url config dependent on HistoryServer host
  1578. if (App.HostComponent.find().someProperty('componentName', 'HISTORYSERVER')) {
  1579. historyServerHost = this.get('serviceConfigs').findProperty('serviceName', 'MAPREDUCE2').configs.findProperty('name', 'hs_host');
  1580. historyServerHost.defaultValue = App.HostComponent.find().findProperty('componentName', 'HISTORYSERVER').get('host.hostName');
  1581. globalConfigs.push(historyServerHost);
  1582. }
  1583. break;
  1584. case 'HIVE':
  1585. var hiveMetastoreHost = serviceConfigs.findProperty('name', 'hivemetastore_host');
  1586. hiveMetastoreHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'HIVE_SERVER').get('host.hostName');
  1587. globalConfigs.push(hiveMetastoreHost);
  1588. var hiveDb = globalConfigs.findProperty('name', 'hive_database').value;
  1589. if (['Existing MySQL Database', 'Existing Oracle Database'].contains(hiveDb)) {
  1590. globalConfigs.findProperty('name', 'hive_hostname').isVisible = true;
  1591. }
  1592. break;
  1593. case 'OOZIE':
  1594. var oozieServerHost = serviceConfigs.findProperty('name', 'oozieserver_host');
  1595. oozieServerHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
  1596. globalConfigs.push(oozieServerHost);
  1597. var oozieDb = globalConfigs.findProperty('name', 'oozie_database').value;
  1598. if (['Existing MySQL Database', 'Existing Oracle Database'].contains(oozieDb)) {
  1599. globalConfigs.findProperty('name', 'oozie_hostname').isVisible = true;
  1600. }
  1601. break;
  1602. case 'HBASE':
  1603. var hbaseMasterHost = serviceConfigs.findProperty('name', 'hbasemaster_host');
  1604. hbaseMasterHost.defaultValue = this.get('content.hostComponents').filterProperty('componentName', 'HBASE_MASTER').mapProperty('host.hostName');
  1605. globalConfigs.push(hbaseMasterHost);
  1606. break;
  1607. case 'HUE':
  1608. var hueServerHost = serviceConfigs.findProperty('name', 'hueserver_host');
  1609. hueServerHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'HUE_SERVER').get('host.hostName');
  1610. globalConfigs.push(hueServerHost);
  1611. break;
  1612. case 'WEBHCAT':
  1613. var webhcatMasterHost = serviceConfigs.findProperty('name', 'webhcatserver_host');
  1614. webhcatMasterHost.defaultValue = this.get('content.hostComponents').filterProperty('componentName', 'WEBHCAT_SERVER').mapProperty('host.hostName');
  1615. globalConfigs.push(webhcatMasterHost);
  1616. var hiveMetastoreHost = this.get('serviceConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hivemetastore_host');
  1617. hiveMetastoreHost.defaultValue = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_SERVER').get('host.hostName');
  1618. globalConfigs.push(hiveMetastoreHost);
  1619. break;
  1620. }
  1621. },
  1622. /**
  1623. * Provides service component name and display-name information for
  1624. * the current selected service.
  1625. */
  1626. getCurrentServiceComponents: function () {
  1627. var service = this.get('content');
  1628. var components = service.get('hostComponents');
  1629. var validComponents = Ember.A([]);
  1630. var seenComponents = {};
  1631. components.forEach(function (component) {
  1632. var cn = component.get('componentName');
  1633. var cdn = component.get('displayName');
  1634. if (!seenComponents[cn]) {
  1635. validComponents.push(Ember.Object.create({
  1636. componentName: cn,
  1637. displayName: cdn,
  1638. selected: false
  1639. }));
  1640. seenComponents[cn] = cn;
  1641. }
  1642. });
  1643. return validComponents;
  1644. }.property('content'),
  1645. getAllHosts: function () {
  1646. return App.router.get('mainHostController.content');
  1647. }.property('App.router.mainHostController.content'),
  1648. doCancel: function () {
  1649. this.loadStep();
  1650. },
  1651. restartComponents: function(e) {
  1652. var commandName = "stop_component";
  1653. if(e.context) {
  1654. if(this.get('content.healthStatus') != 'green'){
  1655. return;
  1656. }
  1657. }else {
  1658. commandName = "start_component";
  1659. if(this.get('content.healthStatus') != 'red'){
  1660. return;
  1661. }
  1662. };
  1663. var content = this;
  1664. return App.ModalPopup.show({
  1665. primary: Em.I18n.t('ok'),
  1666. secondary: Em.I18n.t('common.cancel'),
  1667. header: Em.I18n.t('popup.confirmation.commonHeader'),
  1668. body: Em.I18n.t('question.sure'),
  1669. content: content,
  1670. onPrimary: function () {
  1671. var selectedService = this.content.get('content.id');
  1672. var hostComponents = App.HostComponent.find().filterProperty('service.id', selectedService).filterProperty('staleConfigs', true)
  1673. hostComponents.forEach(function(item){
  1674. var componentName = item.get('componentName');
  1675. var hostName = item.get('host.hostName');
  1676. App.ajax.send({
  1677. name: 'config.stale.'+commandName,
  1678. sender: this,
  1679. data: {
  1680. hostName: hostName,
  1681. componentName: componentName,
  1682. displayName: App.format.role(componentName)
  1683. }
  1684. });
  1685. })
  1686. this.hide();
  1687. App.router.get('backgroundOperationsController').showPopup();
  1688. },
  1689. onSecondary: function () {
  1690. this.hide();
  1691. }
  1692. });
  1693. },
  1694. showHostsShouldBeRestarted: function() {
  1695. var hosts = [];
  1696. for(var hostName in this.get('content.restartRequiredHostsAndComponents')) {
  1697. hosts.push(hostName);
  1698. }
  1699. hosts = hosts.join(', ');
  1700. this.showItemsShouldBeRestarted(hosts, Em.I18n.t('service.service.config.restartService.hostsShouldBeRestarted'));
  1701. },
  1702. showComponentsShouldBeRestarted: function() {
  1703. var rhc = this.get('content.restartRequiredHostsAndComponents');
  1704. var hostsComponets = [];
  1705. var componentsObject = {};
  1706. for(var hostName in rhc) {
  1707. rhc[hostName].forEach(function(hostComponent) {
  1708. hostsComponets.push(hostComponent);
  1709. if(componentsObject[hostComponent] != undefined) {
  1710. componentsObject[hostComponent]++;
  1711. } else {
  1712. componentsObject[hostComponent] = 1;
  1713. }
  1714. })
  1715. }
  1716. var componentsList = [];
  1717. for( var obj in componentsObject) {
  1718. var componentDisplayName = (componentsObject[obj] > 1) ? obj + 's' : obj;
  1719. componentsList.push(componentsObject[obj] + ' ' + componentDisplayName);
  1720. }
  1721. hostsComponets = componentsList.join(', ');
  1722. this.showItemsShouldBeRestarted(hostsComponets, Em.I18n.t('service.service.config.restartService.componentsShouldBeRestarted'));
  1723. },
  1724. showItemsShouldBeRestarted: function(content, header) {
  1725. App.ModalPopup.show({
  1726. content: content,
  1727. header: header,
  1728. bodyClass: Em.View.extend({
  1729. templateName: require('templates/common/selectable_popup'),
  1730. textareaVisible: false,
  1731. textTrigger: function() {
  1732. this.set('textareaVisible', !this.get('textareaVisible'));
  1733. },
  1734. putContentToTextarea: function() {
  1735. var content = this.get('parentView.content');
  1736. if (this.get('textareaVisible')) {
  1737. var wrapper = $(".task-detail-log-maintext");
  1738. $('.task-detail-log-clipboard').html(content).width(wrapper.width()).height(wrapper.height());
  1739. Em.run.next(function() {
  1740. $('.task-detail-log-clipboard').select();
  1741. });
  1742. }
  1743. }.observes('textareaVisible')
  1744. }),
  1745. secondary: null
  1746. });
  1747. },
  1748. addOverrideProperty: function(serviceConfigProperty) {
  1749. var overrides = serviceConfigProperty.get('overrides');
  1750. if (!overrides) {
  1751. overrides = [];
  1752. serviceConfigProperty.set('overrides', overrides);
  1753. }
  1754. // create new override with new value
  1755. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  1756. newSCP.set('value', '');
  1757. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  1758. newSCP.set('parentSCP', serviceConfigProperty);
  1759. newSCP.set('isEditable', true);
  1760. console.debug("createOverrideProperty(): Added:", newSCP, " to main-property:", serviceConfigProperty);
  1761. overrides.pushObject(newSCP);
  1762. },
  1763. selectConfigGroup: function (event) {
  1764. this.set('selectedConfigGroup', event.context);
  1765. }
  1766. });