ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject git commit: AMBARI-5057. Maintenance info not passed on Nagios restart like START/STOP does (ncole)
Date Thu, 13 Mar 2014 14:25:58 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk df85df87e -> e40bf7090


AMBARI-5057.  Maintenance info not passed on Nagios restart like START/STOP does (ncole)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e40bf709
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e40bf709
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e40bf709

Branch: refs/heads/trunk
Commit: e40bf7090a209568b5e5d404d3287d7be734a837
Parents: df85df8
Author: Nate Cole <ncole@hortonworks.com>
Authored: Wed Mar 12 15:57:40 2014 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Thu Mar 13 10:25:23 2014 -0400

----------------------------------------------------------------------
 .../AmbariCustomCommandExecutionHelper.java     | 10 ++
 .../controller/MaintenanceStateHelper.java      |  5 +-
 .../NAGIOS/package/scripts/nagios_server.py     |  7 ++
 .../AmbariManagementControllerTest.java         | 99 ++++++++++++++++++++
 4 files changed, 119 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e40bf709/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index abd82ac..7f63a41 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -21,6 +21,7 @@ package org.apache.ambari.server.controller;
 import com.google.gson.Gson;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
@@ -52,6 +53,7 @@ import org.apache.ambari.server.utils.StageUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -60,6 +62,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
+
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMPONENT_CATEGORY;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.CUSTOM_COMMAND;
@@ -299,6 +302,13 @@ public class AmbariCustomCommandExecutionHelper {
       }
       roleParams.put(COMPONENT_CATEGORY, componentInfo.getCategory());
       execCmd.setRoleParams(roleParams);
+      
+      // if the target is NAGIOS (for example: restart command), make passive info always
available
+      if (execCmd.getRole().equals(Role.NAGIOS_SERVER.name())) {
+        execCmd.setPassiveInfo(
+          MaintenanceStateHelper.getMaintenanceHostComponents(clusters, cluster));
+      }
+      
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/e40bf709/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java
index 833e176..690b83a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/MaintenanceStateHelper.java
@@ -119,6 +119,8 @@ public class MaintenanceStateHelper {
   public static Set<Map<String, String>> getMaintenanceHostComponents(Clusters
clusters, Cluster cluster) throws AmbariException {
     
     Set<Map<String, String>> set = new HashSet<Map<String, String>>();
+
+    Map<String, Host> hosts = clusters.getHostsForCluster(cluster.getClusterName());
     
     for (Service service : cluster.getServices().values()) {
       for (ServiceComponent sc : service.getServiceComponents().values()) {
@@ -126,8 +128,7 @@ public class MaintenanceStateHelper {
           continue;
 
         for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
-          Host host = clusters.getHostsForCluster(
-              cluster.getClusterName()).get(sch.getHostName());
+          Host host = hosts.get(sch.getHostName());
           
           if (MaintenanceState.OFF != getEffectiveState(cluster.getClusterId(),
               service, host, sch)) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/e40bf709/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server.py
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server.py
index 32b6cd9..c115e9a 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server.py
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/NAGIOS/package/scripts/nagios_server.py
@@ -79,12 +79,14 @@ def update_ignorable(params):
     return
   else:
     buf = ""
+    count = 0
     for define in params.config['passiveInfo']:
       try:
         host = str(define['host'])
         service = str(define['service'])
         component = str(define['component'])
         buf += host + " " + service + " " + component + "\n"
+        count += 1
       except KeyError:
         pass
 
@@ -92,7 +94,12 @@ def update_ignorable(params):
     try:
       f = open('/var/nagios/ignore.dat', 'w')
       f.write(buf)
+      if 1 == count:
+        Logger.info("Persisted '/var/nagios/ignore.dat' with 1 entry")
+      elif count > 1:
+        Logger.info("Persisted '/var/nagios/ignore.dat' with " + str(count) + " entries")
     except:
+      Logger.info("Could not persist '/var/nagios/ignore.dat'")
       pass
     finally:
       if f is not None:

http://git-wip-us.apache.org/repos/asf/ambari/blob/e40bf709/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index c2192d0..c877ac0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -4008,8 +4008,107 @@ public class AmbariManagementControllerTest {
     Assert.assertTrue(hostParams.containsKey(ExecutionCommand.KeyNames.MYSQL_JDBC_URL));
     Assert.assertTrue(hostParams.containsKey(ExecutionCommand.KeyNames.ORACLE_JDBC_URL));
     Assert.assertEquals("CLIENT", roleParams.get(ExecutionCommand.KeyNames.COMPONENT_CATEGORY));
+    
+    // verify passive info is not passed when not NAGIOS
+    Assert.assertNull(hrc.getExecutionCommandWrapper().getExecutionCommand().getPassiveInfo());
   }
 
+  @Test
+  public void testPassiveSentWithNagiosRestart() throws AmbariException {
+    setupClusterWithHosts("c1", "HDP-2.0.7", Arrays.asList("h1"), "centos5");
+
+    Cluster cluster = clusters.getCluster("c1");
+    cluster.setDesiredStackVersion(new StackId("HDP-2.0.7"));
+    cluster.setCurrentStackVersion(new StackId("HDP-2.0.7"));
+
+    Service hdfs = cluster.addService("HDFS");
+    hdfs.persist();
+    hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist();
+    hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
+    hdfs.addServiceComponent(Role.DATANODE.name()).persist();
+    
+    hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost("h1").persist();
+    hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost("h1").persist();
+    hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost("h1").persist();
+    
+
+    
+    Service nagios = cluster.addService("NAGIOS");
+    nagios.persist();
+    nagios.addServiceComponent(Role.NAGIOS_SERVER.name()).persist();
+    nagios.getServiceComponent(Role.NAGIOS_SERVER.name()).addServiceComponentHost("h1").persist();
+    
+    installService("c1", "HDFS", false, false);
+    installService("c1", "NAGIOS", false, false);
+
+    startService("c1", "HDFS", false, false);
+    startService("c1", "NAGIOS", false, false);
+
+    // set this after starting - setting it before will skip it due to rules
+    // around bulk starts
+    hdfs.getServiceComponent(Role.DATANODE.name()).getServiceComponentHost(
+        "h1").setMaintenanceState(MaintenanceState.ON);    
+    
+    Cluster c = clusters.getCluster("c1");
+    Service s = c.getService("HDFS");
+
+    Assert.assertEquals(State.STARTED, s.getDesiredState());
+    for (ServiceComponent sc : s.getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        if (sc.isClientComponent()) {
+          Assert.assertEquals(State.INSTALLED, sch.getDesiredState());
+        } else {
+          Assert.assertEquals(State.STARTED, sch.getDesiredState());
+        }
+      }
+    }
+
+    Map<String, String> params = new HashMap<String, String>() {{
+      put("test", "test");
+    }};
+    RequestResourceFilter resourceFilter = new RequestResourceFilter(
+      "NAGIOS",
+      "NAGIOS_SERVER",
+      new ArrayList<String>() {{ add("h1"); }});
+    ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1",
+      "RESTART", params);
+    actionRequest.getResourceFilters().add(resourceFilter);
+
+    Map<String, String> requestProperties = new HashMap<String, String>();
+    requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test");
+
+    RequestStatusResponse response = controller.createAction(actionRequest, requestProperties);
+
+    List<Stage> stages = actionDB.getAllStages(response.getRequestId());
+    Assert.assertNotNull(stages);
+
+    HostRoleCommand hrc = null;
+    for (Stage stage : stages) {
+      for (HostRoleCommand cmd : stage.getOrderedHostRoleCommands()) {
+        if (cmd.getRole().equals(Role.NAGIOS_SERVER)) {
+          hrc = cmd;
+        }
+      }
+    }
+    Assert.assertNotNull(hrc);
+    Assert.assertEquals("RESTART NAGIOS/NAGIOS_SERVER", hrc.getCommandDetail());
+
+    
+    Set<Map<String, String>> pi =
+        hrc.getExecutionCommandWrapper().getExecutionCommand().getPassiveInfo();
+    
+    Assert.assertNotNull(pi);
+    Assert.assertTrue(pi.size() > 0);
+    Map<String, String> map = pi.iterator().next();
+    Assert.assertTrue(map.containsKey("host"));
+    Assert.assertTrue(map.containsKey("service"));
+    Assert.assertTrue(map.containsKey("component"));
+    Assert.assertEquals("h1", map.get("host"));
+    Assert.assertEquals("HDFS", map.get("service"));
+    Assert.assertEquals("DATANODE", map.get("component"));
+  }  
+  
+  
   @SuppressWarnings("serial")
   @Test
   public void testCreateActionsFailures() throws Exception {


Mime
View raw message