123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- /**
- * 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.MainAdminHighAvailabilityController = Em.Controller.extend({
- name: 'mainAdminHighAvailabilityController',
- securityEnabled: false,
- tag: null,
- dataIsLoaded: false,
- /**
- * enable High Availability
- * @return {Boolean}
- */
- enableHighAvailability: function () {
- var message = [];
- var hostComponents = App.HostComponent.find();
- //Prerequisite Checks
- if (this.get('securityEnabled')) {
- this.showErrorPopup(Em.I18n.t('admin.highAvailability.error.security'));
- return false;
- } else {
- if (hostComponents.findProperty('componentName', 'NAMENODE').get('workStatus') !== 'STARTED') {
- message.push(Em.I18n.t('admin.highAvailability.error.namenodeStarted'));
- }
- if (hostComponents.filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) {
- message.push(Em.I18n.t('admin.highAvailability.error.zooKeeperNum'));
- }
- if (App.router.get('mainHostController.hostsCountMap.TOTAL') < 3) {
- message.push(Em.I18n.t('admin.highAvailability.error.hostsNum'));
- }
- if (message.length > 0) {
- this.showErrorPopup(message);
- return false;
- }
- }
- App.router.transitionTo('main.admin.enableHighAvailability');
- return true;
- },
- disableHighAvailability: function () {
- App.router.transitionTo('main.admin.rollbackHighAvailability');
- },
- /**
- * enable ResourceManager High Availability
- * @return {Boolean}
- */
- enableRMHighAvailability: function () {
- //Prerequisite Checks
- var message = [];
- if (App.HostComponent.find().filterProperty('componentName', 'ZOOKEEPER_SERVER').length < 3) {
- message.push(Em.I18n.t('admin.rm_highAvailability.error.zooKeeperNum'));
- }
- if (App.router.get('mainHostController.hostsCountMap.TOTAL') < 3) {
- message.push(Em.I18n.t('admin.rm_highAvailability.error.hostsNum'));
- }
- if (message.length > 0) {
- this.showErrorPopup(message);
- return false;
- }
- App.router.transitionTo('main.admin.enableRMHighAvailability');
- return true;
- },
- setSecurityStatus: function () {
- if (App.testMode) {
- this.set('securityEnabled', !App.testEnableSecurity);
- this.set('dataIsLoaded', true);
- } else {
- //get Security Status From Server
- App.ajax.send({
- name: 'admin.security_status',
- sender: this,
- success: 'getSecurityStatusFromServerSuccessCallback',
- error: 'errorCallback'
- });
- }
- },
- errorCallback: function () {
- this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
- },
- getSecurityStatusFromServerSuccessCallback: function (data) {
- var configs = data.Clusters.desired_configs;
- if ('hadoop-env' in configs) {
- this.set('tag', configs['hadoop-env'].tag);
- this.getServiceConfigsFromServer();
- } else {
- this.showErrorPopup(Em.I18n.t('admin.security.status.error'));
- }
- },
- /**
- * get service configs from server and
- * indicate whether security is enabled
- */
- getServiceConfigsFromServer: function () {
- var self = this;
- var tags = [
- {
- siteName: "hadoop-env",
- tagName: this.get('tag')
- }
- ];
- App.router.get('configurationController').getConfigsByTags(tags).done(function (data) {
- var configs = data.findProperty('tag', self.get('tag')).properties;
- var securityEnabled = !!(configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true));
- self.set('securityEnabled', securityEnabled);
- self.set('dataIsLoaded', true);
- });
- },
- /**
- * join or wrap message depending on whether it is array or string
- * @param message
- * @return {*}
- */
- joinMessage: function (message) {
- if (Array.isArray(message)) {
- return message.join('<br/>');
- } else {
- return '<p>' + message + '</p>';
- }
- },
- showErrorPopup: function (message) {
- message = this.joinMessage(message);
- App.ModalPopup.show({
- header: Em.I18n.t('common.error'),
- bodyClass: Ember.View.extend({
- template: Ember.Handlebars.compile(message)
- }),
- secondary: false
- });
- }
- });
|