chukwa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject [05/22] chukwa git commit: CHUKWA-755. Added a reverse proxy to Solr for HICC. (Eric Yang)
Date Thu, 25 Jun 2015 20:48:36 GMT
CHUKWA-755. Added a reverse proxy to Solr for HICC.  (Eric Yang)


Project: http://git-wip-us.apache.org/repos/asf/chukwa/repo
Commit: http://git-wip-us.apache.org/repos/asf/chukwa/commit/d26630bf
Tree: http://git-wip-us.apache.org/repos/asf/chukwa/tree/d26630bf
Diff: http://git-wip-us.apache.org/repos/asf/chukwa/diff/d26630bf

Branch: refs/heads/master
Commit: d26630bff21d561832ac62b8c3aad9b528d96b61
Parents: 2d20ab5
Author: Eric Yang <eyang@apache.org>
Authored: Thu Jun 18 18:27:04 2015 -0700
Committer: Eric Yang <eyang@apache.org>
Committed: Thu Jun 18 18:27:04 2015 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |   2 +
 conf/chukwa-common.xml                          |   6 +
 .../hadoop/chukwa/hicc/proxy/HttpProxy.java     | 149 +++++++++++++++++++
 src/main/web/hicc/WEB-INF/web.xml               |   8 +-
 4 files changed, 161 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/chukwa/blob/d26630bf/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 26b9aa9..665ae09 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -4,6 +4,8 @@ Trunk (unreleased changes)
 
   NEW FEATURES
 
+    CHUKWA-755. Added a reverse proxy to Solr for HICC.  (Eric Yang)
+
     CHUKWA-746. Redesigned Chukwa dashboard.  (Eric Yang)
 
     CHUKWA-736. SSL support for chukwa. (Shreyas Subramanya)

http://git-wip-us.apache.org/repos/asf/chukwa/blob/d26630bf/conf/chukwa-common.xml
----------------------------------------------------------------------
diff --git a/conf/chukwa-common.xml b/conf/chukwa-common.xml
index 36165c6..c1d1ee0 100644
--- a/conf/chukwa-common.xml
+++ b/conf/chukwa-common.xml
@@ -33,6 +33,12 @@
     <description>Location of Chukwa data on HDFS</description>
   </property>
 
+  <property>
+    <name>chukwa.solr.url</name>
+    <value>http://localhost:7574/solr</value>
+    <description>Solr cloud URL</description>
+  </property>
+
   <!-- uncomment to enable network compression
   <property>
     <name>chukwaAgent.output.compress</name>

http://git-wip-us.apache.org/repos/asf/chukwa/blob/d26630bf/src/main/java/org/apache/hadoop/chukwa/hicc/proxy/HttpProxy.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/chukwa/hicc/proxy/HttpProxy.java b/src/main/java/org/apache/hadoop/chukwa/hicc/proxy/HttpProxy.java
new file mode 100644
index 0000000..c9413bd
--- /dev/null
+++ b/src/main/java/org/apache/hadoop/chukwa/hicc/proxy/HttpProxy.java
@@ -0,0 +1,149 @@
+/*
+ * 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.
+ */
+package org.apache.hadoop.chukwa.hicc.proxy;
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
+import org.apache.log4j.Logger;
+
+/**
+ * HTTP Proxy Servlet for Solr
+ *
+ */
+public class HttpProxy extends HttpServlet {
+  private static final long serialVersionUID = 7574L;
+  private final String USER_AGENT = "Mozilla/5.0";
+  private final static String SOLR_URL = "chukwa.solr.url";
+  private final static Logger LOG = Logger.getLogger(HttpProxy.class);
+  private ChukwaConfiguration conf = new ChukwaConfiguration();
+  private String solrUrl = null;
+
+  public HttpProxy() {
+    super();
+    solrUrl = conf.get(SOLR_URL);
+  }
+
+  protected void doGet(HttpServletRequest request, HttpServletResponse response)
+      throws ServletException, IOException {
+    // Create Get request dynamically to remote server
+    String url = solrUrl + request.getPathInfo()
+        + "?" + request.getQueryString();
+
+    URL obj = new URL(url);
+    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
+
+    // optional default is GET
+    con.setRequestMethod("GET");
+
+    // add request header
+    con.setRequestProperty("User-Agent", USER_AGENT);
+
+    int responseCode = con.getResponseCode();
+    LOG.info("Sending 'GET' request to URL : " + url);
+    LOG.info("Response Code : " + responseCode);
+
+    BufferedReader in = new BufferedReader(new InputStreamReader(
+        con.getInputStream()));
+    String inputLine;
+    StringBuffer response1 = new StringBuffer();
+
+    ServletOutputStream sout = response.getOutputStream();
+
+    while ((inputLine = in.readLine()) != null) {
+      response1.append(inputLine);
+      sout.write(inputLine.getBytes());
+    }
+    in.close();
+
+    sout.flush();
+
+  }
+
+  protected void doPost(HttpServletRequest request, HttpServletResponse response)
+      throws ServletException, IOException {
+    // Create Post request dynamically to remote server
+    String url = solrUrl + request.getPathInfo();
+
+    URL obj = new URL(url);
+    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
+
+    // add reuqest header
+    con.setRequestMethod("POST");
+    con.setRequestProperty("User-Agent", USER_AGENT);
+    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
+
+    StringBuilder sb = new StringBuilder();
+    @SuppressWarnings("rawtypes")
+    Map map = request.getParameterMap();
+    for (Object key : request.getParameterMap().keySet()) {
+      if (sb.length() > 0) {
+        sb.append('&');
+      }
+      String keyStr = (String) key;
+      String[] temp = (String[]) map.get(keyStr);
+      for (String s : temp) {
+        sb.append(URLEncoder.encode(keyStr, "UTF-8")).append('=')
+            .append(URLEncoder.encode(s, "UTF-8"));
+      }
+    }
+
+    String urlParameters = sb.toString();
+
+    // Send post request
+    con.setDoOutput(true);
+    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
+    wr.writeBytes(urlParameters);
+    wr.flush();
+    wr.close();
+
+    int responseCode = con.getResponseCode();
+    LOG.debug("\nSending 'POST' request to URL : " + url);
+    LOG.debug("Post parameters : " + urlParameters);
+    LOG.debug("Response Code : " + responseCode);
+
+    BufferedReader in = new BufferedReader(new InputStreamReader(
+        con.getInputStream()));
+    String inputLine;
+    StringBuffer response1 = new StringBuffer();
+
+    ServletOutputStream sout = response.getOutputStream();
+
+    while ((inputLine = in.readLine()) != null) {
+      response1.append(inputLine);
+      sout.write(inputLine.getBytes());
+    }
+    in.close();
+
+    sout.flush();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/chukwa/blob/d26630bf/src/main/web/hicc/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/src/main/web/hicc/WEB-INF/web.xml b/src/main/web/hicc/WEB-INF/web.xml
index 36e9691..2b2e685 100644
--- a/src/main/web/hicc/WEB-INF/web.xml
+++ b/src/main/web/hicc/WEB-INF/web.xml
@@ -47,16 +47,16 @@
         <servlet-class>org.apache.hadoop.chukwa.hicc.Workspace</servlet-class>
     </servlet>
     <servlet> 
-        <servlet-name>Iframe</servlet-name> 
-        <servlet-class>org.apache.hadoop.chukwa.hicc.Iframe</servlet-class> 
+        <servlet-name>SolrProxy</servlet-name> 
+        <servlet-class>org.apache.hadoop.chukwa.hicc.proxy.HttpProxy</servlet-class>

     </servlet>
     <servlet-mapping>
         <servlet-name>Workspace</servlet-name>
         <url-pattern>/Workspace</url-pattern>
     </servlet-mapping>
     <servlet-mapping> 
-        <servlet-name>Iframe</servlet-name> 
-        <url-pattern>/iframe/*</url-pattern> 
+        <servlet-name>SolrProxy</servlet-name> 
+        <url-pattern>/solr/*</url-pattern> 
     </servlet-mapping>
 
     <servlet>


Mime
View raw message