123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629 |
- /**
- * 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');
- require('controllers/wizard/slave_component_groups_controller');
- App.MainServiceInfoConfigsController = Em.Controller.extend({
- name: 'mainServiceInfoConfigsController',
- dataIsLoaded: false,
- stepConfigs: [], //contains all field properties that are viewed in this service
- selectedService: null,
- serviceConfigTags: null,
- globalConfigs: [],
- uiConfigs: [],
- customConfig: [],
- isApplyingChanges: false,
- serviceConfigs: function(){
- return App.config.get('preDefinedServiceConfigs');
- }.property('App.config.preDefinedServiceConfigs'),
- configMapping: function(){
- return App.config.get('configMapping');
- }.property('App.config.configMapping'),
- customConfigs: require('data/custom_configs'),
- configs: function() {
- return App.config.get('preDefinedConfigProperties');
- }.property('App.config.preDefinedConfigProperties'),
- secureConfigs: require('data/secure_mapping'),
-
- /**
- * During page load time, we get the host overrides from the server.
- * The current host -> site:tag map is stored below. This will be
- * useful during save, so that removals can also be determined.
- *
- * Example:
- * {
- * 'hostname1':{
- * 'global': 'version1',
- * 'core-site': 'version1',
- * 'hdfs-site', 'tag3187261938'
- * }
- * }
- *
- * @see savedHostToOverrideSiteToTagMap
- */
- loadedHostToOverrideSiteToTagMap: {},
- /**
- * During page load time the cluster level site to tag
- * mapping is stored here.
- *
- * Example:
- * {
- * 'global': 'version1',
- * 'hdfs-site': 'version1',
- * 'core-site': 'version1'
- * }
- */
- loadedClusterSiteToTagMap: {},
- /**
- * During page save time, we set the host overrides to the server.
- * The new host -> site:tag map is stored below. This will be
- * useful during save, to update the host's host components. Also,
- * it will be useful in deletion of overrides.
- *
- * Example:
- * {
- * 'hostname1': {
- * 'global': {
- * 'tagName': 'tag3187261938_hostname1',
- * 'map': {
- * 'hadoop_heapsize': '2048m'
- * }
- * }
- * }
- * }
- *
- * @see loadedHostToOverrideSiteToTagMap
- */
- savedHostToOverrideSiteToTagMap: {},
- /**
- * Holds the actual base service-config server data uploaded.
- * This is used by the host-override mechanism to update host
- * specific values.
- */
- savedSiteNameToServerServiceConfigDataMap: {},
-
- isSubmitDisabled: function () {
- return (!(this.stepConfigs.everyProperty('errorCount', 0)) || this.get('isApplyingChanges'));
- }.property('stepConfigs.@each.errorCount', 'isApplyingChanges'),
- slaveComponentGroups: null,
- /**
- * Filter text will be located here
- */
- filter: '',
- /**
- * Dropdown menu items in filter compbobox
- */
- filterColumns: function(){
- var result = [];
- for(var i = 1; i<4; i++){
- result.push(Ember.Object.create({
- name: this.t('common.combobox.dropdown.' + i),
- selected: false
- }));
- }
- return result;
- }.property(),
- /**
- * clear and set properties to default value
- */
- clearStep: function () {
- this.set('dataIsLoaded', false);
- this.set('filter', '');
- this.get('filterColumns').setEach('selected', false);
- this.get('stepConfigs').clear();
- this.get('globalConfigs').clear();
- this.get('uiConfigs').clear();
- this.get('customConfig').clear();
- this.set('loadedHostToOverrideSiteToTagMap', {});
- this.set('savedHostToOverrideSiteToTagMap', {});
- this.set('savedSiteNameToServerServiceConfigDataMap', {});
- if (this.get('serviceConfigTags')) {
- this.set('serviceConfigTags', null);
- }
- },
- serviceConfigProperties: function () {
- return App.db.getServiceConfigProperties();
- }.property('content'),
- /**
- * On load function
- */
- loadStep: function () {
- console.log("TRACE: Loading configure for service");
- this.clearStep();
- this.loadServiceConfigs();
- },
- /**
- * Loads the actual configuration of all host components.
- * This helps in determining which services need a restart, and also
- * in showing which properties are actually applied or not.
- * This method also compares the actual_configs with the desired_configs
- * and builds a diff structure.
- *
- * Internall it calculates an array of host-components which need restart.
- * Example:
- * [
- * {
- * componentName: 'DATANODE',
- * serviceName: 'HDFS',
- * host: 'host.name',
- * type: 'core-site',
- * desiredConfigTags: {tag:'version1'},
- * actualConfigTags: {tag:'version4'. host_override:'version2'}
- * },
- * ...
- * ]
- *
- * From there it return the following restart-data for this service.
- * It represents the hosts, whose components need restart, and the
- * properties which require restart.
- *
- * {
- * hostAndHostComponents: {
- * 'hostname1': {
- * 'DATANODE': {
- * 'property1': 'value1',
- * 'property2': 'value2'
- * },
- * 'TASKTRACKER': {
- * 'prop1': 'val1'
- * }
- * },
- * 'hostname6': {
- * 'ZOOKEEPER': {
- * 'property1': 'value3'
- * }
- * }
- * },
- * propertyToHostAndComponent: {
- * 'property1': {
- * 'hostname1': ['DATANODE'],
- * 'hostname6': ['ZOOKEEPER']
- * },
- * 'property2': {
- * 'hostname1': ['DATANODE']
- * },
- * 'prop1': {
- * 'hostname1': ['TASKTRACKER']
- * }
- * }
- * }
- */
- loadActualConfigsAndCalculateRestarts: function () {
- var currentService = this.get('content.serviceName');
- var restartData = {
- hostAndHostComponents: {},
- propertyToHostAndComponent: {}
- };
- var self = this;
- var actualConfigsUrl = this.getUrl('/data/services/host_component_actual_configs.json', '/services?fields=components/host_components/HostRoles/actual_configs');
- $.ajax({
- type: 'GET',
- url: actualConfigsUrl,
- async: false,
- timeout: 10000,
- dataType: 'json',
- success: function (data) {
- var diffHostComponents = [];
- console.debug("loadActualConfigs(" + actualConfigsUrl + "): Data=", data);
- var configsToDownload = [];
- data.items.forEach(function (service) {
- // For current service, do any of the host_components differ in
- // configuration?
- if (currentService === service.ServiceInfo.service_name) {
- service.components.forEach(function (serviceComponent) {
- serviceComponent.host_components.forEach(function (hostComponent) {
- if (hostComponent.HostRoles.actual_configs) {
- for ( var site in hostComponent.HostRoles.actual_configs) {
- var actualConfigsTags = hostComponent.HostRoles.actual_configs[site];
- var desiredConfigTags = self.getDesiredConfigTag(site, hostComponent.HostRoles.host_name);
- if (desiredConfigTags.tag !== actualConfigsTags.tag ||
- (desiredConfigTags.host_override != null &&
- actualConfigsTags.host_override != null &&
- desiredConfigTags.host_override !== actualConfigsTags.host_override)) {
- // Restart may be necessary for this host-component
- diffHostComponents.push({
- componentName: hostComponent.HostRoles.component_name,
- serviceName: serviceComponent.ServiceComponentInfo.service_name,
- host: hostComponent.HostRoles.host_name,
- type: site,
- desiredConfigTags: desiredConfigTags,
- actualConfigTags: actualConfigsTags
- });
- self.addConfigDownloadParam(site, actualConfigsTags.tag, configsToDownload);
- self.addConfigDownloadParam(site, actualConfigsTags.host_override, configsToDownload);
- self.addConfigDownloadParam(site, desiredConfigTags.tag, configsToDownload);
- self.addConfigDownloadParam(site, desiredConfigTags.host_override, configsToDownload);
- }
- }
- }
- });
- });
- }
- });
- if (configsToDownload.length > 0) {
- var url = self.getUrl('/data/configurations/cluster_level_actual_configs.json?' + configsToDownload.join('|'), '/configurations?' + configsToDownload.join('|'));
- $.ajax({
- type: 'GET',
- url: url,
- async: false,
- timeout: 10000,
- dataType: 'json',
- success: function (data) {
- console.log("configsToDownload(): In success for ", url);
- if (data.items) {
- data.items.forEach(function (item) {
- App.config.loadedConfigurationsCache[item.type + "_" + item.tag] = item.properties;
- });
- }
- },
- error: function (request, ajaxOptions, error) {
- console.log("TRACE: In error function for the configsToDownload call");
- console.log("TRACE: value of the url is: " + url);
- console.log("TRACE: error code status is: " + request.status);
- },
- statusCode: require('data/statusCodes')
- });
- }
- // Now all the configurations are loaded.
- // Find the diff in properties
- if (diffHostComponents.length > 0) {
- diffHostComponents.forEach(function (diffHostComponent) {
- var actualConfigs = App.config.loadedConfigurationsCache[diffHostComponent.type + "_" + diffHostComponent.actualConfigTags.tag];
- var desiredConfigs = App.config.loadedConfigurationsCache[diffHostComponent.type + "_" + diffHostComponent.desiredConfigTags.tag];
- var diffs = self.getConfigDifferences(actualConfigs, desiredConfigs);
- if (!jQuery.isEmptyObject(diffs)) {
- var skip = false;
- if (diffHostComponent.type == 'global') {
- if(!App.config.isServiceEffectedByGlobalChange(
- diffHostComponent.serviceName,
- diffHostComponent.desiredConfigTags.tag,
- diffHostComponent.actualConfigTags.tag)){
- skip = true;
- }
- }
- if(!skip){
- // Populate restartData.hostAndHostComponents
- if (!(diffHostComponent.host in restartData.hostAndHostComponents)) {
- restartData.hostAndHostComponents[diffHostComponent.host] = {};
- }
- if (!(diffHostComponent.componentName in restartData.hostAndHostComponents[diffHostComponent.host])) {
- restartData.hostAndHostComponents[diffHostComponent.host][diffHostComponent.componentName] = {};
- }
- jQuery.extend(restartData.hostAndHostComponents[diffHostComponent.host][diffHostComponent.componentName], diffs);
- // Populate restartData.propertyToHostAndComponent
- for ( var diff in diffs) {
- if (!(diff in restartData.propertyToHostAndComponent)) {
- restartData.propertyToHostAndComponent[diff] = {};
- }
- if (!(diffHostComponent.host in restartData.propertyToHostAndComponent[diff])) {
- restartData.propertyToHostAndComponent[diff][diffHostComponent.host] = [];
- }
- if (!(restartData.propertyToHostAndComponent[diff][diffHostComponent.host].contains(diffHostComponent.componentName))) {
- restartData.propertyToHostAndComponent[diff][diffHostComponent.host].push(diffHostComponent.componentName);
- }
- }
- }
- }
- });
- }
- console.log("loadActualConfigs(): Finished loading. Restart host components = ", diffHostComponents);
- },
- error: function (request, ajaxOptions, error) {
- console.log("loadActualConfigs(): URL:" + actualConfigsUrl + ". Status:", request.status, ", Error:", error);
- },
- statusCode: require('data/statusCodes')
- });
- console.log("loadActualConfigsAndCalculateRestarts(): Restart data = ", restartData);
- return restartData;
- },
-
- /**
- * Determines the differences between desired and actual configs and returns
- * them as an object. The key is the property, and value is actual_config.
- */
- getConfigDifferences: function (actualConfigs, desiredConfigs) {
- var differences = {};
- if (actualConfigs != null && desiredConfigs != null) {
- for(var desiredProp in desiredConfigs){
- if(desiredConfigs[desiredProp] !== actualConfigs[desiredProp]){
- differences[desiredProp] = actualConfigs[desiredProp];
- }
- }
- }
- return differences;
- },
-
- addConfigDownloadParam: function(site, tag, configsToDownload){
- if(tag!=null && !(site+"_"+tag in App.config.loadedConfigurationsCache)){
- var configParam = "(type="+site+"&tag="+tag+")";
- if(!configsToDownload.contains(configParam)){
- configsToDownload.push(configParam);
- }
- }
- },
-
- getDesiredConfigTag: function(site, hostName){
- var tag = {tag: this.loadedClusterSiteToTagMap[site], host_override: null};
- if(hostName in this.loadedHostToOverrideSiteToTagMap){
- var map = this.loadedHostToOverrideSiteToTagMap[hostName];
- if(site in map){
- tag.host_overrides = map[site];
- }
- }
- return tag;
- },
- /**
- * Loads service configurations
- */
- loadServiceConfigs: function () {
- App.ajax.send({
- name: 'config.tags',
- sender: this,
- data: {
- serviceName: this.get('content.serviceName'),
- serviceConfigsDef: this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'))
- },
- success: 'loadServiceTagsSuccess'
- });
- },
- loadServiceTagsSuccess: function(data, opt, params){
- var serviceConfigsDef = params.serviceConfigsDef;
- var serviceName = this.get('content.serviceName');
- console.debug("loadServiceConfigs(): data=", data);
- this.loadedClusterSiteToTagMap = {};
- //STEP 1: handle tags from JSON data
- for ( var site in data.Clusters.desired_configs) {
- if (serviceConfigsDef.sites.indexOf(site) > -1) {
- this.loadedClusterSiteToTagMap[site] = data.Clusters.desired_configs[site]['tag'];
- var overrides = data.Clusters.desired_configs[site].host_overrides;
- if (overrides) {
- overrides.forEach(function (override) {
- var hostname = override.host_name;
- var tag = override.tag;
- if(!this.loadedHostToOverrideSiteToTagMap[hostname]){
- this.loadedHostToOverrideSiteToTagMap[hostname] = {};
- }
- this.loadedHostToOverrideSiteToTagMap[hostname][site] = tag;
- }, this);
- }
- }
- }
- //STEP 2: Create an array of objects defining tag names to be polled and new tag names to be set after submit
- this.setServiceConfigTags(this.loadedClusterSiteToTagMap);
- //STEP 3: Load advanced configs from server
- var advancedConfigs = App.config.loadAdvancedConfig(serviceName) || [];
- //STEP 4: Load on-site config by service from server
- var configGroups = App.config.loadConfigsByTags(this.get('serviceConfigTags'));
- //STEP 5: Merge global and on-site configs with pre-defined
- var configSet = App.config.mergePreDefinedWithLoaded(configGroups, advancedConfigs, this.get('serviceConfigTags'), serviceName);
- //var serviceConfigs = this.getSitesConfigProperties(advancedConfigs);
- var configs = configSet.configs;
- //put global configs into globalConfigs to save them separately
- this.set('globalConfigs', configSet.globalConfigs);
- //STEP 6: add advanced configs
- //App.config.addAdvancedConfigs(configs, advancedConfigs, serviceName);
- //STEP 7: add custom configs
- App.config.addCustomConfigs(configs);
- //STEP 8: add configs as names of host components
- this.addHostNamesToGlobalConfig();
- var allConfigs = this.get('globalConfigs').concat(configs);
- //this.loadServiceConfigHostsOverrides(serviceConfigs, this.loadedHostToOverrideSiteToTagMap);
- //STEP 9: Load and add host override configs
- App.config.loadServiceConfigHostsOverrides(allConfigs, this.loadedHostToOverrideSiteToTagMap);
- var restartData = this.loadActualConfigsAndCalculateRestarts();
- //STEP 10: creation of serviceConfig object which contains configs for current service
- var serviceConfig = App.config.createServiceConfig(serviceName);
- this.checkForRestart(serviceConfig, restartData);
- if (serviceName || serviceConfig.serviceName === 'MISC') {
- //STEP 11: render configs and wrap each in ServiceConfigProperty object
- this.loadComponentConfigs(allConfigs, serviceConfig, restartData);
- this.get('stepConfigs').pushObject(serviceConfig);
- }
- this.set('selectedService', this.get('stepConfigs').objectAt(0));
- this.checkForSecureConfig( this.get('selectedService'));
- this.set('dataIsLoaded', true);
- },
- /**
- * Changes format from Object to Array
- *
- * {
- * 'core-site': 'version1',
- * 'hdfs-site': 'version1',
- * 'global': 'version2',
- * ...
- * }
- *
- * to
- *
- * [
- * {
- * siteName: 'core-site',
- * tagName: 'version1',
- * newTageName: null
- * },
- * ...
- * ]
- *
- * set tagnames for configuration of the *-site.xml
- */
- setServiceConfigTags: function (desiredConfigsSiteTags) {
- console.debug("setServiceConfigTags(): Trying to set ", desiredConfigsSiteTags);
- var newServiceConfigTags = [];
- for (var index in desiredConfigsSiteTags) {
- newServiceConfigTags.pushObject({
- siteName: index,
- tagName: desiredConfigsSiteTags[index],
- newTagName: null
- }, this);
- }
- console.debug("setServiceConfigTags(): Setting 'serviceConfigTags' to ", newServiceConfigTags);
- this.set('serviceConfigTags', newServiceConfigTags);
- },
- /**
- * check whether host component must be restarted
- * @param serviceConfig
- * @param restartData
- */
- checkForRestart: function(serviceConfig, restartData){
- var hostsCount = 0;
- var hostComponentCount = 0;
- var restartHosts = Ember.A([]);
- if(restartData != null && restartData.hostAndHostComponents != null && !jQuery.isEmptyObject(restartData.hostAndHostComponents)){
- serviceConfig.set('restartRequired', true);
- for(var host in restartData.hostAndHostComponents) {
- hostsCount++;
- var componentsArray = Ember.A([]);
- for(var component in restartData.hostAndHostComponents[host]){
- componentsArray.push(Ember.Object.create({name: App.format.role(component)}));
- hostComponentCount++;
- }
- var hostObj = App.Host.find(host);
- restartHosts.push(Ember.Object.create({hostData: hostObj, components: componentsArray}))
- }
- serviceConfig.set('restartRequiredHostsAndComponents', restartHosts);
- serviceConfig.set('restartRequiredMessage', 'Service needs '+hostComponentCount+' components on ' + hostsCount +' hosts to be restarted.')
- }
- },
- /**
- * check whether the config property is a security related knob
- * @param serviceConfig
- */
- checkForSecureConfig: function(serviceConfig) {
- serviceConfig.get('configs').forEach(function(_config){
- this.get('secureConfigs').forEach(function(_secureConfig){
- if(_config.get('name')=== _secureConfig.name) {
- _config.set('isSecureConfig',true);
- }
- },this)
- },this)
- },
- /**
- * Load child components to service config object
- * @param configs
- * @param componentConfig
- * @param restartData
- */
- loadComponentConfigs: function (configs, componentConfig, restartData) {
- configs.forEach(function (_serviceConfigProperty) {
- console.log("config", _serviceConfigProperty);
- if (!_serviceConfigProperty) return;
- var overrides = _serviceConfigProperty.overrides;
- // we will populate the override properties below
- _serviceConfigProperty.overrides = null;
- if (_serviceConfigProperty.isOverridable === undefined) {
- _serviceConfigProperty.isOverridable = true;
- }
- var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
- var propertyName = serviceConfigProperty.get('name');
- if (restartData != null && propertyName in restartData.propertyToHostAndComponent) {
- serviceConfigProperty.set('isRestartRequired', true);
- var message = '<ul>';
- for(var host in restartData.propertyToHostAndComponent[propertyName]){
- var appHost = App.Host.find(host);
- message += "<li>"+appHost.get('publicHostName');
- message += "<ul>";
- restartData.propertyToHostAndComponent[propertyName][host].forEach(function(comp){
- message += "<li>"+App.format.role(comp)+"</li>"
- });
- message += "</ul></li>";
- }
- message += "</ul>";
- serviceConfigProperty.set('restartRequiredMessage', message);
- }
- if (serviceConfigProperty.get('serviceName') === this.get('content.serviceName')) {
- // serviceConfigProperty.serviceConfig = componentConfig;
- if (App.get('isAdmin')) {
- serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
- } else {
- serviceConfigProperty.set('isEditable', false);
- }
- console.log("config result", serviceConfigProperty);
- } else {
- serviceConfigProperty.set('isVisible', false);
- }
- if (overrides != null) {
- for(var overridenValue in overrides){
- var hostsArray = overrides[overridenValue];
- var newSCP = App.ServiceConfigProperty.create(_serviceConfigProperty);
- newSCP.set('value', overridenValue);
- newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
- newSCP.set('parentSCP', serviceConfigProperty);
- newSCP.set('selectedHostOptions', Ember.A(hostsArray));
- var parentOverridesArray = serviceConfigProperty.get('overrides');
- if(parentOverridesArray == null){
- parentOverridesArray = Ember.A([]);
- serviceConfigProperty.set('overrides', parentOverridesArray);
- }
- parentOverridesArray.pushObject(newSCP);
- console.debug("createOverrideProperty(): Added:", newSCP, " to main-property:", serviceConfigProperty)
- }
- }
- componentConfig.configs.pushObject(serviceConfigProperty);
- serviceConfigProperty.validate();
- }, this);
- },
- /**
- * Determines which host components are running on each host.
- * @param status 'running' or 'unknown'
- * @return Returned in the following format:
- * {
- * runningHosts: {
- * 'hostname1': 'NameNode, DataNode, JobTracker',
- * 'hostname2': 'DataNode',
- * },
- * runningComponentCount: 5
- * }
- */
- getHostComponentsByStatus: function (services, status) {
- var hosts = [];
- var componentCount = 0;
- var hostToIndexMap = {};
- services.forEach(function (service) {
- var hostComponents = (status == App.HostComponentStatus.started) ? service.get('runningHostComponents') : service.get('unknownHostComponents');
- if (hostComponents != null) {
- hostComponents.forEach(function (hc) {
- var hostName = hc.get('host.publicHostName');
- var componentName = hc.get('displayName');
- componentCount++;
- if (!(hostName in hostToIndexMap)) {
- hosts.push({
- name: hostName,
- components: ""
- });
- hostToIndexMap[hostName] = hosts.length - 1;
- }
- var hostObj = hosts[hostToIndexMap[hostName]];
- if (hostObj.components.length > 0)
- hostObj.components += ", " + componentName;
- else
- hostObj.components += componentName;
- });
- hosts.sort(function (a, b) {
- return a.name.localeCompare(b.name);
- });
- }
- });
- return {
- hosts: hosts,
- componentCount: componentCount
- };
- },
-
- /**
- * open popup with appropriate message
- */
- restartServicePopup: function (event) {
- if(this.get("isSubmitDisabled")){
- return;
- }
- var header;
- var message;
- var messageClass;
- var hasUnknown = false;
- var value;
- var flag = false;
- var runningHosts = null;
- var runningComponentCount = 0;
- var unknownHosts = null;
- var unknownComponentCount = 0;
- var dfd = $.Deferred();
- var self = this;
- var serviceName = this.get('content.serviceName');
- var displayName = this.get('content.displayName');
- if (App.supports.hostOverrides ||
- (serviceName !== 'HDFS' && this.get('content.isStopped') === true) ||
- ((serviceName === 'HDFS') && this.get('content.isStopped') === true && (!App.Service.find().someProperty('id', 'MAPREDUCE') || App.Service.find('MAPREDUCE').get('isStopped')))) {
- // warn the user if any service directories are being changed
- var dirChanged = false;
- if (serviceName === 'HDFS') {
- var hdfsConfigs = self.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs');
- if (
- hdfsConfigs.findProperty('name', 'dfs_name_dir').get('isNotDefaultValue') ||
- hdfsConfigs.findProperty('name', 'fs_checkpoint_dir').get('isNotDefaultValue') ||
- hdfsConfigs.findProperty('name', 'dfs_data_dir').get('isNotDefaultValue')
- ) {
- dirChanged = true;
- }
- } else if (serviceName === 'MAPREDUCE') {
- var mapredConfigs = self.get('stepConfigs').findProperty('serviceName', 'MAPREDUCE').get('configs');
- if (
- mapredConfigs.findProperty('name', 'mapred_local_dir').get('isNotDefaultValue') ||
- mapredConfigs.findProperty('name', 'mapred_system_dir').get('isNotDefaultValue')
- ) {
- dirChanged = true;
- }
- }
- if (dirChanged) {
- App.showConfirmationPopup(function() {
- dfd.resolve();
- }, Em.I18n.t('services.service.config.confirmDirectoryChange').format(displayName));
- } else {
- dfd.resolve();
- }
- dfd.done(function() {
- var result = self.saveServiceConfigProperties();
- App.router.get('clusterController').updateClusterData();
- flag = result.flag;
- if (result.flag === true) {
- header = Em.I18n.t('services.service.config.saved');
- message = Em.I18n.t('services.service.config.saved.message');
- messageClass = 'alert alert-success';
- // warn the user if any of the components are in UNKNOWN state
- var uhc;
- if (self.get('content.serviceName') !== 'HDFS' || (self.get('content.serviceName') === 'HDFS' && !App.Service.find().someProperty('id', 'MAPREDUCE'))) {
- uhc = self.getHostComponentsByStatus([self.get('content')], App.HostComponentStatus.unknown);
- } else {
- uhc = self.getHostComponentsByStatus([self.get('content'), App.Service.find('MAPREDUCE')], App.HostComponentStatus.unknown);
- }
- unknownHosts = uhc.hosts;
- unknownComponentCount = uhc.componentCount;
- } else {
- header = Em.I18n.t('common.failure');
- message = result.message;
- messageClass = 'alert alert-error';
- value = result.value;
- }
- });
- } else {
- var rhc;
- if (this.get('content.serviceName') !== 'HDFS' || (this.get('content.serviceName') === 'HDFS' && !App.Service.find().someProperty('id', 'MAPREDUCE'))) {
- rhc = this.getHostComponentsByStatus([this.get('content')], App.HostComponentStatus.started);
- header = Em.I18n.t('services.service.config.notSaved');
- message = Em.I18n.t('services.service.config.msgServiceStop');
- } else {
- rhc = this.getHostComponentsByStatus([this.get('content'), App.Service.find('MAPREDUCE')], App.HostComponentStatus.started);
- header = Em.I18n.t('services.service.config.notSaved');
- message = Em.I18n.t('services.service.config.msgHDFSMapRServiceStop');
- }
- messageClass = 'alert alert-error';
- runningHosts = rhc.hosts;
- runningComponentCount = rhc.componentCount;
- dfd.resolve();
- }
- dfd.done(function () {
- App.ModalPopup.show({
- header: header,
- primary: Em.I18n.t('ok'),
- secondary: null,
- onPrimary: function () {
- this.hide();
- if (flag) {
- self.loadStep();
- }
- },
- bodyClass: Ember.View.extend({
- flag: flag,
- message: message,
- messageClass: messageClass,
- runningHosts: runningHosts,
- runningComponentCount: runningComponentCount,
- unknownHosts: unknownHosts,
- unknownComponentCount: unknownComponentCount,
- siteProperties: value,
- getDisplayMessage: function () {
- var displayMsg = [];
- var siteProperties = this.get('siteProperties');
- if (siteProperties) {
- siteProperties.forEach(function (_siteProperty) {
- var displayProperty = _siteProperty.siteProperty;
- var displayNames = _siteProperty.displayNames;
- /////////
- if (displayNames && displayNames.length) {
- if (displayNames.length === 1) {
- displayMsg.push(displayProperty + Em.I18n.t('as') + displayNames[0]);
- } else {
- var name;
- displayNames.forEach(function (_name, index) {
- if (index === 0) {
- name = _name;
- } else if (index === siteProperties.length - 1) {
- name = name + Em.I18n.t('and') + _name;
- } else {
- name = name + ', ' + _name;
- }
- }, this);
- displayMsg.push(displayProperty + Em.I18n.t('as') + name);
- }
- } else {
- displayMsg.push(displayProperty);
- }
- }, this);
- }
- return displayMsg;
- }.property('siteProperties'),
- runningHostsMessage: function () {
- return Em.I18n.t('services.service.config.stopService.runningHostComponents').format(this.get('runningComponentCount'), this.get('runningHosts.length'));
- }.property('runningComponentCount', 'runningHosts.length'),
- unknownHostsMessage: function () {
- return Em.I18n.t('services.service.config.stopService.unknownHostComponents').format(this.get('unknownComponentCount'), this.get('unknownHosts.length'));
- }.property('unknownComponentCount', 'unknownHosts.length'),
- templateName: require('templates/main/service/info/configs_save_popup')
- })
- })
- });
- },
- /**
- * Save config properties
- */
- saveServiceConfigProperties: function () {
- var result = {
- flag: false,
- message: null,
- value: null
- };
- this.savedHostToOverrideSiteToTagMap = {};
- var configs = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName')).get('configs');
- this.saveGlobalConfigs(configs);
- this.saveSiteConfigs(configs);
- /**
- * First we put cluster configurations, which automatically creates /configurations
- * resources. Next we update host level overrides.
- */
- result.flag = this.doPUTClusterConfigurations();
- if (!result.flag) {
- result.message = Em.I18n.t('services.service.config.failSaveConfig');
- }else{
- result.flag = result.flag && this.doPUTHostOverridesConfigurationSites();
- if (!result.flag) {
- result.message = Em.I18n.t('services.service.config.failSaveConfigHostExceptions');
- }
- }
- console.log("The result from applyCreatdConfToService is: " + result);
- return result;
- },
- /**
- * save new or change exist configs in global configs
- * @param configs
- */
- saveGlobalConfigs: function (configs) {
- var globalConfigs = this.get('globalConfigs');
- configs.filterProperty('id', 'puppet var').forEach(function (uiConfigProperty) {
- if (globalConfigs.someProperty('name', uiConfigProperty.name)) {
- var modelGlobalConfig = globalConfigs.findProperty('name', uiConfigProperty.name);
- modelGlobalConfig.value = uiConfigProperty.value;
- var uiOverrides = uiConfigProperty.get('overrides');
- if(uiOverrides!=null && uiOverrides.get('length')>0){
- modelGlobalConfig.overrides = {};
- uiOverrides.forEach(function(uiOverride){
- var value = uiOverride.get('value');
- modelGlobalConfig.overrides[value] = [];
- uiOverride.get('selectedHostOptions').forEach(function(host){
- modelGlobalConfig.overrides[value].push(host);
- });
- });
- }
- } else {
- globalConfigs.pushObject({
- name: uiConfigProperty.name,
- value: uiConfigProperty.value
- });
- }
- }, this);
- this.setHiveHostName(globalConfigs);
- this.setOozieHostName(globalConfigs);
- this.set('globalConfigs', globalConfigs);
- },
- /**
- * set hive hostnames in global configs
- * @param globals
- */
- setHiveHostName: function (globals) {
- if (globals.someProperty('name', 'hive_database')) {
- var hiveDb = globals.findProperty('name', 'hive_database');
- if (hiveDb.value === 'New MySQL Database') {
- var ambariHost = globals.findProperty('name', 'hive_ambari_host');
- if (ambariHost) {
- ambariHost.name = 'hive_hostname';
- }
- globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_host'));
- globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_database'));
- globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_host'));
- globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_database'));
- } else if (hiveDb.value === 'Existing MySQL Database'){
- var existingMySqlHost = globals.findProperty('name', 'hive_existing_mysql_host');
- if (existingMySqlHost) {
- existingMySqlHost.name = 'hive_hostname';
- }
- globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
- globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
- globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_host'));
- globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_database'));
- } else { //existing oracle database
- var existingOracleHost = globals.findProperty('name', 'hive_existing_oracle_host');
- if (existingOracleHost) {
- existingOracleHost.name = 'hive_hostname';
- }
- globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
- globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
- globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_host'));
- globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_database'));
- }
- }
- },
- /**
- * set oozie hostnames in global configs
- * @param globals
- */
- setOozieHostName: function (globals) {
- if (globals.someProperty('name', 'oozie_database')) {
- var oozieDb = globals.findProperty('name', 'oozie_database');
- if (oozieDb.value === 'New Derby Database'){
- globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
- globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
- } else if (oozieDb.value === 'New MySQL Database') {
- var ambariHost = globals.findProperty('name', 'oozie_ambari_host');
- if (ambariHost) {
- ambariHost.name = 'oozie_hostname';
- }
- globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
- globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
- } else if (oozieDb.value === 'Existing MySQL Database') {
- var existingMySqlHost = globals.findProperty('name', 'oozie_existing_mysql_host');
- if (existingMySqlHost) {
- existingMySqlHost.name = 'oozie_hostname';
- }
- globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
- globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
- globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
- } else{ //existing oracle database
- var existingOracleHost = globals.findProperty('name', 'oozie_existing_oracle_host');
- if (existingOracleHost) {
- existingOracleHost.name = 'oozie_hostname';
- }
- globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
- globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
- globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
- globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
- }
- }
- },
- /**
- * save site configs
- * @param configs
- */
- saveSiteConfigs: function (configs) {
- //storedConfigs contains custom configs as well
- var serviceConfigProperties = configs.filterProperty('id', 'site property');
- serviceConfigProperties.forEach(function(_config){
- if(typeof _config.get('value') === "boolean") _config.set('value', _config.value.toString());
- });
- var storedConfigs = serviceConfigProperties.filterProperty('value');
- var allUiConfigs = this.loadUiSideConfigs(this.get('configMapping').all());
- this.set('uiConfigs', storedConfigs.concat(allUiConfigs));
- },
- /**
- * return configs from the UI side
- * @param configMapping array with configs
- * @return {Array}
- */
- loadUiSideConfigs: function (configMapping) {
- var uiConfig = [];
- var configs = configMapping.filterProperty('foreignKey', null);
- configs.forEach(function (_config) {
- var valueWithOverrides = this.getGlobConfigValueWithOverrides(_config.templateName, _config.value, _config.name);
- if (valueWithOverrides !== null) {
- uiConfig.pushObject({
- "id": "site property",
- "name": _config.name,
- "value": valueWithOverrides.value,
- "filename": _config.filename,
- "overrides": valueWithOverrides.overrides
- });
- }
- }, this);
- return uiConfig;
- },
- /**
- * return global config value
- * @param templateName
- * @param expression
- * @param name
- * @return {
- * value: '...',
- * overrides: {
- * 'value1': [h1, h2],
- * 'value2': [h3]
- * }
- * }
- */
- getGlobConfigValueWithOverrides: function (templateName, expression, name) {
- var express = expression.match(/<(.*?)>/g);
- var value = expression;
- if (express == null) {
- return { value : expression, overrides: {}}; // if site property do not map any global property then return the value
- }
- var overrideHostToValue = {};
- express.forEach(function (_express) {
- //console.log("The value of template is: " + _express);
- var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
- if (this.get('globalConfigs').someProperty('name', templateName[index])) {
- //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
- var globalObj = this.get('globalConfigs').findProperty('name', templateName[index]);
- var globValue = globalObj.value;
- // Hack for templeton.zookeeper.hosts
- var preReplaceValue = null;
- if (value !== null) { // if the property depends on more than one template name like <templateName[0]>/<templateName[1]> then don't proceed to the next if the prior is null or not found in the global configs
- preReplaceValue = value;
- value = this._replaceConfigValues(name, _express, value, globValue);
- }
- if(globalObj.overrides!=null){
- for(ov in globalObj.overrides){
- var hostsArray = globalObj.overrides[ov];
- hostsArray.forEach(function(host){
- if(!(host in overrideHostToValue)){
- overrideHostToValue[host] = this._replaceConfigValues(name, _express, preReplaceValue, ov);
- }else{
- overrideHostToValue[host] = this._replaceConfigValues(name, _express, overrideHostToValue[host], ov);
- }
- }, this);
- }
- }
- } else {
- /*
- console.log("ERROR: The variable name is: " + templateName[index]);
- console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
- "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
- "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
- */
- value = null;
- }
- }, this);
- var valueWithOverrides = {
- value: value,
- overrides: {}
- };
- if(!jQuery.isEmptyObject(overrideHostToValue)){
- for(var host in overrideHostToValue){
- var hostVal = overrideHostToValue[host];
- if(!(hostVal in valueWithOverrides.overrides)){
- valueWithOverrides.overrides[hostVal] = [];
- }
- valueWithOverrides.overrides[hostVal].push(host);
- }
- }
- return valueWithOverrides;
- },
-
- _replaceConfigValues: function (name, express, value, globValue) {
- if (name === "templeton.zookeeper.hosts" || name === 'hbase.zookeeper.quorum') {
- var zooKeeperPort = '2181';
- if (typeof globValue === 'string') {
- var temp = [];
- temp.push(globValue);
- globValue = temp;
- }
- if (name === "templeton.zookeeper.hosts") {
- var temp = [];
- globValue.forEach(function (_host, index) {
- temp.push(globValue[index] + ':' + zooKeeperPort);
- }, this);
- globValue = temp;
- }
- value = value.replace(express, globValue.toString());
- } else {
- value = value.replace(express, globValue);
- }
- return value;
- },
- /**
- * Saves cluster level configurations for all necessary sites.
- * PUT calls are made to /api/v1/clusters/clusterName for each site.
- *
- * @return {Boolean}
- */
- doPUTClusterConfigurations: function () {
- var result = true;
- var serviceConfigTags = this.get('serviceConfigTags');
- this.setNewTagNames(serviceConfigTags);
- var siteNameToServerDataMap = {};
-
- serviceConfigTags.forEach(function (_serviceTags) {
- if (_serviceTags.siteName === 'global') {
- console.log("TRACE: Inside global");
- var serverGlobalConfigs = this.createGlobalSiteObj(_serviceTags.newTagName);
- siteNameToServerDataMap['global'] = serverGlobalConfigs;
- if(this.isConfigChanged(App.config.loadedConfigurationsCache['global_'+this.loadedClusterSiteToTagMap['global']], serverGlobalConfigs.properties)){
- result = result && this.doPUTClusterConfigurationSite(serverGlobalConfigs);
- }
- } else if (_serviceTags.siteName === 'core-site') {
- console.log("TRACE: Inside core-site");
- if (this.get('content.serviceName') === 'HDFS' || this.get('content.serviceName') === 'HCFS') {
- var coreSiteConfigs = this.createCoreSiteObj(_serviceTags.newTagName);
- siteNameToServerDataMap['core-site'] = coreSiteConfigs;
- if(this.isConfigChanged(App.config.loadedConfigurationsCache['core-site_'+this.loadedClusterSiteToTagMap['core-site']], coreSiteConfigs.properties)){
- result = result && this.doPUTClusterConfigurationSite(coreSiteConfigs);
- }
- }
- } else {
- var serverConfigs = this.createSiteObj(_serviceTags.siteName, _serviceTags.newTagName);
- siteNameToServerDataMap[_serviceTags.siteName] = serverConfigs;
- if(this.isConfigChanged(App.config.loadedConfigurationsCache[_serviceTags.siteName+'_'+this.loadedClusterSiteToTagMap[_serviceTags.siteName]], serverConfigs.properties)){
- result = result && this.doPUTClusterConfigurationSite(serverConfigs);
- }
- }
- }, this);
- this.savedSiteNameToServerServiceConfigDataMap = siteNameToServerDataMap;
- return result;
- },
-
- /**
- * Compares the loaded config values with the saving config values.
- */
- isConfigChanged: function (loadedConfig, savingConfig) {
- var changed = false;
- if (loadedConfig != null && savingConfig != null) {
- var seenLoadKeys = [];
- for ( var loadKey in loadedConfig) {
- seenLoadKeys.push(loadKey);
- var loadValue = loadedConfig[loadKey];
- var saveValue = savingConfig[loadKey];
- if("boolean" == typeof(saveValue)){
- saveValue = saveValue.toString();
- }
- if(saveValue==null){
- saveValue = "null";
- }
- if (loadValue !== saveValue) {
- changed = true;
- break;
- }
- }
- for ( var saveKey in savingConfig) {
- if (seenLoadKeys.indexOf(saveKey) < 0) {
- changed = true;
- break;
- }
- }
- }
- return changed;
- },
-
- /**
- * Saves configuration of a particular site. The provided data
- * contains the site name and tag to be used.
- */
- doPUTClusterConfigurationSite: function (data) {
- var result;
- var url = this.getUrl('', '');
- var clusterData = {
- Clusters: {
- desired_config: data
- }
- };
- console.log("applyClusterConfigurationToSite(): PUTting data:", clusterData);
- $.ajax({
- type: 'PUT',
- url: url,
- async: false,
- dataType: 'text',
- data: JSON.stringify(clusterData),
- timeout: 5000,
- success: function (data) {
- console.log("applyClusterConfigurationToSite(): In success for data:", data);
- result = true;
- },
- error: function (request, ajaxOptions, error) {
- console.log('applyClusterConfigurationToSite(): ERROR:', request.responseText, ", error=", error);
- result = false;
- },
- statusCode: require('data/statusCodes')
- });
- console.log("applyClusterConfigurationToSite(): Exiting with result=" + result);
- return result;
- },
- /**
- * Creates host level overrides for service configuration.
- *
- */
- doPUTHostOverridesConfigurationSites: function(){
- var singlePUTHostData = [];
- var savedHostSiteArray = [];
- for ( var host in this.savedHostToOverrideSiteToTagMap) {
- for ( var siteName in this.savedHostToOverrideSiteToTagMap[host]) {
- var tagName = this.savedHostToOverrideSiteToTagMap[host][siteName].tagName;
- var map = this.savedHostToOverrideSiteToTagMap[host][siteName].map;
- savedHostSiteArray.push(host+"///"+siteName);
- singlePUTHostData.push({
- RequestInfo: {
- query: 'Hosts/host_name='+host
- },
- Body: {
- Hosts: {
- desired_config: {
- type: siteName,
- tag: tagName,
- properties: map
- }
- }
- }
- });
- }
- }
- // Now cleanup removed overrides
- for ( var loadedHost in this.loadedHostToOverrideSiteToTagMap) {
- for ( var loadedSiteName in this.loadedHostToOverrideSiteToTagMap[loadedHost]) {
- if (!(savedHostSiteArray.contains(loadedHost + "///" + loadedSiteName))) {
- // This host-site combination was loaded, but not saved.
- // Meaning it is not needed anymore. Hence send a DELETE command.
- singlePUTHostData.push({
- RequestInfo: {
- query: 'Hosts/host_name='+loadedHost
- },
- Body: {
- Hosts: {
- desired_config: {
- type: loadedSiteName,
- tag: this.loadedHostToOverrideSiteToTagMap[loadedHost][loadedSiteName],
- selected: false
- }
- }
- }
- });
- }
- }
- }
- console.debug("createHostOverrideConfigSites(): PUTting host-overrides. Data=",singlePUTHostData);
- if(singlePUTHostData.length>0){
- var url = this.getUrl('', '/hosts');
- var hostOverrideResult = true;
- $.ajax({
- type: 'PUT',
- url: url,
- data: JSON.stringify(singlePUTHostData),
- async: false,
- dataType: 'text',
- timeout: 5000,
- success: function (data) {
- var jsonData = jQuery.parseJSON(data);
- hostOverrideResult = true;
- console.log("createHostOverrideConfigSites(): SUCCESS:", url, ". RESPONSE:",jsonData);
- },
- error: function (request, ajaxOptions, error) {
- hostOverrideResult = false;
- console.log("createHostOverrideConfigSites(): ERROR:", url, ". RESPONSE:",request.responseText);
- },
- statusCode: require('data/statusCodes')
- });
- return hostOverrideResult;
- }
- return true;
- },
-
- /**
- * add newTagName property to each config in serviceConfigs
- * @param serviceConfigs
- */
- setNewTagNames: function (serviceConfigs) {
- var time = (new Date).getTime();
- serviceConfigs.forEach(function (_serviceConfigs) {
- _serviceConfigs.newTagName = 'version' + time;
- }, this);
- },
- /**
- * create global site object
- * @param tagName
- * @return {Object}
- */
- createGlobalSiteObj: function (tagName) {
- var globalSiteProperties = {};
- this.get('globalConfigs').forEach(function (_globalSiteObj) {
- // do not pass any globalConfigs whose name ends with _host or _hosts
- if (!/_hosts?$/.test(_globalSiteObj.name)) {
- // append "m" to JVM memory options except for hadoop_heapsize
- if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && _globalSiteObj.name !== 'hadoop_heapsize') {
- _globalSiteObj.value += "m";
- }
- globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
- this.recordHostOverride(_globalSiteObj, 'global', tagName, this);
- //console.log("TRACE: name of the global property is: " + _globalSiteObj.name);
- //console.log("TRACE: value of the global property is: " + _globalSiteObj.value);
- }
- }, this);
- return {"type": "global", "tag": tagName, "properties": globalSiteProperties};
- },
-
- recordHostOverride: function(serviceConfigObj, siteName, tagName, self){
- if('get' in serviceConfigObj){
- return this._recordHostOverrideFromEmberObj(serviceConfigObj, siteName, tagName, self);
- }else{
- return this._recordHostOverrideFromObj(serviceConfigObj, siteName, tagName, self);
- }
- },
-
- /**
- * Records all the host overrides per site/tag
- */
- _recordHostOverrideFromObj: function(serviceConfigObj, siteName, tagName, self){
- var overrides = serviceConfigObj.overrides;
- if(overrides){
- for(var value in overrides){
- overrides[value].forEach(function(host){
- if(!(host in self.savedHostToOverrideSiteToTagMap)){
- self.savedHostToOverrideSiteToTagMap[host] = {};
- }
- if(!(siteName in self.savedHostToOverrideSiteToTagMap[host])){
- self.savedHostToOverrideSiteToTagMap[host][siteName] = {};
- self.savedHostToOverrideSiteToTagMap[host][siteName].map = {};
- }
- var finalTag = tagName + '_' + host;
- console.log("recordHostOverride(): Saving host override for host="+host+", site="+siteName+", tag="+finalTag+", (key,value)=("+serviceConfigObj.name+","+value+")");
- self.savedHostToOverrideSiteToTagMap[host][siteName].tagName = finalTag;
- self.savedHostToOverrideSiteToTagMap[host][siteName].map[serviceConfigObj.name] = value;
- });
- }
- }
- },
- /**
- * Records all the host overrides per site/tag
- */
- _recordHostOverrideFromEmberObj: function(serviceConfigObj, siteName, tagName, self){
- var overrides = serviceConfigObj.get('overrides');
- if(overrides){
- overrides.forEach(function(override){
- override.get('selectedHostOptions').forEach(function(host){
- if(!(host in self.savedHostToOverrideSiteToTagMap)){
- self.savedHostToOverrideSiteToTagMap[host] = {};
- }
- if(!(siteName in self.savedHostToOverrideSiteToTagMap[host])){
- self.savedHostToOverrideSiteToTagMap[host][siteName] = {};
- self.savedHostToOverrideSiteToTagMap[host][siteName].map = {};
- }
- var finalTag = tagName + '_' + host;
- console.log("recordHostOverride(): Saving host override for host="+host+", site="+siteName+", tag="+finalTag+", (key,value)=("+serviceConfigObj.name+","+override.get('value')+")");
- self.savedHostToOverrideSiteToTagMap[host][siteName].tagName = finalTag;
- self.savedHostToOverrideSiteToTagMap[host][siteName].map[serviceConfigObj.name] = override.get('value');
- });
- });
- }
- },
- /**
- * create core site object
- * @param tagName
- * @return {Object}
- */
- createCoreSiteObj: function (tagName) {
- var coreSiteObj = this.get('uiConfigs').filterProperty('filename', 'core-site.xml');
- var coreSiteProperties = {};
- // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
- var isOozieSelected = App.Service.find().someProperty('serviceName', 'OOZIE');
- var oozieUser = this.get('globalConfigs').someProperty('name', 'oozie_user') ? this.get('globalConfigs').findProperty('name', 'oozie_user').value : null;
- var isHiveSelected = App.Service.find().someProperty('serviceName', 'HIVE');
- var hiveUser = this.get('globalConfigs').someProperty('name', 'hive_user') ? this.get('globalConfigs').findProperty('name', 'hive_user').value : null;
- var isHcatSelected = App.Service.find().someProperty('serviceName', 'WEBHCAT');
- var hcatUser = this.get('globalConfigs').someProperty('name', 'hcat_user') ? this.get('globalConfigs').findProperty('name', 'hcat_user').value : null;
- coreSiteObj.forEach(function (_coreSiteObj) {
- if ((isOozieSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.groups')) && (isHiveSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.groups')) && (isHcatSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.groups'))) {
- coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
- this.recordHostOverride(_coreSiteObj, 'core-site', tagName, this);
- }
- }, this);
- return {"type": "core-site", "tag": tagName, "properties": coreSiteProperties};
- },
- /**
- * create site object
- * @param siteName
- * @param tagName
- * @return {Object}
- */
- createSiteObj: function (siteName, tagName) {
- var siteObj = this.get('uiConfigs').filterProperty('filename', siteName + '.xml');
- var siteProperties = {};
- if (siteName == 'oozie-site') {
- siteObj = this.getOozieSiteObj(siteObj);
- } else if (siteName == 'hive-site') {
- siteObj = this.getHiveSiteObj(siteObj);
- }
- siteObj.forEach(function (_siteObj) {
- siteProperties[_siteObj.name] = _siteObj.value;
- this.recordHostOverride(_siteObj, siteName, tagName, this);
- }, this);
- return {"type": siteName, "tag": tagName, "properties": siteProperties};
- },
- /**
- * create site object for Oozie
- * @param siteObj
- * @return {Object}
- */
- getOozieSiteObj: function (siteObj) {
- var jdbcUrl = siteObj.findProperty('name', 'oozie.service.JPAService.jdbc.url');
- var jdbcDriver = siteObj.findProperty('name', 'oozie.service.JPAService.jdbc.driver');
- var oozieDb = this.get('globalConfigs').findProperty('name', 'oozie_database').value;
- // oozieHost is undefined if the database is oozie
- var oozieHost = (oozieDb == 'New Derby Database') ? '' : this.get('globalConfigs').findProperty('name', 'oozie_hostname').value;
- var oozieDbName = this.get('globalConfigs').findProperty('name', 'oozie_database_name').value;
- switch (oozieDb) {
- case 'New Derby Database':
- jdbcUrl.value = "jdbc:derby:${oozie.data.dir}/${oozie.db.schema.name}-db;create=true";
- jdbcDriver.value = "org.apache.derby.jdbc.EmbeddedDriver";
- break;
- case 'Existing MySQL Database':
- jdbcUrl.value = "jdbc:mysql://" + oozieHost + "/" + oozieDbName;
- jdbcDriver.value = "com.mysql.jdbc.Driver";
- break;
- case 'Existing Oracle Database':
- jdbcUrl.value = "jdbc:oracle:thin:@//" + oozieHost + ":1521/" + oozieDbName;
- jdbcDriver.value = "oracle.jdbc.driver.OracleDriver";
- break;
- }
- return siteObj;
- },
- /**
- * create site object for Hive
- * @param siteObj
- * @return {Object}
- */
- getHiveSiteObj: function (siteObj) {
- var jdbcUrl = siteObj.findProperty('name', 'javax.jdo.option.ConnectionURL');
- var jdbcDriver = siteObj.findProperty('name', 'javax.jdo.option.ConnectionDriverName');
- var hiveDb = this.get('globalConfigs').findProperty('name', 'hive_database').value;
- var hiveHost = this.get('globalConfigs').findProperty('name', 'hive_hostname').value;
- var hiveDbName = this.get('globalConfigs').findProperty('name', 'hive_database_name').value;
- switch (hiveDb) {
- case 'New MySQL Database':
- jdbcUrl.value = "jdbc:mysql://"+ hiveHost + "/" + hiveDbName + "?createDatabaseIfNotExist=true";
- jdbcDriver.value = "com.mysql.jdbc.Driver";
- break;
- case 'Existing MySQL Database':
- jdbcUrl.value = "jdbc:mysql://"+ hiveHost + "/" + hiveDbName + "?createDatabaseIfNotExist=true";
- jdbcDriver.value = "com.mysql.jdbc.Driver";
- break;
- case 'Existing Oracle Database':
- jdbcUrl.value = "jdbc:oracle:thin:@//"+ hiveHost + ":1521/" + hiveDbName;
- jdbcDriver.value = "oracle.jdbc.driver.OracleDriver";
- break;
- }
- return siteObj;
- },
- /**
- * Set display names of the property from the puppet/global names
- * @param: displayNames: a field to be set with displayNames
- * @param names: array of property puppet/global names
- */
- setPropertyDisplayNames: function (displayNames, names) {
- var stepConfigs = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName')).configs;
- names.forEach(function (_name, index) {
- if (stepConfigs.someProperty('name', _name)) {
- displayNames.push(stepConfigs.findProperty('name', _name).displayName);
- }
- }, this);
- },
- /**
- * Set property of the site variable
- */
- setSiteProperty: function (key, value, filename) {
- if (filename === 'core-site.xml' && this.get('uiConfigs').filterProperty('filename', 'core-site.xml').someProperty('name', key)) {
- this.get('uiConfigs').filterProperty('filename', 'core-site.xml').findProperty('name', key).value = value;
- return;
- }
- this.get('uiConfigs').pushObject({
- "id": "site property",
- "name": key,
- "value": value,
- "filename": filename
- });
- },
- /**
- * return either specific url for request if testMode is false or testUrl
- * @param testUrl
- * @param url
- * @return {*}
- */
- getUrl: function (testUrl, url) {
- return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + App.router.getClusterName() + url;
- },
- /**
- * Adds host name of master component to global config;
- */
- addHostNamesToGlobalConfig: function () {
- var serviceName = this.get('content.serviceName');
- var globalConfigs = this.get('globalConfigs');
- var serviceConfigs = this.get('serviceConfigs').findProperty('serviceName', serviceName).configs;
- //namenode_host is required to derive "fs.default.name" a property of core-site
- var nameNodeHost = this.get('serviceConfigs').findProperty('serviceName', 'HDFS').configs.findProperty('name', 'namenode_host');
- try {
- nameNodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'NAMENODE').get('host.hostName');
- globalConfigs.push(nameNodeHost);
- } catch (err) {
- console.log("No NameNode Host available. This is expected if you're using HCFS rather than HDFS.");
- }
- //zooKeeperserver_host
- var zooKeperHost = this.get('serviceConfigs').findProperty('serviceName', 'ZOOKEEPER').configs.findProperty('name', 'zookeeperserver_hosts');
- if (serviceName === 'ZOOKEEPER' || serviceName === 'HBASE' || serviceName === 'WEBHCAT') {
- zooKeperHost.defaultValue = App.Service.find('ZOOKEEPER').get('hostComponents').filterProperty('componentName', 'ZOOKEEPER_SERVER').mapProperty('host.hostName');
- globalConfigs.push(zooKeperHost);
- }
- switch (serviceName) {
- case 'HDFS':
- var sNameNodeHost = serviceConfigs.findProperty('name', 'snamenode_host');
- sNameNodeHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'SECONDARY_NAMENODE').get('host.hostName');
- globalConfigs.push(sNameNodeHost);
- break;
- case 'MAPREDUCE':
- var jobTrackerHost = serviceConfigs.findProperty('name', 'jobtracker_host');
- jobTrackerHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'JOBTRACKER').get('host.hostName');
- globalConfigs.push(jobTrackerHost);
- break;
- case 'HIVE':
- var hiveMetastoreHost = serviceConfigs.findProperty('name', 'hivemetastore_host');
- hiveMetastoreHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'HIVE_SERVER').get('host.hostName');
- globalConfigs.push(hiveMetastoreHost);
- var hiveDb = globalConfigs.findProperty('name', 'hive_database').value;
- if (['Existing MySQL Database', 'Existing Oracle Database'].contains(hiveDb)) {
- globalConfigs.findProperty('name', 'hive_hostname').isVisible = true;
- }
- break;
- case 'OOZIE':
- var oozieServerHost = serviceConfigs.findProperty('name', 'oozieserver_host');
- oozieServerHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
- globalConfigs.push(oozieServerHost);
- var oozieDb = globalConfigs.findProperty('name', 'oozie_database').value;
- if (['Existing MySQL Database', 'Existing Oracle Database'].contains(oozieDb)) {
- globalConfigs.findProperty('name', 'oozie_hostname').isVisible = true;
- }
- break;
- case 'HBASE':
- var hbaseMasterHost = serviceConfigs.findProperty('name', 'hbasemaster_host');
- hbaseMasterHost.defaultValue = this.get('content.hostComponents').filterProperty('componentName', 'HBASE_MASTER').mapProperty('host.hostName');
- globalConfigs.push(hbaseMasterHost);
- break;
- case 'HUE':
- var hueServerHost = serviceConfigs.findProperty('name', 'hueserver_host');
- hueServerHost.defaultValue = this.get('content.hostComponents').findProperty('componentName', 'HUE_SERVER').get('host.hostName');
- globalConfigs.push(hueServerHost);
- break;
- case 'WEBHCAT':
- var webhcatMasterHost = serviceConfigs.findProperty('name', 'webhcatserver_host');
- webhcatMasterHost.defaultValue = this.get('content.hostComponents').filterProperty('componentName', 'WEBHCAT_SERVER').mapProperty('host.hostName');
- globalConfigs.push(webhcatMasterHost);
- break;
- }
- },
-
- /**
- * Provides service component name and display-name information for
- * the current selected service.
- */
- getCurrentServiceComponents: function () {
- var service = this.get('content');
- var components = service.get('hostComponents');
- var validComponents = Ember.A([]);
- var seenComponents = {};
- components.forEach(function(component){
- var cn = component.get('componentName');
- var cdn = component.get('displayName');
- if(!seenComponents[cn]){
- validComponents.push(Ember.Object.create({
- componentName: cn,
- displayName: cdn,
- selected: false
- }));
- seenComponents[cn] = cn;
- }
- });
- return validComponents;
- }.property('content'),
-
- getAllHosts: function () {
- return App.router.get('mainHostController.content');
- }.property('App.router.mainHostController.content'),
-
- doCancel: function () {
- this.loadStep();
- }
- });
|