accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [accumulo] branch master updated: ACCUMULO-4755 Custom serialization for AbstractId types (#336)
Date Fri, 15 Dec 2017 01:28:31 GMT
This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d177a0  ACCUMULO-4755 Custom serialization for AbstractId types (#336)
0d177a0 is described below

commit 0d177a084ca91c23da943b75344ca4998bcc5394
Author: Benjamin F <32075798+bfach10@users.noreply.github.com>
AuthorDate: Thu Dec 14 20:28:28 2017 -0500

    ACCUMULO-4755 Custom serialization for AbstractId types (#336)
    
    Custom JAXB marshaling with XmlJavaTypeAdapter
---
 core/pom.xml                                       |  4 +++
 .../core/client/impl/JaxbAbstractIdSerializer.java | 39 ++++++++++++++++++++++
 .../accumulo/core/client/impl/Namespace.java       |  3 ++
 .../apache/accumulo/core/client/impl/Table.java    |  3 ++
 pom.xml                                            |  5 +++
 server/monitor/pom.xml                             |  4 +++
 .../rest/problems/ProblemSummaryInformation.java   |  4 +--
 .../monitor/rest/tables/TableInformation.java      |  6 ++--
 .../monitor/rest/tservers/CurrentOperations.java   |  4 +--
 9 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/core/pom.xml b/core/pom.xml
index b459a82..b8379e5 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -68,6 +68,10 @@
       <artifactId>commons-logging</artifactId>
     </dependency>
     <dependency>
+      <groupId>javax.xml.bind</groupId>
+      <artifactId>jaxb-api</artifactId>
+    </dependency>
+    <dependency>
       <groupId>jline</groupId>
       <artifactId>jline</artifactId>
     </dependency>
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 0000000..ec9d080
--- /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 56d7073..cb7133a 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 @@ package org.apache.accumulo.core.client.impl;
 
 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 @@ public class Namespace {
    * 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 15517d9..0de551c 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 @@ package org.apache.accumulo.core.client.impl;
 
 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 @@ public class Table {
    * 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 217011e..db2a0c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -291,6 +291,11 @@
         <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>
         <version>2.11</version>
diff --git a/server/monitor/pom.xml b/server/monitor/pom.xml
index cfb51da..70c69ee 100644
--- a/server/monitor/pom.xml
+++ b/server/monitor/pom.xml
@@ -53,6 +53,10 @@
       <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>
     </dependency>
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 165bf86..9f688c0 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 @@ public class ProblemSummaryInformation {
 
   // 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 class 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 cacd342..d151046 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 @@ public class TableInformation {
 
   // 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 class 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 class TableInformation {
    */
   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 50f9bff..fab1969 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 @@ public class CurrentOperations {
   // 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 class 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;

-- 
To stop receiving notification emails like this one, please contact
['"commits@accumulo.apache.org" <commits@accumulo.apache.org>'].

Mime
View raw message