chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r1042251 - in /incubator/chukwa/trunk: ./ ivy/ src/java/org/apache/hadoop/chukwa/datastore/ src/java/org/apache/hadoop/chukwa/hicc/rest/ src/java/org/apache/hadoop/chukwa/inputtools/log4j/ src/java/org/apache/hadoop/chukwa/rest/actions/ src...
Date Sat, 04 Dec 2010 22:29:43 GMT
Author: eyang
Date: Sat Dec  4 22:29:42 2010
New Revision: 1042251

URL: http://svn.apache.org/viewvc?rev=1042251&view=rev
Log:
CHUKWA-474. Replaced JSON library with JSON-Simple. (Eric Yang)

Removed:
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/actions/
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/objects/
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/services/
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/DatabaseRestServerSetup.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseClientTraceTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseClusterDiskTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseClusterHadoopRpcTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseDfsDataNodeTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseDfsFsNameSystemTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseDfsNameNodeTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseDfsThroughputTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseDiskTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseHadoopJvmTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseHadoopRpcTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseMrJobConfTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseMrJobTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseMrTaskTest.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/TestDatabaseSystemMetricsTest.java
Modified:
    incubator/chukwa/trunk/ivy.xml
    incubator/chukwa/trunk/ivy/ivysettings.xml
    incubator/chukwa/trunk/ivy/libraries.properties
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/rest/MetricsController.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/database/TestDatabaseWebJson.java
    incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/TestUserResource.java

Modified: incubator/chukwa/trunk/ivy.xml
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/ivy.xml?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/ivy.xml (original)
+++ incubator/chukwa/trunk/ivy.xml Sat Dec  4 22:29:42 2010
@@ -61,6 +61,10 @@
       name="hadoop-test"
       rev="${hadoop.version}"
       conf="common->master"/>
+    <dependency org="com.googlecode.json-simple"
+      name="json-simple"
+      rev="${json-simple.version}"
+      conf="common->master"/>
 <!--    <dependency org="org.apache.hbase"
       name="hbase"
       rev="${hbase.version}"

Modified: incubator/chukwa/trunk/ivy/ivysettings.xml
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/ivy/ivysettings.xml?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/ivy/ivysettings.xml (original)
+++ incubator/chukwa/trunk/ivy/ivysettings.xml Sat Dec  4 22:29:42 2010
@@ -45,6 +45,12 @@
   <property name="google.com"
     value="http://google-maven-repository.googlecode.com/svn/repository/"
     override="false"/>
+  <property name="googlecode"
+    value="http://mirrors.ibiblio.org/pub/mirrors/maven2/"
+    override="false"/>
+  <property name="jboss.org"
+    value="http://repository.jboss.org/maven2/"
+    override="false"/>
   <property name="maven2.pattern"
     value="[organisation]/[module]/[revision]/[module]-[revision]"/>
   <property name="maven2.pattern.ext"
@@ -82,6 +88,14 @@
       root="${google.com}"
       m2compatible="true"
       />
+    <ibiblio name="googlecode"
+      root="${googlecode}"
+      m2compatible="true"
+      />
+    <ibiblio name="jboss"
+      root="${jboss.org}"
+      m2compatible="true"
+      />
     <chain name="default" dual="true">
       <resolver ref="local"/>
       <resolver ref="apache"/>
@@ -89,6 +103,8 @@
       <resolver ref="facebook"/>
       <resolver ref="ibiblio"/>
       <resolver ref="google"/>
+      <resolver ref="googlecode"/>
+      <resolver ref="jboss"/>
     </chain>
     <chain name="internal">
       <resolver ref="local"/>
@@ -98,6 +114,8 @@
       <resolver ref="maven2"/>
       <resolver ref="facebook"/>
       <resolver ref="google"/>
+      <resolver ref="googlecode"/>
+      <resolver ref="jboss"/>
     </chain>
     <chain name="external-and-snapshots">
       <resolver ref="maven2"/>

Modified: incubator/chukwa/trunk/ivy/libraries.properties
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/ivy/libraries.properties?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/ivy/libraries.properties (original)
+++ incubator/chukwa/trunk/ivy/libraries.properties Sat Dec  4 22:29:42 2010
@@ -50,9 +50,10 @@ jdiff.version=1.0.9
 xmlenc.version=0.52
 xerces.version=1.4.4
 #jaxb.version=2.1.12
-hbase.version=0.89.0-SNAPSHOT
+hbase.version=0.21.0-SNAPSHOT
 thrift.version=0.2.0
 zookeeper.version=3.2.2
 jersey.version=1.1.5.1
 guava.version=r05
 #avro.version=1.3.2
+json-simple.version=1.1

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java Sat
Dec  4 22:29:42 2010
@@ -23,8 +23,9 @@ import java.io.IOException;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
 
 import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
 import org.apache.hadoop.chukwa.hicc.HiccWebServer;
@@ -72,7 +73,7 @@ public class UserStore {
         viewStream.readFully(buffer);
         viewStream.close();
         try {
-          JSONObject json = new JSONObject(new String(buffer));
+          JSONObject json = (JSONObject) JSONValue.parse(new String(buffer));
           profile = new UserBean(json);
         } catch (Exception e) {
           log.error(ExceptionUtil.getStackTrace(e));
@@ -137,8 +138,8 @@ public class UserStore {
           profileStream.readFully(buffer);
           profileStream.close();
           try {
-            UserBean user = new UserBean(new JSONObject(new String(buffer)));
-            list.put(user.getId());
+            UserBean user = new UserBean((JSONObject) JSONValue.parse(new String(buffer)));
+            list.add(user.getId());
           } catch (Exception e) {
             log.error(ExceptionUtil.getStackTrace(e));
           }

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java Sat
Dec  4 22:29:42 2010
@@ -20,11 +20,12 @@ package org.apache.hadoop.chukwa.datasto
 
 import java.io.File;
 import java.io.IOException;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONObject;
+
 
 import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
 import org.apache.hadoop.chukwa.hicc.HiccWebServer;
@@ -36,6 +37,10 @@ import org.apache.hadoop.fs.FSDataOutput
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
+import org.json.simple.parser.JSONParser;
 
 public class ViewStore {
   private String vid = null;
@@ -87,7 +92,7 @@ public class ViewStore {
         viewStream.readFully(buffer);
         viewStream.close();
         try {
-          view = new ViewBean(new JSONObject(new String(buffer)));
+          view = new ViewBean(buffer);
           view.update();
         } catch (Exception e) {
           log.error(ExceptionUtil.getStackTrace(e));
@@ -217,8 +222,8 @@ public class ViewStore {
             viewStream.readFully(buffer);
             viewStream.close();
             try {
-              ViewBean view = new ViewBean(new JSONObject(new String(buffer)));
-              JSONObject json = new JSONObject();
+              ViewBean view = new ViewBean(buffer);
+              Map<String, String> json=new LinkedHashMap<String, String>();
               json.put("name", view.getName());
               json.put("type", view.getPermissionType());
               json.put("owner", view.getOwner());
@@ -227,7 +232,7 @@ public class ViewStore {
               } else {
                 json.put("editable","false");
               }
-              list.put(json);
+              list.add(json);
             } catch (Exception e) {
               log.error(ExceptionUtil.getStackTrace(e));
             }

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java Sat
Dec  4 22:29:42 2010
@@ -24,7 +24,8 @@ import java.util.HashMap;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONObject;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
 
 import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
 import org.apache.hadoop.chukwa.hicc.HiccWebServer;
@@ -93,7 +94,8 @@ public class WidgetStore {
           widgetStream.readFully(buffer);
           widgetStream.close();
           try {
-            WidgetBean widget = new WidgetBean(new JSONObject(new String(buffer)));
+            JSONObject widgetBuffer = (JSONObject) JSONValue.parse(new String(buffer));
+            WidgetBean widget = new WidgetBean(widgetBuffer);
             catalog.addCatalog(widget);
             list.put(widget.getId(),widget);
           } catch (Exception e) {

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/rest/MetricsController.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/rest/MetricsController.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/rest/MetricsController.java
(original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/rest/MetricsController.java
Sat Dec  4 22:29:42 2010
@@ -21,7 +21,7 @@ import org.apache.hadoop.chukwa.datastor
 import org.apache.hadoop.chukwa.hicc.TimeHandler;
 import org.apache.hadoop.chukwa.hicc.bean.Series;
 import org.apache.log4j.Logger;
-import org.json.JSONArray;
+import org.json.simple.JSONArray;
 
 @Path("/metrics")
 public class MetricsController {
@@ -89,7 +89,7 @@ public class MetricsController {
           JSONArray seriesList = new JSONArray();
           for(String rowKey : rkeys) {
             Series output = ChukwaHBaseStore.getSeries(table, rowKey, column, startTime,
endTime, true);
-            seriesList.put(output.toJSONObject());
+            seriesList.add(output.toJSONObject());
           }
           buffer = seriesList.toString();
       } else {
@@ -110,7 +110,7 @@ public class MetricsController {
     Set<String> tableNames = ChukwaHBaseStore.getTableNames();
     JSONArray tables = new JSONArray();
     for(String table : tableNames) {
-      tables.put(table);
+      tables.add(table);
     }
     return tables.toString();
   }
@@ -122,7 +122,7 @@ public class MetricsController {
     Set<String> familyNames = ChukwaHBaseStore.getFamilyNames(tableName);
     JSONArray families = new JSONArray();
     for(String family : familyNames) {
-      families.put(family);
+      families.add(family);
     }
     return families.toString();
   }
@@ -155,7 +155,7 @@ public class MetricsController {
     Set<String> columnNames = ChukwaHBaseStore.getColumnNames(tableName, family, startTime,
endTime);
     JSONArray columns = new JSONArray();
     for(String column : columnNames) {
-      columns.put(column);
+      columns.add(column);
     }
     return columns.toString();
   }
@@ -188,7 +188,7 @@ public class MetricsController {
     Set<String> columnNames = ChukwaHBaseStore.getRowNames(tableName, column, startTime,
endTime);
     JSONArray rows = new JSONArray();
     for(String row : columnNames) {
-      rows.put(row);
+      rows.add(row);
     }
     return rows.toString();
   }

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java
(original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java
Sat Dec  4 22:29:42 2010
@@ -34,8 +34,7 @@ import org.apache.hadoop.metrics.spi.Abs
 import org.apache.hadoop.metrics.spi.OutputRecord;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PatternLayout;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.json.simple.JSONObject;
 
 public class Log4JMetricsContext extends AbstractMetricsContext {
   Logger log = Logger.getLogger(Log4JMetricsContext.class);
@@ -116,7 +115,7 @@ public class Log4JMetricsContext extends
       for (String metricName : outRec.getMetricNames()) {
         json.put(metricName, outRec.getMetric(metricName));
       }
-    } catch (JSONException e) {
+    } catch (Exception e) {
       log.warn("exception in Log4jMetricsContext:" , e);
     }
     out.info(json.toString());

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java Sat
Dec  4 22:29:42 2010
@@ -26,9 +26,8 @@ import javax.xml.bind.annotation.XmlTran
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
 
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
 
@@ -42,11 +41,11 @@ public class ColumnBean {
   
   public ColumnBean(JSONArray json) throws ParseException {
     try {
-      widgets = new WidgetBean[json.length()];
-      for(int i=0;i<json.length();i++) {
-        widgets[i]=new WidgetBean(json.getJSONObject(i));
+      widgets = new WidgetBean[json.size()];
+      for(int i=0;i<json.size();i++) {
+        widgets[i]=new WidgetBean((JSONObject) json.get(i));
       }
-    } catch (JSONException e) {
+    } catch (Exception e) {
       log.error(ExceptionUtil.getStackTrace(e));
       throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
     }
@@ -70,7 +69,7 @@ public class ColumnBean {
   public JSONArray deserialize() {
     JSONArray ja = new JSONArray();
     for(int i=0;i<widgets.length;i++) {
-      ja.put(widgets[i].deserialize());
+      ja.add(widgets[i].deserialize());
     }
     return ja;
   }

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java Sat
Dec  4 22:29:42 2010
@@ -26,7 +26,7 @@ import javax.xml.bind.annotation.XmlType
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONObject;
+import org.json.simple.JSONObject;
 
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
 
@@ -42,8 +42,8 @@ public class ConfigBean {
   
   public ConfigBean(JSONObject json) throws ParseException {
     try {
-      key = json.getString("key");
-      value = json.getString("value");
+      key = (String) json.get("key");
+      value = (String) json.get("value");
     } catch (Exception e) {
       log.error(ExceptionUtil.getStackTrace(e));
       throw new ParseException("Error parsing user object.",0);

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java Sat
Dec  4 22:29:42 2010
@@ -24,8 +24,7 @@ import javax.xml.bind.annotation.XmlElem
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.json.simple.JSONObject;
 
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
 
@@ -39,9 +38,9 @@ public class OptionBean {
   
   public OptionBean(JSONObject json) throws ParseException {
     try {
-      label = json.getString("label");
-      value = json.getString("value");
-    } catch (JSONException e) {
+      label = (String) json.get("label");
+      value = (String) json.get("value");
+    } catch (Exception e) {
       throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
     }
   }

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java Sat
Dec  4 22:29:42 2010
@@ -27,9 +27,8 @@ import javax.xml.bind.annotation.XmlType
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
 
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
 
@@ -46,22 +45,22 @@ public class PagesBean {
   
   public PagesBean(JSONObject json) throws ParseException {
     try {
-      title = json.getString("title");
-      columns = json.getInt("columns");
-      JSONArray layout = json.getJSONArray("layout");
-      this.layout = new ColumnBean[layout.length()];
-      for(int i=0;i<layout.length();i++) {
-        ColumnBean c = new ColumnBean(layout.getJSONArray(i));
+      title = (String) json.get("title");
+      columns = ((Long) json.get("columns")).intValue();
+      JSONArray layout = (JSONArray) json.get("layout");
+      this.layout = new ColumnBean[layout.size()];
+      for(int i=0;i<layout.size();i++) {
+        ColumnBean c = new ColumnBean((JSONArray) layout.get(i));
         this.layout[i]=c;
       }
-      if(json.has("colSize")) {
-        JSONArray ja = json.getJSONArray("colSize");
-        columnSizes = new int[ja.length()];
-        for(int i=0; i< ja.length(); i++) {
-          columnSizes[i] = ja.getInt(i);
+      if(json.containsKey("colSize")) {
+        JSONArray ja = (JSONArray) json.get("colSize");
+        columnSizes = new int[ja.size()];
+        for(int i=0; i< ja.size(); i++) {
+          columnSizes[i] = ((Long) ja.get(i)).intValue();
         }
       }
-    } catch (JSONException e) {
+    } catch (Exception e) {
       log.error(ExceptionUtil.getStackTrace(e));
       throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
     }
@@ -121,13 +120,13 @@ public class PagesBean {
     try {
       json.put("title", this.title);
       for(int i=0;i<layout.length;i++) {
-        ja.put(layout[i].deserialize());
+        ja.add(layout[i].deserialize());
       }
       json.put("layout", (JSONArray) ja);
       json.put("columns", layout.length);
       if(columnSizes!=null) {
         for(int colSize : columnSizes) {
-          sizes.put(colSize);
+          sizes.add(colSize);
         }
       }
       json.put("colSize", (JSONArray) sizes);

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java
(original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java
Sat Dec  4 22:29:42 2010
@@ -25,8 +25,8 @@ import java.util.HashSet;
 import javax.xml.bind.annotation.XmlElement;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
 
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
 
@@ -46,43 +46,47 @@ public class ParametersBean {
   
   public ParametersBean(JSONObject json) throws ParseException {
     try {
-      name=json.getString("name");
-      type=json.getString("type");
-      if(json.has("value")) {
+      name=(String) json.get("name");
+      type=(String) json.get("type");
+      if(json.containsKey("value")) {
         if(json.get("value").getClass()==JSONArray.class) {
-          JSONArray ja = json.getJSONArray("value");
+          JSONArray ja = (JSONArray) json.get("value");
           Collection<String> c = new HashSet<String>();
-          for(int i = 0; i < ja.length(); i++) {
-            c.add(ja.getString(i));
+          for(int i = 0; i < ja.size(); i++) {
+            c.add((String) ja.get(i));
           }
           this.value = c;
         } else {
           Collection<String> c = new HashSet<String>();
-          c.add(json.getString("value"));
+          c.add((String)json.get("value"));
           this.value = c;
         }        
       }
-      if(json.has("label")) {
-        label=json.getString("label");
+      if(json.containsKey("label")) {
+        label=(String) json.get("label");
       } else {
-        label=json.getString("name");
+        label=(String) json.get("name");
       }
       if(json.get("type").toString().intern()=="custom".intern()) {
-        control=json.getString("control");
+        control=(String) json.get("control");
       }
-      if(json.has("callback")) {
-        callback=json.getString("callback");
+      if(json.containsKey("callback")) {
+        callback=(String) json.get("callback");
       }
-      if(json.has("options")) {
-        JSONArray aj = json.getJSONArray("options");
-        options = new OptionBean[aj.length()];
-        for(int i=0;i<aj.length();i++) {
-          OptionBean o = new OptionBean(aj.getJSONObject(i));
+      if(json.containsKey("options")) {
+        JSONArray aj = (JSONArray) json.get("options");
+        options = new OptionBean[aj.size()];
+        for(int i=0;i<aj.size();i++) {
+          OptionBean o = new OptionBean((JSONObject) aj.get(i));
           options[i]=o;
         }
       }
-      if(json.has("edit")) {
-        edit=json.getInt("edit");
+      if(json.containsKey("edit")) {
+        if(json.get("edit").getClass().equals(String.class)) {
+          edit=(new Integer((String)json.get("edit"))).intValue();          
+        } else if(json.get("edit").getClass().equals(Long.class)) {
+          edit=((Long)json.get("edit")).intValue();          
+        }
       }
     } catch (Exception e) {
       log.error(ExceptionUtil.getStackTrace(e));
@@ -170,7 +174,7 @@ public class ParametersBean {
       if(this.value!=null) {
         JSONArray ja = new JSONArray();
         for(String s : this.value) {
-          ja.put(s);
+          ja.add(s);
         }
         json.put("value", ja);
       }
@@ -185,7 +189,7 @@ public class ParametersBean {
       if(options!=null) {
         JSONArray ja = new JSONArray();
         for(int i=0;i<options.length;i++) {
-          ja.put(this.options[i].deserialize());          
+          ja.add(this.options[i].deserialize());          
         }
         json.put("options", ja);
       }

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java Sat Dec
 4 22:29:42 2010
@@ -26,9 +26,9 @@ import javax.xml.bind.annotation.XmlType
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
 
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
 
@@ -47,10 +47,10 @@ public class UserBean {
   
   public UserBean(JSONObject json) throws ParseException {
     try {
-      id = json.getString("id");
-      views = json.getJSONArray("views");
-      if(json.has("properties")) {
-        properties = json.getJSONObject("properties");
+      id = (String) json.get("id");
+      views = (JSONArray) json.get("views");
+      if(json.containsKey("properties")) {
+        properties = (JSONObject) json.get("properties");
       } else {
         properties = new JSONObject();
       }
@@ -77,14 +77,14 @@ public class UserBean {
 
   public void setProperties(String buffer) {
     try {
-      this.properties = new JSONObject(buffer);
+      this.properties = (JSONObject) JSONValue.parse(buffer);
     } catch (Exception e) {
       log.error(ExceptionUtil.getStackTrace(e));
     }
   }
   
-  public String getPropertyValue(String key) throws JSONException {
-    return this.properties.getString(key);
+  public String getPropertyValue(String key) {
+    return (String) this.properties.get(key);
   }
   
   public void setId(String id) {

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java Sat Dec
 4 22:29:42 2010
@@ -26,9 +26,9 @@ import javax.xml.bind.annotation.XmlType
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
 
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
 
@@ -46,23 +46,26 @@ public class ViewBean {
   public ViewBean() {  
   }
   
-  public ViewBean(JSONObject json) throws ParseException {
+  public ViewBean(byte[] buffer) throws ParseException {
+    JSONParser parser = new JSONParser();
     try {
-      if(json.has("description")) {
-        this.description = json.getString("description");
+      JSONObject json = (JSONObject) parser.parse(new String(buffer));
+      if(json.containsKey("description")) {
+        this.description = (String) json.get("description");
       } else {
         this.description = "";
       }
-      this.owner=json.getString("owner");
-      this.name=json.getString("name");
-      this.permissionType=json.getString("permissionType");
-      int size = json.getJSONArray("pages").length();
+      this.owner= (String) json.get("owner");
+      this.name= (String) json.get("name");
+      this.permissionType= (String) json.get("permissionType");
+      int size = ((JSONArray) json.get("pages")).size();
       PagesBean[] pages = new PagesBean[size];
+      JSONArray pagesArray = (JSONArray) json.get("pages");
       for(int i=0;i<size;i++) {
-        pages[i] = new PagesBean(json.getJSONArray("pages").getJSONObject(i));
+        pages[i] = new PagesBean((JSONObject) pagesArray.get(i));
       }
       this.pages=pages;
-    } catch (JSONException e) {
+    } catch (Exception e) {
       log.error(ExceptionUtil.getStackTrace(e));
       throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
     }
@@ -126,22 +129,23 @@ public class ViewBean {
     }
   }
   
-  public String deserialize() {
+  @SuppressWarnings("unchecked")
+  public JSONObject deserialize() {
     update();
-    JSONObject json = new JSONObject();
+    JSONObject view = new JSONObject();
     try {
-      json.put("name", this.name);
-      json.put("owner", this.owner);
-      json.put("permissionType", this.permissionType);
-      json.put("description", this.description);
+      view.put("name", this.name);
+      view.put("owner", this.owner);
+      view.put("permissionType", this.permissionType);
+      view.put("description", this.description);
       JSONArray ja = new JSONArray();
       for(int i=0;i<this.pages.length;i++) {
-        ja.put(this.pages[i].deserialize());
+        ja.add(this.pages[i].deserialize());
       }
-      json.put("pages", (JSONArray) ja);
+      view.put("pages", (JSONArray) ja);
     } catch (Exception e){
       log.error(ExceptionUtil.getStackTrace(e));
     }
-    return json.toString();
+    return view;
   }
 }

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java (original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java Sat
Dec  4 22:29:42 2010
@@ -27,9 +27,8 @@ import javax.xml.bind.annotation.XmlType
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
 
 import org.apache.hadoop.chukwa.datastore.WidgetStore;
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
@@ -53,24 +52,30 @@ public class WidgetBean {
   
   public WidgetBean(JSONObject json) throws ParseException {
     try {
-      this.id=json.getString("id");
-      this.title=json.getString("title");
-      this.version=json.getString("version");
-      this.categories=json.getString("categories");
-      this.url=json.getString("url");
-      this.description=json.getString("description");
-      this.refresh=json.getInt("refresh");
+      this.id=(String) json.get("id");
+      this.title=(String) json.get("title");
+      this.version=(String) json.get("version");
+      this.categories=(String) json.get("categories");
+      this.url=(String) json.get("url");
+      this.description=(String) json.get("description");
+      if(json.get("refresh").getClass().equals("String")) {
+        int refresh = Integer.parseInt((String) json.get("refresh"));
+        this.refresh = refresh;
+      } else if(json.get("refresh").getClass().equals("Long")) {
+        this.refresh = ((Long) json.get("refresh")).intValue();
+      }
       try {
-        int size = json.getJSONArray("parameters").length();
+        int size = ((JSONArray) json.get("parameters")).size();
         ParametersBean[] list = new ParametersBean[size];
         for(int i=0;i<size;i++) {
-          list[i] = new ParametersBean(json.getJSONArray("parameters").getJSONObject(i));
+          JSONArray jsonArray = (JSONArray) json.get("parameters");
+          list[i] = new ParametersBean((JSONObject) jsonArray.get(i));
         }
         this.parameters=list;
-      } catch (JSONException e) {
+      } catch (Exception e) {
         this.parameters=null;
       }
-    } catch (JSONException e) {
+    } catch (Exception e) {
       log.error(ExceptionUtil.getStackTrace(e));
       throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
     }
@@ -186,12 +191,12 @@ public class WidgetBean {
       json.put("description", this.description);
       json.put("version", this.version);
       json.put("categories", this.categories);
-      json.put("refresh",this.refresh);
+      json.put("refresh", this.refresh);
       json.put("url", this.url);
       JSONArray ja = new JSONArray();
       if(this.parameters!=null) {
         for(int i=0;i<this.parameters.length;i++) {
-          ja.put(this.parameters[i].deserialize());
+          ja.add(this.parameters[i].deserialize());
         }
       }
       json.put("parameters", (JSONArray) ja);

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java
(original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java
Sat Dec  4 22:29:42 2010
@@ -88,6 +88,7 @@ public class ViewResource {
       if(owner.intern()==request.getRemoteUser().intern()) {
         ViewStore vs = new ViewStore(owner, vid);
         ViewBean view = vs.get();
+        vs.delete();
         view.setPermissionType(permission);
         vs.set(view);
       } else {
@@ -132,7 +133,6 @@ public class ViewResource {
   public ReturnCodeBean deleteView(@Context HttpServletRequest request, @PathParam("owner")
String owner, @PathParam("vid") String vid) {
     try {
       if(owner.intern()==request.getRemoteUser().intern()) {
-        log.info("owner: "+owner+" vid: "+vid);
         ViewStore vs = new ViewStore(owner, vid);
         vs.delete();
       } else {
@@ -156,7 +156,7 @@ public class ViewResource {
       if(uid==null) {
         uid = request.getRemoteUser();
       }
-      result = ViewStore.list(uid).toString();
+      result = ViewStore.list(uid).toJSONString();
     } catch (Exception e) {
       throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
           .entity("View does not exist.").build());

Modified: incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/database/TestDatabaseWebJson.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/database/TestDatabaseWebJson.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/database/TestDatabaseWebJson.java
(original)
+++ incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/database/TestDatabaseWebJson.java
Sat Dec  4 22:29:42 2010
@@ -29,6 +29,9 @@ import org.apache.commons.httpclient.par
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.json.*;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
 import org.mortbay.jetty.Server;
 import org.mortbay.xml.XmlConfiguration;
 import org.apache.hadoop.chukwa.util.*;
@@ -202,9 +205,9 @@ public class TestDatabaseWebJson extends
 	    String cluster = "demo";
 	    DatabaseWriter db = new DatabaseWriter(cluster);
 
-	    JSONArray json_array=new JSONArray(json_str);
-	    for (int i=0; i < json_array.length(); i++) {
-		JSONObject row_obj=json_array.getJSONObject(i);
+	    JSONArray json_array=(JSONArray)JSONValue.parse(json_str);
+	    for (int i=0; i < json_array.size(); i++) {
+		JSONObject row_obj=(JSONObject) json_array.get(i);
 
 		// get the database row
 
@@ -214,7 +217,7 @@ public class TestDatabaseWebJson extends
 		// move to the first record
 		rs.next();
 		ResultSetMetaData md=rs.getMetaData();
-		Iterator names=row_obj.keys();
+		Iterator names=row_obj.keySet().iterator();
 		while (names.hasNext()) {
 		    String name=(String)names.next();
 		    String jsonValue=(String)row_obj.get(name);

Modified: incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/TestUserResource.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/TestUserResource.java?rev=1042251&r1=1042250&r2=1042251&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/TestUserResource.java
(original)
+++ incubator/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/TestUserResource.java
Sat Dec  4 22:29:42 2010
@@ -17,12 +17,12 @@
  */
 package org.apache.hadoop.chukwa.rest.resource;
 
-import org.json.JSONObject;
+import org.json.simple.JSONObject;
 
 import org.apache.hadoop.chukwa.rest.bean.ReturnCodeBean;
 import org.apache.hadoop.chukwa.rest.bean.UserBean;
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
-import org.json.JSONArray;
+import org.json.simple.JSONArray;
 
 import com.sun.jersey.api.client.Client;
 



Mime
View raw message