You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2014/01/23 19:08:46 UTC

git commit: AMBARI-4402. Delete Config Group Host mapping broken due to error introduced by perf patch. (swagle)

Updated Branches:
  refs/heads/branch-1.4.4 e660415a5 -> 4d02841f0


AMBARI-4402. Delete Config Group Host mapping broken due to error introduced by perf patch. (swagle)


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

Branch: refs/heads/branch-1.4.4
Commit: 4d02841f02c2f01088ad5ce3b530bd19d7c0c1be
Parents: e660415
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Thu Jan 23 09:59:05 2014 -0800
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Thu Jan 23 10:07:25 2014 -0800

----------------------------------------------------------------------
 .../orm/dao/ConfigGroupHostMappingDAO.java      | 36 +++++++-------------
 .../ambari/server/state/ConfigGroupTest.java    | 20 +++++++++++
 2 files changed, 33 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4d02841f/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
index 3612a07..6693a36 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
@@ -105,29 +105,19 @@ public class ConfigGroupHostMappingDAO {
     }
     
   }
-  
+
+  /**
+   * Return entity object which can be used for operations like remove
+   * directly.
+   * @param configGroupHostMappingEntityPK
+   * @return
+   */
   @Transactional
-  public ConfigGroupHostMapping findByPK(final ConfigGroupHostMappingEntityPK
+  public ConfigGroupHostMappingEntity findByPK(final ConfigGroupHostMappingEntityPK
         configGroupHostMappingEntityPK) {
     
-    populateCache();
-    
-    if (!configGroupHostMappingByHost.containsKey(configGroupHostMappingEntityPK.getHostname()))
-      return null;
-    
-    Set<ConfigGroupHostMapping> set = 
-        new HashSet<ConfigGroupHostMapping>(configGroupHostMappingByHost.get(configGroupHostMappingEntityPK.getHostname()));
-    
-    ConfigGroupHostMapping itemByPk = (ConfigGroupHostMapping) CollectionUtils.find(set, new Predicate() {
-      
-      @Override
-      public boolean evaluate(Object arg0) {
-        return ((ConfigGroupHostMapping) arg0).getConfigGroupId().
-            equals(configGroupHostMappingEntityPK.getConfigGroupId());
-      }
-    });
-    
-    return itemByPk;
+    return entityManagerProvider.get()
+      .find(ConfigGroupHostMappingEntity.class, configGroupHostMappingEntityPK);
   }
 
   @Transactional
@@ -247,10 +237,10 @@ public class ConfigGroupHostMappingDAO {
                          configGroupHostMappingEntityPK) {
     populateCache();
     
-    entityManagerProvider.get().remove(findByPK
-      (configGroupHostMappingEntityPK));
+    entityManagerProvider.get().remove(findByPK(configGroupHostMappingEntityPK));
     
-    Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost.get(configGroupHostMappingEntityPK.getHostname());
+    Set<ConfigGroupHostMapping> setByHost = configGroupHostMappingByHost
+      .get(configGroupHostMappingEntityPK.getHostname());
     
     if (setByHost != null) {
       CollectionUtils.filter(setByHost, new Predicate() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/4d02841f/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
index 36c4aac..ac63b22 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
@@ -27,6 +27,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.dao.ConfigGroupDAO;
+import org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO;
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.entities.ConfigGroupConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.ConfigGroupEntity;
@@ -53,6 +54,7 @@ public class ConfigGroupTest {
   private ConfigFactory configFactory;
   private HostDAO hostDAO;
   private ConfigGroupDAO configGroupDAO;
+  private ConfigGroupHostMappingDAO configGroupHostMappingDAO;
 
   @Before
   public void setup() throws Exception {
@@ -64,6 +66,8 @@ public class ConfigGroupTest {
     configGroupFactory = injector.getInstance(ConfigGroupFactory.class);
     hostDAO = injector.getInstance(HostDAO.class);
     configGroupDAO = injector.getInstance(ConfigGroupDAO.class);
+    configGroupHostMappingDAO = injector.getInstance
+      (ConfigGroupHostMappingDAO.class);
 
     metaInfo.init();
     clusterName = "foo";
@@ -188,6 +192,22 @@ public class ConfigGroupTest {
   }
 
   @Test
+  public void testRemoveHost() throws Exception {
+    ConfigGroup configGroup = createConfigGroup();
+    Assert.assertNotNull(configGroup);
+    Long id = configGroup.getId();
+
+    configGroup = cluster.getConfigGroups().get(id);
+    Assert.assertNotNull(configGroup);
+
+    clusters.unmapHostFromCluster("h1", clusterName);
+
+    Assert.assertNull(clusters.getHostsForCluster(clusterName).get("h1"));
+    Assert.assertTrue(configGroupHostMappingDAO.findByHost("h1").isEmpty());
+    Assert.assertNull(configGroup.getHosts().get("h1"));
+  }
+
+  @Test
   public void testGetConfigGroup() throws Exception {
     ConfigGroup configGroup = createConfigGroup();
     Assert.assertNotNull(configGroup);