configs.js 72 KB

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