chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r885291 [1/7] - in /hadoop/chukwa/trunk: ./ conf/ contrib/chukwa-pig/ ivy/ src/java/org/apache/hadoop/chukwa/conf/ src/java/org/apache/hadoop/chukwa/datastore/ src/java/org/apache/hadoop/chukwa/hicc/ src/java/org/apache/hadoop/chukwa/rest/b...
Date Sun, 29 Nov 2009 23:16:17 GMT
Author: eyang
Date: Sun Nov 29 23:16:13 2009
New Revision: 885291

URL: http://svn.apache.org/viewvc?rev=885291&view=rev
Log:
CHUKWA-207.  Store HICC dashboard in HDFS. (Eric Yang)

Added:
    hadoop/chukwa/trunk/conf/auth.conf
    hadoop/chukwa/trunk/conf/chukwa-common.xml.template
    hadoop/chukwa/trunk/contrib/chukwa-pig/chukwa-pig.jar
      - copied, changed from r816347, hadoop/chukwa/trunk/contrib/chukwa-pig/chukwa-pig.jar
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CatalogBean.java
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CategoryBean.java
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ReturnCodeBean.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/UserResource.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewContextResolver.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java   (with props)
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/WidgetContextResolver.java
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/WidgetResource.java   (with props)
    hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/
    hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/SetupTestEnv.java
    hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/TestUserResource.java
    hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/TestViewResource.java
    hadoop/chukwa/trunk/src/test/org/apache/hadoop/chukwa/rest/resource/TestWidgetResource.java
    hadoop/chukwa/trunk/src/web/hicc/css/images/titlebar.png   (with props)
    hadoop/chukwa/trunk/src/web/hicc/images/application_edit.png   (with props)
    hadoop/chukwa/trunk/src/web/hicc/images/bullet_arrow_top.png   (with props)
    hadoop/chukwa/trunk/src/web/hicc/images/bullet_white.png   (with props)
    hadoop/chukwa/trunk/src/web/hicc/images/clone.png   (with props)
    hadoop/chukwa/trunk/src/web/hicc/js/jquery-1.3.2.min.js
Modified:
    hadoop/chukwa/trunk/CHANGES.txt
    hadoop/chukwa/trunk/build.xml
    hadoop/chukwa/trunk/ivy.xml
    hadoop/chukwa/trunk/ivy/libraries.properties
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/conf/ChukwaConfiguration.java
    hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/HiccWebServer.java
    hadoop/chukwa/trunk/src/web/hicc/WEB-INF/jetty.xml
    hadoop/chukwa/trunk/src/web/hicc/WEB-INF/web.xml
    hadoop/chukwa/trunk/src/web/hicc/css/default.css
    hadoop/chukwa/trunk/src/web/hicc/descriptors/client_trace.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/cluster_disk.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/cluster_disk_pcnt.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/cluster_metrics.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/cluster_metrics_pcnt.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/cluster_selector.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/debug.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/dfs_datanode_counter.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/dfs_datanode_rate.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/dfs_fsnamesystem.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/dfs_namenode_counter.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/dfs_namenode_rate.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/dfs_throughput.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/disk.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/disk_pcnt.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/event_viewer.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/hadoop_jvm_counter.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/hadoop_jvm_rate.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/hadoop_mapred.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/heatmap-static.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/heatmap_datanode.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/host_selector.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/node_activity_chart.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/rpc_metrics.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/sql_client.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/swimlanes-static.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/swimlanes.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/system_metrics.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/system_metrics_pcnt.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/time.descriptor
    hadoop/chukwa/trunk/src/web/hicc/descriptors/utilization.descriptor
    hadoop/chukwa/trunk/src/web/hicc/index.jsp
    hadoop/chukwa/trunk/src/web/hicc/js/treeview-min.js
    hadoop/chukwa/trunk/src/web/hicc/js/workspace/custom_edits.js
    hadoop/chukwa/trunk/src/web/hicc/js/workspace/workspace.js
    hadoop/chukwa/trunk/src/web/hicc/js/yahoo-dom-event.js
    hadoop/chukwa/trunk/src/web/hicc/jsp/chart.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/event_viewer_helper.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/heatmap_datanode.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/job_viewer.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/swimlanes.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/table_viewer.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/time_range.jsp
    hadoop/chukwa/trunk/src/web/hicc/views/default.view

Modified: hadoop/chukwa/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/CHANGES.txt?rev=885291&r1=885290&r2=885291&view=diff
==============================================================================
--- hadoop/chukwa/trunk/CHANGES.txt (original)
+++ hadoop/chukwa/trunk/CHANGES.txt Sun Nov 29 23:16:13 2009
@@ -8,6 +8,8 @@
  
    IMPROVEMENTS
 
+    CHUKWA-207. Store HICC dashboard data in HDFS. (Eric Yang)
+
     CHUKWA-415. Read initial adaptors at start every time. (asrabkin)
 
     CHUKWA-413. Improve admin guide. (asrabkin)

Modified: hadoop/chukwa/trunk/build.xml
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/build.xml?rev=885291&r1=885290&r2=885291&view=diff
==============================================================================
--- hadoop/chukwa/trunk/build.xml (original)
+++ hadoop/chukwa/trunk/build.xml Sun Nov 29 23:16:13 2009
@@ -466,6 +466,7 @@
 	<target name="test-chukwa" depends="compile,compile-test,compress" description="Run Chukwa unit tests">
 		<mkdir dir="${test.build.dir}/var" />
 		<mkdir dir="${test.build.dir}/var/log" />
+		<mkdir dir="${test.build.dir}/var/run" />
 		<mkdir dir="${test.build.classes}/webapps" />
 		<mkdir dir="${test.build.classes}/logs" />
                 <copy todir="${test.build.dir}/var/log">
@@ -480,22 +481,52 @@
                 </copy>
                 <copy todir="${test.build.classes}/webapps">
                   <fileset dir="${build.dir}">
-                    <include name="chukwa.war" />
+                    <!-- include name="chukwa.war" / -->
                     <include name="hicc.war" />
                   </fileset>
                 </copy>
-                <copy file="${basedir}/conf/chukwa-demux-conf.xml" tofile="${test.build.dir}/conf/chukwa-demux-conf.xml"></copy>
+                <copy file="${conf.dir}/chukwa-common.xml.template" tofile="${test.build.dir}/conf/chukwa-common.xml">
+			<filterchain>
+				<replacetokens>
+					<token key="CHUKWA_DIR" value="/tmp/chukwa" />
+				</replacetokens>
+			</filterchain>
+                </copy>
+                <copy file="${basedir}/conf/chukwa-demux-conf.xml.template" tofile="${test.build.dir}/conf/chukwa-demux-conf.xml">
+			<filterchain>
+		
+			    <replacetokens>
+					<token key="TODO-DEMUX-IO-SORT-MB" value="${TODO-DEMUX-IO-SORT-MB}" />
+				</replacetokens>
+				<replacetokens>
+					<token key="TODO-DEMUX-FS-INMEMORY-SIZE_MB" value="${TODO-DEMUX-FS-INMEMORY-SIZE_MB}" />
+				</replacetokens>
+				<replacetokens>
+					<token key="TODO-DEMUX-IO-SORT-FACTOR" value="${TODO-DEMUX-IO-SORT-FACTOR}" />
+				</replacetokens>
+
+			</filterchain>
+                </copy>
                 <copy file="${basedir}/conf/log4j.properties" tofile="${test.build.dir}/conf/log4j.properties"></copy>
                 <copy file="${build.dir}/hicc.war" tofile="${test.build.classes}/webapps/hicc.war"></copy>
+                <copy file="${basedir}/conf/auth.conf" tofile="${test.build.dir}/var/auth.conf"></copy>
 		<junit showoutput="${test.output}" fork="yes" printsummary="${test.printsummary}" forkmode="${test.junit.fork.mode}" maxmemory="${test.junit.maxmemory}" dir="${test.build.dir}/classes/" timeout="${test.timeout}" errorProperty="tests.failed" failureProperty="tests.failed">
 			<classpath refid="testClasspath" />
 			<env key="CHUKWA_CONF_DIR" value="${test.build.dir}/conf" />
 			<env key="CHUKWA_DATA_DIR" value="${test.build.dir}/var" />
 			<env key="CHUKWA_LOG_DIR" value="${test.build.dir}/var/log" />
+			<env key="CHUKWA_PID_DIR" value="${test.build.dir}/var/run" />
+			<env key="CHUKWA_HDFS" value="/chukwa" />
 			<env key="CHUKWA_HOME" value="${test.build.classes}" />
 			<sysproperty key="test.src.dir" value="${test.src.dir}" />
 			<sysproperty key="test.build.classes" value="${test.build.classes}" />
 			<sysproperty key="log4j.configuration" value="log4j.properties" />
+			<sysproperty key="CHUKWA_DATA_DIR" value="${test.build.dir}/var" />
+			<sysproperty key="CHUKWA_CONF_DIR" value="${test.build.dir}/conf" />
+			<sysproperty key="CHUKWA_LOG_DIR" value="${test.build.dir}/var/log" />
+			<sysproperty key="CHUKWA_PID_DIR" value="${test.build.dir}/var/run" />
+			<sysproperty key="CHUKWA_HDFS" value="/chukwa" />
+			<sysproperty key="CHUKWA_HOME" value="${test.build.classes}" />
 			<formatter type="${test.junit.output.format}" />
 			<batchtest todir="${test.build.dir}" unless="testcase">
 				<fileset dir="${test.src.dir}">
@@ -1011,7 +1042,7 @@
 	</target>
 
 	<target name="chukwa-config" description="create real files based on templates" depends="init">
-
+                <mkdir dir="${build.dir}/conf" />
 		<copy todir="${build.dir}/conf">
 			<fileset dir="${basedir}/conf">
 				<exclude name="*.template" />
@@ -1021,6 +1052,14 @@
 		<copy file="${basedir}/conf/jdbc.conf.template" tofile="${build.dir}/conf/jdbc.conf.template">
 		</copy>
 
+                <copy file="${conf.dir}/chukwa-common.xml.template" tofile="${build.dir}/conf/chukwa-common.xml">
+			<filterchain>
+				<replacetokens>
+					<token key="CHUKWA_DIR" value="/chukwa" />
+				</replacetokens>
+			</filterchain>
+                </copy>
+
 		<copy file="${basedir}/conf/alert.template" tofile="${build.dir}/conf/alert">
 			<filterchain>
 				<replacetokens>

Added: hadoop/chukwa/trunk/conf/auth.conf
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/conf/auth.conf?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/conf/auth.conf (added)
+++ hadoop/chukwa/trunk/conf/auth.conf Sun Nov 29 23:16:13 2009
@@ -0,0 +1 @@
+admin: admin, user

Added: hadoop/chukwa/trunk/conf/chukwa-common.xml.template
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/conf/chukwa-common.xml.template?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/conf/chukwa-common.xml.template (added)
+++ hadoop/chukwa/trunk/conf/chukwa-common.xml.template Sun Nov 29 23:16:13 2009
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!--
+   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.
+-->
+<?xml-stylesheet type="text/xsl"  href="configuration.xsl"?>
+
+<!-- Global Chukwa Configuration file. -->
+
+<configuration>
+
+  <property>
+    <name>chukwa.data.dir</name>
+    <value>@CHUKWA_DIR@</value>
+    <description>Location of Chukwa data on HDFS</description>
+  </property>
+  
+</configuration>

Copied: hadoop/chukwa/trunk/contrib/chukwa-pig/chukwa-pig.jar (from r816347, hadoop/chukwa/trunk/contrib/chukwa-pig/chukwa-pig.jar)
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/contrib/chukwa-pig/chukwa-pig.jar?p2=hadoop/chukwa/trunk/contrib/chukwa-pig/chukwa-pig.jar&p1=hadoop/chukwa/trunk/contrib/chukwa-pig/chukwa-pig.jar&r1=816347&r2=885291&rev=885291&view=diff
==============================================================================
Binary files - no diff available.

Modified: hadoop/chukwa/trunk/ivy.xml
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/ivy.xml?rev=885291&r1=885290&r2=885291&view=diff
==============================================================================
--- hadoop/chukwa/trunk/ivy.xml (original)
+++ hadoop/chukwa/trunk/ivy.xml Sun Nov 29 23:16:13 2009
@@ -145,14 +145,22 @@
       name="servlet-api-2.5"
       rev="${jetty.version}"
       conf="jetty->master"/>
-    <dependency org="org.apache.ant"
+<!--    <dependency org="org.apache.ant"
       name="ant"
       rev="${jetty.ant.version}"
-      conf="common->default"/>
+      conf="common->default"/> -->
     <dependency org="org.eclipse.jdt"
       name="core"
       rev="${jetty.eclipse.jdt.core.version}"
       conf="jetty->master"/>
+<!--    <dependency org="jaxb"
+      name="jaxb-api"
+      rev="${jaxb.version}"
+      conf="jetty->master"/>
+    <dependency org="jaxb"
+      name="jaxb-impl"
+      rev="${jaxb.version}"
+      conf="jetty->master"/> -->
 <!--    <dependency org="org.apache.tomcat"
       name="jasper"
       rev="${jasper.version}"

Modified: hadoop/chukwa/trunk/ivy/libraries.properties
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/ivy/libraries.properties?rev=885291&r1=885290&r2=885291&view=diff
==============================================================================
--- hadoop/chukwa/trunk/ivy/libraries.properties (original)
+++ hadoop/chukwa/trunk/ivy/libraries.properties Sun Nov 29 23:16:13 2009
@@ -47,3 +47,4 @@
 jdiff.version=1.0.9
 xmlenc.version=0.52
 xerces.version=1.4.4
+#jaxb.version=2.1.12

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/conf/ChukwaConfiguration.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/conf/ChukwaConfiguration.java?rev=885291&r1=885290&r2=885291&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/conf/ChukwaConfiguration.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/conf/ChukwaConfiguration.java Sun Nov 29 23:16:13 2009
@@ -50,6 +50,9 @@
 
       log.info("chukwaConf is " + chukwaConf);
 
+      super.addResource(new Path(chukwaConf + "/chukwa-common.xml"));
+      log.debug("added chukwa-agent-conf.xml to ChukwaConfiguration");
+
       super.addResource(new Path(chukwaConf + "/chukwa-agent-conf.xml"));
       log.debug("added chukwa-agent-conf.xml to ChukwaConfiguration");
 

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,136 @@
+package org.apache.hadoop.chukwa.datastore;
+
+import java.io.File;
+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.apache.hadoop.chukwa.conf.ChukwaConfiguration;
+import org.apache.hadoop.chukwa.hicc.HiccWebServer;
+import org.apache.hadoop.chukwa.rest.bean.UserBean;
+import org.apache.hadoop.chukwa.util.ExceptionUtil;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+public class UserStore {
+  private String uid = null;
+  private UserBean profile = null;
+  private static Log log = LogFactory.getLog(UserStore.class);
+  private static Configuration config = new Configuration();
+  private static ChukwaConfiguration chukwaConf = new ChukwaConfiguration();
+  private static String hiccPath = config.get("fs.default.name")+File.separator+chukwaConf.get("chukwa.data.dir")+File.separator+"hicc"+File.separator+"users";
+  
+  public UserStore() throws IllegalAccessException {
+    UserStore.config = HiccWebServer.getConfig();
+  }
+
+  public UserStore(String uid) throws IllegalAccessException {
+    this.uid = uid;
+    init(uid);
+  }
+
+  public void init(String uid) throws IllegalAccessException {
+    StringBuilder profilePath = new StringBuilder();
+    profilePath.append(hiccPath);
+    profilePath.append(File.separator);
+    profilePath.append(uid);
+    profilePath.append(".profile");
+    Path profileFile = new Path(profilePath.toString());
+    FileSystem fs;
+    try {
+      fs = FileSystem.get(config);
+      if(fs.exists(profileFile)) {
+        FileStatus[] fstatus = fs.listStatus(profileFile);
+        long size = fstatus[0].getLen();
+        FSDataInputStream viewStream = fs.open(profileFile);
+        byte[] buffer = new byte[(int)size];
+        viewStream.readFully(buffer);
+        viewStream.close();
+        try {
+          JSONObject json = new JSONObject(new String(buffer));
+          profile = new UserBean(json);
+        } catch (Exception e) {
+          log.error(ExceptionUtil.getStackTrace(e));
+          throw new IllegalAccessException("Unable to access user profile database.");
+        }
+      } else {
+        profile = new UserBean();
+        profile.setId(uid);
+        JSONArray ja = new JSONArray();
+        profile.setViews(ja);
+        JSONObject json = new JSONObject();
+        profile.setProperties(json);
+      }
+    } catch (IOException ex) {
+      log.error(ExceptionUtil.getStackTrace(ex));
+    }
+  }
+  
+  public UserBean get() throws IllegalAccessException {
+    if(profile==null) {
+      init(uid);
+    }
+    return profile;
+  }
+  
+  public void set(UserBean profile) throws IllegalAccessException {
+    StringBuilder profilePath = new StringBuilder();
+    profilePath.append(hiccPath);
+    profilePath.append(File.separator);
+    profilePath.append(profile.getId());
+    profilePath.append(".profile");
+    Path profileFile = new Path(profilePath.toString());
+    FileSystem fs;
+    try {
+      fs = FileSystem.get(config);
+      FSDataOutputStream out = fs.create(profileFile,true);
+      out.write(profile.deserialize().toString().getBytes());
+      out.close();
+    } catch (IOException ex) {
+      log.error(ExceptionUtil.getStackTrace(ex));
+      throw new IllegalAccessException("Unable to access user profile database.");
+    }
+    this.profile = profile;
+  }
+  
+  public static JSONArray list() throws IllegalAccessException {
+    StringBuilder profilePath = new StringBuilder();
+    profilePath.append(hiccPath);
+    profilePath.append(File.separator);
+    profilePath.append("*.profile");
+    Path viewFile = new Path(profilePath.toString());
+    FileSystem fs;
+    JSONArray list = new JSONArray();
+    try {
+      fs = FileSystem.get(config);
+      FileStatus[] fstatus = fs.listStatus(viewFile);
+      if(fstatus!=null) {
+        for(int i=0;i<fstatus.length;i++) {
+          long size = fstatus[i].getLen();
+          FSDataInputStream profileStream = fs.open(fstatus[i].getPath());
+          byte[] buffer = new byte[(int)size];
+          profileStream.readFully(buffer);
+          profileStream.close();
+          try {
+            UserBean user = new UserBean(new JSONObject(new String(buffer)));
+            list.put(user.getId());
+          } catch (Exception e) {
+            log.error(ExceptionUtil.getStackTrace(e));
+          }
+        }
+      }
+    } catch (IOException ex) {
+      log.error(ExceptionUtil.getStackTrace(ex));
+      throw new IllegalAccessException("Unable to access user profile database."); 
+    }
+    return list;    
+  }
+}
+           
\ No newline at end of file

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/UserStore.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,223 @@
+package org.apache.hadoop.chukwa.datastore;
+
+import java.io.File;
+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.apache.hadoop.chukwa.conf.ChukwaConfiguration;
+import org.apache.hadoop.chukwa.hicc.HiccWebServer;
+import org.apache.hadoop.chukwa.rest.bean.ViewBean;
+import org.apache.hadoop.chukwa.util.ExceptionUtil;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+public class ViewStore {
+  private String vid = null;
+  private String uid = null;
+  private ViewBean view = null;
+  private static Log log = LogFactory.getLog(ViewStore.class);
+  private static Configuration config = new Configuration();
+  private static ChukwaConfiguration chukwaConf = new ChukwaConfiguration();
+  private static String viewPath = config.get("fs.default.name")+File.separator+chukwaConf.get("chukwa.data.dir")+File.separator+"hicc"+File.separator+"views";
+  private static String publicViewPath = viewPath+File.separator+"public";
+  private static String usersViewPath = viewPath+File.separator+"users";
+  private static String PUBLIC = "PUBLIC".intern();
+  private static String PRIVATE = "PRIVATE".intern();
+
+  public ViewStore() throws IllegalAccessException {
+    ViewStore.config = HiccWebServer.getConfig();
+  }
+
+  public ViewStore(String uid, String vid) throws IllegalAccessException {
+    this.uid=uid;
+    this.vid=vid;
+    load(uid, vid);
+  }
+
+  public void load(String uid, String vid) throws IllegalAccessException {
+    StringBuilder vp = new StringBuilder();
+    vp.append(usersViewPath);
+    vp.append(File.separator);
+    vp.append(uid);
+    vp.append(File.separator);
+    vp.append(vid);
+    vp.append(".view");
+    Path viewFile = new Path(vp.toString());
+    try {
+      FileSystem fs = FileSystem.get(config);
+      if(!fs.exists(viewFile)) {
+        StringBuilder pubPath = new StringBuilder();
+        pubPath.append(publicViewPath);
+        pubPath.append(File.separator);
+        pubPath.append(vid);
+        pubPath.append(".view");
+        viewFile = new Path(pubPath.toString());        
+      }
+      if(fs.exists(viewFile)) {
+        FileStatus[] fstatus = fs.listStatus(viewFile);
+        long size = fstatus[0].getLen();
+        FSDataInputStream viewStream = fs.open(viewFile);
+        byte[] buffer = new byte[(int)size];
+        viewStream.readFully(buffer);
+        viewStream.close();
+        try {
+          view = new ViewBean(new JSONObject(new String(buffer)));
+          view.update();
+        } catch (Exception e) {
+          log.error(ExceptionUtil.getStackTrace(e));
+          throw new IllegalAccessException("Unable to access view: "+vid);
+        }
+      }
+    } catch (IOException ex) {
+      log.error(ExceptionUtil.getStackTrace(ex));
+    }
+  }
+  
+  public String getMessage() {
+    return view.toString();  
+  }
+  
+  public ViewBean get() throws IllegalAccessException {
+    if(view==null) {
+      load(uid, vid);
+    }
+    if(view==null) {
+      // Display global default view if user default view does not exist.
+      try {
+        load(null, vid);
+      } catch(Exception e) {
+        log.error(ExceptionUtil.getStackTrace(e));
+        view = null;
+      }
+    }
+    return view;
+  }
+  
+  public void set(ViewBean view) throws IllegalAccessException {
+    try {
+      if (this.view == null || (this.view.getOwner().intern() == view.getOwner().intern())) {
+        if(this.view!=null) {
+          delete();
+        }
+        StringBuilder viewPath = new StringBuilder();
+        if(view.getPermissionType().intern()==PUBLIC) {
+          viewPath.append(publicViewPath);
+        } else {
+          viewPath.append(usersViewPath);
+          viewPath.append(File.separator);
+          viewPath.append(uid);
+        }
+        viewPath.append(File.separator);
+        viewPath.append(view.getName());
+        viewPath.append(".view");
+        Path viewFile = new Path(viewPath.toString());
+        try {
+          FileSystem fs = FileSystem.get(config);
+          FSDataOutputStream out = fs.create(viewFile,true);
+          out.write(view.deserialize().toString().getBytes());
+          out.close();
+        } catch (IOException ex) {
+          log.error(ExceptionUtil.getStackTrace(ex));
+        }
+        this.view = view;
+      } else {
+        if(view.getPermissionType().intern()==PUBLIC) {
+          throw new IllegalAccessException("Unable to save public view, duplicated view exists.");
+        } else {
+          throw new IllegalAccessException("Unable to save user view.");          
+        }
+      }
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new IllegalAccessException("Unable to access user view.");
+    }
+  }
+
+  public void delete() throws IllegalAccessException {
+    try {
+      if(this.view==null) {
+        get();
+      }
+      if (this.view!=null) {
+        StringBuilder viewPath = new StringBuilder();
+        if(view.getPermissionType().intern()==PUBLIC) {
+          viewPath.append(publicViewPath);
+        } else {
+          viewPath.append(usersViewPath);
+          viewPath.append(File.separator);
+          viewPath.append(uid);
+        }
+        viewPath.append(File.separator);
+        viewPath.append(view.getName());
+        viewPath.append(".view");
+        Path viewFile = new Path(viewPath.toString());
+        try {
+          FileSystem fs = FileSystem.get(config);
+          fs.delete(viewFile, true);
+        } catch (IOException ex) {
+          log.error(ExceptionUtil.getStackTrace(ex));
+        }
+      } else {
+        throw new IllegalAccessException("Unable to delete user view, view does not exist.");          
+      }
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new IllegalAccessException("Unable to access user view.");
+    }
+  }
+  
+  public static JSONArray list(String uid) throws IllegalAccessException {
+    StringBuilder viewPath = new StringBuilder();
+    viewPath.append(usersViewPath);
+    viewPath.append(File.separator);
+    viewPath.append(uid);
+    String[] pathList = new String[2];
+    pathList[0]=viewPath.toString();
+    pathList[1]=publicViewPath;
+    JSONArray list = new JSONArray();
+    for(String path : pathList) {
+      Path viewFile = new Path(path);
+      try {
+        FileSystem fs = FileSystem.get(config);
+        FileStatus[] fstatus = fs.listStatus(viewFile);
+        if(fstatus!=null) {
+          for(int i=0;i<fstatus.length;i++) {
+            long size = fstatus[i].getLen();
+            FSDataInputStream viewStream = fs.open(fstatus[i].getPath());
+            byte[] buffer = new byte[(int)size];
+            viewStream.readFully(buffer);
+            viewStream.close();
+            try {
+              ViewBean view = new ViewBean(new JSONObject(new String(buffer)));
+              JSONObject json = new JSONObject();
+              json.put("name", view.getName());
+              json.put("type", view.getPermissionType());
+              json.put("owner", view.getOwner());
+              if(uid.intern()==view.getOwner().intern()) {
+                json.put("editable","true");
+              } else {
+                json.put("editable","false");
+              }
+              list.put(json);
+            } catch (Exception e) {
+              log.error(ExceptionUtil.getStackTrace(e));
+            }
+          }
+        }
+      } catch (IOException ex) {
+        log.error(ExceptionUtil.getStackTrace(ex));
+        throw new IllegalAccessException("Unable to access user view."); 
+      }
+    }
+    return list;
+  }
+}
+           

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/ViewStore.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,106 @@
+package org.apache.hadoop.chukwa.datastore;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONObject;
+
+import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
+import org.apache.hadoop.chukwa.hicc.HiccWebServer;
+import org.apache.hadoop.chukwa.rest.bean.CatalogBean;
+import org.apache.hadoop.chukwa.rest.bean.WidgetBean;
+import org.apache.hadoop.chukwa.util.ExceptionUtil;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+public class WidgetStore {
+  private static Log log = LogFactory.getLog(WidgetStore.class);
+  private static Configuration config = new Configuration();
+  private static ChukwaConfiguration chukwaConf = new ChukwaConfiguration();
+  private static String hiccPath = config.get("fs.default.name")+File.separator+chukwaConf.get("chukwa.data.dir")+File.separator+"hicc"+File.separator+"widgets";
+  private static CatalogBean catalog = null;
+  private static HashMap<String, WidgetBean> list = new HashMap<String, WidgetBean>();
+  
+  public WidgetStore() throws IllegalAccessException {
+    WidgetStore.config = HiccWebServer.getConfig();
+  }
+
+  public void set(WidgetBean widget) throws IllegalAccessException {
+    try {
+      StringBuilder widgetPath = new StringBuilder();
+      widgetPath.append(hiccPath);
+      widgetPath.append(File.separator);
+      widgetPath.append(widget.getId());
+      widgetPath.append(".descriptor");
+      Path widgetFile = new Path(widgetPath.toString());
+      FileSystem fs;
+      try {
+        fs = FileSystem.get(config);
+        FSDataOutputStream out = fs.create(widgetFile,true);
+        out.writeUTF(widget.deserialize().toString());
+        out.close();
+      } catch (IOException ex) {
+        log.error(ExceptionUtil.getStackTrace(ex));
+      }
+      cacheWidgets();
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new IllegalAccessException("Unable to access user view database.");
+    }
+  }
+  
+  public static void cacheWidgets() throws IllegalAccessException {
+    StringBuilder widgetPath = new StringBuilder();
+    widgetPath.append(hiccPath);
+    Path widgetFiles = new Path(widgetPath.toString());
+    FileSystem fs;
+    catalog = new CatalogBean();
+    catalog.setId("root");
+    catalog.setLabel("root");
+    try {
+      fs = FileSystem.get(config);
+      FileStatus[] fstatus = fs.listStatus(widgetFiles);
+      if(fstatus!=null) {
+        for(int i=0;i<fstatus.length;i++) {
+          long size = fstatus[i].getLen();
+          FSDataInputStream widgetStream = fs.open(fstatus[i].getPath());
+          byte[] buffer = new byte[(int)size];
+          widgetStream.readFully(buffer);
+          widgetStream.close();
+          try {
+            WidgetBean widget = new WidgetBean(new JSONObject(new String(buffer)));
+            catalog.addCatalog(widget);
+            list.put(widget.getId(),widget);
+          } catch (Exception e) {
+            log.error(ExceptionUtil.getStackTrace(e));
+          }
+        }
+      }
+    } catch (IOException ex) {
+      log.error(ExceptionUtil.getStackTrace(ex));
+      throw new IllegalAccessException("Unable to access user view database."); 
+    }    
+  }
+
+  public static CatalogBean getCatalog() throws IllegalAccessException {
+    if(catalog==null) {
+      cacheWidgets();
+    }
+    return catalog;
+  }
+  
+  public static HashMap<String, WidgetBean> list() throws IllegalAccessException {
+    if(list.size()==0) {
+      cacheWidgets();
+    }
+    return list;
+  }
+}
+           

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/datastore/WidgetStore.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/HiccWebServer.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/HiccWebServer.java?rev=885291&r1=885290&r2=885291&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/HiccWebServer.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/HiccWebServer.java Sun Nov 29 23:16:13 2009
@@ -17,11 +17,33 @@
  */
 package org.apache.hadoop.chukwa.hicc;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URISyntaxException;
 import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 
+import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
 import org.apache.hadoop.chukwa.util.DaemonWatcher;
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.json.JSONObject;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.handler.ContextHandler;
 import org.mortbay.xml.XmlConfiguration;
@@ -32,16 +54,166 @@
   private static Log log = LogFactory.getLog(HiccWebServer.class);
   private static URL serverConf = null;
   private Server server = null;
+  private String chukwaHdfs;
+  private String hiccData;
+  public static ChukwaConfiguration chukwaConf = new ChukwaConfiguration();
+  public static Configuration config = new Configuration();
+  public static FileSystem fs = null;
+  private static HiccWebServer instance = null;
 
-  public HiccWebServer() {
-    DaemonWatcher.createInstance("hicc");
-    serverConf = HiccWebServer.class.getResource("/WEB-INF/jetty.xml");
-    if(serverConf==null) {
-      log.error("Unable to locate jetty-web.xml.");
-      DaemonWatcher.bailout(-1);
+  protected HiccWebServer() {
+  }
+
+//  public HiccWebServer(Configuration conf) {
+//    config = conf;
+//  }
+//  
+  public static HiccWebServer getInstance() {
+    if(instance==null) {
+      config = new Configuration();
+      instance = new HiccWebServer();
+    }
+    return instance;
+ }
+
+  public void start() {
+    try {
+      if(fs==null) {
+        fs = FileSystem.get(config);
+        chukwaHdfs = config.get("fs.default.name")+File.separator+chukwaConf.get("chukwa.data.dir");
+        hiccData = chukwaHdfs+File.separator+"hicc";
+        DaemonWatcher.createInstance("hicc");
+        serverConf = HiccWebServer.class.getResource("/WEB-INF/jetty.xml");
+        if(serverConf==null) {
+          log.error("Unable to locate jetty-web.xml.");
+          DaemonWatcher.bailout(-1);
+        }
+        instance = this;
+        setupDefaultData();
+        run();
+      }
+    } catch(Exception e) {
+      log.error("HDFS unavailable, check configuration in chukwa-env.sh.");
+      System.exit(-1);
     }
   }
+
+  public static Configuration getConfig() {
+    return config;
+  }
+  
+  public static FileSystem getFileSystem() {
+    return fs;
+  }
   
+  public List<String> getResourceListing(String path) throws URISyntaxException, IOException {
+    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+    URL dirURL = contextClassLoader.getResource(path);
+
+    if (dirURL == null) {
+      dirURL = contextClassLoader.getResource(path);
+    }
+    
+    if (dirURL.getProtocol().equals("jar")) {
+      /* A JAR path */
+      String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); //strip out only the JAR file
+      JarFile jar = new JarFile(jarPath);
+      Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
+      List<String> result = new ArrayList<String>(); //avoid duplicates in case it is a subdirectory
+      while(entries.hasMoreElements()) {
+        String name = entries.nextElement().getName();
+        if (name.startsWith(path)) { //filter according to the path
+          String entry = name.substring(path.length());
+          int checkSubdir = entry.indexOf("/");
+          if (checkSubdir == 0 && entry.length()>1) {
+            // if it is a subdirectory, we just return the directory name
+            result.add(name);
+          }
+        }
+      }
+      return result;
+    } 
+      
+    throw new UnsupportedOperationException("Cannot list files for URL "+dirURL);
+  }
+  
+  public void populateDir(List<String> files, Path path) {
+    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+      for(String source : files) {
+        String name = source.substring(source.indexOf(File.separator));
+        Path dest = new Path(path.toString()+File.separator+name);
+        InputStream is = contextClassLoader.getResourceAsStream(source);
+        StringBuilder sb = new StringBuilder();
+        String line = null;
+
+        try {
+          BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+          while ((line = reader.readLine()) != null) {
+            sb.append(line + "\n");
+          }
+          FSDataOutputStream out = fs.create(dest);
+          out.write(sb.toString().getBytes());
+          out.close();
+          } catch(IOException e) {
+            log.error("Error writing file: "+dest.toString());
+          }
+      }
+  }
+  
+  public void setupDefaultData() {
+    Path hiccPath = new Path(hiccData);
+    try {
+      fs = FileSystem.get(config);
+      if(!fs.exists(hiccPath)) {
+        log.info("Initializing HICC Datastore.");
+        // Create chukwa directory
+        if(!fs.exists(new Path(chukwaHdfs))) {
+          fs.mkdirs(new Path(chukwaHdfs));
+        }
+        
+        // Create hicc directory        
+        fs.mkdirs(hiccPath);
+        
+        // Populate widgets repository
+        StringBuffer hiccWidgets = new StringBuffer();
+        hiccWidgets.append(hiccData);
+        hiccWidgets.append(File.separator);
+        hiccWidgets.append("widgets");
+        Path widgetsPath = new Path(hiccWidgets.toString());
+        fs.mkdirs(widgetsPath);
+        List<String> widgets = getResourceListing("descriptors");
+        populateDir(widgets, widgetsPath);
+        
+        // Create views directory
+        StringBuffer hiccViews = new StringBuffer();
+        hiccViews.append(hiccData);
+        hiccViews.append(File.separator);
+        hiccViews.append("views");        
+        fs.mkdirs(new Path(hiccViews.toString()));
+        
+        // Create users repository
+        StringBuffer hiccUsers = new StringBuffer();
+        hiccUsers.append(hiccViews);
+        hiccUsers.append(File.separator);
+        hiccUsers.append("users");
+        fs.mkdirs(new Path(hiccUsers.toString()));
+
+        // Populate public repository
+        StringBuffer hiccPublic = new StringBuffer();
+        hiccPublic.append(hiccViews);
+        hiccPublic.append(File.separator);
+        hiccPublic.append("public");
+        Path viewsPath = new Path(hiccPublic.toString());
+        fs.mkdirs(viewsPath);
+        List<String> views = getResourceListing("views");
+        populateDir(views, viewsPath);
+        log.info("HICC Datastore initialization completed.");
+      }
+    } catch (Exception ex) {
+      log.error(ExceptionUtil.getStackTrace(ex));
+    }
+  }
+
   public void run() {
     server = new Server();
     XmlConfiguration configuration;
@@ -62,8 +234,10 @@
       log.error(ExceptionUtil.getStackTrace(e));
     }
   }
+  
   public static void main(String[] args) {
-    HiccWebServer hicc = new HiccWebServer();
-    hicc.run();
+    HiccWebServer hicc = HiccWebServer.getInstance();
+    hicc.start();
   }
+
 }

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CatalogBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CatalogBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CatalogBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CatalogBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,92 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+@XmlRootElement
+@XmlType(propOrder={"type", "id", "label", "children"})
+public class CatalogBean {
+  private static Log log = LogFactory.getLog(CatalogBean.class);
+  private List<CatalogBean> children = new ArrayList<CatalogBean>();
+  private String type = "text";
+  private String label = null;
+  private String id = null;
+  
+  public CatalogBean() {
+  }
+  
+  @XmlElement
+  public String getType() {
+    return type;
+  }
+  
+  @XmlElement
+  public String getId() {
+    return id;
+  }
+  
+  @XmlElement
+  public String getLabel() {
+    return label;
+  }
+  
+  @XmlElement
+  public List<CatalogBean> getChildren() {
+    return children;
+  }
+  
+  public void setType(String type) {
+    this.type = type;  
+  }
+  
+  public void setId(String id) {
+    this.id = id;
+  }
+  
+  public void setLabel(String label) {
+    this.label = label;
+  }
+  
+  public void setChildren(List<CatalogBean> children) {
+    this.children = children;
+  }
+  
+  public void addCatalog(WidgetBean widget) {
+    String[] path = widget.getCategories().split(",");
+    List<CatalogBean> tracker = this.children;
+    if(tracker==null) {
+      tracker = new ArrayList<CatalogBean>();
+    }
+    for(int i=0;i<path.length;i++) {
+      boolean duplicate = false;
+      for(int j=0;j<tracker.size();j++) {
+        if(tracker.get(j).getLabel().intern()==path[i].intern()) {
+          duplicate = true;
+          tracker = tracker.get(j).getChildren();
+          continue;
+        }
+      }
+      if(!duplicate) {
+        tracker = addCategory(tracker, widget.getId(), path[i]);
+      }
+    }
+    tracker = addCategory(tracker, widget.getId(), widget.getTitle());
+  }
+  
+  public List<CatalogBean> addCategory(List<CatalogBean> tracker, String id, String label) {
+    CatalogBean c = new CatalogBean();
+    c.setId(id);
+    c.setLabel(label);
+    tracker.add(c);
+    return c.getChildren();
+  }
+  
+}

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CategoryBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CategoryBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CategoryBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/CategoryBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,50 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+@XmlType(propOrder={"type", "label", "children"})
+public class CategoryBean {
+  private static Log log = LogFactory.getLog(CategoryBean.class);
+  private List<CategoryBean> children = new ArrayList<CategoryBean>();
+  private String type = "text";
+  private String label = null;
+  
+  public CategoryBean() {
+  }
+  
+  @XmlElement
+  public String getType() {
+    return type;
+  }
+  
+  @XmlElement
+  public String getLabel() {
+    return label;
+  }
+  
+  @XmlElement
+  public List<CategoryBean> getChildren() {
+    return children;
+  }
+  
+  public void setType(String type) {
+    this.type = type;  
+  }
+  
+  public void setLabel(String label) {
+    this.label = label;
+  }
+  
+  public void setChildren(List<CategoryBean> children) {
+    this.children = children;
+  }  
+}

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,59 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.text.ParseException;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlTransient;
+
+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.apache.hadoop.chukwa.util.ExceptionUtil;
+
+public class ColumnBean {
+  private WidgetBean[] widgets;
+  
+  private static Log log = LogFactory.getLog(ColumnBean.class);
+  
+  public 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));
+      }
+    } catch (JSONException e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
+    }
+  }
+  
+  @XmlElement
+  public WidgetBean[] getWidgets() {
+    return widgets;
+  }
+  
+  public void setWidgets(WidgetBean[] ws) {
+    widgets=ws;
+  }
+  
+  public void update() {
+    for(int i=0;i<widgets.length;i++) {
+      widgets[i].update();
+    }
+  }
+  
+  public JSONArray deserialize() {
+    JSONArray ja = new JSONArray();
+    for(int i=0;i<widgets.length;i++) {
+      ja.put(widgets[i].deserialize());
+    }
+    return ja;
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ColumnBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,52 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.text.ParseException;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONObject;
+
+import org.apache.hadoop.chukwa.util.ExceptionUtil;
+
+@XmlRootElement
+@XmlType(propOrder={"key", "value"})
+public class ConfigBean {
+  private String key = null;
+  private String value = null;
+  private static Log log = LogFactory.getLog(ViewBean.class);
+  
+  public ConfigBean() {
+  }
+  
+  public ConfigBean(JSONObject json) throws ParseException {
+    try {
+      key = json.getString("key");
+      value = json.getString("value");
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new ParseException("Error parsing user object.",0);
+    }
+  }
+  
+  @XmlElement
+  public String getKey() {
+    return key;
+  }
+  
+  @XmlElement
+  public String getValue() {
+    return value;
+  }
+  
+  public void setKey(String key) {
+    this.key = key;
+  }
+  
+  public void setValue(String value) {
+    this.value = value;
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ConfigBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,63 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.text.ParseException;
+
+import javax.xml.bind.annotation.XmlElement;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import org.apache.hadoop.chukwa.util.ExceptionUtil;
+
+public class OptionBean {
+  private String label;
+  private String value;
+  private static Log log = LogFactory.getLog(OptionBean.class);
+
+  public OptionBean() {  
+  }
+  
+  public OptionBean(JSONObject json) throws ParseException {
+    try {
+      label = json.getString("label");
+      value = json.getString("value");
+    } catch (JSONException e) {
+      throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
+    }
+  }
+
+  @XmlElement
+  public String getLabel() {
+    return label;
+  }
+  
+  @XmlElement
+  public String getValue() {
+    return value;
+  }
+  
+  public void setLabel(String label) {
+    this.label=label;
+  }
+  
+  public void setValue(String value) {
+    this.value=value;
+  }
+  
+  public void update() {
+    
+  }
+  
+  public JSONObject deserialize() {
+    JSONObject json = new JSONObject();
+    try {
+      json.put("label", label);
+      json.put("value", value);
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+    }
+    return json;
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/OptionBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,115 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.text.ParseException;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+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.apache.hadoop.chukwa.util.ExceptionUtil;
+
+public class PagesBean {
+  private static Log log = LogFactory.getLog(PagesBean.class);
+  private String title;
+  private int[] columnSizes;
+  private ColumnBean[] layout;
+  private int columns;
+  
+  public 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));
+        this.layout[i]=c;
+      }
+    } catch (JSONException e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
+    }
+  }
+  
+  @XmlElement
+  public String getTitle() {
+    return title;
+  }
+
+//  @XmlElement
+//  public String getLayoutStyle() {
+//    return layoutStyle;
+//  }
+
+  @XmlElement(name="layout")
+  public ColumnBean[] getLayout() {
+    return layout;
+  }
+  
+  public void update() {
+    for(int i=0;i<layout.length;i++) {
+      layout[i].update();
+    }
+  }
+  
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public void setLayout(ColumnBean[] layout) {
+    this.layout = layout;
+  }
+
+  @XmlElement(name="colSize")
+  public int[] getColSize() {
+    return this.columnSizes;  
+  }
+  
+  public void setColSize(int[] size) {
+    this.columnSizes = size;    
+  }
+
+  @XmlElement(name="columns")
+  public int getColumns() {
+    return this.columns;
+  }
+  
+  public void setColumns(int columns) {
+    this.columns = columns;
+  }
+  
+  public JSONObject deserialize() {
+    JSONObject json = new JSONObject();
+    JSONArray ja = new JSONArray();
+    JSONArray sizes = new JSONArray();
+    try {
+      json.put("title", this.title);
+      for(int i=0;i<layout.length;i++) {
+        ja.put(layout[i].deserialize());
+      }
+      json.put("layout", (JSONArray) ja);
+      json.put("columns", layout.length);
+      if(columnSizes!=null) {
+        for(int colSize : columnSizes) {
+          sizes.put(colSize);
+        }
+      }
+      json.put("colSize", (JSONArray) sizes);
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+    }
+    return json;
+  }
+
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/PagesBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,128 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.text.ParseException;
+
+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.apache.hadoop.chukwa.util.ExceptionUtil;
+
+public class ParametersBean {
+  private static Log log = LogFactory.getLog(ParametersBean.class);
+  private String name=null;
+  private String type=null;
+  private String value=null;
+  private String control=null;
+  private String label=null;
+  private OptionBean[] options=null;
+  
+  public ParametersBean() {    
+  }
+  
+  public ParametersBean(JSONObject json) throws ParseException {
+    try {
+      name=json.getString("name");
+      type=json.getString("type");
+      value=json.getString("value");
+      if(json.has("label")) {
+        label=json.getString("label");
+      } else {
+        label=json.getString("name");
+      }
+      if(json.get("type").toString().intern()=="custom".intern()) {
+        control=json.getString("control");
+      }
+      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));
+          options[i]=o;
+        }
+      }
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
+    }
+  }
+  
+  @XmlElement
+  public String getName() {
+    return name;
+  }
+  
+  @XmlElement
+  public String getType() {
+    return type;
+  }
+
+  @XmlElement
+  public String getValue() {
+    return value;
+  }
+  
+  @XmlElement
+  public String getControl() {
+    return control;  
+  }
+  
+  @XmlElement
+  public String getLabel() {
+    return label;  
+  }
+  
+  @XmlElement
+  public OptionBean[] getOptions() {
+   return options; 
+  }
+  
+  public void setName(String name) {
+    this.name = name;
+  }
+  
+  public void setType(String type) {
+    this.type = type;
+  }
+  
+  public void setValue(String value) {
+    this.value = value;
+  }
+  
+  public void setControl(String control) {
+    this.control = control;
+  }
+  
+  public void setLabel(String label) {
+    this.label = label;
+  }
+  
+  public void setOptions(OptionBean[] options) {
+    this.options = options;
+  }
+  
+  public JSONObject deserialize() {
+    JSONObject json = new JSONObject();
+    try {
+      json.put("name",this.name);
+      json.put("type",this.type);
+      json.put("value",this.value);
+      if(control!=null) {
+        json.put("control",this.control);
+      }
+      json.put("label",this.label);
+      if(options!=null) {
+        JSONArray ja = new JSONArray();
+        for(int i=0;i<options.length;i++) {
+          ja.put(this.options[i].deserialize());          
+        }
+        json.put("options", (JSONArray) ja);
+      }
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+    }
+    return json;
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ParametersBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ReturnCodeBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ReturnCodeBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ReturnCodeBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ReturnCodeBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,40 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlRootElement
+@XmlType(propOrder={"code", "message"})
+public class ReturnCodeBean {
+  public static int FAIL=0;
+  public static int SUCCESS=1;
+  private int code;
+  private String message;
+  
+  public ReturnCodeBean() {
+  }
+  
+  public ReturnCodeBean(int code, String message) {
+    this.code=code;
+    this.message=message;
+  }
+  
+  @XmlElement
+  public int getCode() {
+    return code;
+  }
+  
+  @XmlElement
+  public String getMessage() {
+    return message;  
+  }
+  
+  public void setCode(int code) {
+    this.code=code;
+  }
+  
+  public void setMessage(String message) {
+    this.message=message;
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ReturnCodeBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,100 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.text.ParseException;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+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.apache.hadoop.chukwa.util.ExceptionUtil;
+
+@XmlRootElement
+@XmlType(propOrder={"id", "views", "properties"})
+public class UserBean {
+  private String id;
+  private JSONArray views;
+  private JSONObject properties;
+  private static Log log = LogFactory.getLog(UserBean.class);
+  
+  public UserBean() {
+    views = new JSONArray();
+    properties = new JSONObject();
+  }
+  
+  public UserBean(JSONObject json) throws ParseException {
+    try {
+      id = json.getString("id");
+      views = json.getJSONArray("views");
+      properties = json.getJSONObject("properties");
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new ParseException("Error parsing user object.",0);
+    }
+  }
+  
+  @XmlElement
+  public String getId() {
+    return id;
+  }
+  
+  @XmlElement
+  public JSONArray getViews() {
+    return views;
+  }
+  
+  @XmlElement
+  public String getProperties() {
+    return properties.toString();
+  }
+
+  public void setProperties(String buffer) {
+    try {
+      this.properties = new JSONObject(buffer);
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+    }
+  }
+  
+  public String getPropertyValue(String key) throws JSONException {
+    return this.properties.getString(key);
+  }
+  
+  public void setId(String id) {
+    this.id=id;  
+  }
+
+  public void setViews(JSONArray ja) {
+    this.views=ja;
+  }
+  
+  public void setProperties(JSONObject properties) {
+    this.properties = properties;
+  }
+
+  public void setProperty(String key, String value) throws ParseException {
+    try {
+      this.properties.put(key, value);
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new ParseException("Error parsing user object.",0);      
+    }
+  }
+  
+  public JSONObject deserialize() {
+    JSONObject json = new JSONObject();
+    try {
+      json.put("id", this.id);
+      json.put("views", this.views);
+      json.put("properties", this.properties);
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+    }
+    return json;
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/UserBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,129 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.text.ParseException;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+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.apache.hadoop.chukwa.util.ExceptionUtil;
+
+@XmlRootElement
+@XmlType
+public class ViewBean {
+  private PagesBean[] pages;
+  private String description;
+  private String owner;
+  
+  private String name;
+  private String permissionType;
+  private static Log log = LogFactory.getLog(ViewBean.class);
+
+  public ViewBean() {  
+  }
+  
+  public ViewBean(JSONObject json) throws ParseException {
+    try {
+      if(json.has("description")) {
+        this.description = json.getString("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();
+      PagesBean[] pages = new PagesBean[size];
+      for(int i=0;i<size;i++) {
+        pages[i] = new PagesBean(json.getJSONArray("pages").getJSONObject(i));
+      }
+      this.pages=pages;
+    } catch (JSONException e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
+    }
+  }
+  
+  @XmlElement
+  public PagesBean[] getPages() {
+    return pages;
+  }
+  
+  @XmlElement
+  public int getPagesCount() {
+    return pages.length;  
+  }
+  
+  @XmlElement
+  public String getDescription() {
+    return this.description;
+  }
+  
+  @XmlElement
+  public String getOwner() {
+    return this.owner;
+  }
+  
+  @XmlElement
+  public String getName() {
+    return this.name;
+  }
+  
+  @XmlElement
+  public String getPermissionType() {
+    return this.permissionType;
+  }
+  
+  public void setPages(PagesBean[] pages) {
+    this.pages = pages;
+  }
+  
+  public void setDescription(String description) {
+    this.description = description;
+  }
+  
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
+  
+  public void setName(String name) {
+    this.name = name;
+  }
+  
+  public void setPermissionType(String permissionType) {
+    this.permissionType = permissionType;
+  }
+  
+  public void update() {
+    if(this.pages!=null) {
+      for(PagesBean page : pages) {
+        page.update();
+      }
+    }
+  }
+  
+  public String deserialize() {
+    update();
+    JSONObject json = new JSONObject();
+    try {
+      json.put("name", this.name);
+      json.put("owner", this.owner);
+      json.put("permissionType", this.permissionType);
+      json.put("description", this.description);
+      JSONArray ja = new JSONArray();
+      for(int i=0;i<this.pages.length;i++) {
+        ja.put(this.pages[i].deserialize());
+      }
+      json.put("pages", (JSONArray) ja);
+    } catch (Exception e){
+      log.error(ExceptionUtil.getStackTrace(e));
+    }
+    return json.toString();
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/ViewBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,184 @@
+package org.apache.hadoop.chukwa.rest.bean;
+
+import java.text.ParseException;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+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.apache.hadoop.chukwa.datastore.WidgetStore;
+import org.apache.hadoop.chukwa.util.ExceptionUtil;
+
+@XmlRootElement
+@XmlType(propOrder={"id", "title", "version", "categories", "url", "description","refresh","parameters"})
+public class WidgetBean {
+  private String id;
+  private String title;
+  private String version;
+  private String categories;
+  private String url;
+  private String description;
+  private int refresh;
+  private ParametersBean[] parameters;
+  private static Log log = LogFactory.getLog(WidgetBean.class);
+
+  public 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");
+      try {
+        int size = json.getJSONArray("parameters").length();
+        ParametersBean[] list = new ParametersBean[size];
+        for(int i=0;i<size;i++) {
+          list[i] = new ParametersBean(json.getJSONArray("parameters").getJSONObject(i));
+        }
+        this.parameters=list;
+      } catch (JSONException e) {
+        this.parameters=null;
+      }
+    } catch (JSONException e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
+    }
+  }
+  
+  @XmlElement
+  public String getId() {
+    return id;
+  }
+
+  @XmlElement
+  public String getTitle() {
+    return title;
+  }
+  
+  @XmlElement
+  public String getVersion() {
+    return version;
+  }
+  
+  @XmlElement
+  public String getCategories() {
+    return categories;
+  }
+  
+  @XmlElement
+  public String getUrl() {
+    return url;
+  }
+  
+  @XmlElement
+  public String getDescription() {
+    return description;
+  }
+  
+  @XmlElement
+  public int getRefresh() {
+    return refresh;
+  }
+  
+  @XmlElement
+  public ParametersBean[] getParameters() {
+    return parameters;
+  }
+  
+  public void setId(String id) {
+    this.id=id;
+  }
+  
+  public void setUrl(String url) {
+    this.url=url;
+  }
+  
+  public void setTitle(String title) {
+    this.title=title;
+  }
+  
+  public void setDescription(String description) {
+    this.description=description;
+  }
+  
+  public void setVersion(String version) {
+    this.version=version;
+  }
+  
+  public void setCategories(String categories) {
+    this.categories=categories;
+  }
+  
+  public void setRefresh(int refresh) {
+    this.refresh=refresh;
+  }
+  
+  public void setParameters(ParametersBean[] p) {
+    this.parameters=p;
+  }
+  
+  public void update() {
+    try {
+      WidgetBean widget = WidgetStore.list().get(this.id);
+      if(widget!=null) {
+        if(widget.getVersion().intern()!=this.version.intern()) {
+          this.categories=widget.getCategories();
+          this.title=widget.getTitle();
+          this.version=widget.getVersion();
+          this.url=widget.getUrl();
+          this.description=widget.getDescription();
+          ParametersBean[] plist = widget.getParameters();
+          for(int i=0;i<this.parameters.length;i++) {
+            String value = this.parameters[i].getValue();
+            for(int j=0;j<plist.length;j++) {
+              if(plist[i].getName().intern()==this.parameters[j].getName().intern()) {
+                plist[j].setValue(value);
+              }
+            }
+          }
+          this.parameters=plist;
+        }
+      } else {
+        log.info("Widget "+this.id+" is deprecated.");
+      }
+    } catch (IllegalAccessException e) {
+      log.error("Unable to update widget: "+this.id+" "+ExceptionUtil.getStackTrace(e));
+    }
+    
+  }
+  
+  public JSONObject deserialize() {
+    JSONObject json = new JSONObject();
+    try {
+      json.put("id", this.id);
+      json.put("title", this.title);
+      json.put("description", this.description);
+      json.put("version", this.version);
+      json.put("categories", this.categories);
+      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());
+        }
+      }
+      json.put("parameters", (JSONArray) ja);
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+    }
+    return json;    
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/bean/WidgetBean.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/UserResource.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/UserResource.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/UserResource.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/UserResource.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,69 @@
+package org.apache.hadoop.chukwa.rest.resource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.chukwa.rest.bean.ReturnCodeBean;
+import org.apache.hadoop.chukwa.rest.bean.UserBean;
+import org.apache.hadoop.chukwa.datastore.UserStore;
+import org.apache.hadoop.chukwa.util.ExceptionUtil;
+
+
+@Path ("/user")
+public class UserResource {
+  protected static Log log = LogFactory.getLog(UserResource.class);
+  
+  @GET
+  @Path("uid/{uid}")
+  public UserBean getProfile(@PathParam("uid") String uid) {
+    UserStore user;
+    UserBean result;
+    try {
+      user = new UserStore(uid);
+      result = user.get();
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
+          .entity("User does not exist.").build());
+    }
+    return result;
+  }
+  
+  @PUT
+  @Consumes("application/json")
+  public ReturnCodeBean setProfile(UserBean user) {
+    try {
+      UserStore us = new UserStore(user.getId());
+      us.set(user);
+    } catch(Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
+          .entity("User does not exist.").build());
+    }
+    return new ReturnCodeBean(ReturnCodeBean.SUCCESS,"Saved.");
+  }
+  
+  @GET
+  @Path("list")
+  @Produces("application/javascript")
+  public String getUserList() {
+    String result = "";
+    try {
+      result = UserStore.list().toString();
+    } catch (IllegalAccessException e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
+          .entity("User does not exist.").build());
+    }
+    return result;
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/UserResource.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewContextResolver.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewContextResolver.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewContextResolver.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewContextResolver.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,57 @@
+package org.apache.hadoop.chukwa.rest.resource;
+
+import com.sun.jersey.api.json.JSONConfiguration;
+import com.sun.jersey.api.json.JSONJAXBContext;
+import org.apache.hadoop.chukwa.rest.bean.ViewBean;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.Provider;
+import javax.xml.bind.JAXBContext;
+
+  @Provider
+  public class ViewContextResolver implements ContextResolver<JAXBContext> {
+      private JAXBContext context;
+      private Set<Class<?>> types;
+      protected Class<?>[] classTypes = new Class[] {ViewBean.class};
+      protected Set<String> jsonArray = new HashSet<String>(5) {
+        {
+            add("pages");
+            add("layout");
+            add("colSize");
+            add("widgets");
+            add("parameters");
+            add("options");
+        }
+      };
+
+      public ViewContextResolver() throws Exception {
+          Map props = new HashMap<String, Object>();
+          props.put(JSONJAXBContext.JSON_NOTATION, JSONJAXBContext.JSONNotation.MAPPED);
+          props.put(JSONJAXBContext.JSON_ROOT_UNWRAPPING, Boolean.TRUE);
+          props.put(JSONJAXBContext.JSON_ARRAYS, jsonArray);
+          this.types = new HashSet<Class<?>>(Arrays.asList(classTypes));
+          this.context = new JSONJAXBContext(classTypes, props);
+      }
+
+      public JAXBContext getContext(Class<?> objectType) {
+          return (types.contains(objectType)) ? context : null;
+      }
+
+//    private final JAXBContext context;
+//
+//    public ViewContextResolver() throws Exception {
+//      this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), "package.of.your.model");
+//  }
+//
+//  public JAXBContext getContext(Class<?> objectType) {
+//      return context;
+//  }
+
+  }
+

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewContextResolver.java
------------------------------------------------------------------------------
    svn:executable = *

Added: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java?rev=885291&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java (added)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java Sun Nov 29 23:16:13 2009
@@ -0,0 +1,149 @@
+package org.apache.hadoop.chukwa.rest.resource;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.hadoop.chukwa.rest.bean.ReturnCodeBean;
+import org.apache.hadoop.chukwa.rest.bean.ViewBean;
+import org.apache.hadoop.chukwa.datastore.ViewStore;
+import org.apache.hadoop.chukwa.util.ExceptionUtil;
+
+@Path ("/view")
+public class ViewResource {
+  protected static Log log = LogFactory.getLog(ViewResource.class);
+
+  @GET
+  @Path("vid/{vid}")
+  public ViewBean getView(@Context HttpServletRequest request, @PathParam("vid") String vid) {
+    ViewStore view;
+    ViewBean vr;
+    String uid = request.getRemoteUser();
+    try {
+      view = new ViewStore(uid, vid);
+      vr = view.get();
+      if(request.getRemoteUser().intern()!=vr.getOwner().intern() && vr.getPermissionType().intern()!="public".intern()) {
+    	  throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).entity("permission denied.").build());
+      }
+    } catch (IllegalAccessException e) {
+      throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
+          .entity("View does not exist.").build());
+    }
+    return vr;
+  }
+  
+  @PUT
+  @Consumes("application/json")
+  public ReturnCodeBean setView(@Context HttpServletRequest request, ViewBean view) {
+    try {
+      if(request.getRemoteUser().intern()==view.getOwner().intern()) {
+        ViewStore vs = new ViewStore(view.getOwner(), view.getName());
+        vs.set(view);
+      } else {
+          throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN)
+              .entity("Permission denied.").build());    	  
+      }
+    } catch (IllegalAccessException e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
+          .entity("View save failed.").build());
+    }
+    return new ReturnCodeBean(ReturnCodeBean.SUCCESS,"Saved");
+  }
+
+  @POST
+  @Path("permission")
+  public ReturnCodeBean changeViewPermission(@Context HttpServletRequest request, @FormParam("owner") String owner, @FormParam("view_vid") String vid, @FormParam("permission") String permission) {
+    try {
+      if(owner.intern()==request.getRemoteUser().intern()) {
+        ViewStore vs = new ViewStore(owner, vid);
+        ViewBean view = vs.get();
+        view.setPermissionType(permission);
+        vs.set(view);
+      } else {
+        throw new Exception("Permission denied.");
+      }
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+          .entity("View save failed.").build());      
+    }
+    return new ReturnCodeBean(ReturnCodeBean.SUCCESS,"Saved");
+  }
+
+  @POST
+  public ReturnCodeBean changeView(@Context HttpServletRequest request, @FormParam("owner") String owner, @FormParam("view_vid") String oldVid, @FormParam("view_name") String name) {
+    try {
+      ViewStore vs;
+      if(oldVid!=null) {
+        vs = new ViewStore(owner, oldVid);
+      } else {
+        vs = new ViewStore(null, "default");
+      }
+      ViewBean view = vs.get();
+      view.setOwner(request.getRemoteUser());
+      view.setName(name);
+      view.setDescription(name);
+      if(oldVid==null) {
+        view.setPermissionType("private");
+      }
+      vs = new ViewStore(request.getRemoteUser(), name);
+      vs.set(view);
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+          .entity("View save failed.").build());      
+    }
+    return new ReturnCodeBean(ReturnCodeBean.SUCCESS,"Saved");
+  }
+
+  @DELETE
+  @Path("delete/{owner}/vid/{vid}")
+  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 {
+        throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN)
+            .entity("View delete failed.").build());              
+      }
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+          .entity("View delete failed.").build());      
+    }
+    return new ReturnCodeBean(ReturnCodeBean.SUCCESS,"Deleted");
+  }
+
+  @GET
+  @Path("list")
+  public String getUserViewList(@Context HttpServletRequest request) {
+    String result = "";
+    String uid = null;
+    try {
+      if(uid==null) {
+        uid = request.getRemoteUser();
+      }
+      result = ViewStore.list(uid).toString();
+    } catch (Exception e) {
+      throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
+          .entity("View does not exist.").build());
+    }
+    return result;
+  }
+}

Propchange: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/rest/resource/ViewResource.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message