Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-20053 347ba2a99 -> f4638d24d


http://git-wip-us.apache.org/repos/asf/ambari/blob/f4638d24/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java
index a0732ab..77593a7 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ServiceConfigDAOTest.java
@@ -29,7 +29,6 @@ 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.entities.ClusterConfigEntity;
-import org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ConfigGroupConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.ConfigGroupEntity;
@@ -41,7 +40,6 @@ import 
org.apache.ambari.server.security.authorization.ResourceType;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.StackId;
-import org.apache.ambari.server.state.cluster.ClusterImpl;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -443,39 +441,52 @@ public class ServiceConfigDAOTest {
     ClusterEntity clusterEntity = clusterDAO.findByName("c1");
 
     Assert.assertTrue(!clusterEntity.getClusterConfigEntities().isEmpty());
-    Assert.assertTrue(!clusterEntity.getConfigMappingEntities().isEmpty());
 
     Assert.assertEquals(5, clusterEntity.getClusterConfigEntities().size());
-    Assert.assertEquals(3, clusterEntity.getConfigMappingEntities().size());
   }
 
+  /**
+   * Tests the ability to find the latest configuration by stack, regardless of
+   * whether that configuration is enabled.
+   *
+   * @throws Exception
+   */
   @Test
-  public void testGetClusterConfigMappingByStack() throws Exception{
+  public void testGetLatestClusterConfigsByStack() throws Exception {
     initClusterEntities();
 
     ClusterEntity clusterEntity = clusterDAO.findByName("c1");
 
-    List<ClusterConfigMappingEntity> clusterConfigMappingEntities = 
clusterDAO.getClusterConfigMappingsByStack(clusterEntity.getClusterId(), 
HDP_01);
-    Assert.assertEquals(2, clusterConfigMappingEntities .size());
+    // there should be 3 configs in HDP-0.1 for this cluster, none selected
+    List<ClusterConfigEntity> clusterConfigEntities = 
clusterDAO.getLatestConfigurations(clusterEntity.getClusterId(), HDP_01);
+    Assert.assertEquals(1, clusterConfigEntities.size());
 
-    ClusterConfigMappingEntity e1 = clusterConfigMappingEntities.get(0);
-    String tag1 = e1.getTag();
-    Assert.assertEquals("version1", tag1);
-    String type1 = e1.getType();
-    Assert.assertEquals("oozie-site", type1);
+    ClusterConfigEntity entity = clusterConfigEntities.get(0);
+    Assert.assertEquals("version3", entity.getTag());
+    Assert.assertEquals("oozie-site", entity.getType());
+    Assert.assertFalse(entity.isSelected());
 
-    ClusterConfigMappingEntity e2 = clusterConfigMappingEntities.get(1);
-    String tag2 = e2.getTag();
-    Assert.assertEquals("version2", tag2);
-    String type2 = e2.getType();
-    Assert.assertEquals("oozie-site", type2);
+    // there should be 2 configs in HDP-0.2 for this cluster, the latest being
+    // selected
+    clusterConfigEntities = 
clusterDAO.getLatestConfigurations(clusterEntity.getClusterId(), HDP_02);
+    Assert.assertEquals(1, clusterConfigEntities.size());
+
+    entity = clusterConfigEntities.get(0);
+    Assert.assertEquals("version5", entity.getTag());
+    Assert.assertEquals("oozie-site", entity.getType());
+    Assert.assertTrue(entity.isSelected());
   }
 
   /**
-   * Test the get latest configuration query against clusterconfig table with 
configuration groups inserted
-   * */
+   * Tests getting latest and enabled configurations when there is a
+   * configuration group. Configurations for configuration groups are not
+   * "selected" as they are merged in with the selected configuration. This can
+   * cause problems if searching simply for the "latest" since it will pickup
+   * the wrong configuration.
+   *
+   */
   @Test
-  public void testGetClusterConfigMappingByStackCG() throws Exception{
+  public void testGetClusterConfigsByStackCG() throws Exception {
     initClusterEntitiesWithConfigGroups();
     ClusterEntity clusterEntity = clusterDAO.findByName("c1");
 
@@ -487,42 +498,42 @@ public class ServiceConfigDAOTest {
     ConfigGroupEntity configGroupEntity = configGroupEntities.get(0);
     Assert.assertNotNull(configGroupEntity);
     Assert.assertEquals("c1", 
configGroupEntity.getClusterEntity().getClusterName());
-    Assert.assertEquals(clusterId, configGroupEntity.getClusterEntity()
-      .getClusterId());
+    Assert.assertEquals(clusterId, 
configGroupEntity.getClusterEntity().getClusterId());
     Assert.assertEquals("oozie_server", configGroupEntity.getGroupName());
     Assert.assertEquals("OOZIE", configGroupEntity.getTag());
     Assert.assertEquals("oozie server", configGroupEntity.getDescription());
 
-    List<ClusterConfigMappingEntity> clusterConfigMappingEntities = 
clusterDAO.getClusterConfigMappingsByStack(clusterEntity.getClusterId(), 
HDP_01);
-    Assert.assertEquals(2, clusterConfigMappingEntities .size());
+    // all 3 are HDP-0.1, but only the 2nd one is enabled
+    List<ClusterConfigEntity> clusterConfigEntities = 
clusterDAO.getEnabledConfigsByStack(
+        clusterEntity.getClusterId(), HDP_01);
+
+    Assert.assertEquals(1, clusterConfigEntities.size());
+
+    ClusterConfigEntity configEntity = clusterConfigEntities.get(0);
+    Assert.assertEquals("version2", configEntity.getTag());
+    Assert.assertEquals("oozie-site", configEntity.getType());
+    Assert.assertTrue(configEntity.isSelected());
 
-    ClusterConfigMappingEntity e1 = clusterConfigMappingEntities.get(0);
-    String tag1 = e1.getTag();
-    Assert.assertEquals("version1", tag1);
-    String type1 = e1.getType();
-    Assert.assertEquals("oozie-site", type1);
+    // this should still return the 2nd one since the 3rd one has never been
+    // selected as its only for configuration groups
+    clusterConfigEntities = 
clusterDAO.getLatestConfigurations(clusterEntity.getClusterId(),
+        HDP_01);
 
-    ClusterConfigMappingEntity e2 = clusterConfigMappingEntities.get(1);
-    String tag2 = e2.getTag();
-    Assert.assertEquals("version2", tag2);
-    String type2 = e2.getType();
-    Assert.assertEquals("oozie-site", type2);
+    configEntity = clusterConfigEntities.get(0);
+    Assert.assertEquals("version2", configEntity.getTag());
+    Assert.assertEquals("oozie-site", configEntity.getType());
+    Assert.assertTrue(configEntity.isSelected());
   }
 
+
   /**
-   * Test
-   *
-   * When the last configuration of a given configuration type to be stored 
into the clusterconfig table is
-   * for a configuration group, there is no corresponding entry generated in 
the clusterconfigmapping.
-   *
-   * Therefore, the getlatestconfiguration query should skip configuration 
groups stored in the clusterconfig table.
-   *
-   * Test to determine the latest configuration of a given type whose 
version_tag
-   * exists in the clusterconfigmapping table.
+   * Tests that when there are multiple configurations for a stack, only the
+   * selected ones get returned.
    *
-   * */
+   * @throws Exception
+   */
   @Test
-  public void testGetLatestClusterConfigMappingByStack() throws Exception {
+  public void testGetEnabledClusterConfigByStack() throws Exception {
     Clusters clusters = injector.getInstance(Clusters.class);
     clusters.addCluster("c1", HDP_01);
 
@@ -530,30 +541,24 @@ public class ServiceConfigDAOTest {
 
     initClusterEntities();
 
-    Collection<ClusterConfigMappingEntity> latestMapingEntities = 
((ClusterImpl) cluster).getLatestConfigMappingsForStack(
-        cluster.getClusterId(), HDP_01);
+    Collection<ClusterConfigEntity> latestConfigs = 
clusterDAO.getEnabledConfigsByStack(
+        cluster.getClusterId(), HDP_02);
 
-    Assert.assertEquals(1, latestMapingEntities.size());
-    for(ClusterConfigMappingEntity e: latestMapingEntities){
-      Assert.assertEquals("version2", e.getTag());
+    Assert.assertEquals(1, latestConfigs.size());
+    for (ClusterConfigEntity e : latestConfigs) {
+      Assert.assertEquals("version5", e.getTag());
       Assert.assertEquals("oozie-site", e.getType());
     }
   }
 
   /**
-   * Test
-   *
-   * When the last configuration of a given configuration type to be stored 
into the clusterconfig table is
-   * for a configuration group, there is no corresponding entry generated in 
the clusterconfigmapping.
-   *
-   * Therefore, the getlatestconfiguration query should skip configuration 
groups stored in the clusterconfig table.
-   *
-   * Test to determine the latest configuration of a given type whose 
version_tag
-   * exists in the clusterconfigmapping table.
-   *
-   * */
+   * When the last configuration of a given configuration type to be stored 
into
+   * the clusterconfig table is for a configuration group, that configuration 
is
+   * not enabled. Therefore, it should be skipped when getting the enabled
+   * configurations for a stack.
+   */
   @Test
-  public void testGetLatestClusterConfigMappingByStackCG() throws Exception{
+  public void testGetLatestClusterConfigByStackCG() throws Exception {
     Clusters clusters = injector.getInstance(Clusters.class);
     clusters.addCluster("c1", HDP_01);
 
@@ -561,11 +566,11 @@ public class ServiceConfigDAOTest {
 
     initClusterEntitiesWithConfigGroups();
 
-    Collection<ClusterConfigMappingEntity> latestMapingEntities = 
((ClusterImpl) cluster).getLatestConfigMappingsForStack(
+    Collection<ClusterConfigEntity> latestConfigs = 
clusterDAO.getEnabledConfigsByStack(
         cluster.getClusterId(), HDP_01);
 
-    Assert.assertEquals(1, latestMapingEntities.size());
-    for(ClusterConfigMappingEntity e: latestMapingEntities){
+    Assert.assertEquals(1, latestConfigs.size());
+    for (ClusterConfigEntity e : latestConfigs) {
       Assert.assertEquals("version2", e.getTag());
       Assert.assertEquals("oozie-site", e.getType());
     }
@@ -596,6 +601,15 @@ public class ServiceConfigDAOTest {
     serviceConfigEntityList = 
serviceConfigDAO.getLastServiceConfigsForService(clusterId, "OOZIE");
     Assert.assertEquals(1, serviceConfigEntityList.size());
   }
+
+  /**
+   * Createa a cluster with 5 configurations for Oozie. Each configuration will
+   * have a tag of "version" plus a count. 3 configs will be for
+   * {@link #HDP_01}, and 2 will be for {@link #HDP_02}. Only the most recent
+   * configuration, {@code version5}, will be enabled.
+   *
+   * @throws Exception
+   */
   private void initClusterEntities() throws Exception{
     String userName = "admin";
 
@@ -615,7 +629,9 @@ public class ServiceConfigDAOTest {
 
     String oozieSite = "oozie-site";
 
-    for (int i = 1; i < 6; i++){
+    // create 5 Oozie Configs, with only the latest from HDP-0.2 being enabled
+    int configsToCreate = 5;
+    for (int i = 1; i <= configsToCreate; i++) {
       Thread.sleep(1);
       ClusterConfigEntity entity = new ClusterConfigEntity();
       entity.setClusterEntity(clusterEntity);
@@ -624,60 +640,35 @@ public class ServiceConfigDAOTest {
       entity.setVersion(Long.valueOf(i));
       entity.setTag("version"+i);
       entity.setTimestamp(new Date().getTime());
-      if(i < 4) {
-        entity.setStack(stackEntityHDP01);
-      } else {
+
+      // set selected to true to get the last selected timestamp populated
+      entity.setSelected(true);
+
+      // now set it to false
+      entity.setSelected(false);
+
+      entity.setStack(stackEntityHDP01);
+      if (i >= 4) {
         entity.setStack(stackEntityHDP02);
+        if (i == configsToCreate) {
+          entity.setSelected(true);
+        }
       }
+
       entity.setData("");
       clusterDAO.createConfig(entity);
       clusterEntity.getClusterConfigEntities().add(entity);
       clusterDAO.merge(clusterEntity);
     }
-
-    Collection<ClusterConfigMappingEntity> entities = 
clusterEntity.getConfigMappingEntities();
-    if(null == entities){
-      entities = new ArrayList<ClusterConfigMappingEntity>();
-      clusterEntity.setConfigMappingEntities(entities);
-    }
-
-    Thread.sleep(1);
-    ClusterConfigMappingEntity e1 = new ClusterConfigMappingEntity();
-    e1.setClusterEntity(clusterEntity);
-    e1.setClusterId(clusterEntity.getClusterId());
-    e1.setCreateTimestamp(System.currentTimeMillis());
-    e1.setSelected(0);
-    e1.setUser(userName);
-    e1.setType(oozieSite);
-    e1.setTag("version1");
-    entities.add(e1);
-    clusterDAO.merge(clusterEntity);
-
-    Thread.sleep(1);
-    ClusterConfigMappingEntity e2 = new ClusterConfigMappingEntity();
-    e2.setClusterEntity(clusterEntity);
-    e2.setClusterId(clusterEntity.getClusterId());
-    e2.setCreateTimestamp(System.currentTimeMillis());
-    e2.setSelected(0);
-    e2.setUser(userName);
-    e2.setType(oozieSite);
-    e2.setTag("version2");
-    entities.add(e2);
-    clusterDAO.merge(clusterEntity);
-
-    Thread.sleep(1);
-    ClusterConfigMappingEntity e3 = new ClusterConfigMappingEntity();
-    e3.setClusterEntity(clusterEntity);
-    e3.setClusterId(clusterEntity.getClusterId());
-    e3.setCreateTimestamp(System.currentTimeMillis());
-    e3.setSelected(1);
-    e3.setUser(userName);
-    e3.setType(oozieSite);
-    e3.setTag("version4");
-    entities.add(e3);
-    clusterDAO.merge(clusterEntity);
   }
 
+  /**
+   * Createa a cluster with 3 configurations for Oozie in the {@link #HDP_01}
+   * stack. Only {@code version2}, will be enabled. {@code version3} will be 
for
+   * a new configuration group.
+   *
+   * @throws Exception
+   */
   private void initClusterEntitiesWithConfigGroups() throws Exception{
     String userName = "admin";
 
@@ -695,8 +686,9 @@ public class ServiceConfigDAOTest {
     StackEntity stackEntityHDP01 = 
stackDAO.find(HDP_01.getStackName(),HDP_01.getStackVersion());
     String oozieSite = "oozie-site";
 
-    int count = 3;
-    for (int i = 1; i < count; i++){
+    // create 2 configurations for HDP-0.1
+    int count = 2;
+    for (int i = 1; i <= count; i++) {
       Thread.sleep(1);
       ClusterConfigEntity entity = new ClusterConfigEntity();
       entity.setClusterEntity(clusterEntity);
@@ -707,43 +699,17 @@ public class ServiceConfigDAOTest {
       entity.setTimestamp(new Date().getTime());
       entity.setStack(stackEntityHDP01);
       entity.setData("");
+      entity.setSelected(false);
+
+      if (i == count) {
+        entity.setSelected(true);
+      }
+
       clusterDAO.createConfig(entity);
       clusterEntity.getClusterConfigEntities().add(entity);
       clusterDAO.merge(clusterEntity);
     }
 
-    Collection<ClusterConfigMappingEntity> entities = 
clusterEntity.getConfigMappingEntities();
-    if(null == entities){
-      entities = new ArrayList<ClusterConfigMappingEntity>();
-      clusterEntity.setConfigMappingEntities(entities);
-    }
-
-    Thread.sleep(1);
-    ClusterConfigMappingEntity e1 = new ClusterConfigMappingEntity();
-    e1.setClusterEntity(clusterEntity);
-    e1.setClusterId(clusterEntity.getClusterId());
-    e1.setCreateTimestamp(System.currentTimeMillis());
-    e1.setSelected(0);
-    e1.setUser(userName);
-    e1.setType(oozieSite);
-    e1.setTag("version1");
-    entities.add(e1);
-    clusterDAO.merge(clusterEntity);
-
-    Thread.sleep(1);
-    ClusterConfigMappingEntity e2 = new ClusterConfigMappingEntity();
-    e2.setClusterEntity(clusterEntity);
-    e2.setClusterId(clusterEntity.getClusterId());
-    e2.setCreateTimestamp(System.currentTimeMillis());
-    e2.setSelected(1);
-    e2.setUser(userName);
-    e2.setType(oozieSite);
-    e2.setTag("version2");
-    entities.add(e2);
-    clusterDAO.merge(clusterEntity);
-
-    ConfigGroupEntity configGroupEntity = new ConfigGroupEntity();
-
     ResourceTypeEntity resourceTypeEntity = 
resourceTypeDAO.findById(ResourceType.CLUSTER.getId());
     if (resourceTypeEntity == null) {
       resourceTypeEntity = new ResourceTypeEntity();
@@ -755,50 +721,48 @@ public class ServiceConfigDAOTest {
     ResourceEntity resourceEntity = new ResourceEntity();
     resourceEntity.setResourceType(resourceTypeEntity);
 
+    // create a configuration group for oozie
+    ConfigGroupEntity configGroupEntity = new ConfigGroupEntity();
     configGroupEntity.setClusterEntity(clusterEntity);
     configGroupEntity.setClusterId(clusterEntity.getClusterId());
     configGroupEntity.setGroupName("oozie_server");
     configGroupEntity.setDescription("oozie server");
     configGroupEntity.setTag("OOZIE");
+    configGroupDAO.create(configGroupEntity);
 
-    ClusterConfigEntity configEntity = new ClusterConfigEntity();
-    configEntity.setType("oozie-site");
-    configEntity.setTag("version3");
-    configEntity.setData("someData");
-    configEntity.setAttributes("someAttributes");
-    configEntity.setStack(stackEntityHDP01);
-
-    List<ClusterConfigEntity> configEntities = new
-      ArrayList<ClusterConfigEntity>();
-    configEntities.add(configEntity);
+    // create a new configuration for oozie, for the config group
+    ClusterConfigEntity configEntityForGroup = new ClusterConfigEntity();
+    configEntityForGroup.setSelected(false);
+    configEntityForGroup.setType("oozie-site");
+    configEntityForGroup.setTag("version3");
+    configEntityForGroup.setData("someData");
+    configEntityForGroup.setAttributes("someAttributes");
+    configEntityForGroup.setStack(stackEntityHDP01);
 
-    configGroupDAO.create(configGroupEntity);
+    List<ClusterConfigEntity> configEntitiesForGroup = new ArrayList<>();
+    configEntitiesForGroup.add(configEntityForGroup);
+    List<ConfigGroupConfigMappingEntity> configMappingEntities = new 
ArrayList<>();
 
-    if (configEntities != null && !configEntities.isEmpty()) {
-      List<ConfigGroupConfigMappingEntity> configMappingEntities = new
-        ArrayList<ConfigGroupConfigMappingEntity>();
-
-      for (ClusterConfigEntity config : configEntities) {
-        config.setClusterEntity(clusterEntity);
-        config.setClusterId(clusterEntity.getClusterId());
-        clusterDAO.createConfig(config);
-
-        Thread.sleep(1);
-        ConfigGroupConfigMappingEntity configMappingEntity = new
-          ConfigGroupConfigMappingEntity();
-        configMappingEntity.setClusterId(clusterEntity.getClusterId());
-        configMappingEntity.setClusterConfigEntity(config);
-        configMappingEntity.setConfigGroupEntity(configGroupEntity);
-        configMappingEntity.setConfigGroupId(configGroupEntity.getGroupId());
-        configMappingEntity.setVersionTag(config.getTag());
-        configMappingEntity.setConfigType(config.getType());
-        configMappingEntity.setTimestamp(System.currentTimeMillis());
-        configMappingEntities.add(configMappingEntity);
-        configGroupConfigMappingDAO.create(configMappingEntity);
-      }
+    for (ClusterConfigEntity config : configEntitiesForGroup) {
+      config.setClusterEntity(clusterEntity);
+      config.setClusterId(clusterEntity.getClusterId());
+      clusterDAO.createConfig(config);
 
-      
configGroupEntity.setConfigGroupConfigMappingEntities(configMappingEntities);
-      configGroupDAO.merge(configGroupEntity);
+      Thread.sleep(1);
+      ConfigGroupConfigMappingEntity configMappingEntity = new
+        ConfigGroupConfigMappingEntity();
+      configMappingEntity.setClusterId(clusterEntity.getClusterId());
+      configMappingEntity.setClusterConfigEntity(config);
+      configMappingEntity.setConfigGroupEntity(configGroupEntity);
+      configMappingEntity.setConfigGroupId(configGroupEntity.getGroupId());
+      configMappingEntity.setVersionTag(config.getTag());
+      configMappingEntity.setConfigType(config.getType());
+      configMappingEntity.setTimestamp(System.currentTimeMillis());
+      configMappingEntities.add(configMappingEntity);
+      configGroupConfigMappingDAO.create(configMappingEntity);
     }
+
+    
configGroupEntity.setConfigGroupConfigMappingEntities(configMappingEntities);
+    configGroupDAO.merge(configGroupEntity);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f4638d24/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.java
index 09aaa92..a397ef4 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/state/DesiredConfigTest.java
@@ -36,12 +36,10 @@ public class DesiredConfigTest {
     DesiredConfig dc = new DesiredConfig();
     dc.setServiceName("service");
     dc.setTag("global");
-    dc.setUser("_test");
 
     Assert.assertEquals("Expected service 'service'", "service", 
dc.getServiceName());
     Assert.assertEquals("Expected version 'global'", "global", dc.getTag());
     Assert.assertEquals("Expected no host overrides", 0, 
dc.getHostOverrides().size());
-    Assert.assertEquals("Expected user '_test'", "_test", dc.getUser());
     
 
     List<DesiredConfig.HostOverride> hosts = Arrays.asList(

http://git-wip-us.apache.org/repos/asf/ambari/blob/f4638d24/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
index 6cdfbad..3d880c0 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
@@ -71,7 +71,6 @@ import org.apache.ambari.server.orm.dao.HostVersionDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
-import org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
@@ -230,7 +229,7 @@ public class ClusterTest {
 
     clusters.addCluster(clusterName, stackId);
 
-    Map<String, String> hostAttributes = new HashMap<String, String>();
+    Map<String, String> hostAttributes = new HashMap<>();
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "5.9");
 
@@ -279,7 +278,7 @@ public class ClusterTest {
     host2.setIpv4("192.168.0.2");
     host3.setIpv4("192.168.0.3");
 
-    List<HostEntity> hostEntities = new ArrayList<HostEntity>();
+    List<HostEntity> hostEntities = new ArrayList<>();
     hostEntities.add(host1);
     hostEntities.add(host2);
 
@@ -309,7 +308,7 @@ public class ClusterTest {
     when(stateEntity.getDesiredStack()).thenReturn(stackEntity);
 
     clusterServiceEntity.setServiceDesiredStateEntity(stateEntity);
-    List<ClusterServiceEntity> clusterServiceEntities = new 
ArrayList<ClusterServiceEntity>();
+    List<ClusterServiceEntity> clusterServiceEntities = new ArrayList<>();
     clusterServiceEntities.add(clusterServiceEntity);
     clusterEntity.setClusterServiceEntities(clusterServiceEntities);
     return clusterEntity;
@@ -444,8 +443,8 @@ public class ClusterTest {
     For some reason this still uses the metainfo.xml files for these services
     from HDP-2.0.5 stack instead of the provided Stack Id
     */
-    HashMap<String, Set<String>> componentsThatAdvertiseVersion = new 
HashMap<String, Set<String>>();
-    HashMap<String, Set<String>> componentsThatDontAdvertiseVersion = new 
HashMap<String, Set<String>>();
+    HashMap<String, Set<String>> componentsThatAdvertiseVersion = new 
HashMap<>();
+    HashMap<String, Set<String>> componentsThatDontAdvertiseVersion = new 
HashMap<>();
 
     Set<String> hdfsComponents = new HashSet<String>() {{ add("NAMENODE"); 
add("DATANODE"); add("HDFS_CLIENT"); }};
     Set<String> zkComponents = new HashSet<String>() {{ 
add("ZOOKEEPER_SERVER"); add("ZOOKEEPER_CLIENT"); }};
@@ -567,7 +566,7 @@ public class ClusterTest {
     hostInfo.setMemoryTotal(10);
     hostInfo.setMemorySize(100);
     hostInfo.setProcessorCount(10);
-    List<DiskInfo> mounts = new ArrayList<DiskInfo>();
+    List<DiskInfo> mounts = new ArrayList<>();
     mounts.add(new DiskInfo("/dev/sda", "/mnt/disk1",
         "5000000", "4000000", "10%", "size", "fstype"));
     hostInfo.setMounts(mounts);
@@ -839,7 +838,7 @@ public class ClusterTest {
     Assert.assertEquals(1, componentHostMap.get("JOBTRACKER").size());
     Assert.assertTrue(componentHostMap.get("JOBTRACKER").contains("h1"));
 
-    componentHostMap = c1.getServiceComponentHostMap(null, new 
HashSet<String>(Arrays.asList("HDFS", "MAPREDUCE")));
+    componentHostMap = c1.getServiceComponentHostMap(null, new 
HashSet<>(Arrays.asList("HDFS", "MAPREDUCE")));
     Assert.assertEquals(3, componentHostMap.size());
     Assert.assertEquals(1, componentHostMap.get("NAMENODE").size());
     Assert.assertTrue(componentHostMap.get("NAMENODE").contains("h1"));
@@ -896,7 +895,7 @@ public class ClusterTest {
     Assert.assertEquals(1, componentHostMap.get("DATANODE").size());
     Assert.assertTrue(componentHostMap.get("DATANODE").contains("h2"));
 
-    componentHostMap = c1.getServiceComponentHostMap(new 
HashSet<String>(Arrays.asList("h1", "h2", "h3")), null);
+    componentHostMap = c1.getServiceComponentHostMap(new 
HashSet<>(Arrays.asList("h1", "h2", "h3")), null);
     Assert.assertEquals(3, componentHostMap.size());
     Assert.assertEquals(1, componentHostMap.get("NAMENODE").size());
     Assert.assertTrue(componentHostMap.get("NAMENODE").contains("h1"));
@@ -959,10 +958,10 @@ public class ClusterTest {
   public void testGetAndSetConfigs() throws Exception {
     createDefaultCluster();
 
-    Map<String, Map<String, String>> c1PropAttributes = new HashMap<String, 
Map<String,String>>();
+    Map<String, Map<String, String>> c1PropAttributes = new HashMap<>();
     c1PropAttributes.put("final", new HashMap<String, String>());
     c1PropAttributes.get("final").put("a", "true");
-    Map<String, Map<String, String>> c2PropAttributes = new HashMap<String, 
Map<String,String>>();
+    Map<String, Map<String, String>> c2PropAttributes = new HashMap<>();
     c2PropAttributes.put("final", new HashMap<String, String>());
     c2PropAttributes.get("final").put("x", "true");
     Config config1 = configFactory.createNew(c1, "global", "version1",
@@ -1020,15 +1019,12 @@ public class ClusterTest {
     Assert.assertTrue("Expect desired config contain " + config3.getType(), 
desiredConfigs.containsKey("core-site"));
     Assert.assertEquals("Expect desired config for global should be " + 
config1.getTag(),
       config1.getTag(), desiredConfigs.get(config1.getType()).getTag());
-    Assert.assertEquals("_test1", 
desiredConfigs.get(config1.getType()).getUser());
-    Assert.assertEquals("_test3", 
desiredConfigs.get(config3.getType()).getUser());
     DesiredConfig dc = desiredConfigs.get(config1.getType());
     Assert.assertTrue("Expect no host-level overrides",
       (null == dc.getHostOverrides() || dc.getHostOverrides().size() == 0));
 
     Thread.sleep(1);
     c1.addDesiredConfig("_test2", Collections.singleton(config2));
-    Assert.assertEquals("_test2", 
c1.getDesiredConfigs().get(config2.getType()).getUser());
 
     Thread.sleep(1);
     c1.addDesiredConfig("_test1", Collections.singleton(config1));
@@ -1068,7 +1064,7 @@ public class ClusterTest {
     host.setIPv4("ipv4");
     host.setIPv6("ipv6");
 
-    Map<String, String> hostAttributes = new HashMap<String, String>();
+    Map<String, String> hostAttributes = new HashMap<>();
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "5.9");
     host.setHostAttributes(hostAttributes);
@@ -1129,7 +1125,7 @@ public class ClusterTest {
     Config config2 = configFactory.createNew(c1, "core-site", "version2",
       new HashMap<String, String>() {{ put("x", "y"); }}, new HashMap<String, 
Map<String,String>>());
 
-    Set<Config> configs = new HashSet<Config>();
+    Set<Config> configs = new HashSet<>();
     configs.add(config1);
     configs.add(config2);
 
@@ -1157,24 +1153,22 @@ public class ClusterTest {
     // ServiceConfig
     Assert.assertEquals(0,
       em.createQuery("SELECT serviceConfig from ServiceConfigEntity 
serviceConfig").getResultList().size());
+
     // ClusterConfig
-    Assert.assertEquals(2,
-      em.createQuery("SELECT config from ClusterConfigEntity 
config").getResultList().size());
-    // ClusterConfigMapping
-    List<ClusterConfigMappingEntity> configMappingEntities =
-        em.createQuery("SELECT configmapping from ClusterConfigMappingEntity 
configmapping",
-        ClusterConfigMappingEntity.class).getResultList();
+    List<ClusterConfigEntity> clusterConfigs = em.createQuery(
+        "SELECT config from ClusterConfigEntity config", 
ClusterConfigEntity.class).getResultList();
 
-    Assert.assertEquals(2, configMappingEntities.size());
+    Assert.assertEquals(2, clusterConfigs.size());
 
-    for (ClusterConfigMappingEntity configMappingEntity : 
configMappingEntities) {
-      if (StringUtils.equals(configMappingEntity.getType(), "core-site")) {
+    for (ClusterConfigEntity configEntity : clusterConfigs) {
+      if (StringUtils.equals(configEntity.getType(), "core-site")) {
         assertEquals("core-site is not part of HDFS in test stack, should 
remain mapped to cluster",
-            1, configMappingEntity.isSelected());
+            true, configEntity.isSelected());
       }
-      if (StringUtils.equals(configMappingEntity.getType(), "hdfs-site")) {
+
+      if (StringUtils.equals(configEntity.getType(), "hdfs-site")) {
         assertEquals("hdfs-site should be unmapped from cluster when HDFS 
service is removed",
-            0, configMappingEntity.isSelected());
+            false, configEntity.isSelected());
       }
     }
 
@@ -1190,7 +1184,7 @@ public class ClusterTest {
     Host host1 = clusters.getHost("h1");
     HostEntity hostEntity1 = hostDAO.findByName("h1");
 
-    Map<String, Map<String, String>> propAttributes = new HashMap<String, 
Map<String,String>>();
+    Map<String, Map<String, String>> propAttributes = new HashMap<>();
     propAttributes.put("final", new HashMap<String, String>());
     propAttributes.get("final").put("test", "true");
     Config config = configFactory.createNew(c1, "hdfs-site", "1", new 
HashMap<String, String>(){{
@@ -1204,7 +1198,7 @@ public class ClusterTest {
     assertTrue(configs.containsKey(hostEntity1.getHostId()));
     assertEquals(1, configs.get(hostEntity1.getHostId()).size());
 
-    List<Long> hostIds = new ArrayList<Long>();
+    List<Long> hostIds = new ArrayList<>();
     hostIds.add(hostEntity1.getHostId());
 
     configs = c1.getHostsDesiredConfigs(hostIds);
@@ -1294,7 +1288,7 @@ public class ClusterTest {
     Config config2 = configFactory.createNew(c1, "core-site", "version2",
       new HashMap<String, String>() {{ put("x", "y"); }}, new HashMap<String, 
Map<String,String>>());
 
-    Set<Config> configs = new HashSet<Config>();
+    Set<Config> configs = new HashSet<>();
     configs.add(config1);
     configs.add(config2);
 
@@ -1949,7 +1943,7 @@ public class ClusterTest {
 
     RepositoryVersionEntity rv1 = helper.getOrCreateRepositoryVersion(stackId, 
v1);
 
-    Map<String, String> hostAttributes = new HashMap<String, String>();
+    Map<String, String> hostAttributes = new HashMap<>();
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "6.4");
 
@@ -2106,7 +2100,7 @@ public class ClusterTest {
 
     RepositoryVersionEntity rv1 = helper.getOrCreateRepositoryVersion(stackId, 
v1);
 
-    Map<String, String> hostAttributes = new HashMap<String, String>();
+    Map<String, String> hostAttributes = new HashMap<>();
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "6.4");
 
@@ -2180,7 +2174,7 @@ public class ClusterTest {
       h.setIPv4("ipv4");
       h.setIPv6("ipv6");
 
-      Map<String, String> hostAttributes = new HashMap<String, String>();
+      Map<String, String> hostAttributes = new HashMap<>();
       hostAttributes.put("os_family", "redhat");
       hostAttributes.put("os_release_version", "5.9");
       h.setHostAttributes(hostAttributes);
@@ -2249,7 +2243,7 @@ public class ClusterTest {
       h.setIPv4("ipv4");
       h.setIPv6("ipv6");
 
-      Map<String, String> hostAttributes = new HashMap<String, String>();
+      Map<String, String> hostAttributes = new HashMap<>();
       hostAttributes.put("os_family", "redhat");
       hostAttributes.put("os_release_version", "5.9");
       h.setHostAttributes(hostAttributes);
@@ -2393,177 +2387,142 @@ public class ClusterTest {
 
     String configType = "foo-type";
 
-    ClusterConfigEntity clusterConfig = new ClusterConfigEntity();
-    clusterConfig.setClusterEntity(clusterEntity);
-    clusterConfig.setConfigId(1L);
-    clusterConfig.setStack(currentStack);
-    clusterConfig.setTag("version-1");
-    clusterConfig.setData("{}");
-    clusterConfig.setType(configType);
-    clusterConfig.setTimestamp(1L);
-    clusterConfig.setVersion(1L);
-
-    clusterDAO.createConfig(clusterConfig);
-    clusterEntity.getClusterConfigEntities().add(clusterConfig);
+    ClusterConfigEntity clusterConfig1 = new ClusterConfigEntity();
+    clusterConfig1.setClusterEntity(clusterEntity);
+    clusterConfig1.setConfigId(1L);
+    clusterConfig1.setStack(currentStack);
+    clusterConfig1.setTag("version-1");
+    clusterConfig1.setData("{}");
+    clusterConfig1.setType(configType);
+    clusterConfig1.setTimestamp(1L);
+    clusterConfig1.setVersion(1L);
+    clusterConfig1.setSelected(true);
+
+    clusterDAO.createConfig(clusterConfig1);
+    clusterEntity.getClusterConfigEntities().add(clusterConfig1);
     clusterEntity = clusterDAO.merge(clusterEntity);
 
-    ClusterConfigEntity newClusterConfig = new ClusterConfigEntity();
-    newClusterConfig.setClusterEntity(clusterEntity);
-    newClusterConfig.setConfigId(2L);
-    newClusterConfig.setStack(newStack);
-    newClusterConfig.setTag("version-2");
-    newClusterConfig.setData("{}");
-    newClusterConfig.setType(configType);
-    newClusterConfig.setTimestamp(2L);
-    newClusterConfig.setVersion(2L);
-
-    clusterDAO.createConfig(newClusterConfig);
-    clusterEntity.getClusterConfigEntities().add(newClusterConfig);
+    ClusterConfigEntity clusterConfig2 = new ClusterConfigEntity();
+    clusterConfig2.setClusterEntity(clusterEntity);
+    clusterConfig2.setConfigId(2L);
+    clusterConfig2.setStack(newStack);
+    clusterConfig2.setTag("version-2");
+    clusterConfig2.setData("{}");
+    clusterConfig2.setType(configType);
+    clusterConfig2.setTimestamp(2L);
+    clusterConfig2.setVersion(2L);
+    clusterConfig2.setSelected(false);
+
+    clusterDAO.createConfig(clusterConfig2);
+    clusterEntity.getClusterConfigEntities().add(clusterConfig2);
     clusterEntity = clusterDAO.merge(clusterEntity);
 
-    // config mapping set to 1
-    ClusterConfigMappingEntity configMapping = new 
ClusterConfigMappingEntity();
-    configMapping.setClusterEntity(clusterEntity);
-    configMapping.setCreateTimestamp(1L);
-    configMapping.setSelected(1);
-    configMapping.setTag("version-1");
-    configMapping.setType(configType);
-    configMapping.setUser("admin");
-
-    // new config mapping set to 0
-    ClusterConfigMappingEntity newConfigMapping = new 
ClusterConfigMappingEntity();
-    newConfigMapping.setClusterEntity(clusterEntity);
-    newConfigMapping.setCreateTimestamp(2L);
-    newConfigMapping.setSelected(0);
-    newConfigMapping.setTag("version-2");
-    newConfigMapping.setType(configType);
-    newConfigMapping.setUser("admin");
-
-    clusterDAO.persistConfigMapping(configMapping);
-    clusterDAO.persistConfigMapping(newConfigMapping);
-    clusterEntity.getConfigMappingEntities().add(configMapping);
-    clusterEntity.getConfigMappingEntities().add(newConfigMapping);
-    clusterEntity = clusterDAO.merge(clusterEntity);
-
-    // check that the original mapping is enabled
-    Collection<ClusterConfigMappingEntity> clusterConfigMappings = 
clusterEntity.getConfigMappingEntities();
-    Assert.assertEquals(2, clusterConfigMappings.size());
-    for (ClusterConfigMappingEntity clusterConfigMapping : 
clusterConfigMappings) {
-      if (clusterConfigMapping.getTag().equals("version-1")) {
-        Assert.assertEquals(1, clusterConfigMapping.isSelected());
+    // check that the original config is enabled
+    Collection<ClusterConfigEntity> clusterConfigs = 
clusterEntity.getClusterConfigEntities();
+    Assert.assertEquals(2, clusterConfigs.size());
+    for (ClusterConfigEntity clusterConfig : clusterConfigs) {
+      if (clusterConfig.getTag().equals("version-1")) {
+        Assert.assertTrue(clusterConfig.isSelected());
       } else {
-        Assert.assertEquals(0, clusterConfigMapping.isSelected());
+        Assert.assertFalse(clusterConfig.isSelected());
       }
     }
 
     cluster.applyLatestConfigurations(newStackId);
     clusterEntity = clusterDAO.findByName("c1");
 
-    // now check that the new config mapping is enabled
-    clusterConfigMappings = clusterEntity.getConfigMappingEntities();
-    Assert.assertEquals(2, clusterConfigMappings.size());
-    for (ClusterConfigMappingEntity clusterConfigMapping : 
clusterConfigMappings) {
-      if (clusterConfigMapping.getTag().equals("version-1")) {
-        Assert.assertEquals(0, clusterConfigMapping.isSelected());
+    // now check that the new config is enabled
+    clusterConfigs = clusterEntity.getClusterConfigEntities();
+    Assert.assertEquals(2, clusterConfigs.size());
+    for (ClusterConfigEntity clusterConfig : clusterConfigs) {
+      if (clusterConfig.getTag().equals("version-1")) {
+        Assert.assertFalse(clusterConfig.isSelected());
       } else {
-        Assert.assertEquals(1, clusterConfigMapping.isSelected());
+        Assert.assertTrue(clusterConfig.isSelected());
       }
     }
   }
 
   /**
    * Tests that {@link Cluster#applyLatestConfigurations(StackId)} sets the
-   * right configs to enabled when there are duplicate mappings for type/tag.
-   * Only the most recent should be enabled.
+   * right configs to enabled when setting them to a prior stack which has
+   * several configs.
    *
    * @throws Exception
    */
   @Test
-  public void testApplyLatestConfigurationsWithMultipleMappings() throws 
Exception {
+  public void testApplyLatestConfigurationsToPreviousStack() throws Exception {
     createDefaultCluster();
     Cluster cluster = clusters.getCluster("c1");
     ClusterEntity clusterEntity = clusterDAO.findByName("c1");
     StackId stackId = cluster.getCurrentStackVersion();
+    StackId newStackId = new StackId("HDP-2.0.6");
 
     StackEntity currentStack = stackDAO.find(stackId.getStackName(), 
stackId.getStackVersion());
+    StackEntity newStack = stackDAO.find(newStackId.getStackName(), 
newStackId.getStackVersion());
+
+    Assert.assertFalse(stackId.equals(newStackId));
 
     String configType = "foo-type";
-    String configTag = "version-1";
 
-    // create the config for the mappings
-    ClusterConfigEntity clusterConfig = new ClusterConfigEntity();
-    clusterConfig.setClusterEntity(clusterEntity);
-    clusterConfig.setConfigId(1L);
-    clusterConfig.setStack(currentStack);
-    clusterConfig.setTag(configTag);
-    clusterConfig.setData("{}");
-    clusterConfig.setType(configType);
-    clusterConfig.setTimestamp(1L);
-    clusterConfig.setVersion(1L);
+    // create 5 configurations in the current stack
+    for (int i = 1; i <= 5; i++) {
+      ClusterConfigEntity clusterConfig = new ClusterConfigEntity();
+      clusterConfig.setClusterEntity(clusterEntity);
+      clusterConfig.setConfigId(Long.valueOf(i));
+      clusterConfig.setStack(currentStack);
+      clusterConfig.setTag("version-" + i);
+      clusterConfig.setData("{}");
+      clusterConfig.setType(configType);
+      clusterConfig.setTimestamp(System.currentTimeMillis());
+      clusterConfig.setVersion(Long.valueOf(i));
+
+      // set to true, then back to false to get a value populated in the
+      // selected timestamp
+      clusterConfig.setSelected(true);
+      clusterConfig.setSelected(false);
+
+      clusterDAO.createConfig(clusterConfig);
+      clusterEntity.getClusterConfigEntities().add(clusterConfig);
+
+      // ensure there is at least some pause between to ensure that the
+      // timestamps are different
+      Thread.sleep(5);
+    }
 
-    clusterDAO.createConfig(clusterConfig);
-    clusterEntity.getClusterConfigEntities().add(clusterConfig);
+    // save them all
     clusterEntity = clusterDAO.merge(clusterEntity);
 
-    // create 3 mappings for the same type/tag, each with a different time
-
-    // config mapping 1
-    ClusterConfigMappingEntity configMapping = new 
ClusterConfigMappingEntity();
-    configMapping.setClusterEntity(clusterEntity);
-    configMapping.setCreateTimestamp(1L);
-    configMapping.setSelected(0);
-    configMapping.setTag(configTag);
-    configMapping.setType(configType);
-    configMapping.setUser("admin");
-    clusterDAO.persistConfigMapping(configMapping);
-    clusterEntity.getConfigMappingEntities().add(configMapping);
-
-    // config mapping 2
-    configMapping = new ClusterConfigMappingEntity();
-    configMapping.setClusterEntity(clusterEntity);
-    configMapping.setCreateTimestamp(2L);
-    configMapping.setSelected(0);
-    configMapping.setTag(configTag);
-    configMapping.setType(configType);
-    configMapping.setUser("admin");
-    clusterDAO.persistConfigMapping(configMapping);
-    clusterEntity.getConfigMappingEntities().add(configMapping);
-
-    // config mapping 3
-    configMapping = new ClusterConfigMappingEntity();
-    configMapping.setClusterEntity(clusterEntity);
-    configMapping.setCreateTimestamp(3L);
-    configMapping.setSelected(0);
-    configMapping.setTag(configTag);
-    configMapping.setType(configType);
-    configMapping.setUser("admin");
-    clusterDAO.persistConfigMapping(configMapping);
-    clusterEntity.getConfigMappingEntities().add(configMapping);
-
+    // create a new configuration in the new stack and enable it
+    ClusterConfigEntity clusterConfigNewStack = new ClusterConfigEntity();
+    clusterConfigNewStack.setClusterEntity(clusterEntity);
+    clusterConfigNewStack.setConfigId(6L);
+    clusterConfigNewStack.setStack(newStack);
+    clusterConfigNewStack.setTag("version-6");
+    clusterConfigNewStack.setData("{}");
+    clusterConfigNewStack.setType(configType);
+    clusterConfigNewStack.setTimestamp(System.currentTimeMillis());
+    clusterConfigNewStack.setVersion(6L);
+    clusterConfigNewStack.setSelected(true);
+
+    clusterDAO.createConfig(clusterConfigNewStack);
+    clusterEntity.getClusterConfigEntities().add(clusterConfigNewStack);
     clusterEntity = clusterDAO.merge(clusterEntity);
 
-    // check all 3 mappings are disabled
-    Collection<ClusterConfigMappingEntity> clusterConfigMappings = 
clusterEntity.getConfigMappingEntities();
-    Assert.assertEquals(3, clusterConfigMappings.size());
-    for (ClusterConfigMappingEntity clusterConfigMapping : 
clusterConfigMappings) {
-      Assert.assertEquals(0, clusterConfigMapping.isSelected());
-    }
+    // check that only the newest configuration is enabled
+    ClusterConfigEntity clusterConfig = clusterDAO.findEnabledConfigByType(
+        clusterEntity.getClusterId(), configType);
+    Assert.assertTrue(clusterConfig.isSelected());
+    Assert.assertEquals(clusterConfigNewStack.getTag(), 
clusterConfig.getTag());
 
-    // apply configurations and check to see we've set the one with the latest
-    // timestamp ONLY
-    cluster.applyLatestConfigurations(cluster.getCurrentStackVersion());
+    // move back to the original stack
+    cluster.applyLatestConfigurations(stackId);
     clusterEntity = clusterDAO.findByName("c1");
 
-    // now check that the new config mapping is enabled
-    clusterConfigMappings = clusterEntity.getConfigMappingEntities();
-    Assert.assertEquals(3, clusterConfigMappings.size());
-    for (ClusterConfigMappingEntity clusterConfigMapping : 
clusterConfigMappings) {
-      if (clusterConfigMapping.getCreateTimestamp() < 3) {
-        Assert.assertEquals(0, clusterConfigMapping.isSelected());
-      } else {
-        Assert.assertEquals(1, clusterConfigMapping.isSelected());
-      }
-    }
+    // now check that latest config from the original stack is enabled
+    clusterConfig = 
clusterDAO.findEnabledConfigByType(clusterEntity.getClusterId(), configType);
+    Assert.assertTrue(clusterConfig.isSelected());
+    Assert.assertEquals("version-5", clusterConfig.getTag());
   }
 
   /**
@@ -2582,8 +2541,8 @@ public class ClusterTest {
     // make sure the stacks are different
     Assert.assertFalse(stackId.equals(newStackId));
 
-    Map<String, String> properties = new HashMap<String, String>();
-    Map<String, Map<String, String>> propertiesAttributes = new 
HashMap<String, Map<String, String>>();
+    Map<String, String> properties = new HashMap<>();
+    Map<String, Map<String, String>> propertiesAttributes = new HashMap<>();
 
     // foo-type for v1 on current stack
     properties.put("foo-property-1", "foo-value-1");
@@ -2665,6 +2624,7 @@ public class ClusterTest {
     clusterConfig.setType(configType);
     clusterConfig.setTimestamp(1L);
     clusterConfig.setVersion(1L);
+    clusterConfig.setSelected(true);
 
     clusterDAO.createConfig(clusterConfig);
     clusterEntity.getClusterConfigEntities().add(clusterConfig);
@@ -2679,35 +2639,12 @@ public class ClusterTest {
     newClusterConfig.setType(configType);
     newClusterConfig.setTimestamp(2L);
     newClusterConfig.setVersion(2L);
+    newClusterConfig.setSelected(false);
 
     clusterDAO.createConfig(newClusterConfig);
     clusterEntity.getClusterConfigEntities().add(newClusterConfig);
     clusterEntity = clusterDAO.merge(clusterEntity);
 
-    // config mapping set to 1
-    ClusterConfigMappingEntity configMapping = new 
ClusterConfigMappingEntity();
-    configMapping.setClusterEntity(clusterEntity);
-    configMapping.setCreateTimestamp(1L);
-    configMapping.setSelected(1);
-    configMapping.setTag("version-1");
-    configMapping.setType(configType);
-    configMapping.setUser("admin");
-
-    // new config mapping set to 0
-    ClusterConfigMappingEntity newConfigMapping = new 
ClusterConfigMappingEntity();
-    newConfigMapping.setClusterEntity(clusterEntity);
-    newConfigMapping.setCreateTimestamp(2L);
-    newConfigMapping.setSelected(0);
-    newConfigMapping.setTag("version-2");
-    newConfigMapping.setType(configType);
-    newConfigMapping.setUser("admin");
-
-    clusterDAO.persistConfigMapping(configMapping);
-    clusterDAO.persistConfigMapping(newConfigMapping);
-    clusterEntity.getConfigMappingEntities().add(configMapping);
-    clusterEntity.getConfigMappingEntities().add(newConfigMapping);
-    clusterEntity = clusterDAO.merge(clusterEntity);
-
     // get back the cluster configs for the new stack
     List<ClusterConfigEntity> clusterConfigs = clusterDAO.getAllConfigurations(
         cluster.getClusterId(), newStackId);

http://git-wip-us.apache.org/repos/asf/ambari/blob/f4638d24/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
index 5b54af4..97d560f 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
@@ -121,7 +121,7 @@ public class ClustersTest {
   }
 
   private void setOsFamily(Host host, String osFamily, String osVersion) {
-         Map<String, String> hostAttributes = new HashMap<String, String>();
+         Map<String, String> hostAttributes = new HashMap<>();
          hostAttributes.put("os_family", osFamily);
          hostAttributes.put("os_release_version", osVersion);
 
@@ -323,7 +323,7 @@ public class ClustersTest {
     Cluster c4 = (Cluster) clusters.getClustersForHost(h2).toArray()[0];
 
     Assert.assertEquals(c3, c4);
-    Set<String> hostnames = new HashSet<String>();
+    Set<String> hostnames = new HashSet<>();
     hostnames.add(h1);
     hostnames.add(h2);
 
@@ -465,7 +465,7 @@ public class ClustersTest {
     ));
     Assert.assertEquals(2, 
injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM 
ClusterConfigEntity config").getResultList().size());
     Assert.assertEquals(1, 
injector.getProvider(EntityManager.class).get().createQuery("SELECT state FROM 
ClusterStateEntity state").getResultList().size());
-    Assert.assertEquals(1, 
injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM 
ClusterConfigMappingEntity config").getResultList().size());
+    Assert.assertEquals(1, 
injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM 
ClusterConfigEntity config WHERE config.selected = 1").getResultList().size());
 
     // add topology request
     Blueprint bp = createNiceMock(Blueprint.class);
@@ -506,7 +506,6 @@ public class ClustersTest {
     ));
     Assert.assertEquals(0, 
injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM 
ClusterConfigEntity config").getResultList().size());
     Assert.assertEquals(0, 
injector.getProvider(EntityManager.class).get().createQuery("SELECT state FROM 
ClusterStateEntity state").getResultList().size());
-    Assert.assertEquals(0, 
injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM 
ClusterConfigMappingEntity config").getResultList().size());
     Assert.assertEquals(0, 
topologyRequestDAO.findByClusterId(cluster.getClusterId()).size());
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f4638d24/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java 
b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
index d418a80..32e8dae 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java
@@ -95,7 +95,7 @@ public class HostTest {
     info.setMemorySize(100);
     info.setProcessorCount(10);
     info.setPhysicalProcessorCount(2);
-    List<DiskInfo> mounts = new ArrayList<DiskInfo>();
+    List<DiskInfo> mounts = new ArrayList<>();
     mounts.add(new DiskInfo("/dev/sda", "/mnt/disk1",
         "5000000", "4000000", "10%", "size", "fstype"));
     info.setMounts(mounts);
@@ -146,7 +146,7 @@ public class HostTest {
     HostInfo info = new HostInfo();
     info.setMemorySize(100);
     info.setProcessorCount(10);
-    List<DiskInfo> mounts = new ArrayList<DiskInfo>();
+    List<DiskInfo> mounts = new ArrayList<>();
     mounts.add(new DiskInfo("/dev/sda", "/mnt/disk1",
         "5000000", "4000000", "10%", "size", "fstype"));
     info.setMounts(mounts);
@@ -375,7 +375,7 @@ public class HostTest {
     host.setIPv4("ipv4");
     host.setIPv6("ipv6");
 
-    Map<String, String> hostAttributes = new HashMap<String, String>();
+    Map<String, String> hostAttributes = new HashMap<>();
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "6.3");
     host.setHostAttributes(hostAttributes);
@@ -400,7 +400,6 @@ public class HostTest {
 
     Map<String, DesiredConfig> map = host.getDesiredConfigs(c1.getClusterId());
     Assert.assertTrue("Expect desired config to contain global", 
map.containsKey("global"));
-    Assert.assertEquals("Expect global user to be '_test'", "_test", 
map.get("global").getUser());
 
     config = configFactory.createNew(c1, "global", "v2",
         new HashMap<String,String>() {{ put("c", "d"); }}, new HashMap<String, 
Map<String,String>>());
@@ -409,7 +408,6 @@ public class HostTest {
     map = host.getDesiredConfigs(c1.getClusterId());
     Assert.assertTrue("Expect desired config to contain global", 
map.containsKey("global"));
     Assert.assertEquals("Expect version to be 'v2'", "v2", 
map.get("global").getTag());
-    Assert.assertEquals("Expect user to be '_test1'", "_test1", 
map.get("global").getUser());
 
     host.addDesiredConfig(c1.getClusterId(), false, "_test2", config);
     map = host.getDesiredConfigs(c1.getClusterId());
@@ -430,7 +428,7 @@ public class HostTest {
     host.setIPv4("ipv4");
     host.setIPv6("ipv6");
 
-    Map<String, String> hostAttributes = new HashMap<String, String>();
+    Map<String, String> hostAttributes = new HashMap<>();
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "6.3");
     host.setHostAttributes(hostAttributes);

Reply via email to