cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject git commit: updated refs/heads/reporter to f7083c2
Date Sun, 07 Dec 2014 08:33:46 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/reporter 2e0642e83 -> f7083c2e8


Add Type Adapter for AtomicLongMap and update Google Gson library


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

Branch: refs/heads/reporter
Commit: f7083c2e88eedec3ced51e446975f8cc86caca9d
Parents: 2e0642e
Author: Wido den Hollander <wido@widodh.nl>
Authored: Sun Dec 7 09:14:35 2014 +0100
Committer: Wido den Hollander <wido@widodh.nl>
Committed: Sun Dec 7 09:19:36 2014 +0100

----------------------------------------------------------------------
 pom.xml                                         |  2 +-
 .../cloudstack/report/AtomicGsonAdapter.java    | 48 ++++++++++++++++++++
 .../apache/cloudstack/report/UsageReporter.java |  9 +++-
 3 files changed, 57 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f7083c2e/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index e68b307..cf1599b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,7 +58,7 @@
     <cs.jasypt.version>1.9.0</cs.jasypt.version>
     <cs.trilead.version>build213-svnkit-1.3-patch</cs.trilead.version>
     <cs.ehcache.version>2.6.6</cs.ehcache.version>
-    <cs.gson.version>1.7.2</cs.gson.version>
+    <cs.gson.version>2.3.1</cs.gson.version>
     <cs.guava.version>14.0-rc1</cs.guava.version>
     <cs.xapi.version>6.2.0-3.1</cs.xapi.version>
     <cs.httpclient.version>3.1</cs.httpclient.version>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f7083c2e/server/src/org/apache/cloudstack/report/AtomicGsonAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/report/AtomicGsonAdapter.java b/server/src/org/apache/cloudstack/report/AtomicGsonAdapter.java
new file mode 100644
index 0000000..23d83f1
--- /dev/null
+++ b/server/src/org/apache/cloudstack/report/AtomicGsonAdapter.java
@@ -0,0 +1,48 @@
+// 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.cloudstack.report;
+
+import com.google.gson.TypeAdapter;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
+import com.google.common.util.concurrent.AtomicLongMap;
+import java.util.Map;
+import java.io.IOException;
+
+public class AtomicGsonAdapter extends TypeAdapter<AtomicLongMap> {
+
+    public AtomicLongMap<Object> read(JsonReader reader) throws IOException {
+        reader.nextNull();
+        return null;
+    }
+
+    public void write(JsonWriter writer, AtomicLongMap value) throws IOException {
+        if (value == null) {
+            writer.nullValue();
+            return;
+        }
+
+        @SuppressWarnings("unchecked")
+        Map <String, Long> map = value.asMap();
+
+        writer.beginObject();
+        for (Map.Entry<String, Long> entry : map.entrySet()) {
+            writer.name(entry.getKey()).value(entry.getValue());
+        }
+        writer.endObject();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f7083c2e/server/src/org/apache/cloudstack/report/UsageReporter.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/report/UsageReporter.java b/server/src/org/apache/cloudstack/report/UsageReporter.java
index ceb1c82..9cef057 100644
--- a/server/src/org/apache/cloudstack/report/UsageReporter.java
+++ b/server/src/org/apache/cloudstack/report/UsageReporter.java
@@ -69,6 +69,7 @@ import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.upgrade.dao.VersionDao;
 import com.cloud.upgrade.dao.VersionVO;
 import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
 import com.google.common.util.concurrent.AtomicLongMap;
 
 @Component
@@ -135,7 +136,13 @@ public class UsageReporter extends ManagerBase implements ComponentMethodInterce
     }
 
     private void sendReport(String reportUri, String uniqueID, Map<String, Object>
reportMap) {
-        Gson gson = new Gson();
+
+        GsonBuilder builder = new GsonBuilder();
+
+        AtomicGsonAdapter adapter = new AtomicGsonAdapter();
+        builder.registerTypeAdapter(AtomicLongMap.class, adapter);
+
+        Gson gson = builder.create();
         String report = gson.toJson(reportMap);
 
         int http_timeout = 15000;


Mime
View raw message