hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From li...@apache.org
Subject svn commit: r1584186 - in /hbase/branches/0.89-fb/src: main/java/org/apache/hadoop/hbase/master/AssignmentPlanData.java main/java/org/apache/hadoop/hbase/master/RegionPlacement.java test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
Date Wed, 02 Apr 2014 21:05:29 GMT
Author: liyin
Date: Wed Apr  2 21:05:29 2014
New Revision: 1584186

URL: http://svn.apache.org/r1584186
Log:
Remove Gson from dependencies.

Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/AssignmentPlanData.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/AssignmentPlanData.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/AssignmentPlanData.java?rev=1584186&r1=1584185&r2=1584186&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/AssignmentPlanData.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/AssignmentPlanData.java
Wed Apr  2 21:05:29 2014
@@ -23,6 +23,8 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.HRegionInfo;
 import org.apache.hadoop.hbase.HServerAddress;
+import org.codehaus.jackson.annotate.JsonCreator;
+import org.codehaus.jackson.annotate.JsonProperty;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -43,7 +45,8 @@ public class AssignmentPlanData {
 
   private List<Assignment> assignments;
 
-  public AssignmentPlanData(List<Assignment> assignments) {
+  @JsonCreator
+  public AssignmentPlanData(@JsonProperty("assignments") List<Assignment> assignments)
{
     this.assignments = assignments;
   }
 
@@ -56,9 +59,12 @@ public class AssignmentPlanData {
    */
   public static class Assignment {
     private String regionname;
+
     private List<String> favored;
 
-    public Assignment(String regionname, List<String> favored) {
+    @JsonCreator
+    public Assignment(@JsonProperty("regionname") String regionname,
+                      @JsonProperty("favored") List<String> favored) {
       this.regionname = regionname;
       this.favored = favored;
     }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java?rev=1584186&r1=1584185&r2=1584186&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java
Wed Apr  2 21:05:29 2014
@@ -63,9 +63,8 @@ import org.apache.hadoop.hbase.util.Pair
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonSyntaxException;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.ObjectMapper;
 
 public class RegionPlacement implements RegionPlacementPolicy{
   private static final Log LOG = LogFactory.getLog(RegionPlacement.class
@@ -1564,10 +1563,10 @@ public class RegionPlacement implements 
             rp.updateAssignmentPlan(newPlan);
           }
           s.close();
+        } catch (JsonParseException je) {
+          LOG.error("Unable to parse json file", je);
         } catch (IOException e) {
-          LOG.error("Unable to load plan file: " + e);
-        } catch (JsonSyntaxException je) {
-          LOG.error("Unable to parse json file: " + je);
+          LOG.error("Unable to load plan file" , e);
         }
       } else if (cmd.hasOption("download")) {
         String path = cmd.getOptionValue("download");
@@ -1575,9 +1574,9 @@ public class RegionPlacement implements 
           RegionAssignmentSnapshot snapshot = rp.getRegionAssignmentSnapshot();
           AssignmentPlan plan = snapshot.getExistingAssignmentPlan();
           AssignmentPlanData data = AssignmentPlanData.constructFromAssignmentPlan(plan);
-          Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
-          String jsonOutput = prettyGson.toJson(data);
-          FileUtils.write(new File(path), jsonOutput);
+
+          ObjectMapper jsonMapper = new ObjectMapper();
+          jsonMapper.defaultPrettyPrintingWriter().writeValue(new File(path), data);
         } catch (Exception e) {
           LOG.error("Unable to download current assignment plan" + e);
           e.printStackTrace();
@@ -1915,12 +1914,11 @@ public class RegionPlacement implements 
    * Convert json string to assignment plan
    * @param jsonStr
    * @return assignment plan converted from json string
-   * @throws JsonSyntaxException
    * @throws IOException
    */
   public AssignmentPlan loadPlansFromJson(String jsonStr)
-      throws JsonSyntaxException, IOException {
-    AssignmentPlanData data = new Gson().fromJson(jsonStr, AssignmentPlanData.class);
+      throws IOException {
+    AssignmentPlanData data = new ObjectMapper().readValue(jsonStr, AssignmentPlanData.class);
     AssignmentPlan newPlan = new AssignmentPlan();
     RegionAssignmentSnapshot snapshot = this.getRegionAssignmentSnapshot();
     Map<String, HRegionInfo> map = snapshot.getRegionNameToRegionInfoMap();

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java?rev=1584186&r1=1584185&r2=1584186&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
(original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
Wed Apr  2 21:05:29 2014
@@ -60,13 +60,12 @@ import org.apache.hadoop.hbase.util.Byte
 import org.apache.hadoop.hbase.util.TagRunner;
 import org.apache.hadoop.hbase.util.TestTag;
 import org.apache.hadoop.hbase.util.Writables;
+import org.codehaus.jackson.map.ObjectMapper;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import com.google.gson.Gson;
-
 @RunWith(TagRunner.class)
 public class TestRegionPlacement {
   final static Log LOG = LogFactory.getLog(TestRegionPlacement.class);
@@ -409,7 +408,7 @@ public class TestRegionPlacement {
   /**
    * Verify the number of user regions is assigned to the primary
    * region server based on the plan is expected
-   * @param expectedNum.
+   * @param expectedNum
    * @throws IOException
    */
   private void verifyRegionOnPrimaryRS(int expectedNum)
@@ -422,7 +421,7 @@ public class TestRegionPlacement {
 
   /**
    * Verify the meta has updated to the latest assignment plan
-   * @param plan
+   * @param expectedPlan
    * @throws IOException
    */
   private void verifyMETAUpdated(AssignmentPlan expectedPlan)
@@ -634,7 +633,7 @@ public class TestRegionPlacement {
       RegionPlacement.printAssignmentPlan(currentPlan);
       AssignmentPlanData data = AssignmentPlanData.constructFromAssignmentPlan(currentPlan);
 
-      String jsonStr = new Gson().toJson(data);
+      String jsonStr = new ObjectMapper().defaultPrettyPrintingWriter().writeValueAsString(data);
       LOG.info("Json version of current assignment plan: " + jsonStr);
       AssignmentPlan loadedPlan = rp.loadPlansFromJson(jsonStr);
       RegionPlacement.printAssignmentPlan(loadedPlan);



Mime
View raw message