123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- /**
- * 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.MainServiceItemView = Em.View.extend({
- templateName: require('templates/main/service/item'),
- serviceName: Em.computed.alias('controller.content.serviceName'),
- displayName: Em.computed.alias('controller.content.displayName'),
- isPassive: Em.computed.equal('controller.content.passiveState', 'ON'),
- /**
- * Some custom commands need custom logic to be executed
- */
- mastersExcludedCommands: {
- 'NAMENODE': ['DECOMMISSION', 'REBALANCEHDFS'],
- 'RESOURCEMANAGER': ['DECOMMISSION', 'REFRESHQUEUES'],
- 'HBASE_MASTER': ['DECOMMISSION'],
- 'KNOX_GATEWAY': ['STARTDEMOLDAP','STOPDEMOLDAP'],
- 'HAWQMASTER': ['IMMEDIATE_STOP_CLUSTER']
- },
- addActionMap: function() {
- return [
- {
- cssClass: 'icon-plus',
- 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.hbase.masterServer')),
- service: 'HBASE',
- component: 'HBASE_MASTER'
- },
- {
- cssClass: 'icon-plus',
- 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.hive.metastore')),
- service: 'HIVE',
- component: 'HIVE_METASTORE',
- isHidden: !App.get('isHadoop22Stack')
- },
- {
- cssClass: 'icon-plus',
- 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.hive.server2')),
- service: 'HIVE',
- component: 'HIVE_SERVER',
- isHidden: !App.get('isHadoop22Stack')
- },
- {
- cssClass: 'icon-plus',
- 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.zookeeper.server')),
- service: 'ZOOKEEPER',
- component: 'ZOOKEEPER_SERVER'
- },
- {
- cssClass: 'icon-plus',
- 'label': '{0} {1}'.format(Em.I18n.t('add'), Em.I18n.t('dashboard.services.flume.agentLabel')),
- service: 'FLUME',
- component: 'FLUME_HANDLER'
- },
- {
- cssClass: 'icon-plus',
- 'label': '{0} {1}'.format(Em.I18n.t('add'), App.format.role('RANGER_KMS_SERVER')),
- service: 'RANGER_KMS',
- component: 'RANGER_KMS_SERVER'
- },
- {
- cssClass: 'icon-plus',
- 'label': '{0} {1}'.format(Em.I18n.t('add'), App.format.role('NIMBUS')),
- service: 'STORM',
- component: 'NIMBUS'
- }
- ]
- },
- /**
- * Create option for MOVE_COMPONENT or ROLLING_RESTART task.
- *
- * @param {Object} option - one of the options that return by <code>App.HostComponentActionMap.getMap()</code>
- * @param {Object} fields - option fields to add/rewrite
- * @return {Object}
- */
- createOption: function(option, fields) {
- return $.extend(true, {}, option, fields);
- },
- maintenance: [],
- isMaintenanceSet: false,
- observeMaintenance: function() {
- if (!this.get('isMaintenanceSet') && this.get('controller.isServicesInfoLoaded')) {
- this.observeMaintenanceOnce();
- }
- Em.run.once(this, 'clearIsMaintenanceSet');
- },
- observeMaintenanceOnce: function() {
- var self = this;
- var options = [];
- var service = this.get('controller.content');
- var allMasters = service.get('hostComponents').filterProperty('isMaster').mapProperty('componentName').uniq();
- var allSlaves = service.get('slaveComponents').rejectProperty('totalCount', 0).mapProperty('componentName');
- var actionMap = App.HostComponentActionMap.getMap(this);
- var serviceCheckSupported = App.get('services.supportsServiceCheck').contains(service.get('serviceName'));
- var hasConfigTab = this.get('hasConfigTab');
- var excludedCommands = this.get('mastersExcludedCommands');
- if (this.get('controller.isClientsOnlyService')) {
- if (serviceCheckSupported) {
- options.push(actionMap.RUN_SMOKE_TEST);
- }
- if (hasConfigTab) {
- options.push(actionMap.REFRESH_CONFIGS);
- }
- } else {
- if (this.get('serviceName') === 'FLUME') {
- options.push(actionMap.REFRESH_CONFIGS);
- }
- if (this.get('serviceName') === 'YARN') {
- options.push(actionMap.REFRESHQUEUES);
- }
- options.push(actionMap.RESTART_ALL);
- allSlaves.concat(allMasters).filter(function (_component) {
- return App.get('components.rollinRestartAllowed').contains(_component);
- }).forEach(function(_component) {
- options.push(self.createOption(actionMap.ROLLING_RESTART, {
- context: _component,
- label: actionMap.ROLLING_RESTART.label.format(App.format.role(_component))
- }));
- });
- allMasters.filter(function(master) {
- return App.get('components.reassignable').contains(master);
- }).forEach(function(master) {
- options.push(self.createOption(actionMap.MOVE_COMPONENT, {
- context: master,
- label: actionMap.MOVE_COMPONENT.label.format(App.format.role(master)),
- disabled: App.allHostNames.length === App.HostComponent.find().filterProperty('componentName', master).mapProperty('hostName').length
- }));
- });
- if (service.get('serviceTypes').contains('HA_MODE') && App.isAuthorized('SERVICE.ENABLE_HA')) {
- switch (service.get('serviceName')) {
- case 'HDFS':
- options.push(actionMap.TOGGLE_NN_HA);
- break;
- case 'YARN':
- options.push(actionMap.TOGGLE_RM_HA);
- break;
- case 'RANGER':
- options.push(actionMap.TOGGLE_RA_HA);
- break;
- }
- }
- if (serviceCheckSupported) {
- options.push(actionMap.RUN_SMOKE_TEST);
- }
- options.push(actionMap.TOGGLE_PASSIVE);
- var serviceName = service.get('serviceName');
- var nnComponent = App.StackServiceComponent.find().findProperty('componentName','NAMENODE');
- var knoxGatewayComponent = App.StackServiceComponent.find().findProperty('componentName','KNOX_GATEWAY');
- if (serviceName === 'HDFS' && nnComponent) {
- var namenodeCustomCommands = nnComponent.get('customCommands');
- if (namenodeCustomCommands && namenodeCustomCommands.contains('REBALANCEHDFS'))
- options.push(actionMap.REBALANCEHDFS);
- }
- if (serviceName === 'KNOX' && knoxGatewayComponent) {
- var knoxGatewayCustomCommands = knoxGatewayComponent.get('customCommands');
- knoxGatewayCustomCommands.forEach(function(command) {
- if (actionMap[command]) {
- options.push(actionMap[command]);
- }
- });
- }
- var hawqMasterComponent = App.StackServiceComponent.find().findProperty('componentName','HAWQMASTER');
- if (serviceName === 'HAWQ' && hawqMasterComponent) {
- var hawqMasterCustomCommands = hawqMasterComponent.get('customCommands');
- customCommandToStopCluster = 'IMMEDIATE_STOP_CLUSTER';
- if (hawqMasterCustomCommands && hawqMasterCustomCommands.contains(customCommandToStopCluster)) {
- options.push(self.createOption(actionMap.IMMEDIATE_STOP_CLUSTER, {
- label: Em.I18n.t('services.service.actions.run.immediateStopHawqCluster.context'),
- context: {
- label: Em.I18n.t('services.service.actions.run.immediateStopHawqCluster.context'),
- service: hawqMasterComponent.get('serviceName'),
- component: hawqMasterComponent.get('componentName'),
- command: customCommandToStopCluster
- }
- })) };
- }
- self.addActionMap().filterProperty('service', serviceName).forEach(function(item) {
- if (App.get('components.addableToHost').contains(item.component)) {
- item.action = 'add' + item.component;
- item.disabled = self.get('controller.isAddDisabled-' + item.component);
- item.tooltip = self.get('controller.addDisabledTooltip' + item.component);
- options.push(item);
- }
- });
- allMasters.forEach(function(master) {
- var component = App.StackServiceComponent.find(master);
- var commands = component.get('customCommands');
- if (!commands.length) {
- return false;
- }
- commands.forEach(function(command) {
- if (excludedCommands[master] && excludedCommands[master].contains(command)){
- return false;
- }
- options.push(self.createOption(actionMap.MASTER_CUSTOM_COMMAND, {
- label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(App.format.normalizeNameBySeparators(command, ["_", "-", " "])),
- context: {
- label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(App.format.normalizeNameBySeparators(command, ["_", "-", " "])),
- service: component.get('serviceName'),
- component: component.get('componentName'),
- command: command
- }
- }));
- });
- });
- }
- if (hasConfigTab) {
- options.push(actionMap.DOWNLOAD_CLIENT_CONFIGS);
- }
- if (this.get('maintenance.length')) {
- this.get('maintenance').forEach(function(option, index) {
- if (JSON.stringify(option) != JSON.stringify(options[index])) {
- self.get('maintenance').removeAt(index).insertAt(index, options[index]);
- }
- });
- options.forEach(function(opt, index) {
- if (JSON.stringify(opt) != JSON.stringify(self.get('maintenance')[index])) {
- self.get('maintenance').pushObject(opt);
- }
- });
- } else {
- this.set('maintenance', options);
- }
- this.set('isMaintenanceSet', true);
- },
- clearIsMaintenanceSet: function () {
- this.set('isMaintenanceSet', false);
- },
- isMaintenanceActive: function() {
- return this.get('state') !== 'inDOM' || this.get('maintenance').length !== 0;
- }.property('maintenance'),
- hasConfigTab: function() {
- return App.isAuthorized('CLUSTER.VIEW_CONFIGS') && !App.get('services.noConfigTypes').contains(this.get('controller.content.serviceName'));
- }.property('controller.content.serviceName','App.services.noConfigTypes'),
- hasHeatmapTab: function() {
- return App.get('services.servicesWithHeatmapTab').contains(this.get('controller.content.serviceName'));
- }.property('controller.content.serviceName', 'App.services.servicesWithHeatmapTab'),
- didInsertElement: function () {
- this.get('controller').setStartStopState();
- },
- maintenanceObsFields: ['isStopDisabled', 'isClientsOnlyService', 'content.isRestartRequired', 'isServicesInfoLoaded'],
- willInsertElement: function () {
- var self = this;
- this.get('maintenanceObsFields').forEach(function (field) {
- self.addObserver('controller.' + field, self, 'observeMaintenance');
- });
- },
- willDestroyElement: function() {
- var self = this;
- this.get('maintenanceObsFields').forEach(function (field) {
- self.removeObserver('controller.' + field, self, 'observeMaintenance');
- });
- },
- service:function () {
- var svc = this.get('controller.content');
- var svcName = svc.get('serviceName');
- if (svcName) {
- switch (svcName.toLowerCase()) {
- case 'hdfs':
- svc = App.HDFSService.find().objectAt(0);
- break;
- case 'yarn':
- svc = App.YARNService.find().objectAt(0);
- break;
- case 'hbase':
- svc = App.HBaseService.find().objectAt(0);
- break;
- case 'flume':
- svc = App.FlumeService.find().objectAt(0);
- break;
- default:
- break;
- }
- }
- return svc;
- }.property('controller.content.serviceName').volatile()
- });
|