12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070 |
- /**
- * 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.MainHostDetailsController = Em.Controller.extend({
- name: 'mainHostDetailsController',
- content: null,
- isFromHosts: false,
- /**
- * path to page visited before
- */
- referer: '',
- /**
- * open dashboard page
- */
- routeHome: function () {
- App.router.transitionTo('main.dashboard');
- },
- /**
- * open summary page of the selected service
- * @param event
- */
- routeToService: function(event){
- var service = event.context;
- App.router.transitionTo('main.services.service.summary',service);
- },
- /**
- * Send specific command to server
- * @param url
- * @param _method
- * @param postData
- * @param callback
- */
- sendCommandToServer : function(url, postData, _method, callback){
- var url = (App.testMode) ?
- '/data/wizard/deploy/poll_1.json' : //content is the same as ours
- App.apiPrefix + '/clusters/' + App.router.getClusterName() + url;
- var method = App.testMode ? 'GET' : _method;
- $.ajax({
- type: method,
- url: url,
- data: JSON.stringify(postData),
- dataType: 'json',
- timeout: App.timeout,
- success: function(data){
- if(data && data.Requests){
- callback(data.Requests.id);
- } else{
- callback(null);
- console.log('cannot get request id from ', data);
- }
- },
- error: function (request, ajaxOptions, error) {
- //do something
- console.log('error on change component host status');
- App.ajax.defaultErrorHandler(request, url, method);
- },
- statusCode: require('data/statusCodes')
- });
- },
- /**
- * send command to server to start selected host component
- * @param event
- */
- startComponent: function (event) {
- var self = this;
- App.showConfirmationPopup(function() {
- var component = event.context;
- var context = Em.I18n.t('requestInfo.startHostComponent') + " " + component.get('displayName');
- self.sendStartComponentCommand(component, context);
- });
- },
-
- /**
- * PUTs a command to server to start a component. If no
- * specific component is provided, all components are started.
- * @param component When <code>null</code> all startable components are started.
- * @param context Context under which this command is beign sent.
- */
- sendStartComponentCommand: function(component, context) {
- var url = component !== null ?
- '/hosts/' + this.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase() :
- '/hosts/' + this.get('content.hostName') + '/host_components';
- var dataToSend = {
- RequestInfo : {
- "context" : context
- },
- Body:{
- HostRoles:{
- state: 'STARTED'
- }
- }
- };
- if (component === null) {
- var allComponents = this.get('content.hostComponents');
- var startable = [];
- allComponents.forEach(function (c) {
- if (c.get('isMaster') || c.get('isSlave')) {
- startable.push(c.get('componentName'));
- }
- });
- dataToSend.RequestInfo.query = "HostRoles/component_name.in(" + startable.join(',') + ")";
- }
- this.sendCommandToServer(url, dataToSend, 'PUT',
- function(requestId){
- if(!requestId){
- return;
- }
- console.log('Send request for STARTING successfully');
- if (App.testMode) {
- if(component === null){
- var allComponents = this.get('content.hostComponents');
- allComponents.forEach(function(component){
- component.set('workStatus', App.HostComponentStatus.stopping);
- setTimeout(function(){
- component.set('workStatus', App.HostComponentStatus.stopped);
- },App.testModeDelayForActions);
- });
- } else {
- component.set('workStatus', App.HostComponentStatus.starting);
- setTimeout(function(){
- component.set('workStatus', App.HostComponentStatus.started);
- },App.testModeDelayForActions);
- }
- } else {
- App.router.get('clusterController').loadUpdatedStatusDelayed(500);
- }
- // load data (if we need to show this background operations popup) from persist
- App.router.get('applicationController').dataLoading().done(function (initValue) {
- if (initValue) {
- App.router.get('backgroundOperationsController').showPopup();
- }
- });
- });
- },
- /**
- * send command to server to delete selected host component
- *
- */
- deleteComponent: function (event) {
- var self = this;
- var component = event.context;
- var componentName = component.get('componentName');
- var displayName = component.get('displayName');
- var isLastComponent = (App.HostComponent.find().filterProperty('componentName', componentName).get('length') === 1);
- App.ModalPopup.show({
- header: Em.I18n.t('popup.confirmation.commonHeader'),
- bodyClass: Ember.View.extend({
- templateName: require('templates/main/host/details/deleteComponentPopup')
- }),
- enablePrimary: false,
- lastComponent: function() {
- if (isLastComponent) {
- this.set('enablePrimary',false);
- return true;
- } else {
- this.set('enablePrimary',true);
- return false;
- }
- }.property(),
- lastComponentError: Em.View.extend({
- template: Ember.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.warning').format(displayName))
- }),
- deleteComponentMsg: function() {
- return Em.I18n.t('hosts.host.deleteComponent.popup.msg').format(displayName);
- }.property(),
- onPrimary: function () {
- if (!this.get('enablePrimary')) return;
- self._doDeleteHostComponent(component);
- this.hide();
- }
- });
- },
- /**
- * Deletes the given host component, or all host components.
- *
- * @param component When <code>null</code> all host components are deleted.
- * @return <code>null</code> when components get deleted.
- * <code>{xhr: XhrObj, url: "http://", method: "DELETE"}</code>
- * when components failed to get deleted.
- */
- _doDeleteHostComponent: function(component) {
- var url = component !== null ?
- '/hosts/' + this.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase() :
- '/hosts/' + this.get('content.hostName') + '/host_components';
- url = App.apiPrefix + '/clusters/' + App.router.getClusterName() + url;
- var deleted = null;
- $.ajax({
- type: 'DELETE',
- url: url,
- timeout: App.timeout,
- async: false,
- success: function (data) {
- deleted = null;
- },
- error: function (xhr, textStatus, errorThrown) {
- console.log('Error deleting host component');
- console.log(textStatus);
- console.log(errorThrown);
- deleted = {xhr: xhr, url: url, method: 'DELETE'};
- },
- statusCode: require('data/statusCodes')
- });
- return deleted;
- },
- /**
- * send command to server to upgrade selected host component
- * @param event
- */
- upgradeComponent: function (event) {
- var self = this;
- var component = event.context;
- App.showConfirmationPopup(function() {
- self.sendCommandToServer('/hosts/' + self.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase(),{
- RequestInfo : {
- "context" : Em.I18n.t('requestInfo.upgradeHostComponent') + " " + component.get('displayName')
- },
- Body:{
- HostRoles:{
- stack_id: 'HDP-1.2.2',
- state: 'INSTALLED'
- }
- }
- }, 'PUT',
- function(requestId){
- if(!requestId){
- return;
- }
- console.log('Send request for UPGRADE successfully');
- if (App.testMode) {
- component.set('workStatus', App.HostComponentStatus.starting);
- setTimeout(function(){
- component.set('workStatus', App.HostComponentStatus.started);
- },App.testModeDelayForActions);
- } else {
- App.router.get('clusterController').loadUpdatedStatusDelayed(500);
- }
- // load data (if we need to show this background operations popup) from persist
- App.router.get('applicationController').dataLoading().done(function (initValue) {
- if (initValue) {
- App.router.get('backgroundOperationsController').showPopup();
- }
- });
- });
- });
- },
- /**
- * send command to server to stop selected host component
- * @param event
- */
- stopComponent: function (event) {
- var self = this;
- App.showConfirmationPopup(function() {
- var component = event.context;
- var context = Em.I18n.t('requestInfo.stopHostComponent')+ " " + component.get('displayName');
- self.sendStopComponentCommand(component, context);
- });
- },
-
- /**
- * PUTs a command to server to stop a component. If no
- * specific component is provided, all components are stopped.
- * @param component When <code>null</code> all components are stopped.
- * @param context Context under which this command is beign sent.
- */
- sendStopComponentCommand: function(component, context){
- var url = component !== null ?
- '/hosts/' + this.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase() :
- '/hosts/' + this.get('content.hostName') + '/host_components';
- var dataToSend = {
- RequestInfo : {
- "context" : context
- },
- Body:{
- HostRoles:{
- state: 'INSTALLED'
- }
- }
- };
- if (component === null) {
- var allComponents = this.get('content.hostComponents');
- var startable = [];
- allComponents.forEach(function (c) {
- if (c.get('isMaster') || c.get('isSlave')) {
- startable.push(c.get('componentName'));
- }
- });
- dataToSend.RequestInfo.query = "HostRoles/component_name.in(" + startable.join(',') + ")";
- }
- this.sendCommandToServer( url, dataToSend, 'PUT',
- function(requestId){
- if(!requestId){
- return;
- }
- console.log('Send request for STOPPING successfully');
- if (App.testMode) {
- if(component === null){
- var allComponents = this.get('content.hostComponents');
- allComponents.forEach(function(component){
- component.set('workStatus', App.HostComponentStatus.stopping);
- setTimeout(function(){
- component.set('workStatus', App.HostComponentStatus.stopped);
- },App.testModeDelayForActions);
- });
- } else {
- component.set('workStatus', App.HostComponentStatus.stopping);
- setTimeout(function(){
- component.set('workStatus', App.HostComponentStatus.stopped);
- },App.testModeDelayForActions);
- }
- } else {
- App.router.get('clusterController').loadUpdatedStatusDelayed(500);
- }
- // load data (if we need to show this background operations popup) from persist
- App.router.get('applicationController').dataLoading().done(function (initValue) {
- if (initValue) {
- App.router.get('backgroundOperationsController').showPopup();
- }
- });
- });
- },
- /**
- * send command to server to install selected host component
- * @param event
- */
- addComponent: function (event, context) {
- var self = this;
- var component = event.context;
- var componentName = component.get('componentName').toUpperCase().toString();
- var subComponentNames = component.get('subComponentNames');
- var displayName = component.get('displayName');
- var securityEnabled = App.router.get('mainAdminSecurityController').getUpdatedSecurityStatus();
- if (componentName === 'ZOOKEEPER_SERVER') {
- App.showConfirmationPopup(function() {
- self.primary(component);
- }, Em.I18n.t('hosts.host.addComponent.addZooKeeper'));
- }
- else {
- if (securityEnabled) {
- App.showConfirmationPopup(function() {
- self.primary(component);
- }, Em.I18n.t('hosts.host.addComponent.securityNote').format(componentName,self.get('content.hostName')));
- }
- else {
- var dn = displayName;
- if (subComponentNames !== null && subComponentNames.length > 0) {
- var dns = [];
- subComponentNames.forEach(function(scn){
- dns.push(App.format.role(scn));
- });
- dn += " ("+dns.join(", ")+")";
- }
- App.ModalPopup.show({
- primary: Em.I18n.t('yes'),
- secondary: Em.I18n.t('no'),
- header: Em.I18n.t('popup.confirmation.commonHeader'),
- addComponentMsg: function() {
- return Em.I18n.t('hosts.host.addComponent.msg').format(dn);
- }.property(),
- bodyClass: Ember.View.extend({
- templateName: require('templates/main/host/details/addComponentPopup')
- }),
- onPrimary: function () {
- this.hide();
- if (component.get('componentName') === 'CLIENTS') {
- // Clients component has many sub-components which
- // need to be installed.
- var scs = component.get('subComponentNames');
- scs.forEach(function (sc, index) {
- var c = Em.Object.create({
- displayName: App.format.role(sc),
- componentName: sc
- });
- self.primary(c, scs.length - index === 1);
- });
- } else {
- self.primary(component, true);
- }
- }
- });
- }
- }
- },
- primary: function(component, showPopup) {
- var self = this;
- var componentName = component.get('componentName').toUpperCase().toString();
- var displayName = component.get('displayName');
- self.sendCommandToServer('/hosts?Hosts/host_name=' + self.get('content.hostName'), {
- RequestInfo: {
- "context": Em.I18n.t('requestInfo.installHostComponent') + " " + displayName
- },
- Body: {
- host_components: [
- {
- HostRoles: {
- component_name: componentName
- }
- }
- ]
- }
- },
- 'POST',
- function (requestId) {
- console.log('Send request for ADDING NEW COMPONENT successfully');
- self.sendCommandToServer('/host_components?HostRoles/host_name=' + self.get('content.hostName') + '\&HostRoles/component_name=' + componentName + '\&HostRoles/state=INIT', {
- RequestInfo: {
- "context": Em.I18n.t('requestInfo.installNewHostComponent') + " " + displayName
- },
- Body: {
- HostRoles: {
- state: 'INSTALLED'
- }
- }
- },
- 'PUT',
- function (requestId) {
- if (!requestId) {
- return;
- }
- console.log('Send request for INSTALLING NEW COMPONENT successfully');
- if (App.testMode) {
- component.set('workStatus', App.HostComponentStatus.installing);
- setTimeout(function () {
- component.set('workStatus', App.HostComponentStatus.stopped);
- }, App.testModeDelayForActions);
- } else {
- App.router.get('clusterController').loadUpdatedStatusDelayed(500);
- }
- // load data (if we need to show this background operations popup) from persist
- App.router.get('applicationController').dataLoading().done(function (initValue) {
- if (initValue) {
- App.router.get('backgroundOperationsController').showPopup();
- }
- if (componentName === 'ZOOKEEPER_SERVER') {
- self.set('zkRequestId', requestId);
- self.addObserver('App.router.backgroundOperationsController.serviceTimestamp', self, self.checkZkConfigs);
- self.checkZkConfigs();
- }
- });
- });
- });
- },
- /**
- * Load tags
- */
- checkZkConfigs: function() {
- var bg = App.router.get('backgroundOperationsController.services').findProperty('id', this.get('zkRequestId'));
- if (!bg) return;
- if (!bg.get('isRunning')) {
- this.loadConfigs();
- }
- },
- loadConfigs: function() {
- this.removeObserver('App.router.backgroundOperationsController.serviceTimestamp', this, this.checkZkConfigs);
- App.ajax.send({
- name: 'config.tags',
- sender: this,
- success: 'loadConfigsSuccessCallback'
- });
- },
- /**
- * Load needed configs
- * @param data
- */
- loadConfigsSuccessCallback: function(data) {
- var urlParams = [];
- urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
- if (App.Service.find().someProperty('serviceName', 'HBASE')) {
- urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
- }
- if (App.Service.find().someProperty('serviceName', 'HIVE')) {
- urlParams.push('(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')');
- }
- App.ajax.send({
- name: 'reassign.load_configs',
- sender: this,
- data: {
- urlParams: urlParams.join('|')
- },
- success: 'setNewZkConfigs'
- });
- },
- /**
- * Set new values for some configs (based on available ZooKeeper Servers)
- * @param data
- */
- setNewZkConfigs: function(data) {
- var configs = [];
- data.items.forEach(function (item) {
- configs[item.type] = item.properties;
- }, this);
- var zks = this.getZkServerHosts();
- var zks_with_port = '';
- zks.forEach(function(zk) {
- zks_with_port += zk + ':2181,';
- });
- zks_with_port = zks_with_port.slice(0,-1);
- if (App.get('isHaEnabled')) {
- configs['core-site']['ha.zookeeper.quorum'] = zks_with_port;
- }
- if (configs['hbase-site']) {
- configs['hbase-site']['hbase.zookeeper.quorum'] = zks.join(',');
- }
- if (configs['webhcat-site']) {
- configs['webhcat-site']['templeton.zookeeper.hosts'] = zks_with_port;
- }
- for (var site in configs) {
- if (!configs.hasOwnProperty(site)) continue;
- App.ajax.send({
- name: 'reassign.save_configs',
- sender: this,
- data: {
- siteName: site,
- properties: configs[site]
- }
- });
- }
- },
- /**
- * Is deleteHost action id fired
- */
- fromDeleteHost: false,
- getZkServerHosts: function() {
- var zks = App.HostComponent.find().filterProperty('componentName', 'ZOOKEEPER_SERVER').mapProperty('host.hostName');
- if (this.get('fromDeleteHost')) {
- this.set('fromDeleteHost', false);
- return zks.without(this.get('content.hostName'));
- }
- return zks;
- },
- /**
- * send command to server to install selected host component
- * @param event
- * @param context
- */
- installComponent: function (event, context) {
- var self = this;
- var component = event.context;
- var componentName = component.get('componentName').toUpperCase().toString();
- var displayName = component.get('displayName');
- App.ModalPopup.show({
- primary: Em.I18n.t('yes'),
- secondary: Em.I18n.t('no'),
- header: Em.I18n.t('popup.confirmation.commonHeader'),
- installComponentMessage: function(){
- return Em.I18n.t('hosts.host.installComponent.msg').format(displayName);
- }.property(),
- bodyClass: Ember.View.extend({
- templateName: require('templates/main/host/details/installComponentPopup')
- }),
- onPrimary: function () {
- this.hide();
- self.sendCommandToServer('/hosts/' + self.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase(), {
- RequestInfo: {
- "context": Em.I18n.t('requestInfo.installHostComponent') + " " + displayName
- },
- Body: {
- HostRoles: {
- state: 'INSTALLED'
- }
- }
- },
- 'PUT',
- function (requestId) {
- if (!requestId) {
- return;
- }
- console.log('Send request for REINSTALL COMPONENT successfully');
- if (App.testMode) {
- component.set('workStatus', App.HostComponentStatus.installing);
- setTimeout(function () {
- component.set('workStatus', App.HostComponentStatus.stopped);
- }, App.testModeDelayForActions);
- } else {
- App.router.get('clusterController').loadUpdatedStatusDelayed(500);
- }
- // load data (if we need to show this background operations popup) from persist
- App.router.get('applicationController').dataLoading().done(function (initValue) {
- if (initValue) {
- App.router.get('backgroundOperationsController').showPopup();
- }
- });
- });
- }
- });
- },
- /**
- * send command to server to run decommission on DATANODE
- * @param event
- */
- decommission: function(event){
- var self = this;
- var decommissionHostNames = this.get('view.decommissionDataNodeHostNames');
- if (decommissionHostNames == null) {
- decommissionHostNames = [];
- }
- App.showConfirmationPopup(function(){
- var component = event.context;
- // Only HDFS service as of now
- var svcName = component.get('service.serviceName');
- if (svcName === "HDFS") {
- var hostName = self.get('content.hostName');
- var index = decommissionHostNames.indexOf(hostName);
- if (index < 0) {
- decommissionHostNames.push(hostName);
- }
- self.doDatanodeDecommission(decommissionHostNames, true);
- }
- // load data (if we need to show this background operations popup) from persist
- App.router.get('applicationController').dataLoading().done(function (initValue) {
- if (initValue) {
- App.router.get('backgroundOperationsController').showPopup();
- }
- });
- });
- },
- /**
- * Performs either Decommission or Recommission by updating the hosts list on
- * server.
- * @param decommission defines context for request (true for decommission and false for recommission)
- */
- doDatanodeDecommission: function(decommissionHostNames, decommission){
- var self = this;
- if (decommissionHostNames == null) {
- decommissionHostNames = [];
- }
- var invocationTag = String(new Date().getTime());
- var context = decommission ? Em.I18n.t('hosts.host.datanode.decommission') : Em.I18n.t('hosts.host.datanode.recommission');
- var clusterName = App.router.get('clusterController.clusterName');
- var clusterUrl = App.apiPrefix + '/clusters/' + clusterName;
- var configsUrl = clusterUrl + '/configurations';
- var configsData = {
- type: "hdfs-exclude-file",
- tag: invocationTag,
- properties: {
- datanodes: decommissionHostNames.join(',')
- }
- };
- var configsAjax = {
- type: 'POST',
- url: configsUrl,
- dataType: 'json',
- data: JSON.stringify(configsData),
- timeout: App.timeout,
- success: function(){
- var actionsUrl = clusterUrl + '/requests';
- var actionsData = {
- RequestInfo: {
- context: context,
- command: 'DECOMMISSION_DATANODE',
- service_name: 'HDFS',
- parameters: {
- excludeFileTag: invocationTag
- }
- }
- };
- var actionsAjax = {
- type: 'POST',
- url: actionsUrl,
- dataType: 'json',
- data: JSON.stringify(actionsData),
- timeout: App.timeout,
- success: function(){
- var persistUrl = App.apiPrefix + '/persist';
- var persistData = {
- "decommissionDataNodesTag": invocationTag
- };
- var persistPutAjax = {
- type: 'POST',
- url: persistUrl,
- dataType: 'json',
- data: JSON.stringify(persistData),
- timeout: App.timeout,
- success: function(){
- var view = self.get('view');
- view.loadDecommissionNodesList();
- }
- };
- jQuery.ajax(persistPutAjax);
- },
- error: function(xhr, textStatus, errorThrown){
- console.log(textStatus);
- console.log(errorThrown);
- }
- };
- jQuery.ajax(actionsAjax);
- },
- error: function(xhr, textStatus, errorThrown){
- console.log(textStatus);
- console.log(errorThrown);
- }
- };
- jQuery.ajax(configsAjax);
- },
- /**
- * send command to server to run recommission on DATANODE
- * @param event
- */
- recommission: function(event){
- var self = this;
- var decommissionHostNames = this.get('view.decommissionDataNodeHostNames');
- if (decommissionHostNames == null) {
- decommissionHostNames = [];
- }
- App.showConfirmationPopup(function(){
- var component = event.context;
- // Only HDFS service as of now
- var svcName = component.get('service.serviceName');
- if (svcName === "HDFS") {
- var hostName = self.get('content.hostName');
- var index = decommissionHostNames.indexOf(hostName);
- decommissionHostNames.splice(index, 1);
- self.doDatanodeDecommission(decommissionHostNames, false);
- }
- // load data (if we need to show this background operations popup) from persist
- App.router.get('applicationController').dataLoading().done(function (initValue) {
- if (initValue) {
- App.router.get('backgroundOperationsController').showPopup();
- }
- });
- });
- },
-
- doAction: function(option) {
- switch (option.context.action) {
- case "deleteHost":
- this.validateAndDeleteHost();
- break;
- case "startAllComponents":
- this.doStartAllComponents();
- break;
- case "stopAllComponents":
- this.doStopAllComponents();
- break;
- default:
- break;
- }
- },
-
- doStartAllComponents: function() {
- var self = this;
- var components = this.get('content.hostComponents');
- var componentsLength = components == null ? 0 : components.get('length');
- if (componentsLength > 0) {
- App.showConfirmationPopup(function() {
- self.sendStartComponentCommand(null,
- Em.I18n.t('hosts.host.maintainance.startAllComponents.context'));
- });
- }
- },
-
- doStopAllComponents: function() {
- var self = this;
- var components = this.get('content.hostComponents');
- var componentsLength = components == null ? 0 : components.get('length');
- if (componentsLength > 0) {
- App.showConfirmationPopup(function() {
- self.sendStopComponentCommand(null,
- Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'));
- });
- }
- },
- /**
- * Deletion of hosts not supported for this version
- */
- validateAndDeleteHost: function () {
- if (!App.supports.deleteHost) {
- return;
- }
- var stoppedStates = [App.HostComponentStatus.stopped,
- App.HostComponentStatus.install_failed,
- App.HostComponentStatus.upgrade_failed,
- App.HostComponentStatus.unknown];
- var masterComponents = [];
- var runningComponents = [];
- var unknownComponents = [];
- var nonDeletableComponents = [];
- var lastComponents = [];
- var componentsOnHost = this.get('content.hostComponents');
- var allComponents = App.HostComponent.find();
- var zkServerInstalled = false;
- if (componentsOnHost && componentsOnHost.get('length') > 0) {
- componentsOnHost.forEach(function (cInstance) {
- if (cInstance.get('componentName') === 'ZOOKEEPER_SERVER') {
- zkServerInstalled = true;
- }
- if (allComponents.filterProperty('componentName', cInstance.get('componentName')).get('length') === 1) {
- lastComponents.push(cInstance.get('displayName'));
- }
- var workStatus = cInstance.get('workStatus');
- if (cInstance.get('isMaster') && !cInstance.get('isDeletable')) {
- masterComponents.push(cInstance.get('displayName'));
- }
- if (stoppedStates.indexOf(workStatus) < 0) {
- runningComponents.push(cInstance.get('displayName'));
- }
- if (!cInstance.get('isDeletable')) {
- nonDeletableComponents.push(cInstance.get('displayName'));
- }
- if (workStatus === App.HostComponentStatus.unknown) {
- unknownComponents.push(cInstance.get('displayName'));
- }
- });
- }
- if (masterComponents.length > 0) {
- this.raiseDeleteComponentsError(masterComponents, 'masterList');
- return;
- } else if (nonDeletableComponents.length > 0) {
- this.raiseDeleteComponentsError(nonDeletableComponents, 'nonDeletableList');
- return;
- } else if (runningComponents.length > 0) {
- this.raiseDeleteComponentsError(runningComponents, 'runningList');
- return;
- }
- if (zkServerInstalled) {
- var self = this;
- App.showConfirmationPopup(function() {
- self._doDeleteHost(unknownComponents, lastComponents);
- }, Em.I18n.t('hosts.host.addComponent.deleteHostWithZooKeeper'));
- }
- else {
- this._doDeleteHost(unknownComponents, lastComponents);
- }
- },
-
- raiseDeleteComponentsError: function (components, type) {
- App.ModalPopup.show({
- header: Em.I18n.t('hosts.cant.do.popup.title'),
- type: type,
- showBodyEnd: function() {
- return this.get('type') === 'runningList' || this.get('type') === 'masterList';
- }.property(),
- components: components,
- componentsStr: function() {
- return this.get('components').join(", ");
- }.property(),
- componentsBody: function() {
- return Em.I18n.t('hosts.cant.do.popup.'+type+'.body').format(this.get('components').length);
- }.property(),
- componentsBodyEnd: function() {
- if (this.get('showBodyEnd')) {
- return Em.I18n.t('hosts.cant.do.popup.'+type+'.body.end');
- }
- return '';
- }.property(),
- bodyClass: Em.View.extend({
- templateName: require('templates/main/host/details/raiseDeleteComponentErrorPopup')
- }),
- secondary: null
- })
- },
- /**
- * show confirmation popup to delete host
- */
- _doDeleteHost: function(unknownComponents,lastComponents) {
- var self = this;
- App.ModalPopup.show({
- header: Em.I18n.t('hosts.delete.popup.title'),
- deletePopupBody: function() {
- return Em.I18n.t('hosts.delete.popup.body').format(self.get('content.publicHostName'));
- }.property(),
- lastComponent: function() {
- if (lastComponents && lastComponents.length) {
- this.set('enablePrimary',false);
- return true;
- } else {
- this.set('enablePrimary',true);
- return false;
- }
- }.property(),
- enablePrimary: false,
- lastComponentError: Em.View.extend({
- template: Ember.Handlebars.compile(Em.I18n.t('hosts.delete.popup.body.msg4').format(lastComponents))
- }),
- unknownComponents: function() {
- if (unknownComponents && unknownComponents.length) {
- return unknownComponents.join(", ");
- }
- return '';
- }.property(),
- bodyClass: Em.View.extend({
- templateName: require('templates/main/host/details/doDeleteHostPopup')
- }),
- onPrimary: function() {
- if (!this.get('enablePrimary')) return;
- self.set('fromDeleteHost', true);
- var allComponents = self.get('content.hostComponents');
- var deleteError = null;
- allComponents.forEach(function(component){
- if (!deleteError) {
- deleteError = self._doDeleteHostComponent(component);
- }
- });
- if (!deleteError) {
- App.ajax.send({
- name: 'host.delete',
- sender: this,
- data: {
- hostName: self.get('content.hostName')
- },
- success: 'deleteHostSuccessCallback',
- error: 'deleteHostErrorCallback'
- });
- }
- else {
- this.hide();
- deleteError.xhr.responseText = "{\"message\": \"" + deleteError.xhr.statusText + "\"}";
- App.ajax.defaultErrorHandler(deleteError.xhr, deleteError.url, deleteError.method, deleteError.xhr.status);
- }
- },
- deleteHostSuccessCallback: function(data) {
- var dialogSelf = this;
- App.router.get('updateController').updateHost(function(){
- self.loadConfigs();
- dialogSelf.hide();
- App.router.transitionTo('hosts.index');
- });
- },
- deleteHostErrorCallback: function (xhr, textStatus, errorThrown, opt) {
- console.log('Error deleting host.');
- console.log(textStatus);
- console.log(errorThrown);
- xhr.responseText = "{\"message\": \"" + xhr.statusText + "\"}";
- self.loadConfigs();
- this.hide();
- App.ajax.defaultErrorHandler(xhr, opt.url, 'DELETE', xhr.status);
- }
- })
- },
- restartComponents: function(e) {
- var staleComponents = this.get('content.hostComponents').filterProperty('staleConfigs', true);
- var commandName = "stop_component";
- if(e.context) {
- if(!staleComponents.findProperty('workStatus','STARTED')){
- return;
- }
- } else {
- commandName = "start_component";
- if(!staleComponents.findProperty('workStatus','INSTALLED')){
- return;
- }
- }
- var content = this;
- return App.ModalPopup.show({
- primary: Em.I18n.t('ok'),
- secondary: Em.I18n.t('common.cancel'),
- header: Em.I18n.t('popup.confirmation.commonHeader'),
- body: Em.I18n.t('question.sure'),
- content: content,
- onPrimary: function () {
- var hostComponents = this.content.get('content.hostComponents').filterProperty('staleConfigs', true);
- hostComponents.forEach(function (item) {
- var state = 'INSTALLED',
- componentName = item.get('componentName'),
- context = "Stop " + App.format.role(componentName),
- hostName = item.get('host.hostName');
- if (commandName === 'start_component') {
- context = "Start " + App.format.role(componentName);
- state = 'STARTED';
- if (item.get('isClient')) {
- //start components action includes install of clients
- context = "Install " + App.format.role(componentName);
- state = "INSTALLED";
- }
- } else if (item.get('isClient')) {
- return false;
- }
- App.ajax.send({
- name: 'host.host_component.action',
- sender: this,
- data: {
- hostName: hostName,
- componentName: componentName,
- context: context,
- state: state
- }
- });
- });
- this.hide();
- // load data (if we need to show this background operations popup) from persist
- App.router.get('applicationController').dataLoading().done(function (initValue) {
- if (initValue) {
- App.router.get('backgroundOperationsController').showPopup();
- }
- });
- }
- });
- },
- /**
- * open Reassign Master Wizard with selected component
- * @param event
- */
- moveComponent: function (event) {
- App.showConfirmationPopup(function() {
- var component = event.context;
- App.db.mergeStorage();
- var reassignMasterController = App.router.get('reassignMasterController');
- reassignMasterController.saveComponentToReassign(component);
- reassignMasterController.getSecurityStatus();
- reassignMasterController.setCurrentStep('1');
- App.router.transitionTo('services.reassign');
- });
- }
- });
|