configs.js 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832
  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. var batchUtils = require('utils/batch_scheduled_requests');
  21. var lazyLoading = require('utils/lazy_loading');
  22. App.MainServiceInfoConfigsController = Em.Controller.extend(App.ServerValidatorMixin, {
  23. name: 'mainServiceInfoConfigsController',
  24. isHostsConfigsPage: false,
  25. forceTransition: false,
  26. isRecommendedLoaded: true,
  27. dataIsLoaded: false,
  28. stepConfigs: [], //contains all field properties that are viewed in this service
  29. selectedService: null,
  30. serviceConfigTags: null,
  31. selectedConfigGroup: null,
  32. configTypesInfo: {
  33. items: [],
  34. supportsFinal: []
  35. },
  36. requestInProgress: null,
  37. selectedServiceConfigTypes: [],
  38. selectedServiceSupportsFinal: [],
  39. configGroups: [],
  40. allConfigs: [],
  41. uiConfigs: [],
  42. customConfig: [],
  43. isApplyingChanges: false,
  44. saveConfigsFlag: true,
  45. isCompareMode: false,
  46. compareServiceVersion: null,
  47. preSelectedConfigVersion: null,
  48. // contain Service Config Property, when user proceed from Select Config Group dialog
  49. overrideToAdd: null,
  50. //version of default config group, configs of which currently applied
  51. currentDefaultVersion: null,
  52. //version selected to view
  53. selectedVersion: null,
  54. // file names of changed configs
  55. modifiedFileNames: [],
  56. // note passed on configs save
  57. serviceConfigVersionNote: '',
  58. versionLoaded: false,
  59. // current cluster-env version
  60. clusterEnvTagVersion: '',
  61. isCurrentSelected: function () {
  62. return App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + this.get('selectedVersion')).get('isCurrent');
  63. }.property('selectedVersion', 'content.serviceName'),
  64. serviceConfigs: function () {
  65. return App.config.get('preDefinedServiceConfigs');
  66. }.property('App.config.preDefinedServiceConfigs'),
  67. customConfigs: function () {
  68. return App.config.get('preDefinedCustomConfigs');
  69. }.property('App.config.preDefinedCustomConfigs'),
  70. configMapping: function () {
  71. return App.config.get('configMapping');
  72. }.property('App.config.configMapping'),
  73. configs: function () {
  74. return App.config.get('preDefinedSiteProperties');
  75. }.property('App.config.preDefinedSiteProperties'),
  76. secureConfigs: function () {
  77. if (App.get('isHadoop2Stack')) {
  78. return require('data/HDP2/secure_mapping');
  79. } else {
  80. return require('data/secure_mapping');
  81. }
  82. }.property('App.isHadoop2Stack'),
  83. showConfigHistoryFeature: true,
  84. /**
  85. * Map, which contains relation between group and site
  86. * to upload overridden properties
  87. */
  88. loadedGroupToOverrideSiteToTagMap: {},
  89. /**
  90. * During page load time the cluster level site to tag
  91. * mapping is stored here.
  92. *
  93. * Example:
  94. * {
  95. * 'hdfs-site': 'version1',
  96. * 'core-site': 'version1'
  97. * }
  98. */
  99. loadedClusterSiteToTagMap: {},
  100. /**
  101. * Holds the actual base service-config server data uploaded.
  102. * This is used by the host-override mechanism to update host
  103. * specific values.
  104. */
  105. savedSiteNameToServerServiceConfigDataMap: {},
  106. isSubmitDisabled: function () {
  107. return (!(this.get('stepConfigs').everyProperty('errorCount', 0)) || this.get('isApplyingChanges'));
  108. }.property('stepConfigs.@each.errorCount', 'isApplyingChanges'),
  109. isPropertiesChanged: function(){
  110. return this.get('stepConfigs').someProperty('isPropertiesChanged', true);
  111. }.property('stepConfigs.@each.isPropertiesChanged'),
  112. slaveComponentGroups: null,
  113. /**
  114. * Filter text will be located here
  115. */
  116. filter: '',
  117. /**
  118. * List of filters for config properties to populate filter combobox
  119. */
  120. propertyFilters: [
  121. {
  122. attributeName: 'isOverridden',
  123. attributeValue: true,
  124. caption: 'common.combobox.dropdown.overridden'
  125. },
  126. {
  127. attributeName: 'isFinal',
  128. attributeValue: true,
  129. caption: 'common.combobox.dropdown.final'
  130. },
  131. {
  132. attributeName: 'hasCompareDiffs',
  133. attributeValue: true,
  134. caption: 'common.combobox.dropdown.changed',
  135. dependentOn: 'isCompareMode'
  136. },
  137. {
  138. attributeName: 'isValid',
  139. attributeValue: false,
  140. caption: 'common.combobox.dropdown.issues'
  141. },
  142. {
  143. attributeName: 'warn',
  144. attributeValue: true,
  145. caption: 'common.combobox.dropdown.warnings'
  146. }
  147. ],
  148. /**
  149. * List of heapsize properties not to be parsed
  150. */
  151. heapsizeException: ['hadoop_heapsize', 'yarn_heapsize', 'nodemanager_heapsize', 'resourcemanager_heapsize', 'apptimelineserver_heapsize', 'jobhistory_heapsize'],
  152. /**
  153. * Regular expression for heapsize properties detection
  154. */
  155. heapsizeRegExp: /_heapsize|_newsize|_maxnewsize|_permsize|_maxpermsize$/,
  156. /**
  157. * Dropdown menu items in filter combobox
  158. */
  159. filterColumns: function () {
  160. var filterColumns = [];
  161. this.get('propertyFilters').forEach(function(filter) {
  162. if (Em.isNone(filter.dependentOn) || this.get(filter.dependentOn)) {
  163. filterColumns.push(Ember.Object.create({
  164. attributeName: filter.attributeName,
  165. attributeValue: filter.attributeValue,
  166. name: this.t(filter.caption),
  167. selected: filter.dependentOn ? this.get(filter.dependentOn) : false
  168. }));
  169. }
  170. }, this);
  171. return filterColumns;
  172. }.property('propertyFilters', 'isCompareMode'),
  173. /**
  174. * indicate wtether service config version belongs to default config group
  175. * @method isVersionDefault
  176. * @param version
  177. * @return {Boolean}
  178. */
  179. isVersionDefault: function(version) {
  180. return (App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + version).get('groupId') == -1);
  181. },
  182. /**
  183. * register request to view to track his progress
  184. * @param request
  185. */
  186. trackRequest: function (request) {
  187. this.set('requestInProgress', request);
  188. },
  189. /**
  190. * clear and set properties to default value
  191. */
  192. clearStep: function () {
  193. if (this.get('requestInProgress') && this.get('requestInProgress').readyState !== 4) {
  194. this.get('requestInProgress').abort();
  195. this.set('requestInProgress', null);
  196. }
  197. this.set("isApplyingChanges", false);
  198. this.set('modifiedFileNames', []);
  199. this.set('isInit', true);
  200. this.set('hash', null);
  201. this.set('forceTransition', false);
  202. this.set('dataIsLoaded', false);
  203. this.set('versionLoaded', false);
  204. this.set('filter', '');
  205. this.get('filterColumns').setEach('selected', false);
  206. this.get('stepConfigs').clear();
  207. this.get('allConfigs').clear();
  208. this.get('uiConfigs').clear();
  209. this.get('customConfig').clear();
  210. this.set('loadedGroupToOverrideSiteToTagMap', {});
  211. this.set('serviceConfigVersionNote', '');
  212. this.set('savedSiteNameToServerServiceConfigDataMap', {});
  213. if (this.get('serviceConfigTags')) {
  214. this.set('serviceConfigTags', null);
  215. }
  216. },
  217. serviceConfigProperties: function () {
  218. return App.db.getServiceConfigProperties();
  219. }.property('content'),
  220. /**
  221. * "Finger-print" of the <code>stepConfigs</code>. Filled after first configGroup selecting
  222. * Used to determine if some changes were made (when user navigates away from this page)
  223. * {String}
  224. */
  225. hash: null,
  226. /**
  227. * Is this initial config group changing
  228. * {Boolean}
  229. */
  230. isInit: true,
  231. restartHosts: Em.A(),
  232. /**
  233. * On load function
  234. */
  235. loadStep: function () {
  236. console.log("TRACE: Loading configure for service");
  237. this.clearStep();
  238. this.loadClusterEnvSite();
  239. },
  240. /**
  241. * load all tag versions of cluster-env site
  242. * @returns {$.ajax}
  243. */
  244. loadClusterEnvSite: function () {
  245. var self = this;
  246. return App.ajax.send({
  247. name: 'config.cluster_env_site',
  248. sender: self,
  249. success: 'loadClusterEnvSiteSuccess'
  250. });
  251. },
  252. loadClusterEnvSiteSuccess: function (data) {
  253. // find the latest tag version
  254. var maxVersion = Math.max.apply(this, data.items.mapProperty('version'));
  255. this.set('clusterEnvTagVersion', data.items.findProperty('version', maxVersion).tag);
  256. this.loadServiceConfigs();
  257. },
  258. getHash: function () {
  259. if (!this.get('stepConfigs')[0]) {
  260. return null;
  261. }
  262. var hash = {};
  263. this.get('stepConfigs')[0].configs.forEach(function (config) {
  264. hash[config.get('name')] = {value: config.get('value'), overrides: [], isFinal: config.get('isFinal')};
  265. if (!config.get('overrides')) return;
  266. if (!config.get('overrides.length')) return;
  267. config.get('overrides').forEach(function (override) {
  268. hash[config.get('name')].overrides.push(override.get('value'));
  269. });
  270. });
  271. return JSON.stringify(hash);
  272. },
  273. /**
  274. * Loads service configurations
  275. */
  276. loadServiceConfigs: function () {
  277. var advancedConfigs = [];
  278. var self = this;
  279. var serviceName = this.get('content.serviceName');
  280. var stackService = App.StackService.find().findProperty('serviceName', serviceName);
  281. if (stackService) {
  282. self.set('configTypesInfo', App.config.getConfigTypesInfoFromService(stackService));
  283. }
  284. this.trackRequest(App.config.loadAdvancedConfig(serviceName, function (properties, xhr) {
  285. if (xhr.statusText === 'abort') return;
  286. advancedConfigs.pushObjects(properties);
  287. self.set('advancedConfigs', advancedConfigs);
  288. self.trackRequest(App.config.loadClusterConfig(function(clusterProperties) {
  289. self.get('advancedConfigs').pushObjects(clusterProperties);
  290. self.trackRequest(self.loadServiceConfigVersions());
  291. }));
  292. }));
  293. },
  294. /**
  295. * get service config versions of current service
  296. */
  297. loadServiceConfigVersions: function () {
  298. return App.ajax.send({
  299. name: 'service.serviceConfigVersions.get',
  300. data: {
  301. serviceName: this.get('content.serviceName')
  302. },
  303. sender: this,
  304. success: 'loadServiceConfigVersionsSuccess',
  305. error: 'loadServiceConfigVersionsError'
  306. })
  307. },
  308. /**
  309. * load service config versions to model
  310. * set currentDefaultVersion
  311. * @param data
  312. * @param opt
  313. * @param params
  314. */
  315. loadServiceConfigVersionsSuccess: function (data, opt, params) {
  316. App.serviceConfigVersionsMapper.map(data);
  317. this.set('currentDefaultVersion', data.items.filterProperty('group_id', -1).findProperty('is_current').service_config_version);
  318. if (this.get('preSelectedConfigVersion')) {
  319. this.loadSelectedVersion(this.get('preSelectedConfigVersion.version'));
  320. } else {
  321. this.loadSelectedVersion();
  322. }
  323. },
  324. /**
  325. * error callback of loadServiceConfigVersions()
  326. * override defaultCallback
  327. * @param request
  328. * @param ajaxOptions
  329. * @param error
  330. * @param opt
  331. * @param params
  332. */
  333. loadServiceConfigVersionsError: Em.K,
  334. /**
  335. * get selected service config version
  336. * In case selected version is undefined then take currentDefaultVersion
  337. * @param version
  338. * @param switchToGroup
  339. */
  340. loadSelectedVersion: function (version, switchToGroup) {
  341. var self = this;
  342. this.set('versionLoaded', false);
  343. version = version || this.get('currentDefaultVersion');
  344. //version of non-default group require properties from current version of default group to correctly display page
  345. var versions = (this.isVersionDefault(version)) ? [version] : [this.get('currentDefaultVersion'), version];
  346. switchToGroup = (this.isVersionDefault(version) && !switchToGroup) ? this.get('configGroups').findProperty('isDefault') : switchToGroup;
  347. if (self.get('dataIsLoaded') && switchToGroup) {
  348. this.set('selectedConfigGroup', switchToGroup);
  349. }
  350. this.trackRequest(App.ajax.send({
  351. name: 'service.serviceConfigVersions.get.multiple',
  352. sender: this,
  353. data: {
  354. serviceName: this.get('content.serviceName'),
  355. serviceConfigVersions: versions
  356. },
  357. success: 'loadSelectedVersionSuccess'
  358. }).complete(function (xhr) {
  359. if (xhr.statusText === 'abort') return;
  360. if (self.get('dataIsLoaded')) {
  361. self.onConfigGroupChange();
  362. } else {
  363. self.loadServiceTagsAndGroups();
  364. }
  365. }));
  366. },
  367. /**
  368. * set cluster to site tag map
  369. * @param data
  370. * @param opt
  371. * @param params
  372. */
  373. loadSelectedVersionSuccess: function (data, opt, params) {
  374. var serviceConfigsDef = this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'));
  375. var siteToTagMap = {};
  376. var configTypesRendered = Object.keys(serviceConfigsDef.get('configTypesRendered'));
  377. var selectedVersion = params.serviceConfigVersions.length > 1 ? params.serviceConfigVersions[1] : params.serviceConfigVersions[0];
  378. var configurations = [];
  379. configTypesRendered.forEach(function (siteName) {
  380. data.items.forEach(function (item) {
  381. if (item.group_id == -1) {
  382. configurations = item.configurations;
  383. if (item.configurations.someProperty('type', siteName)) {
  384. siteToTagMap[siteName] = item.configurations.findProperty('type', siteName).tag;
  385. } else {
  386. siteToTagMap[siteName] = 'version1';
  387. }
  388. } else {
  389. //set config tags of non-default config group to load overrides from selected version
  390. this.loadedGroupToOverrideSiteToTagMap[item.group_name] = {};
  391. item.configurations.forEach(function (config) {
  392. this.loadedGroupToOverrideSiteToTagMap[item.group_name][config.type] = config.tag;
  393. }, this)
  394. }
  395. }, this)
  396. }, this);
  397. App.router.get('configurationController').saveToDB(configurations);
  398. // add cluster-env tag
  399. siteToTagMap['cluster-env'] = this.get('clusterEnvTagVersion');
  400. this.loadedClusterSiteToTagMap = siteToTagMap;
  401. this.set('selectedVersion', selectedVersion);
  402. //reset map if selected current version of default group
  403. if (this.get('isCurrentSelected') && selectedVersion === this.get('currentDefaultVersion')) {
  404. this.loadedGroupToOverrideSiteToTagMap = {};
  405. }
  406. },
  407. /**
  408. * load config groups of service
  409. */
  410. loadServiceTagsAndGroups: function () {
  411. this.trackRequest(App.ajax.send({
  412. name: 'config.tags_and_groups',
  413. sender: this,
  414. data: {
  415. serviceName: this.get('content.serviceName'),
  416. urlParams: "&config_groups/ConfigGroup/tag=" + this.get('content.serviceName')
  417. },
  418. success: 'loadServiceConfigsSuccess'
  419. }));
  420. },
  421. loadServiceConfigsSuccess: function (data, opt, params) {
  422. this.setConfigGroups(data, opt, params);
  423. },
  424. setConfigTags: function (data, opt, params) {
  425. var serviceConfigsDef = this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'));
  426. var siteToTagMap = {};
  427. var configTypesRendered = Object.keys(serviceConfigsDef.get('configTypesRendered'));
  428. configTypesRendered.forEach(function (siteName) {
  429. if (data.Clusters.desired_configs[siteName]) {
  430. siteToTagMap[siteName] = data.Clusters.desired_configs[siteName].tag;
  431. } else {
  432. siteToTagMap[siteName] = 'version1';
  433. }
  434. }, this);
  435. this.loadedClusterSiteToTagMap = siteToTagMap;
  436. },
  437. setConfigGroups: function (data, opt, params) {
  438. var serviceName = this.get('content.serviceName');
  439. var displayName = this.get('content.displayName');
  440. var selectedConfigGroup;
  441. var defaultHosts = App.get('allHostNames');
  442. //parse loaded config groups
  443. var configGroups = [];
  444. if (data && data.config_groups && data.config_groups.length) {
  445. data.config_groups.forEach(function (item) {
  446. item = item.ConfigGroup;
  447. if (item.tag === this.get('content.serviceName')) {
  448. var groupHosts = item.hosts.mapProperty('host_name');
  449. var newConfigGroup = App.ConfigGroup.create({
  450. id: item.id,
  451. name: item.group_name,
  452. description: item.description,
  453. isDefault: false,
  454. parentConfigGroup: null,
  455. service: App.Service.find().findProperty('serviceName', item.tag),
  456. hosts: groupHosts,
  457. configSiteTags: []
  458. });
  459. for (var i = 0; i < groupHosts.length; i++) {
  460. defaultHosts = defaultHosts.without(groupHosts[i]);
  461. }
  462. item.desired_configs.forEach(function (config) {
  463. newConfigGroup.configSiteTags.push(App.ConfigSiteTag.create({
  464. site: config.type,
  465. tag: config.tag
  466. }));
  467. }, this);
  468. // select default selected group for hosts page
  469. if (!selectedConfigGroup && this.get('isHostsConfigsPage') && newConfigGroup.get('hosts').contains(this.get('host.hostName')) && this.get('content.serviceName') === item.tag) {
  470. selectedConfigGroup = newConfigGroup;
  471. }
  472. configGroups.push(newConfigGroup);
  473. }
  474. }, this);
  475. }
  476. this.set('configGroups', configGroups);
  477. var defaultConfigGroup = App.ConfigGroup.create({
  478. name: displayName + " Default",
  479. description: "Default cluster level " + serviceName + " configuration",
  480. isDefault: true,
  481. hosts: defaultHosts,
  482. parentConfigGroup: null,
  483. service: this.get('content'),
  484. serviceName: serviceName,
  485. configSiteTags: []
  486. });
  487. if (!selectedConfigGroup) {
  488. selectedConfigGroup = configGroups.findProperty('name', this.get('preSelectedConfigVersion.groupName')) || defaultConfigGroup;
  489. }
  490. this.get('configGroups').sort(function (configGroupA, configGroupB) {
  491. return (configGroupA.name > configGroupB.name);
  492. });
  493. this.get('configGroups').unshift(defaultConfigGroup);
  494. this.set('selectedConfigGroup', selectedConfigGroup);
  495. this.set('preSelectedConfigVersion', null);
  496. },
  497. onConfigGroupChange: function () {
  498. var self = this;
  499. this.get('stepConfigs').clear();
  500. var selectedConfigGroup = this.get('selectedConfigGroup');
  501. var serviceName = this.get('content.serviceName');
  502. //STEP 1: handle tags from JSON data for host overrides
  503. var configGroupsWithOverrides = selectedConfigGroup.get('isDefault') && !this.get('isHostsConfigsPage') ? this.get('configGroups') : [selectedConfigGroup];
  504. configGroupsWithOverrides.forEach(function (item) {
  505. var groupName = item.get('name');
  506. if (Em.isNone(this.loadedGroupToOverrideSiteToTagMap[groupName])) {
  507. this.loadedGroupToOverrideSiteToTagMap[groupName] = {};
  508. item.get('configSiteTags').forEach(function (siteTag) {
  509. var site = siteTag.get('site');
  510. this.loadedGroupToOverrideSiteToTagMap[groupName][site] = siteTag.get('tag');
  511. }, this);
  512. }
  513. }, this);
  514. //STEP 2: Create an array of objects defining tag names to be polled and new tag names to be set after submit
  515. this.setServiceConfigTags(this.loadedClusterSiteToTagMap);
  516. //STEP 3: Load advanced configs
  517. var advancedConfigs = this.get('advancedConfigs');
  518. //STEP 4: Load on-site config by service from server
  519. App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags')).done(function(configGroups){
  520. //Merge on-site configs with pre-defined
  521. var configSet = App.config.mergePreDefinedWithLoaded(configGroups, advancedConfigs, self.get('serviceConfigTags'), serviceName);
  522. configSet = App.config.syncOrderWithPredefined(configSet);
  523. var configs = configSet.configs;
  524. //add custom configs
  525. App.config.addCustomConfigs(configs);
  526. //put properties from capacity-scheduler.xml into one config with textarea view
  527. if (self.get('content.serviceName') === 'YARN') {
  528. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  529. }
  530. self.set('allConfigs', configs);
  531. //add configs as names of host components
  532. self.addHostNamesToConfig();
  533. //load configs of version being compared against
  534. self.loadCompareVersionConfigs(self.get('allConfigs')).done(function (isComparison) {
  535. //Load and add overriden configs of group
  536. if (!isComparison && (!self.get('selectedConfigGroup').get('isDefault') || self.get('isCurrentSelected'))) {
  537. App.config.loadServiceConfigGroupOverrides(self.get('allConfigs'), self.get('loadedGroupToOverrideSiteToTagMap'), self.get('configGroups'), self.onLoadOverrides, self);
  538. } else {
  539. self.onLoadOverrides(self.get('allConfigs'));
  540. }
  541. });
  542. });
  543. }.observes('selectedConfigGroup'),
  544. /**
  545. * load version configs for comparison
  546. * @param allConfigs
  547. * @return {object}
  548. */
  549. loadCompareVersionConfigs: function (allConfigs) {
  550. var dfd = $.Deferred();
  551. var self = this;
  552. var compareServiceVersions = [];
  553. if (this.get('compareServiceVersion')) {
  554. if (!this.isVersionDefault(this.get('compareServiceVersion').get('version'))) {
  555. compareServiceVersions = [this.get('compareServiceVersion').get('version'), this.get('selectedVersion')];
  556. } else {
  557. compareServiceVersions = [this.get('compareServiceVersion').get('version')];
  558. }
  559. this.getCompareVersionConfigs(compareServiceVersions).done(function (json) {
  560. self.initCompareConfig(allConfigs, json);
  561. self.set('compareServiceVersion', null);
  562. self.set('isCompareMode', true);
  563. dfd.resolve(true);
  564. }).fail(function () {
  565. self.set('compareServiceVersion', null);
  566. dfd.resolve(true);
  567. });
  568. } else {
  569. self.set('isCompareMode', false);
  570. allConfigs.setEach('isComparison', false);
  571. dfd.resolve(false);
  572. }
  573. return dfd.promise();
  574. },
  575. /**
  576. * attach analogical config to each property for comparison
  577. * @param allConfigs
  578. * @param json
  579. */
  580. initCompareConfig: function(allConfigs, json) {
  581. var serviceVersionMap = {};
  582. var configNamesMap = {};
  583. var serviceName = this.get('content.serviceName');
  584. var compareVersionNumber = this.get('compareServiceVersion').get('version');
  585. //indicate whether compared versions are from non-default group
  586. var compareNonDefaultVersions = (json.items.length > 1);
  587. serviceVersionMap[compareVersionNumber] = {};
  588. if (compareNonDefaultVersions) {
  589. serviceVersionMap[this.get('selectedVersion')] = {};
  590. }
  591. allConfigs.mapProperty('name').forEach(function(name) {
  592. configNamesMap[name] = true;
  593. });
  594. json.items.forEach(function (item) {
  595. item.configurations.forEach(function (configuration) {
  596. if (serviceName == 'YARN' && configuration.type == 'capacity-scheduler') {
  597. // put all properties in a single textarea for capacity-scheduler
  598. var value = '';
  599. for (var prop in configuration.properties) {
  600. value += prop + '=' + configuration.properties[prop] + '\n';
  601. }
  602. serviceVersionMap[item.service_config_version][configuration.type + '-' + configuration.type] = {
  603. name: configuration.type,
  604. value: value,
  605. type: configuration.type,
  606. tag: configuration.tag,
  607. version: configuration.version,
  608. service_config_version: item.service_config_version
  609. };
  610. } else {
  611. for (var prop in configuration.properties) {
  612. serviceVersionMap[item.service_config_version][prop + '-' + configuration.type] = {
  613. name: prop,
  614. value: configuration.properties[prop],
  615. type: configuration.type,
  616. tag: configuration.tag,
  617. version: configuration.version,
  618. service_config_version: item.service_config_version
  619. };
  620. if (Em.isNone(configNamesMap[prop])) {
  621. allConfigs.push(this.getMockConfig(prop, serviceName, App.config.getOriginalFileName(configuration.type)));
  622. }
  623. }
  624. }
  625. if (configuration.properties_attributes && configuration.properties_attributes.final) {
  626. for (var final in configuration.properties_attributes.final) {
  627. serviceVersionMap[item.service_config_version][final + '-' + configuration.type].isFinal = (configuration.properties_attributes.final[final] === 'true');
  628. }
  629. }
  630. }, this);
  631. }, this);
  632. if (compareNonDefaultVersions) {
  633. allConfigs.forEach(function (serviceConfig) {
  634. this.setCompareConfigs(serviceConfig, serviceVersionMap, compareVersionNumber, this.get('selectedVersion'));
  635. }, this);
  636. } else {
  637. allConfigs.forEach(function (serviceConfig) {
  638. var serviceCfgVersionMap = serviceVersionMap[this.get('compareServiceVersion').get('version')];
  639. var compareConfig = serviceCfgVersionMap[serviceConfig.name + '-' + App.config.getConfigTagFromFileName(serviceConfig.filename)]
  640. this.setCompareDefaultGroupConfig(serviceConfig, compareConfig);
  641. }, this);
  642. }
  643. },
  644. /**
  645. * set compare properties to service config of non-default group
  646. * @param serviceConfig
  647. * @param serviceVersionMap
  648. * @param compareVersion
  649. * @param selectedVersion
  650. */
  651. setCompareConfigs: function (serviceConfig, serviceVersionMap, compareVersion, selectedVersion) {
  652. var compareConfig = serviceVersionMap[compareVersion][serviceConfig.name + '-' + App.config.getConfigTagFromFileName(serviceConfig.filename)];
  653. var selectedConfig = serviceVersionMap[selectedVersion][serviceConfig.name + '-' + App.config.getConfigTagFromFileName(serviceConfig.filename)];
  654. serviceConfig.compareConfigs = [];
  655. serviceConfig.isComparison = true;
  656. if (compareConfig && selectedConfig) {
  657. serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, compareConfig));
  658. serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, selectedConfig));
  659. serviceConfig.hasCompareDiffs = this.hasCompareDiffs(serviceConfig.compareConfigs[0], serviceConfig.compareConfigs[1]);
  660. } else if (compareConfig && !selectedConfig) {
  661. serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, compareConfig));
  662. serviceConfig.compareConfigs.push(this.getMockComparisonConfig(selectedConfig, selectedVersion));
  663. serviceConfig.hasCompareDiffs = true;
  664. } else if (!compareConfig && selectedConfig) {
  665. serviceConfig.compareConfigs.push(this.getMockComparisonConfig(selectedConfig, compareVersion));
  666. serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, selectedConfig));
  667. serviceConfig.hasCompareDiffs = true;
  668. }
  669. },
  670. /**
  671. * init attributes and wrap mock compare config into App.ServiceConfigProperty
  672. * @param serviceConfig
  673. * @param compareConfig
  674. * @return {object}
  675. */
  676. getMockComparisonConfig: function (serviceConfig, compareServiceVersion) {
  677. var compareObject = $.extend(true, {isComparison: true}, serviceConfig);
  678. compareObject.isEditable = false;
  679. compareObject.serviceVersion = App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + compareServiceVersion);
  680. compareObject.isMock = true;
  681. compareObject.displayType = 'label';
  682. compareObject = App.ServiceConfigProperty.create(compareObject);
  683. compareObject.set('value', Em.I18n.t('common.property.undefined'));
  684. return compareObject;
  685. },
  686. /**
  687. * init attributes and wrap compare config into App.ServiceConfigProperty
  688. * @param serviceConfig
  689. * @param compareConfig
  690. * @return {object}
  691. */
  692. getComparisonConfig: function (serviceConfig, compareConfig) {
  693. var compareObject = $.extend(true, {isComparison: true}, serviceConfig);
  694. compareObject.isEditable = false;
  695. if (compareConfig) {
  696. if (serviceConfig.isMock) {
  697. compareObject.displayType = 'string';
  698. compareObject.isMock = false;
  699. }
  700. compareObject.serviceVersion = App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + compareConfig.service_config_version);
  701. compareObject = App.ServiceConfigProperty.create(compareObject);
  702. compareObject.set('isFinal', compareConfig.isFinal);
  703. compareObject.set('value', App.config.formatOverrideValue(serviceConfig, compareConfig.value));
  704. this.setSupportsFinal(compareObject);
  705. }
  706. return compareObject;
  707. },
  708. /**
  709. * set compare properties to service config of default group
  710. * @param serviceConfig
  711. * @param compareConfig
  712. */
  713. setCompareDefaultGroupConfig: function (serviceConfig, compareConfig) {
  714. var compareObject = {};
  715. serviceConfig.compareConfigs = [];
  716. serviceConfig.isComparison = true;
  717. //if config isn't reconfigurable then it can't have changed value to compare
  718. if (compareConfig && (serviceConfig.isReconfigurable || serviceConfig.isUserProperty)) {
  719. compareObject = this.getComparisonConfig(serviceConfig, compareConfig);
  720. serviceConfig.hasCompareDiffs = serviceConfig.isMock || this.hasCompareDiffs(serviceConfig, compareObject);
  721. serviceConfig.compareConfigs.push(compareObject);
  722. } else if (serviceConfig.isUserProperty) {
  723. serviceConfig.compareConfigs.push(this.getMockComparisonConfig(serviceConfig, this.get('compareServiceVersion.version')));
  724. serviceConfig.hasCompareDiffs = true;
  725. }
  726. return serviceConfig;
  727. },
  728. /**
  729. * check value and final attribute of original and compare config for differencies
  730. * @param originalConfig
  731. * @param compareConfig
  732. * @return {Boolean}
  733. */
  734. hasCompareDiffs: function (originalConfig, compareConfig) {
  735. return (originalConfig.value !== compareConfig.value) || (!!originalConfig.isFinal !== (compareConfig.isFinal == true));
  736. },
  737. /**
  738. * generate mock config object
  739. * @param name
  740. * @param serviceName
  741. * @param filename
  742. * @return {Object}
  743. */
  744. getMockConfig: function (name, serviceName, filename) {
  745. var undefinedConfig = {
  746. description: name,
  747. displayName: name,
  748. id: "site property",
  749. isOverridable: false,
  750. isReconfigurable: false,
  751. isRequired: false,
  752. isRequiredByAgent: false,
  753. isSecureConfig: false,
  754. isUserProperty: true,
  755. isVisible: true,
  756. name: name,
  757. filename: filename,
  758. serviceName: serviceName,
  759. value: Em.I18n.t('common.property.undefined'),
  760. isMock: true,
  761. displayType: 'label'
  762. };
  763. var category = App.config.identifyCategory(undefinedConfig);
  764. undefinedConfig.category = category && category.name;
  765. return undefinedConfig;
  766. },
  767. /**
  768. * get configs of chosen version from server to compare
  769. * @param compareServiceVersions
  770. * @return {$.ajax}
  771. */
  772. getCompareVersionConfigs: function (compareServiceVersions) {
  773. this.set('versionLoaded', false);
  774. return App.ajax.send({
  775. name: 'service.serviceConfigVersions.get.multiple',
  776. sender: this,
  777. data: {
  778. serviceName: this.get('content.serviceName'),
  779. serviceConfigVersions: compareServiceVersions
  780. }
  781. });
  782. },
  783. checkDatabaseProperties: function (serviceConfig) {
  784. this.hideSinkDatabaseProperties(serviceConfig.configs);
  785. this.hideHiveDatabaseProperties(serviceConfig.configs);
  786. this.hideOozieDatabaseProperties(serviceConfig.configs);
  787. },
  788. hideSinkDatabaseProperties: function (configs) {
  789. if (!['HDFS'].contains(this.get('content.serviceName'))) return;
  790. var property = configs.findProperty('name', 'sink.dbservername');
  791. if (property) property.set('isVisible', false);
  792. var hadoop_user_property = configs.findProperty('name', 'hadoop.user.name');
  793. if(hadoop_user_property)
  794. {
  795. hadoop_user_property.setProperties({
  796. isVisible: false,
  797. isRequired: false
  798. });
  799. }
  800. var hadoop_password_property = configs.findProperty('name', 'hadoop.user.password');
  801. if(hadoop_password_property)
  802. {
  803. hadoop_password_property.setProperties({
  804. isVisible: false,
  805. isRequired: false
  806. });
  807. }
  808. if (configs.someProperty('name', 'sink_database')) {
  809. var sinkDb = configs.findProperty('name', 'sink_database');
  810. if (sinkDb.value === 'Existing MSSQL Server database with integrated authentication') {
  811. configs.findProperty('name', 'sink.dblogin').setProperties({
  812. isVisible: false,
  813. isRequired: false
  814. });
  815. configs.findProperty('name', 'sink.dbpassword').setProperties({
  816. isVisible: false,
  817. isRequired: false
  818. });
  819. }
  820. }
  821. },
  822. hideHiveDatabaseProperties: function (configs) {
  823. if (!['HIVE'].contains(this.get('content.serviceName'))) return;
  824. var property = configs.findProperty('name', 'hive_hostname');
  825. if (property) property.set('isVisible', false);
  826. if (configs.someProperty('name', 'hive_database')) {
  827. var hiveDb = configs.findProperty('name', 'hive_database');
  828. if (hiveDb.value === 'Existing MSSQL Server database with integrated authentication') {
  829. configs.findProperty('name', 'javax.jdo.option.ConnectionUserName').setProperties({
  830. isVisible: false,
  831. isRequired: false
  832. });
  833. configs.findProperty('name', 'javax.jdo.option.ConnectionPassword').setProperties({
  834. isVisible: false,
  835. isRequired: false
  836. });
  837. }
  838. }
  839. },
  840. hideOozieDatabaseProperties: function (configs) {
  841. if (!['OOZIE'].contains(this.get('content.serviceName'))) return;
  842. var property = configs.findProperty('name', 'oozie_hostname');
  843. if (property) property.set('isVisible', false);
  844. if (configs.someProperty('name', 'oozie_database')) {
  845. var oozieDb = configs.findProperty('name', 'oozie_database');
  846. if (oozieDb.value === 'Existing MSSQL Server database with integrated authentication') {
  847. configs.findProperty('name', 'oozie.service.JPAService.jdbc.username').setProperties({
  848. isVisible: false,
  849. isRequired: false
  850. });
  851. configs.findProperty('name', 'oozie.service.JPAService.jdbc.password').setProperties({
  852. isVisible: false,
  853. isRequired: false
  854. });
  855. }
  856. }
  857. },
  858. onLoadOverrides: function (allConfigs) {
  859. var serviceName = this.get('content.serviceName');
  860. var advancedConfigs = this.get('advancedConfigs');
  861. //STEP 10: creation of serviceConfig object which contains configs for current service
  862. var serviceConfig = App.config.createServiceConfig(serviceName);
  863. //STEP11: Make SecondaryNameNode invisible on enabling namenode HA
  864. if (serviceConfig.get('serviceName') === 'HDFS') {
  865. App.config.OnNnHAHideSnn(serviceConfig);
  866. }
  867. serviceConfig = App.config.createServiceConfig(this.get('content.serviceName'));
  868. this.loadConfigs(this.get('allConfigs'), serviceConfig);
  869. this.checkOverrideProperty(serviceConfig);
  870. this.checkDatabaseProperties(serviceConfig);
  871. this.get('stepConfigs').pushObject(serviceConfig);
  872. this.set('selectedService', this.get('stepConfigs').objectAt(0));
  873. this.checkForSecureConfig(this.get('selectedService'));
  874. this.set('dataIsLoaded', true);
  875. this.set('versionLoaded', true);
  876. this.set('hash', this.getHash());
  877. this.set('isInit', false);
  878. },
  879. /**
  880. * Changes format from Object to Array
  881. *
  882. * {
  883. * 'core-site': 'version1',
  884. * 'hdfs-site': 'version1',
  885. * ...
  886. * }
  887. *
  888. * to
  889. *
  890. * [
  891. * {
  892. * siteName: 'core-site',
  893. * tagName: 'version1',
  894. * newTageName: null
  895. * },
  896. * ...
  897. * ]
  898. *
  899. * set tagnames for configuration of the *-site.xml
  900. */
  901. setServiceConfigTags: function (desiredConfigsSiteTags) {
  902. console.debug("setServiceConfigTags(): Trying to set ", desiredConfigsSiteTags);
  903. var newServiceConfigTags = [];
  904. for (var index in desiredConfigsSiteTags) {
  905. newServiceConfigTags.pushObject({
  906. siteName: index,
  907. tagName: desiredConfigsSiteTags[index],
  908. newTagName: null
  909. }, this);
  910. }
  911. console.debug("setServiceConfigTags(): Setting 'serviceConfigTags' to ", newServiceConfigTags);
  912. this.set('serviceConfigTags', newServiceConfigTags);
  913. },
  914. /**
  915. * check whether the config property is a security related knob
  916. * @param serviceConfig
  917. */
  918. checkForSecureConfig: function (serviceConfig) {
  919. serviceConfig.get('configs').forEach(function (_config) {
  920. this.get('secureConfigs').forEach(function (_secureConfig) {
  921. if (_config.get('name') === _secureConfig.name) {
  922. _config.set('isSecureConfig', true);
  923. }
  924. }, this)
  925. }, this)
  926. },
  927. /**
  928. * Load child components to service config object
  929. * @param {Array} configs - array of configs
  930. * @param {Object} componentConfig - component config object
  931. * @method loadConfigs
  932. */
  933. loadConfigs: function (configs, componentConfig) {
  934. var serviceConfigsData = App.StackService.find().findProperty('serviceName', this.get('content.serviceName'));
  935. var defaultGroupSelected = this.get('selectedConfigGroup.isDefault');
  936. configs.forEach(function (_serviceConfigProperty) {
  937. var serviceConfigProperty = this.createConfigProperty(_serviceConfigProperty, defaultGroupSelected, serviceConfigsData);
  938. componentConfig.configs.pushObject(serviceConfigProperty);
  939. serviceConfigProperty.validate();
  940. }, this);
  941. componentConfig.set('initConfigsLength', componentConfig.get('configs.length'));
  942. },
  943. /**
  944. * create {Em.Object} service_cfg_property based on {Object}_serviceConfigProperty and additional info
  945. * @param {Object} _serviceConfigProperty - config object
  946. * @param {Boolean} defaultGroupSelected - true if selected cfg group is default
  947. * @param {Object} serviceConfigsData - service cfg object
  948. * @returns {Ember.Object|null}
  949. * @method createConfigProperty
  950. */
  951. createConfigProperty: function (_serviceConfigProperty, defaultGroupSelected, serviceConfigsData) {
  952. if (!_serviceConfigProperty) return null;
  953. var overrides = _serviceConfigProperty.overrides;
  954. // we will populate the override properties below
  955. Em.set(_serviceConfigProperty, 'overrides', null);
  956. _serviceConfigProperty.isOverridable = Em.isNone(_serviceConfigProperty.isOverridable) ? true : _serviceConfigProperty.isOverridable;
  957. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  958. this.setValueForCheckBox(serviceConfigProperty);
  959. this.setSupportsFinal(serviceConfigProperty);
  960. this.setValuesForOverrides(overrides, _serviceConfigProperty, serviceConfigProperty, defaultGroupSelected);
  961. this.setEditability(serviceConfigProperty, defaultGroupSelected);
  962. return serviceConfigProperty;
  963. },
  964. /**
  965. * trigger addOverrideProperty
  966. * @param {Object} componentConfig
  967. * @method checkOverrideProperty
  968. */
  969. checkOverrideProperty: function (componentConfig) {
  970. var overrideToAdd = this.get('overrideToAdd');
  971. if (overrideToAdd) {
  972. overrideToAdd = componentConfig.configs.filter(function(c){
  973. return c.name == overrideToAdd.name && c.filename == overrideToAdd.filename;
  974. });
  975. if (overrideToAdd[0]) {
  976. this.addOverrideProperty(overrideToAdd[0]);
  977. this.set('overrideToAdd', null);
  978. }
  979. }
  980. },
  981. /**
  982. * set isEditable property of config for admin
  983. * if default cfg group and not on the host config page
  984. * @param {Ember.Object} serviceConfigProperty
  985. * @param {Boolean} defaultGroupSelected
  986. * @method setEditability
  987. */
  988. setEditability: function (serviceConfigProperty, defaultGroupSelected) {
  989. serviceConfigProperty.set('isEditable', false);
  990. if (serviceConfigProperty.get('isComparison')) return;
  991. if (App.isAccessible('ADMIN') && defaultGroupSelected && !this.get('isHostsConfigsPage') && !serviceConfigProperty.get('group')) {
  992. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  993. } else if (serviceConfigProperty.get('group') && this.get('selectedConfigGroup.name') === serviceConfigProperty.get('group.name')) {
  994. serviceConfigProperty.set('isEditable', true);
  995. }
  996. },
  997. /**
  998. * set supportsFinal property of config for admin
  999. * @param {Ember.Object} serviceConfigProperty
  1000. * @method setSupportsFinal
  1001. */
  1002. setSupportsFinal: function (serviceConfigProperty) {
  1003. if (serviceConfigProperty.get('isMock')) return;
  1004. var fileName = serviceConfigProperty.get('filename');
  1005. var matchingConfigType = this.get('configTypesInfo').supportsFinal.find(function(configType) {
  1006. return fileName.startsWith(configType);
  1007. });
  1008. serviceConfigProperty.set('supportsFinal', !!matchingConfigType);
  1009. },
  1010. /**
  1011. * set override values
  1012. * @param overrides
  1013. * @param _serviceConfigProperty
  1014. * @param serviceConfigProperty
  1015. * @param defaultGroupSelected
  1016. */
  1017. setValuesForOverrides: function (overrides, _serviceConfigProperty, serviceConfigProperty, defaultGroupSelected) {
  1018. if (Em.isNone(overrides)) return;
  1019. overrides.forEach(function (override) {
  1020. var newSCP = this.createNewSCP(override, _serviceConfigProperty, serviceConfigProperty, defaultGroupSelected);
  1021. var parentOverridesArray = serviceConfigProperty.get('overrides');
  1022. if (parentOverridesArray == null) {
  1023. parentOverridesArray = Em.A([]);
  1024. serviceConfigProperty.set('overrides', parentOverridesArray);
  1025. }
  1026. parentOverridesArray.pushObject(newSCP);
  1027. serviceConfigProperty.set('overrideValues', parentOverridesArray.mapProperty('value'));
  1028. serviceConfigProperty.set('overrideIsFinalValues', parentOverridesArray.mapProperty('isFinal'));
  1029. console.debug("createOverrideProperty(): Added override to main-property:", serviceConfigProperty.get('name'));
  1030. }, this);
  1031. },
  1032. /**
  1033. * create new overridden property and set appropriate fields
  1034. * @param override
  1035. * @param _serviceConfigProperty
  1036. * @param serviceConfigProperty
  1037. * @param defaultGroupSelected
  1038. * @returns {*}
  1039. */
  1040. createNewSCP: function (override, _serviceConfigProperty, serviceConfigProperty, defaultGroupSelected) {
  1041. var newSCP = App.ServiceConfigProperty.create(_serviceConfigProperty);
  1042. newSCP.set('value', override.value);
  1043. newSCP.set('isFinal', override.isFinal);
  1044. newSCP.set('supportsFinal', serviceConfigProperty.get('supportsFinal'));
  1045. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  1046. newSCP.set('parentSCP', serviceConfigProperty);
  1047. if (defaultGroupSelected) {
  1048. newSCP.set('group', override.group);
  1049. newSCP.set('isEditable', false);
  1050. }
  1051. return newSCP;
  1052. },
  1053. /**
  1054. * convert string values to boolean for checkboxes
  1055. * @param {Ember.Object} serviceConfigProperty
  1056. */
  1057. setValueForCheckBox: function (serviceConfigProperty) {
  1058. if (serviceConfigProperty.get("displayType") == 'checkbox') {
  1059. switch (serviceConfigProperty.get("value")) {
  1060. case 'true':
  1061. serviceConfigProperty.set("value", true);
  1062. serviceConfigProperty.set("defaultValue", true);
  1063. break;
  1064. case 'false':
  1065. serviceConfigProperty.set("value", false);
  1066. serviceConfigProperty.set("defaultValue", false);
  1067. break;
  1068. }
  1069. }
  1070. },
  1071. /**
  1072. * Initialize save configs popup
  1073. */
  1074. restartServicePopup: function () {
  1075. if (this.get("isSubmitDisabled")) {
  1076. return;
  1077. }
  1078. this.set("isApplyingChanges", true);
  1079. var self = this;
  1080. var header, message, messageClass, status;
  1081. var serviceName = this.get('content.serviceName'),
  1082. displayName = this.get('content.displayName'),
  1083. urlParams = '';
  1084. this.serverSideValidation().done(function () {
  1085. if (self.isDirChanged()) {
  1086. App.showConfirmationPopup(function () {
  1087. self.saveConfigs();
  1088. }, Em.I18n.t('services.service.config.confirmDirectoryChange').format(displayName), function () {
  1089. self.set('isApplyingChanges', false);
  1090. });
  1091. } else {
  1092. self.saveConfigs();
  1093. }
  1094. }).fail(function () {
  1095. self.set('isApplyingChanges', false);
  1096. });
  1097. },
  1098. /**
  1099. * Define if user has changed some dir properties
  1100. * @return {Boolean}
  1101. */
  1102. isDirChanged: function () {
  1103. var dirChanged = false;
  1104. var serviceName = this.get('content.serviceName');
  1105. if (serviceName === 'HDFS') {
  1106. var hdfsConfigs = this.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs');
  1107. if (App.get('isHadoop2Stack')) {
  1108. if ((hdfsConfigs.findProperty('name', 'dfs.namenode.name.dir') && hdfsConfigs.findProperty('name', 'dfs.namenode.name.dir').get('isNotDefaultValue')) ||
  1109. (hdfsConfigs.findProperty('name', 'dfs.namenode.checkpoint.dir') && hdfsConfigs.findProperty('name', 'dfs.namenode.checkpoint.dir').get('isNotDefaultValue')) ||
  1110. (hdfsConfigs.findProperty('name', 'dfs.datanode.data.dir') && hdfsConfigs.findProperty('name', 'dfs.datanode.data.dir').get('isNotDefaultValue'))) {
  1111. dirChanged = true;
  1112. }
  1113. } else {
  1114. if ((hdfsConfigs.findProperty('name', 'dfs.name.dir') && hdfsConfigs.findProperty('name', 'dfs.name.dir').get('isNotDefaultValue')) ||
  1115. (hdfsConfigs.findProperty('name', 'fs.checkpoint.dir') && hdfsConfigs.findProperty('name', 'fs.checkpoint.dir').get('isNotDefaultValue')) ||
  1116. (hdfsConfigs.findProperty('name', 'dfs.data.dir') && hdfsConfigs.findProperty('name', 'dfs.data.dir').get('isNotDefaultValue'))) {
  1117. dirChanged = true;
  1118. }
  1119. }
  1120. } else if (serviceName === 'MAPREDUCE') {
  1121. var mapredConfigs = this.get('stepConfigs').findProperty('serviceName', 'MAPREDUCE').get('configs');
  1122. if ((mapredConfigs.findProperty('name', 'mapred.local.dir') && mapredConfigs.findProperty('name', 'mapred.local.dir').get('isNotDefaultValue')) ||
  1123. (mapredConfigs.findProperty('name', 'mapred.system.dir') && mapredConfigs.findProperty('name', 'mapred.system.dir').get('isNotDefaultValue'))) {
  1124. dirChanged = true;
  1125. }
  1126. }
  1127. return dirChanged;
  1128. },
  1129. /**
  1130. * Save changed configs and config groups
  1131. */
  1132. saveConfigs: function () {
  1133. var selectedConfigGroup = this.get('selectedConfigGroup');
  1134. var configs = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName')).get('configs');
  1135. var self = this;
  1136. if (selectedConfigGroup.get('isDefault')) {
  1137. if (this.get('content.serviceName') === 'YARN') {
  1138. configs = App.config.textareaIntoFileConfigs(configs, 'capacity-scheduler.xml');
  1139. }
  1140. var modifiedConfigs = configs
  1141. // get only modified and created configs
  1142. .filter(function(config) { return config.get('isNotDefaultValue') || config.get('isNotSaved'); })
  1143. // get file names and add file names that was modified, for example after property removing
  1144. .mapProperty('filename').concat(this.get('modifiedFileNames')).uniq()
  1145. // get configs by filename
  1146. .map(function(fileName) {
  1147. return configs.filterProperty('filename', fileName);
  1148. });
  1149. if (!!modifiedConfigs.length) {
  1150. // concatenate results
  1151. modifiedConfigs = modifiedConfigs.reduce(function(current, prev) { return current.concat(prev); });
  1152. }
  1153. // save modified original configs that have no group
  1154. this.saveSiteConfigs(modifiedConfigs.filter(function(config) { return !config.get('group'); }));
  1155. /**
  1156. * First we put cluster configurations, which automatically creates /configurations
  1157. * resources. Next we update host level overrides.
  1158. */
  1159. this.doPUTClusterConfigurations();
  1160. } else {
  1161. var overridenConfigs = [];
  1162. var groupHosts = [];
  1163. configs.filterProperty('isOverridden', true).forEach(function (config) {
  1164. overridenConfigs = overridenConfigs.concat(config.get('overrides'));
  1165. });
  1166. // find custom original properties that assigned to selected config group
  1167. overridenConfigs = overridenConfigs.concat(configs.filterProperty('group')
  1168. .filter(function(config) { return config.get('group.name') == self.get('selectedConfigGroup.name'); }));
  1169. this.formatConfigValues(overridenConfigs);
  1170. selectedConfigGroup.get('hosts').forEach(function (hostName) {
  1171. groupHosts.push({"host_name": hostName});
  1172. });
  1173. this.putConfigGroupChanges({
  1174. ConfigGroup: {
  1175. "id": selectedConfigGroup.get('id'),
  1176. "cluster_name": App.get('clusterName'),
  1177. "group_name": selectedConfigGroup.get('name'),
  1178. "tag": selectedConfigGroup.get('service.id'),
  1179. "description": selectedConfigGroup.get('description'),
  1180. "hosts": groupHosts,
  1181. "service_config_version_note": this.get('serviceConfigVersionNote'),
  1182. "desired_configs": this.buildGroupDesiredConfigs(overridenConfigs)
  1183. }
  1184. }, true);
  1185. }
  1186. },
  1187. /**
  1188. * On save configs handler. Open save configs popup with appropriate message.
  1189. */
  1190. onDoPUTClusterConfigurations: function () {
  1191. var header, message, messageClass, value, status = 'unknown', urlParams = '',
  1192. result = {
  1193. flag: this.get('saveConfigsFlag'),
  1194. message: null,
  1195. value: null
  1196. },
  1197. extendedModel = App.Service.extendedModel[this.get('content.serviceName')],
  1198. currentService = extendedModel ? App[extendedModel].find(this.get('content.serviceName')) : App.Service.find(this.get('content.serviceName'));
  1199. if (!result.flag) {
  1200. result.message = Em.I18n.t('services.service.config.failSaveConfig');
  1201. }
  1202. App.router.get('clusterController').updateClusterData();
  1203. App.router.get('updateController').updateComponentConfig(function () {
  1204. });
  1205. var flag = result.flag;
  1206. if (result.flag === true) {
  1207. header = Em.I18n.t('services.service.config.saved');
  1208. message = Em.I18n.t('services.service.config.saved.message');
  1209. messageClass = 'alert alert-success';
  1210. // warn the user if any of the components are in UNKNOWN state
  1211. urlParams += ',ServiceComponentInfo/installed_count,ServiceComponentInfo/total_count';
  1212. if (this.get('content.serviceName') === 'HDFS' || App.Service.find().someProperty('id', 'MAPREDUCE')) {
  1213. urlParams += '&ServiceComponentInfo/service_name.in(HDFS,MAPREDUCE)'
  1214. }
  1215. } else {
  1216. header = Em.I18n.t('common.failure');
  1217. message = result.message;
  1218. messageClass = 'alert alert-error';
  1219. value = result.value;
  1220. }
  1221. if(currentService){
  1222. App.QuickViewLinks.proto().set('content', currentService);
  1223. App.QuickViewLinks.proto().loadTags();
  1224. }
  1225. this.showSaveConfigsPopup(header, flag, message, messageClass, value, status, urlParams);
  1226. },
  1227. /**
  1228. * Show save configs popup
  1229. * @method showSaveConfigsPopup
  1230. * @return {App.ModalPopup}
  1231. */
  1232. showSaveConfigsPopup: function (header, flag, message, messageClass, value, status, urlParams) {
  1233. var self = this;
  1234. if (flag) {
  1235. this.set('forceTransition', flag);
  1236. self.loadStep();
  1237. }
  1238. return App.ModalPopup.show({
  1239. header: header,
  1240. primary: Em.I18n.t('ok'),
  1241. secondary: null,
  1242. onPrimary: function () {
  1243. this.hide();
  1244. if (!flag) {
  1245. self.set('isApplyingChanges', false);
  1246. }
  1247. },
  1248. onClose: function () {
  1249. this.hide();
  1250. self.set('isApplyingChanges', false);
  1251. },
  1252. disablePrimary: true,
  1253. bodyClass: Ember.View.extend({
  1254. flag: flag,
  1255. message: function () {
  1256. return this.get('isLoaded') ? message : Em.I18n.t('services.service.config.saving.message');
  1257. }.property('isLoaded'),
  1258. messageClass: function () {
  1259. return this.get('isLoaded') ? messageClass : 'alert alert-info';
  1260. }.property('isLoaded'),
  1261. setDisablePrimary: function () {
  1262. this.get('parentView').set('disablePrimary', !this.get('isLoaded'));
  1263. }.observes('isLoaded'),
  1264. runningHosts: [],
  1265. runningComponentCount: 0,
  1266. unknownHosts: [],
  1267. unknownComponentCount: 0,
  1268. siteProperties: value,
  1269. isLoaded: false,
  1270. componentsFilterSuccessCallback: function (response) {
  1271. var count = 0,
  1272. view = this,
  1273. lazyLoadHosts = function (dest) {
  1274. lazyLoading.run({
  1275. initSize: 20,
  1276. chunkSize: 50,
  1277. delay: 50,
  1278. destination: dest,
  1279. source: hosts,
  1280. context: view
  1281. });
  1282. },
  1283. /**
  1284. * Map components for their hosts
  1285. * Return format:
  1286. * <code>
  1287. * {
  1288. * host1: [component1, component2, ...],
  1289. * host2: [component3, component4, ...]
  1290. * }
  1291. * </code>
  1292. * @return {object}
  1293. */
  1294. setComponents = function (item, components) {
  1295. item.host_components.forEach(function (c) {
  1296. var name = c.HostRoles.host_name;
  1297. if (!components[name]) {
  1298. components[name] = [];
  1299. }
  1300. components[name].push(App.format.role(item.ServiceComponentInfo.component_name));
  1301. });
  1302. return components;
  1303. },
  1304. /**
  1305. * Map result of <code>setComponents</code> to array
  1306. * @return {{name: string, components: string}[]}
  1307. */
  1308. setHosts = function (components) {
  1309. var hosts = [];
  1310. Em.keys(components).forEach(function (key) {
  1311. hosts.push({
  1312. name: key,
  1313. components: components[key].join(', ')
  1314. });
  1315. });
  1316. return hosts;
  1317. },
  1318. components = {},
  1319. hosts = [];
  1320. switch (status) {
  1321. case 'unknown':
  1322. response.items.filter(function (item) {
  1323. return (item.ServiceComponentInfo.total_count > item.ServiceComponentInfo.started_count + item.ServiceComponentInfo.installed_count);
  1324. }).forEach(function (item) {
  1325. var total = item.ServiceComponentInfo.total_count,
  1326. started = item.ServiceComponentInfo.started_count,
  1327. installed = item.ServiceComponentInfo.installed_count,
  1328. unknown = total - started + installed;
  1329. components = setComponents(item, components);
  1330. count += unknown;
  1331. });
  1332. hosts = setHosts(components);
  1333. this.set('unknownComponentCount', count);
  1334. lazyLoadHosts(this.get('unknownHosts'));
  1335. break;
  1336. case 'started':
  1337. response.items.filterProperty('ServiceComponentInfo.started_count').forEach(function (item) {
  1338. var started = item.ServiceComponentInfo.started_count;
  1339. components = setComponents(item, components);
  1340. count += started;
  1341. hosts = setHosts(components);
  1342. });
  1343. this.set('runningComponentCount', count);
  1344. lazyLoadHosts(this.get('runningHosts'));
  1345. break;
  1346. }
  1347. },
  1348. componentsFilterErrorCallback: function () {
  1349. this.set('isLoaded', true);
  1350. },
  1351. didInsertElement: function () {
  1352. return App.ajax.send({
  1353. name: 'components.filter_by_status',
  1354. sender: this,
  1355. data: {
  1356. clusterName: App.get('clusterName'),
  1357. urlParams: urlParams
  1358. },
  1359. success: 'componentsFilterSuccessCallback',
  1360. error: 'componentsFilterErrorCallback'
  1361. });
  1362. },
  1363. getDisplayMessage: function () {
  1364. var displayMsg = [];
  1365. var siteProperties = this.get('siteProperties');
  1366. if (siteProperties) {
  1367. siteProperties.forEach(function (_siteProperty) {
  1368. var displayProperty = _siteProperty.siteProperty;
  1369. var displayNames = _siteProperty.displayNames;
  1370. if (displayNames && displayNames.length) {
  1371. if (displayNames.length === 1) {
  1372. displayMsg.push(displayProperty + Em.I18n.t('as') + displayNames[0]);
  1373. } else {
  1374. var name;
  1375. displayNames.forEach(function (_name, index) {
  1376. if (index === 0) {
  1377. name = _name;
  1378. } else if (index === siteProperties.length - 1) {
  1379. name = name + Em.I18n.t('and') + _name;
  1380. } else {
  1381. name = name + ', ' + _name;
  1382. }
  1383. }, this);
  1384. displayMsg.push(displayProperty + Em.I18n.t('as') + name);
  1385. }
  1386. } else {
  1387. displayMsg.push(displayProperty);
  1388. }
  1389. }, this);
  1390. }
  1391. return displayMsg;
  1392. }.property('siteProperties'),
  1393. runningHostsMessage: function () {
  1394. return Em.I18n.t('services.service.config.stopService.runningHostComponents').format(this.get('runningComponentCount'), this.get('runningHosts.length'));
  1395. }.property('runningComponentCount', 'runningHosts.length'),
  1396. unknownHostsMessage: function () {
  1397. return Em.I18n.t('services.service.config.stopService.unknownHostComponents').format(this.get('unknownComponentCount'), this.get('unknownHosts.length'));
  1398. }.property('unknownComponentCount', 'unknownHosts.length'),
  1399. templateName: require('templates/main/service/info/configs_save_popup')
  1400. })
  1401. })
  1402. },
  1403. /**
  1404. * construct desired_configs for config groups from overriden properties
  1405. * @param configs
  1406. * @param timeTag
  1407. * @return {Array}
  1408. */
  1409. buildGroupDesiredConfigs: function (configs, timeTag) {
  1410. var sites = [];
  1411. var time = timeTag || (new Date).getTime();
  1412. var siteFileNames = configs.mapProperty('filename').uniq();
  1413. sites = siteFileNames.map(function (filename) {
  1414. return {
  1415. type: filename.replace('.xml', ''),
  1416. tag: 'version' + time,
  1417. properties: []
  1418. };
  1419. });
  1420. configs.forEach(function (config) {
  1421. var type = config.get('filename').replace('.xml', '');
  1422. var site = sites.findProperty('type', type);
  1423. site.properties.push(config);
  1424. });
  1425. return sites.map(function (site) {
  1426. return this.createSiteObj(site.type, site.tag, site.properties);
  1427. }, this);
  1428. },
  1429. /**
  1430. * persist properties of config groups to server
  1431. * show result popup if <code>showPopup</code> is true
  1432. * @param data {Object}
  1433. * @param showPopup {Boolean}
  1434. */
  1435. putConfigGroupChanges: function (data, showPopup) {
  1436. var ajaxOptions = {
  1437. name: 'config_groups.update_config_group',
  1438. sender: this,
  1439. data: {
  1440. id: data.ConfigGroup.id,
  1441. configGroup: data
  1442. }
  1443. };
  1444. if (showPopup) {
  1445. ajaxOptions.success = "putConfigGroupChangesSuccess";
  1446. }
  1447. App.ajax.send(ajaxOptions);
  1448. },
  1449. putConfigGroupChangesSuccess: function () {
  1450. this.set('saveConfigsFlag', true);
  1451. this.onDoPUTClusterConfigurations();
  1452. },
  1453. /**
  1454. * set sink hostnames in configs
  1455. * @param configs
  1456. */
  1457. setSinkHostName: function (configs) {
  1458. var dbHostPropertyName = null;
  1459. if (configs.someProperty('name', 'sink_database')) {
  1460. var sinkDb = configs.findProperty('name', 'sink_database');
  1461. if (sinkDb.value === 'Existing MSSQL Server database with integrated authentication') {
  1462. var existingMSSQLServerHost = configs.findProperty('name', 'sink_existing_mssql_server_host');
  1463. if (existingMSSQLServerHost) {
  1464. dbHostPropertyName = 'sink_existing_mssql_server_host';
  1465. }
  1466. configs = configs.without(configs.findProperty('name', 'sink_existing_mssql_server_2_database'));
  1467. configs = configs.without(configs.findProperty('name', 'sink_existing_mssql_server_2_host'));
  1468. } else if (sinkDb.value === 'Existing MSSQL Server database with sql auth') {
  1469. var existingMSSQL2ServerHost = configs.findProperty('name', 'sink_existing_mssql_server_2_host');
  1470. if (existingMSSQL2ServerHost) {
  1471. dbHostPropertyName = 'sink_existing_mssql_server_2_host';
  1472. }
  1473. configs = configs.without(configs.findProperty('name', 'sink_existing_mssql_server_database'));
  1474. configs = configs.without(configs.findProperty('name', 'sink_existing_mssql_server_host'));
  1475. }
  1476. }
  1477. if (dbHostPropertyName) {
  1478. var sinkHostNameProperty = App.ServiceConfigProperty.create(App.config.get('preDefinedSiteProperties').findProperty('name', 'sink.dbservername'));
  1479. sinkHostNameProperty.set('value', configs.findProperty('name', dbHostPropertyName).get('value'));
  1480. configs.pushObject(sinkHostNameProperty);
  1481. }
  1482. },
  1483. /**
  1484. * set hive hostnames in configs
  1485. * @param configs
  1486. */
  1487. setHiveHostName: function (configs) {
  1488. var dbHostPropertyName = null;
  1489. if (configs.someProperty('name', 'hive_database')) {
  1490. var hiveDb = configs.findProperty('name', 'hive_database');
  1491. if (hiveDb.value === 'New MySQL Database' || hiveDb.value === 'New PostgreSQL Database') {
  1492. var ambariHost = configs.findProperty('name', 'hive_ambari_host');
  1493. if (ambariHost) {
  1494. ambariHost.name = 'hive_hostname';
  1495. }
  1496. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_host'));
  1497. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_database'));
  1498. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_host'));
  1499. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_database'));
  1500. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_host'));
  1501. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_database'));
  1502. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_database'));
  1503. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_host'));
  1504. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_database'));
  1505. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_host'));
  1506. } else if (hiveDb.value === 'Existing MySQL Database') {
  1507. var existingMySqlHost = configs.findProperty('name', 'hive_existing_mysql_host');
  1508. if (existingMySqlHost) {
  1509. dbHostPropertyName = 'hive_existing_mysql_host';
  1510. }
  1511. configs = configs.without(configs.findProperty('name', 'hive_ambari_host'));
  1512. configs = configs.without(configs.findProperty('name', 'hive_ambari_database'));
  1513. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_host'));
  1514. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_database'));
  1515. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_host'));
  1516. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_database'));
  1517. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_database'));
  1518. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_host'));
  1519. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_database'));
  1520. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_host'));
  1521. } else if (hiveDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  1522. var existingPostgreSqlHost = configs.findProperty('name', 'hive_existing_postgresql_host');
  1523. if (existingPostgreSqlHost) {
  1524. dbHostPropertyName = 'hive_existing_postgresql_host';
  1525. }
  1526. configs = configs.without(configs.findProperty('name', 'hive_ambari_host'));
  1527. configs = configs.without(configs.findProperty('name', 'hive_ambari_database'));
  1528. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_host'));
  1529. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_database'));
  1530. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_host'));
  1531. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_database'));
  1532. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_database'));
  1533. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_host'));
  1534. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_database'));
  1535. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_host'));
  1536. } else if (hiveDb.value === 'Existing Oracle Database') {
  1537. var existingOracleHost = configs.findProperty('name', 'hive_existing_oracle_host');
  1538. if (existingOracleHost) {
  1539. dbHostPropertyName = 'hive_existing_oracle_host';
  1540. }
  1541. configs = configs.without(configs.findProperty('name', 'hive_ambari_host'));
  1542. configs = configs.without(configs.findProperty('name', 'hive_ambari_database'));
  1543. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_host'));
  1544. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_database'));
  1545. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_host'));
  1546. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_database'));
  1547. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_database'));
  1548. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_host'));
  1549. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_database'));
  1550. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_host'));
  1551. } else if (hiveDb.value === 'Existing MSSQL Server database with integrated authentication') {
  1552. var existingMSSQLServerHost = configs.findProperty('name', 'hive_existing_mssql_server_host');
  1553. if (existingMSSQLServerHost) {
  1554. dbHostPropertyName = 'hive_existing_mssql_server_host';
  1555. }
  1556. configs = configs.without(configs.findProperty('name', 'hive_ambari_host'));
  1557. configs = configs.without(configs.findProperty('name', 'hive_ambari_database'));
  1558. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_host'));
  1559. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_database'));
  1560. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_host'));
  1561. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_database'));
  1562. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_host'));
  1563. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_database'));
  1564. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_database'));
  1565. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_2_host'));
  1566. } else if (hiveDb.value === 'Existing MSSQL Server database with sql auth') {
  1567. var existingMSSQL2ServerHost = configs.findProperty('name', 'hive_existing_mssql_server_2_host');
  1568. if (existingMSSQL2ServerHost) {
  1569. dbHostPropertyName = 'hive_existing_mssql_server_2_host';
  1570. }
  1571. configs = configs.without(configs.findProperty('name', 'hive_ambari_host'));
  1572. configs = configs.without(configs.findProperty('name', 'hive_ambari_database'));
  1573. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_host'));
  1574. configs = configs.without(configs.findProperty('name', 'hive_existing_mysql_database'));
  1575. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_host'));
  1576. configs = configs.without(configs.findProperty('name', 'hive_existing_postgresql_database'));
  1577. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_host'));
  1578. configs = configs.without(configs.findProperty('name', 'hive_existing_oracle_database'));
  1579. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_database'));
  1580. configs = configs.without(configs.findProperty('name', 'hive_existing_mssql_server_host'));
  1581. }
  1582. }
  1583. if (dbHostPropertyName) {
  1584. var hiveHostNameProperty = App.ServiceConfigProperty.create(App.config.get('preDefinedSiteProperties').findProperty('name', 'hive_hostname'));
  1585. hiveHostNameProperty.set('value', configs.findProperty('name', dbHostPropertyName).get('value'));
  1586. configs.pushObject(hiveHostNameProperty);
  1587. }
  1588. },
  1589. /**
  1590. * set oozie hostnames in configs
  1591. * @param configs
  1592. */
  1593. setOozieHostName: function (configs) {
  1594. var dbHostPropertyName = null;
  1595. if (configs.someProperty('name', 'oozie_database')) {
  1596. var oozieDb = configs.findProperty('name', 'oozie_database');
  1597. if (oozieDb.value === 'New Derby Database') {
  1598. configs = configs.without(configs.findProperty('name', 'oozie_ambari_host'));
  1599. configs = configs.without(configs.findProperty('name', 'oozie_ambari_database'));
  1600. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_host'));
  1601. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_database'));
  1602. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_host'));
  1603. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_database'));
  1604. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_host'));
  1605. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_database'));
  1606. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_database'));
  1607. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_host'));
  1608. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_database'));
  1609. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_host'));
  1610. } else if (oozieDb.value === 'New MySQL Database') {
  1611. var ambariHost = configs.findProperty('name', 'oozie_ambari_host');
  1612. if (ambariHost) {
  1613. ambariHost.name = 'oozie_hostname';
  1614. }
  1615. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_host'));
  1616. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_database'));
  1617. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_host'));
  1618. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_database'));
  1619. configs = configs.without(configs.findProperty('name', 'oozie_derby_database'));
  1620. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_host'));
  1621. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_database'));
  1622. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_database'));
  1623. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_host'));
  1624. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_database'));
  1625. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_host'));
  1626. } else if (oozieDb.value === 'Existing MySQL Database') {
  1627. var existingMySqlHost = configs.findProperty('name', 'oozie_existing_mysql_host');
  1628. if (existingMySqlHost) {
  1629. dbHostPropertyName = 'oozie_existing_mysql_host';
  1630. }
  1631. configs = configs.without(configs.findProperty('name', 'oozie_ambari_host'));
  1632. configs = configs.without(configs.findProperty('name', 'oozie_ambari_database'));
  1633. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_host'));
  1634. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_database'));
  1635. configs = configs.without(configs.findProperty('name', 'oozie_derby_database'));
  1636. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_host'));
  1637. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_database'));
  1638. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_database'));
  1639. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_host'));
  1640. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_database'));
  1641. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_host'));
  1642. } else if (oozieDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  1643. var existingPostgreSqlHost = configs.findProperty('name', 'oozie_existing_postgresql_host');
  1644. if (existingPostgreSqlHost) {
  1645. dbHostPropertyName = 'oozie_existing_postgresql_host';
  1646. }
  1647. configs = configs.without(configs.findProperty('name', 'oozie_ambari_host'));
  1648. configs = configs.without(configs.findProperty('name', 'oozie_ambari_database'));
  1649. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_host'));
  1650. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_database'));
  1651. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_host'));
  1652. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_database'));
  1653. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_database'));
  1654. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_host'));
  1655. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_database'));
  1656. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_host'));
  1657. }
  1658. else if (oozieDb.value === 'Existing Oracle Database') {
  1659. var existingOracleHost = configs.findProperty('name', 'oozie_existing_oracle_host');
  1660. if (existingOracleHost) {
  1661. dbHostPropertyName = 'oozie_existing_oracle_host';
  1662. }
  1663. configs = configs.without(configs.findProperty('name', 'oozie_ambari_host'));
  1664. configs = configs.without(configs.findProperty('name', 'oozie_ambari_database'));
  1665. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_host'));
  1666. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_database'));
  1667. configs = configs.without(configs.findProperty('name', 'oozie_derby_database'));
  1668. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_database'));
  1669. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_host'));
  1670. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_database'));
  1671. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_host'));
  1672. } else if (oozieDb.value === 'Existing MSSQL Server database with integrated authentication') {
  1673. var existingMySqlServerHost = configs.findProperty('name', 'oozie_existing_mssql_server_host');
  1674. if (existingMySqlServerHost) {
  1675. dbHostPropertyName = 'oozie_existing_mssql_server_host';
  1676. }
  1677. configs = configs.without(configs.findProperty('name', 'oozie_ambari_host'));
  1678. configs = configs.without(configs.findProperty('name', 'oozie_ambari_database'));
  1679. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_host'));
  1680. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_database'));
  1681. configs = configs.without(configs.findProperty('name', 'oozie_derby_database'));
  1682. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_host'));
  1683. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_database'));
  1684. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_host'));
  1685. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_database'));
  1686. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_database'));
  1687. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_2_host'));
  1688. } else if (oozieDb.value === 'Existing MSSQL Server database with sql auth') {
  1689. var existingMySql2ServerHost = configs.findProperty('name', 'oozie_existing_mssql_server_2_host');
  1690. if (existingMySql2ServerHost) {
  1691. dbHostPropertyName = 'oozie_existing_mssql_server_2_host';
  1692. }
  1693. configs = configs.without(configs.findProperty('name', 'oozie_ambari_host'));
  1694. configs = configs.without(configs.findProperty('name', 'oozie_ambari_database'));
  1695. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_host'));
  1696. configs = configs.without(configs.findProperty('name', 'oozie_existing_oracle_database'));
  1697. configs = configs.without(configs.findProperty('name', 'oozie_derby_database'));
  1698. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_host'));
  1699. configs = configs.without(configs.findProperty('name', 'oozie_existing_postgresql_database'));
  1700. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_host'));
  1701. configs = configs.without(configs.findProperty('name', 'oozie_existing_mysql_database'));
  1702. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_database'));
  1703. configs = configs.without(configs.findProperty('name', 'oozie_existing_mssql_server_host'));
  1704. }
  1705. }
  1706. if (dbHostPropertyName) {
  1707. var oozieHostNameProperty = App.ServiceConfigProperty.create(App.config.get('preDefinedSiteProperties').findProperty('name', 'oozie_hostname'));
  1708. oozieHostNameProperty.set('value', configs.findProperty('name', dbHostPropertyName).get('value'));
  1709. configs.pushObject(oozieHostNameProperty);
  1710. }
  1711. },
  1712. /**
  1713. * save site configs
  1714. * @param configs
  1715. */
  1716. saveSiteConfigs: function (configs) {
  1717. //storedConfigs contains custom configs as well
  1718. this.setHiveHostName(configs);
  1719. this.setOozieHostName(configs);
  1720. this.setSinkHostName(configs);
  1721. this.formatConfigValues(configs);
  1722. var mappedConfigs = App.config.excludeUnsupportedConfigs(this.get('configMapping').all(), App.Service.find().mapProperty('serviceName'));
  1723. var allUiConfigs = this.loadUiSideConfigs(mappedConfigs);
  1724. this.set('uiConfigs', configs.concat(allUiConfigs));
  1725. },
  1726. formatConfigValues: function (serviceConfigProperties) {
  1727. serviceConfigProperties.forEach(function (_config) {
  1728. if (typeof _config.get('value') === "boolean") _config.set('value', _config.value.toString());
  1729. _config.set('value', App.config.trimProperty(_config, true));
  1730. });
  1731. },
  1732. /**
  1733. * return configs from the UI side
  1734. * @param configMapping array with configs
  1735. * @return {Array}
  1736. */
  1737. loadUiSideConfigs: function (configMapping) {
  1738. var uiConfig = [];
  1739. var configs = configMapping.filterProperty('foreignKey', null);
  1740. this.addDynamicProperties(configs);
  1741. configs.forEach(function (_config) {
  1742. var valueWithOverrides = this.getGlobConfigValueWithOverrides(_config.templateName, _config.value);
  1743. if (valueWithOverrides !== null) {
  1744. uiConfig.pushObject({
  1745. "id": "site property",
  1746. "name": _config.name,
  1747. "value": valueWithOverrides.value,
  1748. "filename": _config.filename,
  1749. "overrides": valueWithOverrides.overrides
  1750. });
  1751. }
  1752. }, this);
  1753. return uiConfig;
  1754. },
  1755. addDynamicProperties: function (configs) {
  1756. var allConfigs = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName')).get('configs');
  1757. var templetonHiveProperty = allConfigs.someProperty('name', 'templeton.hive.properties');
  1758. if (!templetonHiveProperty && this.get('content.serviceName') === 'HIVE') {
  1759. configs.pushObject({
  1760. "name": "templeton.hive.properties",
  1761. "templateName": ["hivemetastore_host"],
  1762. "foreignKey": null,
  1763. "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",
  1764. "filename": "webhcat-site.xml"
  1765. });
  1766. }
  1767. },
  1768. /**
  1769. * return config value
  1770. * @param templateName
  1771. * @param expression
  1772. * @return {Object}
  1773. * example: <code>{
  1774. * value: '...',
  1775. * overrides: {
  1776. * 'value1': [h1, h2],
  1777. * 'value2': [h3]
  1778. * }
  1779. * }</code>
  1780. */
  1781. getGlobConfigValueWithOverrides: function (templateName, expression) {
  1782. var express = expression.match(/<(.*?)>/g);
  1783. var value = expression;
  1784. var overrideHostToValue = {};
  1785. if (express != null) {
  1786. express.forEach(function (_express) {
  1787. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  1788. var globalObj = this.get('allConfigs').findProperty('name', templateName[index]);
  1789. if (globalObj) {
  1790. var globOverride = globalObj.overrides;
  1791. if (globOverride != null) {
  1792. for (var ov in globOverride) {
  1793. globOverride[ov].forEach(function (host) {
  1794. var replacedVal = (host in overrideHostToValue) ? overrideHostToValue[host] : expression;
  1795. overrideHostToValue[host] = replacedVal.replace(_express, ov);
  1796. }, this);
  1797. }
  1798. }
  1799. value = expression.replace(_express, globalObj.value);
  1800. } else {
  1801. value = null;
  1802. }
  1803. }, this);
  1804. }
  1805. return this.getValueWithOverrides(value, overrideHostToValue)
  1806. },
  1807. getValueWithOverrides: function (value, overrideHostToValue) {
  1808. var valueWithOverrides = {
  1809. value: value,
  1810. overrides: {}
  1811. };
  1812. if (!jQuery.isEmptyObject(overrideHostToValue)) {
  1813. for (var host in overrideHostToValue) {
  1814. var hostVal = overrideHostToValue[host];
  1815. if (!(hostVal in valueWithOverrides.overrides)) {
  1816. valueWithOverrides.overrides[hostVal] = [];
  1817. }
  1818. valueWithOverrides.overrides[hostVal].push(host);
  1819. }
  1820. }
  1821. return valueWithOverrides;
  1822. },
  1823. /**
  1824. * Saves cluster level configurations for all necessary sites.
  1825. * PUT calls are made to /api/v1/clusters/clusterName for each site.
  1826. * @return {Boolean}
  1827. * @method doPUTClusterConfigurations
  1828. */
  1829. doPUTClusterConfigurations: function () {
  1830. this.set('saveConfigsFlag', true);
  1831. var serviceConfigTags = this.get('serviceConfigTags');
  1832. this.setNewTagNames(serviceConfigTags);
  1833. var siteNameToServerDataMap = {};
  1834. var configsToSave = [];
  1835. serviceConfigTags.forEach(function (_serviceTags) {
  1836. var configs = this.createConfigObject(_serviceTags.siteName, _serviceTags.newTagName);
  1837. if (configs) {
  1838. configsToSave.push(configs);
  1839. siteNameToServerDataMap[_serviceTags.siteName] = configs;
  1840. }
  1841. }, this);
  1842. configsToSave = this.filterChangedConfiguration(configsToSave);
  1843. if (configsToSave.length > 0) {
  1844. this.doPUTClusterConfigurationSites(configsToSave);
  1845. } else {
  1846. this.onDoPUTClusterConfigurations();
  1847. }
  1848. this.set("savedSiteNameToServerServiceConfigDataMap", siteNameToServerDataMap);
  1849. },
  1850. /**
  1851. * create different config object depending on siteName
  1852. * @param {String} siteName
  1853. * @param {String} tagName
  1854. * @returns {Object|null}
  1855. * @method createConfigObject
  1856. */
  1857. createConfigObject: function (siteName, tagName) {
  1858. console.log("TRACE: Inside " + siteName);
  1859. var configObject = {};
  1860. switch (siteName) {
  1861. case 'core-site':
  1862. if (this.get('content.serviceName') === 'HDFS' || this.get('content.serviceName') === 'GLUSTERFS') {
  1863. configObject = this.createCoreSiteObj(tagName);
  1864. } else {
  1865. return null;
  1866. }
  1867. break;
  1868. default:
  1869. var filename = (App.config.get('filenameExceptions').contains(siteName)) ? siteName : siteName + '.xml';
  1870. if (filename === 'mapred-queue-acls.xml') {
  1871. return null;
  1872. }
  1873. configObject = this.createSiteObj(siteName, tagName, this.get('uiConfigs').filterProperty('filename', filename));
  1874. break;
  1875. }
  1876. configObject.service_config_version_note = this.get('serviceConfigVersionNote');
  1877. return configObject;
  1878. },
  1879. /**
  1880. * filter out unchanged configurations
  1881. * @param {Array} configsToSave
  1882. * @method filterChangedConfiguration
  1883. */
  1884. filterChangedConfiguration: function (configsToSave) {
  1885. var changedConfigs = [];
  1886. configsToSave.forEach(function (configSite) {
  1887. var oldConfig = App.router.get('configurationController').getConfigsByTags([
  1888. {siteName: configSite.type, tagName: this.loadedClusterSiteToTagMap[configSite.type]}
  1889. ]);
  1890. oldConfig = oldConfig[0] || {};
  1891. var oldProperties = oldConfig.properties || {};
  1892. var oldAttributes = oldConfig["properties_attributes"] || {};
  1893. var newProperties = configSite.properties || {};
  1894. var newAttributes = configSite["properties_attributes"] || {};
  1895. if (this.isAttributesChanged(oldAttributes, newAttributes) || this.isConfigChanged(oldProperties, newProperties)) {
  1896. changedConfigs.push(configSite);
  1897. }
  1898. }, this);
  1899. return changedConfigs;
  1900. },
  1901. /**
  1902. * Compares the loaded config values with the saving config values.
  1903. * @param {Object} loadedConfig -
  1904. * loadedConfig: {
  1905. * configName1: "configValue1",
  1906. * configName2: "configValue2"
  1907. * }
  1908. * @param {Object} savingConfig
  1909. * savingConfig: {
  1910. * configName1: "configValue1",
  1911. * configName2: "configValue2"
  1912. * }
  1913. * @returns {boolean}
  1914. * @method isConfigChanged
  1915. */
  1916. isConfigChanged: function (loadedConfig, savingConfig) {
  1917. if (loadedConfig != null && savingConfig != null) {
  1918. var seenLoadKeys = [];
  1919. for (var loadKey in loadedConfig) {
  1920. if (!loadedConfig.hasOwnProperty(loadKey)) continue;
  1921. seenLoadKeys.push(loadKey);
  1922. var loadValue = loadedConfig[loadKey];
  1923. var saveValue = savingConfig[loadKey];
  1924. if ("boolean" == typeof(saveValue)) {
  1925. saveValue = saveValue.toString();
  1926. }
  1927. if (saveValue == null) {
  1928. saveValue = "null";
  1929. }
  1930. if (loadValue !== saveValue) {
  1931. return true;
  1932. }
  1933. }
  1934. for (var saveKey in savingConfig) {
  1935. if (seenLoadKeys.indexOf(saveKey) < 0) {
  1936. return true;
  1937. }
  1938. }
  1939. }
  1940. return false;
  1941. },
  1942. /**
  1943. * Compares the loaded config properties attributes with the saving config properties attributes.
  1944. * @param {Object} oldAttributes -
  1945. * oldAttributes: {
  1946. * supports: {
  1947. * final: {
  1948. * "configValue1" : "true",
  1949. * "configValue2" : "true"
  1950. * }
  1951. * }
  1952. * }
  1953. * @param {Object} newAttributes
  1954. * newAttributes: {
  1955. * supports: {
  1956. * final: {
  1957. * "configValue1" : "true",
  1958. * "configValue2" : "true"
  1959. * }
  1960. * }
  1961. * }
  1962. * @returns {boolean}
  1963. * @method isConfigChanged
  1964. */
  1965. isAttributesChanged: function (oldAttributes, newAttributes) {
  1966. oldAttributes = oldAttributes.final || {};
  1967. newAttributes = newAttributes.final || {};
  1968. var key;
  1969. for (key in oldAttributes) {
  1970. if (oldAttributes.hasOwnProperty(key)
  1971. && (!newAttributes.hasOwnProperty(key) || newAttributes[key] !== oldAttributes[key])) {
  1972. return true;
  1973. }
  1974. }
  1975. for (key in newAttributes) {
  1976. if (newAttributes.hasOwnProperty(key)
  1977. && (!oldAttributes.hasOwnProperty(key) || newAttributes[key] !== oldAttributes[key])) {
  1978. return true;
  1979. }
  1980. }
  1981. return false;
  1982. },
  1983. /**
  1984. * Saves configuration of set of sites. The provided data
  1985. * contains the site name and tag to be used.
  1986. * @param {Object} sites
  1987. * @method doPUTClusterConfigurationSites
  1988. */
  1989. doPUTClusterConfigurationSites: function (sites) {
  1990. App.ajax.send({
  1991. name: 'common.service.configurations',
  1992. sender: this,
  1993. data: {
  1994. desired_config: sites
  1995. },
  1996. success: 'doPUTClusterConfigurationSiteSuccessCallback',
  1997. error: 'doPUTClusterConfigurationSiteErrorCallback'
  1998. });
  1999. },
  2000. doPUTClusterConfigurationSiteSuccessCallback: function () {
  2001. this.onDoPUTClusterConfigurations();
  2002. },
  2003. doPUTClusterConfigurationSiteErrorCallback: function () {
  2004. this.set('saveConfigsFlag', false);
  2005. this.doPUTClusterConfigurationSiteSuccessCallback();
  2006. },
  2007. /**
  2008. * add newTagName property to each config in serviceConfigs
  2009. * @param serviceConfigs
  2010. */
  2011. setNewTagNames: function (serviceConfigs) {
  2012. var time = (new Date).getTime();
  2013. serviceConfigs.forEach(function (_serviceConfigs) {
  2014. _serviceConfigs.newTagName = 'version' + time;
  2015. }, this);
  2016. },
  2017. /**
  2018. * Save "final" attribute for properties
  2019. * @param {Array} properties - array of properties
  2020. * @returns {Object|null}
  2021. * */
  2022. getConfigAttributes: function(properties) {
  2023. var attributes = {
  2024. final: {}
  2025. };
  2026. var finalAttributes = attributes.final;
  2027. var hasAttributes = false;
  2028. properties.forEach(function (property) {
  2029. if (property.isRequiredByAgent !== false && property.isFinal) {
  2030. hasAttributes = true;
  2031. finalAttributes[property.name] = "true";
  2032. }
  2033. });
  2034. if (hasAttributes) {
  2035. return attributes;
  2036. }
  2037. return null;
  2038. },
  2039. /**
  2040. * create core site object
  2041. * @param tagName
  2042. * @return {{"type": String, "tag": String, "properties": Object}}
  2043. * @method createCoreSiteObj
  2044. */
  2045. createCoreSiteObj: function (tagName) {
  2046. var coreSiteObj = this.get('uiConfigs').filterProperty('filename', 'core-site.xml');
  2047. var coreSiteProperties = {};
  2048. coreSiteObj.forEach(function (_coreSiteObj) {
  2049. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  2050. //this.recordHostOverride(_coreSiteObj, 'core-site', tagName, this);
  2051. }, this);
  2052. var result = {"type": "core-site", "tag": tagName, "properties": coreSiteProperties};
  2053. var attributes = this.getConfigAttributes(coreSiteObj);
  2054. if (attributes) {
  2055. result['properties_attributes'] = attributes;
  2056. }
  2057. return result;
  2058. },
  2059. /**
  2060. * create site object
  2061. * @param siteName
  2062. * @param tagName
  2063. * @param siteObj
  2064. * @return {Object}
  2065. */
  2066. createSiteObj: function (siteName, tagName, siteObj) {
  2067. var heapsizeException = this.get('heapsizeException');
  2068. var heapsizeRegExp = this.get('heapsizeRegExp');
  2069. var siteProperties = {};
  2070. siteObj.forEach(function (_siteObj) {
  2071. var value = _siteObj.value;
  2072. if (_siteObj.isRequiredByAgent == false) return;
  2073. // site object name follow the format *permsize/*heapsize and the value NOT ends with "m"
  2074. if (heapsizeRegExp.test(_siteObj.name) && !heapsizeException.contains(_siteObj.name) && !(_siteObj.value).endsWith("m")) {
  2075. value += "m";
  2076. }
  2077. siteProperties[_siteObj.name] = value;
  2078. switch (siteName) {
  2079. case 'falcon-startup.properties':
  2080. case 'falcon-runtime.properties':
  2081. case 'pig-properties':
  2082. siteProperties[_siteObj.name] = value;
  2083. break;
  2084. default:
  2085. siteProperties[_siteObj.name] = this.setServerConfigValue(_siteObj.name, value);
  2086. }
  2087. }, this);
  2088. var result = {"type": siteName, "tag": tagName, "properties": siteProperties};
  2089. var attributes = this.getConfigAttributes(siteObj);
  2090. if (attributes) {
  2091. result['properties_attributes'] = attributes;
  2092. }
  2093. return result;
  2094. },
  2095. /**
  2096. * This method will be moved to config's decorators class.
  2097. *
  2098. * For now, provide handling for special properties that need
  2099. * be specified in special format required for server.
  2100. *
  2101. * @param configName {String} - name of config property
  2102. * @param value {Mixed} - value of config property
  2103. *
  2104. * @return {String} - formated value
  2105. */
  2106. setServerConfigValue: function (configName, value) {
  2107. switch (configName) {
  2108. case 'storm.zookeeper.servers':
  2109. if( Object.prototype.toString.call( value ) === '[object Array]' ) {
  2110. return JSON.stringify(value).replace(/"/g, "'");
  2111. } else {
  2112. return value;
  2113. }
  2114. break;
  2115. default:
  2116. return value;
  2117. }
  2118. },
  2119. /**
  2120. * Array of Objects
  2121. * {
  2122. * hostProperty - hostName property name for current component
  2123. * componentName - master componentName
  2124. * serviceName - serviceName of component
  2125. * serviceUseThis - services that use hostname property of component(componentName)
  2126. * m(multiple) - true if can be more than one components installed on cluster
  2127. * }
  2128. */
  2129. hostComponentsmapping: [
  2130. {
  2131. hostProperty: 'snamenode_host',
  2132. componentName: 'SECONDARY_NAMENODE',
  2133. serviceName: 'HDFS',
  2134. serviceUseThis: []
  2135. },
  2136. {
  2137. hostProperty: 'jobtracker_host',
  2138. componentName: 'JOBTRACKER',
  2139. serviceName: 'MAPREDUCE',
  2140. serviceUseThis: []
  2141. },
  2142. {
  2143. hostProperty: 'jobtracker_host',
  2144. componentName: 'JOBTRACKER',
  2145. serviceName: 'MAPREDUCE2',
  2146. serviceUseThis: []
  2147. },
  2148. {
  2149. hostProperty: 'hs_host',
  2150. componentName: 'HISTORYSERVER',
  2151. serviceName: 'MAPREDUCE2',
  2152. serviceUseThis: ['YARN']
  2153. },
  2154. {
  2155. hostProperty: 'hs_host',
  2156. componentName: 'HISTORYSERVER',
  2157. serviceName: 'MAPREDUCE',
  2158. serviceUseThis: []
  2159. },
  2160. {
  2161. hostProperty: 'ats_host',
  2162. componentName: 'APP_TIMELINE_SERVER',
  2163. serviceName: 'YARN',
  2164. serviceUseThis: []
  2165. },
  2166. {
  2167. hostProperty: 'rm_host',
  2168. componentName: 'RESOURCEMANAGER',
  2169. serviceName: 'YARN',
  2170. serviceUseThis: []
  2171. },
  2172. {
  2173. hostProperty: 'hivemetastore_host',
  2174. componentName: 'HIVE_SERVER',
  2175. serviceName: 'HIVE',
  2176. serviceUseThis: ['HIVE']
  2177. },
  2178. {
  2179. hostProperty: 'oozieserver_host',
  2180. componentName: 'OOZIE_SERVER',
  2181. serviceName: 'OOZIE',
  2182. serviceUseThis: []
  2183. },
  2184. {
  2185. hostProperty: 'hbasemaster_host',
  2186. componentName: 'HBASE_MASTER',
  2187. serviceName: 'HBASE',
  2188. serviceUseThis: [],
  2189. m: true
  2190. },
  2191. {
  2192. hostProperty: 'webhcatserver_host',
  2193. componentName: 'WEBHCAT_SERVER',
  2194. serviceName: 'HIVE',
  2195. serviceUseThis: [],
  2196. m: true
  2197. },
  2198. {
  2199. hostProperty: 'zookeeperserver_hosts',
  2200. componentName: 'ZOOKEEPER_SERVER',
  2201. serviceName: 'ZOOKEEPER',
  2202. serviceUseThis: ['HBASE', 'HIVE'],
  2203. m: true
  2204. },
  2205. {
  2206. hostProperty: 'stormuiserver_host',
  2207. componentName: 'STORM_UI_SERVER',
  2208. serviceName: 'STORM',
  2209. serviceUseThis: []
  2210. },
  2211. {
  2212. hostProperty: 'drpcserver_host',
  2213. componentName: 'DRPC_SERVER',
  2214. serviceName: 'STORM',
  2215. serviceUseThis: []
  2216. },
  2217. {
  2218. hostProperty: 'storm_rest_api_host',
  2219. componentName: 'STORM_REST_API',
  2220. serviceName: 'STORM',
  2221. serviceUseThis: []
  2222. },
  2223. {
  2224. hostProperty: 'supervisor_hosts',
  2225. componentName: 'SUPERVISOR',
  2226. serviceName: 'STORM',
  2227. serviceUseThis: [],
  2228. m: true
  2229. }
  2230. ],
  2231. /**
  2232. * Adds host name of master component to config;
  2233. * @method addHostNamesToGlobalConfig
  2234. */
  2235. addHostNamesToConfig: function () {
  2236. var serviceName = this.get('content.serviceName');
  2237. var configs = this.get('allConfigs');
  2238. //namenode_host is required to derive "fs.default.name" a property of core-site
  2239. try {
  2240. this.setHostForService('HDFS', 'NAMENODE', 'namenode_host', true);
  2241. } catch (err) {
  2242. console.log("No NameNode Host available. This is expected if you're using GLUSTERFS rather than HDFS.");
  2243. }
  2244. var hostProperties = this.get('hostComponentsmapping').filter(function (h) {
  2245. return h.serviceUseThis.contains(serviceName) || h.serviceName == serviceName;
  2246. });
  2247. hostProperties.forEach(function (h) {
  2248. this.setHostForService(h.serviceName, h.componentName, h.hostProperty, h.m);
  2249. }, this);
  2250. if (serviceName === 'HIVE') {
  2251. var hiveDb = configs.findProperty('name', 'hive_database').value;
  2252. if (['Existing MySQL Database', 'Existing Oracle Database', 'Existing PostgreSQL Database', 'Existing MSSQL Server database with integrated authentication', 'Existing MSSQL Server database with sql auth'].contains(hiveDb)) {
  2253. configs.findProperty('name', 'hive_hostname').isVisible = true;
  2254. }
  2255. }
  2256. if (serviceName === 'OOZIE') {
  2257. var oozieDb = configs.findProperty('name', 'oozie_database').value;
  2258. if (['Existing MySQL Database', 'Existing Oracle Database', 'Existing PostgreSQL Database', 'Existing MSSQL Server database with integrated authentication', 'Existing MSSQL Server database with sql auth'].contains(oozieDb)) {
  2259. configs.findProperty('name', 'oozie_hostname').isVisible = true;
  2260. }
  2261. }
  2262. if(App.get('isHadoopWindowsStack')) {
  2263. if (serviceName === 'HDFS') {
  2264. var sinkDB = configs.findProperty('name', 'sink_database').value;
  2265. if (['Existing MSSQL Server database with integrated authentication', 'Existing MSSQL Server database with sql auth'].contains(sinkDB)) {
  2266. configs.findProperty('name', 'sink.dbservername').isVisible = true;
  2267. }
  2268. }
  2269. }
  2270. },
  2271. /**
  2272. * set host name(s) property for component
  2273. * @param {String} serviceName - service name of component
  2274. * @param {String} componentName - component name whic host we want to know
  2275. * @param {String} hostProperty - name of host property for current component
  2276. * @param {Boolean} multiple - true if can be more than one component
  2277. * @method setHostForService
  2278. */
  2279. setHostForService: function (serviceName, componentName, hostProperty, multiple) {
  2280. var configs = this.get('allConfigs');
  2281. var serviceConfigs = this.get('serviceConfigs').findProperty('serviceName', serviceName).get('configs');
  2282. var hostConfig = serviceConfigs.findProperty('name', hostProperty);
  2283. if (hostConfig) {
  2284. hostConfig.defaultValue = this.getMasterComponentHostValue(componentName, multiple);
  2285. configs.push(hostConfig);
  2286. }
  2287. },
  2288. /**
  2289. * get hostName of component
  2290. * @param {String} componentName
  2291. * @param {Boolean} multiple - true if can be more than one component installed on cluster
  2292. * @return {String|Array|Boolean} hostName|hostNames|false if missing component
  2293. * @method getMasterComponentHostValue
  2294. */
  2295. getMasterComponentHostValue: function (componentName, multiple) {
  2296. var components = this.get('content.hostComponents').filterProperty('componentName', componentName);
  2297. if (components.length > 0) {
  2298. return multiple ? components.mapProperty('hostName') : components[0].get('hostName');
  2299. }
  2300. return false;
  2301. },
  2302. /**
  2303. * Provides service component name and display-name information for
  2304. * the current selected service.
  2305. * @return {Em.Array} validComponents - array of valid components
  2306. * @method getCurrentServiceComponents
  2307. */
  2308. getCurrentServiceComponents: function () {
  2309. var components = this.get('content.hostComponents');
  2310. var validComponents = Ember.A([]);
  2311. var seenComponents = {};
  2312. components.forEach(function (component) {
  2313. var cn = component.get('componentName');
  2314. var cdn = component.get('displayName');
  2315. if (!seenComponents[cn]) {
  2316. validComponents.push(Ember.Object.create({
  2317. componentName: cn,
  2318. displayName: cdn,
  2319. selected: false
  2320. }));
  2321. seenComponents[cn] = cn;
  2322. }
  2323. });
  2324. return validComponents;
  2325. }.property('content'),
  2326. /**
  2327. * trigger loadStep
  2328. * @method loadStep
  2329. */
  2330. doCancel: function () {
  2331. Em.run.once(this, 'onConfigGroupChange');
  2332. },
  2333. /**
  2334. * trigger restartAllServiceHostComponents(batchUtils) if confirmed in popup
  2335. * @method restartAllStaleConfigComponents
  2336. * @return App.showConfirmationFeedBackPopup
  2337. */
  2338. restartAllStaleConfigComponents: function () {
  2339. var self = this;
  2340. var serviceDisplayName = this.get('content.displayName');
  2341. var bodyMessage = Em.Object.create({
  2342. confirmMsg: Em.I18n.t('services.service.restartAll.confirmMsg').format(serviceDisplayName),
  2343. confirmButton: Em.I18n.t('services.service.restartAll.confirmButton'),
  2344. additionalWarningMsg: this.get('content.passiveState') === 'OFF' ? Em.I18n.t('services.service.restartAll.warningMsg.turnOnMM').format(serviceDisplayName) : null
  2345. });
  2346. return App.showConfirmationFeedBackPopup(function (query) {
  2347. var selectedService = self.get('content.id');
  2348. batchUtils.restartAllServiceHostComponents(selectedService, true, query);
  2349. }, bodyMessage);
  2350. },
  2351. /**
  2352. * trigger launchHostComponentRollingRestart(batchUtils)
  2353. * @method rollingRestartStaleConfigSlaveComponents
  2354. */
  2355. rollingRestartStaleConfigSlaveComponents: function (componentName) {
  2356. batchUtils.launchHostComponentRollingRestart(componentName.context, this.get('content.displayName'), this.get('content.passiveState') === "ON", true);
  2357. },
  2358. /**
  2359. * trigger showItemsShouldBeRestarted popup with hosts that requires resetart
  2360. * @method showHostsShouldBeRestarted
  2361. */
  2362. showHostsShouldBeRestarted: function (restartRequiredHostsAndComponents) {
  2363. var hosts = [];
  2364. var rhc = this.get('content.restartRequiredHostsAndComponents') || restartRequiredHostsAndComponents;
  2365. for (var hostName in rhc) {
  2366. hosts.push(hostName);
  2367. }
  2368. var hostsText = hosts.length == 1 ? Em.I18n.t('common.host') : Em.I18n.t('common.hosts');
  2369. hosts = hosts.join(', ');
  2370. this.showItemsShouldBeRestarted(hosts, Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(hostsText));
  2371. },
  2372. /**
  2373. * trigger showItemsShouldBeRestarted popup with components that requires resetart
  2374. * @method showComponentsShouldBeRestarted
  2375. */
  2376. showComponentsShouldBeRestarted: function (restartRequiredHostsAndComponents) {
  2377. var rhc = this.get('content.restartRequiredHostsAndComponents') || restartRequiredHostsAndComponents;
  2378. var hostsComponets = [];
  2379. var componentsObject = {};
  2380. for (var hostName in rhc) {
  2381. rhc[hostName].forEach(function (hostComponent) {
  2382. hostsComponets.push(hostComponent);
  2383. if (componentsObject[hostComponent] != undefined) {
  2384. componentsObject[hostComponent]++;
  2385. } else {
  2386. componentsObject[hostComponent] = 1;
  2387. }
  2388. })
  2389. }
  2390. var componentsList = [];
  2391. for (var obj in componentsObject) {
  2392. var componentDisplayName = (componentsObject[obj] > 1) ? obj + 's' : obj;
  2393. componentsList.push(componentsObject[obj] + ' ' + componentDisplayName);
  2394. }
  2395. var componentsText = componentsList.length == 1 ? Em.I18n.t('common.component') : Em.I18n.t('common.components');
  2396. hostsComponets = componentsList.join(', ');
  2397. this.showItemsShouldBeRestarted(hostsComponets, Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(componentsText));
  2398. },
  2399. showItemsShouldBeRestarted: function (content, header) {
  2400. App.ModalPopup.show({
  2401. content: content,
  2402. header: header,
  2403. bodyClass: Em.View.extend({
  2404. templateName: require('templates/common/selectable_popup'),
  2405. textareaVisible: false,
  2406. textTrigger: function () {
  2407. this.set('textareaVisible', !this.get('textareaVisible'));
  2408. },
  2409. putContentToTextarea: function () {
  2410. var content = this.get('parentView.content');
  2411. if (this.get('textareaVisible')) {
  2412. var wrapper = $(".task-detail-log-maintext");
  2413. $('.task-detail-log-clipboard').html(content).width(wrapper.width()).height(wrapper.height());
  2414. Em.run.next(function () {
  2415. $('.task-detail-log-clipboard').select();
  2416. });
  2417. }
  2418. }.observes('textareaVisible')
  2419. }),
  2420. secondary: null
  2421. });
  2422. },
  2423. /**
  2424. * add new overridden property to config property object
  2425. * @param {object} serviceConfigProperty - config property object
  2426. * @method addOverrideProperty
  2427. */
  2428. addOverrideProperty: function (serviceConfigProperty) {
  2429. var overrides = serviceConfigProperty.get('overrides');
  2430. if (!overrides) {
  2431. overrides = [];
  2432. serviceConfigProperty.set('overrides', overrides);
  2433. }
  2434. // create new override with new value
  2435. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  2436. newSCP.set('value', '');
  2437. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  2438. newSCP.set('parentSCP', serviceConfigProperty);
  2439. newSCP.set('isEditable', true);
  2440. console.debug("createOverrideProperty(): Added:", newSCP, " to main-property:", serviceConfigProperty);
  2441. overrides.pushObject(newSCP);
  2442. },
  2443. /**
  2444. * trigger manageConfigurationGroups
  2445. * @method manageConfigurationGroup
  2446. */
  2447. manageConfigurationGroup: function () {
  2448. this.manageConfigurationGroups();
  2449. },
  2450. manageConfigurationGroups: function (controller) {
  2451. var serviceData = (controller && controller.get('selectedService')) || this.get('content');
  2452. var serviceName = serviceData.get('serviceName');
  2453. var displayName = serviceData.get('displayName');
  2454. App.router.get('manageConfigGroupsController').set('isInstaller', !!controller);
  2455. App.router.get('manageConfigGroupsController').set('serviceName', serviceName);
  2456. if (controller) {
  2457. App.router.get('manageConfigGroupsController').set('isAddService', controller.get('content.controllerName') == 'addServiceController');
  2458. }
  2459. return App.ModalPopup.show({
  2460. header: Em.I18n.t('services.service.config_groups_popup.header').format(displayName),
  2461. bodyClass: App.MainServiceManageConfigGroupView.extend({
  2462. serviceName: serviceName,
  2463. displayName: displayName,
  2464. controllerBinding: 'App.router.manageConfigGroupsController'
  2465. }),
  2466. classNames: ['sixty-percent-width-modal', 'manage-configuration-group-popup'],
  2467. primary: Em.I18n.t('common.save'),
  2468. onPrimary: function () {
  2469. var modifiedConfigGroups = this.get('subViewController.hostsModifiedConfigGroups');
  2470. // Save modified config-groups
  2471. if (!!controller) {
  2472. controller.set('selectedService.configGroups', App.router.get('manageConfigGroupsController.configGroups'));
  2473. controller.selectedServiceObserver();
  2474. if (controller.get('name') == "wizardStep7Controller") {
  2475. if (controller.get('selectedService.selected') === false && modifiedConfigGroups.toDelete.length > 0) {
  2476. controller.setGroupsToDelete(modifiedConfigGroups.toDelete);
  2477. }
  2478. App.config.persistWizardStep7ConfigGroups();
  2479. this.updateConfigGroupOnServicePage();
  2480. }
  2481. this.hide();
  2482. return;
  2483. }
  2484. console.log("manageConfigurationGroups(): Saving modified config-groups: ", modifiedConfigGroups);
  2485. var self = this;
  2486. var errors = [];
  2487. var deleteQueriesCounter = modifiedConfigGroups.toClearHosts.length + modifiedConfigGroups.toDelete.length;
  2488. var createQueriesCounter = modifiedConfigGroups.toSetHosts.length + modifiedConfigGroups.toCreate.length;
  2489. var deleteQueriesRun = false;
  2490. var createQueriesRun = false;
  2491. var runNextQuery = function () {
  2492. if (!deleteQueriesRun && deleteQueriesCounter > 0) {
  2493. deleteQueriesRun = true;
  2494. modifiedConfigGroups.toClearHosts.forEach(function (cg) {
  2495. App.config.clearConfigurationGroupHosts(cg, finishFunction, finishFunction);
  2496. }, this);
  2497. modifiedConfigGroups.toDelete.forEach(function (cg) {
  2498. App.config.deleteConfigGroup(cg, finishFunction, finishFunction);
  2499. }, this);
  2500. } else if (!createQueriesRun && deleteQueriesCounter < 1) {
  2501. createQueriesRun = true;
  2502. modifiedConfigGroups.toSetHosts.forEach(function (cg) {
  2503. App.config.updateConfigurationGroup(cg, finishFunction, finishFunction);
  2504. }, this);
  2505. modifiedConfigGroups.toCreate.forEach(function (cg) {
  2506. App.config.postNewConfigurationGroup(cg, finishFunction);
  2507. }, this);
  2508. }
  2509. };
  2510. var finishFunction = function (xhr, text, errorThrown) {
  2511. if (xhr && errorThrown) {
  2512. var error = xhr.status + "(" + errorThrown + ") ";
  2513. try {
  2514. var json = $.parseJSON(xhr.responseText);
  2515. error += json.message;
  2516. } catch (err) {
  2517. }
  2518. console.error('Error updating Config Group:', error);
  2519. errors.push(error);
  2520. }
  2521. if (createQueriesRun) {
  2522. createQueriesCounter--;
  2523. } else {
  2524. deleteQueriesCounter--;
  2525. }
  2526. if (deleteQueriesCounter + createQueriesCounter < 1) {
  2527. if (errors.length > 0) {
  2528. console.log(errors);
  2529. self.get('subViewController').set('errorMessage', errors.join(". "));
  2530. } else {
  2531. self.updateConfigGroupOnServicePage();
  2532. self.hide();
  2533. }
  2534. } else {
  2535. runNextQuery();
  2536. }
  2537. };
  2538. runNextQuery();
  2539. },
  2540. onSecondary: function () {
  2541. this.hide();
  2542. },
  2543. onClose: function () {
  2544. this.hide();
  2545. },
  2546. subViewController: function () {
  2547. return App.router.get('manageConfigGroupsController');
  2548. }.property('App.router.manageConfigGroupsController'),
  2549. updateConfigGroupOnServicePage: function () {
  2550. var subViewController = this.get('subViewController');
  2551. var selectedConfigGroup = subViewController.get('selectedConfigGroup');
  2552. var managedConfigGroups = subViewController.get('configGroups');
  2553. if (!controller) {
  2554. controller = App.router.get('mainServiceInfoConfigsController');
  2555. controller.set('configGroups', managedConfigGroups);
  2556. } else {
  2557. controller.set('selectedService.configGroups', managedConfigGroups);
  2558. }
  2559. var selectEventObject = {};
  2560. //check whether selectedConfigGroup exists
  2561. if (selectedConfigGroup && controller.get('configGroups').someProperty('name', selectedConfigGroup.get('name'))) {
  2562. selectEventObject.context = selectedConfigGroup;
  2563. } else {
  2564. selectEventObject.context = managedConfigGroups.findProperty('isDefault', true);
  2565. }
  2566. controller.selectConfigGroup(selectEventObject);
  2567. },
  2568. updateButtons: function () {
  2569. var modified = this.get('subViewController.isHostsModified');
  2570. this.set('disablePrimary', !modified);
  2571. }.observes('subViewController.isHostsModified'),
  2572. secondary: Em.I18n.t('common.cancel'),
  2573. didInsertElement: Em.K
  2574. });
  2575. },
  2576. /**
  2577. * If user changes cfg group if some configs was changed popup with propose to save changes must be shown
  2578. * @param {object} event - triggered event for selecting another config-group
  2579. * @method selectConfigGroup
  2580. */
  2581. selectConfigGroup: function (event) {
  2582. var self = this;
  2583. function callback() {
  2584. self.doSelectConfigGroup(event);
  2585. }
  2586. if (!this.get('isInit')) {
  2587. if (this.hasUnsavedChanges()) {
  2588. this.showSavePopup(null, callback);
  2589. return;
  2590. }
  2591. }
  2592. callback();
  2593. },
  2594. /**
  2595. * switch view to selected group
  2596. * @param event
  2597. * @method selectConfigGroup
  2598. */
  2599. doSelectConfigGroup: function (event) {
  2600. //clean when switch config group
  2601. this.loadedGroupToOverrideSiteToTagMap = {};
  2602. var configGroupVersions = App.ServiceConfigVersion.find().filterProperty('groupId', event.context.get('id'));
  2603. //check whether config group has config versions
  2604. if (configGroupVersions.length > 0) {
  2605. this.loadSelectedVersion(configGroupVersions.findProperty('isCurrent').get('version'), event.context);
  2606. } else {
  2607. this.loadSelectedVersion(null, event.context);
  2608. }
  2609. },
  2610. /**
  2611. * Are some unsaved changes available
  2612. * @returns {boolean}
  2613. */
  2614. hasUnsavedChanges: function () {
  2615. return this.get('hash') != this.getHash();
  2616. },
  2617. /**
  2618. * If some configs are changed and user navigates away or select another config-group, show this popup with propose to save changes
  2619. * @param {String} path
  2620. * @param {object} callback - callback with action to change configs view(change group or version)
  2621. * @method showSavePopup
  2622. */
  2623. showSavePopup: function (path, callback) {
  2624. var self = this;
  2625. return App.ModalPopup.show({
  2626. header: Em.I18n.t('common.warning'),
  2627. bodyClass: Em.View.extend({
  2628. templateName: require('templates/common/configs/save_configuration'),
  2629. showSaveWarning: true,
  2630. notesArea: Em.TextArea.extend({
  2631. classNames: ['full-width'],
  2632. placeholder: Em.I18n.t('dashboard.configHistory.info-bar.save.popup.placeholder'),
  2633. onChangeValue: function() {
  2634. this.get('parentView.parentView').set('serviceConfigNote', this.get('value'));
  2635. }.observes('value')
  2636. })
  2637. }),
  2638. footerClass: Ember.View.extend({
  2639. templateName: require('templates/main/service/info/save_popup_footer')
  2640. }),
  2641. primary: Em.I18n.t('common.save'),
  2642. secondary: Em.I18n.t('common.cancel'),
  2643. onSave: function () {
  2644. self.set('serviceConfigVersionNote', this.get('serviceConfigNote'));
  2645. self.restartServicePopup();
  2646. this.hide();
  2647. },
  2648. onDiscard: function () {
  2649. self.set('preSelectedConfigVersion', null);
  2650. if (path) {
  2651. self.set('forceTransition', true);
  2652. App.router.route(path);
  2653. } else if (callback) {
  2654. // Prevent multiple popups
  2655. self.set('hash', self.getHash());
  2656. callback();
  2657. }
  2658. this.hide();
  2659. },
  2660. onCancel: function () {
  2661. this.hide();
  2662. }
  2663. });
  2664. }
  2665. });