ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: AMBARI-5216. stale_configs parameter works not properly after removing config group. (swagle)
Date Wed, 26 Mar 2014 00:14:35 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 7501cfa12 -> 1aa731f83


AMBARI-5216. stale_configs parameter works not properly after removing config group. (swagle)


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

Branch: refs/heads/trunk
Commit: 1aa731f83d8bd64596f835544534bc51350b6abe
Parents: 7501cfa
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Tue Mar 25 17:14:28 2014 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Tue Mar 25 17:14:28 2014 -0700

----------------------------------------------------------------------
 .../server/state/cluster/ClusterImpl.java       |  5 ++-
 .../ambari/server/state/host/HostImpl.java      |  3 +-
 .../svccomphost/ServiceComponentHostImpl.java   | 34 +++++++-------------
 .../svccomphost/ServiceComponentHostTest.java   | 21 ++++++++++++
 4 files changed, 36 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1aa731f8/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index 377471b..4717498 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -362,15 +362,14 @@ public class ClusterImpl implements Cluster {
   @Override
   public Map<Long, ConfigGroup> getConfigGroupsByHostname(String hostname)
     throws AmbariException {
-    Map<Long, ConfigGroup> configGroupMap = getConfigGroups();
     Map<Long, ConfigGroup> configGroups = new HashMap<Long, ConfigGroup>();
+    Map<Long, ConfigGroup> configGroupMap = getConfigGroups();
 
     clusterGlobalLock.readLock().lock();
     try {
       readLock.lock();
       try {
-        Set<ConfigGroupHostMapping> hostMappingEntities =
-          configGroupHostMappingDAO.findByHost(hostname);
+        Set<ConfigGroupHostMapping> hostMappingEntities = configGroupHostMappingDAO.findByHost(hostname);
 
         if (hostMappingEntities != null && !hostMappingEntities.isEmpty()) {
           for (ConfigGroupHostMapping entity : hostMappingEntities) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/1aa731f8/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
index 319b288..24e3f8f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
@@ -1192,8 +1192,7 @@ public class HostImpl implements Host {
       hostConfigMap.put(desiredConfigEntry.getKey(), hostConfig);
     }
 
-    Map<Long, ConfigGroup> configGroups = cluster.getConfigGroupsByHostname
-      (this.getHostName());
+    Map<Long, ConfigGroup> configGroups = cluster.getConfigGroupsByHostname(this.getHostName());
 
     if (configGroups != null && !configGroups.isEmpty()) {
       for (ConfigGroup configGroup : configGroups.values()) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/1aa731f8/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index 2e1480c..9bdbd29 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
@@ -1295,21 +1295,21 @@ public class ServiceComponentHostImpl implements ServiceComponentHost
{
   
   @Override
   public void updateActualConfigs(Map<String, Map<String, String>> configTags)
{
-    Cluster cluster = null;
-    Map<Long, ConfigGroup> configGroupMap = new HashMap<Long, ConfigGroup>();
+    Map<Long, ConfigGroup> configGroupMap = null;
+    String clusterName = getClusterName();
     try {
-      cluster = clusters.getClusterById(getClusterId());
-      if (cluster != null) {
-        configGroupMap = cluster.getConfigGroups();
-      }
-    } catch (AmbariException ae) {
-      LOG.warn("Unable to get cluster info for cluster id = " + getClusterId());
+      Cluster cluster = clusters.getCluster(clusterName);
+      configGroupMap = cluster.getConfigGroups();
+    } catch (AmbariException e) {
+      LOG.warn("Unable to find cluster, " + clusterName);
+      return;
     }
 
     clusterGlobalLock.readLock().lock();
     try {
       writeLock.lock();
       try {
+        LOG.debug("Updating actual config tags: " + configTags);
         actualConfigs = new HashMap<String, HostConfig>();
 
         for (Entry<String, Map<String, String>> entry : configTags.entrySet())
{
@@ -1325,22 +1325,13 @@ public class ServiceComponentHostImpl implements ServiceComponentHost
{
 
           if (!values.isEmpty()) {
             for (Entry<String, String> overrideEntry : values.entrySet()) {
-              try {
-                Long groupId = Long.parseLong(overrideEntry.getKey());
-                ConfigGroup configGroup = configGroupMap.get(groupId);
-                if (configGroup != null) {
-                  hc.getConfigGroupOverrides().put(groupId,
-                    overrideEntry.getValue());
-                } else {
-                  LOG.info("Cannot find config group with id = " + groupId);
-                }
-              } catch (Exception e) {
-                LOG.warn("Unable to retrieve config group info for id = " +
-                  overrideEntry.getKey());
+              Long groupId = Long.parseLong(overrideEntry.getKey());
+              hc.getConfigGroupOverrides().put(groupId, overrideEntry.getValue());
+              if (!configGroupMap.containsKey(groupId)) {
+                LOG.debug("Config group does not exist, id = " + groupId);
               }
             }
           }
-
         }
       } finally {
         writeLock.unlock();
@@ -1348,7 +1339,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost
{
     } finally {
       clusterGlobalLock.readLock().unlock();
     }
-
   }
   
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/1aa731f8/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
index 1a46442..9969b20 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.state.svccomphost;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -784,6 +785,26 @@ public class ServiceComponentHostTest {
     Assert.assertTrue(sch1.convertToResponse().isStaleConfig());
     Assert.assertTrue(sch2.convertToResponse().isStaleConfig());
     Assert.assertTrue(sch3.convertToResponse().isStaleConfig());
+
+    // Test actual configs are updated for deleted config group
+    Long id = configGroup.getId();
+    HashMap<String, String> tags = new HashMap<String, String>();
+    tags.put("tag", "version1");
+    tags.put(id.toString(), "version2");
+    actual.put("core-site", tags);
+    sch3.updateActualConfigs(actual);
+
+    Assert.assertFalse(sch3.convertToResponse().isStaleConfig());
+
+    cluster.deleteConfigGroup(id);
+    Assert.assertNull(cluster.getConfigGroups().get(id));
+
+    sch3.updateActualConfigs(actual);
+    Assert.assertTrue(sch3.convertToResponse().isStaleConfig());
+
+    tags.remove(id.toString());
+    sch3.updateActualConfigs(actual);
+    Assert.assertFalse(sch3.convertToResponse().isStaleConfig());
   }
 
   /**


Mime
View raw message