123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
- /**
- * 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');
- var validator = require('utils/validator');
- var componentHelper = require('utils/component');
- var batchUtils = require('utils/batch_scheduled_requests');
- App.MainHostController = Em.ArrayController.extend({
- name:'mainHostController',
- content: App.Host.find(),
- clearFilters: null,
- /**
- * Components which will be shown in component filter
- * @returns {Array}
- */
- componentsForFilter:function() {
- var installedComponents = componentHelper.getInstalledComponents();
- installedComponents.setEach('checkedForHostFilter', false);
- return installedComponents;
- }.property('App.router.clusterController.isLoaded'),
- /**
- * Master components
- * @returns {Array}
- */
- masterComponents:function () {
- return this.get('componentsForFilter').filterProperty('isMaster', true);
- }.property('componentsForFilter'),
- /**
- * Slave components
- * @returns {Array}
- */
- slaveComponents:function () {
- return this.get('componentsForFilter').filterProperty('isSlave', true);
- }.property('componentsForFilter'),
- /**
- * Client components
- * @returns {Array}
- */
- clientComponents: function() {
- return this.get('componentsForFilter').filterProperty('isClient', true);
- }.property('componentsForFilter'),
- /**
- * Filter hosts by componentName of <code>component</code>
- * @param {App.HostComponent} component
- */
- filterByComponent:function (component) {
- if(!component)
- return;
- var id = component.get('componentName');
- var column = 6;
- this.get('componentsForFilter').setEach('checkedForHostFilter', false);
- var filterForComponent = {
- iColumn: column,
- value: id,
- type: 'multiple'
- };
- App.db.setFilterConditions(this.get('name'), [filterForComponent]);
- },
- /**
- * On click callback for delete button
- */
- deleteButtonPopup:function () {
- var self = this;
- App.showConfirmationPopup(function(){
- self.removeHosts();
- });
- },
- showAlertsPopup: function (event) {
- var host = event.context;
- App.router.get('mainAlertsController').loadAlerts(host.get('hostName'), "HOST");
- App.ModalPopup.show({
- header: this.t('services.alerts.headingOfList'),
- bodyClass: Ember.View.extend({
- templateName: require('templates/main/host/alerts_popup'),
- controllerBinding: 'App.router.mainAlertsController',
- alerts: function () {
- return this.get('controller.alerts');
- }.property('controller.alerts'),
- closePopup: function () {
- this.get('parentView').hide();
- }
- }),
- primary: Em.I18n.t('common.close'),
- secondary : null,
- didInsertElement: function () {
- this.$().find('.modal-footer').addClass('align-center');
- this.$().children('.modal').css({'margin-top': '-350px'});
- }
- });
- event.stopPropagation();
- },
- /**
- * remove selected hosts
- */
- removeHosts:function () {
- var hosts = this.get('content');
- var selectedHosts = hosts.filterProperty('isChecked', true);
- selectedHosts.forEach(function (_hostInfo) {
- console.log('Removing: ' + _hostInfo.hostName);
- });
- this.get('fullContent').removeObjects(selectedHosts);
- },
- /**
- * remove hosts with id equal host_id
- * @param {String} host_id
- */
- checkRemoved:function (host_id) {
- var hosts = this.get('content');
- var selectedHosts = hosts.filterProperty('id', host_id);
- this.get('fullContent').removeObjects(selectedHosts);
- },
- /**
- * Bulk operation wrapper
- * @param {Object} operationData - data about bulk operation (action, hosts or hostComponents etc)
- * @param {Array} hosts - list of affected hosts
- */
- bulkOperation: function(operationData, hosts) {
- if (operationData.componentNameFormatted) {
- if (operationData.action === 'RESTART') {
- this.bulkOperationForHostComponentsRestart(operationData, hosts);
- }
- else {
- if (operationData.action === 'PASSIVE_STATE') {
- this.bulkOperationForHostComponentsPassiveState(operationData, hosts);
- }
- else {
- if (operationData.action.indexOf('DECOMMISSION') != -1) {
- this.bulkOperationForHostComponentsDecommission(operationData, hosts);
- }
- else {
- this.bulkOperationForHostComponents(operationData, hosts);
- }
- }
- }
- }
- else {
- if (operationData.action === 'RESTART') {
- this.bulkOperationForHostsRestart(operationData, hosts);
- }
- else {
- if (operationData.action === 'PASSIVE_STATE') {
- this.bulkOperationForHostsPassiveState(operationData, hosts);
- }
- else {
- this.bulkOperationForHosts(operationData, hosts);
- }
- }
- }
- },
- /**
- * Bulk operation (start/stop all) for selected hosts
- * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
- * @param {Array} hosts - list of affected hosts
- */
- bulkOperationForHosts: function(operationData, hosts) {
- var query = [];
- hosts.forEach(function(host) {
- var subQuery = '(HostRoles/component_name.in(%@)&HostRoles/host_name=' + host.get('hostName') + ')';
- var components = [];
- host.get('hostComponents').forEach(function(hostComponent) {
- if (hostComponent.get('isMaster') || hostComponent.get('isSlave')) {
- if (hostComponent.get('workStatus') === operationData.actionToCheck) {
- components.push(hostComponent.get('componentName'));
- }
- }
- });
- if (components.length) {
- query.push(subQuery.fmt(components.join(',')));
- }
- });
- if (query.length) {
- query = query.join('|');
- App.ajax.send({
- name: 'bulk_request.hosts.all_components',
- sender: this,
- data: {
- query: query,
- state: operationData.action,
- requestInfo: operationData.message
- },
- success: 'bulkOperationForHostComponentsSuccessCallback'
- });
- }
- else {
- App.ModalPopup.show({
- header: Em.I18n.t('rolling.nothingToDo.header'),
- body: Em.I18n.t('rolling.nothingToDo.body').format(Em.I18n.t('hosts.host.maintainance.allComponents.context')),
- secondary: false
- });
- }
- },
- /**
- * Bulk restart for selected hosts
- * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
- * @param {Array} hosts - list of affected hosts
- */
- bulkOperationForHostsRestart: function(operationData, hosts) {
- var hostComponents = [];
- hosts.forEach(function(host) {
- hostComponents.pushObjects(host.get('hostComponents').toArray());
- });
- batchUtils.restartHostComponents(hostComponents);
- },
- /**
- * Bulk turn on/off passive state for selected hosts
- * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
- * @param {Array} hosts - list of affected hosts
- */
- bulkOperationForHostsPassiveState: function(operationData, hosts) {
- var affectedHosts = [];
- hosts.forEach(function(host) {
- if (host.get('passiveState') !== operationData.state) {
- affectedHosts.push(host.get('hostName'));
- }
- });
- if (affectedHosts.length) {
- App.ajax.send({
- name: 'bulk_request.hosts.passive_state',
- sender: this,
- data: {
- hostNames: affectedHosts.join(','),
- passive_state: operationData.state,
- requestInfo: operationData.message
- }
- });
- }
- else {
- App.ModalPopup.show({
- header: Em.I18n.t('rolling.nothingToDo.header'),
- body: Em.I18n.t('hosts.bulkOperation.passiveState.nothingToDo.body'),
- secondary: false
- });
- }
- },
- /**
- * Bulk operation for selected hostComponents
- * @param {Object} operationData - data about bulk operation (action, hostComponents etc)
- * @param {Array} hosts - list of affected hosts
- */
- bulkOperationForHostComponents: function(operationData, hosts) {
- var service = App.Service.find(operationData.serviceName);
- var components = service.get('hostComponents').filter(function(hc) {
- if (hc.get('componentName') != operationData.componentName) {
- return false;
- }
- if(hc.get('workStatus') == operationData.action) {
- return false;
- }
- return hosts.contains(hc.get('host'));
- });
- if (components.length) {
- var hostsWithComponentInProperState = components.mapProperty('host.hostName');
- App.ajax.send({
- name: 'bulk_request.host_components',
- sender: this,
- data: {
- hostNames: hostsWithComponentInProperState.join(','),
- state: operationData.action,
- requestInfo: operationData.message + ' ' + operationData.componentNameFormatted,
- componentName: operationData.componentName
- },
- success: 'bulkOperationForHostComponentsSuccessCallback'
- });
- }
- else {
- App.ModalPopup.show({
- header: Em.I18n.t('rolling.nothingToDo.header'),
- body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
- secondary: false
- });
- }
- },
- /**
- * Bulk decommission for selected hostComponents
- * @param {Object} operationData
- * @param {Array} hosts
- */
- bulkOperationForHostComponentsDecommission: function(operationData, hosts) {
- var service = App.Service.find(operationData.serviceName);
- var components = service.get('hostComponents').filter(function(hc) {
- if (hc.get('componentName') != operationData.realComponentName) {
- return false;
- }
- return hosts.contains(hc.get('host'));
- });
- if (components.length) {
- var hostsWithComponentInProperState = components.mapProperty('host.hostName');
- var turn_off = operationData.action.indexOf('OFF') !== -1;
- var parameters = {
- "slave_type": operationData.realComponentName
- };
- if (turn_off) {
- parameters['included_hosts'] = hostsWithComponentInProperState.join(',')
- }
- else {
- parameters['excluded_hosts'] = hostsWithComponentInProperState.join(',');
- }
- App.ajax.send({
- name: 'bulk_request.decommission',
- sender: this,
- data: {
- context: turn_off ? Em.I18n.t('hosts.host.datanode.recommission') : Em.I18n.t('hosts.host.datanode.decommission'),
- serviceName: service.get('serviceName'),
- componentName: operationData.componentName,
- parameters: parameters
- },
- success: 'bulkOperationForHostComponentsSuccessCallback'
- });
- }
- else {
- App.ModalPopup.show({
- header: Em.I18n.t('rolling.nothingToDo.header'),
- body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
- secondary: false
- });
- }
- },
- /**
- * Bulk restart for selected hostComponents
- * @param {Object} operationData
- * @param {Array} hosts
- */
- bulkOperationForHostComponentsRestart: function(operationData, hosts) {
- var service = App.Service.find(operationData.serviceName);
- var components = service.get('hostComponents').filter(function(hc) {
- if (hc.get('componentName') != operationData.componentName) {
- return false;
- }
- return hosts.contains(hc.get('host'));
- });
- if (components.length) {
- batchUtils._doPostBatchRollingRestartRequest(components, components.length, 1, 1);
- }
- else {
- App.ModalPopup.show({
- header: Em.I18n.t('rolling.nothingToDo.header'),
- body: Em.I18n.t('rolling.nothingToDo.body').format(operationData.componentNameFormatted),
- secondary: false
- });
- }
- },
- /**
- * Bulk turn on/off passive state for selected hostComponents
- * @param {Object} operationData
- * @param {Array} hosts
- */
- bulkOperationForHostComponentsPassiveState: function(operationData, hosts) {
- var affectedHosts = [];
- hosts.forEach(function(host) {
- host.get('hostComponents').forEach(function(hostComponent) {
- if (hostComponent.get('componentName') == operationData.componentName) {
- if (hostComponent.get('passiveState') !== operationData.state) {
- if (hostComponent.get('passiveState') === 'IMPLIED') {
- if (operationData.state === 'ACTIVE') {
- affectedHosts.push(host.get('hostName'));
- }
- }
- else {
- if (hostComponent.get('passiveState') === 'PASSIVE') {
- if (operationData.state === 'ACTIVE') {
- affectedHosts.push(host.get('hostName'));
- }
- }
- else {
- if (operationData.state === 'PASSIVE') {
- affectedHosts.push(host.get('hostName'));
- }
- }
- }
- }
- }
- });
- });
- if (affectedHosts.length) {
- App.ajax.send({
- name: 'bulk_request.hosts.all_components.passive_state',
- sender: this,
- data: {
- query: 'HostRoles/component_name=' + operationData.componentName + '&HostRoles/host_name.in(' + affectedHosts.join(',') + ')',
- passive_state: operationData.state,
- requestInfo: operationData.message
- }
- });
- }
- else {
- App.ModalPopup.show({
- header: Em.I18n.t('rolling.nothingToDo.header'),
- body: Em.I18n.t('hosts.bulkOperation.host_components.passiveState.nothingToDo.body'),
- secondary: false
- });
- }
- },
- /**
- * Show BO popup after bulk request
- */
- bulkOperationForHostComponentsSuccessCallback: function() {
- App.router.get('applicationController').dataLoading().done(function (initValue) {
- if (initValue) {
- App.router.get('backgroundOperationsController').showPopup();
- }
- });
- }
- });
|