12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628 |
- /**
- * 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(var 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 = {};
- coreSiteObj.forEach(function (_coreSiteObj) {
- 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 derby
- 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;
- var defaultJdbcUrl;
- switch (oozieDb) {
- case 'New Derby Database':
- defaultJdbcUrl = "jdbc:derby:${oozie.data.dir}/${oozie.db.schema.name}-db;create=true";
- jdbcDriver.value = "org.apache.derby.jdbc.EmbeddedDriver";
- break;
- case 'Existing MySQL Database':
- defaultJdbcUrl = "jdbc:mysql://" + oozieHost + "/" + oozieDbName;
- jdbcDriver.value = "com.mysql.jdbc.Driver";
- break;
- case 'Existing Oracle Database':
- defaultJdbcUrl = "jdbc:oracle:thin:@//" + oozieHost + ":1521/" + oozieDbName;
- jdbcDriver.value = "oracle.jdbc.driver.OracleDriver";
- break;
- }
- // in case the user upgraded from Ambari version <= 1.2.3, they will not have oozie_jdbc_connection_url global
- var jdbcUrlInGlobal = this.get('globalConfigs').findProperty('name', 'oozie_jdbc_connection_url');
- jdbcUrl.value = jdbcUrlInGlobal ? jdbcUrlInGlobal.value : defaultJdbcUrl;
- 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;
- var defaultJdbcUrl;
- switch (hiveDb) {
- case 'New MySQL Database':
- defaultJdbcUrl = "jdbc:mysql://"+ hiveHost + "/" + hiveDbName + "?createDatabaseIfNotExist=true";
- jdbcDriver.value = "com.mysql.jdbc.Driver";
- break;
- case 'Existing MySQL Database':
- defaultJdbcUrl = "jdbc:mysql://"+ hiveHost + "/" + hiveDbName + "?createDatabaseIfNotExist=true";
- jdbcDriver.value = "com.mysql.jdbc.Driver";
- break;
- case 'Existing Oracle Database':
- defaultJdbcUrl = "jdbc:oracle:thin:@//"+ hiveHost + ":1521/" + hiveDbName;
- jdbcDriver.value = "oracle.jdbc.driver.OracleDriver";
- break;
- }
- // in case the user upgraded from Ambari <= 1.2.3, they will not have hive_jdbc_connection_url global
- var jdbcUrlInGlobal = this.get('globalConfigs').findProperty('name', 'hive_jdbc_connection_url');
- jdbcUrl.value = jdbcUrlInGlobal ? jdbcUrlInGlobal.value : defaultJdbcUrl;
- 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();
- }
- });
|