Repository: ambari
Updated Branches:
  refs/heads/trunk 02a7eb72e -> 18ed939b2


AMBARI-16203. Blueprint deployments could cause NullPointerExceptions. (Laszlo 
Puskas via stoader)


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

Branch: refs/heads/trunk
Commit: 18ed939b2f5fc5e1dbd011d10ff0b1c596410727
Parents: 02a7eb7
Author: Laszlo Puskas <lpus...@hortonworks.com>
Authored: Tue May 10 09:39:55 2016 +0200
Committer: Toader, Sebastian <stoa...@hortonworks.com>
Committed: Tue May 10 12:11:05 2016 +0200

----------------------------------------------------------------------
 .../BlueprintConfigurationProcessor.java        | 34 +++++++--
 .../BlueprintConfigurationProcessorTest.java    | 72 +++++++++++++++++---
 2 files changed, 88 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/18ed939b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
index ec02f00..1ddc4e1 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java
@@ -2670,24 +2670,44 @@ public class BlueprintConfigurationProcessor {
 
     }
 
-    addExcludedConfigProperties(configuration, configTypesUpdated, services);
+    addExcludedConfigProperties(configuration, configTypesUpdated, services, 
clusterTopology.getBlueprint().getStack());
 
   }
 
   /**
    * Adds properties from excluded config files (marked as excluded in service 
metainfo.xml) like Falcon related properties
    * from oozie-site.xml defined in FALCON/configuration. (AMBARI-13017)
+   *
+   * In case the excluded config-type related service is not present in the 
blueprint, excluded configs are ignored
    * @param configuration
    * @param configTypesUpdated
-   * @param services
+   * @param blueprintServices
+   * @param stack
    */
-  private void addExcludedConfigProperties(Configuration configuration, 
Set<String> configTypesUpdated, Collection<String> services) {
-    Stack stack = clusterTopology.getBlueprint().getStack();
+  private void addExcludedConfigProperties(Configuration configuration, 
Set<String> configTypesUpdated, Collection<String> blueprintServices, Stack 
stack) {
+    LOG.debug("Handling excluded properties for blueprint services: {}", 
blueprintServices);
+
+    for (String blueprintService : blueprintServices) {
+
+      LOG.debug("Handling excluded properties for blueprint service: {}", 
blueprintService);
+      Set<String> excludedConfigTypes = 
stack.getExcludedConfigurationTypes(blueprintService);
+
+      if (excludedConfigTypes.isEmpty()) {
+        LOG.debug("There are no excluded config types for blueprint service: 
{}", blueprintService);
+        continue;
+      }
 
-    for(String service: services){
-      Set<String> excludedConfigTypes = 
stack.getExcludedConfigurationTypes(service);
       for(String configType: excludedConfigTypes) {
-        Map<String, String> configProperties = 
stack.getConfigurationProperties(service, configType);
+        LOG.debug("Handling excluded config type [{}] for blueprint service: 
[{}]", configType, blueprintService);
+
+        String blueprintServiceForExcludedConfig = 
stack.getServiceForConfigType(configType);
+        if (!blueprintServices.contains(blueprintServiceForExcludedConfig)) {
+          LOG.debug("Service [{}] for excluded config type [{}] is not present 
in the blueprint. " +
+              "Ignoring excluded config entries.", 
blueprintServiceForExcludedConfig, configType);
+          continue;
+        }
+
+        Map<String, String> configProperties = 
stack.getConfigurationProperties(blueprintService, configType);
         for(Map.Entry<String, String> entry: configProperties.entrySet()) {
           LOG.debug("ADD property " + configType + " " + entry.getKey() + " " 
+ entry.getValue());
           ensureProperty(configuration, configType, entry.getKey(), 
entry.getValue(), configTypesUpdated);

http://git-wip-us.apache.org/repos/asf/ambari/blob/18ed939b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
index 2759869..5c6aeaf 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
@@ -45,9 +45,13 @@ import org.apache.ambari.server.topology.HostGroupImpl;
 import org.apache.ambari.server.topology.HostGroupInfo;
 import org.apache.ambari.server.topology.InvalidTopologyException;
 import org.apache.ambari.server.utils.CollectionPresentationUtils;
+import org.easymock.EasyMockRule;
+import org.easymock.Mock;
+import org.easymock.MockType;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
@@ -63,7 +67,6 @@ import static junit.framework.Assert.assertNull;
 import static junit.framework.Assert.assertTrue;
 import static junit.framework.Assert.fail;
 import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.reset;
@@ -73,16 +76,23 @@ import static org.easymock.EasyMock.reset;
  */
 public class BlueprintConfigurationProcessorTest {
 
-  private static final String CLUSTER_NAME = "test-cluster";
-  private static final Configuration EMPTY_CONFIG = new 
Configuration(Collections.<String, Map<String, String>>emptyMap(),
-      Collections.<String, Map<String, Map<String, String>>>emptyMap());
-
+  private static final Configuration EMPTY_CONFIG = new 
Configuration(Collections.<String, Map<String, String>>emptyMap(), 
Collections.<String, Map<String, Map<String, String>>>emptyMap());
   private final Map<String, Collection<String>> serviceComponents = new 
HashMap<String, Collection<String>>();
 
-  private final Blueprint bp = createNiceMock(Blueprint.class);
-  private final ServiceInfo serviceInfo = createNiceMock(ServiceInfo.class);
-  private final Stack stack = createNiceMock(Stack.class);
-  private final AmbariContext ambariConext = 
createNiceMock(AmbariContext.class);
+  @Rule
+  public EasyMockRule mocks = new EasyMockRule(this);
+
+  @Mock(type = MockType.NICE)
+  private AmbariContext ambariConext;
+
+  @Mock(type = MockType.NICE)
+  private Blueprint bp;
+
+  @Mock(type = MockType.NICE)
+  private ServiceInfo serviceInfo;
+
+  @Mock(type = MockType.NICE)
+  private Stack stack;
 
   @Before
   public void init() throws Exception {
@@ -3951,7 +3961,7 @@ public class BlueprintConfigurationProcessorTest {
   }
 
   @Test
-  public void testAddExcludedProperties() throws Exception {
+  public void testExcludedPropertiesShouldBeAddedWhenServiceIsInBlueprint() 
throws Exception {
     reset(stack);
 
     // defaults from init() method that we need
@@ -3960,8 +3970,10 @@ public class BlueprintConfigurationProcessorTest {
     expect(stack.isMasterComponent((String) 
anyObject())).andReturn(false).anyTimes();
 
     // customized stack calls for this test only
-    
expect(stack.getExcludedConfigurationTypes("FALCON")).andReturn(Collections.singleton("oozie-site")).anyTimes();
+    
expect(stack.getExcludedConfigurationTypes("FALCON")).andReturn(Collections.singleton("oozie-site"));
+    
expect(stack.getExcludedConfigurationTypes("OOZIE")).andReturn(Collections.<String>emptySet());
     expect(stack.getConfigurationProperties("FALCON", 
"oozie-site")).andReturn(Collections.singletonMap("oozie.service.ELService.ext.functions.coord-job-submit-instances",
 "testValue")).anyTimes();
+    
expect(stack.getServiceForConfigType("oozie-site")).andReturn("OOZIE").anyTimes();
 
     Map<String, Map<String, String>> properties = new HashMap<String, 
Map<String, String>>();
     Configuration clusterConfig = new Configuration(properties, 
Collections.<String, Map<String, Map<String, String>>>emptyMap());
@@ -3969,6 +3981,8 @@ public class BlueprintConfigurationProcessorTest {
     Collection<String> hgComponents = new HashSet<String>();
     hgComponents.add("FALCON_SERVER");
     hgComponents.add("FALCON_CLIENT");
+    hgComponents.add("OOZIE_SERVER");
+    hgComponents.add("OOZIE_CLIENT");
     List<String> hosts = new ArrayList<String>();
     hosts.add("c6401.apache.ambari.org");
     hosts.add("serverTwo");
@@ -3987,6 +4001,42 @@ public class BlueprintConfigurationProcessorTest {
   }
 
   @Test
+  public void 
testExcludedPropertiesShouldBeIgnoredWhenServiceIsNotInBlueprint() throws 
Exception {
+    reset(stack);
+
+    // defaults from init() method that we need
+    expect(stack.getName()).andReturn("testStack").anyTimes();
+    expect(stack.getVersion()).andReturn("1").anyTimes();
+    expect(stack.isMasterComponent((String) 
anyObject())).andReturn(false).anyTimes();
+
+    // customized stack calls for this test only
+    
expect(stack.getExcludedConfigurationTypes("FALCON")).andReturn(Collections.singleton("oozie-site")).anyTimes();
+    expect(stack.getConfigurationProperties("FALCON", 
"oozie-site")).andReturn(Collections.singletonMap("oozie.service.ELService.ext.functions.coord-job-submit-instances",
 "testValue")).anyTimes();
+    
expect(stack.getServiceForConfigType("oozie-site")).andReturn("OOZIE").anyTimes();
+
+    Map<String, Map<String, String>> properties = new HashMap<String, 
Map<String, String>>();
+    Configuration clusterConfig = new Configuration(properties, 
Collections.<String, Map<String, Map<String, String>>>emptyMap());
+
+    Collection<String> hgComponents = new HashSet<String>();
+    hgComponents.add("FALCON_SERVER");
+    hgComponents.add("FALCON_CLIENT");
+    List<String> hosts = new ArrayList<String>();
+    hosts.add("c6401.apache.ambari.org");
+    hosts.add("serverTwo");
+    TestHostGroup group1 = new TestHostGroup("host_group_1", hgComponents, 
hosts);
+
+    Collection<TestHostGroup> hostGroups = new HashSet<TestHostGroup>();
+    hostGroups.add(group1);
+
+    ClusterTopology topology = createClusterTopology(bp, clusterConfig, 
hostGroups);
+    BlueprintConfigurationProcessor updater = new 
BlueprintConfigurationProcessor(topology);
+
+    updater.doUpdateForClusterCreate();
+
+    Assert.assertNull("Excluded properties shouldn't be added in this setup!", 
clusterConfig.getPropertyValue("oozie-site", 
"oozie.service.ELService.ext.functions.coord-job-submit-instances"));
+  }
+
+  @Test
   public void testAddExcludedPropertiesAreOverwrittenByBlueprintConfigs() 
throws Exception {
     reset(stack);
 

Reply via email to