Forráskód Böngészése

AMBARI-12771. Adding a CustomCommands causes Components are not being displayed in Host view. (Shantanu Mundkur and Jaimin Jetly)

Jaimin Jetly 10 éve
szülő
commit
7871a32927

+ 4 - 2
ambari-web/app/views/main/host/details/host_component_view.js

@@ -350,11 +350,13 @@ App.HostComponentView = Em.View.extend({
       if (!isSlave && !self.meetsCustomCommandReq(component, command)) {
         return;
       }
+
+      var isContextPresent =  (!isSlave && (command in App.HostComponentActionMap.getMap(self)) &&  App.HostComponentActionMap.getMap(self)[command].context);
       customCommands.push({
         label: self.getCustomCommandLabel(command, isSlave),
         service: component.get('serviceName'),
         hosts: hostComponent.get('hostName'),
-        context: isSlave ? null : App.HostComponentActionMap.getMap(self)[command].context,
+        context: isContextPresent ? App.HostComponentActionMap.getMap(self)[command].context : null,
         component: component.get('componentName'),
         command: command
       });
@@ -370,7 +372,7 @@ App.HostComponentView = Em.View.extend({
    * @returns {String}
    */
   getCustomCommandLabel: function (command, isSlave) {
-    if (isSlave) {
+    if (isSlave || !(command in App.HostComponentActionMap.getMap(this)) || !App.HostComponentActionMap.getMap(this)[command].label) {
       return Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(command)
     }
     return App.HostComponentActionMap.getMap(this)[command].label;

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

@@ -588,4 +588,70 @@ describe('App.HostComponentView', function() {
       hostComponentView.runningComponentCounter.restore();
     });
   });
+
+  describe('#getCustomCommandLabel', function() {
+
+    beforeEach(function () {
+      sinon.stub(App.HostComponentActionMap, 'getMap', function () {
+        return {
+          MASTER_CUSTOM_COMMAND: {
+            action: 'executeCustomCommand',
+            cssClass: 'icon-play-circle',
+            isHidden: false,
+            disabled: false
+          },
+          REFRESHQUEUES: {
+            action: 'refreshYarnQueues',
+            customCommand: 'REFRESHQUEUES',
+            context : Em.I18n.t('services.service.actions.run.yarnRefreshQueues.context'),
+            label: Em.I18n.t('services.service.actions.run.yarnRefreshQueues.menu'),
+            cssClass: 'icon-refresh',
+            disabled: false
+          }
+        }
+      });
+    });
+    afterEach(function() {
+      App.HostComponentActionMap.getMap.restore();
+    });
+
+    var tests = Em.A([
+      {
+        msg: 'Non-slave component not present in `App.HostComponentActionMap.getMap()` should have a default valid label',
+        isSlave: false,
+        command: 'CUSTOM',
+        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('CUSTOM')
+      },
+      {
+        msg: 'Non-slave component present in `App.HostComponentActionMap.getMap()` with no label should have a default valid label',
+        isSlave: false,
+        command: 'MASTER_CUSTOM_COMMAND',
+        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('MASTER_CUSTOM_COMMAND')
+      },
+      {
+        msg: 'Non-slave component present in `App.HostComponentActionMap.getMap()` with label should have a custom valid label',
+        isSlave: false,
+        command: 'REFRESHQUEUES',
+        e: Em.I18n.t('services.service.actions.run.yarnRefreshQueues.menu')
+      },
+      {
+        msg: 'Slave component not present in `App.HostComponentActionMap.getMap()` should have a default valid label',
+        isSlave: true,
+        command: 'CUSTOM',
+        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('CUSTOM')
+      },
+      {
+        msg: 'Slave component present in `App.HostComponentActionMap.getMap()` should have a default valid label',
+        isSlave: true,
+        command: 'REFRESHQUEUES',
+        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('REFRESHQUEUES')
+      }
+    ]);
+
+    tests.forEach(function(test) {
+      it(test.msg, function() {
+        expect(hostComponentView.getCustomCommandLabel(test.command, test.isSlave)).to.equal(test.e);
+      })
+    });
+  });
 });