You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by js...@apache.org on 2015/04/27 21:09:32 UTC
ambari git commit: AMBARI-10770. Fix blueprint configuration
validation regarding password properties.
Repository: ambari
Updated Branches:
refs/heads/trunk 3a42dfa77 -> fa6194265
AMBARI-10770. Fix blueprint configuration validation regarding password properties.
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/fa619426
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/fa619426
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/fa619426
Branch: refs/heads/trunk
Commit: fa6194265f8ae0ba98806b50f88497bf659cdead
Parents: 3a42dfa
Author: John Speidel <js...@hortonworks.com>
Authored: Mon Apr 27 12:46:40 2015 -0400
Committer: John Speidel <js...@hortonworks.com>
Committed: Mon Apr 27 15:09:21 2015 -0400
----------------------------------------------------------------------
.../server/controller/internal/Stack.java | 35 +++---
.../server/controller/internal/StackTest.java | 117 +++++++++++++++++++
2 files changed, 137 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/fa619426/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/Stack.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/Stack.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/Stack.java
index 82d03fd..7167449 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/Stack.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/Stack.java
@@ -634,25 +634,23 @@ public class Stack {
// shouldn't have any required properties in stack level configuration
for (StackConfigurationResponse config : serviceConfigs) {
- String type = config.getType();
- //strip .xml from type
- if (type.endsWith(".xml")) {
- type = type.substring(0, type.length() - 4);
- }
+ ConfigProperty configProperty = new ConfigProperty(config);
+ String type = configProperty.getType();
+
Map<String, ConfigProperty> mapTypeConfig = mapServiceConfig.get(type);
if (mapTypeConfig == null) {
mapTypeConfig = new HashMap<String, ConfigProperty>();
mapServiceConfig.put(type, mapTypeConfig);
}
- ConfigProperty property = new ConfigProperty(config);
- mapTypeConfig.put(config.getPropertyName(), property);
+
+ mapTypeConfig.put(config.getPropertyName(), configProperty);
if (config.isRequired()) {
Map<String, ConfigProperty> requiredTypeConfig = mapRequiredServiceConfig.get(type);
if (requiredTypeConfig == null) {
requiredTypeConfig = new HashMap<String, ConfigProperty>();
mapRequiredServiceConfig.put(type, requiredTypeConfig);
}
- requiredTypeConfig.put(config.getPropertyName(), property);
+ requiredTypeConfig.put(config.getPropertyName(), configProperty);
}
}
}
@@ -663,18 +661,17 @@ public class Stack {
Collections.singleton(new StackLevelConfigurationRequest(name, version, null)));
for (StackConfigurationResponse config : stackLevelConfigs) {
- String type = config.getType();
- //strip .xml from type
- if (type.endsWith(".xml")) {
- type = type.substring(0, type.length() - 4);
- }
+ ConfigProperty configProperty = new ConfigProperty(config);
+ String type = configProperty.getType();
+
Map<String, ConfigProperty> mapTypeConfig = stackConfigurations.get(type);
if (mapTypeConfig == null) {
mapTypeConfig = new HashMap<String, ConfigProperty>();
stackConfigurations.put(type, mapTypeConfig);
}
+
mapTypeConfig.put(config.getPropertyName(),
- new ConfigProperty(config));
+ configProperty);
}
}
@@ -710,7 +707,7 @@ public class Stack {
this.value = config.getPropertyValue();
this.attributes = config.getPropertyAttributes();
this.propertyTypes = config.getPropertyType();
- this.type = config.getType();
+ this.type = normalizeType(config.getType());
}
public ConfigProperty(String type, String name, String value) {
@@ -750,5 +747,13 @@ public class Stack {
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
+
+ private String normalizeType(String type) {
+ //strip .xml from type
+ if (type.endsWith(".xml")) {
+ type = type.substring(0, type.length() - 4);
+ }
+ return type;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/fa619426/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackTest.java
new file mode 100644
index 0000000..3df9ec1
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackTest.java
@@ -0,0 +1,117 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.controller.internal;
+
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.StackConfigurationRequest;
+import org.apache.ambari.server.controller.StackConfigurationResponse;
+import org.apache.ambari.server.controller.StackLevelConfigurationRequest;
+import org.apache.ambari.server.controller.StackServiceComponentRequest;
+import org.apache.ambari.server.controller.StackServiceComponentResponse;
+import org.apache.ambari.server.controller.StackServiceRequest;
+import org.apache.ambari.server.controller.StackServiceResponse;
+import org.apache.ambari.server.state.DependencyInfo;
+import org.apache.ambari.server.topology.Configuration;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Set;
+
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.powermock.api.easymock.PowerMock.createNiceMock;
+import static org.powermock.api.easymock.PowerMock.replay;
+
+/**
+ * Stack unit tests.
+ */
+public class StackTest {
+
+ @Test
+ public void testTestXmlExtensionStrippedOff() throws Exception {
+ AmbariManagementController controller = createNiceMock(AmbariManagementController.class);
+ AmbariMetaInfo metaInfo = createNiceMock(AmbariMetaInfo.class);
+ Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
+ StackServiceResponse stackServiceResponse = createNiceMock(StackServiceResponse.class);
+ Capture<Set<StackServiceComponentRequest>> stackComponentRequestCapture = new Capture<Set<StackServiceComponentRequest>>();
+ StackServiceComponentResponse stackComponentResponse = createNiceMock(StackServiceComponentResponse.class);
+ Capture<Set<StackConfigurationRequest>> stackConfigurationRequestCapture = new Capture<Set<StackConfigurationRequest>>();
+ Capture<Set<StackLevelConfigurationRequest>> stackLevelConfigurationRequestCapture = new Capture<Set<StackLevelConfigurationRequest>>();
+ StackConfigurationResponse stackConfigurationResponse = EasyMock.createNiceMock(StackConfigurationResponse.class);
+
+ expect(controller.getStackServices(capture(stackServiceRequestCapture))).
+ andReturn(Collections.singleton(stackServiceResponse)).anyTimes();
+
+ expect(controller.getAmbariMetaInfo()).andReturn(metaInfo).anyTimes();
+
+ expect(stackServiceResponse.getServiceName()).andReturn("service1").anyTimes();
+ expect(stackServiceResponse.getExcludedConfigTypes()).andReturn(Collections.<String>emptySet());
+
+ expect(controller.getStackComponents(capture(stackComponentRequestCapture))).
+ andReturn(Collections.singleton(stackComponentResponse)).anyTimes();
+
+ expect(stackComponentResponse.getComponentName()).andReturn("component1").anyTimes();
+ expect(stackComponentResponse.getComponentCategory()).andReturn("test-site.xml").anyTimes();
+
+ expect(controller.getStackConfigurations(capture(stackConfigurationRequestCapture))).
+ andReturn(Collections.singleton(stackConfigurationResponse)).anyTimes();
+
+ // no stack level configs for this test
+ expect(controller.getStackLevelConfigurations(capture(stackLevelConfigurationRequestCapture))).
+ andReturn(Collections.<StackConfigurationResponse>emptySet()).anyTimes();
+
+ expect(stackConfigurationResponse.getPropertyName()).andReturn("prop1").anyTimes();
+ expect(stackConfigurationResponse.getPropertyValue()).andReturn("prop1Val").anyTimes();
+ expect(stackConfigurationResponse.getType()).andReturn("test-site.xml").anyTimes();
+ expect(stackConfigurationResponse.getPropertyType()).andReturn(
+ Collections.<org.apache.ambari.server.state.PropertyInfo.PropertyType>emptySet()).anyTimes();
+ expect(stackConfigurationResponse.getPropertyAttributes()).andReturn(Collections.<String, String>emptyMap()).anyTimes();
+ expect(stackConfigurationResponse.isRequired()).andReturn(true).anyTimes();
+
+ expect(metaInfo.getComponentDependencies("test", "1.0", "service1", "component1")).
+ andReturn(Collections.<DependencyInfo>emptyList()).anyTimes();
+
+
+ replay(controller, stackServiceResponse, stackComponentResponse, stackConfigurationResponse, metaInfo);
+
+
+ Stack stack = new Stack("test", "1.0", controller);
+ Configuration configuration = stack.getConfiguration(Collections.singleton("service1"));
+ assertEquals("prop1Val", configuration.getProperties().get("test-site").get("prop1"));
+
+ assertEquals("test-site", stack.getRequiredConfigurationProperties("service1").iterator().next().getType());
+
+ // assertions
+ StackServiceRequest stackServiceRequest = stackServiceRequestCapture.getValue().iterator().next();
+ assertEquals("test", stackServiceRequest.getStackName());
+ assertEquals("1.0", stackServiceRequest.getStackVersion());
+
+ StackServiceComponentRequest stackComponentRequest = stackComponentRequestCapture.getValue().iterator().next();
+ assertEquals("service1", stackComponentRequest.getServiceName());
+ assertEquals("test", stackComponentRequest.getStackName());
+ assertEquals("1.0", stackComponentRequest.getStackVersion());
+ assertNull(stackComponentRequest.getComponentName());
+ }
+
+}