123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var App = require('app');
- var stringUtils = require('utils/string_utils');
- var serviceComponents = {};
- var configGroupsByTag = [];
- var globalPropertyToServicesMap = null;
- App.config = Em.Object.create({
- preDefinedServiceConfigs: function(){
- var configs = this.get('preDefinedConfigProperties');
- var services = [];
- require('data/service_configs').forEach(function(service){
- service.configs = configs.filterProperty('serviceName', service.serviceName);
- services.push(service);
- });
- return services;
- }.property('preDefinedConfigProperties'),
- configMapping: function() {
- if (App.get('isHadoop2Stack')) {
- return require('data/HDP2/config_mapping');
- }
- return require('data/config_mapping');
- }.property('App.isHadoop2Stack'),
- preDefinedConfigProperties: function() {
- if (App.get('isHadoop2Stack')) {
- return require('data/HDP2/config_properties').configProperties;
- }
- return require('data/config_properties').configProperties;
- }.property('App.isHadoop2Stack'),
- preDefinedCustomConfigs: function () {
- if (App.get('isHadoop2Stack')) {
- return require('data/HDP2/custom_configs');
- }
- return require('data/custom_configs');
- }.property('App.isHadoop2Stack'),
- //categories which contain custom configs
- categoriesWithCustom: ['CapacityScheduler'],
- //configs with these filenames go to appropriate category not in Advanced
- customFileNames: function() {
- if (App.supports.capacitySchedulerUi) {
- if(App.get('isHadoop2Stack')){
- return ['capacity-scheduler.xml'];
- }
- return ['capacity-scheduler.xml', 'mapred-queue-acls.xml'];
- } else {
- return [];
- }
- }.property('App.isHadoop2Stack'),
- /**
- * Cache of loaded configurations. This is useful in not loading
- * same configuration multiple times. It is populated in multiple
- * places.
- *
- * Example:
- * {
- * 'global_version1': {...},
- * 'global_version2': {...},
- * 'hdfs-site_version3': {...},
- * }
- */
- loadedConfigurationsCache: {},
- /**
- * Array of global "service/desired_tag/actual_tag" strings which
- * indicate different configurations. We cache these so that
- * we dont have to recalculate if two tags are difference.
- */
- differentGlobalTagsCache:[],
-
- identifyCategory: function(config){
- var category = null;
- var serviceConfigMetaData = this.get('preDefinedServiceConfigs').findProperty('serviceName', config.serviceName);
- if (serviceConfigMetaData) {
- serviceConfigMetaData.configCategories.forEach(function (_category) {
- if (_category.siteFileNames && Array.isArray(_category.siteFileNames) && _category.siteFileNames.contains(config.filename)) {
- category = _category;
- }
- });
- category = (category == null) ? serviceConfigMetaData.configCategories.findProperty('siteFileName', config.filename) : category;
- }
- return category;
- },
- /**
- * additional handling for special properties such as
- * checkbox and digital which values with 'm' at the end
- * @param config
- */
- handleSpecialProperties: function(config){
- if (config.displayType === 'int' && /\d+m$/.test(config.value)) {
- config.value = config.value.slice(0, config.value.length - 1);
- config.defaultValue = config.value;
- }
- if (config.displayType === 'checkbox') {
- config.value = (config.value === 'true') ? config.defaultValue = true : config.defaultValue = false;
- }
- },
- /**
- * calculate config properties:
- * category, filename, isRequired, isUserProperty
- * @param config
- * @param isAdvanced
- * @param advancedConfigs
- */
- calculateConfigProperties: function(config, isAdvanced, advancedConfigs){
- if (!isAdvanced || this.get('customFileNames').contains(config.filename)) {
- var categoryMetaData = this.identifyCategory(config);
- if (categoryMetaData != null) {
- config.category = categoryMetaData.get('name');
- if(!isAdvanced) config.isUserProperty = true;
- }
- } else {
- config.category = 'Advanced';
- config.filename = isAdvanced && advancedConfigs.findProperty('name', config.name).filename;
- config.isRequired = true;
- }
- },
- capacitySchedulerFilter: function () {
- var yarnRegex = /^yarn\.scheduler\.capacity\.root\.(?!unfunded)([a-z]([\_\-a-z0-9]{0,50}))\.(acl_administer_jobs|acl_submit_jobs|state|user-limit-factor|maximum-capacity|capacity)$/i;
- var self = this;
- if(App.get('isHadoop2Stack')){
- return function (_config) {
- return (yarnRegex.test(_config.name));
- }
- } else {
- return function (_config) {
- return (_config.name.indexOf('mapred.capacity-scheduler.queue.') !== -1) ||
- (/^mapred\.queue\.[a-z]([\_\-a-z0-9]{0,50})\.(acl-administer-jobs|acl-submit-job)$/i.test(_config.name));
- }
- }
- }.property('App.isHadoop2Stack'),
- /**
- * return:
- * configs,
- * globalConfigs,
- * mappingConfigs
- *
- * @param configGroups
- * @param advancedConfigs
- * @param tags
- * @param serviceName
- * @return {object}
- */
- mergePreDefinedWithLoaded: function (configGroups, advancedConfigs, tags, serviceName) {
- var configs = [];
- var globalConfigs = [];
- var preDefinedConfigs = this.get('preDefinedConfigProperties');
- var mappingConfigs = [];
- tags.forEach(function (_tag) {
- var isAdvanced = null;
- var properties = configGroups.filter(function (serviceConfigProperties) {
- return _tag.tagName === serviceConfigProperties.tag && _tag.siteName === serviceConfigProperties.type;
- });
- properties = (properties.length) ? properties.objectAt(0).properties : {};
- for (var index in properties) {
- var configsPropertyDef = preDefinedConfigs.findProperty('name', index) || null;
- var serviceConfigObj = App.ServiceConfig.create({
- name: index,
- value: properties[index],
- defaultValue: properties[index],
- filename: _tag.siteName + ".xml",
- isUserProperty: false,
- isOverridable: true,
- serviceName: serviceName,
- belongsToService: []
- });
- if (configsPropertyDef) {
- serviceConfigObj.displayType = configsPropertyDef.displayType;
- serviceConfigObj.isRequired = (configsPropertyDef.isRequired !== undefined) ? configsPropertyDef.isRequired : true;
- serviceConfigObj.isReconfigurable = (configsPropertyDef.isReconfigurable !== undefined) ? configsPropertyDef.isReconfigurable : true;
- serviceConfigObj.isVisible = (configsPropertyDef.isVisible !== undefined) ? configsPropertyDef.isVisible : true;
- serviceConfigObj.unit = (configsPropertyDef.unit !== undefined) ? configsPropertyDef.unit : undefined;
- serviceConfigObj.description = (configsPropertyDef.description !== undefined) ? configsPropertyDef.description : undefined;
- serviceConfigObj.isOverridable = configsPropertyDef.isOverridable === undefined ? true : configsPropertyDef.isOverridable;
- serviceConfigObj.serviceName = configsPropertyDef ? configsPropertyDef.serviceName : null;
- serviceConfigObj.index = configsPropertyDef.index;
- serviceConfigObj.isSecureConfig = configsPropertyDef.isSecureConfig === undefined ? false : configsPropertyDef.isSecureConfig;
- serviceConfigObj.belongsToService = configsPropertyDef.belongsToService;
- }
- // MAPREDUCE contains core-site properties but doesn't show them
- if(serviceConfigObj.serviceName === 'MAPREDUCE' && serviceConfigObj.filename === 'core-site.xml'){
- serviceConfigObj.isVisible = false;
- }
- if (_tag.siteName === 'global') {
- if (configsPropertyDef) {
- this.handleSpecialProperties(serviceConfigObj);
- } else {
- serviceConfigObj.isVisible = false; // if the global property is not defined on ui metadata config_properties.js then it shouldn't be a part of errorCount
- }
- serviceConfigObj.id = 'puppet var';
- serviceConfigObj.displayName = configsPropertyDef ? configsPropertyDef.displayName : null;
- serviceConfigObj.category = configsPropertyDef ? configsPropertyDef.category : null;
- serviceConfigObj.options = configsPropertyDef ? configsPropertyDef.options : null;
- globalConfigs.push(serviceConfigObj);
- } else if (!this.get('configMapping').computed().someProperty('name', index)) {
- isAdvanced = advancedConfigs.someProperty('name', index);
- serviceConfigObj.id = 'site property';
- serviceConfigObj.displayType = stringUtils.isSingleLine(serviceConfigObj.value) ? 'advanced' : 'multiLine';
- serviceConfigObj.displayName = configsPropertyDef ? configsPropertyDef.displayName : index;
- this.calculateConfigProperties(serviceConfigObj, isAdvanced, advancedConfigs);
- configs.push(serviceConfigObj);
- } else {
- mappingConfigs.push(serviceConfigObj);
- }
- }
- }, this);
- return {
- configs: configs,
- globalConfigs: globalConfigs,
- mappingConfigs: mappingConfigs
- }
- },
- /**
- * merge stored configs with pre-defined
- * @param storedConfigs
- * @param advancedConfigs
- * @return {*}
- */
- mergePreDefinedWithStored: function (storedConfigs, advancedConfigs) {
- var mergedConfigs = [];
- var preDefinedConfigs = $.extend(true, [], this.get('preDefinedConfigProperties'));
- var preDefinedNames = [];
- var storedNames = [];
- var names = [];
- var categoryMetaData = null;
- storedConfigs = (storedConfigs) ? storedConfigs : [];
- preDefinedNames = this.get('preDefinedConfigProperties').mapProperty('name');
- storedNames = storedConfigs.mapProperty('name');
- names = preDefinedNames.concat(storedNames).uniq();
- names.forEach(function (name) {
- var stored = storedConfigs.findProperty('name', name);
- var preDefined = preDefinedConfigs.findProperty('name', name);
- var configData = {};
- var isAdvanced = advancedConfigs.someProperty('name', name);
- if (preDefined && stored) {
- configData = preDefined;
- configData.value = stored.value;
- configData.defaultValue = stored.defaultValue;
- configData.overrides = stored.overrides;
- } else if (!preDefined && stored) {
- configData = {
- id: stored.id,
- name: stored.name,
- displayName: stored.name,
- serviceName: stored.serviceName,
- value: stored.value,
- defaultValue: stored.defaultValue,
- displayType: stringUtils.isSingleLine(stored.value) ? 'advanced' : 'multiLine',
- filename: stored.filename,
- category: 'Advanced',
- isUserProperty: stored.isUserProperty === true,
- isOverridable: true,
- overrides: stored.overrides,
- isRequired: true
- };
- this.calculateConfigProperties(configData, isAdvanced, advancedConfigs);
- } else if (preDefined && !stored) {
- configData = preDefined;
- if (isAdvanced) {
- configData.filename = advancedConfigs.findProperty('name', configData.name).filename;
- }
- }
- mergedConfigs.push(configData);
- }, this);
- return mergedConfigs;
- },
- /**
- * look over advanced configs and add missing configs to serviceConfigs
- * filter fetched configs by service if passed
- * @param serviceConfigs
- * @param advancedConfigs
- * @param serviceName
- */
- addAdvancedConfigs: function (serviceConfigs, advancedConfigs, serviceName) {
- var configsToVerifying = (serviceName) ? serviceConfigs.filterProperty('serviceName', serviceName) : serviceConfigs;
- advancedConfigs.forEach(function (_config) {
- var configCategory = 'Advanced';
- var categoryMetaData = null;
- if (_config) {
- if (this.get('configMapping').computed().someProperty('name', _config.name)) {
- } else if (!(configsToVerifying.someProperty('name', _config.name))) {
- if(this.get('customFileNames').contains(_config.filename)){
- categoryMetaData = this.identifyCategory(_config);
- if (categoryMetaData != null) {
- configCategory = categoryMetaData.get('name');
- }
- }
- _config.id = "site property";
- _config.category = configCategory;
- _config.displayName = _config.name;
- _config.defaultValue = _config.value;
- // make all advanced configs optional and populated by default
- /*
- * if (/\${.*}/.test(_config.value) || (service.serviceName !==
- * 'OOZIE' && service.serviceName !== 'HBASE')) { _config.isRequired =
- * false; _config.value = ''; } else if
- * (/^\s+$/.test(_config.value)) { _config.isRequired = false; }
- */
- _config.isRequired = true;
- _config.displayType = stringUtils.isSingleLine(_config.value) ? 'advanced' : 'multiLine';
- serviceConfigs.push(_config);
- }
- }
- }, this);
- },
- /**
- * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
- */
- addCustomConfigs: function (configs) {
- var preDefinedCustomConfigs = $.extend(true, [], this.get('preDefinedCustomConfigs'));
- var stored = configs.filter(function (_config) {
- return this.get('categoriesWithCustom').contains(_config.category);
- }, this);
- if(App.supports.capacitySchedulerUi){
- var queueProperties = stored.filter(this.get('capacitySchedulerFilter'));
- if (queueProperties.length) {
- queueProperties.setEach('isQueue', true);
- }
- }
- },
- miscConfigVisibleProperty: function (configs, serviceToShow) {
- configs.forEach(function(item) {
- item.set("isVisible", item.belongsToService.some(function(cur){return serviceToShow.contains(cur)}));
- });
- return configs;
- },
- /**
- * render configs, distribute them by service
- * and wrap each in ServiceConfigProperty object
- * @param configs
- * @param allInstalledServiceNames
- * @param selectedServiceNames
- * @return {Array}
- */
- renderConfigs: function (configs, storedConfigs, allInstalledServiceNames, selectedServiceNames) {
- var renderedServiceConfigs = [];
- var localDB = {
- hosts: App.db.getHosts(),
- masterComponentHosts: App.db.getMasterComponentHosts(),
- slaveComponentHosts: App.db.getSlaveComponentHosts()
- };
- var services = [];
- this.get('preDefinedServiceConfigs').forEach(function (serviceConfig) {
- if (allInstalledServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
- console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
- if (selectedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
- serviceConfig.showConfig = true;
- }
- services.push(serviceConfig);
- }
- });
- services.forEach(function (service) {
- var serviceConfig = {};
- var configsByService = [];
- var serviceConfigs = configs.filterProperty('serviceName', service.serviceName);
- serviceConfigs.forEach(function (_config) {
- var serviceConfigProperty = {};
- _config.isOverridable = (_config.isOverridable === undefined) ? true : _config.isOverridable;
- serviceConfigProperty = App.ServiceConfigProperty.create(_config);
- this.updateHostOverrides(serviceConfigProperty, _config);
- if (!storedConfigs) {
- serviceConfigProperty.initialValue(localDB);
- }
- this.tweakDynamicDefaults(localDB, serviceConfigProperty, _config);
- serviceConfigProperty.validate();
- configsByService.pushObject(serviceConfigProperty);
- }, this);
- serviceConfig = this.createServiceConfig(service.serviceName);
- serviceConfig.set('showConfig', service.showConfig);
- serviceConfig.set('configs', configsByService);
- renderedServiceConfigs.push(serviceConfig);
- }, this);
- return renderedServiceConfigs;
- },
- /**
- Takes care of the "dynamic defaults" for the HCFS configs. Sets
- some of the config defaults to previously user-entered data.
- **/
- tweakDynamicDefaults: function (localDB, serviceConfigProperty, config) {
- console.log("Step7: Tweaking Dynamic defaults");
- var firstHost = null;
- for(var host in localDB.hosts) {
- firstHost = host;
- break;
- }
- try {
- if (typeof(config == "string") && config.defaultValue.indexOf("{firstHost}") >= 0) {
- serviceConfigProperty.set('value', serviceConfigProperty.value.replace(new RegExp("{firstHost}"), firstHost));
- serviceConfigProperty.set('defaultValue', serviceConfigProperty.defaultValue.replace(new RegExp("{firstHost}"), firstHost));
- }
- } catch (err) {
- // Nothing to worry about here, most likely trying indexOf on a non-string
- }
- },
- /**
- * create new child configs from overrides, attach them to parent config
- * override - value of config, related to particular host(s)
- * @param configProperty
- * @param storedConfigProperty
- */
- updateHostOverrides: function (configProperty, storedConfigProperty) {
- if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
- var overrides = [];
- storedConfigProperty.overrides.forEach(function (overrideEntry) {
- // create new override with new value
- var newSCP = App.ServiceConfigProperty.create(configProperty);
- newSCP.set('value', overrideEntry.value);
- newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
- newSCP.set('parentSCP', configProperty);
- var hostsArray = Ember.A([]);
- overrideEntry.hosts.forEach(function (host) {
- hostsArray.push(host);
- });
- newSCP.set('selectedHostOptions', hostsArray);
- overrides.pushObject(newSCP);
- });
- configProperty.set('overrides', overrides);
- }
- },
- /**
- * create new ServiceConfig object by service name
- * @param serviceName
- */
- createServiceConfig: function (serviceName) {
- var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName);
- var serviceConfig = App.ServiceConfig.create({
- filename: preDefinedServiceConfig.filename,
- serviceName: preDefinedServiceConfig.serviceName,
- displayName: preDefinedServiceConfig.displayName,
- configCategories: preDefinedServiceConfig.configCategories,
- configs: []
- });
- serviceConfig.configCategories.filterProperty('isCustomView', true).forEach(function (category) {
- switch (category.name) {
- case 'CapacityScheduler':
- if(App.supports.capacitySchedulerUi){
- category.set('customView', App.ServiceConfigCapacityScheduler);
- } else {
- category.set('isCustomView', false);
- }
- break;
- }
- }, this);
- return serviceConfig;
- },
- /**
- * GETs all cluster level sites in one call.
- *
- * @return Array of all site configs
- */
- loadConfigsByTags: function (tags) {
- var urlParams = [];
- tags.forEach(function (_tag) {
- urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
- });
- var params = urlParams.join('|');
- App.ajax.send({
- name: 'config.on_site',
- sender: this,
- data: {
- params: params
- },
- success: 'loadConfigsByTagsSuccess'
- });
- return configGroupsByTag;
- },
- loadConfigsByTagsSuccess: function (data) {
- if (data.items) {
- configGroupsByTag = [];
- data.items.forEach(function (item) {
- this.loadedConfigurationsCache[item.type + "_" + item.tag] = item.properties;
- configGroupsByTag.push(item);
- }, this);
- }
- },
- /**
- * Generate serviceProperties save it to localDB
- * called form stepController step6WizardController
- *
- * @param serviceName
- * @return {*}
- */
- loadAdvancedConfig: function (serviceName) {
- App.ajax.send({
- name: 'config.advanced',
- sender: this,
- data: {
- serviceName: serviceName,
- stack2VersionUrl: App.get('stack2VersionURL'),
- stackVersion: App.get('currentStackVersionNumber')
- },
- success: 'loadAdvancedConfigSuccess'
- });
- return serviceComponents[serviceName];
- //TODO clean serviceComponents
- },
- loadAdvancedConfigSuccess: function (data, opt, params) {
- console.log("TRACE: In success function for the loadAdvancedConfig; url is ", opt.url);
- var properties = [];
- if (data.items.length) {
- data.items.forEach(function (item) {
- item = item.StackConfigurations;
- item.isVisible = item.type !== 'global.xml';
- properties.push({
- serviceName: item.service_name,
- name: item.property_name,
- value: item.property_value,
- description: item.property_description,
- isVisible: item.isVisible,
- filename: item.filename || item.type
- });
- }, this);
- serviceComponents[data.items[0].StackConfigurations.service_name] = properties;
- }
- },
- /**
- * Determine the map which shows which services
- * each global property effects.
- *
- * @return {*}
- * Example:
- * {
- * 'hive_pid_dir': ['HIVE'],
- * ...
- * }
- */
- loadGlobalPropertyToServicesMap: function () {
- if (globalPropertyToServicesMap == null) {
- App.ajax.send({
- name: 'config.advanced.global',
- sender: this,
- data: {
- stack2VersionUrl: App.get('stack2VersionURL')
- },
- success: 'loadGlobalPropertyToServicesMapSuccess'
- });
- }
- return globalPropertyToServicesMap;
- },
-
- loadGlobalPropertyToServicesMapSuccess: function (data) {
- globalPropertyToServicesMap = {};
- if(data.items!=null){
- data.items.forEach(function(service){
- service.configurations.forEach(function(config){
- if("global.xml" === config.StackConfigurations.type){
- if(!(config.StackConfigurations.property_name in globalPropertyToServicesMap)){
- globalPropertyToServicesMap[config.StackConfigurations.property_name] = [];
- }
- globalPropertyToServicesMap[config.StackConfigurations.property_name].push(service.StackServices.service_name);
- }
- });
- });
- }
- },
-
- /**
- * When global configuration changes, not all services are effected
- * by all properties. This method determines if a given service
- * is effected by the difference in desired and actual configs.
- *
- * This method might make a call to server to determine the actual
- * key/value pairs involved.
- */
- isServiceEffectedByGlobalChange: function (service, desiredTag, actualTag) {
- var effected = false;
- if (service != null && desiredTag != null && actualTag != null) {
- if(this.differentGlobalTagsCache.indexOf(service+"/"+desiredTag+"/"+actualTag) < 0){
- this.loadGlobalPropertyToServicesMap();
- var desiredConfigs = this.loadedConfigurationsCache['global_' + desiredTag];
- var actualConfigs = this.loadedConfigurationsCache['global_' + actualTag];
- var requestTags = [];
- if (!desiredConfigs) {
- requestTags.push({
- siteName: 'global',
- tagName: desiredTag
- });
- }
- if (!actualConfigs) {
- requestTags.push({
- siteName: 'global',
- tagName: actualTag
- });
- }
- if (requestTags.length > 0) {
- this.loadConfigsByTags(requestTags);
- desiredConfigs = this.loadedConfigurationsCache['global_' + desiredTag];
- actualConfigs = this.loadedConfigurationsCache['global_' + actualTag];
- }
- if (desiredConfigs != null && actualConfigs != null) {
- for ( var property in desiredConfigs) {
- if (!effected) {
- var dpv = desiredConfigs[property];
- var apv = actualConfigs[property];
- if (dpv !== apv && globalPropertyToServicesMap[property] != null) {
- effected = globalPropertyToServicesMap[property].indexOf(service) > -1;
- if(effected){
- this.differentGlobalTagsCache.push(service+"/"+desiredTag+"/"+actualTag);
- }
- }
- }
- }
- }
- }else{
- effected = true; // We already know they are different
- }
- }
- return effected;
- },
- /**
- * Hosts can override service configurations per property. This method GETs
- * the overriden configurations and sets only the changed properties into
- * the 'overrides' of serviceConfig.
- *
- *
- */
- loadServiceConfigHostsOverrides: function (serviceConfigs, loadedHostToOverrideSiteToTagMap) {
- var configKeyToConfigMap = {};
- serviceConfigs.forEach(function (item) {
- configKeyToConfigMap[item.name] = item;
- });
- var typeTagToHostMap = {};
- var urlParams = [];
- for (var hostname in loadedHostToOverrideSiteToTagMap) {
- var overrideTypeTags = loadedHostToOverrideSiteToTagMap[hostname];
- for (var type in overrideTypeTags) {
- var tag = overrideTypeTags[type];
- typeTagToHostMap[type + "///" + tag] = hostname;
- urlParams.push('(type=' + type + '&tag=' + tag + ')');
- }
- }
- var params = urlParams.join('|');
- if (urlParams.length) {
- App.ajax.send({
- name: 'config.host_overrides',
- sender: this,
- data: {
- params: params,
- configKeyToConfigMap: configKeyToConfigMap,
- typeTagToHostMap: typeTagToHostMap
- },
- success: 'loadServiceConfigHostsOverridesSuccess'
- });
- }
- },
- loadServiceConfigHostsOverridesSuccess: function (data, opt, params) {
- console.debug("loadServiceConfigHostsOverrides: Data=", data);
- data.items.forEach(function (config) {
- App.config.loadedConfigurationsCache[config.type + "_" + config.tag] = config.properties;
- var hostname = params.typeTagToHostMap[config.type + "///" + config.tag];
- var properties = config.properties;
- for (var prop in properties) {
- var serviceConfig = params.configKeyToConfigMap[prop];
- var hostOverrideValue = properties[prop];
- if (serviceConfig && serviceConfig.displayType === 'int') {
- if (/\d+m$/.test(hostOverrideValue)) {
- hostOverrideValue = hostOverrideValue.slice(0, hostOverrideValue.length - 1);
- }
- } else if (serviceConfig && serviceConfig.displayType === 'checkbox') {
- switch (hostOverrideValue) {
- case 'true':
- hostOverrideValue = true;
- break;
- case 'false':
- hostOverrideValue = false;
- break;
- }
- }
- if (serviceConfig) {
- // Value of this property is different for this host.
- var overrides = 'overrides';
- if (!(overrides in serviceConfig)) {
- serviceConfig.overrides = {};
- }
- if (!(hostOverrideValue in serviceConfig.overrides)) {
- serviceConfig.overrides[hostOverrideValue] = [];
- }
- console.log("loadServiceConfigHostsOverrides(): [" + hostname + "] OVERRODE(" + serviceConfig.name + "): " + serviceConfig.value + " -> " + hostOverrideValue);
- serviceConfig.overrides[hostOverrideValue].push(hostname);
- }
- }
- });
- console.log("loadServiceConfigHostsOverrides(): Finished loading.");
- },
- /**
- * Set all site property that are derived from other site-properties
- */
- setConfigValue: function (mappedConfigs, allConfigs, config, globalConfigs) {
- var globalValue;
- if (config.value == null) {
- return;
- }
- var fkValue = config.value.match(/<(foreignKey.*?)>/g);
- var fkName = config.name.match(/<(foreignKey.*?)>/g);
- var templateValue = config.value.match(/<(templateName.*?)>/g);
- if (fkValue) {
- fkValue.forEach(function (_fkValue) {
- var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
- if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
- globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
- config.value = config.value.replace(_fkValue, globalValue);
- } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
- if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
- globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
- } else {
- globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
- }
- config.value = config.value.replace(_fkValue, globalValue);
- }
- }, this);
- }
- // config._name - formatted name from original config name
- if (fkName) {
- fkName.forEach(function (_fkName) {
- var index = parseInt(_fkName.match(/\[([\d]*)(?=\])/)[1]);
- if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
- globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
- config._name = config.name.replace(_fkName, globalValue);
- } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
- if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
- globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
- } else {
- globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
- }
- config._name = config.name.replace(_fkName, globalValue);
- }
- }, this);
- }
- //For properties in the configMapping file having foreignKey and templateName properties.
- if (templateValue) {
- templateValue.forEach(function (_value) {
- var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
- if (globalConfigs.someProperty('name', config.templateName[index])) {
- var globalValue = globalConfigs.findProperty('name', config.templateName[index]).value;
- config.value = config.value.replace(_value, globalValue);
- } else {
- config.value = null;
- }
- }, this);
- }
- },
- complexConfigs: [
- {
- "id": "site property",
- "name": "capacity-scheduler",
- "displayName": "Capacity Scheduler",
- "value": "",
- "defaultValue": "",
- "description": "Capacity Scheduler properties",
- "displayType": "custom",
- "isOverridable": true,
- "isRequired": true,
- "isVisible": true,
- "serviceName": "YARN",
- "filename": "capacity-scheduler.xml",
- "category": "ResourceManager"
- }
- ],
- /**
- * transform set of configs from file
- * into one config with textarea content:
- * name=value
- * @param configs
- * @param filename
- * @return {*}
- */
- fileConfigsIntoTextarea: function(configs, filename){
- var fileConfigs = configs.filterProperty('filename', filename);
- var value = '';
- var defaultValue = '';
- var complexConfig = this.get('complexConfigs').findProperty('filename', filename);
- if(complexConfig){
- fileConfigs.forEach(function(_config){
- value += _config.name + '=' + _config.value + '\n';
- defaultValue += _config.name + '=' + _config.defaultValue + '\n';
- }, this);
- complexConfig.value = value;
- complexConfig.defaultValue = defaultValue;
- configs = configs.filter(function(_config){
- return _config.filename !== filename;
- });
- configs.push(complexConfig);
- }
- return configs;
- },
- /**
- * transform one config with textarea content
- * into set of configs of file
- * @param configs
- * @param filename
- * @return {*}
- */
- textareaIntoFileConfigs: function(configs, filename){
- var complexConfigName = this.get('complexConfigs').findProperty('filename', filename).name;
- var configsTextarea = configs.findProperty('name', complexConfigName);
- var properties = configsTextarea.get('value').replace(/( |\n)+/g, '\n').split('\n');
- properties.forEach(function(_property){
- var name, value;
- if(_property){
- _property = _property.split('=');
- name = _property[0];
- value = (_property[1]) ? _property[1] : "";
- configs.push(Em.Object.create({
- id: configsTextarea.get('id'),
- name: name,
- value: value,
- defaultValue: value,
- serviceName: configsTextarea.get('serviceName'),
- filename: filename
- }));
- }
- });
- return configs.without(configsTextarea);
- }
- });
|