accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jtr...@apache.org
Subject svn commit: r1422979 - in /accumulo/trunk: pom.xml server/pom.xml server/src/main/java/org/apache/accumulo/server/monitor/servlets/JSONServlet.java
Date Mon, 17 Dec 2012 15:22:50 GMT
Author: jtrost
Date: Mon Dec 17 15:22:49 2012
New Revision: 1422979

URL: http://svn.apache.org/viewvc?rev=1422979&view=rev
Log:
ACCUMULO-903

Integrating patch from Christian Rohling (crohling88 at gmail dot com) that add GSON json
lib and makes the JSON Servlet output JSON spec compliant data.


Modified:
    accumulo/trunk/pom.xml
    accumulo/trunk/server/pom.xml
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/servlets/JSONServlet.java

Modified: accumulo/trunk/pom.xml
URL: http://svn.apache.org/viewvc/accumulo/trunk/pom.xml?rev=1422979&r1=1422978&r2=1422979&view=diff
==============================================================================
--- accumulo/trunk/pom.xml (original)
+++ accumulo/trunk/pom.xml Mon Dec 17 15:22:49 2012
@@ -144,7 +144,7 @@
             <configuration>
               <outputDirectory>../lib</outputDirectory>
               <!-- just grab the non-provided runtime dependencies -->
-              <includeArtifactIds>commons-collections,commons-configuration,commons-io,commons-lang,jline,log4j,libthrift,commons-jci-core,commons-jci-fam,commons-logging,commons-logging-api,commons-vfs2</includeArtifactIds>
+              <includeArtifactIds>commons-collections,commons-configuration,commons-io,commons-lang,jline,log4j,libthrift,commons-jci-core,commons-jci-fam,commons-logging,commons-logging-api,commons-vfs2,gson</includeArtifactIds>
               <excludeTransitive>true</excludeTransitive>
             </configuration>
           </execution>
@@ -712,6 +712,11 @@
         <artifactId>commons-jci-fam</artifactId>
         <version>1.0</version>
       </dependency>
+      <dependency>
+        <groupId>com.google.code.gson</groupId>
+        <artifactId>gson</artifactId>
+        <version>2.2.2</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 

Modified: accumulo/trunk/server/pom.xml
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/pom.xml?rev=1422979&r1=1422978&r2=1422979&view=diff
==============================================================================
--- accumulo/trunk/server/pom.xml (original)
+++ accumulo/trunk/server/pom.xml Mon Dec 17 15:22:49 2012
@@ -114,6 +114,10 @@
       <groupId>org.mortbay.jetty</groupId>
       <artifactId>jetty</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.google.code.gson</groupId>
+      <artifactId>gson</artifactId>
+     </dependency>
   </dependencies>
 
   <profiles>

Modified: accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/servlets/JSONServlet.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/servlets/JSONServlet.java?rev=1422979&r1=1422978&r2=1422979&view=diff
==============================================================================
--- accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/servlets/JSONServlet.java
(original)
+++ accumulo/trunk/server/src/main/java/org/apache/accumulo/server/monitor/servlets/JSONServlet.java
Mon Dec 17 15:22:49 2012
@@ -16,6 +16,10 @@
  */
 package org.apache.accumulo.server.monitor.servlets;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
 
 import javax.servlet.http.HttpServletRequest;
@@ -27,9 +31,13 @@ import org.apache.accumulo.core.master.t
 import org.apache.accumulo.server.monitor.Monitor;
 import org.apache.accumulo.server.monitor.util.celltypes.TServerLinkType;
 
+import com.google.gson.Gson;
+
 public class JSONServlet extends BasicServlet {
   private static final long serialVersionUID = 1L;
   
+  private Gson gson = new Gson();
+  
   @Override
   protected String getTitle(HttpServletRequest req) {
     return "JSON Report";
@@ -38,15 +46,22 @@ public class JSONServlet extends BasicSe
   @Override
   protected void pageStart(HttpServletRequest req, HttpServletResponse resp, StringBuilder
sb) {
     resp.setContentType("application/json");
-    sb.append("{ 'servers': [\n");
   }
   
-  private static void addServerLine(StringBuilder sb, String ip, String hostname, double
osload, double ingest, double query, double ingestMB, double queryMB,
+  private static Map<String,Object> addServer(String ip, String hostname, double osload,
double ingest, double query, double ingestMB, double queryMB,
       int scans, double scansessions, long holdtime) {
-    sb.append("  {'ip': '").append(ip).append("',\n  'hostname': '").append(hostname).append("',\n
 'osload': ").append(osload).append(",\n  'ingest': ")
-        .append(ingest).append(",\n  'query': ").append(query).append(",\n  'ingestMB': ").append(ingestMB).append(",\n
 'queryMB': ").append(queryMB)
-        .append(",\n  'scans': ").append(scans).append(",\n  'scansessions': ").append(scansessions).append(",\n
 'holdtime': ").append(holdtime)
-        .append("},\n");
+	Map<String,Object> map = new HashMap<String,Object>();
+	map.put("ip", ip);
+	map.put("hostname", hostname);
+	map.put("osload", osload);
+	map.put("ingest", ingest);
+	map.put("query", query);
+	map.put("ingestMB", ingestMB);
+	map.put("queryMB", queryMB);
+	map.put("scans", scans);
+	map.put("scans", scansessions);
+	map.put("holdtime", holdtime);
+	return map;
   }
   
   @Override
@@ -55,26 +70,34 @@ public class JSONServlet extends BasicSe
       return;
     }
     
+    Map<String,Object> results = new HashMap<String,Object>();
+    List<Map<String,Object>> servers = new ArrayList<Map<String,Object>>();
+    
     for (TabletServerStatus status : Monitor.getMmi().tServerInfo) {
       TableInfo summary = Monitor.summarizeTableStats(status);
-      addServerLine(sb, status.name, TServerLinkType.displayName(status.name), status.osLoad,
summary.ingestRate, summary.queryRate,
+      servers.add(addServer(status.name, TServerLinkType.displayName(status.name), status.osLoad,
summary.ingestRate, summary.queryRate,
           summary.ingestByteRate / 1000000.0, summary.queryByteRate / 1000000.0, summary.scans.running
+ summary.scans.queued, Monitor.getLookupRate(),
-          status.holdTime);
+          status.holdTime));
     }
     
     for (Entry<String,Byte> entry : Monitor.getMmi().badTServers.entrySet()) {
-      sb.append("  {'ip': '").append(entry.getKey()).append("',\n  'bad':true},\n");
+      Map<String,Object> badServer = new HashMap<String,Object>();
+      badServer.put("ip", entry.getKey());
+      badServer.put("bad", true);
+      servers.add(badServer);
     }
     
     for (DeadServer dead : Monitor.getMmi().deadTabletServers) {
-      sb.append("  {'ip': '").append(dead.server).append("',\n  'dead': true},\n");
+        Map<String,Object> deadServer = new HashMap<String,Object>();
+        deadServer.put("ip", dead.server);
+        deadServer.put("dead", true);
+        servers.add(deadServer);
     }
-    if (Monitor.getMmi().tServerInfo.size() > 0 || Monitor.getMmi().badTServers.size()
> 0 || Monitor.getMmi().deadTabletServers.size() > 0)
-      sb.setLength(sb.length() - 2);
+    
+    results.put("servers", servers);
+    sb.append(gson.toJson(results));
   }
   
   @Override
-  protected void pageEnd(HttpServletRequest req, HttpServletResponse resp, StringBuilder
sb) {
-    sb.append("\n  ]\n}\n");
-  }
+  protected void pageEnd(HttpServletRequest req, HttpServletResponse resp, StringBuilder
sb) {}
 }



Mime
View raw message