浏览代码

AMBARI-5635 UI changes for required for MM support. (ababiichuk)

aBabiichuk 11 年之前
父节点
当前提交
6cd8a8021e

+ 4 - 2
ambari-web/app/controllers/main/host.js

@@ -194,6 +194,7 @@ App.MainHostController = Em.ArrayController.extend({
         query.push(subQuery.fmt(components.join(',')));
       }
     });
+    var hostNames = hosts.mapProperty('hostName').join(",");
     if (query.length) {
       query = query.join('|');
       App.ajax.send({
@@ -202,7 +203,8 @@ App.MainHostController = Em.ArrayController.extend({
         data: {
           query: query,
           state: operationData.action,
-          requestInfo: operationData.message
+          requestInfo: operationData.message,
+          hostName: hostNames
         },
         success: 'bulkOperationForHostComponentsSuccessCallback'
       });
@@ -226,7 +228,7 @@ App.MainHostController = Em.ArrayController.extend({
     hosts.forEach(function(host) {
       hostComponents.pushObjects(host.get('hostComponents').filterProperty('passiveState','OFF').toArray());
     });
-    batchUtils.restartHostComponents(hostComponents, Em.I18n.t('rollingrestart.context.allOnSelectedHosts'));
+    batchUtils.restartHostComponents(hostComponents, Em.I18n.t('rollingrestart.context.allOnSelectedHosts'), "HOST");
   },
 
   /**

+ 28 - 12
ambari-web/app/controllers/main/host/details.js

@@ -111,7 +111,7 @@ App.MainHostDetailsController = Em.Controller.extend({
    * @method sendStartComponentCommand
    */
   sendStartComponentCommand: function (component, context) {
-    var dataToSend = this.getDataToSend('STARTED', context);
+    var dataToSend = this.getDataToSend('STARTED', context, component);
     var data = {
       hostName: this.get('content.hostName'),
       component: component
@@ -127,14 +127,30 @@ App.MainHostDetailsController = Em.Controller.extend({
   },
   /**
    * construct meta data for query
-   * @param state
-   * @param context
-   * @return {Object}
-   */
-  getDataToSend: function (state, context) {
+   * @param {String} state
+   * @param {String} context
+   * @param {String|Array} component - componentName or Array of components
+   * @return {Object} request info
+   * @method getDataToSend creates request info to start/stop component(s)
+   */
+  getDataToSend: function (state, context, component) {
+    var operationLevel = {
+      "cluster_name":  App.get('clusterName'),
+      "host_name": this.get("content.hostName")
+    };
+
+    if (Array.isArray(component)) {
+      operationLevel["level"] = "HOST";
+    } else if(component){
+      operationLevel["level"] = "HOST_COMPONENT",
+      operationLevel["hostcomponent_name"] = component.get("componentName"),
+      operationLevel["service_name"] = component.get("service.serviceName")
+    }
+
     return {
       RequestInfo: {
-        "context": context
+        "context": context,
+        "operation_level": operationLevel
       },
       Body: {
         HostRoles: {
@@ -390,7 +406,7 @@ App.MainHostDetailsController = Em.Controller.extend({
    * @method sendStopComponentCommand
    */
   sendStopComponentCommand: function (component, context) {
-    var dataToSend = this.getDataToSend('INSTALLED', context);
+    var dataToSend = this.getDataToSend('INSTALLED', context, component);
     var data = {
       hostName: this.get('content.hostName'),
       component: component
@@ -431,7 +447,7 @@ App.MainHostDetailsController = Em.Controller.extend({
   restartComponent: function (event) {
     var component = event.context;
     return App.showConfirmationPopup(function () {
-      batchUtils.restartHostComponents([component], Em.I18n.t('rollingrestart.context.selectedComponentOnSelectedHost').format(component.get('displayName')));
+      batchUtils.restartHostComponents([component], Em.I18n.t('rollingrestart.context.selectedComponentOnSelectedHost').format(component.get('displayName')), "HOST_COMPONENT");
     });
   },
   /**
@@ -1356,7 +1372,7 @@ App.MainHostDetailsController = Em.Controller.extend({
     var componentsLength = Em.isNone(components) ? 0 : components.get('length');
     if (componentsLength > 0) {
       App.showConfirmationPopup(function () {
-        batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allOnSelectedHost').format(self.get('content.hostName')));
+        batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allOnSelectedHost').format(self.get('content.hostName')), "HOST");
       });
     }
   },
@@ -1566,7 +1582,7 @@ App.MainHostDetailsController = Em.Controller.extend({
     var self = this;
     return App.showConfirmationPopup(function () {
       var staleComponents = self.get('content.componentsWithStaleConfigs');
-      batchUtils.restartHostComponents(staleComponents, Em.I18n.t('rollingrestart.context.allWithStaleConfigsOnSelectedHost').format(self.get('content.hostName')));
+      batchUtils.restartHostComponents(staleComponents, Em.I18n.t('rollingrestart.context.allWithStaleConfigsOnSelectedHost').format(self.get('content.hostName')), "HOST");
     });
   },
 
@@ -1598,7 +1614,7 @@ App.MainHostDetailsController = Em.Controller.extend({
     });
     if (components.get('length') > 0) {
       return App.showConfirmationPopup(function () {
-        batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allClientsOnSelectedHost').format(self.get('content.hostName')));
+        batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allClientsOnSelectedHost').format(self.get('content.hostName')), "HOST");
       });
     }
   }

+ 4 - 2
ambari-web/app/controllers/main/service.js

@@ -120,11 +120,13 @@ App.MainServiceController = Em.ArrayController.extend({
     if (state == 'stopAllService') {
       data = '{"RequestInfo": {"context" :"' +
         App.BackgroundOperationsController.CommandContexts.STOP_ALL_SERVICES +
-        '"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
+        '", "operation_level": {"level": "CLUSTER","cluster_name" : "' + App.get('clusterName') +
+        '"}}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}';
     } else {
       data = '{"RequestInfo": {"context" :"' +
         App.BackgroundOperationsController.CommandContexts.START_ALL_SERVICES +
-        '"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
+        '", "operation_level": {"level": "CLUSTER","cluster_name" : "' + App.get('clusterName') +
+        '"}}, "Body": {"ServiceInfo": {"state": "STARTED"}}}';
     }
 
     App.ajax.send({

+ 1 - 1
ambari-web/app/controllers/main/service/item.js

@@ -313,7 +313,7 @@ App.MainServiceItemController = Em.Controller.extend({
     var self = this;
     if (this.get('content.isClientsOnly')) {
       return App.showConfirmationFeedBackPopup(function(query) {
-        batchUtils.restartHostComponents(self.get('content.hostComponents'), Em.I18n.t('rollingrestart.context.allForSelectedService').format(self.get('content.serviceName')), query);
+        batchUtils.restartHostComponents(self.get('content.hostComponents'), Em.I18n.t('rollingrestart.context.allForSelectedService').format(self.get('content.serviceName')),"SERVICE",  query);
       });
     }
   },

+ 14 - 34
ambari-web/app/utils/ajax/ajax.js

@@ -71,7 +71,12 @@ var urls = {
         type: 'PUT',
         data: JSON.stringify({
           RequestInfo: {
-            "context": data.requestInfo
+            "context": data.requestInfo,
+            "operation_level": {
+              "level": "SERVICE",
+              "cluster_name" : data.clusterName,
+              "service_name" : data.serviceName
+            }
           },
           Body: {
             ServiceInfo: {
@@ -398,25 +403,6 @@ var urls = {
       };
     }
   },
-  'host.host_component.action': {
-    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
-    'mock': '',
-    'type': 'PUT',
-    'format': function (data) {
-      return {
-        data: JSON.stringify({
-          RequestInfo: {
-            "context": data.context
-          },
-          Body: {
-            "HostRoles": {
-              "state": data.state
-            }
-          }
-        })
-      }
-    }
-  },
 
   'host.host_component.delete': {
     'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
@@ -474,18 +460,6 @@ var urls = {
     }
   },
 
-  'host.host_components.start': {
-    'real': '/clusters/{clusterName}/hosts/{hostName}/host_components',
-    'mock': '/data/wizard/deploy/poll_1.json',
-    'format': function(data) {
-      return {
-        type: 'PUT',
-        async: false,
-        data: data.data
-      }
-    }
-  },
-
   'host.host_component.install': {
     'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
     'mock': '/data/wizard/deploy/poll_1.json',
@@ -1775,7 +1749,8 @@ var urls = {
         data : JSON.stringify({
           "RequestInfo": {
             "command": "RESTART",
-            "context": data.context
+            "context": data.context,
+            "operation_level": data.operation_level
           },
           "Requests/resource_filters": data.resource_filters
         })
@@ -1964,7 +1939,12 @@ var urls = {
         data: JSON.stringify({
           RequestInfo: {
             context: data.requestInfo,
-            query: data.query
+            query: data.query,
+            operation_level: {
+              level: "HOST",
+              cluster_name: data.clusterName,
+              host_name: data.hostName
+            }
           },
           Body: {
             HostRoles: {

+ 38 - 3
ambari-web/app/utils/batch_scheduled_requests.js

@@ -89,7 +89,7 @@ module.exports = {
       if (staleConfigsOnly) {
         hostComponents = hostComponents.filterProperty('staleConfigs', true);
       }
-      this.restartHostComponents(hostComponents, context, query);
+      this.restartHostComponents(hostComponents, context, "SERVICE", query);
     }
   },
 
@@ -97,8 +97,10 @@ module.exports = {
    * Restart list of host components
    * @param {Ember.Enumerable} hostComponentsList list of host components should be restarted
    * @param {String} context message to show in BG popup
+   * @param {String} level - operation level, can be ("CLUSTER", "SERVICE", "HOST", "HOSTCOMPONENT")
+   * @param {String} query
    */
-  restartHostComponents: function(hostComponentsList, context, query) {
+  restartHostComponents: function(hostComponentsList, context, level, query) {
     context = context || Em.I18n.t('rollingrestart.context.default');
     /**
      * Format: {
@@ -108,6 +110,7 @@ module.exports = {
      * }
      */
     var componentToHostsMap = {};
+    var hosts = [];
     var componentServiceMap = App.QuickDataMapper.componentServiceMap();
     hostComponentsList.forEach(function(hc) {
       var componentName = hc.get('componentName');
@@ -115,6 +118,7 @@ module.exports = {
         componentToHostsMap[componentName] = [];
       }
       componentToHostsMap[componentName].push(hc.get('host.hostName'));
+      hosts.push(hc.get('host.hostName'));
     });
     var resource_filters = [];
     for (var componentName in componentToHostsMap) {
@@ -126,6 +130,12 @@ module.exports = {
         });
       }
     }
+      if(hostComponentsList.length > 0) {
+      var operation_level = this.getOperationLevelobject(level, hosts.uniq().join(","),
+          hostComponentsList[0].get("service.serviceName"), hostComponentsList[0].get("componentName"));
+    }
+
+
     if (resource_filters.length) {
       App.ajax.send({
         name: 'restart.hostComponents',
@@ -136,7 +146,8 @@ module.exports = {
         data: {
           context: context,
           resource_filters: resource_filters,
-          query: query
+          query: query,
+          operation_level: operation_level
         },
         success: 'successCallback',
         error: 'errorCallback'
@@ -144,6 +155,30 @@ module.exports = {
     }
   },
 
+  /**
+   * @param {String} level - operation level name, can be ("CLUSTER", "SERVICE", "HOST", "HOSTCOMPONENT")
+   * @param {String} hostName get host name or hostNames as String("host1,host2")
+   * @param {String} serviceName
+   * @param {String} componentName
+   * @returns {Object} {{level: *, cluster_name: *}} - operation level object
+   * @method getOperationLevelobject - create operation level object to be included into ajax query
+   */
+  getOperationLevelobject: function(level, hostName, serviceName, componentName) {
+    var operationLevel = {
+      "level": level,
+      "cluster_name": App.get("clusterName")
+    };
+    if (level === "HOST") {
+      operationLevel["host_name"] = hostName;
+    } else if (level === "SERVICE") {
+      operationLevel["service_name"] = serviceName;
+    } else {
+      operationLevel["host_name"] = hostName;
+      operationLevel["service_name"] = serviceName;
+      operationLevel["hostcomponent_name"] = componentName;
+    }
+    return operationLevel;
+  },
   /**
    * Makes a REST call to the server requesting the rolling restart of the
    * provided host components.

+ 34 - 2
ambari-web/test/controllers/main/host/details_test.js

@@ -126,10 +126,42 @@ describe('App.MainHostDetailsController', function () {
   });
 
   describe('#getDataToSend()', function () {
+    var component = Em.Object.create({
+      componentName: 'comp1',
+      host: {
+        hostName: 'host1'
+      },
+      service: {
+        serviceName: 'serv1'
+      }
+    });
     it('should return correct query info', function () {
-      expect(controller.getDataToSend('STATE1', 'context')).to.eql({
+      controller.set("content.hostName", "host1");
+      expect(controller.getDataToSend('STATE1', 'context', component)).to.deep.eql({
         RequestInfo: {
-          "context": 'context'
+          "context": 'context',
+          "operation_level": {
+            "cluster_name": "tdk",
+            "host_name": "host1",
+            "hostcomponent_name": "comp1",
+            "service_name": "serv1",
+            "level": "HOST_COMPONENT"
+          }
+        },
+        Body: {
+          HostRoles: {
+            state: 'STATE1'
+          }
+        }
+      });
+      expect(controller.getDataToSend('STATE1', 'context', [component])).to.deep.eql({
+        RequestInfo: {
+          "context": 'context',
+          "operation_level": {
+            "cluster_name": "tdk",
+            "host_name": "host1",
+            "level": "HOST"
+          }
         },
         Body: {
           HostRoles: {