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 2014/03/31 15:49:07 UTC
git commit: AMBARI-5268. Allow custom configuration properties to be
sepcified in blueprint.
Repository: ambari
Updated Branches:
refs/heads/trunk 8ad29b5ae -> 1cb63dc2c
AMBARI-5268. Allow custom configuration properties to be sepcified in blueprint.
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1cb63dc2
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1cb63dc2
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1cb63dc2
Branch: refs/heads/trunk
Commit: 1cb63dc2cb9555ed2470f23d2dc585fed8c7be96
Parents: 8ad29b5
Author: John Speidel <js...@hortonworks.com>
Authored: Fri Mar 28 17:36:15 2014 -0400
Committer: John Speidel <js...@hortonworks.com>
Committed: Mon Mar 31 09:48:24 2014 -0400
----------------------------------------------------------------------
.../internal/ClusterResourceProvider.java | 84 +++++++++++---------
.../internal/ClusterResourceProviderTest.java | 28 +++++--
2 files changed, 66 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1cb63dc2/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
index ed485a3..8d26cfa 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
@@ -677,44 +677,27 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider
* @param blueprintHostGroups host groups contained in the blueprint
*/
private void processConfigurations(Map<String, Map<String, String>> blueprintConfigurations,
- Stack stack, Map<String,
- HostGroup> blueprintHostGroups) {
-
- Set<String> services = getServicesToDeploy(stack, blueprintHostGroups);
- for (String service : services) {
- Collection<String> configTypes = stack.getConfigurationTypes(service);
- for (String type : configTypes) {
- Map<String, String> properties = stack.getConfigurationProperties(service, type);
- for (Map.Entry<String, String> entry : properties.entrySet()) {
- String propName = entry.getKey();
- String value = entry.getValue();
-
- //todo: move to Stack
- //strip .xml from type
- if (type.endsWith(".xml")) {
- type = type.substring(0, type.length() - 4);
- }
- // overlay property if specified at cluster scope in blueprint
- Map<String, String> blueprintTypeConfig = blueprintConfigurations.get(type);
- if (blueprintTypeConfig != null && blueprintTypeConfig.containsKey(propName)) {
- System.out.println("Overwriting property: " + propName + " for configuration " + type);
- value = blueprintTypeConfig.get(propName);
- }
+ Stack stack, Map<String, HostGroup> blueprintHostGroups) {
+
+ for (String service : getServicesToDeploy(stack, blueprintHostGroups)) {
+ for (String type : stack.getConfigurationTypes(service)) {
+ Map<String, String> typeProps = mapClusterConfigurations.get(type);
+ if (typeProps == null) {
+ typeProps = new HashMap<String, String>();
+ mapClusterConfigurations.put(type, typeProps);
+ }
+ typeProps.putAll(stack.getConfigurationProperties(service, type));
+ }
+ }
+ processBlueprintClusterConfigurations(blueprintConfigurations);
- Map<String, String> typeProps = mapClusterConfigurations.get(type);
- if (typeProps == null) {
- typeProps = new HashMap<String, String>();
- mapClusterConfigurations.put(type, typeProps);
- }
- // todo: should an exception be thrown if a property is included under multiple services
- if (! typeProps.containsKey(propName)) {
- // see if property needs to be updated
- PropertyUpdater propertyUpdater = propertyUpdaters.get(propName);
- if (propertyUpdater != null) {
- value = propertyUpdater.update(blueprintHostGroups, entry.getValue());
- }
- typeProps.put(propName, value);
- }
+ for (Map.Entry<String, Map<String, String>> entry : mapClusterConfigurations.entrySet()) {
+ for (Map.Entry<String, String> propertyEntry : entry.getValue().entrySet()) {
+ String propName = propertyEntry.getKey();
+ // see if property needs to be updated
+ PropertyUpdater propertyUpdater = propertyUpdaters.get(propName);
+ if (propertyUpdater != null) {
+ propertyEntry.setValue(propertyUpdater.update(blueprintHostGroups, propertyEntry.getValue()));
}
}
}
@@ -722,6 +705,27 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider
}
/**
+ * Process cluster scoped configurations provided in blueprint.
+ *
+ * @param blueprintConfigurations map of blueprint configurations keyed by type
+ */
+ private void processBlueprintClusterConfigurations(Map<String, Map<String, String>> blueprintConfigurations) {
+ for (Map.Entry<String, Map<String, String>> entry : blueprintConfigurations.entrySet()) {
+ Map<String, String> properties = entry.getValue();
+ if (properties != null && !properties.isEmpty()) {
+ String type = entry.getKey();
+ Map<String, String> typeProps = mapClusterConfigurations.get(type);
+ if (typeProps == null) {
+ typeProps = new HashMap<String, String>();
+ mapClusterConfigurations.put(type, typeProps);
+ }
+ // override default properties
+ typeProps.putAll(properties);
+ }
+ }
+ }
+
+ /**
* Explicitly set any properties that are required but not currently provided in the stack definition.
*/
private void setMissingConfigurations() {
@@ -1028,10 +1032,14 @@ public class ClusterResourceProvider extends AbstractControllerResourceProvider
Set<StackConfigurationResponse> serviceConfigs = getManagementController().getStackConfigurations(
Collections.singleton(new StackConfigurationRequest(name, version, service, null)
- ));
+ ));
for (StackConfigurationResponse config : serviceConfigs) {
String type = config.getType();
+ //strip .xml from type
+ if (type.endsWith(".xml")) {
+ type = type.substring(0, type.length() - 4);
+ }
Map<String, String> mapTypeConfig = mapServiceConfig.get(type);
if (mapTypeConfig == null) {
mapTypeConfig = new HashMap<String, String>();
http://git-wip-us.apache.org/repos/asf/ambari/blob/1cb63dc2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
index ae0b2ec..922df27 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
@@ -33,6 +33,7 @@ import static org.junit.Assert.fail;
import java.util.*;
+import com.google.gson.Gson;
import org.apache.ambari.server.api.services.PersistKeyValueImpl;
import org.apache.ambari.server.api.services.PersistKeyValueService;
import org.apache.ambari.server.controller.AmbariManagementController;
@@ -161,6 +162,8 @@ public class ClusterResourceProviderTest {
Capture<Set<StackConfigurationRequest>> serviceConfigurationRequestCapture1 = new Capture<Set<StackConfigurationRequest>>();
Capture<Set<StackConfigurationRequest>> serviceConfigurationRequestCapture2 = new Capture<Set<StackConfigurationRequest>>();
+ BlueprintConfigEntity blueprintConfig = createNiceMock(BlueprintConfigEntity.class);
+
HostGroupEntity hostGroup = createNiceMock(HostGroupEntity.class);
HostGroupComponentEntity hostGroupComponent1 = createNiceMock(HostGroupComponentEntity.class);
HostGroupComponentEntity hostGroupComponent2 = createNiceMock(HostGroupComponentEntity.class);
@@ -233,12 +236,17 @@ public class ClusterResourceProviderTest {
hostGroupHosts.add(hostGroupHostProperties);
properties.put("host-groups", hostGroups);
+ // blueprint cluster configuration properties
+ Map<String, String> blueprintConfigProperties = new HashMap<String, String>();
+ blueprintConfigProperties.put("property1", "value2");
+ blueprintConfigProperties.put("new.property", "new.property.value");
+
// expectations
expect(request.getProperties()).andReturn(propertySet).anyTimes();
expect(blueprintDAO.findByName(blueprintName)).andReturn(blueprint);
expect(blueprint.getStackName()).andReturn(stackName);
expect(blueprint.getStackVersion()).andReturn(stackVersion);
- expect(blueprint.getConfigurations()).andReturn(Collections.<BlueprintConfigEntity>emptyList());
+ expect(blueprint.getConfigurations()).andReturn(Collections.<BlueprintConfigEntity>singletonList(blueprintConfig));
expect(managementController.getStackServices(capture(stackServiceRequestCapture))).andReturn(stackServiceResponses);
expect(stackServiceResponse1.getServiceName()).andReturn("service1");
@@ -273,6 +281,10 @@ public class ClusterResourceProviderTest {
expect(stackConfigurationResponse4.getPropertyName()).andReturn("property3");
expect(stackConfigurationResponse4.getPropertyValue()).andReturn("value3");
+ expect(blueprintConfig.getBlueprintName()).andReturn("test-blueprint").anyTimes();
+ expect(blueprintConfig.getType()).andReturn("core-site").anyTimes();
+ expect(blueprintConfig.getConfigData()).andReturn(new Gson().toJson(blueprintConfigProperties));
+
expect(blueprint.getHostGroups()).andReturn(Collections.singleton(hostGroup));
expect(hostGroup.getName()).andReturn("group1");
expect(hostGroup.getComponents()).andReturn(hostGroupComponents);
@@ -300,10 +312,9 @@ public class ClusterResourceProviderTest {
replay(blueprintDAO, managementController, request, response, blueprint, stackServiceResponse1, stackServiceResponse2,
stackServiceComponentResponse1, stackServiceComponentResponse2, stackServiceComponentResponse3,
- stackConfigurationResponse1, stackConfigurationResponse2, stackConfigurationResponse3,
- stackConfigurationResponse4, hostGroup, hostGroupComponent1, hostGroupComponent2, hostGroupComponent3,
- serviceResourceProvider, componentResourceProvider, hostResourceProvider, hostComponentResourceProvider,
- persistKeyValue);
+ stackConfigurationResponse1, stackConfigurationResponse2, stackConfigurationResponse3, stackConfigurationResponse4,
+ blueprintConfig, hostGroup, hostGroupComponent1, hostGroupComponent2, hostGroupComponent3, serviceResourceProvider,
+ componentResourceProvider, hostResourceProvider, hostComponentResourceProvider, persistKeyValue);
// test
ClusterResourceProvider.injectBlueprintDAO(blueprintDAO);
@@ -393,11 +404,12 @@ public class ClusterResourceProviderTest {
assertEquals(1, hdfsConfigRequest.getProperties().size());
assertEquals("value2", hdfsConfigRequest.getProperties().get("property2"));
ConfigurationRequest coreConfigRequest = mapConfigRequests.get("core-site");
- assertEquals(4, coreConfigRequest.getProperties().size());
- assertEquals("value1", coreConfigRequest.getProperties().get("property1"));
+ assertEquals(5, coreConfigRequest.getProperties().size());
+ assertEquals("value2", coreConfigRequest.getProperties().get("property1"));
assertEquals("value3", coreConfigRequest.getProperties().get("property3"));
assertEquals("*", coreConfigRequest.getProperties().get("hadoop.proxyuser.oozie.hosts"));
assertEquals("users", coreConfigRequest.getProperties().get("hadoop.proxyuser.oozie.groups"));
+ assertEquals("new.property.value", coreConfigRequest.getProperties().get("new.property"));
assertNull(updateClusterPropertyMapCapture.getValue());
assertNull(updateClusterPropertyMapCapture2.getValue());
assertNull(updateClusterPropertyMapCapture3.getValue());
@@ -439,7 +451,7 @@ public class ClusterResourceProviderTest {
verify(blueprintDAO, managementController, request, response, blueprint, stackServiceResponse1, stackServiceResponse2,
stackServiceComponentResponse1, stackServiceComponentResponse2, stackServiceComponentResponse3,
stackConfigurationResponse1, stackConfigurationResponse2, stackConfigurationResponse3, stackConfigurationResponse4,
- hostGroup, hostGroupComponent1, hostGroupComponent2, hostGroupComponent3, serviceResourceProvider,
+ blueprintConfig, hostGroup, hostGroupComponent1, hostGroupComponent2, hostGroupComponent3, serviceResourceProvider,
componentResourceProvider, hostResourceProvider, hostComponentResourceProvider, persistKeyValue);
}