Skip to content
Permalink
Browse files
Implement deactivate rest API (#1988)
Implement deactivate REST API
Added a new REST API for deactivating cluster from supercluster.
  • Loading branch information
qqu0127 committed Mar 24, 2022
1 parent 86e9881 commit 1e5aa3cf53f55c3d79b5b59f44a7efadd4b5d14a
Showing 5 changed files with 35 additions and 2 deletions.
@@ -1255,6 +1255,9 @@ public void addStateModelDef(String clusterName, String stateModelDef,
@Override
public void dropResource(String clusterName, String resourceName) {
logger.info("Drop resource {} from cluster {}", resourceName, clusterName);
if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
throw new HelixException("Cluster " + clusterName + " is not setup yet");
}
HelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
@@ -297,8 +297,10 @@ public void testMsgTriggeredRebalance() throws Exception {
@Test
public void testChangeIdealStateWithPendingMsg() throws Exception {
String clusterName = "CLUSTER_" + _className + "_pending";
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);

System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
admin.addCluster(clusterName);
HelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<>(_gZkClient));
HelixManager manager =
@@ -356,7 +358,6 @@ public void testChangeIdealStateWithPendingMsg() throws Exception {

// round2: drop resource, but keep the
// message, make sure controller should not send O->DROPPED until O->S is done
HelixAdmin admin = new ZKHelixAdmin(_gZkClient);
admin.dropResource(clusterName, resourceName);
List<IdealState> idealStates = accessor.getChildValues(accessor.keyBuilder().idealStates(), true);
cache.setIdealStates(idealStates);
@@ -58,6 +58,7 @@ public enum Properties {

public enum Command {
activate,
deactivate,
addInstanceTag,
addVirtualTopologyGroup,
expand,
@@ -243,6 +243,18 @@ public Response updateCluster(@PathParam("clusterId") String clusterId,
}
break;

case deactivate:
if (superCluster == null) {
return badRequest("Super Cluster name is missing!");
}
try {
clusterSetup.activateCluster(clusterId, superCluster, false);
} catch (Exception ex) {
LOG.error("Failed to deactivate cluster {} from super cluster {}.", clusterId, superCluster);
return serverError(ex);
}
break;

case addVirtualTopologyGroup:
try {
addVirtualTopologyGroup(clusterId, content);
@@ -781,6 +781,22 @@ public void testActivateSuperCluster() throws Exception {
LiveInstance leader = normalAccessor.getProperty(normKeyBuilder.controllerLeader());
Assert.assertEquals(leader.getId(), superClusterleader);

// deactivate cluster ACTIVATE_NORM_CLUSTER from super cluster ACTIVATE_SUPER_CLUSTER
post("clusters/" + ACTIVATE_NORM_CLUSTER,
ImmutableMap.of("command", "deactivate", "superCluster", ACTIVATE_SUPER_CLUSTER),
Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.OK .getStatusCode());
idealState = accessor.getProperty(keyBuilder.idealStates(ACTIVATE_NORM_CLUSTER));
Assert.assertNull(idealState);

post("clusters/" + ACTIVATE_NORM_CLUSTER,
ImmutableMap.of("command", "activate", "superCluster", ACTIVATE_SUPER_CLUSTER),
Entity.entity("", MediaType.APPLICATION_JSON_TYPE), Response.Status.OK .getStatusCode());
idealState = accessor.getProperty(keyBuilder.idealStates(ACTIVATE_NORM_CLUSTER));
Assert.assertNotNull(idealState);
Assert.assertEquals(idealState.getRebalanceMode(), IdealState.RebalanceMode.FULL_AUTO);
Assert.assertEquals(idealState.getRebalancerClassName(), WagedRebalancer.class.getName());
Assert.assertEquals(idealState.getReplicas(), "3");

// clean up by tearing down controllers and delete clusters
for (ClusterDistributedController dc: clusterDistributedControllers) {
if (dc != null && dc.isConnected()) {

0 comments on commit 1e5aa3c

Please sign in to comment.