helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject helix git commit: [HELIX-691] Allow users to update InstanceConfig
Date Mon, 09 Apr 2018 19:33:18 GMT
Repository: helix
Updated Branches:
  refs/heads/master 477264e72 -> 72d524847


[HELIX-691] Allow users to update InstanceConfig

In helix-rest, we provide a method in InstanceAccessor, updateInstanceConfig, that updates
the instance's config through a POST call.


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/72d52484
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/72d52484
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/72d52484

Branch: refs/heads/master
Commit: 72d52484716bf2f90323f141a478893fdd0843f1
Parents: 477264e
Author: narendly <narendly@gmail.com>
Authored: Mon Apr 9 12:04:26 2018 -0700
Committer: narendly <narendly@gmail.com>
Committed: Mon Apr 9 12:04:26 2018 -0700

----------------------------------------------------------------------
 .../java/org/apache/helix/ConfigAccessor.java   |  2 +-
 .../apache/helix/manager/zk/ZKHelixAdmin.java   |  2 --
 .../org/apache/helix/manager/zk/ZKUtil.java     |  1 -
 .../resources/helix/InstanceAccessor.java       | 16 +++++----
 .../resources/helix/ResourceAccessor.java       | 36 +++++++++-----------
 .../helix/rest/server/TestInstanceAccessor.java |  2 +-
 6 files changed, 28 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/72d52484/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java b/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
index 4ee12bc..5562af5 100644
--- a/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
@@ -735,7 +735,7 @@ public class ConfigAccessor {
   }
 
   /**
-   * Update ResourceConfig of the given resource. The value of field in current config will
be
+   * Update InstanceConfig of the given resource. The value of field in current config will
be
    * replaced with the value of the same field in given config if it presents. If there is
new field
    * in given config but not in current config, the field will be added into the current
config..
    * The list fields and map fields will be replaced as a single entry.

http://git-wip-us.apache.org/repos/asf/helix/blob/72d52484/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
index 9e44797..8688665 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKHelixAdmin.java
@@ -34,13 +34,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
-import java.util.TreeSet;
 import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
 import org.I0Itec.zkclient.DataUpdater;
 import org.I0Itec.zkclient.exception.ZkNoNodeException;
-import org.apache.commons.math.stat.clustering.Cluster;
 import org.apache.helix.AccessOption;
 import org.apache.helix.BaseDataAccessor;
 import org.apache.helix.ConfigAccessor;

http://git-wip-us.apache.org/repos/asf/helix/blob/72d52484/helix-core/src/main/java/org/apache/helix/manager/zk/ZKUtil.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKUtil.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKUtil.java
index d6a54f5..1151fc9 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZKUtil.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZKUtil.java
@@ -25,7 +25,6 @@ import java.util.List;
 
 import org.I0Itec.zkclient.DataUpdater;
 import org.apache.helix.BaseDataAccessor;
-import org.apache.helix.HelixException;
 import org.apache.helix.InstanceType;
 import org.apache.helix.PropertyPathBuilder;
 import org.apache.helix.ZNRecord;

http://git-wip-us.apache.org/repos/asf/helix/blob/72d52484/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstanceAccessor.java
----------------------------------------------------------------------
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstanceAccessor.java
b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstanceAccessor.java
index 2748dea..31be5cf 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstanceAccessor.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/InstanceAccessor.java
@@ -32,6 +32,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response;
 
+import org.apache.helix.ConfigAccessor;
 import org.apache.helix.HelixAdmin;
 import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.HelixException;
@@ -315,11 +316,10 @@ public class InstanceAccessor extends AbstractHelixResource {
     return notFound();
   }
 
-  @PUT
+  @POST
   @Path("{instanceName}/configs")
   public Response updateInstanceConfig(@PathParam("clusterId") String clusterId,
-      @PathParam("instanceName") String instanceName, String content) throws IOException
{
-    HelixAdmin admin = getHelixAdmin();
+      @PathParam("instanceName") String instanceName, String content) {
     ZNRecord record;
     try {
       record = toZNRecord(content);
@@ -327,14 +327,16 @@ public class InstanceAccessor extends AbstractHelixResource {
       _logger.error("Failed to deserialize user's input " + content + ", Exception: " + e);
       return badRequest("Input is not a vaild ZNRecord!");
     }
-
+    InstanceConfig instanceConfig = new InstanceConfig(record);
+    ConfigAccessor configAccessor = getConfigAccessor();
     try {
-      admin.setInstanceConfig(clusterId, instanceName, new InstanceConfig(record));
+      configAccessor.updateInstanceConfig(clusterId, instanceName, instanceConfig);
+    } catch (HelixException ex) {
+      return notFound(ex.getMessage());
     } catch (Exception ex) {
-      _logger.error("Error in update instance config: " + instanceName, ex);
+      _logger.error(String.format("Error in update instance config for instance: %s", instanceName),
ex);
       return serverError(ex);
     }
-
     return OK();
   }
 

http://git-wip-us.apache.org/repos/asf/helix/blob/72d52484/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
----------------------------------------------------------------------
diff --git a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
index 968122f..5eb8a4c 100644
--- a/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
+++ b/helix-rest/src/main/java/org/apache/helix/rest/server/resources/helix/ResourceAccessor.java
@@ -240,22 +240,22 @@ public class ResourceAccessor extends AbstractHelixResource {
     HelixAdmin admin = getHelixAdmin();
     try {
       switch (cmd) {
-        case enable:
-          admin.enableResource(clusterId, resourceName, true);
-          break;
-        case disable:
-          admin.enableResource(clusterId, resourceName, false);
-          break;
-        case rebalance:
-          if (replicas == -1) {
-            return badRequest("Number of replicas is needed for rebalancing!");
-          }
-          keyPrefix = keyPrefix.length() == 0 ? resourceName : keyPrefix;
-          admin.rebalance(clusterId, resourceName, replicas, keyPrefix, group);
-          break;
-        default:
-          _logger.error("Unsupported command :" + command);
-          return badRequest("Unsupported command :" + command);
+      case enable:
+        admin.enableResource(clusterId, resourceName, true);
+        break;
+      case disable:
+        admin.enableResource(clusterId, resourceName, false);
+        break;
+      case rebalance:
+        if (replicas == -1) {
+          return badRequest("Number of replicas is needed for rebalancing!");
+        }
+        keyPrefix = keyPrefix.length() == 0 ? resourceName : keyPrefix;
+        admin.rebalance(clusterId, resourceName, replicas, keyPrefix, group);
+        break;
+      default:
+        _logger.error("Unsupported command :" + command);
+        return badRequest("Unsupported command :" + command);
       }
     } catch (Exception e) {
       _logger.error("Failed in updating resource : " + resourceName, e);
@@ -309,9 +309,7 @@ public class ResourceAccessor extends AbstractHelixResource {
     } catch (HelixException ex) {
       return notFound(ex.getMessage());
     } catch (Exception ex) {
-      _logger.error(
-          "Failed to update cluster config, cluster " + clusterId + " new config: " + content
-              + ", Exception: " + ex);
+      _logger.error(String.format("Error in update resource config for resource: %s", resourceName),
ex);
       return serverError(ex);
     }
     return OK();

http://git-wip-us.apache.org/repos/asf/helix/blob/72d52484/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
----------------------------------------------------------------------
diff --git a/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
b/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
index ce2bec9..24d2910 100644
--- a/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
+++ b/helix-rest/src/test/java/org/apache/helix/rest/server/TestInstanceAccessor.java
@@ -213,7 +213,7 @@ public class TestInstanceAccessor extends AbstractTestClass {
 
     Entity entity =
         Entity.entity(OBJECT_MAPPER.writeValueAsString(record), MediaType.APPLICATION_JSON_TYPE);
-    put("clusters/" + CLUSTER_NAME + "/instances/" + instanceName + "/configs", null, entity,
+    post("clusters/" + CLUSTER_NAME + "/instances/" + instanceName + "/configs", null, entity,
         Response.Status.OK.getStatusCode());
     Assert.assertEquals(record.getSimpleFields(),
         _configAccessor.getInstanceConfig(CLUSTER_NAME, instanceName).getRecord()


Mime
View raw message