helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject git commit: [HELIX-396] Make REST api for /instances parseable
Date Wed, 05 Mar 2014 02:16:09 GMT
Repository: helix
Updated Branches:
  refs/heads/helix-0.6.2-release 44707c6c6 -> 65285540f


[HELIX-396] Make REST api for /instances parseable


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

Branch: refs/heads/helix-0.6.2-release
Commit: 65285540fad3e8904ddb60c5dad872ef428d6272
Parents: 44707c6
Author: Kanak Biscuitwala <kanak@apache.org>
Authored: Tue Mar 4 13:35:38 2014 -0800
Committer: Kanak Biscuitwala <kanak@apache.org>
Committed: Tue Mar 4 18:15:58 2014 -0800

----------------------------------------------------------------------
 .../webapp/resources/InstancesResource.java     | 27 +++++++++++++++-----
 .../webapp/TestClusterManagementWebapp.java     | 12 ++++-----
 2 files changed, 26 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/65285540/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/InstancesResource.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/InstancesResource.java
b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/InstancesResource.java
index 0e98f44..41c6a15 100644
--- a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/InstancesResource.java
+++ b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/InstancesResource.java
@@ -27,6 +27,7 @@ import java.util.TreeMap;
 
 import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.HelixException;
+import org.apache.helix.ZNRecord;
 import org.apache.helix.manager.zk.ZkClient;
 import org.apache.helix.model.InstanceConfig;
 import org.apache.helix.model.LiveInstance;
@@ -35,9 +36,6 @@ import org.apache.helix.webapp.RestAdminApplication;
 import org.apache.log4j.Logger;
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
-import org.restlet.Context;
-import org.restlet.Request;
-import org.restlet.Response;
 import org.restlet.data.MediaType;
 import org.restlet.data.Status;
 import org.restlet.representation.Representation;
@@ -45,6 +43,8 @@ import org.restlet.representation.StringRepresentation;
 import org.restlet.representation.Variant;
 import org.restlet.resource.ServerResource;
 
+import com.google.common.collect.Lists;
+
 public class InstancesResource extends ServerResource {
   private final static Logger LOG = Logger.getLogger(InstancesResource.class);
 
@@ -54,7 +54,6 @@ public class InstancesResource extends ServerResource {
     setNegotiated(false);
   }
 
-
   @Override
   public Representation get() {
     StringRepresentation presentation = null;
@@ -99,10 +98,16 @@ public class InstancesResource extends ServerResource {
       }
     }
 
+    // Wrap raw data into an object, then serialize it
+    List<ZNRecord> recordList = Lists.newArrayList();
+    for (InstanceConfig instanceConfig : instanceConfigsMap.values()) {
+      recordList.add(instanceConfig.getRecord());
+    }
+    ListInstancesWrapper wrapper = new ListInstancesWrapper();
+    wrapper.instanceInfo = recordList;
+    wrapper.tagInfo = tagInstanceLists;
     StringRepresentation representation =
-        new StringRepresentation(
-            ClusterRepresentationUtil.ObjectToJson(instanceConfigsMap.values())
-                + ClusterRepresentationUtil.ObjectToJson(tagInstanceLists),
+        new StringRepresentation(ClusterRepresentationUtil.ObjectToJson(wrapper),
             MediaType.APPLICATION_JSON);
 
     return representation;
@@ -156,4 +161,12 @@ public class InstancesResource extends ServerResource {
     }
     return null;
   }
+
+  /**
+   * A wrapper class for quick serialization of the data presented by this call
+   */
+  public static class ListInstancesWrapper {
+    public List<ZNRecord> instanceInfo;
+    public Map<String, List<String>> tagInfo;
+  }
 }

http://git-wip-us.apache.org/repos/asf/helix/blob/65285540/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestClusterManagementWebapp.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestClusterManagementWebapp.java
b/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestClusterManagementWebapp.java
index c1251de..3eee0a1 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestClusterManagementWebapp.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/webapp/TestClusterManagementWebapp.java
@@ -22,7 +22,6 @@ package org.apache.helix.webapp;
 import java.io.IOException;
 import java.io.StringReader;
 import java.io.StringWriter;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -31,10 +30,10 @@ import org.apache.helix.PropertyPathConfig;
 import org.apache.helix.PropertyType;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.model.InstanceConfig.InstanceConfigProperty;
-import org.apache.helix.model.StateModelDefinition;
 import org.apache.helix.tools.AdminTestBase;
 import org.apache.helix.tools.ClusterSetup;
 import org.apache.helix.webapp.resources.ClusterRepresentationUtil;
+import org.apache.helix.webapp.resources.InstancesResource.ListInstancesWrapper;
 import org.apache.helix.webapp.resources.JsonParameters;
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
@@ -100,7 +99,6 @@ public class TestClusterManagementWebapp extends AdminTestBase {
 
     ZNRecord r = new ZNRecord("Test");
     r.merge(zn);
-    StateModelDefinition newStateModel = new StateModelDefinition(r);
 
     httpUrlBase = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/StateModelDefs";
     resourceRef = new Reference(httpUrlBase);
@@ -223,9 +221,10 @@ public class TestClusterManagementWebapp extends AdminTestBase {
 
     ObjectMapper mapper = new ObjectMapper();
 
-    TypeReference<ArrayList<ZNRecord>> typeRef = new TypeReference<ArrayList<ZNRecord>>()
{
+    TypeReference<ListInstancesWrapper> typeRef = new TypeReference<ListInstancesWrapper>()
{
     };
-    List<ZNRecord> znList = mapper.readValue(new StringReader(sw.toString()), typeRef);
+    ListInstancesWrapper wrapper = mapper.readValue(new StringReader(sw.toString()), typeRef);
+    List<ZNRecord> znList = wrapper.instanceInfo;
     AssertJUnit.assertTrue(znList.get(0).getId().equals(instance1 + "_" + instancePort));
 
     // the case to add more than 1 instances
@@ -264,7 +263,8 @@ public class TestClusterManagementWebapp extends AdminTestBase {
 
     mapper = new ObjectMapper();
 
-    znList = mapper.readValue(new StringReader(sw.toString()), typeRef);
+    wrapper = mapper.readValue(new StringReader(sw.toString()), typeRef);
+    znList = wrapper.instanceInfo;
 
     for (String instance : instances) {
       boolean found = false;


Mime
View raw message