Browse Source

AMBARI-4676. Pass request properties to PASSIVE custom action (ncole)

Nate Cole 11 years ago
parent
commit
6a1f1bfd42

+ 2 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -1538,7 +1538,8 @@ public class AmbariManagementControllerImpl implements
           } else {
           } else {
             sch.setPassiveState(newPassive);
             sch.setPassiveState(newPassive);
             try {
             try {
-              PassiveStateHelper.createRequest(this, sch.getClusterName(), sch.getServiceComponentName());
+              PassiveStateHelper.createRequest(this, sch.getClusterName(),
+                  requestProperties);
             } catch (AmbariException e) {
             } catch (AmbariException e) {
               LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
               LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
             }
             }

+ 2 - 5
ambari-server/src/main/java/org/apache/ambari/server/controller/PassiveStateHelper.java

@@ -120,7 +120,7 @@ public class PassiveStateHelper {
   }
   }
   
   
   public static RequestStatusResponse createRequest(AmbariManagementController amc,
   public static RequestStatusResponse createRequest(AmbariManagementController amc,
-      String clusterName, String desc) throws AmbariException {
+      String clusterName, Map<String, String> requestProperties) throws AmbariException {
     
     
     Map<String, String> params = new HashMap<String, String>();
     Map<String, String> params = new HashMap<String, String>();
     
     
@@ -128,10 +128,7 @@ public class PassiveStateHelper {
         clusterName, RoleCommand.ACTIONEXECUTE.name(),
         clusterName, RoleCommand.ACTIONEXECUTE.name(),
         NAGIOS_ACTION_NAME, NAGIOS_SERVICE, NAGIOS_COMPONENT, null, params);
         NAGIOS_ACTION_NAME, NAGIOS_SERVICE, NAGIOS_COMPONENT, null, params);
 
 
-    Map<String, String> map = new HashMap<String, String>();
-    map.put("context", "Update " + desc + " passive state");
-    
-    return amc.createAction(actionRequest, map);
+    return amc.createAction(actionRequest, requestProperties);
   }  
   }  
   
   
 }
 }

+ 6 - 4
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java

@@ -241,7 +241,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
   }
   }
 
 
   @Override
   @Override
-  public RequestStatus updateResources(Request request, Predicate predicate)
+  public RequestStatus updateResources(final Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
       throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
 
 
     final Set<HostRequest> requests = new HashSet<HostRequest>();
     final Set<HostRequest> requests = new HashSet<HostRequest>();
@@ -252,7 +252,7 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     modifyResources(new Command<Void>() {
     modifyResources(new Command<Void>() {
       @Override
       @Override
       public Void invoke() throws AmbariException {
       public Void invoke() throws AmbariException {
-        updateHosts(requests);
+        updateHosts(requests, request.getRequestInfoProperties());
         return null;
         return null;
       }
       }
     });
     });
@@ -518,7 +518,8 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
     return response;
     return response;
   }
   }
 
 
-  protected synchronized void updateHosts(Set<HostRequest> requests)
+  protected synchronized void updateHosts(Set<HostRequest> requests,
+      Map<String, String> requestProperties)
       throws AmbariException {
       throws AmbariException {
 
 
     if (requests.isEmpty()) {
     if (requests.isEmpty()) {
@@ -576,7 +577,8 @@ public class HostResourceProvider extends AbstractControllerResourceProvider {
           } else {
           } else {
             h.setPassiveState(c.getClusterId(), newState);
             h.setPassiveState(c.getClusterId(), newState);
             try {
             try {
-              PassiveStateHelper.createRequest(controller, c.getClusterName(), h.getHostName());
+              PassiveStateHelper.createRequest(controller, c.getClusterName(),
+                  requestProperties);
             } catch (Exception e) {
             } catch (Exception e) {
               LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
               LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
             }
             }

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java

@@ -562,7 +562,7 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
             s.setPassiveState(newPassive);
             s.setPassiveState(newPassive);
             try {
             try {
               PassiveStateHelper.createRequest(controller, cluster.getClusterName(),
               PassiveStateHelper.createRequest(controller, cluster.getClusterName(),
-                  s.getName());
+                  requestProperties);
             } catch (Exception e) {
             } catch (Exception e) {
               LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
               LOG.warn("Could not send passive status to Nagios (" + e.getMessage() + ")");
             }
             }

+ 4 - 2
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -9220,7 +9220,8 @@ public class AmbariManagementControllerTest {
     // passivate a host
     // passivate a host
     HostRequest hr = new HostRequest(host1, clusterName, requestProperties);
     HostRequest hr = new HostRequest(host1, clusterName, requestProperties);
     hr.setPassiveState(PassiveState.PASSIVE.name());
     hr.setPassiveState(PassiveState.PASSIVE.name());
-    HostResourceProviderTest.updateHosts(controller, Collections.singleton(hr));
+    HostResourceProviderTest.updateHosts(controller, Collections.singleton(hr),
+        new HashMap<String, String>());
     
     
     Host host = hosts.get(host1);
     Host host = hosts.get(host1);
     Assert.assertEquals(PassiveState.PASSIVE, host.getPassiveState(cluster.getClusterId()));
     Assert.assertEquals(PassiveState.PASSIVE, host.getPassiveState(cluster.getClusterId()));
@@ -9240,7 +9241,8 @@ public class AmbariManagementControllerTest {
     
     
     // reset
     // reset
     hr.setPassiveState(PassiveState.ACTIVE.name());
     hr.setPassiveState(PassiveState.ACTIVE.name());
-    HostResourceProviderTest.updateHosts(controller, Collections.singleton(hr));
+    HostResourceProviderTest.updateHosts(controller, Collections.singleton(hr),
+        new HashMap<String, String>());
     
     
     host = hosts.get(host1);
     host = hosts.get(host1);
     Assert.assertEquals(PassiveState.ACTIVE, host.getPassiveState(cluster.getClusterId()));
     Assert.assertEquals(PassiveState.ACTIVE, host.getPassiveState(cluster.getClusterId()));

+ 12 - 6
ambari-server/src/test/java/org/apache/ambari/server/controller/PassiveStateHelperTest.java

@@ -78,10 +78,12 @@ public class PassiveStateHelperTest {
     
     
     replay(amc, cluster, sch);
     replay(amc, cluster, sch);
     
     
-    PassiveStateHelper.createRequest(amc, sch.getClusterName(), sch.getServiceComponentName());
+    Map<String, String> map = new HashMap<String, String>();
+    map.put("context", "abc");
+    PassiveStateHelper.createRequest(amc, sch.getClusterName(), map);
     
     
     ExecuteActionRequest ear = earCapture.getValue();
     ExecuteActionRequest ear = earCapture.getValue();
-    Map<String, String> map = rpCapture.getValue();
+    map = rpCapture.getValue();
     
     
     Assert.assertEquals("nagios_update_ignore", ear.getActionName());
     Assert.assertEquals("nagios_update_ignore", ear.getActionName());
     Assert.assertEquals("ACTIONEXECUTE", ear.getCommandName());
     Assert.assertEquals("ACTIONEXECUTE", ear.getCommandName());
@@ -127,10 +129,12 @@ public class PassiveStateHelperTest {
     
     
     replay(amc, cluster, service, sch1, host);
     replay(amc, cluster, service, sch1, host);
     
     
-    PassiveStateHelper.createRequest(amc, cluster.getClusterName(), host.getHostName());
+    Map<String, String> map = new HashMap<String, String>();
+    map.put("context", "abc");
+    PassiveStateHelper.createRequest(amc, cluster.getClusterName(), map);
     
     
     ExecuteActionRequest ear = earCapture.getValue();
     ExecuteActionRequest ear = earCapture.getValue();
-    Map<String, String> map = rpCapture.getValue();
+    rpCapture.getValue();
     
     
     Assert.assertEquals("nagios_update_ignore", ear.getActionName());
     Assert.assertEquals("nagios_update_ignore", ear.getActionName());
     Assert.assertEquals("ACTIONEXECUTE", ear.getCommandName());
     Assert.assertEquals("ACTIONEXECUTE", ear.getCommandName());
@@ -176,10 +180,12 @@ public class PassiveStateHelperTest {
     
     
     replay(amc, cluster, service, sc1, sc2, sch1);
     replay(amc, cluster, service, sc1, sc2, sch1);
     
     
-    PassiveStateHelper.createRequest(amc, "c1", service.getName());
+    Map<String, String> map = new HashMap<String, String>();
+    map.put("context", "abc");
+    PassiveStateHelper.createRequest(amc, "c1", map);
     
     
     ExecuteActionRequest ear = earCapture.getValue();
     ExecuteActionRequest ear = earCapture.getValue();
-    Map<String, String> map = rpCapture.getValue();
+    map = rpCapture.getValue();
     
     
     Assert.assertEquals("nagios_update_ignore", ear.getActionName());
     Assert.assertEquals("nagios_update_ignore", ear.getActionName());
     Assert.assertEquals("ACTIONEXECUTE", ear.getCommandName());
     Assert.assertEquals("ACTIONEXECUTE", ear.getCommandName());

+ 3 - 2
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java

@@ -1143,10 +1143,11 @@ public class HostResourceProviderTest {
     provider.deleteHosts(requests);
     provider.deleteHosts(requests);
   }
   }
   
   
-  public static void updateHosts(AmbariManagementController controller, Set<HostRequest> requests)
+  public static void updateHosts(AmbariManagementController controller, Set<HostRequest> requests,
+      Map<String, String> requestProperties)
       throws AmbariException {
       throws AmbariException {
     HostResourceProvider provider = getHostProvider(controller);
     HostResourceProvider provider = getHostProvider(controller);
-    provider.updateHosts(requests);
+    provider.updateHosts(requests, requestProperties);
   }
   }
   
   
 }
 }