Pārlūkot izejas kodu

AMBARI-6415 Allow enabling MM for host components from UI. (ababiichuk)

aBabiichuk 11 gadi atpakaļ
vecāks
revīzija
97e8119745

+ 2 - 1
ambari-web/app/controllers/main/admin/highAvailability/rollback_controller.js

@@ -393,11 +393,12 @@ App.HighAvailabilityRollbackController = App.HighAvailabilityProgressPageControl
     }
     for (var i = 0; i < hostName.length; i++) {
       App.ajax.send({
-        name: 'admin.high_availability.maintenance_mode',
+        name: 'common.host.host_component.passive',
         sender: this,
         data: {
           hostName: hostName[i],
           componentName: componentName,
+          passive_state: "ON",
           taskNum: hostName.length,
           callback: 'checkBeforeDelete'
         },

+ 2 - 1
ambari-web/app/controllers/main/admin/highAvailability/step5_controller.js

@@ -62,10 +62,11 @@ App.HighAvailabilityWizardStep5Controller = App.HighAvailabilityProgressPageCont
   disableSNameNode: function () {
     var hostName = this.get('content.masterComponentHosts').findProperty('component', 'SECONDARY_NAMENODE').hostName;
     App.ajax.send({
-      name: 'admin.high_availability.maintenance_mode',
+      name: 'common.host.host_component.passive',
       sender: this,
       data: {
         hostName: hostName,
+        passive_state: "ON",
         componentName: 'SECONDARY_NAMENODE'
       },
       success: 'onTaskCompleted',

+ 1 - 1
ambari-web/app/controllers/main/admin/user.js

@@ -46,7 +46,7 @@ App.MainAdminUserController = Em.Controller.extend({
 
       onPrimary: function () {
         App.ajax.send({
-          name: 'admin.user.delete',
+          name: 'common.delete.user',
           sender: self,
           data: {
             user: event.context.get("userName"),

+ 43 - 0
ambari-web/app/controllers/main/host/details.js

@@ -1220,6 +1220,40 @@ App.MainHostDetailsController = Em.Controller.extend({
     batchUtils.infoPassiveState(params.passive_state);
   },
 
+  /**
+   * Send request to get passive state for hostComponent
+   * @param {object} component - hostComponentn object
+   * @param {string} state
+   * @param {string} message
+   * @method hostPassiveModeRequest
+   */
+  updateComponentPassiveState: function (component, state, message) {
+    App.ajax.send({
+      name: 'common.host.host_component.passive',
+      sender: this,
+      data: {
+        hostName: this.get('content.hostName'),
+        componentName: component.get('componentName'),
+        component: component,
+        passive_state: state,
+        context: message
+      },
+      success: 'updateHostComponent'
+    });
+  },
+
+  /**
+   * Success callback for receiving hostComponent passive state
+   * @param {object} data
+   * @param {object} opt
+   * @param {object} params
+   * @method updateHost
+   */
+  updateHostComponent: function (data, opt, params) {
+    params.component.set('passiveState', params.passive_state)
+    batchUtils.infoPassiveState(params.passive_state);
+  },
+
   /**
    * Show confirmation popup for action "start all components"
    * @method doStartAllComponents
@@ -1514,5 +1548,14 @@ App.MainHostDetailsController = Em.Controller.extend({
         batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allClientsOnSelectedHost').format(self.get('content.hostName')), "HOST");
       });
     }
+  },
+
+  toggleMaintenanceMode: function(event) {
+    var self = this;
+    var state = event.context.get('passiveState') === "ON" ? "OFF" : "ON";
+    var message = Em.I18n.t('passiveState.turn' + state.toCapital() +'For').format(event.context.get('displayName'));
+    return App.showConfirmationPopup(function () {
+      self.updateComponentPassiveState(event.context, state, message);
+    });
   }
 });

+ 2 - 1
ambari-web/app/controllers/main/service/reassign/step4_controller.js

@@ -147,10 +147,11 @@ App.ReassignMasterWizardStep4Controller = App.HighAvailabilityProgressPageContro
     var hostName = this.get('content.reassignHosts.source');
     for (var i = 0; i < hostComponents.length; i++) {
       App.ajax.send({
-        name: 'reassign.maintenance_mode',
+        name: 'common.host.host_component.passive',
         sender: this,
         data: {
           hostName: hostName,
+          passive_state: "ON",
           componentName: hostComponents[i]
         },
         success: 'onComponentsTasksSuccess',

+ 1 - 1
ambari-web/app/controllers/wizard/step8_controller.js

@@ -938,7 +938,7 @@ App.WizardStep8Controller = Em.Controller.extend({
   deleteClusters: function (clusterNames) {
     clusterNames.forEach(function (clusterName, index) {
       App.ajax.send({
-        name: 'wizard.step8.delete_cluster',
+        name: 'common.delete.cluster',
         sender: this,
         data: {
           name: clusterName,

+ 12 - 2
ambari-web/app/templates/main/host/details/host_component.hbs

@@ -37,9 +37,9 @@
   {{#if component.staleConfigs}}
     <span class="text-warning icon-refresh"></span>
   {{/if}}
-  {{#if component.service.isInPassive}}
+  {{#unless component.isActive}}
     <span class="icon-medkit"></span>
-  {{/if}}
+  {{/unless}}
 </div>
 <div class="span5 pull-right">
   {{#if App.isAdmin}}
@@ -100,6 +100,16 @@
               </a>
             </li>
           {{/if}}
+          <li {{bindAttr class="view.noActionAvailable"}}>
+            <a href="javascript:void(null)"
+               data-toggle="modal" {{action "toggleMaintenanceMode" view.content target="controller"}}>
+              {{#if view.isActive}}
+                {{t passiveState.turnOn}}
+              {{else}}
+                {{t passiveState.turnOff}}
+              {{/if}}
+            </a>
+          </li>
         {{/unless}}
         {{#if view.isInit}}
           <li {{bindAttr class="view."}}>

+ 56 - 124
ambari-web/app/utils/ajax/ajax.js

@@ -147,15 +147,70 @@ var urls = {
     }
   },
 
+  'common.service.passive': {
+    'real': '/clusters/{clusterName}/services/{serviceName}',
+    'mock': '',
+    'format': function (data) {
+      return {
+        type: 'PUT',
+        data: JSON.stringify({
+          RequestInfo: {
+            "context": data.requestInfo
+          },
+          Body: {
+            ServiceInfo: {
+              maintenance_state: data.passive_state
+            }
+          }
+        })
+      };
+    }
+  },
+
+  'common.host.host_component.passive': {
+    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
+    'mock': '',
+    'type': 'PUT',
+    'format': function(data) {
+      return {
+        data: JSON.stringify({
+          RequestInfo: {
+            "context": data.context
+          },
+          Body: {
+            HostRoles: {
+              maintenance_state: data.passive_state
+            }
+          }
+        })
+      };
+    }
+  },
+
   'common.delete.host': {
     'real': '/clusters/{clusterName}/hosts/{hostName}',
     'type': 'DELETE'
   },
-
   'common.delete.host_component': {
     'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
     'type': 'DELETE'
   },
+  'common.delete.user': {
+    'real': '/users/{user}',
+    'type': 'DELETE'
+  },
+  'common.delete.config_group': {
+    'real': '/clusters/{clusterName}/config_groups/{id}',
+    'type': 'DELETE'
+  },
+  'common.delete.cluster': {
+    'real': '/clusters/{name}',
+    'type': 'DELETE'
+  },
+  'common.delete.request_schedule': {
+    'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
+    'type': 'DELETE'
+  },
 
   'alerts.get_by_service': {
     'real': '/clusters/{clusterName}/services/{serviceName}?fields=alerts',
@@ -196,25 +251,6 @@ var urls = {
       };
     }
   },
-  'service.item.passive': {
-    'real': '/clusters/{clusterName}/services/{serviceName}',
-    'mock': '',
-    'format': function (data) {
-      return {
-        type: 'PUT',
-        data: JSON.stringify({
-          RequestInfo: {
-            "context": data.requestInfo
-          },
-          Body: {
-            ServiceInfo: {
-              maintenance_state: data.passive_state
-            }
-          }
-        })
-      };
-    }
-  },
   'service.load_config_groups': {
     'real': '/clusters/{clusterName}/config_groups?ConfigGroup/tag={serviceName}&fields=*',
     'mock': '/data/configurations/config_group.json'
@@ -239,22 +275,6 @@ var urls = {
       }
     }
   },
-  'reassign.maintenance_mode': {
-    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
-    'mock': '',
-    'type': 'PUT',
-    'format': function () {
-      return {
-        data: JSON.stringify(
-          {
-            "HostRoles": {
-              "maintenance_state": "ON"
-            }
-          }
-        )
-      }
-    }
-  },
   'reassign.load_configs': {
     'real': '/clusters/{clusterName}/configurations?{urlParams}',
     'mock': ''
@@ -279,26 +299,6 @@ var urls = {
     }
   },
 
-  'host_component.passive': {
-    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
-    'mock': '',
-    'type': 'PUT',
-    'format': function(data) {
-      return {
-        data: JSON.stringify({
-          RequestInfo: {
-            "context": data.requestInfo
-          },
-          Body: {
-            HostRoles: {
-              maintenance_state: data.passive_state
-            }
-          }
-        })
-      };
-    }
-  },
-
   'config.cluster_configuration.put': {
     'real': '/clusters/{cluster}',
     'mock': '',
@@ -354,11 +354,6 @@ var urls = {
       }
     }
   },
-  'config_groups.delete_config_group': {
-    'real': '/clusters/{clusterName}/config_groups/{id}',
-    'mock': '',
-    'type': 'DELETE'
-  },
   'config.on_site': {
     'real': '/clusters/{clusterName}/configurations?{params}',
     'mock': '/data/configurations/cluster_level_configs.json?{params}',
@@ -437,26 +432,6 @@ var urls = {
       }
     }
   },
-  'host.host_component.recommission_slave' : {
-    'real' : '/clusters/{clusterName}/requests',
-    'mock' : '',
-    'format' : function(data) {
-      return {
-        type : 'POST',
-        data : JSON.stringify({
-          RequestInfo: {
-            context: data.context,
-            command: data.command,
-            parameters: {
-              slave_type: data.slaveType,
-              included_hosts: data.hostName
-            }
-          },
-          "Requests/resource_filters": [{"service_name" : data.serviceName, "component_name" : data.componentName}]
-        })
-      }
-    }
-  },
 
   'host.host_component.refresh_configs': {
     'real':'/clusters/{clusterName}/requests',
@@ -855,20 +830,6 @@ var urls = {
       }
     }
   },
-  'admin.high_availability.maintenance_mode': {
-    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
-    'mock': '',
-    'type': 'PUT',
-    'format': function () {
-      return {
-        data: JSON.stringify({
-          "HostRoles": {
-            "state": "DISABLED"
-          }
-        })
-      }
-    }
-  },
   'admin.high_availability.load_configs': {
     'real': '/clusters/{clusterName}/configurations?(type=core-site&tag={coreSiteTag})|(type=hdfs-site&tag={hdfsSiteTag})',
     'mock': ''
@@ -967,16 +928,6 @@ var urls = {
     }
   },
 
-  'admin.user.delete': {
-    'real': '/users/{user}',
-    'mock': '/data/users/users.json',
-    'format': function() {
-      return {
-        type: 'DELETE'
-      }
-    }
-  },
-
   'admin.user.edit': {
     'real': '/users/{user}',
     'mock':'/data/users/users.json',
@@ -1031,15 +982,6 @@ var urls = {
     }
   },
 
-  'wizard.step8.delete_cluster': {
-    'real': '/clusters/{name}',
-    'mock': '',
-    'format': function() {
-      return {
-        type: 'DELETE'
-      };
-    }
-  },
   'wizard.step8.existing_cluster_names': {
     'real': '/clusters',
     'mock': '',
@@ -1354,15 +1296,6 @@ var urls = {
       }
     }
   },
-  'request_schedule.delete': {
-    'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
-    'mock': '',
-    'format' : function() {
-      return {
-        type : 'DELETE'
-      }
-    }
-  },
   'request_schedule.get': {
     'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
     'mock': ''
@@ -1414,7 +1347,6 @@ var urls = {
     'apiPrefix': ''
   },
 
-
   'mirroring.create_new_dataset': {
     'real': '/proxy?url=http://{falconServer}:15000/api/entities/submitAndSchedule/feed?user.name=ambari-qa',
     'mock': '/data/mirroring/succeeded.json',

+ 2 - 2
ambari-web/app/utils/batch_scheduled_requests.js

@@ -267,7 +267,7 @@ module.exports = {
 
   turnOnOffPassiveRequest: function(state, message, serviceName, callback) {
     App.ajax.send({
-      'name': 'service.item.passive',
+      'name': 'common.service.passive',
       'sender': {
         'successCallback': callback || defaultSuccessCallback,
         'errorCallback': defaultErrorCallback
@@ -551,7 +551,7 @@ module.exports = {
     if (requestScheduleId != null && !isNaN(requestScheduleId) && requestScheduleId > -1) {
       errorCallback = errorCallback || defaultErrorCallback;
       App.ajax.send({
-        name : 'request_schedule.delete',
+        name : 'common.delete.request_schedule',
         sender : {
           successCallbackFunction : function(data) {
             successCallback(data);

+ 1 - 2
ambari-web/app/utils/config.js

@@ -19,7 +19,6 @@
 var App = require('app');
 var stringUtils = require('utils/string_utils');
 
-var categotyConfigs = require('data/service_configs');
 var configGroupsByTag = [];
 
 App.config = Em.Object.create({
@@ -1460,7 +1459,7 @@ App.config = Em.Object.create({
 
   deleteConfigGroup: function (configGroup, successCallback, errorCallback) {
     var sendData = {
-      name: 'config_groups.delete_config_group',
+      name: 'common.delete.config_group',
       sender: this,
       data: {
         id: configGroup.get('id')

+ 10 - 0
ambari-web/app/utils/helper.js

@@ -66,6 +66,16 @@ String.prototype.capitalize = function () {
   return this.charAt(0).toUpperCase() + this.slice(1);
 };
 
+/**
+ * Capitalize the first letter of string.
+ * And set to lowercase other part of string
+ * @method toCapital
+ * @return {string}
+ */
+String.prototype.toCapital = function () {
+  return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
+};
+
 /**
  * Finds the value in an object where this string is a key.
  * Optionally, the index of the key can be provided where the

+ 0 - 8
ambari-web/app/views/main/host/details/host_component_view.js

@@ -184,14 +184,6 @@ App.HostComponentView = Em.View.extend({
     return (this.get('content.passiveState') == "OFF");
   }.property('content.passiveState'),
 
-  /**
-   * For PASSIVE <code>passiveState</code> of host or service
-   * @type {bool}
-   */
-  isImplied: function() {
-    return (this.get('parentView.content.passiveState') === 'ON' || this.get('content.service.passiveState') === 'ON');
-  }.property('parentView.content.passiveState', 'content.service.passiveState'),
-
   /**
    * Shows whether we need to show Delete button
    * @type {bool}

+ 0 - 43
ambari-web/test/views/main/host/details/host_component_view_test.js

@@ -187,49 +187,6 @@ describe('App.HostComponentView', function() {
 
   });
 
-  describe('#isImplied', function() {
-
-    var tests = Em.A([
-      {
-        content: {service: {passiveState: 'ON'}},
-        parentView: {content: {passiveState: 'ON'}},
-        m: 'service in ON, host in ON',
-        e: true
-      },
-      {
-        content: {service: {passiveState: 'ON', serviceName:'SERVICE_NAME'}},
-        parentView: {content: {passiveState: 'OFF'}},
-        m: 'service in ON, host in OFF',
-        e: true
-      },
-      {
-        content: {service: {passiveState: 'OFF', serviceName:'SERVICE_NAME'}},
-        parentView: {content: {passiveState: 'ON'}},
-        m: 'service in OFF, host in ON',
-        e: true
-      },
-      {
-        content: {service: {passiveState: 'OFF'}},
-        parentView: {content: {passiveState: 'OFF'}},
-        m: 'service in OFF, host in OFF',
-        e: false
-      }
-    ]);
-
-    tests.forEach(function(test) {
-      it(test.m, function() {
-        hostComponentView = App.HostComponentView.create({
-          startBlinking: function(){},
-          doBlinking: function(){},
-          parentView: test.parentView,
-          content: test.content
-        });
-        expect(hostComponentView.get('isImplied')).to.equal(test.e);
-      });
-    });
-
-  });
-
   describe('#isRestartComponentDisabled', function() {
 
     var tests = ['STARTED'];