123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- /**
- * 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');
- App.MainAdminSecurityAddStep4Controller = App.MainAdminSecurityProgressController.extend({
- name: 'mainAdminSecurityAddStep4Controller',
- serviceUsersBinding: 'App.router.mainAdminSecurityController.serviceUsers',
- secureServices: function() {
- return this.get('content.services');
- }.property('content.services'),
- isBackBtnDisabled: function () {
- return !this.get('stages').someProperty('isError', true);
- }.property('stages.@each.isCompleted'),
- isOozieSelected: function () {
- return this.get('secureServices').someProperty('serviceName', 'OOZIE');
- }.property('secureServices'),
- isHiveSelected: function () {
- return this.get('secureServices').someProperty('serviceName', 'HIVE');
- }.property('secureServices'),
- isNagiosSelected: function () {
- return this.get('secureServices').someProperty('serviceName', 'NAGIOS');
- }.property('secureServices'),
- isZkSelected: function () {
- return this.get('secureServices').someProperty('serviceName', 'ZOOKEEPER');
- }.property('secureServices'),
- isWebHcatSelected: function () {
- var installedServices = App.Service.find().mapProperty('serviceName');
- return installedServices.contains('WEBHCAT');
- },
- isSecurityApplied: function () {
- return this.get('stages').someProperty('stage', 'stage3') && this.get('stages').findProperty('stage', 'stage3').get('isSuccess');
- }.property('stages.@each.isCompleted'),
- clearStep: function () {
- this.get('stages').clear();
- this.set('isSubmitDisabled', true);
- this.set('isBackBtnDisabled', true);
- this.get('serviceConfigTags').clear();
- },
- loadStep: function () {
- this.set('secureMapping', require('data/secure_mapping').slice(0));
- this.clearStep();
- var stages = App.db.getSecurityDeployStages();
- this.prepareSecureConfigs();
- if (stages && stages.length > 0) {
- stages.forEach(function (_stage, index) {
- stages[index] = App.Poll.create(_stage);
- }, this);
- if (stages.someProperty('isError', true)) {
- this.get('stages').pushObjects(stages);
- this.addObserver('stages.@each.isSuccess', this, 'onCompleteStage');
- return;
- } else if (stages.filterProperty('isStarted', true).someProperty('isCompleted', false)) {
- var runningStage = stages.filterProperty('isStarted', true).findProperty('isCompleted', false);
- runningStage.set('isStarted', false);
- this.get('stages').pushObjects(stages);
- } else {
- this.get('stages').pushObjects(stages);
- }
- } else {
- this.loadStages();
- this.addInfoToStages();
- var runningOperations = App.router.get('backgroundOperationsController.services').filterProperty('isRunning');
- var stopAllOperation = runningOperations.findProperty('name', 'Stop All Services');
- var stopStage = this.get('stages').findProperty('name', 'STOP_SERVICES');
- if (stopStage.get('name') === 'STOP_SERVICES' && stopAllOperation) {
- stopStage.set('requestId', stopAllOperation.get('id'));
- }
- }
- this.addObserver('stages.@each.isSuccess', this, 'onCompleteStage');
- this.moveToNextStage();
- },
- enableSubmit: function () {
- var addSecurityController = App.router.get('addSecurityController');
- if (this.get('stages').someProperty('isError', true) || this.get('stages').everyProperty('isSuccess', true)) {
- this.set('isSubmitDisabled', false);
- if (this.get('stages').someProperty('isError', true)) {
- addSecurityController.setStepsEnable();
- }
- } else {
- this.set('isSubmitDisabled', true);
- addSecurityController.setLowerStepsDisable(4);
- }
- }.observes('stages.@each.isCompleted'),
- loadUiSideConfigs: function () {
- var uiConfig = [];
- var configs = this.get('secureMapping').filterProperty('foreignKey', null);
- configs.forEach(function (_config) {
- var value = _config.value;
- if (_config.hasOwnProperty('dependedServiceName')) {
- value = this.checkServiceForConfigValue(value, _config.dependedServiceName);
- }
- value = this.getGlobConfigValue(_config.templateName, value, _config.name);
- uiConfig.pushObject({
- "id": "site property",
- "name": _config.name,
- "value": value,
- "filename": _config.filename
- });
- }, this);
- var dependentConfig = this.get('secureMapping').filterProperty('foreignKey');
- dependentConfig.forEach(function (_config) {
- if (App.Service.find().mapProperty('serviceName').contains(_config.serviceName)) {
- this.setConfigValue(uiConfig, _config);
- uiConfig.pushObject({
- "id": "site property",
- "name": _config._name || _config.name,
- "value": _config.value,
- "filename": _config.filename
- });
- }
- }, this);
- return uiConfig;
- },
- checkServiceForConfigValue: function (value, serviceNames) {
- serviceNames.forEach(function (_serviceName) {
- if (!App.Service.find().mapProperty('serviceName').contains(_serviceName.name)) {
- value = value.replace(_serviceName.replace, '');
- }
- }, this);
- return value;
- },
- /**
- * Set all site property that are derived from other puppet-variable
- */
- getGlobConfigValue: function (templateName, expression, name) {
- var express = expression.match(/<(.*?)>/g);
- var value = expression;
- if (express == null) {
- return expression;
- }
- express.forEach(function (_express) {
- //console.log("The value of template is: " + _express);
- var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
- var globValue = this.get('globalProperties').findProperty('name', templateName[index]);
- if (globValue) {
- console.log('The template value of templateName ' + '[' + index + ']' + ': ' + templateName[index] + ' is: ' + globValue);
- 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
- value = value.replace(_express, globValue.value);
- }
- } else {
- /*
- console.log("ERROR: The variable name is: " + templateName[index]);
- console.log("ERROR: mapped config from secureMapping 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);
- return value;
- },
- /**
- * Set all site property that are derived from other site-properties
- */
- setConfigValue: function (uiConfig, config) {
- if (config.value == null) {
- return;
- }
- var fkValue = config.name.match(/<(foreignKey.*?)>/g);
- if (fkValue) {
- fkValue.forEach(function (_fkValue) {
- var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
- var globalValue;
- if (uiConfig.someProperty('name', config.foreignKey[index])) {
- globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
- config._name = config.name.replace(_fkValue, globalValue);
- } else if (this.get('globalProperties').someProperty('name', config.foreignKey[index])) {
- globalValue = this.get('globalProperties').findProperty('name', config.foreignKey[index]).value;
- config._name = config.name.replace(_fkValue, globalValue);
- }
- }, this);
- }
- //For properties in the configMapping file having foreignKey and templateName properties.
- var templateValue = config.value.match(/<(templateName.*?)>/g);
- if (templateValue) {
- templateValue.forEach(function (_value) {
- var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
- var globValue = this.get('globalProperties').findProperty('name', config.templateName[index]);
- if (globValue) {
- config.value = config.value.replace(_value, globValue.value);
- } else {
- config.value = null;
- }
- }, this);
- }
- },
- prepareSecureConfigs: function () {
- this.loadGlobals();
- var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property');
- var uiConfigs = this.loadUiSideConfigs();
- this.set('configs', storedConfigs.concat(uiConfigs));
- },
- loadGlobals: function () {
- var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
- this.set('globalProperties', globals);
- this.loadStaticGlobal(); //Hack for properties which are declared in global_properties.js and not able to retrieve values declared in secure_properties.js
- this.loadUsersToGlobal();
- this.loadHostNamesToGlobal();
- this.loadPrimaryNamesToGlobals();
- },
- loadUsersToGlobal: function () {
- if (!this.get('serviceUsers').length) {
- this.loadUsersFromServer();
- }
- App.router.get('mainAdminSecurityController.serviceUsers').forEach(function (_user) {
- this.get('globalProperties').pushObject(_user);
- }, this);
- },
- loadHostNamesToGlobal: function () {
- var oozieHostComponent = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER');
- if (this.get('isOozieSelected') && oozieHostComponent) {
- var oozieHostName = oozieHostComponent.get('host.hostName');
- this.get('globalProperties').pushObject({
- id: 'puppet var',
- name: 'oozieserver_host',
- value: oozieHostName
- });
- }
- var hiveHostComponent = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_METASTORE');
- if (this.get('isHiveSelected') && hiveHostComponent) {
- var hiveHostName = hiveHostComponent.get('host.hostName');
- this.get('globalProperties').pushObject({
- id: 'puppet var',
- name: 'hivemetastore_host',
- value: hiveHostName
- });
- }
- var webHcatComponent = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER');
- if (this.isWebHcatSelected() && webHcatComponent) {
- var webHcatHostName = webHcatComponent.get('host.hostName');
- this.get('globalProperties').pushObject({
- id: 'puppet var',
- name: 'webhcat_server',
- value: webHcatHostName
- });
- }
- },
- loadStaticGlobal: function () {
- var globalProperties = this.get('globalProperties');
- this.get('globalProperties').forEach(function (_property) {
- switch (_property.name) {
- case 'security_enabled':
- _property.value = 'true';
- break;
- }
- }, this);
- },
- loadPrimaryNamesToGlobals: function () {
- var principalProperties = this.getPrincipalNames();
- principalProperties.forEach(function (_principalProperty) {
- var name = _principalProperty.name.replace('principal', 'primary');
- var value = _principalProperty.value.split('/')[0];
- this.get('globalProperties').pushObject({name: name, value: value});
- }, this);
- },
- getPrincipalNames: function () {
- var principalNames = [];
- var allPrincipalNames = [];
- this.get('globalProperties').forEach(function (_globalProperty) {
- if (/principal_name?$/.test(_globalProperty.name)) {
- principalNames.pushObject(_globalProperty);
- }
- }, this);
- this.get('secureProperties').forEach(function (_secureProperty) {
- if (/principal_name?$/.test(_secureProperty.name)) {
- var principalName = principalNames.findProperty('name', _secureProperty.name);
- if (!principalName) {
- _secureProperty.value = _secureProperty.defaultValue;
- principalNames.pushObject(_secureProperty);
- }
- }
- }, this);
- return principalNames;
- },
- loadUsersFromServer: function () {
- if (App.testMode) {
- var serviceUsers = this.get('serviceUsers');
- serviceUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
- serviceUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
- serviceUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
- serviceUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
- } else {
- App.router.set('mainAdminSecurityController.serviceUsers', App.db.getSecureUserInfo());
- }
- },
- manageSecureConfigs: function () {
- try {
- this.get('serviceConfigTags').forEach(function (_serviceConfigTags) {
- _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
- if (_serviceConfigTags.siteName === 'global') {
- var realmName = this.get('globalProperties').findProperty('name', 'kerberos_domain');
- if (this.get('isNagiosSelected')) {
- var nagiosPrincipalName = this.get('globalProperties').findProperty('name', 'nagios_principal_name');
- nagiosPrincipalName.value = nagiosPrincipalName.value + '@' + realmName.value;
- }
- if (this.get('isZkSelected')) {
- var zkPrincipalName = this.get('globalProperties').findProperty('name', 'zookeeper_principal_name');
- zkPrincipalName.value = zkPrincipalName.value + '@' + realmName.value;
- }
- this.get('globalProperties').forEach(function (_globalProperty) {
- if (!/_hosts?$/.test(_globalProperty.name)) {
- _serviceConfigTags.configs[_globalProperty.name] = _globalProperty.value;
- }
- }, this);
- }
- else {
- this.get('configs').filterProperty('id', 'site property').filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
- _serviceConfigTags.configs[_config.name] = _config.value;
- }, this);
- }
- }, this);
- } catch (err) {
- var stage3 = this.get('stages').findProperty('stage', 'stage3');
- if (stage3) {
- stage3.set('isSuccess', false);
- stage3.set('isError', true);
- }
- if (err) {
- console.log("Error: Error occurred while applying secure configs to the server. Error message: " + err);
- }
- this.onJsError();
- return false;
- }
- return true;
- },
- onJsError: function () {
- App.ModalPopup.show({
- header: Em.I18n.t('common.error'),
- secondary: false,
- onPrimary: function () {
- this.hide();
- },
- bodyClass: Ember.View.extend({
- template: Ember.Handlebars.compile('<p>{{t admin.security.apply.configuration.error}}</p>')
- })
- });
- }
- });
|