You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chukwa.apache.org by as...@apache.org on 2009/03/11 23:39:32 UTC
svn commit: r752666 [12/16] - in /hadoop/chukwa/trunk: ./
src/java/org/apache/hadoop/chukwa/ src/java/org/apache/hadoop/chukwa/conf/
src/java/org/apache/hadoop/chukwa/database/
src/java/org/apache/hadoop/chukwa/datacollection/
src/java/org/apache/hadoo...
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/DatasetMapper.java Wed Mar 11 22:39:26 2009
@@ -18,185 +18,190 @@
package org.apache.hadoop.chukwa.hicc;
+
import java.text.SimpleDateFormat;
import java.util.TreeMap;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class DatasetMapper {
- private String jdbc;
- private static Log log = LogFactory.getLog(DatasetMapper.class);
- private TreeMap<String, TreeMap<String, Double>> dataset;
- private List<String> labels;
- public DatasetMapper(String jdbc) {
- this.jdbc=jdbc;
- this.dataset = new TreeMap<String, TreeMap<String, Double>>();
- this.labels = new ArrayList<String>();
- }
- public void execute(String query, boolean groupBySecondColumn, boolean calculateSlope, String formatTime) {
- SimpleDateFormat sdf = null;
- dataset.clear();
- try {
- // The newInstance() call is a work around for some
- // broken Java implementations
- String jdbcDriver = System.getenv("JDBC_DRIVER");
- Class.forName(jdbcDriver).newInstance();
- } catch (Exception ex) {
- // handle the error
- }
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- int counter = 0;
- int size = 0;
- labels.clear();
- double max=0.0;
- int labelsCount=0;
- try {
- conn = DriverManager.getConnection(jdbc);
- stmt = conn.createStatement();
- //rs = stmt.executeQuery(query);
- if (stmt.execute(query)) {
- rs = stmt.getResultSet();
- ResultSetMetaData rmeta = rs.getMetaData();
- int col=rmeta.getColumnCount();
- double[] previousArray = new double[col+1];
- for(int k=0;k<col;k++) {
- previousArray[k]=0.0;
- }
- int i=0;
- java.util.TreeMap<String, Double> data = null;
- HashMap<String, Double> previousHash = new HashMap<String, Double>();
- HashMap<String, Integer> xAxisMap = new HashMap<String, Integer>();
- while (rs.next()) {
- String label = "";
- if(rmeta.getColumnType(1)==java.sql.Types.TIMESTAMP) {
- long time = rs.getTimestamp(1).getTime();
- label = ""+time;
- } else {
- label = rs.getString(1);
- }
- if(!xAxisMap.containsKey(label)) {
- xAxisMap.put(label, i);
- labels.add(label);
- i++;
- }
- if(groupBySecondColumn) {
- String item = rs.getString(2);
- // Get the data from the row using the series column
- for(int j=3;j<=col;j++) {
- item = rs.getString(2) + " " + rmeta.getColumnName(j);
- data = dataset.get(item);
- if(data == null) {
- data = new java.util.TreeMap<String, Double>();
- }
- if(calculateSlope) {
- double current = rs.getDouble(j);
- double tmp = 0L;
- if(data.size()>1) {
- tmp = current - previousHash.get(item).doubleValue();
- } else {
- tmp = 0;
- }
- if(tmp<0) {
- tmp=Double.NaN;
- }
- previousHash.put(item,current);
- if(tmp>max) {
- max=tmp;
- }
- data.put(label, tmp);
- } else {
- double current = rs.getDouble(3);
- if(current>max) {
- max=current;
- }
- data.put(label, current);
- }
- dataset.put(item,data);
- }
- } else {
- for(int j=2;j<=col;j++) {
- String item = rmeta.getColumnName(j);
- // Get the data from the row using the column name
- double current = rs.getDouble(j);
- if(current>max) {
- max=current;
- }
- data = dataset.get(item);
- if(data == null) {
- data = new java.util.TreeMap<String, Double>();
- }
- if(calculateSlope) {
- double tmp = current;
- if(data.size()>1) {
- tmp = tmp - previousArray[j];
- } else {
- tmp = 0.0;
- }
- if(tmp<0) {
- tmp=Double.NaN;
- }
- previousArray[j]=current;
- data.put(label, tmp);
- } else {
- data.put(label, current);
- }
- dataset.put(item,data);
- }
- }
- }
- labelsCount=i;
- } else {
- log.error("query is not executed.");
- }
- // Now do something with the ResultSet ....
- } catch (SQLException ex) {
- // handle any errors
- log.error("SQLException: " + ex.getMessage());
- log.error("SQLState: " + ex.getSQLState());
- log.error("VendorError: " + ex.getErrorCode());
- } catch (Exception ex) {
- } finally {
- // it is a good idea to release
- // resources in a finally{} block
- // in reverse-order of their creation
- // if they are no-longer needed
- if (rs != null) {
- try {
- rs.close();
- } catch (SQLException sqlEx) {
- // ignore
- }
- rs = null;
- }
- if (stmt != null) {
- try {
- stmt.close();
- } catch (SQLException sqlEx) {
- // ignore
- }
- stmt = null;
- }
- if (conn != null) {
- try {
- conn.close();
- } catch (SQLException sqlEx) {
- // ignore
- }
- conn = null;
- }
- }
- }
- public List<String> getXAxisMap() {
- return labels;
- }
- public TreeMap<String, TreeMap<String, Double>> getDataset() {
- return dataset;
- }
+ private String jdbc;
+ private static Log log = LogFactory.getLog(DatasetMapper.class);
+ private TreeMap<String, TreeMap<String, Double>> dataset;
+ private List<String> labels;
+
+ public DatasetMapper(String jdbc) {
+ this.jdbc = jdbc;
+ this.dataset = new TreeMap<String, TreeMap<String, Double>>();
+ this.labels = new ArrayList<String>();
+ }
+
+ public void execute(String query, boolean groupBySecondColumn,
+ boolean calculateSlope, String formatTime) {
+ SimpleDateFormat sdf = null;
+ dataset.clear();
+ try {
+ // The newInstance() call is a work around for some
+ // broken Java implementations
+ String jdbcDriver = System.getenv("JDBC_DRIVER");
+ Class.forName(jdbcDriver).newInstance();
+ } catch (Exception ex) {
+ // handle the error
+ }
+ Connection conn = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+ int counter = 0;
+ int size = 0;
+ labels.clear();
+ double max = 0.0;
+ int labelsCount = 0;
+ try {
+ conn = DriverManager.getConnection(jdbc);
+ stmt = conn.createStatement();
+ // rs = stmt.executeQuery(query);
+ if (stmt.execute(query)) {
+ rs = stmt.getResultSet();
+ ResultSetMetaData rmeta = rs.getMetaData();
+ int col = rmeta.getColumnCount();
+ double[] previousArray = new double[col + 1];
+ for (int k = 0; k < col; k++) {
+ previousArray[k] = 0.0;
+ }
+ int i = 0;
+ java.util.TreeMap<String, Double> data = null;
+ HashMap<String, Double> previousHash = new HashMap<String, Double>();
+ HashMap<String, Integer> xAxisMap = new HashMap<String, Integer>();
+ while (rs.next()) {
+ String label = "";
+ if (rmeta.getColumnType(1) == java.sql.Types.TIMESTAMP) {
+ long time = rs.getTimestamp(1).getTime();
+ label = "" + time;
+ } else {
+ label = rs.getString(1);
+ }
+ if (!xAxisMap.containsKey(label)) {
+ xAxisMap.put(label, i);
+ labels.add(label);
+ i++;
+ }
+ if (groupBySecondColumn) {
+ String item = rs.getString(2);
+ // Get the data from the row using the series column
+ for (int j = 3; j <= col; j++) {
+ item = rs.getString(2) + " " + rmeta.getColumnName(j);
+ data = dataset.get(item);
+ if (data == null) {
+ data = new java.util.TreeMap<String, Double>();
+ }
+ if (calculateSlope) {
+ double current = rs.getDouble(j);
+ double tmp = 0L;
+ if (data.size() > 1) {
+ tmp = current - previousHash.get(item).doubleValue();
+ } else {
+ tmp = 0;
+ }
+ if (tmp < 0) {
+ tmp = Double.NaN;
+ }
+ previousHash.put(item, current);
+ if (tmp > max) {
+ max = tmp;
+ }
+ data.put(label, tmp);
+ } else {
+ double current = rs.getDouble(3);
+ if (current > max) {
+ max = current;
+ }
+ data.put(label, current);
+ }
+ dataset.put(item, data);
+ }
+ } else {
+ for (int j = 2; j <= col; j++) {
+ String item = rmeta.getColumnName(j);
+ // Get the data from the row using the column name
+ double current = rs.getDouble(j);
+ if (current > max) {
+ max = current;
+ }
+ data = dataset.get(item);
+ if (data == null) {
+ data = new java.util.TreeMap<String, Double>();
+ }
+ if (calculateSlope) {
+ double tmp = current;
+ if (data.size() > 1) {
+ tmp = tmp - previousArray[j];
+ } else {
+ tmp = 0.0;
+ }
+ if (tmp < 0) {
+ tmp = Double.NaN;
+ }
+ previousArray[j] = current;
+ data.put(label, tmp);
+ } else {
+ data.put(label, current);
+ }
+ dataset.put(item, data);
+ }
+ }
+ }
+ labelsCount = i;
+ } else {
+ log.error("query is not executed.");
+ }
+ // Now do something with the ResultSet ....
+ } catch (SQLException ex) {
+ // handle any errors
+ log.error("SQLException: " + ex.getMessage());
+ log.error("SQLState: " + ex.getSQLState());
+ log.error("VendorError: " + ex.getErrorCode());
+ } catch (Exception ex) {
+ } finally {
+ // it is a good idea to release
+ // resources in a finally{} block
+ // in reverse-order of their creation
+ // if they are no-longer needed
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (SQLException sqlEx) {
+ // ignore
+ }
+ rs = null;
+ }
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException sqlEx) {
+ // ignore
+ }
+ stmt = null;
+ }
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException sqlEx) {
+ // ignore
+ }
+ conn = null;
+ }
+ }
+ }
+
+ public List<String> getXAxisMap() {
+ return labels;
+ }
+
+ public TreeMap<String, TreeMap<String, Double>> getDataset() {
+ return dataset;
+ }
}
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Iframe.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Iframe.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Iframe.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Iframe.java Wed Mar 11 22:39:26 2009
@@ -1,49 +1,51 @@
package org.apache.hadoop.chukwa.hicc;
+
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-public class Iframe extends HttpServlet {
-
- private String id;
- private String height="100%";
-
- public void doGet(HttpServletRequest request,
- HttpServletResponse response) throws IOException, ServletException {
- if(request.getParameter("boxId")!=null) {
- this.id=request.getParameter("boxId");
- } else {
- this.id="0";
- }
- response.setHeader("boxId", request.getParameter("boxId"));
- PrintWriter out = response.getWriter();
- StringBuffer source = new StringBuffer();
- String requestURL = request.getRequestURL().toString().replaceFirst("iframe/", "");
- source.append(requestURL);
- source.append("?");
- Enumeration names = request.getParameterNames();
- while(names.hasMoreElements()) {
- String key = (String) names.nextElement();
- String[] values = request.getParameterValues(key);
- for(int i=0;i<values.length;i++) {
- source.append(key+"="+values[i]+"&");
- }
- if(key.toLowerCase().intern()=="height".intern()) {
- height = request.getParameter(key);
- }
- }
- out.println("<html><body><iframe id=\"iframe"+ this.id +"\" "+
- "src=\"" + source + "\" width=\"100%\" height=\"" + height + "\" "+
- "frameborder=\"0\" style=\"overflow: hidden\"></iframe>");
- }
- public void doPost(HttpServletRequest request,
- HttpServletResponse response) throws IOException, ServletException {
- doGet(request, response);
- }
+public class Iframe extends HttpServlet {
+
+ private String id;
+ private String height = "100%";
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ if (request.getParameter("boxId") != null) {
+ this.id = request.getParameter("boxId");
+ } else {
+ this.id = "0";
+ }
+ response.setHeader("boxId", request.getParameter("boxId"));
+ PrintWriter out = response.getWriter();
+ StringBuffer source = new StringBuffer();
+ String requestURL = request.getRequestURL().toString().replaceFirst(
+ "iframe/", "");
+ source.append(requestURL);
+ source.append("?");
+ Enumeration names = request.getParameterNames();
+ while (names.hasMoreElements()) {
+ String key = (String) names.nextElement();
+ String[] values = request.getParameterValues(key);
+ for (int i = 0; i < values.length; i++) {
+ source.append(key + "=" + values[i] + "&");
+ }
+ if (key.toLowerCase().intern() == "height".intern()) {
+ height = request.getParameter(key);
+ }
+ }
+ out.println("<html><body><iframe id=\"iframe" + this.id + "\" " + "src=\""
+ + source + "\" width=\"100%\" height=\"" + height + "\" "
+ + "frameborder=\"0\" style=\"overflow: hidden\"></iframe>");
+ }
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ doGet(request, response);
+ }
}
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/JSONLoader.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/JSONLoader.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/JSONLoader.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/JSONLoader.java Wed Mar 11 22:39:26 2009
@@ -18,75 +18,78 @@
package org.apache.hadoop.chukwa.hicc;
+
import java.net.*;
import java.io.*;
import org.json.*;
public class JSONLoader {
- public JSONArray jsonData;
- static public String getContents(String source) {
- //...checks on aFile are elided
- StringBuffer contents = new StringBuffer();
-
- try {
- //use buffering, reading one line at a time
- //FileReader always assumes default encoding is OK!
- URL yahoo = new URL(source);
- BufferedReader in = new BufferedReader(
- new InputStreamReader(
- yahoo.openStream()));
-
- String inputLine;
-
- while ((inputLine = in.readLine()) != null) {
- contents.append(inputLine);
- contents.append(System.getProperty("line.separator"));
- }
- in.close();
- } catch (IOException ex){
- ex.printStackTrace();
- }
-
- return contents.toString();
- }
+ public JSONArray jsonData;
- public JSONLoader(String source) {
- String buffer = getContents(source);
- try {
- JSONObject rows = new JSONObject(buffer);
- jsonData = new JSONArray((String)rows.get("rows").toString());
- } catch (JSONException e) {
- }
- }
-
- public String getTS(int i) {
- String ts = null;
- try {
- ts = ((JSONObject)((JSONArray)jsonData).get(i)).get("ts").toString();
- } catch (JSONException e) {
- }
- return ts;
- }
-
- public String getTags(int i) {
- String tags = null;
- try {
- tags = ((JSONObject)((JSONArray)jsonData).get(i)).get("tags").toString();
- } catch (JSONException e) {
- }
- return tags;
- }
-
- public String getValue(int i) {
- String value = null;
- try {
- value = ((JSONObject)((JSONArray)jsonData).get(i)).get("value").toString();
- } catch (JSONException e) {
- }
- return value;
- }
-
- public int length() {
- return ((JSONArray)jsonData).length();
- }
+ static public String getContents(String source) {
+ // ...checks on aFile are elided
+ StringBuffer contents = new StringBuffer();
+
+ try {
+ // use buffering, reading one line at a time
+ // FileReader always assumes default encoding is OK!
+ URL yahoo = new URL(source);
+ BufferedReader in = new BufferedReader(new InputStreamReader(yahoo
+ .openStream()));
+
+ String inputLine;
+
+ while ((inputLine = in.readLine()) != null) {
+ contents.append(inputLine);
+ contents.append(System.getProperty("line.separator"));
+ }
+ in.close();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+
+ return contents.toString();
+ }
+
+ public JSONLoader(String source) {
+ String buffer = getContents(source);
+ try {
+ JSONObject rows = new JSONObject(buffer);
+ jsonData = new JSONArray((String) rows.get("rows").toString());
+ } catch (JSONException e) {
+ }
+ }
+
+ public String getTS(int i) {
+ String ts = null;
+ try {
+ ts = ((JSONObject) ((JSONArray) jsonData).get(i)).get("ts").toString();
+ } catch (JSONException e) {
+ }
+ return ts;
+ }
+
+ public String getTags(int i) {
+ String tags = null;
+ try {
+ tags = ((JSONObject) ((JSONArray) jsonData).get(i)).get("tags")
+ .toString();
+ } catch (JSONException e) {
+ }
+ return tags;
+ }
+
+ public String getValue(int i) {
+ String value = null;
+ try {
+ value = ((JSONObject) ((JSONArray) jsonData).get(i)).get("value")
+ .toString();
+ } catch (JSONException e) {
+ }
+ return value;
+ }
+
+ public int length() {
+ return ((JSONArray) jsonData).length();
+ }
}
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/TimeHandler.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/TimeHandler.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/TimeHandler.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/TimeHandler.java Wed Mar 11 22:39:26 2009
@@ -18,194 +18,206 @@
package org.apache.hadoop.chukwa.hicc;
+
import javax.servlet.http.*;
import java.util.Calendar;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
public class TimeHandler {
- private HttpSession session = null;
- private HttpServletRequest request = null;
- private TimeZone tz = null;
- private long start = 0;
- private long end = 0;
- private String startDate = null;
- private String startHour = null;
- private String startMin = null;
- private String endDate = null;
- private String endHour = null;
- private String endMin = null;
- private String startS = null;
- private String endS = null;
-
- public TimeHandler(HttpServletRequest request) {
- this.tz=TimeZone.getTimeZone("UTC");
- init(request);
- }
-
- public TimeHandler(HttpServletRequest request, String tz) {
- if(tz!=null) {
- this.tz=TimeZone.getTimeZone(tz);
- } else {
- this.tz=TimeZone.getTimeZone("UTC");
- }
- init(request);
- }
-
- public void init(HttpServletRequest request) {
- Calendar now = Calendar.getInstance();
- this.session = request.getSession();
- this.request = request;
- String timeType = "last";
- if(request.getParameter("time_type")==null && session.getAttribute("time_type")==null && session.getAttribute("period")==null && request.getParameter("period")==null) {
- timeType = "last";
- end = now.getTimeInMillis();
- start = end - 60*60*1000;
- session.setAttribute("period", "last1hr");
- session.setAttribute("time_type", "last");
- session.setAttribute("start", ""+start);
- session.setAttribute("end", ""+end);
- } else if(request.getParameter("period")!=null && !request.getParameter("period").equals("")) {
- String period = request.getParameter("period");
- this.start = now.getTimeInMillis();
- this.end = now.getTimeInMillis();
- if(period.equals("last1hr")) {
- start = end - (60*60*1000);
- } else if(period.equals("last2hr")) {
- start = end - (2*60*60*1000);
- } else if(period.equals("last3hr")) {
- start = end - (3*60*60*1000);
- } else if(period.equals("last6hr")) {
- start = end - (6*60*60*1000);
- } else if(period.equals("last12hr")) {
- start = end - (12*60*60*1000);
- } else if(period.equals("last24hr")) {
- start = end - (24*60*60*1000);
- } else if(period.equals("last7d")) {
- start = end - (7*24*60*60*1000);
- } else if(period.equals("last30d")) {
- start = end - (30*24*60*60*1000);
- }
- } else if(request.getParameter("start")!=null && request.getParameter("end")!=null) {
- start = Long.parseLong(request.getParameter("start"));
- end = Long.parseLong(request.getParameter("end"));
- } else if(session.getAttribute("time_type").equals("range")) {
- start = Long.parseLong((String) session.getAttribute("start"));
- end = Long.parseLong((String) session.getAttribute("end"));
- } else if(session.getAttribute("time_type").equals("last") && session.getAttribute("period")!=null){
- String period = (String) session.getAttribute("period");
- this.start = now.getTimeInMillis();
- this.end = now.getTimeInMillis();
- if(period.equals("last1hr")) {
- start = end - (60*60*1000);
- } else if(period.equals("last2hr")) {
- start = end - (2*60*60*1000);
- } else if(period.equals("last3hr")) {
- start = end - (3*60*60*1000);
- } else if(period.equals("last6hr")) {
- start = end - (6*60*60*1000);
- } else if(period.equals("last12hr")) {
- start = end - (12*60*60*1000);
- } else if(period.equals("last24hr")) {
- start = end - (24*60*60*1000);
- } else if(period.equals("last7d")) {
- start = end - (7*24*60*60*1000);
- } else if(period.equals("last30d")) {
- start = end - (30L*24*60*60*1000);
- }
- }
-// if((request.getParameter("period")==null || request.getParameter("period").equals("")) && session.getAttribute("time_type")!=null) {
-// timeType = (String)session.getAttribute("time_type");
-// }
-// if((request.getParameter("period")!=null && !request.getParameter("period").equals("")) || (timeType!=null && timeType.equals("last"))) {
-// String period = request.getParameter("period");
-// if(period == null) {
-// period = (String) session.getAttribute("period");
-// if(period == null) {
-// period = "last1hr";
-// session.setAttribute("period",period);
-// }
-// }
-// // no time specified in request nor session, set default time in session.
-// if(request.getParameter("time_type")!=null && request.getParameter("time_type").equals("range")) {
-// session.setAttribute("start", ""+start);
-// session.setAttribute("end", ""+end);
-// }
-// } else {
-// // no time specified in request, use session time.
-// start = Long.parseLong((String) session.getAttribute("start"));
-// end = Long.parseLong((String) session.getAttribute("end"));
-// }
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
- SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
- SimpleDateFormat formatHour = new SimpleDateFormat("HH");
- SimpleDateFormat formatMin = new SimpleDateFormat("mm");
-
- formatter.setTimeZone(this.tz);
- formatDate.setTimeZone(this.tz);
- formatHour.setTimeZone(this.tz);
- formatMin.setTimeZone(this.tz);
-
- startS = formatter.format(start);
- this.startDate = formatDate.format(start);
- this.startHour = formatHour.format(start);
- this.startMin = formatMin.format(start);
- endS = formatter.format(end);
- this.endDate = formatDate.format(end);
- this.endHour = formatHour.format(end);
- this.endMin = formatMin.format(end);
- }
-
- public String getStartDate(String format) {
- SimpleDateFormat formatter = new SimpleDateFormat(format);
- formatter.setTimeZone(this.tz);
- return formatter.format(this.start);
- }
-
- public String getStartDate() {
- return this.startDate;
- }
-
- public String getStartHour() {
- return this.startHour;
- }
-
- public String getStartMinute() {
- return this.startMin;
- }
-
- public String getStartTimeText() {
- return this.startS;
- }
-
- public long getStartTime() {
- return start;
- }
-
- public String getEndDate(String format) {
- SimpleDateFormat formatter = new SimpleDateFormat(format);
- formatter.setTimeZone(this.tz);
- return formatter.format(this.end);
- }
-
- public String getEndDate() {
- return this.endDate;
- }
-
- public String getEndHour() {
- return this.endHour;
- }
-
- public String getEndMinute() {
- return this.endMin;
- }
-
- public String getEndTimeText() {
- return this.endS;
- }
-
- public long getEndTime() {
- return end;
- }
+ private HttpSession session = null;
+ private HttpServletRequest request = null;
+ private TimeZone tz = null;
+ private long start = 0;
+ private long end = 0;
+ private String startDate = null;
+ private String startHour = null;
+ private String startMin = null;
+ private String endDate = null;
+ private String endHour = null;
+ private String endMin = null;
+ private String startS = null;
+ private String endS = null;
+
+ public TimeHandler(HttpServletRequest request) {
+ this.tz = TimeZone.getTimeZone("UTC");
+ init(request);
+ }
+
+ public TimeHandler(HttpServletRequest request, String tz) {
+ if (tz != null) {
+ this.tz = TimeZone.getTimeZone(tz);
+ } else {
+ this.tz = TimeZone.getTimeZone("UTC");
+ }
+ init(request);
+ }
+
+ public void init(HttpServletRequest request) {
+ Calendar now = Calendar.getInstance();
+ this.session = request.getSession();
+ this.request = request;
+ String timeType = "last";
+ if (request.getParameter("time_type") == null
+ && session.getAttribute("time_type") == null
+ && session.getAttribute("period") == null
+ && request.getParameter("period") == null) {
+ timeType = "last";
+ end = now.getTimeInMillis();
+ start = end - 60 * 60 * 1000;
+ session.setAttribute("period", "last1hr");
+ session.setAttribute("time_type", "last");
+ session.setAttribute("start", "" + start);
+ session.setAttribute("end", "" + end);
+ } else if (request.getParameter("period") != null
+ && !request.getParameter("period").equals("")) {
+ String period = request.getParameter("period");
+ this.start = now.getTimeInMillis();
+ this.end = now.getTimeInMillis();
+ if (period.equals("last1hr")) {
+ start = end - (60 * 60 * 1000);
+ } else if (period.equals("last2hr")) {
+ start = end - (2 * 60 * 60 * 1000);
+ } else if (period.equals("last3hr")) {
+ start = end - (3 * 60 * 60 * 1000);
+ } else if (period.equals("last6hr")) {
+ start = end - (6 * 60 * 60 * 1000);
+ } else if (period.equals("last12hr")) {
+ start = end - (12 * 60 * 60 * 1000);
+ } else if (period.equals("last24hr")) {
+ start = end - (24 * 60 * 60 * 1000);
+ } else if (period.equals("last7d")) {
+ start = end - (7 * 24 * 60 * 60 * 1000);
+ } else if (period.equals("last30d")) {
+ start = end - (30 * 24 * 60 * 60 * 1000);
+ }
+ } else if (request.getParameter("start") != null
+ && request.getParameter("end") != null) {
+ start = Long.parseLong(request.getParameter("start"));
+ end = Long.parseLong(request.getParameter("end"));
+ } else if (session.getAttribute("time_type").equals("range")) {
+ start = Long.parseLong((String) session.getAttribute("start"));
+ end = Long.parseLong((String) session.getAttribute("end"));
+ } else if (session.getAttribute("time_type").equals("last")
+ && session.getAttribute("period") != null) {
+ String period = (String) session.getAttribute("period");
+ this.start = now.getTimeInMillis();
+ this.end = now.getTimeInMillis();
+ if (period.equals("last1hr")) {
+ start = end - (60 * 60 * 1000);
+ } else if (period.equals("last2hr")) {
+ start = end - (2 * 60 * 60 * 1000);
+ } else if (period.equals("last3hr")) {
+ start = end - (3 * 60 * 60 * 1000);
+ } else if (period.equals("last6hr")) {
+ start = end - (6 * 60 * 60 * 1000);
+ } else if (period.equals("last12hr")) {
+ start = end - (12 * 60 * 60 * 1000);
+ } else if (period.equals("last24hr")) {
+ start = end - (24 * 60 * 60 * 1000);
+ } else if (period.equals("last7d")) {
+ start = end - (7 * 24 * 60 * 60 * 1000);
+ } else if (period.equals("last30d")) {
+ start = end - (30L * 24 * 60 * 60 * 1000);
+ }
+ }
+ // if((request.getParameter("period")==null ||
+ // request.getParameter("period").equals("")) &&
+ // session.getAttribute("time_type")!=null) {
+ // timeType = (String)session.getAttribute("time_type");
+ // }
+ // if((request.getParameter("period")!=null &&
+ // !request.getParameter("period").equals("")) || (timeType!=null &&
+ // timeType.equals("last"))) {
+ // String period = request.getParameter("period");
+ // if(period == null) {
+ // period = (String) session.getAttribute("period");
+ // if(period == null) {
+ // period = "last1hr";
+ // session.setAttribute("period",period);
+ // }
+ // }
+ // // no time specified in request nor session, set default time in session.
+ // if(request.getParameter("time_type")!=null &&
+ // request.getParameter("time_type").equals("range")) {
+ // session.setAttribute("start", ""+start);
+ // session.setAttribute("end", ""+end);
+ // }
+ // } else {
+ // // no time specified in request, use session time.
+ // start = Long.parseLong((String) session.getAttribute("start"));
+ // end = Long.parseLong((String) session.getAttribute("end"));
+ // }
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+ SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
+ SimpleDateFormat formatHour = new SimpleDateFormat("HH");
+ SimpleDateFormat formatMin = new SimpleDateFormat("mm");
+
+ formatter.setTimeZone(this.tz);
+ formatDate.setTimeZone(this.tz);
+ formatHour.setTimeZone(this.tz);
+ formatMin.setTimeZone(this.tz);
+
+ startS = formatter.format(start);
+ this.startDate = formatDate.format(start);
+ this.startHour = formatHour.format(start);
+ this.startMin = formatMin.format(start);
+ endS = formatter.format(end);
+ this.endDate = formatDate.format(end);
+ this.endHour = formatHour.format(end);
+ this.endMin = formatMin.format(end);
+ }
+
+ public String getStartDate(String format) {
+ SimpleDateFormat formatter = new SimpleDateFormat(format);
+ formatter.setTimeZone(this.tz);
+ return formatter.format(this.start);
+ }
+
+ public String getStartDate() {
+ return this.startDate;
+ }
+
+ public String getStartHour() {
+ return this.startHour;
+ }
+
+ public String getStartMinute() {
+ return this.startMin;
+ }
+
+ public String getStartTimeText() {
+ return this.startS;
+ }
+
+ public long getStartTime() {
+ return start;
+ }
+
+ public String getEndDate(String format) {
+ SimpleDateFormat formatter = new SimpleDateFormat(format);
+ formatter.setTimeZone(this.tz);
+ return formatter.format(this.end);
+ }
+
+ public String getEndDate() {
+ return this.endDate;
+ }
+
+ public String getEndHour() {
+ return this.endHour;
+ }
+
+ public String getEndMinute() {
+ return this.endMin;
+ }
+
+ public String getEndTimeText() {
+ return this.endS;
+ }
+
+ public long getEndTime() {
+ return end;
+ }
}
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Views.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Views.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Views.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Views.java Wed Mar 11 22:39:26 2009
@@ -18,108 +18,114 @@
package org.apache.hadoop.chukwa.hicc;
+
import java.io.*;
import java.util.*;
import org.json.*;
public class Views {
- public JSONArray viewsData;
- private String path = System.getProperty("catalina.home")+"/webapps/hicc/views/workspace_view_list.cache";
- static public String getContents(File aFile) {
- //...checks on aFile are elided
- StringBuffer contents = new StringBuffer();
-
- try {
- //use buffering, reading one line at a time
- //FileReader always assumes default encoding is OK!
- BufferedReader input = new BufferedReader(new FileReader(aFile));
- try {
- String line = null; //not declared within while loop
- /*
- * readLine is a bit quirky :
- * it returns the content of a line MINUS the newline.
- * it returns null only for the END of the stream.
- * it returns an empty String if two newlines appear in a row.
- */
- while (( line = input.readLine()) != null){
- contents.append(line);
- contents.append(System.getProperty("line.separator"));
- }
- } finally {
- input.close();
- }
- }
- catch (IOException ex){
- ex.printStackTrace();
- }
-
- return contents.toString();
- }
-
- public Views() {
- File aFile = new File(path);
- String buffer = getContents(aFile);
- try {
- viewsData = new JSONArray(buffer);
- } catch (JSONException e) {
- }
- }
-
- public String getOwner(int i) {
- String owner = null;
- try {
- owner = ((JSONObject)((JSONArray)viewsData).get(i)).get("owner").toString();
- } catch (JSONException e) {
- }
- return owner;
- }
-
- public Iterator getPermission(int i) {
- Iterator permission = null;
- try {
- permission = ((JSONObject)((JSONObject)((JSONArray)viewsData).get(i)).get("permission")).keys();
- } catch (JSONException e) {
- }
- return permission;
- }
-
- public String getReadPermission(int i, String who) {
- String read = null;
- try {
- read = ((JSONObject)((JSONObject)((JSONObject)((JSONArray)viewsData).get(i)).get("permission")).get(who)).get("read").toString();
- } catch (JSONException e) {
- }
- return read;
- }
-
- public String getWritePermission(int i, String who) {
- String write = null;
- try {
- write = ((JSONObject)((JSONObject)((JSONObject)((JSONArray)viewsData).get(i)).get("permission")).get(who)).get("write").toString();
- } catch (JSONException e) {
- }
- return write;
- }
-
- public String getDescription(int i) {
- String description = null;
- try {
- description = ((JSONObject)((JSONArray)viewsData).get(i)).get("description").toString();
- } catch (JSONException e) {
- }
- return description;
- }
-
- public String getKey(int i) {
- String key = null;
- try {
- key = ((JSONObject)((JSONArray)viewsData).get(i)).get("key").toString();
- } catch (JSONException e) {
- }
- return key;
- }
-
- public int length() {
- return ((JSONArray)viewsData).length();
- }
+ public JSONArray viewsData;
+ private String path = System.getProperty("catalina.home")
+ + "/webapps/hicc/views/workspace_view_list.cache";
+
+ static public String getContents(File aFile) {
+ // ...checks on aFile are elided
+ StringBuffer contents = new StringBuffer();
+
+ try {
+ // use buffering, reading one line at a time
+ // FileReader always assumes default encoding is OK!
+ BufferedReader input = new BufferedReader(new FileReader(aFile));
+ try {
+ String line = null; // not declared within while loop
+ /*
+ * readLine is a bit quirky : it returns the content of a line MINUS the
+ * newline. it returns null only for the END of the stream. it returns
+ * an empty String if two newlines appear in a row.
+ */
+ while ((line = input.readLine()) != null) {
+ contents.append(line);
+ contents.append(System.getProperty("line.separator"));
+ }
+ } finally {
+ input.close();
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+
+ return contents.toString();
+ }
+
+ public Views() {
+ File aFile = new File(path);
+ String buffer = getContents(aFile);
+ try {
+ viewsData = new JSONArray(buffer);
+ } catch (JSONException e) {
+ }
+ }
+
+ public String getOwner(int i) {
+ String owner = null;
+ try {
+ owner = ((JSONObject) ((JSONArray) viewsData).get(i)).get("owner")
+ .toString();
+ } catch (JSONException e) {
+ }
+ return owner;
+ }
+
+ public Iterator getPermission(int i) {
+ Iterator permission = null;
+ try {
+ permission = ((JSONObject) ((JSONObject) ((JSONArray) viewsData).get(i))
+ .get("permission")).keys();
+ } catch (JSONException e) {
+ }
+ return permission;
+ }
+
+ public String getReadPermission(int i, String who) {
+ String read = null;
+ try {
+ read = ((JSONObject) ((JSONObject) ((JSONObject) ((JSONArray) viewsData)
+ .get(i)).get("permission")).get(who)).get("read").toString();
+ } catch (JSONException e) {
+ }
+ return read;
+ }
+
+ public String getWritePermission(int i, String who) {
+ String write = null;
+ try {
+ write = ((JSONObject) ((JSONObject) ((JSONObject) ((JSONArray) viewsData)
+ .get(i)).get("permission")).get(who)).get("write").toString();
+ } catch (JSONException e) {
+ }
+ return write;
+ }
+
+ public String getDescription(int i) {
+ String description = null;
+ try {
+ description = ((JSONObject) ((JSONArray) viewsData).get(i)).get(
+ "description").toString();
+ } catch (JSONException e) {
+ }
+ return description;
+ }
+
+ public String getKey(int i) {
+ String key = null;
+ try {
+ key = ((JSONObject) ((JSONArray) viewsData).get(i)).get("key").toString();
+ } catch (JSONException e) {
+ }
+ return key;
+ }
+
+ public int length() {
+ return ((JSONArray) viewsData).length();
+ }
}
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ViewsTag.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ViewsTag.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ViewsTag.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/ViewsTag.java Wed Mar 11 22:39:26 2009
@@ -18,6 +18,7 @@
package org.apache.hadoop.chukwa.hicc;
+
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
@@ -25,29 +26,31 @@
import org.apache.hadoop.chukwa.hicc.Views;
public class ViewsTag extends SimpleTagSupport {
- private String key = null;
- private String owner = null;
- private String description = null;
- Views views = new Views();
- public void doTag() throws JspException, IOException {
- for(int i=0;i<views.length();i++) {
- int j=0;
- getJspContext().setAttribute( "key", views.getKey(i) );
- Iterator permission = views.getPermission(i);
- String[] authUsers = new String[100];
- for ( Iterator perm = permission; perm.hasNext(); ) {
- String who = perm.next().toString();
- authUsers[j]=who;
-// getJspContext().setAttribute( "permission."+who+".read", views.getReadPermission(i,who) );
-// getJspContext().setAttribute( "permission."+who+".write", views.getWritePermission(i,who) );
- j=j+1;
- }
-// getJspContext().setAttribute( "permission", authUsers );
- getJspContext().setAttribute( "owner", views.getOwner(i) );
- getJspContext().setAttribute( "description", views.getDescription(i) );
- getJspBody().invoke(null);
- }
+ private String key = null;
+ private String owner = null;
+ private String description = null;
+ Views views = new Views();
+
+ public void doTag() throws JspException, IOException {
+ for (int i = 0; i < views.length(); i++) {
+ int j = 0;
+ getJspContext().setAttribute("key", views.getKey(i));
+ Iterator permission = views.getPermission(i);
+ String[] authUsers = new String[100];
+ for (Iterator perm = permission; perm.hasNext();) {
+ String who = perm.next().toString();
+ authUsers[j] = who;
+ // getJspContext().setAttribute( "permission."+who+".read",
+ // views.getReadPermission(i,who) );
+ // getJspContext().setAttribute( "permission."+who+".write",
+ // views.getWritePermission(i,who) );
+ j = j + 1;
+ }
+ // getJspContext().setAttribute( "permission", authUsers );
+ getJspContext().setAttribute("owner", views.getOwner(i));
+ getJspContext().setAttribute("description", views.getDescription(i));
+ getJspBody().invoke(null);
}
+ }
}
-
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Workspace.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Workspace.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Workspace.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/hicc/Workspace.java Wed Mar 11 22:39:26 2009
@@ -18,6 +18,7 @@
package org.apache.hadoop.chukwa.hicc;
+
import java.io.*;
import java.util.*;
import javax.servlet.*;
@@ -27,341 +28,332 @@
public class Workspace extends HttpServlet {
- private String path=System.getProperty("catalina.home")+"/webapps/hicc";
- private JSONObject hash=new JSONObject();
- private String user="admin";
-
- public void doGet(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- String method = request.getParameter("method");
- if(method.equals("get_views_list")) {
- getViewsList(request, response);
- }
- if(method.equals("get_view")) {
- getView(request, response);
- }
- if(method.equals("save_view")) {
- saveView(request, response);
- }
- if(method.equals("change_view_info")) {
- changeViewInfo(request, response);
- }
- if(method.equals("get_widget_list")) {
- getWidgetList(request, response);
- }
- if(method.equals("clone_view")) {
- cloneView(request, response);
- }
- if(method.equals("delete_view")) {
- deleteView(request, response);
- }
- }
-
- public void doPost(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
- doGet(request, response);
- }
-
- static public String getContents(File aFile) {
- //...checks on aFile are elided
- StringBuffer contents = new StringBuffer();
-
+ private String path = System.getProperty("catalina.home") + "/webapps/hicc";
+ private JSONObject hash = new JSONObject();
+ private String user = "admin";
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ response.setContentType("text/html");
+ PrintWriter out = response.getWriter();
+ String method = request.getParameter("method");
+ if (method.equals("get_views_list")) {
+ getViewsList(request, response);
+ }
+ if (method.equals("get_view")) {
+ getView(request, response);
+ }
+ if (method.equals("save_view")) {
+ saveView(request, response);
+ }
+ if (method.equals("change_view_info")) {
+ changeViewInfo(request, response);
+ }
+ if (method.equals("get_widget_list")) {
+ getWidgetList(request, response);
+ }
+ if (method.equals("clone_view")) {
+ cloneView(request, response);
+ }
+ if (method.equals("delete_view")) {
+ deleteView(request, response);
+ }
+ }
+
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ doGet(request, response);
+ }
+
+ static public String getContents(File aFile) {
+ // ...checks on aFile are elided
+ StringBuffer contents = new StringBuffer();
+
+ try {
+ // use buffering, reading one line at a time
+ // FileReader always assumes default encoding is OK!
+ BufferedReader input = new BufferedReader(new FileReader(aFile));
+ try {
+ String line = null; // not declared within while loop
+ /*
+ * readLine is a bit quirky : it returns the content of a line MINUS the
+ * newline. it returns null only for the END of the stream. it returns
+ * an empty String if two newlines appear in a row.
+ */
+ while ((line = input.readLine()) != null) {
+ contents.append(line);
+ contents.append(System.getProperty("line.separator"));
+ }
+ } finally {
+ input.close();
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+
+ return contents.toString();
+ }
+
+ public void setContents(String fName, String buffer) {
+ try {
+ FileWriter fstream = new FileWriter(fName);
+ BufferedWriter out = new BufferedWriter(fstream);
+ out.write(buffer);
+ out.close();
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ }
+ }
+
+ public void cloneView(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ PrintWriter out = response.getWriter();
+ String name = request.getParameter("name");
+ String template = request.getParameter("clone_name");
+ File aFile = new File(path + "/views/" + template);
+ String config = getContents(aFile);
+ int i = 0;
+ boolean check = true;
+ while (check) {
+ String tmpName = name;
+ if (i > 0) {
+ tmpName = name + i;
+ }
+ File checkFile = new File(path + "/views/" + tmpName + ".view");
+ check = checkFile.exists();
+ if (!check) {
+ name = tmpName;
+ }
+ i = i + 1;
+ }
+ setContents(path + "/views/" + name + ".view", config);
+ File deleteCache = new File(path + "/views/workspace_view_list.cache");
+ deleteCache.delete();
+ genViewCache(path + "/views");
+ aFile = new File(path + "/views/workspace_view_list.cache");
+ String viewsCache = getContents(aFile);
+ out.println(viewsCache);
+ }
+
+ public void deleteView(HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ PrintWriter out = response.getWriter();
+ String name = request.getParameter("name");
+ File aFile = new File(path + "/views/" + name + ".view");
+ aFile.delete();
+ File deleteCache = new File(path + "/views/workspace_view_list.cache");
+ deleteCache.delete();
+ genViewCache(path + "/views");
+ }
+
+ public void getViewsList(HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ PrintWriter out = response.getWriter();
+ String format = request.getParameter("format");
+ File aFile = new File(path + "/views/workspace_view_list.cache");
+ String viewsCache = getContents(aFile);
+ out.println(viewsCache);
+ }
+
+ public void getView(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ PrintWriter out = response.getWriter();
+ String id = request.getParameter("id");
+ genViewCache(path + "/views");
+ File aFile = new File(path + "/views/" + id + ".view");
+ String view = getContents(aFile);
+ out.println(view);
+ }
+
+ public void changeViewInfo(HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ PrintWriter out = response.getWriter();
+ String id = request.getParameter("name");
+ String config = request.getParameter("config");
+ try {
+ JSONObject jt = new JSONObject(config);
+ File aFile = new File(path + "/views/" + id + ".view");
+ String original = getContents(aFile);
+ JSONObject updateObject = new JSONObject(original);
+ updateObject.put("description", jt.get("description"));
+ setContents(path + "/views/" + id + ".view", updateObject.toString());
+ if (!rename(id, jt.get("description").toString())) {
+ throw new Exception("Rename view file failed");
+ }
+ File deleteCache = new File(path + "/views/workspace_view_list.cache");
+ deleteCache.delete();
+ genViewCache(path + "/views");
+ out.println("Workspace is stored successfully.");
+ } catch (Exception e) {
+ out.println("Workspace store failed.");
+ }
+ }
+
+ public void saveView(HttpServletRequest request, HttpServletResponse response)
+ throws IOException, ServletException {
+ PrintWriter out = response.getWriter();
+ String id = request.getParameter("name");
+ String config = request.getParameter("config");
+ File aFile = new File(path + "/views/" + id + ".view");
+ setContents(path + "/views/" + id + ".view", config);
+ out.println("Workspace is stored successfully.");
+ }
+
+ public void getWidgetList(HttpServletRequest request,
+ HttpServletResponse response) throws IOException, ServletException {
+ PrintWriter out = response.getWriter();
+ String format = request.getParameter("format");
+ genWidgetCache(path + "/descriptors");
+ File aFile = new File(path + "/descriptors/workspace_plugin.cache");
+ String viewsCache = getContents(aFile);
+ out.println(viewsCache);
+ }
+
+ private void genViewCache(String source) {
+ File cacheFile = new File(source + "/workspace_view_list.cache");
+ if (!cacheFile.exists()) {
+ File dir = new File(source);
+ File[] filesWanted = dir.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".view");
+ }
+ });
+ JSONObject[] cacheGroup = new JSONObject[filesWanted.length];
+ for (int i = 0; i < filesWanted.length; i++) {
+ String buffer = getContents(filesWanted[i]);
try {
- //use buffering, reading one line at a time
- //FileReader always assumes default encoding is OK!
- BufferedReader input = new BufferedReader(new FileReader(aFile));
- try {
- String line = null; //not declared within while loop
- /*
- * readLine is a bit quirky :
- * it returns the content of a line MINUS the newline.
- * it returns null only for the END of the stream.
- * it returns an empty String if two newlines appear in a row.
- */
- while (( line = input.readLine()) != null){
- contents.append(line);
- contents.append(System.getProperty("line.separator"));
- }
- } finally {
- input.close();
- }
- }
- catch (IOException ex){
- ex.printStackTrace();
- }
-
- return contents.toString();
- }
-
- public void setContents(String fName, String buffer) {
- try {
- FileWriter fstream = new FileWriter(fName);
- BufferedWriter out = new BufferedWriter(fstream);
- out.write(buffer);
- out.close();
+ JSONObject jt = new JSONObject(buffer);
+ String fn = filesWanted[i].getName();
+ jt.put("key", fn.substring(0, (fn.length() - 5)));
+ cacheGroup[i] = jt;
} catch (Exception e) {
- System.err.println("Error: "+e.getMessage());
}
+ }
+ String viewList = convertObjectsToViewList(cacheGroup);
+ setContents(source + "/workspace_view_list.cache", viewList);
+ }
+ }
+
+ public String convertObjectsToViewList(JSONObject[] objArray) {
+ JSONArray jsonArr = new JSONArray();
+ JSONObject permission = new JSONObject();
+ JSONObject user = new JSONObject();
+ try {
+ permission.put("read", 1);
+ permission.put("modify", 1);
+ user.put("all", permission);
+ } catch (Exception e) {
+ System.err.println("JSON Exception: " + e.getMessage());
}
-
- public void cloneView(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
- PrintWriter out = response.getWriter();
- String name = request.getParameter("name");
- String template = request.getParameter("clone_name");
- File aFile = new File(path+"/views/"+template);
- String config = getContents(aFile);
- int i=0;
- boolean check=true;
- while(check) {
- String tmpName = name;
- if(i>0) {
- tmpName = name + i;
- }
- File checkFile = new File(path+"/views/"+tmpName+".view");
- check = checkFile.exists();
- if(!check) {
- name =tmpName;
- }
- i=i+1;
- }
- setContents(path+"/views/"+name+".view",config);
- File deleteCache = new File(path+"/views/workspace_view_list.cache");
- deleteCache.delete();
- genViewCache(path+"/views");
- aFile = new File(path+"/views/workspace_view_list.cache");
- String viewsCache = getContents(aFile);
- out.println(viewsCache);
- }
- public void deleteView(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
- PrintWriter out = response.getWriter();
- String name = request.getParameter("name");
- File aFile = new File(path+"/views/"+name+".view");
- aFile.delete();
- File deleteCache = new File(path+"/views/workspace_view_list.cache");
- deleteCache.delete();
- genViewCache(path+"/views");
- }
- public void getViewsList(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
- PrintWriter out = response.getWriter();
- String format = request.getParameter("format");
- File aFile = new File(path+"/views/workspace_view_list.cache");
- String viewsCache = getContents(aFile);
- out.println(viewsCache);
- }
- public void getView(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
- PrintWriter out = response.getWriter();
- String id = request.getParameter("id");
- genViewCache(path+"/views");
- File aFile = new File(path+"/views/"+id+".view");
- String view = getContents(aFile);
- out.println(view);
- }
- public void changeViewInfo(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
- PrintWriter out = response.getWriter();
- String id = request.getParameter("name");
- String config = request.getParameter("config");
- try {
- JSONObject jt = new JSONObject(config);
- File aFile = new File(path+"/views/"+id+".view");
- String original = getContents(aFile);
- JSONObject updateObject = new JSONObject(original);
- updateObject.put("description",jt.get("description"));
- setContents(path+"/views/"+id+".view",updateObject.toString());
- if(!rename(id,jt.get("description").toString())) {
- throw new Exception("Rename view file failed");
- }
- File deleteCache = new File(path+"/views/workspace_view_list.cache");
- deleteCache.delete();
- genViewCache(path+"/views");
- out.println("Workspace is stored successfully.");
- } catch(Exception e) {
- out.println("Workspace store failed.");
- }
- }
- public void saveView(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
- PrintWriter out = response.getWriter();
- String id = request.getParameter("name");
- String config = request.getParameter("config");
- File aFile = new File(path+"/views/"+id+".view");
- setContents(path+"/views/"+id+".view",config);
- out.println("Workspace is stored successfully.");
- }
- public void getWidgetList(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
- PrintWriter out = response.getWriter();
- String format = request.getParameter("format");
- genWidgetCache(path+"/descriptors");
- File aFile = new File(path+"/descriptors/workspace_plugin.cache");
- String viewsCache = getContents(aFile);
- out.println(viewsCache);
- }
- private void genViewCache(String source) {
- File cacheFile = new File(source+"/workspace_view_list.cache");
- if(! cacheFile.exists()) {
- File dir = new File(source);
- File[] filesWanted = dir.listFiles(
- new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".view");
- }
- });
- JSONObject[] cacheGroup = new JSONObject[filesWanted.length];
- for(int i=0; i< filesWanted.length; i++) {
- String buffer = getContents(filesWanted[i]);
- try {
- JSONObject jt = new JSONObject(buffer);
- String fn = filesWanted[i].getName();
- jt.put("key", fn.substring(0,(fn.length()-5)));
- cacheGroup[i] = jt;
- } catch (Exception e) {
- }
- }
- String viewList = convertObjectsToViewList(cacheGroup);
- setContents(source+"/workspace_view_list.cache", viewList);
- }
- }
- public String convertObjectsToViewList(JSONObject[] objArray) {
- JSONArray jsonArr = new JSONArray();
- JSONObject permission = new JSONObject();
- JSONObject user = new JSONObject();
- try {
- permission.put("read",1);
- permission.put("modify",1);
- user.put("all",permission);
- } catch (Exception e) {
- System.err.println("JSON Exception: "+e.getMessage());
- }
- for(int i=0;i<objArray.length;i++) {
- try {
- JSONObject jsonObj = new JSONObject();
- jsonObj.put("key",objArray[i].get("key"));
- jsonObj.put("description",objArray[i].get("description"));
- jsonObj.put("owner","");
- jsonObj.put("permission",user);
- jsonArr.put(jsonObj);
- } catch (Exception e) {
- System.err.println("JSON Exception: "+e.getMessage());
- }
- }
- return jsonArr.toString();
- }
- private void genWidgetCache(String source) {
- File cacheFile = new File(source+"/workspace_plugin.cache");
- File cacheDir = new File(source);
- if(! cacheFile.exists() || cacheFile.lastModified()<cacheDir.lastModified()) {
- File dir = new File(source);
- File[] filesWanted = dir.listFiles(
- new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return name.endsWith(".descriptor");
- }
- });
- JSONObject[] cacheGroup = new JSONObject[filesWanted.length];
- for(int i=0; i< filesWanted.length; i++) {
- String buffer = getContents(filesWanted[i]);
- try {
- JSONObject jt = new JSONObject(buffer);
- cacheGroup[i] = jt;
- } catch (Exception e) {
- }
- }
- String widgetList = convertObjectsToWidgetList(cacheGroup);
- setContents(source+"/workspace_plugin.cache", widgetList);
- }
- }
- public String convertObjectsToWidgetList(JSONObject[] objArray) {
+ for (int i = 0; i < objArray.length; i++) {
+ try {
JSONObject jsonObj = new JSONObject();
- JSONArray jsonArr = new JSONArray();
- for(int i=0;i<objArray.length;i++) {
- jsonArr.put(objArray[i]);
- }
+ jsonObj.put("key", objArray[i].get("key"));
+ jsonObj.put("description", objArray[i].get("description"));
+ jsonObj.put("owner", "");
+ jsonObj.put("permission", user);
+ jsonArr.put(jsonObj);
+ } catch (Exception e) {
+ System.err.println("JSON Exception: " + e.getMessage());
+ }
+ }
+ return jsonArr.toString();
+ }
+
+ private void genWidgetCache(String source) {
+ File cacheFile = new File(source + "/workspace_plugin.cache");
+ File cacheDir = new File(source);
+ if (!cacheFile.exists()
+ || cacheFile.lastModified() < cacheDir.lastModified()) {
+ File dir = new File(source);
+ File[] filesWanted = dir.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".descriptor");
+ }
+ });
+ JSONObject[] cacheGroup = new JSONObject[filesWanted.length];
+ for (int i = 0; i < filesWanted.length; i++) {
+ String buffer = getContents(filesWanted[i]);
try {
- jsonObj.put("detail", jsonArr);
+ JSONObject jt = new JSONObject(buffer);
+ cacheGroup[i] = jt;
} catch (Exception e) {
- System.err.println("JSON Exception: "+e.getMessage());
- }
- JSONObject tmpHash = new JSONObject();
- for(int i=0;i<objArray.length;i++) {
- try {
- String[] categoriesArray = objArray[i].get("categories").toString().split(",");
- hash = addToHash(hash,categoriesArray,objArray[i]);
- } catch (JSONException e) {
- System.err.println("JSON Exception: "+e.getMessage());
- }
}
+ }
+ String widgetList = convertObjectsToWidgetList(cacheGroup);
+ setContents(source + "/workspace_plugin.cache", widgetList);
+ }
+ }
+
+ public String convertObjectsToWidgetList(JSONObject[] objArray) {
+ JSONObject jsonObj = new JSONObject();
+ JSONArray jsonArr = new JSONArray();
+ for (int i = 0; i < objArray.length; i++) {
+ jsonArr.put(objArray[i]);
+ }
+ try {
+ jsonObj.put("detail", jsonArr);
+ } catch (Exception e) {
+ System.err.println("JSON Exception: " + e.getMessage());
+ }
+ JSONObject tmpHash = new JSONObject();
+ for (int i = 0; i < objArray.length; i++) {
+ try {
+ String[] categoriesArray = objArray[i].get("categories").toString()
+ .split(",");
+ hash = addToHash(hash, categoriesArray, objArray[i]);
+ } catch (JSONException e) {
+ System.err.println("JSON Exception: " + e.getMessage());
+ }
+ }
+ try {
+ jsonObj.put("children", hash);
+ } catch (Exception e) {
+ System.err.println("JSON Exception: " + e.getMessage());
+ }
+ return jsonObj.toString();
+ }
+
+ public JSONObject addToHash(JSONObject hash, String[] categoriesArray,
+ JSONObject obj) {
+ JSONObject subHash = hash;
+ for (int i = 0; i < categoriesArray.length; i++) {
+ String id = categoriesArray[i];
+ if (i >= categoriesArray.length - 1) {
try {
- jsonObj.put("children",hash);
+ subHash.put("leaf:" + obj.get("title"), obj.get("id"));
} catch (Exception e) {
- System.err.println("JSON Exception: "+e.getMessage());
+ System.err.println("JSON Exception: " + e.getMessage());
}
- return jsonObj.toString();
- }
- public JSONObject addToHash(JSONObject hash, String[] categoriesArray, JSONObject obj) {
- JSONObject subHash=hash;
- for(int i=0;i<categoriesArray.length;i++) {
- String id = categoriesArray[i];
- if(i>=categoriesArray.length-1) {
- try {
- subHash.put("leaf:"+obj.get("title"),obj.get("id"));
- } catch (Exception e) {
- System.err.println("JSON Exception: "+e.getMessage());
- }
- } else {
- try {
- subHash=subHash.getJSONObject("node:"+id);
- } catch (JSONException e) {
- try {
- JSONObject tmpHash = new JSONObject();
- subHash.put("node:"+id, tmpHash);
- subHash=tmpHash;
- } catch (JSONException ex) {
- }
- }
- }
+ } else {
+ try {
+ subHash = subHash.getJSONObject("node:" + id);
+ } catch (JSONException e) {
+ try {
+ JSONObject tmpHash = new JSONObject();
+ subHash.put("node:" + id, tmpHash);
+ subHash = tmpHash;
+ } catch (JSONException ex) {
+ }
}
- return hash;
- }
-
- private boolean rename(String id, String desc) {
- try {
- File view = new File(path+"/views/"+id+".view");
- File newFile = new File(path+File.separator+"views"+File.separator+desc+".view");
- view.renameTo(newFile);
- } catch(Exception e) {
- return false;
- }
- return true;
+ }
}
- private JSONObject filterViewsByPermission(String userid, JSONObject viewArray) {
- return viewArray;
- }
-}
-
-
+ return hash;
+ }
+ private boolean rename(String id, String desc) {
+ try {
+ File view = new File(path + "/views/" + id + ".view");
+ File newFile = new File(path + File.separator + "views" + File.separator
+ + desc + ".view");
+ view.renameTo(newFile);
+ } catch (Exception e) {
+ return false;
+ }
+ return true;
+ }
+
+ private JSONObject filterViewsByPermission(String userid, JSONObject viewArray) {
+ return viewArray;
+ }
+}
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/ChukwaInputFormat.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/ChukwaInputFormat.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/ChukwaInputFormat.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/ChukwaInputFormat.java Wed Mar 11 22:39:26 2009
@@ -18,8 +18,8 @@
package org.apache.hadoop.chukwa.inputtools;
-import java.io.IOException;
+import java.io.IOException;
import java.util.regex.*;
import org.apache.hadoop.chukwa.*;
import org.apache.hadoop.mapred.*;
@@ -30,76 +30,77 @@
import org.apache.log4j.Logger;
/***
- * An InputFormat for processing logfiles in Chukwa.
- * Designed to be a nearly drop-in replacement for the Hadoop default
- * TextInputFormat so that code can be ported to use Chukwa with minimal
- * modification.
- *
- * Has an optional configuration option, chukwa.inputfilter.datatype
- * which can be used to filter the input by datatype. If need
- * exists, this mechanism could be extended to also filter by
- * other fields.
+ * An InputFormat for processing logfiles in Chukwa. Designed to be a nearly
+ * drop-in replacement for the Hadoop default TextInputFormat so that code can
+ * be ported to use Chukwa with minimal modification.
+ *
+ * Has an optional configuration option, chukwa.inputfilter.datatype which can
+ * be used to filter the input by datatype. If need exists, this mechanism could
+ * be extended to also filter by other fields.
*
*/
-public class ChukwaInputFormat extends SequenceFileInputFormat<LongWritable, Text> {
+public class ChukwaInputFormat extends
+ SequenceFileInputFormat<LongWritable, Text> {
+
+ public static class ChukwaRecordReader implements
+ RecordReader<LongWritable, Text> {
- public static class ChukwaRecordReader implements RecordReader<LongWritable, Text> {
-
static Logger LOG = Logger.getLogger(ChukwaInputFormat.class);
-
+
private SequenceFileRecordReader<ChukwaArchiveKey, Chunk> sfrr;
- private long lineInFile =0;
+ private long lineInFile = 0;
private Chunk curChunk = null;
- private int lineInChunk; //outside of next, it's the array offset of next line to be returned
+ private int lineInChunk; // outside of next, it's the array offset of next
+ // line to be returned
private int[] lineOffsets = null;
private int byteOffsetOfLastLine = 0;
Pattern dtPattern;
-
-
+
public ChukwaRecordReader(Configuration conf, FileSplit split)
- throws IOException {
+ throws IOException {
sfrr = new SequenceFileRecordReader<ChukwaArchiveKey, Chunk>(conf, split);
- dtPattern = Pattern.compile(conf.get("chukwa.inputfilter.datatype", ".*"));
+ dtPattern = Pattern
+ .compile(conf.get("chukwa.inputfilter.datatype", ".*"));
}
-
+
@Override
public void close() throws IOException {
sfrr.close();
}
-
+
@Override
public LongWritable createKey() {
return new LongWritable();
}
-
+
@Override
public Text createValue() {
return new Text();
}
-
+
@Override
public long getPos() throws IOException {
return sfrr.getPos();
}
-
+
@Override
public float getProgress() throws IOException {
return sfrr.getProgress();
}
-
+
private boolean passesFilters(Chunk c) {
return dtPattern.matcher(c.getDataType()).matches();
}
-
+
@Override
public boolean next(LongWritable key, Text value) throws IOException {
- if(curChunk == null) {
+ if (curChunk == null) {
ChukwaArchiveKey k = new ChukwaArchiveKey();
curChunk = ChunkImpl.getBlankChunk();
boolean unfilteredChunk = false;
- while(!unfilteredChunk) {
+ while (!unfilteredChunk) {
boolean readOK = sfrr.next(k, curChunk);
- if(!readOK) {
+ if (!readOK) {
curChunk = null;
return false;
}
@@ -108,23 +109,23 @@
lineOffsets = curChunk.getRecordOffsets();
lineInChunk = 0;
byteOffsetOfLastLine = 0;
- } //end curChunk == null
- value.set(curChunk.getData(), byteOffsetOfLastLine , lineOffsets[lineInChunk]-byteOffsetOfLastLine);
- if(lineInChunk >= lineOffsets.length - 1) { //end of chunk
+ } // end curChunk == null
+ value.set(curChunk.getData(), byteOffsetOfLastLine,
+ lineOffsets[lineInChunk] - byteOffsetOfLastLine);
+ if (lineInChunk >= lineOffsets.length - 1) { // end of chunk
curChunk = null;
} else
- byteOffsetOfLastLine = lineOffsets[lineInChunk++]+1;
-
+ byteOffsetOfLastLine = lineOffsets[lineInChunk++] + 1;
+
key.set(lineInFile);
lineInFile++;
return true;
}
- } //end ChukwaRecordReader
+ } // end ChukwaRecordReader
@Override
public RecordReader<LongWritable, Text> getRecordReader(InputSplit split,
- JobConf job, Reporter reporter)
- throws IOException {
+ JobConf job, Reporter reporter) throws IOException {
reporter.setStatus(split.toString());
LOG.info("returning a new chukwa record reader");
return new ChukwaRecordReader(job, (FileSplit) split);
Modified: hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/ChukwaTTInstru.java
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/ChukwaTTInstru.java?rev=752666&r1=752665&r2=752666&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/ChukwaTTInstru.java (original)
+++ hadoop/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/ChukwaTTInstru.java Wed Mar 11 22:39:26 2009
@@ -17,55 +17,58 @@
*/
package org.apache.hadoop.chukwa.inputtools;
+
import java.io.File;
import java.util.Map;
import java.util.HashMap;
-
import org.apache.hadoop.chukwa.datacollection.controller.ChukwaAgentController;
import org.apache.hadoop.mapred.*;
/**
- * An instrumentation plugin for Hadoop, to trigger Chukwa-based task logfile collection.
+ * An instrumentation plugin for Hadoop, to trigger Chukwa-based task logfile
+ * collection.
+ *
+ * WARNING: This code depends on hadoop features only available in 0.19. It
+ * won't do any good if you try to use it with an earlier Hadoop.
*
- * WARNING: This code depends on hadoop features only available in 0.19.
- * It won't do any good if you try to use it with an earlier Hadoop.
- *
*/
-public class ChukwaTTInstru extends TaskTrackerMetricsInst
-{
+public class ChukwaTTInstru extends TaskTrackerMetricsInst {
private Map<TaskAttemptID, Long> stdOutAdaptors;
private Map<TaskAttemptID, Long> stdErrAdaptors;
private ChukwaAgentController chukwa;
-// private TaskTrackerMetricsInst parent; //for chaining together multiple
- //instrumentation subsystems
-
+
+ // private TaskTrackerMetricsInst parent; //for chaining together multiple
+ // instrumentation subsystems
+
public ChukwaTTInstru(TaskTracker t) {
super(t);
stdOutAdaptors = new HashMap<TaskAttemptID, Long>();
stdErrAdaptors = new HashMap<TaskAttemptID, Long>();
chukwa = new ChukwaAgentController();
}
-
- public void reportTaskLaunch(TaskAttemptID taskid, File stdout, File stderr) {
-// parent.reportTaskLaunch(taskid, stdout, stderr);
- long stdoutID = chukwa.addFile("unknown-userdata", stdout.getAbsolutePath());
- long stderrID = chukwa.addFile("unknown-userdata", stderr.getAbsolutePath());
+
+ public void reportTaskLaunch(TaskAttemptID taskid, File stdout, File stderr) {
+ // parent.reportTaskLaunch(taskid, stdout, stderr);
+ long stdoutID = chukwa
+ .addFile("unknown-userdata", stdout.getAbsolutePath());
+ long stderrID = chukwa
+ .addFile("unknown-userdata", stderr.getAbsolutePath());
stdOutAdaptors.put(taskid, stdoutID);
stdErrAdaptors.put(taskid, stderrID);
}
-
+
public void reportTaskEnd(TaskAttemptID taskid) {
try {
Long id = stdOutAdaptors.remove(taskid);
- if(id != null)
+ if (id != null)
chukwa.remove(id);
-
+
id = stdErrAdaptors.remove(taskid);
- if(id != null)
+ if (id != null)
chukwa.remove(id);
- } catch(java.io.IOException e) {
- //failed to talk to chukwa. Not much to be done.
+ } catch (java.io.IOException e) {
+ // failed to talk to chukwa. Not much to be done.
}
}
}