You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2014/01/03 20:58:17 UTC

git commit: AMBARI-4224. When issuing Start/Stop of host components then predicate stale_config=true does not work

Updated Branches:
  refs/heads/branch-1.4.3 5f4f34773 -> 0d0291bc9


AMBARI-4224. When issuing Start/Stop of host components then predicate stale_config=true does not work


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

Branch: refs/heads/branch-1.4.3
Commit: 0d0291bc9a8fde9458e349fd3972b86b4d30a285
Parents: 5f4f347
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Fri Jan 3 11:58:03 2014 -0800
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Fri Jan 3 11:58:03 2014 -0800

----------------------------------------------------------------------
 .../AmbariManagementControllerImpl.java         | 19 +++--
 .../controller/ServiceComponentHostRequest.java | 16 ++++
 .../internal/HostComponentResourceProvider.java |  4 +
 .../AmbariManagementControllerTest.java         | 87 ++++++++++++++++++++
 4 files changed, 121 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0d0291bc/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 6e3329c..0435322 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -589,7 +589,7 @@ public class AmbariManagementControllerImpl implements
 
     if (request.getHostname() != null) {
       try {
-        if (! clusters.getClustersForHost(request.getHostname()).contains(cluster)) {
+        if (!clusters.getClustersForHost(request.getHostname()).contains(cluster)) {
           // case where host exists but not associated with given cluster
           throw new ParentObjectNotFoundException("Parent Host resource doesn't exist",
               new HostNotFoundException(request.getClusterName(), request.getHostname()));
@@ -617,7 +617,7 @@ public class AmbariManagementControllerImpl implements
         if (serviceName == null
             || serviceName.isEmpty()) {
           throw new ServiceComponentHostNotFoundException(
-              cluster.getClusterName(), null, request.getComponentName(),request.getHostname());
+              cluster.getClusterName(), null, request.getComponentName(), request.getHostname());
         }
         request.setServiceName(serviceName);
       }
@@ -635,6 +635,12 @@ public class AmbariManagementControllerImpl implements
 
     boolean checkDesiredState = false;
     State desiredStateToCheck = null;
+    boolean filterBasedConfigStaleness = false;
+    boolean staleConfig = true;
+    if (request.getStaleConfig() != null) {
+      filterBasedConfigStaleness = true;
+      staleConfig = "true".equals(request.getStaleConfig().toLowerCase());
+    }
     if (request.getDesiredState() != null
         && !request.getDesiredState().isEmpty()) {
       desiredStateToCheck = State.valueOf(request.getDesiredState());
@@ -653,7 +659,7 @@ public class AmbariManagementControllerImpl implements
       } else {
         components.addAll(s.getServiceComponents().values());
       }
-      for(ServiceComponent sc : components) {
+      for (ServiceComponent sc : components) {
         if (request.getComponentName() != null) {
           if (!sc.getName().equals(request.getComponentName())) {
             continue;
@@ -676,13 +682,12 @@ public class AmbariManagementControllerImpl implements
           } catch (ServiceComponentHostNotFoundException e) {
             if (request.getServiceName() != null && request.getComponentName() != null) {
               throw new ServiceComponentHostNotFoundException(cluster.getClusterName(),
-                  request.getServiceName(), request.getComponentName(),request.getHostname());
+                  request.getServiceName(), request.getComponentName(), request.getHostname());
             } else {
               // ignore this since host_component was not specified
               // this is an artifact of how we get host_components and can happen
               // in case where we get all host_components for a host
             }
-
           }
         } else {
           for (ServiceComponentHost sch :
@@ -691,7 +696,11 @@ public class AmbariManagementControllerImpl implements
                 && (desiredStateToCheck != sch.getDesiredState())) {
               continue;
             }
+
             ServiceComponentHostResponse r = sch.convertToResponse();
+            if (filterBasedConfigStaleness && r.isStaleConfig() != staleConfig) {
+              continue;
+            }
             response.add(r);
           }
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0d0291bc/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
index 7cfc489..13cbde9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
@@ -33,6 +33,8 @@ public class ServiceComponentHostRequest {
   private String desiredState; // CREATE/UPDATE
 
   private String desiredStackId; // UPDATE
+
+  private String staleConfig; // GET - predicate
   
   public ServiceComponentHostRequest(String clusterName,
                                      String serviceName,
@@ -131,6 +133,20 @@ public class ServiceComponentHostRequest {
     this.clusterName = clusterName;
   }
 
+  /**
+   * @param staleConfig whether the config is stale
+   */
+  public void setStaleConfig(String staleConfig) {
+    this.staleConfig = staleConfig;
+  }
+
+  /**
+   * @return Stale config indicator
+   */
+  public String getStaleConfig() {
+    return this.staleConfig;
+  }
+
   public String toString() {
     StringBuilder sb = new StringBuilder();
     sb.append("{"

http://git-wip-us.apache.org/repos/asf/ambari/blob/0d0291bc/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
index 108bd1d..0485c4a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
@@ -292,6 +292,10 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
         (String) properties.get(HOST_COMPONENT_STATE_PROPERTY_ID));
     serviceComponentHostRequest.setDesiredStackId(
         (String) properties.get(HOST_COMPONENT_STACK_ID_PROPERTY_ID));
+    if (properties.get(HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID) != null) {
+      serviceComponentHostRequest.setStaleConfig(
+          properties.get(HOST_COMPONENT_STALE_CONFIGS_PROPERTY_ID).toString());
+    }
 
     return serviceComponentHostRequest;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0d0291bc/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 811e62d..aba1140 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
@@ -2100,9 +2100,96 @@ public class AmbariManagementControllerTest {
         resp.getStackVersion());
     Assert.assertNotNull(resp.getActualConfigs());
     Assert.assertEquals(1, resp.getActualConfigs().size());
+  }
+
+  @Test
+  public void testGetServiceComponentHostsWithFilter() throws AmbariException {
+    String clusterName = "foo1";
+    createCluster(clusterName);
+    clusters.getCluster(clusterName)
+        .setDesiredStackVersion(new StackId("HDP-2.0.5"));
+    String serviceName = "HDFS";
+    createService(clusterName, serviceName, null);
+    String componentName1 = "NAMENODE";
+    String componentName2 = "DATANODE";
+    String componentName3 = "HDFS_CLIENT";
+
+    createServiceComponent(clusterName, serviceName, componentName1,
+        State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName2,
+        State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName3,
+        State.INIT);
+
+    String host1 = "h1";
+    clusters.addHost(host1);
+    clusters.getHost("h1").setOsType("centos5");
+    clusters.getHost("h1").setState(HostState.HEALTHY);
+    clusters.getHost("h1").persist();
+
+    clusters.mapHostToCluster(host1, clusterName);
+
+    createServiceComponentHost(clusterName, serviceName, componentName1,
+        host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName2,
+        host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName3,
+        host1, null);
+
+    // Install
+    installService(clusterName, serviceName, false, false);
+
+    // Create and attach config
+    Map<String, String> configs = new HashMap<String, String>();
+    configs.put("a", "b");
+
+    ConfigurationRequest cr1;
+    cr1 = new ConfigurationRequest(clusterName, "hdfs-site","version1",
+        configs);
+    ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null);
+    crReq.setDesiredConfig(cr1);
+    controller.updateClusters(Collections.singleton(crReq), null);
+
+    // Start
+    startService(clusterName, serviceName, false, false);
+
+    //Update actual config
+    Service s1 = clusters.getCluster(clusterName).getService(serviceName);
+    ServiceComponentHost sch1 = s1.getServiceComponent(componentName1)
+        .getServiceComponentHost(host1);
+    ServiceComponentHost sch2 = s1.getServiceComponent(componentName2)
+        .getServiceComponentHost(host1);
+    ServiceComponentHost sch3 = s1.getServiceComponent(componentName3)
+        .getServiceComponentHost(host1);
+    sch1.updateActualConfigs(new HashMap<String, Map<String,String>>() {{
+      put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version1"); }});
+    }});
+    sch2.updateActualConfigs(new HashMap<String, Map<String,String>>() {{
+      put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version1"); }});
+    }});
+    sch3.updateActualConfigs(new HashMap<String, Map<String,String>>() {{
+      put("hdfs-site", new HashMap<String,String>() {{ put("tag", "version2"); }});
+    }});
+
+    ServiceComponentHostRequest r =
+        new ServiceComponentHostRequest(clusterName, null, null, null, null);
+    Set<ServiceComponentHostResponse> resps = controller.getHostComponents(Collections.singleton(r));
+    Assert.assertEquals(3, resps.size());
+
+    //Get all host components with stale config = true
+    r = new ServiceComponentHostRequest(clusterName, null, null, null, null);
+    r.setStaleConfig("true");
+    resps = controller.getHostComponents(Collections.singleton(r));
+    Assert.assertEquals(1, resps.size());
 
+    //Get all host components with stale config = false
+    r = new ServiceComponentHostRequest(clusterName, null, null, null, null);
+    r.setStaleConfig("false");
+    resps = controller.getHostComponents(Collections.singleton(r));
+    Assert.assertEquals(2, resps.size());
   }
 
+
   private Cluster setupClusterWithHosts(String clusterName, String stackId, List<String> hosts,
                              String osType) throws AmbariException {
     clusters.addCluster(clusterName);