You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2013/03/13 22:36:16 UTC
svn commit: r1456146 - in /incubator/ambari/trunk: ./
ambari-server/src/main/java/org/apache/ambari/server/controller/
ambari-server/src/test/java/org/apache/ambari/server/controller/
Author: ncole
Date: Wed Mar 13 21:36:16 2013
New Revision: 1456146
URL: http://svn.apache.org/r1456146
Log:
AMBARI-1592. Fix for configuration propagation
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1456146&r1=1456145&r2=1456146&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Mar 13 21:36:16 2013
@@ -458,6 +458,8 @@ Trunk (unreleased changes):
BUG FIXES
+ AMBARI-1592. Fix configuration propagation.
+
AMBARI-1619. Fix for category path separators.
AMBARI-1616. Error during upgrading Ambari Server from 1.2.0/1.2.1 to
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1456146&r1=1456145&r2=1456146&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Wed Mar 13 21:36:16 2013
@@ -1905,6 +1905,7 @@ public class AmbariManagementControllerI
+ ", roleCommand=" + roleCommand.name());
}
+ // [ type -> [ key, value ] ]
Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String,String>>();
// Do not use host component config mappings. Instead, the rules are:
@@ -1914,30 +1915,34 @@ public class AmbariManagementControllerI
// since we are dealing with host components in this loop, get the
// config mappings for the service this host component applies to
- Service service = cluster.getService(scHost.getServiceName());
- Map<String, Config> configs = service.getDesiredConfigs();
- for (Config svcConfig : configs.values()) {
- // 1) use the cluster desired config
- Config clusterConfig = cluster.getDesiredConfigByType(svcConfig.getType());
-
- if (null == clusterConfig)
- clusterConfig = cluster.getConfig(svcConfig.getType(), svcConfig.getVersionTag());
-
- Map<String, String> props = new HashMap<String,String>(clusterConfig.getProperties());
-
- // 2) apply the service overrides, if any
- props.putAll(svcConfig.getProperties());
+ for (Entry<String, DesiredConfig> entry : cluster.getDesiredConfigs().entrySet()) {
+ String type = entry.getKey();
+ String tag = entry.getValue().getVersion();
+ // 1) start with cluster config
+ Config config = cluster.getConfig(type, tag);
+
+ if (null == config)
+ continue;
+
+ Map<String, String> props = new HashMap<String, String>(config.getProperties());
+
+ // 2) apply the service overrides, if any are defined with different tags
+ Service service = cluster.getService(scHost.getServiceName());
+ Config svcConfig = service.getDesiredConfigs().get(type);
+ if (null != svcConfig && !svcConfig.getVersionTag().equals(tag)) {
+ props.putAll(svcConfig.getProperties());
+ }
// 3) apply the host overrides, if any
Host host = clusters.getHost(scHost.getHostName());
- DesiredConfig dc = host.getDesiredConfigs(scHost.getClusterId()).get(svcConfig.getType());
+ DesiredConfig dc = host.getDesiredConfigs(scHost.getClusterId()).get(type);
if (null != dc) {
Config hostConfig = cluster.getConfig(svcConfig.getType(), dc.getVersion());
props.putAll(hostConfig.getProperties());
}
- configurations.put(svcConfig.getType(), props);
+ configurations.put(type, props);
}
// HACK HACK HACK
@@ -1949,6 +1954,7 @@ public class AmbariManagementControllerI
}
configurations.get("global").put("rca_enabled", "false");
}
+
createHostAction(cluster, stage, scHost, configurations,
roleCommand, requestParameters, event);
}
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1456146&r1=1456145&r2=1456146&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java Wed Mar 13 21:36:16 2013
@@ -30,8 +30,18 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+
+import javax.persistence.EntityManager;
+
import junit.framework.Assert;
-import org.apache.ambari.server.*;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ClusterNotFoundException;
+import org.apache.ambari.server.DuplicateResourceException;
+import org.apache.ambari.server.ParentObjectNotFoundException;
+import org.apache.ambari.server.Role;
+import org.apache.ambari.server.RoleCommand;
+import org.apache.ambari.server.StackAccessException;
import org.apache.ambari.server.actionmanager.ActionDBAccessor;
import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
import org.apache.ambari.server.actionmanager.HostRoleCommand;
@@ -42,7 +52,6 @@ import org.apache.ambari.server.api.serv
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.dao.RoleDAO;
-import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
import org.apache.ambari.server.orm.entities.RoleEntity;
import org.apache.ambari.server.security.authorization.Users;
import org.apache.ambari.server.state.Cluster;
@@ -60,16 +69,15 @@ import org.apache.ambari.server.state.St
import org.apache.ambari.server.state.State;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
import org.apache.ambari.server.utils.StageUtils;
-import org.eclipse.persistence.jpa.JpaEntityManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
-import javax.persistence.EntityManager;
public class AmbariManagementControllerTest {
@@ -3149,16 +3157,18 @@ public class AmbariManagementControllerT
createServiceComponentHost(clusterName, serviceName, componentName3,
host1, null);
createServiceComponentHost(clusterName, serviceName, componentName3,
- host2, null);
-
+ host2, null);
+
Map<String, String> configs = new HashMap<String, String>();
configs.put("a", "b");
configs.put("rca_enabled", "true");
-
- ConfigurationRequest cr1 = new ConfigurationRequest(clusterName, "global",
- "v1", configs);
- controller.createConfiguration(cr1);
-
+
+
+ ClusterRequest cr = new ClusterRequest(null, clusterName, null, null);
+ cr.setDesiredConfig(new ConfigurationRequest(clusterName, "global",
+ "v1", configs));
+ controller.updateCluster(cr);
+
Set<ServiceRequest> sReqs = new HashSet<ServiceRequest>();
Map<String, String> configVersions = new HashMap<String, String>();
configVersions.put("global", "v1");
@@ -3977,24 +3987,24 @@ public class AmbariManagementControllerT
Assert.assertEquals(Role.PIG_SERVICE_CHECK.toString(),
taskStatuses.get(0).getRole());
}
-
-
+
+
@Test
public void testGetStacks() throws Exception {
-
+
StackRequest request = new StackRequest(null);
Set<StackResponse> responses = controller.getStacks(Collections.singleton(request));
Assert.assertEquals(STACKS_CNT, responses.size());
-
+
StackRequest requestWithParams = new StackRequest(STACK_NAME);
Set<StackResponse> responsesWithParams = controller.getStacks(Collections.singleton(requestWithParams));
Assert.assertEquals(1, responsesWithParams.size());
for (StackResponse responseWithParams: responsesWithParams) {
Assert.assertEquals(responseWithParams.getStackName(), STACK_NAME);
-
+
}
-
+
StackRequest invalidRequest = new StackRequest(NON_EXT_VALUE);
try {
controller.getStacks(Collections.singleton(invalidRequest));
@@ -4002,47 +4012,47 @@ public class AmbariManagementControllerT
Assert.assertTrue(e instanceof StackAccessException);
}
}
-
+
@Test
public void testGetStackVersions() throws Exception {
-
+
StackVersionRequest request = new StackVersionRequest(STACK_NAME, null);
Set<StackVersionResponse> responses = controller.getStackVersions(Collections.singleton(request));
Assert.assertEquals(STACK_VERSIONS_CNT, responses.size());
-
+
StackVersionRequest requestWithParams = new StackVersionRequest(STACK_NAME, STACK_VERSION);
Set<StackVersionResponse> responsesWithParams = controller.getStackVersions(Collections.singleton(requestWithParams));
Assert.assertEquals(1, responsesWithParams.size());
for (StackVersionResponse responseWithParams: responsesWithParams) {
Assert.assertEquals(responseWithParams.getStackVersion(), STACK_VERSION);
-
+
}
-
+
StackVersionRequest invalidRequest = new StackVersionRequest(STACK_NAME, NON_EXT_VALUE);
try {
controller.getStackVersions(Collections.singleton(invalidRequest));
} catch (StackAccessException e) {
Assert.assertTrue(e instanceof StackAccessException);
- }
+ }
}
-
+
@Test
public void testGetRepositories() throws Exception {
-
+
RepositoryRequest request = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, null);
Set<RepositoryResponse> responses = controller.getRepositories(Collections.singleton(request));
Assert.assertEquals(REPOS_CNT, responses.size());
-
+
RepositoryRequest requestWithParams = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, REPO_ID);
Set<RepositoryResponse> responsesWithParams = controller.getRepositories(Collections.singleton(requestWithParams));
Assert.assertEquals(1, responsesWithParams.size());
for (RepositoryResponse responseWithParams: responsesWithParams) {
Assert.assertEquals(responseWithParams.getRepoId(), REPO_ID);
-
+
}
-
+
RepositoryRequest invalidRequest = new RepositoryRequest(STACK_NAME, STACK_VERSION, OS_TYPE, NON_EXT_VALUE);
try {
controller.getRepositories(Collections.singleton(invalidRequest));
@@ -4050,52 +4060,52 @@ public class AmbariManagementControllerT
Assert.assertTrue(e instanceof StackAccessException);
}
}
-
-
+
+
@Test
public void testGetStackServices() throws Exception {
-
+
StackServiceRequest request = new StackServiceRequest(STACK_NAME, STACK_VERSION, null);
Set<StackServiceResponse> responses = controller.getStackServices(Collections.singleton(request));
Assert.assertEquals(STACK_SERVICES_CNT, responses.size());
-
-
+
+
StackServiceRequest requestWithParams = new StackServiceRequest(STACK_NAME, STACK_VERSION, SERVICE_NAME);
Set<StackServiceResponse> responsesWithParams = controller.getStackServices(Collections.singleton(requestWithParams));
Assert.assertEquals(1, responsesWithParams.size());
for (StackServiceResponse responseWithParams: responsesWithParams) {
Assert.assertEquals(responseWithParams.getServiceName(), SERVICE_NAME);
-
+
}
-
+
StackServiceRequest invalidRequest = new StackServiceRequest(STACK_NAME, STACK_VERSION, NON_EXT_VALUE);
try {
controller.getStackServices(Collections.singleton(invalidRequest));
} catch (StackAccessException e) {
Assert.assertTrue(e instanceof StackAccessException);
}
-
-
+
+
}
-
+
@Test
public void testGetStackConfigurations() throws Exception {
-
+
StackConfigurationRequest request = new StackConfigurationRequest(STACK_NAME, STACK_VERSION, SERVICE_NAME, null);
Set<StackConfigurationResponse> responses = controller.getStackConfigurations(Collections.singleton(request));
Assert.assertEquals(STACK_PROPERTIES_CNT, responses.size());
-
-
+
+
StackConfigurationRequest requestWithParams = new StackConfigurationRequest(STACK_NAME, STACK_VERSION, SERVICE_NAME, PROPERTY_NAME);
Set<StackConfigurationResponse> responsesWithParams = controller.getStackConfigurations(Collections.singleton(requestWithParams));
Assert.assertEquals(1, responsesWithParams.size());
for (StackConfigurationResponse responseWithParams: responsesWithParams) {
Assert.assertEquals(responseWithParams.getPropertyName(), PROPERTY_NAME);
-
+
}
-
+
StackConfigurationRequest invalidRequest = new StackConfigurationRequest(STACK_NAME, STACK_VERSION, SERVICE_NAME, NON_EXT_VALUE);
try {
controller.getStackConfigurations(Collections.singleton(invalidRequest));
@@ -4103,60 +4113,60 @@ public class AmbariManagementControllerT
Assert.assertTrue(e instanceof StackAccessException);
}
}
-
-
+
+
@Test
public void testGetStackComponents() throws Exception {
-
+
StackServiceComponentRequest request = new StackServiceComponentRequest(STACK_NAME, STACK_VERSION, SERVICE_NAME, null);
Set<StackServiceComponentResponse> responses = controller.getStackComponents(Collections.singleton(request));
Assert.assertEquals(STACK_COMPONENTS_CNT, responses.size());
-
-
+
+
StackServiceComponentRequest requestWithParams = new StackServiceComponentRequest(STACK_NAME, STACK_VERSION, SERVICE_NAME, COMPONENT_NAME);
Set<StackServiceComponentResponse> responsesWithParams = controller.getStackComponents(Collections.singleton(requestWithParams));
Assert.assertEquals(1, responsesWithParams.size());
for (StackServiceComponentResponse responseWithParams: responsesWithParams) {
Assert.assertEquals(responseWithParams.getComponentName(), COMPONENT_NAME);
-
+
}
-
+
StackServiceComponentRequest invalidRequest = new StackServiceComponentRequest(STACK_NAME, STACK_VERSION, SERVICE_NAME, NON_EXT_VALUE);
try {
controller.getStackComponents(Collections.singleton(invalidRequest));
} catch (StackAccessException e) {
Assert.assertTrue(e instanceof StackAccessException);
}
-
-
+
+
}
-
+
@Test
public void testGetStackOperatingSystems() throws Exception {
-
+
OperatingSystemRequest request = new OperatingSystemRequest(STACK_NAME, STACK_VERSION, null);
Set<OperatingSystemResponse> responses = controller.getStackOperatingSystems(Collections.singleton(request));
Assert.assertEquals(OS_CNT, responses.size());
-
-
+
+
OperatingSystemRequest requestWithParams = new OperatingSystemRequest(STACK_NAME, STACK_VERSION, OS_TYPE);
Set<OperatingSystemResponse> responsesWithParams = controller.getStackOperatingSystems(Collections.singleton(requestWithParams));
Assert.assertEquals(1, responsesWithParams.size());
for (OperatingSystemResponse responseWithParams: responsesWithParams) {
Assert.assertEquals(responseWithParams.getOsType(), OS_TYPE);
-
+
}
-
+
OperatingSystemRequest invalidRequest = new OperatingSystemRequest(STACK_NAME, STACK_VERSION, NON_EXT_VALUE);
try {
controller.getStackOperatingSystems(Collections.singleton(invalidRequest));
} catch (StackAccessException e) {
Assert.assertTrue(e instanceof StackAccessException);
}
-
-
+
+
}
@Test