chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r780850 - in /hadoop/chukwa/trunk: ./ src/web/hicc/descriptors/ src/web/hicc/js/ src/web/hicc/js/workspace/ src/web/hicc/jsp/
Date Mon, 01 Jun 2009 21:58:44 GMT
Author: eyang
Date: Mon Jun  1 21:58:44 2009
New Revision: 780850

URL: http://svn.apache.org/viewvc?rev=780850&view=rev
Log:
CHUKWA-271. Added SQL client to HICC for SQL data exploration. (Eric Yang)

Added:
    hadoop/chukwa/trunk/src/web/hicc/descriptors/sql_client.descriptor
    hadoop/chukwa/trunk/src/web/hicc/jsp/query.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/sql_client.jsp
    hadoop/chukwa/trunk/src/web/hicc/jsp/table.jsp
Removed:
    hadoop/chukwa/trunk/src/web/hicc/descriptors/sql_charter.descriptor
Modified:
    hadoop/chukwa/trunk/CHANGES.txt
    hadoop/chukwa/trunk/src/web/hicc/js/flot.extend.js
    hadoop/chukwa/trunk/src/web/hicc/js/workspace/workspace.js

Modified: hadoop/chukwa/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/CHANGES.txt?rev=780850&r1=780849&r2=780850&view=diff
==============================================================================
--- hadoop/chukwa/trunk/CHANGES.txt (original)
+++ hadoop/chukwa/trunk/CHANGES.txt Mon Jun  1 21:58:44 2009
@@ -4,6 +4,8 @@
 
   NEW FEATURES
 
+    CHUKWA-271. Added SQL client to HICC for SQL data exploration. (Eric Yang)
+
     CHUKWA-210. Add new job conf metrics as database columns. (Cheng Zhang via Eric Yang)
 
     CHUKWA-91.  Additional test case for acks. (asrabkin)

Added: hadoop/chukwa/trunk/src/web/hicc/descriptors/sql_client.descriptor
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/descriptors/sql_client.descriptor?rev=780850&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/descriptors/sql_client.descriptor (added)
+++ hadoop/chukwa/trunk/src/web/hicc/descriptors/sql_client.descriptor Mon Jun  1 21:58:44
2009
@@ -0,0 +1,45 @@
+{
+"id":"sql_client",
+"title":"SQL Client",
+"version":"0.1",
+"categories":"Developer,Utility",
+"module":"iframe/jsp/sql_client.jsp",
+"description":"Display table or chart from SQL queries",
+"refresh":"0",
+"parameters":[
+{"name":"query","type":"text","value":"select host,max(sda_rkbs) from [system_metrics] where
timestamp between '[start]' and '[end]' group by host","label":"Query","edit":"1"},
+{"name":"_force_refresh","type":"string","value":"true","edit":"0"},
+{"name":"title","type":"string","label":"Title","value":"","edit":"1"},
+{"name":"x_axis_label","type":"string","value":"Host","label":"X Axis Label","edit":"1"},
+{"name":"y_axis_label","type":"string","value":"Bytes Per Second","label":"Y Axis Label","edit":"1"},
+{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
+{"name":"width","type":"select","value":"300","label":"Width","options":[
+{"label":"300","value":"300"},
+{"label":"400","value":"400"},
+{"label":"500","value":"500"},
+{"label":"600","value":"600"},
+{"label":"800","value":"800"},
+{"label":"1000","value":"1000"},
+{"label":"1200","value":"1200"}
+]},
+{"name":"height","type":"select","value":"400","label":"Height","options":[
+{"label":"200","value":"200"},
+{"label":"400","value":"400"},
+{"label":"600","value":"600"},
+{"label":"800","value":"800"},
+{"label":"1000","value":"1000"}
+]},
+{"name":"legend","type":"radio","value":"on","label":"Show Legends","options":[
+{"label":"On","value":"on"},
+{"label":"Off","value":"off"}
+]},
+{"name":"render","type":"select","value":"table","label":"Output Type","options":[
+{"label":"Table","value":"table"},
+{"label":"Area Chart","value":"area"},
+{"label":"Bar Chart","value":"bar"},
+{"label":"Line Chart","value":"line"},
+{"label":"Scatter Chart","value":"point"},
+{"label":"Stacked Area Chart","value":"stack-area"},
+]}
+]
+}

Modified: hadoop/chukwa/trunk/src/web/hicc/js/flot.extend.js
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/js/flot.extend.js?rev=780850&r1=780849&r2=780850&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/js/flot.extend.js (original)
+++ hadoop/chukwa/trunk/src/web/hicc/js/flot.extend.js Mon Jun  1 21:58:44 2009
@@ -252,13 +252,21 @@
     zoom=false;
   } else {
     if(parameters.indexOf("render=stack")>0) {
-      throw "force iframe refresh";
+      return false;
+    }
+    if(parameters.indexOf("_force_refresh")>0) {
+      return false;
     }
     var dataURL = url+"?"+parameters;
     $.get(dataURL,{format: 'json'}, function(data){
+      try {
         eval(data);
         wholePeriod();
         document.getElementById('placeholderTitle').innerHTML=chartTitle;
-      });
+      } catch(err) {
+        return false;
+      }
+    });
   }
+  return true;
 }

Modified: hadoop/chukwa/trunk/src/web/hicc/js/workspace/workspace.js
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/js/workspace/workspace.js?rev=780850&r1=780849&r2=780850&view=diff
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/js/workspace/workspace.js (original)
+++ hadoop/chukwa/trunk/src/web/hicc/js/workspace/workspace.js Mon Jun  1 21:58:44 2009
@@ -547,7 +547,7 @@
 	content+='<tr><td>'+'Refresh (min)'+':<\/td><td>';
 	content+='<input type="text" id="'+this.pageid+'_'+this.boxIndex + '_refreshrate" value="'
+ this.block_obj.refresh + '" size="20" maxlength="255"\/><\/td><\/tr>'
 
-      	content+='<tr><td colspan="2"><input class="formButton" type="button"
onclick="saveParameters(\'' + this.pageid+'_'+this.boxIndex + '\');saveView();" value="'+'Save'+'">&nbsp;<input
class="formButton" type="button" onclick="resetParameters(\'' + this.pageid+'_'+this.boxIndex
+ '\');" value="'+'Reset'+'"><\/td><\/tr><\/table><\/form>';
+      	content+='<tr><td colspan="2"><input class="formButton" type="button"
onclick="saveParameters(\'' + this.pageid+'_'+this.boxIndex + '\');" value="'+'Apply'+'">&nbsp;<input
class="formButton" type="button" onclick="resetParameters(\'' + this.pageid+'_'+this.boxIndex
+ '\');" value="'+'Reset'+'">&nbsp;<input class="formButton" type="button" onclick="closeEditBox(\''
+ this.pageid+'_'+this.boxIndex + '\');" value="'+'Close'+'"><\/td><\/tr><\/table><\/form>';
 	content+='<\/td><\/tr><\/table>';
 	content+='<br/>';
 
@@ -592,6 +592,9 @@
 	this.view.setModified(1);
 	this.reloadBoxData();
 
+    },
+
+    closeEditBox: function() {
 	// close the edit box
    	var editBox= $('dragableBoxEdit' + this.pageid+"_"+this.boxIndex);
       	editBox.style.display='none';
@@ -898,19 +901,31 @@
         parameters=this.getParametersString()+"&_s="+(d.getTime());
         if(document.getElementById('iframe'+this.pageid+"_"+this.boxIndex)) {
             var d = document.getElementById('iframe'+this.pageid+"_"+this.boxIndex);
+            var new_url=url.replace(/iframe\//,"");
+            var refresh_check = false;
             try {
-                var new_url=url.replace(/iframe\//,"");
-                d.contentWindow.refresh(new_url, parameters);
-       	        var now=new Date();
+                refresh_check = d.contentWindow.refresh(new_url, parameters);
+            } catch(err) {
+                refresh_check = false;
+            }
+            if(refresh_check) {
+ 	        var now=new Date();
                 $msg="<font style='font-size:9px;'>Updated: "+now.formatDate("H:i:s")+"&nbsp;&nbsp;</font>";
        	        $('dragableBoxStatusBar'+this.pageid+"_"+this.boxIndex).innerHTML=$msg;
                 if($('dragableBoxRefreshSource'+this.pageid+"_"+this.boxIndex)) {
                     $('dragableBoxRefreshSource'+this.pageid+"_"+this.boxIndex).setAttribute('alt','Refresh
Widget. '+$msg);
                     showHeader(this.pageid+"_"+this.boxIndex, 'hidden');
                 }
-                return false;
-            } catch(err) {
+            } else {
+	        var myAjax = new Ajax.Request(
+         	    url,
+         	    { method: 'get', 
+		      parameters: parameters,
+		      onSuccess: function(request) { loadContentComplete(request); }
+		    }		
+      		  );   
             }
+            return false;
         } 
 	var myAjax = new Ajax.Request(
          	url,
@@ -1232,6 +1247,10 @@
 	_currentView.pages[idsplit[0]].dragableBoxesArray[idsplit[1]].saveParameters();
 }
 
+function closeEditBox(id) {
+   var idsplit=id.split("_");
+	_currentView.pages[idsplit[0]].dragableBoxesArray[idsplit[1]].closeEditBox();
+}
 Array.prototype.exists = function (x) {
     for (var i = 0; i < this.length; i++) {
         if (this[i] == x) return true;

Added: hadoop/chukwa/trunk/src/web/hicc/jsp/query.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/query.jsp?rev=780850&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/query.jsp (added)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/query.jsp Mon Jun  1 21:58:44 2009
@@ -0,0 +1,113 @@
+<%
+/*
+ * 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.
+ */
+%>
+<%@ page import = "java.text.DecimalFormat,java.text.NumberFormat" %>
+<%@ page import = "java.sql.*" %>
+<%@ page import = "java.io.*" %>
+<%@ page import = "org.json.*" %>
+<%@ page import = "java.util.Calendar" %>
+<%@ page import = "java.util.Date" %>
+<%@ page import = "java.text.SimpleDateFormat" %>
+<%@ page import = "java.util.*" %>
+<%@ page import = "org.apache.hadoop.chukwa.hicc.ClusterConfig" %>
+<%@ page import = "org.apache.hadoop.chukwa.hicc.TimeHandler" %>
+<%@ page import = "org.apache.hadoop.chukwa.util.DatabaseWriter" %>
+<%@ page import = "org.apache.hadoop.chukwa.database.Macro" %>
+<%@ page import = "org.apache.hadoop.chukwa.util.XssFilter" %>
+<%@ page import = "org.apache.hadoop.chukwa.database.DatabaseConfig" %>
+<%
+    XssFilter xf = new XssFilter(request);
+    NumberFormat nf = new DecimalFormat("###,###,###,##0.00");
+    response.setHeader("boxId", xf.getParameter("boxId"));
+    response.setContentType("text/html; chartset=UTF-8//IGNORE");
+    String boxId=xf.getParameter("boxId");
+    String cluster = (String) session.getAttribute("cluster");
+    DatabaseWriter dbw = new DatabaseWriter(cluster);
+    String path = "";
+    Calendar now = Calendar.getInstance();
+    HashMap<String, Integer> index = new HashMap<String, Integer>();
+    long start = 0;
+    long end = now.getTimeInMillis();
+    String startS="";
+    String endS="";
+    String[] columns = xf.getParameterValues("column");
+    TimeHandler time = new TimeHandler(request, (String)session.getAttribute("time_zone"));
+    startS = time.getStartTimeText();
+    endS = time.getEndTimeText();
+    start = time.getStartTime();
+    end = time.getEndTime();
+    String queryMacro = session.getAttribute("query_"+xf.getParameter("boxId")).toString();
+    Macro mp = new Macro(start,end,queryMacro, request);
+    int pageNum = 0;
+    int rp = 15;
+    if(xf.getParameter("page")!=null) {
+      pageNum = Integer.parseInt(xf.getParameter("page"));
+      rp = Integer.parseInt(xf.getParameter("rp")); 
+    }
+    int total=0;
+    if(xf.getParameter("total")!=null) {
+      total = Integer.parseInt(xf.getParameter("total"));
+    }
+    StringBuilder query = new StringBuilder();
+    String q = mp.toString();
+    query.append(q);
+    
+    if(q.indexOf("select ")!=-1 && q.indexOf("limit")==-1) {
+      query.append(" limit ");
+      query.append(pageNum);
+      query.append(",");
+      query.append(rp);
+    }
+    
+    ResultSet rs = dbw.query(query.toString());
+    ResultSetMetaData rmeta = rs.getMetaData();
+    int col = rmeta.getColumnCount();
+    JSONObject data = new JSONObject();
+    JSONArray rows = new JSONArray();
+    while(rs.next()) {
+      JSONArray cells = new JSONArray();
+      for(int i=1;i<=col;i++) {
+        if(rmeta.getColumnType(i)==java.sql.Types.BIGINT) {
+          cells.put(nf.format(rs.getBigDecimal(i)));
+        } else if(rmeta.getColumnType(i)==java.sql.Types.TINYINT ||
+          rmeta.getColumnType(i)==java.sql.Types.INTEGER) {
+          cells.put(nf.format(rs.getInt(i)));
+        } else if(rmeta.getColumnType(i)==java.sql.Types.FLOAT ||
+          rmeta.getColumnType(i)==java.sql.Types.DOUBLE ||
+          rmeta.getColumnType(i)==java.sql.Types.DECIMAL ) {
+          cells.put(nf.format(rs.getDouble(i)));
+        } else {
+          cells.put(rs.getString(i));
+        }
+      }
+      JSONObject row = new JSONObject();
+      if(rs.getString(1)!=null) {
+        row.put("id",rs.getString(1));
+      } else {
+        row.put("id","null");
+      }
+      row.put("cell",cells);
+      rows.put(row);
+    }
+    data.put("page",pageNum);
+    data.put("rows",rows);
+    data.put("total",total);
+    dbw.close();
+    out.println(data.toString());
+%>

Added: hadoop/chukwa/trunk/src/web/hicc/jsp/sql_client.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/sql_client.jsp?rev=780850&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/sql_client.jsp (added)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/sql_client.jsp Mon Jun  1 21:58:44 2009
@@ -0,0 +1,69 @@
+<%
+/*
+ * 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.
+ */
+%>
+<%@ page import = "java.text.SimpleDateFormat" %>
+<%@ page import = "java.text.NumberFormat" %>
+<%@ page import = "java.util.Hashtable" %>
+<%@ page import = "java.util.Enumeration" %>
+<%@ page import = "java.util.Calendar" %>
+<%@ page import = "java.util.Date" %>
+<%@ page import = "java.util.regex.Pattern" %>
+<%@ page import = "java.util.regex.Matcher" %>
+<%@ page import = "org.apache.hadoop.chukwa.hicc.TimeHandler" %>
+<%@ page import = "org.apache.hadoop.chukwa.util.XssFilter" %>
+<%@ page import = "org.apache.hadoop.chukwa.util.ExceptionUtil" %>
+<%
+  RequestDispatcher disp = null;
+  XssFilter xf = new XssFilter(request);
+  response.setContentType("text/html; chartset=UTF-8//IGNORE");
+  response.setHeader("boxId", xf.getParameter("boxId"));
+  Pattern pDelete = Pattern.compile("delete*from", Pattern.CASE_INSENSITIVE);
+  Pattern pInsert = Pattern.compile("insert ", Pattern.CASE_INSENSITIVE);
+  Pattern pReplace = Pattern.compile("replace ", Pattern.CASE_INSENSITIVE);
+  Pattern pDrop = Pattern.compile("drop ", Pattern.CASE_INSENSITIVE);
+  Pattern pUpdate = Pattern.compile("update ", Pattern.CASE_INSENSITIVE);
+  try {
+    String format="table";
+    if(request.getParameter("render")!=null) {
+      format=xf.getParameter("render");
+    }
+    if(pDelete.matcher(xf.getParameter("query")).matches() ||
+       pInsert.matcher(xf.getParameter("query")).matches() ||
+       pReplace.matcher(xf.getParameter("query")).matches() ||
+       pDrop.matcher(xf.getParameter("query")).matches() ||
+       pUpdate.matcher(xf.getParameter("query")).matches()) {
+       throw new Exception("Read only query supported");
+    }
+    if(format.intern()=="table".intern()) {
+      disp = getServletContext( ).getRequestDispatcher("/jsp/table.jsp");
+      disp.forward(request, response);
+    } else if(format.intern()=="area".intern() ||
+        format.intern()=="bar".intern() ||
+        format.intern()=="line".intern() ||
+        format.intern()=="point".intern() ||
+        format.intern()=="stack-area".intern()) {
+      disp = getServletContext( ).getRequestDispatcher("/jsp/single-series-chart-javascript.jsp");
+      disp.forward(request, response);
+    }
+  } catch(Exception ex) {
+    out.println("Unsupported query.<pre>");
+    out.println(ExceptionUtil.getStackTrace(ex));
+    out.println("</pre>");
+  } 
+%>

Added: hadoop/chukwa/trunk/src/web/hicc/jsp/table.jsp
URL: http://svn.apache.org/viewvc/hadoop/chukwa/trunk/src/web/hicc/jsp/table.jsp?rev=780850&view=auto
==============================================================================
--- hadoop/chukwa/trunk/src/web/hicc/jsp/table.jsp (added)
+++ hadoop/chukwa/trunk/src/web/hicc/jsp/table.jsp Mon Jun  1 21:58:44 2009
@@ -0,0 +1,71 @@
+<%
+/*
+ * 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.
+ */
+%>
+<%@ page import = "java.text.SimpleDateFormat" %>
+<%@ page import = "java.sql.*" %>
+<%@ page import = "java.text.NumberFormat" %>
+<%@ page import = "java.util.Hashtable" %>
+<%@ page import = "java.util.Enumeration" %>
+<%@ page import = "java.util.Calendar" %>
+<%@ page import = "java.util.Date" %>
+<%@ page import = "org.apache.hadoop.chukwa.hicc.TimeHandler" %>
+<%@ page import = "org.apache.hadoop.chukwa.util.XssFilter" %>
+<%@ page import = "org.apache.hadoop.chukwa.util.DatabaseWriter" %>
+<%@ page import = "org.apache.hadoop.chukwa.database.Macro" %>
+<%
+  RequestDispatcher disp = null;
+  XssFilter xf = new XssFilter(request);
+  response.setContentType("text/html; chartset=UTF-8//IGNORE");
+  response.setHeader("boxId", xf.getParameter("boxId"));
+  String cluster = (String) session.getAttribute("cluster");
+  DatabaseWriter dbw = new DatabaseWriter(cluster);
+
+  TimeHandler time = new TimeHandler(request, (String)session.getAttribute("time_zone"));
+  long start = time.getStartTime();
+  long end = time.getEndTime();
+
+  Macro mp = new Macro(start,end,request.getParameter("query"));
+  String query = mp.toString();
+  ResultSet rs = dbw.query(query);
+  ResultSetMetaData rmeta = rs.getMetaData();
+  int col = rmeta.getColumnCount();
+  rs.last();
+  int size = rs.getRow();
+  StringBuilder url = new StringBuilder();
+  url.append("/jsp/table_viewer.jsp?");
+  url.append("total=");
+  url.append(size);
+  url.append("&boxId=");
+  url.append(xf.getParameter("boxId"));
+  url.append("&report=/hicc/jsp/query.jsp&height=");
+  url.append(xf.getParameter("height"));
+  url.append("&query=");
+  StringBuilder qid = new StringBuilder();
+  qid.append("query_");
+  qid.append(xf.getParameter("boxId"));
+  session.setAttribute(qid.toString(),request.getParameter("query"));
+  for(int i=1;i<=col;i++) {
+    url.append("&column=");
+    url.append(rmeta.getColumnName(i));
+    url.append("&columnSize=200");
+    url.append("&columnAlign=left");
+  }
+  disp = getServletContext( ).getRequestDispatcher(url.toString());
+  disp.forward(request, response);
+%>



Mime
View raw message