AMBARI-20542 Fixed configuration type validation in case of blueprint deployments (unit tests added, removed unnecessary NP checks).
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f5eaa81e Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f5eaa81e Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f5eaa81e Branch: refs/heads/branch-2.5 Commit: f5eaa81e13adf00e5f7515b5466653a354808a93 Parents: 5892b35 Author: lpuskas <lpus...@apache.org> Authored: Mon Mar 27 13:03:29 2017 +0200 Committer: lpuskas <lpus...@apache.org> Committed: Thu Mar 30 17:02:43 2017 +0200 ---------------------------------------------------------------------- .../validators/ClusterConfigTypeValidator.java | 14 +--- .../ClusterConfigTypeValidatorTest.java | 70 ++++++++++++++------ 2 files changed, 52 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/f5eaa81e/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java index 305c88e..634ab08 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidator.java @@ -33,21 +33,11 @@ public class ClusterConfigTypeValidator implements TopologyValidator { @Override public void validate(ClusterTopology topology) throws InvalidTopologyException { - if (topology.getConfiguration() == null) { - LOGGER.debug("No configuration is set into the topology"); - return; - } - - if (topology.getConfiguration().getProperties() == null) { - LOGGER.debug("No properties is set into the topology configuration"); - return; - } - - // config types in from the request + // config types in from the request / configuration is always set in the request instance Set<String> topologyClusterConfigTypes = new HashSet(topology.getConfiguration().getAllConfigTypes()); LOGGER.debug("Cluster config types: {}", topologyClusterConfigTypes); - if (topologyClusterConfigTypes == null || topologyClusterConfigTypes.isEmpty()) { + if (topologyClusterConfigTypes.isEmpty()) { LOGGER.debug("No config types to be checked."); return; } http://git-wip-us.apache.org/repos/asf/ambari/blob/f5eaa81e/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidatorTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidatorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidatorTest.java index bb10df9..a701507 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidatorTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/validators/ClusterConfigTypeValidatorTest.java @@ -17,7 +17,7 @@ package org.apache.ambari.server.topology.validators; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.Map; +import java.util.Set; import org.apache.ambari.server.controller.internal.Stack; import org.apache.ambari.server.topology.Blueprint; @@ -41,14 +41,10 @@ public class ClusterConfigTypeValidatorTest extends EasyMockSupport { @Rule public EasyMockRule mocks = new EasyMockRule(this); - @Mock private Configuration clusterConfigurationMock; @Mock - private Map<String, Map<String, String>> clusterConfigurationMapMock; - - @Mock private Blueprint blueprintMock; @Mock @@ -57,13 +53,14 @@ public class ClusterConfigTypeValidatorTest extends EasyMockSupport { @Mock private ClusterTopology clusterTopologyMock; + private Set<String> clusterRequestConfigTypes; + @TestSubject private ClusterConfigTypeValidator clusterConfigTypeValidator = new ClusterConfigTypeValidator(); @Before public void before() { EasyMock.expect(clusterTopologyMock.getConfiguration()).andReturn(clusterConfigurationMock).anyTimes(); - EasyMock.expect(clusterConfigurationMock.getProperties()).andReturn(clusterConfigurationMapMock).anyTimes(); EasyMock.expect(clusterTopologyMock.getBlueprint()).andReturn(blueprintMock).anyTimes(); EasyMock.expect(blueprintMock.getStack()).andReturn(stackMock).anyTimes(); @@ -76,38 +73,71 @@ public class ClusterConfigTypeValidatorTest extends EasyMockSupport { @Test - public void testShouldValidationPassIfNoConfigTypesSpecifiedInCCTemplate() throws Exception { - //GIVEN - EasyMock.expect(clusterConfigurationMapMock.keySet()).andReturn(Collections.<String>emptySet()); + public void testShouldValidationPassWhenNoConfigTypesSpecifiedInCCTemplate() throws Exception { + // GIVEN + clusterRequestConfigTypes = Collections.<String>emptySet(); + EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(clusterRequestConfigTypes).anyTimes(); + + replayAll(); + + // WHEN + clusterConfigTypeValidator.validate(clusterTopologyMock); + + // THEN + } + + + @Test + public void testShouldValidationPassWhenAllConfigTypesAreValid() throws Exception { + // GIVEN + // all the config types are OK + clusterRequestConfigTypes = new HashSet<String>(Arrays.asList("core-site", "yarn-site")); + EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(clusterRequestConfigTypes).anyTimes(); + + EasyMock.expect(blueprintMock.getServices()).andReturn(new HashSet<String>(Arrays.asList("YARN", "HDFS"))); + + EasyMock.expect(stackMock.getConfigurationTypes("HDFS")).andReturn(Arrays.asList("core-site")); + EasyMock.expect(stackMock.getConfigurationTypes("YARN")).andReturn(Arrays.asList("yarn-site")); + replayAll(); - //WHEN + // WHEN clusterConfigTypeValidator.validate(clusterTopologyMock); + + // THEN + // Exception is thrown + } @Test(expected = InvalidTopologyException.class) public void testShouldValidationFailWhenInvalidConfigGroupsSpecifiedInCCTemplate() throws Exception { - // given - EasyMock.expect(clusterConfigurationMapMock.keySet()).andReturn(new HashSet<String>(Arrays.asList("oozie-site"))); - EasyMock.expect(blueprintMock.getServices()).andReturn(new HashSet<String>(Arrays.asList("YARN", "HDFS"))); + // GIVEN + // the config type that is not present in the stack definition for services + clusterRequestConfigTypes = new HashSet<String>(Arrays.asList("oozie-site")); + EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(clusterRequestConfigTypes).anyTimes(); + + EasyMock.expect(blueprintMock.getServices()).andReturn(new HashSet<String>(Arrays.asList("YARN", "HDFS"))); EasyMock.expect(stackMock.getConfigurationTypes("HDFS")).andReturn(Arrays.asList("core-site")); EasyMock.expect(stackMock.getConfigurationTypes("YARN")).andReturn(Arrays.asList("yarn-site")); replayAll(); - //when + // WHEN clusterConfigTypeValidator.validate(clusterTopologyMock); - // then + // THEN // Exception is thrown } @Test(expected = InvalidTopologyException.class) - public void testShouldValidationFailWhenInvalidConfigGroupProvided() throws Exception { - // given - EasyMock.expect(clusterConfigurationMapMock.keySet()).andReturn(new HashSet<String>(Arrays.asList("core-site", "yarn-site", "oozie-site"))); + public void testShouldValidationFailWhenThereIsAnInvalidConfigGroupProvided() throws Exception { + // GIVEN + // oozzie-type is wrong! + clusterRequestConfigTypes = new HashSet<String>(Arrays.asList("core-site", "yarn-site", "oozie-site")); + EasyMock.expect(clusterConfigurationMock.getAllConfigTypes()).andReturn(clusterRequestConfigTypes).anyTimes(); + EasyMock.expect(blueprintMock.getServices()).andReturn(new HashSet<String>(Arrays.asList("YARN", "HDFS"))); EasyMock.expect(stackMock.getConfigurationTypes("HDFS")).andReturn(Arrays.asList("core-site")); @@ -115,10 +145,10 @@ public class ClusterConfigTypeValidatorTest extends EasyMockSupport { replayAll(); - //when + // WHEN clusterConfigTypeValidator.validate(clusterTopologyMock); - // then + // THEN // Exception is thrown }