123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- /**
- * 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,
- /**
- * 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);
- },
- /**
- * set new value to isFromHosts property
- * @param isFromHosts new value
- */
- setBack: function(isFromHosts){
- this.set('isFromHosts', isFromHosts);
- },
- /**
- * Send specific command to server
- * @param url
- * @param data Object to send
- */
- sendCommandToServer : function(url, postData, 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' : 'PUT';
- $.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
- callback(null);
- console.log('error on change component host status')
- },
- 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;
- self.sendCommandToServer('/hosts/' + self.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase(),{
- HostRoles:{
- state: 'STARTED'
- }
- }, function(requestId){
- if(!requestId){
- return;
- }
- console.log('Send request for STARTING 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);
- App.router.get('backgroundOperationsController.eventsArray').push({
- "when" : function(controller){
- var result = (controller.getOperationsForRequestId(requestId).length == 0);
- console.log('startComponent.when = ', result)
- return result;
- },
- "do" : function(){
- App.router.get('clusterController').loadUpdatedStatus();
- }
- });
- }
- 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;
- self.sendCommandToServer('/hosts/' + self.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase(),{
- HostRoles:{
- state: 'INSTALLED'
- }
- }, function(requestId){
- if(!requestId){
- return
- }
- console.log('Send request for STOPPING successfully');
- if (App.testMode) {
- component.set('workStatus', App.HostComponentStatus.stopping);
- setTimeout(function(){
- component.set('workStatus', App.HostComponentStatus.stopped);
- },App.testModeDelayForActions);
- } else {
- App.router.get('clusterController').loadUpdatedStatus();
- App.router.get('backgroundOperationsController.eventsArray').push({
- "when" : function(controller){
- var result = (controller.getOperationsForRequestId(requestId).length == 0);
- console.log('stopComponent.when = ', result)
- return result;
- },
- "do" : function(){
- App.router.get('clusterController').loadUpdatedStatus();
- }
- });
- }
- 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);
- }
- App.router.get('backgroundOperationsController').showPopup();
- });
- },
- /**
- * Performs either Decommission or Recommision by updating the hosts list on
- * server.
- */
- doDatanodeDecommission: function(decommissionHostNames){
- var self = this;
- if (decommissionHostNames == null) {
- decommissionHostNames = [];
- }
- var invocationTag = String(new Date().getTime());
- 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 + '/services/HDFS/actions/DECOMMISSION_DATANODE';
- var actionsData = {
- 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);
- }
- App.router.get('backgroundOperationsController').showPopup();
- });
- },
- /**
- * Deletion of hosts not supported for this version
- *
- * validateDeletion: function () { var slaveComponents = [ 'DataNode',
- * 'TaskTracker', 'RegionServer' ]; var masterComponents = []; var
- * workingComponents = [];
- *
- * var components = this.get('content.components');
- * components.forEach(function (cInstance) { var cName =
- * cInstance.get('componentName'); if (slaveComponents.contains(cName)) { if
- * (cInstance.get('workStatus') === App.HostComponentStatus.stopped &&
- * !cInstance.get('decommissioned')) { workingComponents.push(cName); } } else {
- * masterComponents.push(cName); } }); // debugger; if
- * (workingComponents.length || masterComponents.length) {
- * this.raiseWarning(workingComponents, masterComponents); } else {
- * this.deleteButtonPopup(); } },
- */
- raiseWarning: function (workingComponents, masterComponents) {
- var self = this;
- var masterString = '';
- var workingString = '';
- if(masterComponents && masterComponents.length) {
- var masterList = masterComponents.join(', ');
- var ml_text = Em.I18n.t('hosts.cant.do.popup.masterList.body');
- masterString = ml_text.format(masterList);
- }
- if(workingComponents && workingComponents.length) {
- var workingList = workingComponents.join(', ');
- var wl_text = Em.I18n.t('hosts.cant.do.popup.workingList.body');
- workingString = wl_text.format(workingList);
- }
- App.ModalPopup.show({
- header: Em.I18n.t('hosts.cant.do.popup.header'),
- html: true,
- body: masterString + workingString,
- primary: Em.I18n.t('ok'),
- secondary: null,
- onPrimary: function() {
- this.hide();
- }
- })
- },
- /**
- * show confirmation popup to delete host
- */
- deleteButtonPopup: function() {
- var self = this;
- App.showConfirmationPopup(function(){
- self.removeHost();
- });
- },
- /**
- * remove host and open hosts page
- */
- removeHost: function () {
- App.router.get('mainHostController').checkRemoved(this.get('content.id'));
- App.router.transitionTo('hosts');
- }
- })
|