123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- /**
- * 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');
- /**
- * By Step 7, we have the following information stored in App.db and set on this
- * controller by the router.
- *
- * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
- * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
- * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
- *
- */
- App.WizardStep7Controller = Em.Controller.extend({
- name: 'wizardStep7Controller',
- stepConfigs: [], //contains all field properties that are viewed in this step
- selectedService: null,
- slaveHostToGroup: null,
- isSubmitDisabled: function () {
- return !this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0);
- }.property('stepConfigs.@each.errorCount'),
- selectedServiceNames: function () {
- return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
- }.property('content.services').cacheable(),
- allInstalledServiceNames: function () {
- return this.get('content.services').filterProperty('isSelected', true).mapProperty('serviceName');
- }.property('content.services').cacheable(),
- masterComponentHosts: function () {
- return this.get('content.masterComponentHosts');
- }.property('content.masterComponentHosts'),
- slaveComponentHosts: function () {
- return this.get('content.slaveGroupProperties');
- }.property('content.slaveGroupProperties', 'content.slaveComponentHosts'),
- serviceConfigs: require('data/service_configs'),
- configMapping: require('data/config_mapping'),
- customConfigs: require('data/custom_configs'),
- customData: [],
- clearStep: function () {
- this.get('stepConfigs').clear();
- },
- /**
- * On load function
- */
- loadStep: function () {
- console.log("TRACE: Loading step7: Configure Services");
- this.clearStep();
- var serviceConfigs = this.get('serviceConfigs');
- var advancedConfig = this.get('content.advancedServiceConfig') || [];
- this.loadAdvancedConfig(serviceConfigs, advancedConfig);
- this.loadCustomConfig();
- this.renderServiceConfigs(serviceConfigs);
- var storedServices = this.get('content.serviceConfigProperties');
- if (storedServices) {
- var configs = new Ember.Set();
- // for all services`
- this.get('stepConfigs').forEach(function (_content) {
- //for all components
- _content.get('configs').forEach(function (_config) {
- var componentVal = storedServices.findProperty('name', _config.get('name'));
- //if we have config for specified component
- if (componentVal) {
- //set it
- _config.set('value', componentVal.value)
- }
- }, this);
- }, this);
- }
- },
- /*
- Loads the advanced configs fetched from the server metadata libarary
- */
- loadAdvancedConfig: function (serviceConfigs, advancedConfig) {
- advancedConfig.forEach(function (_config) {
- if (_config) {
- var service = serviceConfigs.findProperty('serviceName', _config.serviceName);
- if (service) {
- if (this.get('configMapping').someProperty('name', _config.name)) {
- } else if (!(service.configs.someProperty('name', _config.name))) {
- _config.id = "site property";
- _config.category = 'Advanced';
- _config.displayName = _config.name;
- _config.defaultValue = _config.value;
- // make all advanced configs optional and populated by default
- /*
- if (/\${.*}/.test(_config.value) || (service.serviceName !== 'OOZIE' && service.serviceName !== 'HBASE')) {
- _config.isRequired = false;
- _config.value = '';
- } else if (/^\s+$/.test(_config.value)) {
- _config.isRequired = false;
- }
- */
- _config.isRequired = false;
- _config.isVisible = true;
- _config.displayType = 'advanced';
- service.configs.pushObject(_config);
- }
- }
- }
- }, this);
- },
- /**
- * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
- */
- loadCustomConfig: function () {
- var serviceConfigs = this.get('serviceConfigs');
- this.get('customConfigs').forEach(function (_config) {
- var service = serviceConfigs.findProperty('serviceName', _config.serviceName);
- if (service) {
- if (!(service.configs.someProperty('name', _config.name))) {
- service.configs.pushObject(_config);
- }
- }
- }, this);
- },
- /**
- * Render configs for active services
- * @param serviceConfigs
- */
- renderServiceConfigs: function (serviceConfigs) {
- serviceConfigs.forEach(function (_serviceConfig) {
- var serviceConfig = App.ServiceConfig.create({
- filename: _serviceConfig.filename,
- serviceName: _serviceConfig.serviceName,
- displayName: _serviceConfig.displayName,
- configCategories: _serviceConfig.configCategories,
- showConfig: false,
- configs: []
- });
- if (this.get('allInstalledServiceNames').contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
- this.loadComponentConfigs(_serviceConfig, serviceConfig);
- console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
- if (this.get('selectedServiceNames').contains(serviceConfig.serviceName)) {
- // AMBARI-1139 - Hiding MISC section // || serviceConfig.serviceName === 'MISC') {
- serviceConfig.showConfig = true;
- }
- this.get('stepConfigs').pushObject(serviceConfig);
- } else {
- console.log('skipping ' + serviceConfig.serviceName);
- }
- }, this);
- var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
- var showProxyGroup = this.get('selectedServiceNames').contains('HIVE') ||
- this.get('selectedServiceNames').contains('HCATALOG') ||
- this.get('selectedServiceNames').contains('OOZIE');
- miscConfigs.findProperty('name', 'proxyuser_group').set('isVisible', showProxyGroup);
- miscConfigs.findProperty('name', 'hbase_user').set('isVisible', this.get('selectedServiceNames').contains('HBASE'));
- miscConfigs.findProperty('name', 'mapred_user').set('isVisible', this.get('selectedServiceNames').contains('MAPREDUCE'));
- miscConfigs.findProperty('name', 'hive_user').set('isVisible', this.get('selectedServiceNames').contains('HIVE'));
- miscConfigs.findProperty('name', 'hcat_user').set('isVisible', this.get('selectedServiceNames').contains('HCATALOG'));
- miscConfigs.findProperty('name', 'webhcat_user').set('isVisible', this.get('selectedServiceNames').contains('WEBHCAT'));
- miscConfigs.findProperty('name', 'oozie_user').set('isVisible', this.get('selectedServiceNames').contains('OOZIE'));
- miscConfigs.findProperty('name', 'pig_user').set('isVisible', this.get('selectedServiceNames').contains('PIG'));
- miscConfigs.findProperty('name', 'sqoop_user').set('isVisible', this.get('selectedServiceNames').contains('SQOOP'));
- miscConfigs.findProperty('name', 'zk_user').set('isVisible', this.get('selectedServiceNames').contains('ZOOKEEPER'));
- this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
- },
- /**
- * Load child components to service config object
- * @param _componentConfig
- * @param componentConfig
- */
- loadComponentConfigs: function (_componentConfig, componentConfig) {
- _componentConfig.configs.forEach(function (_serviceConfigProperty) {
- var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
- serviceConfigProperty.serviceConfig = componentConfig;
- serviceConfigProperty.initialValue();
- componentConfig.configs.pushObject(serviceConfigProperty);
- serviceConfigProperty.validate();
- }, this);
- },
- validateCustomConfig: function () {
- var flag = true;
- var serviceProperties = [];
- this.get('stepConfigs').forEach(function (_serviceContent) {
- var configProperties = _serviceContent.get('configs');
- if (configProperties.someProperty('id', 'conf-site')) {
- var serviceProperty = {};
- serviceProperty.serviceName = _serviceContent.get("serviceName");
- serviceProperty.siteProperties = [];
- var customSite = configProperties.findProperty('id', 'conf-site');
- var keyValue = customSite.value.split(/\n+/);
- if (keyValue) {
- keyValue.forEach(function (_keyValue) {
- console.log("The value of the keyValue is: " + _keyValue.trim());
- _keyValue = _keyValue.trim();
- var key = _keyValue.match(/(.+)=/);
- var value = _keyValue.match(/=(.*)/);
- if (key) {
- // Check that entered config is allowed to reconfigure
- if (configProperties.someProperty('name', key[1]) || this.get('configMapping').someProperty('name', key[1])) {
- var property = {
- siteProperty: key[1],
- displayNames: [],
- displayMsg: null
- };
- if (this.get('configMapping').someProperty('name', key[1])) {
- this.setPropertyDisplayNames(property.displayNames, this.get('configMapping').findProperty('name', key[1]).templateName, configProperties);
- }
- property.displayMsg = this.setDisplayMessage(property.siteProperty, property.displayNames);
- serviceProperty.siteProperties.push(property);
- flag = false;
- }
- }
- }, this);
- }
- serviceProperties.push(serviceProperty);
- }
- }, this);
- var result = {
- flag: flag,
- value: serviceProperties
- };
- return result;
- },
- /**
- * @param: An array of display names
- */
- setDisplayMessage: function (siteProperty, displayNames) {
- var displayMsg = null;
- if (displayNames && displayNames.length) {
- if (displayNames.length === 1) {
- displayMsg = siteProperty + ' as ' + displayNames[0];
- } else {
- var name = null;
- displayNames.forEach(function (_name, index) {
- if (index === 0) {
- name = _name;
- } else if (index === displayNames.length - 1) {
- name = name + ' and ' + _name;
- } else {
- name = name + ', ' + _name;
- }
- }, this);
- displayMsg = siteProperty + ' as ' + name;
- }
- } else {
- displayMsg = siteProperty;
- }
- return displayMsg;
- },
- /**
- * Set display names of the property tfrom he puppet/global names
- * @param: displayNames: a field to be set with displayNames
- * @param names: array of property puppet/global names
- * @param configProperties: array of config properties of the respective service to the name param
- */
- setPropertyDisplayNames: function (displayNames, names, configProperties) {
- names.forEach(function (_name, index) {
- if (configProperties.someProperty('name', _name)) {
- displayNames.push(configProperties.findProperty('name', _name).displayName);
- }
- }, this);
- },
- /**
- * Display Error Message with service name, its custom configuration name and displaynames on the page
- * @param: customConfig: array with custom configuration, serviceName and displayNames relative to custom configuration
- */
- showCustomConfigErrMsg: function (customConfig) {
- App.ModalPopup.show({
- header: 'Custom configuration error: ',
- primary: 'OK',
- secondary: null,
- onPrimary: function () {
- this.hide();
- },
- bodyClass: Ember.View.extend({
- message: 'Error in custom configuration. Some properties entered in the box are already exposed on this page',
- siteProperties: customConfig,
- getDisplayMessage: function () {
- }.property('customConfig.@each.siteProperties.@each.siteProperty'),
- customConfig: customConfig,
- template: Ember.Handlebars.compile([
- '<h5>{{view.message}}</h5>',
- '<br/>',
- '<div class="pre-scrollable" style="max-height: 250px;">',
- '<ul>',
- '{{#each val in view.customConfig}}',
- '{{#if val.siteProperties}}',
- '<li>',
- '{{val.serviceName}}',
- '<ul>',
- '{{#each item in val.siteProperties}}',
- '<li>',
- '{{item.displayMsg}}',
- '</li>',
- '{{/each}}',
- '</ul>',
- '</li>',
- '{{/if}}',
- '{{/each}}',
- '</ul>',
- '</div>'
- ].join('\n'))
- })
- });
- },
- submit: function () {
- if (!this.get('isSubmitDisabled')) {
- App.router.send('next');
- /*
- var result = {};
- result = this.validateCustomConfig();
- if (result.flag === true) {
- App.router.send('next');
- } else {
- this.showCustomConfigErrMsg(result.value);
- }
- */
- }
- }
- });
|