You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2018/01/25 21:49:09 UTC
[18/50] [abbrv] helix git commit: REST API support cluster
maintenance mode enable disable
REST API support cluster maintenance mode enable disable
Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/3cfe7850
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/3cfe7850
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/3cfe7850
Branch: refs/heads/master
Commit: 3cfe7850dee324a531caeb2e5a8852ce13879aeb
Parents: ae53705
Author: Junkai Xue <jx...@linkedin.com>
Authored: Wed Nov 15 13:09:39 2017 -0800
Committer: Junkai Xue <jx...@linkedin.com>
Committed: Wed Jan 24 18:31:37 2018 -0800
----------------------------------------------------------------------
.../rest/server/resources/AbstractResource.java | 2 ++
.../rest/server/resources/ClusterAccessor.java | 24 ++++++++++++++++++--
.../helix/rest/server/TestClusterAccessor.java | 21 +++++++++++++++++
3 files changed, 45 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/helix/blob/3cfe7850/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
----------------------------------------------------------------------
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
index d800eb0..50f6f08 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/AbstractResource.java
@@ -65,6 +65,8 @@ public class AbstractResource {
expand,
enable,
disable,
+ enableMaintenanceMode,
+ disableMaintenanceMode,
update,
delete,
rebalance,
http://git-wip-us.apache.org/repos/asf/helix/blob/3cfe7850/helix-rest/src/main/java/org/apache/helix/rest/server/resources/ClusterAccessor.java
----------------------------------------------------------------------
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/ClusterAccessor.java b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/ClusterAccessor.java
index 6e90400..1c998b7 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/ClusterAccessor.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/ClusterAccessor.java
@@ -62,6 +62,7 @@ public class ClusterAccessor extends AbstractResource {
liveInstances,
resources,
paused,
+ maintenance,
messages,
stateModelDefinitions,
clusters
@@ -100,6 +101,9 @@ public class ClusterAccessor extends AbstractResource {
boolean paused = (dataAccessor.getProperty(keyBuilder.pause()) == null ? false : true);
clusterInfo.put(ClusterProperties.paused.name(), paused);
+ boolean maintenance =
+ (dataAccessor.getProperty(keyBuilder.maintenance()) == null ? false : true);
+ clusterInfo.put(ClusterProperties.maintenance.name(), maintenance);
List<String> idealStates = dataAccessor.getChildNames(keyBuilder.idealStates());
clusterInfo.put(ClusterProperties.resources.name(), idealStates);
@@ -151,7 +155,8 @@ public class ClusterAccessor extends AbstractResource {
@POST
@Path("{clusterId}")
public Response updateCluster(@PathParam("clusterId") String clusterId,
- @QueryParam("command") String commandStr, @QueryParam("superCluster") String superCluster) {
+ @QueryParam("command") String commandStr, @QueryParam("superCluster") String superCluster,
+ String content) {
Command command;
try {
command = getCommand(commandStr);
@@ -201,7 +206,22 @@ public class ClusterAccessor extends AbstractResource {
return serverError(ex);
}
break;
-
+ case enableMaintenanceMode:
+ try {
+ helixAdmin.enableMaintenanceMode(clusterId, true, content);
+ } catch (Exception ex) {
+ _logger.error("Failed to enable maintenance mode " + clusterId);
+ return serverError(ex);
+ }
+ break;
+ case disableMaintenanceMode:
+ try {
+ helixAdmin.enableMaintenanceMode(clusterId, false);
+ } catch (Exception ex) {
+ _logger.error("Failed to disable maintenance mode " + clusterId);
+ return serverError(ex);
+ }
+ break;
default:
return badRequest("Unsupported command " + command);
}
http://git-wip-us.apache.org/repos/asf/helix/blob/3cfe7850/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
----------------------------------------------------------------------
diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
index 95d1951..b48c01b 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestClusterAccessor.java
@@ -31,11 +31,14 @@ import java.util.Set;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.apache.helix.HelixDataAccessor;
import org.apache.helix.PropertyKey;
import org.apache.helix.TestHelper;
import org.apache.helix.ZNRecord;
+import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZKUtil;
import org.apache.helix.model.ClusterConfig;
+import org.apache.helix.model.MaintenanceSignal;
import org.apache.helix.rest.server.auditlog.AuditLog;
import org.apache.helix.rest.server.resources.AbstractResource.Command;
import org.apache.helix.rest.server.resources.ClusterAccessor;
@@ -236,6 +239,24 @@ public class TestClusterAccessor extends AbstractTestClass {
getClusterConfigFromRest(cluster);
}
+ @Test(dependsOnMethods = "testGetClusterConfig")
+ public void testEnableDisableMaintenanceMode() {
+ System.out.println("Start test :" + TestHelper.getTestMethodName());
+ String cluster = _clusters.iterator().next();
+ String reason = "Test reason";
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(cluster, _baseAccessor);
+ post("clusters/" + cluster, ImmutableMap.of("command", "enableMaintenanceMode"),
+ Entity.entity(reason, MediaType.APPLICATION_JSON_TYPE),
+ Response.Status.OK.getStatusCode());
+ MaintenanceSignal signal = accessor.getProperty(accessor.keyBuilder().maintenance());
+ Assert.assertNotNull(signal);
+ Assert.assertEquals(reason, signal.getReason());
+ post("clusters/" + cluster, ImmutableMap.of("command", "disableMaintenanceMode"),
+ Entity.entity(new String(), MediaType.APPLICATION_JSON_TYPE),
+ Response.Status.OK.getStatusCode());
+ Assert.assertNull(accessor.getProperty(accessor.keyBuilder().maintenance()));
+ }
+
private ClusterConfig getClusterConfigFromRest(String cluster) throws IOException {
String body = get("clusters/" + cluster + "/configs", Response.Status.OK.getStatusCode(), true);