You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2015/12/17 19:53:01 UTC
ambari git commit: AMBARI-14418 - After Downgrade Cluster Desired
Configurations Are Not Set (jonathanhurley)
Repository: ambari
Updated Branches:
refs/heads/trunk d86dbf35c -> cc452ed8f
AMBARI-14418 - After Downgrade Cluster Desired Configurations Are Not Set (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cc452ed8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cc452ed8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cc452ed8
Branch: refs/heads/trunk
Commit: cc452ed8f634531a3d0471a3f1220054b7efaa37
Parents: d86dbf3
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Thu Dec 17 10:26:37 2015 -0500
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Thu Dec 17 13:52:44 2015 -0500
----------------------------------------------------------------------
.../server/state/cluster/ClusterImpl.java | 56 +++++++----
.../server/state/cluster/ClusterTest.java | 100 +++++++++++++++++++
2 files changed, 136 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc452ed8/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 6d3bc7a..a0c6cfc 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
@@ -36,6 +36,7 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.annotation.Nullable;
+import javax.persistence.EntityManager;
import javax.persistence.RollbackException;
import org.apache.ambari.server.AmbariException;
@@ -61,7 +62,6 @@ import org.apache.ambari.server.orm.dao.AlertDispatchDAO;
import org.apache.ambari.server.orm.dao.ClusterDAO;
import org.apache.ambari.server.orm.dao.ClusterStateDAO;
import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
-import org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO;
import org.apache.ambari.server.orm.dao.HostConfigMappingDAO;
import org.apache.ambari.server.orm.dao.HostDAO;
import org.apache.ambari.server.orm.dao.HostVersionDAO;
@@ -90,8 +90,6 @@ import org.apache.ambari.server.orm.entities.StackEntity;
import org.apache.ambari.server.orm.entities.TopologyRequestEntity;
import org.apache.ambari.server.security.authorization.AuthorizationException;
import org.apache.ambari.server.security.authorization.AuthorizationHelper;
-import org.apache.ambari.server.security.authorization.ResourceType;
-import org.apache.ambari.server.security.authorization.RoleAuthorization;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.ClusterHealthReport;
import org.apache.ambari.server.state.Clusters;
@@ -192,9 +190,15 @@ public class ClusterImpl implements Cluster {
private final ReentrantReadWriteLock hostTransitionStateLock = new ReentrantReadWriteLock();
private final Lock hostTransitionStateWriteLock = hostTransitionStateLock.writeLock();
+ /**
+ * The backing cluster entity - this should never be cached locally.
+ */
private ClusterEntity clusterEntity;
- private long clusterId;
+ /**
+ * The unique ID of the {@link #clusterEntity}.
+ */
+ private final long clusterId;
@Inject
private ClusterDAO clusterDAO;
@@ -224,9 +228,6 @@ public class ClusterImpl implements Cluster {
private ConfigGroupFactory configGroupFactory;
@Inject
- private ConfigGroupHostMappingDAO configGroupHostMappingDAO;
-
- @Inject
private RequestExecutionFactory requestExecutionFactory;
@Inject
@@ -278,6 +279,7 @@ public class ClusterImpl implements Cluster {
Injector injector) throws AmbariException {
injector.injectMembers(this);
this.clusterEntity = clusterEntity;
+ clusterId = clusterEntity.getClusterId();
serviceComponentHosts = new HashMap<String,
Map<String, Map<String, ServiceComponentHost>>>();
@@ -2165,8 +2167,9 @@ public class ClusterImpl implements Cluster {
c.setVersion(allConfigs.get(e.getType()).get(e.getTag()).getVersion());
Set<DesiredConfig> configs = map.get(e.getType());
- if (configs == null)
+ if (configs == null) {
configs = new HashSet<>();
+ }
configs.add(c);
@@ -2195,8 +2198,9 @@ public class ClusterImpl implements Cluster {
hostIdToName.get(mappingEntity.getHostId()), mappingEntity.getVersion()));
}
- for (DesiredConfig c: entry.getValue())
+ for (DesiredConfig c: entry.getValue()) {
c.setHostOverrides(hostOverrides);
+ }
}
}
@@ -3017,21 +3021,27 @@ public class ClusterImpl implements Cluster {
public void applyLatestConfigurations(StackId stackId) {
clusterGlobalLock.writeLock().lock();
try {
+ ClusterEntity clusterEntity = getClusterEntity();
+ Collection<ClusterConfigMappingEntity> configMappingEntities = clusterEntity.getConfigMappingEntities();
- Collection<ClusterConfigMappingEntity> configMappingEntities = clusterDAO.getClusterConfigMappingEntitiesByCluster(getClusterId());
-
- // disable previous config
+ // disable all configs
for (ClusterConfigMappingEntity e : configMappingEntities) {
LOG.debug("{} with tag {} is unselected", e.getType(), e.getTag());
e.setSelected(0);
}
- List<ClusterConfigMappingEntity> clusterConfigMappingEntities = clusterDAO.getClusterConfigMappingsByStack(clusterEntity.getClusterId(), stackId);
- Collection<ClusterConfigMappingEntity> latestConfigMappingByStack = getLatestConfigMapping(clusterConfigMappingEntities);
+ List<ClusterConfigMappingEntity> clusterConfigMappingsForStack = clusterDAO.getClusterConfigMappingsByStack(
+ clusterEntity.getClusterId(), stackId);
+
+ Collection<ClusterConfigMappingEntity> latestConfigMappingByStack = getLatestConfigMapping(
+ clusterConfigMappingsForStack);
+ // loop through all configs and set the latest to enabled for the
+ // specified stack
for(ClusterConfigMappingEntity e: configMappingEntities){
- String type = e.getType(); //loop thru all the config mappings
+ String type = e.getType();
String tag = e.getTag();
+
for (ClusterConfigMappingEntity latest : latestConfigMappingByStack) {
String t = latest.getType();
String tagLatest = latest.getTag();
@@ -3042,7 +3052,9 @@ public class ClusterImpl implements Cluster {
}
}
- clusterDAO.mergeConfigMappings(clusterConfigMappingEntities);
+ clusterEntity.setConfigMappingEntities(configMappingEntities);
+ clusterEntity = clusterDAO.merge(clusterEntity);
+ clusterDAO.mergeConfigMappings(configMappingEntities);
refresh();
cacheConfigurations();
@@ -3279,13 +3291,20 @@ public class ClusterImpl implements Cluster {
// Iterate through the topology requests associated with this cluster and look for PROVISION request
for (TopologyRequestEntity topologyRequest: topologyRequests) {
TopologyRequest.Type requestAction = TopologyRequest.Type.valueOf(topologyRequest.getAction());
- if (requestAction == TopologyRequest.Type.PROVISION)
+ if (requestAction == TopologyRequest.Type.PROVISION) {
return true;
+ }
}
return false;
}
+ /**
+ * Gets the {@link ClusterEntity} for this {@link Cluster} from the
+ * {@link EntityManager} cache.
+ *
+ * @return
+ */
private ClusterEntity getClusterEntity() {
if (!clusterDAO.isManaged(clusterEntity)) {
clusterEntity = clusterDAO.findById(clusterEntity.getClusterId());
@@ -3293,6 +3312,3 @@ public class ClusterImpl implements Cluster {
return clusterEntity;
}
}
-
-
-
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc452ed8/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 b6eb8d0..05dbce1 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
@@ -62,6 +62,7 @@ import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
import org.apache.ambari.server.orm.dao.ResourceTypeDAO;
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.ClusterStateEntity;
@@ -2265,6 +2266,105 @@ public class ClusterTest {
assertTrue(clusterConfigEntity.getData().contains("two"));
assertTrue(clusterConfigEntity.getData().contains("three"));
assertTrue(clusterConfigEntity.getData().contains("four"));
+ }
+
+ /**
+ * Tests that {@link Cluster#applyLatestConfigurations(StackId)} sets the
+ * right configs to enabled.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testApplyLatestConfigurations() 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";
+
+ 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);
+ 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);
+ 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());
+ } else {
+ Assert.assertEquals(0, clusterConfigMapping.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());
+ } else {
+ Assert.assertEquals(1, clusterConfigMapping.isSelected());
+ }
+ }
}
}