12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289 |
- /**
- * 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 batchUtils = require('utils/batch_scheduled_requests');
- 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);
- },
- serviceActiveComponents: function() {
- return this.get('content.hostComponents').filterProperty('service.isInPassive',false);
- }.property('content.hostComponents'),
- serviceNonClientActiveComponents: function() {
- return this.get('serviceActiveComponents').filterProperty('isClient',false);
- }.property('serviceActiveComponents'),
- /**
- * 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(components, context) {
- var url = Em.isArray(components) ?
- '/hosts/' + this.get('content.hostName') + '/host_components' :
- '/hosts/' + this.get('content.hostName') + '/host_components/' + components.get('componentName').toUpperCase();
- var dataToSend = {
- RequestInfo : {
- "context" : context
- },
- Body:{
- HostRoles:{
- state: 'STARTED'
- }
- }
- };
- if (Em.isArray(components)) {
- dataToSend.RequestInfo.query = "HostRoles/component_name.in(" + components.mapProperty('componentName').join(',') + ")";
- }
- this.sendCommandToServer(url, dataToSend, 'PUT',
- function(requestId){
- if(!requestId){
- return;
- }
- console.log('Send request for STARTING successfully');
- if (App.testMode) {
- if(Em.isArray(components)){
- 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 {
- components.set('workStatus', App.HostComponentStatus.starting);
- setTimeout(function(){
- components.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'),
- primary: Em.I18n.t('hosts.host.deleteComponent.popup.confirm'),
- bodyClass: Ember.View.extend({
- templateName: require('templates/main/host/details/deleteComponentPopup')
- }),
- isChecked: false,
- disablePrimary: function () {
- return !this.get('isChecked');
- }.property('isChecked'),
- lastComponent: function() {
- if (isLastComponent) {
- this.set('isChecked', false);
- return true;
- } else {
- this.set('isChecked', true);
- return false;
- }
- }.property(),
- lastComponentError: Em.View.extend({
- template: Ember.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.warning').format(displayName))
- }),
- restartNagiosMsg: Em.View.extend({
- template: Ember.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.msg2').format(displayName))
- }),
- deleteComponentMsg: function() {
- return Em.I18n.t('hosts.host.deleteComponent.popup.msg1').format(displayName);
- }.property(),
- onPrimary: function () {
- self._doDeleteHostComponent(component);
- self.set('redrawComponents', true);
- this.hide();
- }
- });
- },
- /**
- * Trigger to reset list of master/slaves components on the view
- * @type {bool}
- */
- redrawComponents: false,
- /**
- * 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(components, context){
- var url = Em.isArray(components) ?
- '/hosts/' + this.get('content.hostName') + '/host_components' :
- '/hosts/' + this.get('content.hostName') + '/host_components/' + components.get('componentName').toUpperCase();
- var dataToSend = {
- RequestInfo : {
- "context" : context
- },
- Body:{
- HostRoles:{
- state: 'INSTALLED'
- }
- }
- };
- if (Em.isArray(components)) {
- dataToSend.RequestInfo.query = "HostRoles/component_name.in(" + components.mapProperty('componentName').join(',') + ")";
- }
- this.sendCommandToServer( url, dataToSend, 'PUT',
- function(requestId){
- if(!requestId){
- return;
- }
- console.log('Send request for STOPPING successfully');
- if (App.testMode) {
- if(Em.isArray(components)){
- components.forEach(function(component){
- component.set('workStatus', App.HostComponentStatus.stopping);
- setTimeout(function(){
- component.set('workStatus', App.HostComponentStatus.stopped);
- },App.testModeDelayForActions);
- });
- } else {
- components.set('workStatus', App.HostComponentStatus.stopping);
- setTimeout(function(){
- components.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();
- }
- });
- });
- },
- restartComponent: function(event) {
- var self = this;
- var component = event.context;
- App.showConfirmationPopup(function(){
- batchUtils.restartHostComponents([component], Em.I18n.t('rollingrestart.context.selectedComponentOnSelectedHost').format(component.get('displayName')));
- });
- },
- /**
- * send command to server to install selected host component
- * @param event
- */
- addComponent: function (event) {
- 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 && component.get('componentName') !== 'CLIENTS') {
- 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('hosts.host.addComponent.popup.confirm'),
- 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')
- }),
- restartNagiosMsg : Em.View.extend({
- template: Ember.Handlebars.compile(Em.I18n.t('hosts.host.addComponent.note').format(dn))
- }),
- 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 = [];
- if (App.get('isHaEnabled')) {
- 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 + ')');
- }
- if (App.Service.find().someProperty('serviceName', 'STORM')) {
- urlParams.push('(type=storm-site&tag=' + data.Clusters.desired_configs['storm-site'].tag + ')');
- }
- if (!urlParams.length) {
- return;
- }
- 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;
- }
- if (configs['storm-site']) {
- configs['storm-site']['storm.zookeeper.servers'] = JSON.stringify(zks).replace(/"/g, "'");
- }
- 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('hosts.host.installComponent.popup.confirm'),
- header: Em.I18n.t('popup.confirmation.commonHeader'),
- installComponentMessage: function(){
- return Em.I18n.t('hosts.host.installComponent.msg').format(displayName);
- }.property(),
- restartNagiosMsg : Em.View.extend({
- template: Ember.Handlebars.compile(Em.I18n.t('hosts.host.addComponent.note').format(displayName))
- }),
- 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, TASKTRACKER, NODEMANAGER, REGIONSERVER
- * @param component
- */
- decommission: function(component){
- var self = this;
- App.showConfirmationPopup(function(){
- var svcName = component.get('service.serviceName');
- var hostName = self.get('content.hostName');
- // HDFS service, decommission DataNode
- if (svcName === "HDFS") {
- self.doDecommission(hostName, svcName, "NAMENODE", "DATANODE");
- }
- // YARN service, decommission NodeManager
- if (svcName === "YARN") {
- self.doDecommission(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
- }
- // MAPREDUCE service, decommission TaskTracker
- if (svcName === "MAPREDUCE") {
- self.doDecommission(hostName, svcName, "JOBTRACKER", "TASKTRACKER");
- }
- // HBASE service, decommission RegionServer
- if (svcName === "HBASE") {
- self.warnBeforeDecommission(hostName, svcName, "HBASE_MASTER", "HBASE_REGIONSERVER");
- }
- // 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 recommission on DATANODE, TASKTRACKER, NODEMANAGER
- * @param component
- */
- recommission: function(component){
- var self = this;
- App.showConfirmationPopup(function(){
- var svcName = component.get('service.serviceName');
- var hostName = self.get('content.hostName');
- // HDFS service, Recommission datanode
- if (svcName === "HDFS") {
- self.doRecommissionAndStart(hostName, svcName, "NAMENODE", "DATANODE");
- }
- // YARN service, Recommission nodeManager
- if (svcName === "YARN") {
- self.doRecommissionAndStart(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
- }
- // MAPREDUCE service, Recommission taskTracker
- if (svcName === "MAPREDUCE") {
- self.doRecommissionAndRestart(hostName, svcName, "JOBTRACKER", "TASKTRACKER");
- }
- // HBASE service, Recommission RegionServer
- if (svcName === "HBASE") {
- self.doRecommissionAndStart(hostName, svcName, "HBASE_MASTER", "HBASE_REGIONSERVER");
- }
- // 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 Decommission (for DN, TT and NM)
- */
- doDecommission: function(hostName, serviceName, componentName, slaveType){
- var contextNameString = 'hosts.host.' + slaveType.toLowerCase() + '.decommission';
- var context = Em.I18n.t(contextNameString);
- App.ajax.send({
- name: 'host.host_component.decommission_slave',
- sender: this,
- data: {
- context: context,
- command: 'DECOMMISSION',
- hostName: hostName,
- serviceName: serviceName ,
- componentName: componentName,
- slaveType: slaveType
- },
- success: 'decommissionSuccessCallback',
- error: 'decommissionErrorCallback'
- });
- },
- /**
- * Recomends user to put component in MM before decommision (for HBASE only)
- * @method warnBeforeDecommission
- * @param {string[]} hostNames - list of host when run from bulk operations or current host
- * @param {string} serviceName - serviceName
- * @param {string} componentName - master compoent name
- * @param {string} slaveType - slave component name
- */
- warnBeforeDecommission: function(hostNames, serviceName, componentName, slaveType) {
- if (this.get('content.hostComponents').findProperty('componentName', componentName).get('passiveState') == "OFF") {
- App.ModalPopup.show({
- header: Em.I18n.t('common.warning'),
- message: function(){
- return Em.I18n.t('hostPopup.reccomendation.beforeDecommission').format(App.format.components[componentName]);
- }.property(),
- bodyClass: Ember.View.extend({
- template: Em.Handlebars.compile('<div class="alert alert-warning">{{message}}</div>')
- }),
- secondary: false
- });
- } else {
- this.doDecommissionRegionServer(hostNames, serviceName, componentName, slaveType);
- }
- },
- /**
- * Performs Decommission (for RegionServer)
- * @method doDecommissionRegionServer
- * @param {string[]} hostNames - list of host when run from bulk operations or current host
- * @param {string} serviceName - serviceName
- * @param {string} componentName - master compoent name
- * @param {string} slaveType - slave component name
- */
- doDecommissionRegionServer: function(hostNames, serviceName, componentName, slaveType){
- App.ajax.send({
- name: 'host.host_component.recommission_and_restart',
- sender: this,
- data: {
- intervalTimeSeconds: 1,
- tolerateSize : 0,
- batches:[
- {
- "order_id" : 1,
- "type" : "POST",
- "uri" : App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
- "RequestBodyInfo" : {
- "RequestInfo" : {
- "context" : Em.I18n.t('hosts.host.regionserver.decommission.batch1'),
- "command" : "DECOMMISSION",
- "parameters" : {
- "slave_type": slaveType,
- "excluded_hosts": hostNames
- }
- },
- "Requests/resource_filters": [{"service_name" : serviceName, "component_name" : componentName}]
- }
- },
- {
- "order_id": 2,
- "type": "PUT",
- "uri" : App.apiPrefix + "/clusters/" + App.get('clusterName') + "/host_components",
- "RequestBodyInfo" : {
- "RequestInfo" : {
- context: Em.I18n.t('hosts.host.regionserver.decommission.batch2'),
- query: 'HostRoles/component_name=' + slaveType + '&HostRoles/host_name.in(' + hostNames + ')&HostRoles/maintenance_state=OFF'
- },
- "Body": {
- HostRoles: {
- state: "INSTALLED"
- }
- }
- }
- },
- {
- "order_id" : 3,
- "type" : "POST",
- "uri" : App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
- "RequestBodyInfo" : {
- "RequestInfo" : {
- "context" : Em.I18n.t('hosts.host.regionserver.decommission.batch3'),
- "command" : "DECOMMISSION",
- "service_name" : serviceName,
- "component_name" : componentName,
- "parameters" : {
- "slave_type": slaveType,
- "excluded_hosts": hostNames,
- "mark_draining_only": "true"
- }
- }
- }
- }
- ]
- },
- success: 'decommissionSuccessCallback',
- error: 'decommissionErrorCallback'
- });
- },
- decommissionErrorCallback: function (request, ajaxOptions, error) {
- console.log('ERROR: '+ error);
- },
- /**
- * Success ajax response for Recommission/Decommission slaves
- * @param data
- * @param ajaxOptions
- */
- decommissionSuccessCallback: function(data, ajaxOptions) {
- if(data && (data.Requests || data.resources[0].RequestSchedule) ) {
- if (!App.testMode) {
- 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();
- }
- });
- }
- else {
- console.log('cannot get request id from ', data);
- }
- },
- doRecommissionAndStart: function(hostNames, serviceName, componentName, slaveType){
- var contextNameString_1 = 'hosts.host.' + slaveType.toLowerCase() + '.recommission';
- var context_1 = Em.I18n.t(contextNameString_1);
- var contextNameString_2 = 'requestInfo.startHostComponent.' + slaveType.toLowerCase();
- var startContext = Em.I18n.t(contextNameString_2);
- App.ajax.send({
- name: 'host.host_component.recommission_and_restart',
- sender: this,
- data: {
- intervalTimeSeconds: 1,
- tolerateSize : 1,
- batches:[
- {
- "order_id" : 1,
- "type" : "POST",
- "uri" : App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
- "RequestBodyInfo" : {
- "RequestInfo" : {
- "context" : context_1,
- "command" : "DECOMMISSION",
- "parameters" : {
- "slave_type": slaveType,
- "included_hosts": hostNames
- }
- },
- "Requests/resource_filters": [{"service_name" : serviceName, "component_name" : componentName}]
- }
- },
- {
- "order_id": 2,
- "type": "PUT",
- "uri" : App.apiPrefix + "/clusters/" + App.get('clusterName') + "/host_components",
- "RequestBodyInfo" : {
- "RequestInfo" : {
- context: startContext,
- query: 'HostRoles/component_name=' + slaveType + '&HostRoles/host_name.in(' + hostNames + ')&HostRoles/maintenance_state=OFF'
- },
- "Body": {
- HostRoles: {
- state: "STARTED"
- }
- }
- }
- }
- ]
- },
- success: 'decommissionSuccessCallback',
- error: 'decommissionErrorCallback'
- });
- },
- doRecommissionAndRestart: function(hostNames, serviceName, componentName, slaveType){
- var contextNameString_1 = 'hosts.host.' + slaveType.toLowerCase() + '.recommission';
- var context_1 = Em.I18n.t(contextNameString_1);
- var contextNameString_2 = 'hosts.host.' + slaveType.toLowerCase() + '.restart';
- var context_2 = Em.I18n.t(contextNameString_2);
- App.ajax.send({
- name: 'host.host_component.recommission_and_restart',
- sender: this,
- data: {
- intervalTimeSeconds: 1,
- tolerateSize : 1,
- batches:[
- {
- "order_id" : 1,
- "type" : "POST",
- "uri" : App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
- "RequestBodyInfo" : {
- "RequestInfo" : {
- "context" : context_1,
- "command" : "DECOMMISSION",
- "parameters" : {
- "slave_type": slaveType,
- "included_hosts": hostNames
- }
- },
- "Requests/resource_filters": [{"service_name" : serviceName, "component_name" : componentName}]
- }
- },
- {
- "order_id" : 2,
- "type" : "POST",
- "uri" : App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
- "RequestBodyInfo" : {
- "RequestInfo" : {
- "context" : context_2,
- "command" : "RESTART",
- "service_name" : serviceName,
- "component_name" : slaveType,
- "hosts" : hostNames
- }
- }
- }
- ]
- },
- success: 'decommissionSuccessCallback',
- error: 'decommissionErrorCallback'
- });
- },
- doAction: function(option) {
- switch (option.context.action) {
- case "deleteHost":
- this.validateAndDeleteHost();
- break;
- case "startAllComponents":
- if (!this.get('content.isNotHeartBeating')) this.doStartAllComponents();
- break;
- case "stopAllComponents":
- if (!this.get('content.isNotHeartBeating')) this.doStopAllComponents();
- break;
- case "restartAllComponents":
- if (!this.get('content.isNotHeartBeating')) this.doRestartAllComponents();
- break;
- case "onOffPassiveModeForHost":
- this.onOffPassiveModeForHost(option.context);
- break;
- default:
- break;
- }
- },
- onOffPassiveModeForHost: function(context) {
- var state = context.active ? 'ON' : 'OFF';
- var self = this;
- var message = context.label + ' for host';
- App.showConfirmationPopup(function() {
- self.hostPassiveModeRequest(state, message)
- },
- Em.I18n.t('hosts.passiveMode.popup').format(context.active ? 'On' : 'Off',this.get('content.hostName'))
- );
- },
- hostPassiveModeRequest: function(state,message) {
- App.ajax.send({
- name: 'bulk_request.hosts.passive_state',
- sender: this,
- data: {
- hostNames: this.get('content.hostName'),
- passive_state: state,
- requestInfo: message
- },
- success: 'updateHost'
- });
- },
- updateHost: function(data, opt, params) {
- this.set('content.passiveState', params.passive_state);
- App.router.get('clusterController').loadUpdatedStatus(function(){
- batchUtils.infoPassiveState(params.passive_state);
- });
- },
- doStartAllComponents: function() {
- var self = this;
- var components = this.get('serviceNonClientActiveComponents');
- var componentsLength = components == null ? 0 : components.get('length');
- if (componentsLength > 0) {
- App.showConfirmationPopup(function() {
- self.sendStartComponentCommand(components, Em.I18n.t('hosts.host.maintainance.startAllComponents.context'));
- });
- }
- },
-
- doStopAllComponents: function() {
- var self = this;
- var components = this.get('serviceNonClientActiveComponents');
- var componentsLength = components == null ? 0 : components.get('length');
- if (componentsLength > 0) {
- App.showConfirmationPopup(function() {
- self.sendStopComponentCommand(components, Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'));
- });
- }
- },
- doRestartAllComponents: function() {
- var self = this;
- var components = this.get('serviceActiveComponents');
- var componentsLength = components == null ? 0 : components.get('length');
- if (componentsLength > 0) {
- App.showConfirmationPopup(function() {
- batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allOnSelectedHost').format(self.get('content.hostName')));
- });
- }
- },
- /**
- * 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.init,
- 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('isChecked', false);
- return true;
- } else {
- this.set('isChecked', true);
- return false;
- }
- }.property(),
- disablePrimary: function () {
- return !this.get('isChecked');
- }.property('isChecked'),
- isChecked: 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() {
- 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);
- }
- })
- },
- restartAllStaleConfigComponents: function() {
- var self = this;
- App.showConfirmationPopup(function () {
- var staleComponents = self.get('content.componentsWithStaleConfigs');
- batchUtils.restartHostComponents(staleComponents, Em.I18n.t('rollingrestart.context.allWithStaleConfigsOnSelectedHost').format(self.get('content.hostName')));
- });
- },
- /**
- * open Reassign Master Wizard with selected component
- * @param event
- */
- moveComponent: function (event) {
- App.showConfirmationPopup(function() {
- var component = event.context;
- var reassignMasterController = App.router.get('reassignMasterController');
- reassignMasterController.saveComponentToReassign(component);
- reassignMasterController.getSecurityStatus();
- reassignMasterController.setCurrentStep('1');
- App.router.transitionTo('reassign');
- });
- },
- /**
- * Restart clients host components to apply config changes
- */
- refreshConfigs: function(event) {
- var self = this;
- var components = event.context.filter(function(component) {
- return component.get('staleConfigs');
- });
- if (components.get('length') > 0) {
- App.showConfirmationPopup(function() {
- batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allClientsOnSelectedHost').format(self.get('content.hostName')));
- });
- }
- }
- });
|