You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2017/12/15 01:28:33 UTC

[GitHub] ctubbsii closed pull request #336: ACCUMULO-4755 Custom serialization for AbstractId types

ctubbsii closed pull request #336: ACCUMULO-4755 Custom serialization for AbstractId types
URL: https://github.com/apache/accumulo/pull/336
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/pom.xml b/core/pom.xml
index b459a8236b..b8379e5591 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -67,6 +67,10 @@
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
     </dependency>
+    <dependency>
+      <groupId>javax.xml.bind</groupId>
+      <artifactId>jaxb-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>jline</groupId>
       <artifactId>jline</artifactId>
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/JaxbAbstractIdSerializer.java b/core/src/main/java/org/apache/accumulo/core/client/impl/JaxbAbstractIdSerializer.java
new file mode 100644
index 0000000000..ec9d080001
--- /dev/null
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/JaxbAbstractIdSerializer.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.client.impl;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+/**
+ * A class for marshaling @link{AbstractId} so REST calls can serialize AbstractId to its canonical value.
+ */
+public class JaxbAbstractIdSerializer extends XmlAdapter<String,AbstractId> {
+
+  @Override
+  public String marshal(AbstractId id) {
+    if (id != null)
+      return id.canonicalID();
+    else
+      return null;
+  }
+
+  @Override
+  public AbstractId unmarshal(String id) {
+    // should not unmarshal from String
+    throw new UnsupportedOperationException("Cannot unmarshal from String");
+  }
+}
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespace.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespace.java
index 56d7073957..cb7133a443 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/Namespace.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Namespace.java
@@ -18,6 +18,8 @@
 
 import java.util.concurrent.ExecutionException;
 
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
 import org.apache.accumulo.core.client.Instance;
 
 import com.google.common.cache.Cache;
@@ -35,6 +37,7 @@
    * Uses an internal cache and private constructor for storing a WeakReference of every Namespace.ID. Therefore, a Namespace.ID can't be instantiated outside
    * this class and is accessed by calling Namespace.ID.{@link #of(String)}.
    */
+  @XmlJavaTypeAdapter(JaxbAbstractIdSerializer.class)
   public static class ID extends AbstractId {
     private static final long serialVersionUID = 8931104141709170293L;
     static final Cache<String,ID> cache = CacheBuilder.newBuilder().weakValues().build();
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Table.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Table.java
index 15517d965c..0de551c192 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/Table.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Table.java
@@ -18,6 +18,8 @@
 
 import java.util.concurrent.ExecutionException;
 
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
 import org.apache.accumulo.core.client.Instance;
 
 import com.google.common.cache.Cache;
@@ -32,6 +34,7 @@
    * Uses an internal cache and private constructor for storing a WeakReference of every Table.ID. Therefore, a Table.ID can't be instantiated outside this
    * class and is accessed by calling Table.ID.{@link #of(String)}.
    */
+  @XmlJavaTypeAdapter(JaxbAbstractIdSerializer.class)
   public static class ID extends AbstractId {
     private static final long serialVersionUID = 7399913185860577809L;
     static final Cache<String,ID> cache = CacheBuilder.newBuilder().weakValues().build();
diff --git a/pom.xml b/pom.xml
index 4cce01242f..597828a26e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -290,6 +290,11 @@
         <artifactId>jsr311-api</artifactId>
         <version>1.1.1</version>
       </dependency>
+      <dependency>
+        <groupId>javax.xml.bind</groupId>
+        <artifactId>jaxb-api</artifactId>
+        <version>2.2.12</version>
+      </dependency>
       <dependency>
         <groupId>jline</groupId>
         <artifactId>jline</artifactId>
diff --git a/server/monitor/pom.xml b/server/monitor/pom.xml
index cfb51daac9..70c69ee9be 100644
--- a/server/monitor/pom.xml
+++ b/server/monitor/pom.xml
@@ -52,6 +52,10 @@
       <groupId>javax.ws.rs</groupId>
       <artifactId>javax.ws.rs-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>javax.xml.bind</groupId>
+      <artifactId>jaxb-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/problems/ProblemSummaryInformation.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/problems/ProblemSummaryInformation.java
index 165bf86cfc..9f688c01a6 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/problems/ProblemSummaryInformation.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/problems/ProblemSummaryInformation.java
@@ -29,7 +29,7 @@
 
   // Variable names become JSON keys
   public String tableName;
-  public String tableID;
+  public Table.ID tableID;
 
   public Integer fileRead;
   public Integer fileWrite;
@@ -53,7 +53,7 @@ public ProblemSummaryInformation() {}
    */
   public ProblemSummaryInformation(String tableName, Table.ID tableId, Integer fileRead, Integer fileWrite, Integer tableLoad) {
     this.tableName = tableName;
-    this.tableID = tableId.canonicalID();
+    this.tableID = tableId;
     this.fileRead = fileRead;
     this.fileWrite = fileWrite;
     this.tableLoad = tableLoad;
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tables/TableInformation.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tables/TableInformation.java
index cacd3424a5..d15104611a 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tables/TableInformation.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tables/TableInformation.java
@@ -30,7 +30,7 @@
 
   // Variable names become JSON keys
   public String tablename;
-  public String tableId;
+  public Table.ID tableId;
   public String tableState;
 
   public int tablets;
@@ -75,7 +75,7 @@ public TableInformation() {}
    */
   public TableInformation(String tableName, Table.ID tableId, String tableState) {
     this.tablename = tableName;
-    this.tableId = tableId.canonicalID();
+    this.tableId = tableId;
     this.tableState = tableState;
   }
 
@@ -95,7 +95,7 @@ public TableInformation(String tableName, Table.ID tableId, String tableState) {
    */
   public TableInformation(String tableName, Table.ID tableId, TableInfo info, Double holdTime, String tableState) {
     this.tablename = tableName;
-    this.tableId = tableId.canonicalID();
+    this.tableId = tableId;
 
     this.tablets = info.tablets;
     this.offlineTablets = info.tablets - info.onlineTablets;
diff --git a/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tservers/CurrentOperations.java b/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tservers/CurrentOperations.java
index 50f9bff6af..fab1969ae3 100644
--- a/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tservers/CurrentOperations.java
+++ b/server/monitor/src/main/java/org/apache/accumulo/monitor/rest/tservers/CurrentOperations.java
@@ -30,7 +30,7 @@
   // Variable names become JSON keys
   public String name;
   public String tablet;
-  public String tableID;
+  public Table.ID tableID;
   public long entries;
   public double ingest;
   public double query;
@@ -74,7 +74,7 @@ public CurrentOperations() {}
   public CurrentOperations(String name, Table.ID tableId, String tablet, long entries, double ingest, double query, Double minorAvg, Double minorStdDev,
       Double minorAvgES, Double majorAvg, Double majorStdDev, Double majorAvgES) {
     this.name = name;
-    this.tableID = tableId.canonicalID();
+    this.tableID = tableId;
     this.tablet = tablet;
     this.entries = entries;
     this.ingest = ingest;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services