Pārlūkot izejas kodu

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

Siddharth Wagle 11 gadi atpakaļ
vecāks
revīzija
33092de45a

+ 13 - 23
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() {

+ 0 - 1
ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java

@@ -193,7 +193,6 @@ public class ConfigGroupTest {
     Assert.assertNull(cluster.getConfigGroups().get(id));
   }
 
-  @Ignore
   @Test
   public void testRemoveHost() throws Exception {
     ConfigGroup configGroup = createConfigGroup();