Author: mahadev
Date: Mon Jan 21 19:12:05 2013
New Revision: 1436557
URL: http://svn.apache.org/viewvc?rev=1436557&view=rev
Log:
AMBARI-1205. Cannot persist service configuration when service is started
(Siddharth Wagle via mahadev)
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=1436557&r1=1436556&r2=1436557&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Mon Jan 21 19:12:05 2013
@@ -85,6 +85,9 @@ Trunk (unreleased changes):
AMBARI-1206. Expose missing metrics on host components. (tbeerbower via
mahadev)
+ AMBARI-1205. Cannot persist service configuration when service is started
+ (Siddharth Wagle via mahadev)
+
BUG FIXES
AMBARI-1230. There is a big gap in the lower part of the Jobs table header.
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=1436557&r1=1436556&r2=1436557&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
Mon Jan 21 19:12:05 2013
@@ -1811,17 +1811,6 @@ public class AmbariManagementControllerI
ServiceComponentHost sch,
State currentState, State newDesiredState)
throws AmbariException {
- if (currentState == State.STARTED
- || currentState == State.STARTING) {
- throw new AmbariException("Changing of configs not supported"
- + " in STARTING or STARTED state"
- + ", clusterName=" + sch.getClusterName()
- + ", serviceName=" + sch.getServiceName()
- + ", componentName=" + sch.getServiceComponentName()
- + ", hostname=" + sch.getHostName()
- + ", currentState=" + currentState
- + ", newDesiredState=" + newDesiredState);
- }
if (newDesiredState != null) {
if (!(newDesiredState == State.INIT
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=1436557&r1=1436556&r2=1436557&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
Mon Jan 21 19:12:05 2013
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEqu
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -66,6 +67,8 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
+import javax.xml.bind.JAXBException;
+
public class AmbariManagementControllerTest {
private static final Logger LOG =
@@ -3157,6 +3160,294 @@ public class AmbariManagementControllerT
}
@Test
+ public void testUpdateConfigForRunningService() throws Exception {
+ String clusterName = "foo1";
+ createCluster(clusterName);
+ clusters.getCluster(clusterName)
+ .setDesiredStackVersion(new StackId("HDP-0.1"));
+ String serviceName = "HDFS";
+ createService(clusterName, serviceName, null);
+ String componentName1 = "NAMENODE";
+ String componentName2 = "DATANODE";
+ String componentName3 = "HDFS_CLIENT";
+ createServiceComponent(clusterName, serviceName, componentName1,
+ State.INIT);
+ createServiceComponent(clusterName, serviceName, componentName2,
+ State.INIT);
+ createServiceComponent(clusterName, serviceName, componentName3,
+ State.INIT);
+
+ String host1 = "h1";
+ clusters.addHost(host1);
+ clusters.getHost("h1").setOsType("centos5");
+ clusters.getHost("h1").persist();
+ String host2 = "h2";
+ clusters.addHost(host2);
+ clusters.getHost("h2").setOsType("centos6");
+ clusters.getHost("h2").persist();
+
+ clusters.mapHostToCluster(host1, clusterName);
+ clusters.mapHostToCluster(host2, clusterName);
+
+
+ // null service should work
+ createServiceComponentHost(clusterName, null, componentName1,
+ host1, null);
+ createServiceComponentHost(clusterName, serviceName, componentName2,
+ host1, null);
+ createServiceComponentHost(clusterName, serviceName, componentName2,
+ host2, null);
+ createServiceComponentHost(clusterName, serviceName, componentName3,
+ host1, null);
+ createServiceComponentHost(clusterName, serviceName, componentName3,
+ host2, null);
+
+ Assert.assertNotNull(clusters.getCluster(clusterName)
+ .getService(serviceName)
+ .getServiceComponent(componentName1)
+ .getServiceComponentHost(host1));
+ Assert.assertNotNull(clusters.getCluster(clusterName)
+ .getService(serviceName)
+ .getServiceComponent(componentName2)
+ .getServiceComponentHost(host1));
+ Assert.assertNotNull(clusters.getCluster(clusterName)
+ .getService(serviceName)
+ .getServiceComponent(componentName2)
+ .getServiceComponentHost(host2));
+ Assert.assertNotNull(clusters.getCluster(clusterName)
+ .getService(serviceName)
+ .getServiceComponent(componentName3)
+ .getServiceComponentHost(host1));
+ Assert.assertNotNull(clusters.getCluster(clusterName)
+ .getService(serviceName)
+ .getServiceComponent(componentName3)
+ .getServiceComponentHost(host2));
+
+ // Install
+ ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
+ State.INSTALLED.toString());
+ Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
+ requests.add(r);
+
+ RequestStatusResponse trackAction =
+ controller.updateServices(requests);
+ Assert.assertEquals(State.INSTALLED,
+ clusters.getCluster(clusterName).getService(serviceName)
+ .getDesiredState());
+
+ // manually change live state to installed as no running action manager
+ for (ServiceComponent sc :
+ clusters.getCluster(clusterName).getService(serviceName)
+ .getServiceComponents().values()) {
+ for (ServiceComponentHost sch :
sc.getServiceComponentHosts().values()) {
+ sch.setState(State.INSTALLED);
+ }
+ }
+
+ // Start
+ r = new ServiceRequest(clusterName, serviceName, null,
+ State.STARTED.toString());
+ requests.clear();
+ requests.add(r);
+ trackAction = controller.updateServices(requests);
+
+ // manually change live state to started as no running action manager
+ for (ServiceComponent sc :
+ clusters.getCluster(clusterName).getService(serviceName)
+ .getServiceComponents().values()) {
+ for (ServiceComponentHost sch :
sc.getServiceComponentHosts().values()) {
+ sch.setState(State.STARTED);
+ }
+ }
+
+ Assert.assertEquals(State.STARTED,
+ clusters.getCluster(clusterName).getService(serviceName)
+ .getDesiredState());
+ for (ServiceComponent sc :
+ clusters.getCluster(clusterName).getService(serviceName)
+ .getServiceComponents().values()) {
+ if (sc.getName().equals("HDFS_CLIENT")) {
+ Assert.assertEquals(State.INSTALLED, sc.getDesiredState());
+ } else {
+ Assert.assertEquals(State.STARTED, sc.getDesiredState());
+ }
+ for (ServiceComponentHost sch :
sc.getServiceComponentHosts().values()) {
+ if (sch.getServiceComponentName().equals("HDFS_CLIENT")) {
+ Assert.assertEquals(State.INSTALLED, sch.getDesiredState());
+ } else {
+ Assert.assertEquals(State.STARTED, sch.getDesiredState());
+ }
+ }
+ }
+
+ Map<String, String> configs = new HashMap<String, String>();
+ configs.put("a", "b");
+
+ ConfigurationRequest cr1, cr2, cr3, cr4, cr5, cr6, cr7, cr8;
+ cr1 = new ConfigurationRequest(clusterName, "typeA","v1", configs);
+ cr2 = new ConfigurationRequest(clusterName, "typeB","v1", configs);
+ cr3 = new ConfigurationRequest(clusterName, "typeC","v1", configs);
+ cr4 = new ConfigurationRequest(clusterName, "typeD","v1", configs);
+ cr5 = new ConfigurationRequest(clusterName, "typeA","v2", configs);
+ cr6 = new ConfigurationRequest(clusterName, "typeB","v2", configs);
+ cr7 = new ConfigurationRequest(clusterName, "typeC","v2", configs);
+ cr8 = new ConfigurationRequest(clusterName, "typeE","v1", configs);
+ controller.createConfiguration(cr1);
+ controller.createConfiguration(cr2);
+ controller.createConfiguration(cr3);
+ controller.createConfiguration(cr4);
+ controller.createConfiguration(cr5);
+ controller.createConfiguration(cr6);
+ controller.createConfiguration(cr7);
+ controller.createConfiguration(cr8);
+
+ Cluster cluster = clusters.getCluster(clusterName);
+ Service s = cluster.getService(serviceName);
+ ServiceComponent sc1 = s.getServiceComponent(componentName1);
+ ServiceComponent sc2 = s.getServiceComponent(componentName2);
+ ServiceComponentHost sch1 = sc1.getServiceComponentHost(host1);
+
+ Set<ServiceComponentHostRequest> schReqs =
+ new HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentRequest> scReqs =
+ new HashSet<ServiceComponentRequest>();
+ Set<ServiceRequest> sReqs = new HashSet<ServiceRequest>();
+ Map<String, String> configVersions = new HashMap<String, String>();
+
+ // update configs at SCH and SC level
+ configVersions.clear();
+ configVersions.put("typeA", "v1");
+ configVersions.put("typeB", "v1");
+ configVersions.put("typeC", "v1");
+ schReqs.clear();
+ schReqs.add(new ServiceComponentHostRequest(clusterName, serviceName,
+ componentName1, host1, configVersions, null));
+ Assert.assertNull(controller.updateHostComponents(schReqs));
+
+ Assert.assertEquals(0, s.getDesiredConfigs().size());
+ Assert.assertEquals(0, sc1.getDesiredConfigs().size());
+ Assert.assertEquals(3, sch1.getDesiredConfigs().size());
+
+ configVersions.clear();
+ configVersions.put("typeC", "v1");
+ configVersions.put("typeD", "v1");
+ scReqs.clear();
+ scReqs.add(new ServiceComponentRequest(clusterName, serviceName,
+ componentName2, configVersions, null));
+ Assert.assertNull(controller.updateComponents(scReqs));
+
+ Assert.assertEquals(0, s.getDesiredConfigs().size());
+ Assert.assertEquals(0, sc1.getDesiredConfigs().size());
+ Assert.assertEquals(2, sc2.getDesiredConfigs().size());
+ Assert.assertEquals(3, sch1.getDesiredConfigs().size());
+
+ // update configs at service level
+ configVersions.clear();
+ configVersions.put("typeA", "v2");
+ configVersions.put("typeC", "v2");
+ configVersions.put("typeE", "v1");
+ sReqs.clear();
+ sReqs.add(new ServiceRequest(clusterName, serviceName, configVersions,
+ null));
+ Assert.assertNull(controller.updateServices(sReqs));
+
+ Assert.assertEquals(3, s.getDesiredConfigs().size());
+ Assert.assertEquals(3, sc1.getDesiredConfigs().size());
+ Assert.assertEquals(4, sc2.getDesiredConfigs().size());
+ Assert.assertEquals(4, sch1.getDesiredConfigs().size());
+
+ Assert.assertEquals("v2",
+ s.getDesiredConfigs().get("typeA").getVersionTag());
+ Assert.assertEquals("v2",
+ s.getDesiredConfigs().get("typeC").getVersionTag());
+ Assert.assertEquals("v1",
+ s.getDesiredConfigs().get("typeE").getVersionTag());
+
+ Assert.assertEquals("v2",
+ sc1.getDesiredConfigs().get("typeA").getVersionTag());
+ Assert.assertEquals("v2",
+ sc1.getDesiredConfigs().get("typeC").getVersionTag());
+ Assert.assertEquals("v1",
+ sc1.getDesiredConfigs().get("typeE").getVersionTag());
+
+ Assert.assertEquals("v2",
+ sc2.getDesiredConfigs().get("typeA").getVersionTag());
+ Assert.assertEquals("v2",
+ sc2.getDesiredConfigs().get("typeC").getVersionTag());
+ Assert.assertEquals("v1",
+ sc2.getDesiredConfigs().get("typeE").getVersionTag());
+ Assert.assertEquals("v1",
+ sc2.getDesiredConfigs().get("typeD").getVersionTag());
+
+ Assert.assertEquals("v2",
+ sch1.getDesiredConfigs().get("typeA").getVersionTag());
+ Assert.assertEquals("v2",
+ sch1.getDesiredConfigs().get("typeC").getVersionTag());
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeE").getVersionTag());
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeB").getVersionTag());
+
+ // update configs at SCH level
+ configVersions.clear();
+ configVersions.put("typeA", "v1");
+ configVersions.put("typeB", "v1");
+ configVersions.put("typeC", "v1");
+ schReqs.clear();
+ schReqs.add(new ServiceComponentHostRequest(clusterName, serviceName,
+ componentName1, host1, configVersions, null));
+ Assert.assertNull(controller.updateHostComponents(schReqs));
+
+ Assert.assertEquals(3, s.getDesiredConfigs().size());
+ Assert.assertEquals(3, sc1.getDesiredConfigs().size());
+ Assert.assertEquals(4, sc2.getDesiredConfigs().size());
+ Assert.assertEquals(4, sch1.getDesiredConfigs().size());
+
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeA").getVersionTag());
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeC").getVersionTag());
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeE").getVersionTag());
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeB").getVersionTag());
+
+ // update configs at SC level
+ configVersions.clear();
+ configVersions.put("typeC", "v2");
+ configVersions.put("typeD", "v1");
+ scReqs.clear();
+ scReqs.add(new ServiceComponentRequest(clusterName, serviceName,
+ componentName1, configVersions, null));
+ Assert.assertNull(controller.updateComponents(scReqs));
+
+ Assert.assertEquals(3, s.getDesiredConfigs().size());
+ Assert.assertEquals(4, sc1.getDesiredConfigs().size());
+ Assert.assertEquals(4, sc2.getDesiredConfigs().size());
+ Assert.assertEquals(5, sch1.getDesiredConfigs().size());
+
+ Assert.assertEquals("v2",
+ sc1.getDesiredConfigs().get("typeA").getVersionTag());
+ Assert.assertEquals("v2",
+ sc1.getDesiredConfigs().get("typeC").getVersionTag());
+ Assert.assertEquals("v1",
+ sc2.getDesiredConfigs().get("typeD").getVersionTag());
+ Assert.assertEquals("v1",
+ sc1.getDesiredConfigs().get("typeE").getVersionTag());
+
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeA").getVersionTag());
+ Assert.assertEquals("v2",
+ sch1.getDesiredConfigs().get("typeC").getVersionTag());
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeD").getVersionTag());
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeE").getVersionTag());
+ Assert.assertEquals("v1",
+ sch1.getDesiredConfigs().get("typeB").getVersionTag());
+ }
+
+ @Test
public void testConfigUpdates() throws AmbariException {
String clusterName = "foo1";
createCluster(clusterName);