AMBARI-20542 Fixed configuration type validation in case of blueprint 
deployments.


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

Branch: refs/heads/branch-2.5
Commit: 5892b3547cfb1cf1a4ebb33030ad3f3e1a58c8ab
Parents: 0fb115b
Author: lpuskas <lpus...@apache.org>
Authored: Thu Mar 23 13:57:58 2017 +0100
Committer: lpuskas <lpus...@apache.org>
Committed: Thu Mar 30 16:27:37 2017 +0200

----------------------------------------------------------------------
 .../validators/ClusterConfigTypeValidator.java  | 19 ++++++------
 .../ClusterConfigTypeValidatorTest.java         | 31 ++++++++++++++++----
 2 files changed, 34 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5892b354/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 18d08b9..305c88e 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
@@ -44,29 +44,28 @@ public class ClusterConfigTypeValidator implements 
TopologyValidator {
     }
 
     // config types in from the request
-    Set<String> clusterConfigTypes = 
topology.getConfiguration().getProperties().keySet();
-    LOGGER.debug("Cluster config types: {}", clusterConfigTypes);
+    Set<String> topologyClusterConfigTypes = new 
HashSet(topology.getConfiguration().getAllConfigTypes());
+    LOGGER.debug("Cluster config types: {}", topologyClusterConfigTypes);
 
-    if (clusterConfigTypes == null || clusterConfigTypes.isEmpty()) {
+    if (topologyClusterConfigTypes == null || 
topologyClusterConfigTypes.isEmpty()) {
       LOGGER.debug("No config types to be checked.");
       return;
     }
 
     // collecting all config types for services in the blueprint (from the 
related stack)
-    Set<String> serviceConfigTypes = new HashSet<>();
+    Set<String> stackServiceConfigTypes = new HashSet<>();
     for (String serviceName : topology.getBlueprint().getServices()) {
-      
serviceConfigTypes.addAll(topology.getBlueprint().getStack().getConfigurationTypes(serviceName));
+      
stackServiceConfigTypes.addAll(topology.getBlueprint().getStack().getConfigurationTypes(serviceName));
     }
 
     // identifying invalid config types
-    Set<String> configTypeIntersection = new 
HashSet<String>(serviceConfigTypes);
+    Set<String> configTypeIntersection = new 
HashSet<String>(topologyClusterConfigTypes);
 
-    // if the intersection is changed, there's been some wrong config type 
provided in the cluster configuration
-    if (configTypeIntersection.retainAll(clusterConfigTypes)) {
-      LOGGER.debug("Valid config types: {}", configTypeIntersection);
+    if (configTypeIntersection.retainAll(stackServiceConfigTypes)) {
+      // there are config types not present in the stack for the services 
listed in the blueprint
 
       // get the wrong  config types
-      Set<String> invalidConfigTypes = new HashSet<>(clusterConfigTypes);
+      Set<String> invalidConfigTypes = new 
HashSet<>(topologyClusterConfigTypes);
       invalidConfigTypes.removeAll(configTypeIntersection);
 
       LOGGER.error("The following config typess are wrong: {}", 
invalidConfigTypes);

http://git-wip-us.apache.org/repos/asf/ambari/blob/5892b354/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 24fa8b8..bb10df9 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
@@ -74,8 +74,19 @@ public class ClusterConfigTypeValidatorTest extends 
EasyMockSupport {
     resetAll();
   }
 
+
+  @Test
+  public void testShouldValidationPassIfNoConfigTypesSpecifiedInCCTemplate() 
throws Exception {
+    //GIVEN
+    
EasyMock.expect(clusterConfigurationMapMock.keySet()).andReturn(Collections.<String>emptySet());
+    replayAll();
+
+    //WHEN
+    clusterConfigTypeValidator.validate(clusterTopologyMock);
+  }
+
   @Test(expected = InvalidTopologyException.class)
-  public void 
testShouldValidationFailWhenInvalidConfigGroupSpecifiedInCCTemplate() throws 
Exception {
+  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")));
@@ -92,15 +103,23 @@ public class ClusterConfigTypeValidatorTest extends 
EasyMockSupport {
     // Exception is thrown
   }
 
-  @Test
-  public void testShouldValidationPassIfNoConfigTypesSpecifiedInCCTemplate() 
throws Exception {
-    //GIVEN
-    
EasyMock.expect(clusterConfigurationMapMock.keySet()).andReturn(Collections.<String>emptySet());
+
+  @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")));
+    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

Reply via email to