You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2014/09/06 01:18:05 UTC
git commit: AMBARI-4671. Support changing the cluster name of an
existing hadoop cluster. (mahadev)
Repository: ambari
Updated Branches:
refs/heads/trunk a6e5c8b3c -> bc54512cf
AMBARI-4671. Support changing the cluster name of an existing hadoop cluster. (mahadev)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bc54512c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bc54512c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bc54512c
Branch: refs/heads/trunk
Commit: bc54512cf289dafabfde4a7dbe769447f3eee7e6
Parents: a6e5c8b
Author: Mahadev Konar <ma...@apache.org>
Authored: Fri Sep 5 16:17:10 2014 -0700
Committer: Mahadev Konar <ma...@apache.org>
Committed: Fri Sep 5 16:17:14 2014 -0700
----------------------------------------------------------------------
.../AmbariManagementControllerImpl.java | 24 ++++--
.../AmbariManagementControllerImplTest.java | 86 ++++++++++++++++++++
2 files changed, 105 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/bc54512c/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index e53433d..99552e5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -1144,17 +1144,23 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
private synchronized RequestStatusResponse updateCluster(ClusterRequest request)
throws AmbariException {
- if (request.getClusterName() == null
- || request.getClusterName().isEmpty()) {
- throw new IllegalArgumentException("Invalid arguments, cluster name"
- + " should not be null");
+ if (request.getClusterId() == null
+ && (request.getClusterName() == null
+ || request.getClusterName().isEmpty())) {
+ throw new IllegalArgumentException("Invalid arguments, cluster id or cluster name should not be null");
}
LOG.info("Received a updateCluster request"
+ + ", clusterId=" + request.getClusterId()
+ ", clusterName=" + request.getClusterName()
+ ", request=" + request);
- final Cluster cluster = clusters.getCluster(request.getClusterName());
+ final Cluster cluster;
+ if (request.getClusterId() == null) {
+ cluster = clusters.getCluster(request.getClusterName());
+ } else {
+ cluster = clusters.getClusterById(request.getClusterId());
+ }
//save data to return configurations created
List<ConfigurationResponse> configurationResponses =
new LinkedList<ConfigurationResponse>();
@@ -1166,6 +1172,14 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
throw new IllegalArgumentException(msg);
}
+ // set the new name of the cluster if change is requested
+ if (!cluster.getClusterName().equals(request.getClusterName())) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Received cluster name change request from " + cluster.getClusterName() + " to " + request.getClusterName());
+ }
+ cluster.setClusterName(request.getClusterName());
+ }
+
// set or create configuration mapping (and optionally create the map of properties)
if (null != request.getDesiredConfig()) {
Set<Config> configs = new HashSet<Config>();
http://git-wip-us.apache.org/repos/asf/ambari/blob/bc54512c/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index 1d7bc7f..ecc2c0d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -26,6 +26,7 @@ import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.expectLastCall;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -65,6 +66,7 @@ import org.apache.ambari.server.state.ServiceComponentHost;
import org.apache.ambari.server.state.StackId;
import org.apache.ambari.server.state.ServiceOsSpecific;
import org.apache.ambari.server.state.ServiceInfo;
+import javax.persistence.RollbackException;
import org.easymock.Capture;
import org.junit.Test;
@@ -281,6 +283,90 @@ public class AmbariManagementControllerImplTest {
verify(injector, clusters, cluster, cluster2, response, response2);
}
+ /**
+ * Ensure that when the cluster id is provided and the given cluster name is different from the cluster's name
+ * then the cluster rename logic is executed.
+ */
+ @Test
+ public void testUpdateClusters() throws Exception {
+ // member state mocks
+ Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+ Injector injector = createStrictMock(Injector.class);
+ Cluster cluster = createNiceMock(Cluster.class);
+ ActionManager actionManager = createNiceMock(ActionManager.class);
+ Clusters clusters = createNiceMock(Clusters.class);
+ ClusterRequest clusterRequest = createNiceMock(ClusterRequest.class);
+
+ // requests
+ Set<ClusterRequest> setRequests = Collections.singleton(clusterRequest);
+
+ // expectations
+ injector.injectMembers(capture(controllerCapture));
+ expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null);
+ expect(clusterRequest.getClusterName()).andReturn("clusterNew").times(4);
+ expect(clusterRequest.getClusterId()).andReturn(1L).times(4);
+ expect(clusters.getClusterById(1L)).andReturn(cluster);
+ expect(cluster.getClusterName()).andReturn("clusterOld").times(2);
+ cluster.setClusterName("clusterNew");
+ expectLastCall();
+
+ // replay mocks
+ replay(actionManager, cluster, clusters, injector, clusterRequest);
+
+ // test
+ AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector);
+ controller.updateClusters(setRequests, null);
+
+ // assert and verify
+ assertSame(controller, controllerCapture.getValue());
+ verify(actionManager, cluster, clusters, injector, clusterRequest);
+ }
+
+ /**
+ * Ensure that RollbackException is thrown outside the updateClusters method
+ * when a unique constraint violation occurs.
+ */
+ @Test
+ public void testUpdateClusters__RollbackException() throws Exception {
+ // member state mocks
+ Capture<AmbariManagementController> controllerCapture = new Capture<AmbariManagementController>();
+ Injector injector = createStrictMock(Injector.class);
+ Cluster cluster = createNiceMock(Cluster.class);
+ ActionManager actionManager = createNiceMock(ActionManager.class);
+ Clusters clusters = createNiceMock(Clusters.class);
+ ClusterRequest clusterRequest = createNiceMock(ClusterRequest.class);
+
+ // requests
+ Set<ClusterRequest> setRequests = Collections.singleton(clusterRequest);
+
+ // expectations
+ injector.injectMembers(capture(controllerCapture));
+ expect(injector.getInstance(Gson.class)).andReturn(null);
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null);
+ expect(clusterRequest.getClusterName()).andReturn("clusterNew").times(4);
+ expect(clusterRequest.getClusterId()).andReturn(1L).times(4);
+ expect(clusters.getClusterById(1L)).andReturn(cluster);
+ expect(cluster.getClusterName()).andReturn("clusterOld").times(2);
+ cluster.setClusterName("clusterNew");
+ expectLastCall().andThrow(new RollbackException());
+
+ // replay mocks
+ replay(actionManager, cluster, clusters, injector, clusterRequest);
+
+ // test
+ AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector);
+ try {
+ controller.updateClusters(setRequests, null);
+ fail("Expected RollbackException");
+ } catch (RollbackException e) {
+ //expected
+ }
+ // assert and verify
+ assertSame(controller, controllerCapture.getValue());
+ verify(actionManager, cluster, clusters, injector, clusterRequest);
+ }
+
@Test
public void testGetHostComponents() throws Exception {
// member state mocks