incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cr...@apache.org
Subject [9/9] git commit: Finished BLUR-367
Date Fri, 05 Dec 2014 00:55:10 GMT
Finished BLUR-367


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/2484173d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/2484173d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/2484173d

Branch: refs/heads/master
Commit: 2484173d0af14091ec76d1d8d3681b9089a25007
Parents: ea10c5b
Author: Chris Rohr <rohr.chris@gmail.com>
Authored: Thu Dec 4 19:54:25 2014 -0500
Committer: Chris Rohr <rohr.chris@gmail.com>
Committed: Thu Dec 4 19:54:25 2014 -0500

----------------------------------------------------------------------
 .../org/apache/blur/console/JettyServer.java    | 32 ++++++++++--------
 .../blur/console/filters/LoggedInFilter.java    |  2 +-
 .../console/servlets/JavascriptServlet.java     |  2 +-
 .../blur/console/servlets/SearchServlet.java    | 18 +++++++++++
 .../org/apache/blur/console/util/HttpUtil.java  |  1 +
 .../apache/blur/console/util/SearchUtil.java    | 34 ++++++++++++++++++++
 blur-console/src/main/resources/log4j.xml       |  4 +++
 blur-console/src/main/webapp/index.html         |  2 +-
 .../src/main/webapp/js/blurconsole.data.js      | 18 +++++++++--
 .../src/main/webapp/js/blurconsole.facets.js    |  3 +-
 .../src/main/webapp/js/blurconsole.fake.js      |  5 ++-
 .../src/main/webapp/js/blurconsole.model.js     |  4 +--
 12 files changed, 99 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
----------------------------------------------------------------------
diff --git a/blur-console/src/main/java/org/apache/blur/console/JettyServer.java b/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
index 31313a9..35e2a4b 100644
--- a/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
+++ b/blur-console/src/main/java/org/apache/blur/console/JettyServer.java
@@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
 import org.eclipse.jetty.server.Handler;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.server.handler.ContextHandlerCollection;
 import org.eclipse.jetty.server.handler.HandlerList;
 import org.eclipse.jetty.server.session.HashSessionIdManager;
 import org.eclipse.jetty.server.session.HashSessionManager;
@@ -32,6 +33,7 @@ import org.eclipse.jetty.servlet.*;
 import org.eclipse.jetty.webapp.WebAppContext;
 
 import javax.servlet.DispatcherType;
+
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -77,29 +79,31 @@ public class JettyServer {
       }
     String warUrlString = warUrl.toExternalForm();
     WebAppContext staticContext = new WebAppContext(warUrlString, CONTEXTPATH);
-
+    staticContext.setSessionHandler(new SessionHandler());
 
     // service calls
-    ContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
-    servletContext.setContextPath("/console/service");
+//    ContextHandler servletContext = new ServletContextHandler(ServletContextHandler.SESSIONS);
+//    servletContext.setContextPath("/console/service");
     ServletHandler serviceHandler = new ServletHandler();
-    serviceHandler.addServletWithMapping(AuthServlet.class, "/auth/*");
-    serviceHandler.addServletWithMapping(NodesServlet.class, "/nodes/*");
-    serviceHandler.addServletWithMapping(TablesServlet.class, "/tables/*");
-    serviceHandler.addServletWithMapping(QueriesServlet.class, "/queries/*");
-    serviceHandler.addServletWithMapping(SearchServlet.class, "/search/*");
-    serviceHandler.addServletWithMapping(JavascriptServlet.class, "/config.js");
-    serviceHandler.addFilterWithMapping(LoggedInFilter.class, "/*", FilterMapping.REQUEST);
-    servletContext.setHandler(serviceHandler);
+    serviceHandler.addServletWithMapping(AuthServlet.class, "/service/auth/*");
+    serviceHandler.addServletWithMapping(NodesServlet.class, "/service/nodes/*");
+    serviceHandler.addServletWithMapping(TablesServlet.class, "/service/tables/*");
+    serviceHandler.addServletWithMapping(QueriesServlet.class, "/service/queries/*");
+    serviceHandler.addServletWithMapping(SearchServlet.class, "/service/search/*");
+    serviceHandler.addServletWithMapping(JavascriptServlet.class, "/service/config.js");
+    serviceHandler.addFilterWithMapping(LoggedInFilter.class, "/service/*", FilterMapping.REQUEST);
+//    servletContext.setHandler(serviceHandler);
+    staticContext.setServletHandler(serviceHandler);
 
 
-    HandlerList handlers = new HandlerList();
-    handlers.setHandlers(new Handler[] { servletContext, staticContext  });
+//    ContextHandlerCollection handlers = new ContextHandlerCollection();
+//    handlers.setHandlers(new Handler[] { /*servletContext,*/ staticContext  });
 
-    server.setHandler(handlers);
+    server.setHandler(staticContext);
     System.out.println("started server on http://localhost:" + port + CONTEXTPATH);
     try {
       server.start();
+      System.out.println(server.getHandlers()[0]);
     } catch (Exception e) {
       log.error("Error starting Blur Console Jetty Server.  Exiting", e);
       System.exit(1);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/java/org/apache/blur/console/filters/LoggedInFilter.java
----------------------------------------------------------------------
diff --git a/blur-console/src/main/java/org/apache/blur/console/filters/LoggedInFilter.java
b/blur-console/src/main/java/org/apache/blur/console/filters/LoggedInFilter.java
index 52372f3..846cf70 100644
--- a/blur-console/src/main/java/org/apache/blur/console/filters/LoggedInFilter.java
+++ b/blur-console/src/main/java/org/apache/blur/console/filters/LoggedInFilter.java
@@ -39,7 +39,7 @@ public class LoggedInFilter implements Filter {
     HttpSession session = request.getSession();
     String path = request.getServletPath();
     User user = (User) session.getAttribute("user");
-    if(path.startsWith("/auth") || path.startsWith("/config.js") || user != null) {
+    if(path.startsWith("/service/auth") || path.startsWith("/service/config.js") || user
!= null) {
       try {
         filterChain.doFilter(servletRequest, servletResponse);
       } catch(UnauthorizedException e) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/java/org/apache/blur/console/servlets/JavascriptServlet.java
----------------------------------------------------------------------
diff --git a/blur-console/src/main/java/org/apache/blur/console/servlets/JavascriptServlet.java
b/blur-console/src/main/java/org/apache/blur/console/servlets/JavascriptServlet.java
index ef99ee3..bbedf72 100644
--- a/blur-console/src/main/java/org/apache/blur/console/servlets/JavascriptServlet.java
+++ b/blur-console/src/main/java/org/apache/blur/console/servlets/JavascriptServlet.java
@@ -30,6 +30,6 @@ public class JavascriptServlet  extends BaseConsoleServlet {
   @Override
   protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
     String javascript = "blurconsole.config = {refreshtime: " + Config.getInt("blur.console.refreshtime",
Config.DEFAULT_REFRESH_TIME) + "}";
-    HttpUtil.sendResponse(res, javascript, HttpUtil.TEXT);
+    HttpUtil.sendResponse(res, javascript, HttpUtil.JS);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
----------------------------------------------------------------------
diff --git a/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
b/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
index 685676e..d0b8a57 100644
--- a/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
+++ b/blur-console/src/main/java/org/apache/blur/console/servlets/SearchServlet.java
@@ -38,6 +38,8 @@ public class SearchServlet extends BaseConsoleServlet {
     String path = req.getPathInfo();
     if (path == null) {
       search(req, res);
+    } else if ("/facets".equalsIgnoreCase(path)) {
+      facetSearch(req, res);
     } else {
       sendNotFound(res, req.getRequestURI());
     }
@@ -58,4 +60,20 @@ public class SearchServlet extends BaseConsoleServlet {
 
     HttpUtil.sendResponse(res, new ObjectMapper().writeValueAsString(results), HttpUtil.JSON);
   }
+
+  private void facetSearch(HttpServletRequest req, HttpServletResponse res) throws IOException
{
+    authorize(req, User.SEARCHER_ROLE);
+    Map<String, String[]> params = req.getParameterMap();
+    Map<String, Long> results = new HashMap<String, Long>();
+    try {
+      results = SearchUtil.facetSearch(params, currentUser(req));
+    } catch (IOException e) {
+      throw new IOException(e);
+    } catch (Exception e) {
+      sendError(res, e);
+      return;
+    }
+
+    HttpUtil.sendResponse(res, new ObjectMapper().writeValueAsString(results), HttpUtil.JSON);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/java/org/apache/blur/console/util/HttpUtil.java
----------------------------------------------------------------------
diff --git a/blur-console/src/main/java/org/apache/blur/console/util/HttpUtil.java b/blur-console/src/main/java/org/apache/blur/console/util/HttpUtil.java
index a86856e..2de9554 100644
--- a/blur-console/src/main/java/org/apache/blur/console/util/HttpUtil.java
+++ b/blur-console/src/main/java/org/apache/blur/console/util/HttpUtil.java
@@ -25,6 +25,7 @@ import java.io.IOException;
 public class HttpUtil {
   public static final String JSON = "application/json";
   public static final String TEXT = "plain/text";
+  public static final String JS = "text/javascript";
 
   public static void sendResponse(HttpServletResponse res, String body, String contentType)
throws IOException {
     res.setContentType(contentType);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
----------------------------------------------------------------------
diff --git a/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java b/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
index e1014f3..5befee6 100644
--- a/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
+++ b/blur-console/src/main/java/org/apache/blur/console/util/SearchUtil.java
@@ -52,6 +52,40 @@ public class SearchUtil {
     return searchAndFetch(table, query, rowQuery, start, fetch, families, user, securityUser);
   }
 
+  public static Map<String, Long> facetSearch(Map<String, String[]> params, User
user) throws IOException, TException {
+    String table = HttpUtil.getFirstParam(params.get("table"));
+    String query = HttpUtil.getFirstParam(params.get("query"));
+    String family = HttpUtil.getFirstParam(params.get("family"));
+    String column = HttpUtil.getFirstParam(params.get("column"));
+    String[] terms = params.get("terms[]");
+    String rowQuery = HttpUtil.getFirstParam(params.get("rowRecordOption"));
+    String securityUser = HttpUtil.getFirstParam(params.get("securityUser"));
+    
+    System.out.println(params);
+
+    Iface client = Config.getClient(user, securityUser);
+
+    BlurQuery blurQuery = new BlurQuery();
+
+    Query q = new Query(query, ROW_ROW_OPTION.equalsIgnoreCase(rowQuery), ScoreType.SUPER,
null, null);
+    blurQuery.setQuery(q);
+    blurQuery.setUserContext(user.getName());
+    for(String term : terms) {
+    	blurQuery.addToFacets(new Facet("+(+" + family + "." + column + ":(" + term + "))",
1000));
+    }
+
+    BlurResults blurResults = client.query(table, blurQuery);
+
+    List<Long> facetCounts = blurResults.getFacetCounts();
+    
+    Map<String, Long> countMap = new HashMap<String, Long>();
+    for (int i = 0; i < terms.length; i++) {
+    	countMap.put(terms[i], facetCounts.get(i));
+    }
+
+    return countMap;
+  }
+
   @SuppressWarnings({"unchecked", "rawtypes"})
   private static Map<String, Object> searchAndFetch(String table, String query, String
rowQuery, String start, String fetch, String[] families, User user, String securityUser) throws
IOException, TException {
     try {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/blur-console/src/main/resources/log4j.xml b/blur-console/src/main/resources/log4j.xml
index 8c988a7..8fd876b 100644
--- a/blur-console/src/main/resources/log4j.xml
+++ b/blur-console/src/main/resources/log4j.xml
@@ -26,6 +26,10 @@ under the License.
       <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
     </layout>
   </appender>
+  
+  <!-- logger name="org.eclipse.jetty">
+  	<level value="debug"/>
+  </logger -->
 
   <root>
     <priority value="warn"/>

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/blur-console/src/main/webapp/index.html b/blur-console/src/main/webapp/index.html
index c00ca69..eb83054 100644
--- a/blur-console/src/main/webapp/index.html
+++ b/blur-console/src/main/webapp/index.html
@@ -65,7 +65,7 @@ under the License.
     </nav>
     <div id="blurconsole"></div>
     <script src="js/blurconsole.js"></script>
-    <script src="/service/config.js"></script>
+    <script src="service/config.js"></script>
     <script type="text/javascript">
       $(function () { blurconsole.initModule( $('#blurconsole') ); });
     </script>

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/webapp/js/blurconsole.data.js
----------------------------------------------------------------------
diff --git a/blur-console/src/main/webapp/js/blurconsole.data.js b/blur-console/src/main/webapp/js/blurconsole.data.js
index 3767218..fa3e4b8 100644
--- a/blur-console/src/main/webapp/js/blurconsole.data.js
+++ b/blur-console/src/main/webapp/js/blurconsole.data.js
@@ -128,7 +128,20 @@ blurconsole.data = (function() {
       'data': params,
       'success': callback,
       'error': function(xhr) {
-        _handleError(xhr, 'tables');
+        _handleError(xhr, 'search');
+      }
+    });
+  }
+
+  function runFacetCount(query, table, family, column, terms, callback) {
+    var params = {table: table, query: query, family: family, column: column, terms: terms};
+
+    $.ajax('service/search/facets', {
+      'type': 'POST',
+      'data': params,
+      'success': callback,
+      'error': function(xhr) {
+        _handleError(xhr, 'search');
       }
     });
   }
@@ -145,6 +158,7 @@ blurconsole.data = (function() {
     getSchema : getSchema,
     findTerms : findTerms,
     copyTable : copyTable,
-    sendSearch : sendSearch
+    sendSearch : sendSearch,
+    runFacetCount : runFacetCount
   };
 }());
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/webapp/js/blurconsole.facets.js
----------------------------------------------------------------------
diff --git a/blur-console/src/main/webapp/js/blurconsole.facets.js b/blur-console/src/main/webapp/js/blurconsole.facets.js
index 921ff3f..9900f6c 100644
--- a/blur-console/src/main/webapp/js/blurconsole.facets.js
+++ b/blur-console/src/main/webapp/js/blurconsole.facets.js
@@ -151,8 +151,7 @@ blurconsole.facets = (function () {
 
     if (family && column && terms.length > 0) {
       $('.facetWarning', jqueryMap.modal).hide();
-      var facetQuery = '+(+' + family + '.' + column + ':(' + terms.join(' ') + '))';
-      blurconsole.model.search.runFacetCount(stateMap.query, stateMap.table, facetQuery,
_displayFacetCounts);
+      blurconsole.model.search.runFacetCount(stateMap.query, stateMap.table, family, column,
terms, _displayFacetCounts);
     } else {
       $('.facetWarning', jqueryMap.modal).show();
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/webapp/js/blurconsole.fake.js
----------------------------------------------------------------------
diff --git a/blur-console/src/main/webapp/js/blurconsole.fake.js b/blur-console/src/main/webapp/js/blurconsole.fake.js
index 84e8a73..5b05223 100644
--- a/blur-console/src/main/webapp/js/blurconsole.fake.js
+++ b/blur-console/src/main/webapp/js/blurconsole.fake.js
@@ -274,9 +274,8 @@ blurconsole.fake = (function() {
     }
   }
 
-  function runFacetCount(query, table, facetQuery, callback) {
-    console.log('sending fake facet count [' + facetQuery + '] on table [' + table + '] on
against query [' + query + ']');
-    var terms = facetQuery.match(/:\((.*)\)\)/)[1].split(' ');
+  function runFacetCount(query, table, family, column, terms, callback) {
+    console.log('sending fake facet count [' + terms + '] on table [' + table + '] on against
query [' + query + ']');
     var data = {};
     $.each(terms, function(i, term){
       data[term] = _randomNumber(100, true);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2484173d/blur-console/src/main/webapp/js/blurconsole.model.js
----------------------------------------------------------------------
diff --git a/blur-console/src/main/webapp/js/blurconsole.model.js b/blur-console/src/main/webapp/js/blurconsole.model.js
index abc78ed..c235217 100644
--- a/blur-console/src/main/webapp/js/blurconsole.model.js
+++ b/blur-console/src/main/webapp/js/blurconsole.model.js
@@ -481,8 +481,8 @@ blurconsole.model = (function() {
       _sendSearch();
     }
 
-    function runFacetCount( query, table, facetQuery, callback ) {
-      configMap.poller.runFacetCount(query, table, facetQuery, callback);
+    function runFacetCount( query, table, family, column, terms, callback ) {
+      configMap.poller.runFacetCount(query, table, family, column, terms, callback);
     }
 
     return {


Mime
View raw message