incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/2] git commit: Adding ServerContext to combine method on the IndexreadCombingCommand.
Date Tue, 23 Sep 2014 13:20:53 GMT
Adding ServerContext to combine method on the IndexreadCombingCommand.


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

Branch: refs/heads/master
Commit: 86f30c9aaea2d2061194b320147b61f0c0435a6b
Parents: 7db1e37
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Tue Sep 23 09:20:43 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Tue Sep 23 09:20:43 2014 -0400

----------------------------------------------------------------------
 .../blur/command/DocumentCountCombiner.java     |  2 +-
 .../org/apache/blur/command/TermsCommand.java   | 21 ++++++-------
 .../blur/command/TestBlurObjectCommand.java     | 11 +------
 .../org/apache/blur/command/ClusterCommand.java |  2 +-
 .../org/apache/blur/command/ClusterContext.java |  1 -
 .../blur/command/ControllerClusterContext.java  |  1 -
 .../blur/command/ControllerCommandManager.java  |  2 +-
 .../org/apache/blur/command/IndexContext.java   |  1 -
 .../blur/command/IndexReadCombiningCommand.java |  4 +--
 .../org/apache/blur/command/ServerContext.java  | 33 ++++++++++++++++++++
 .../blur/command/ShardCommandManager.java       | 28 +++++++++++++++--
 11 files changed, 74 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-command/src/main/java/org/apache/blur/command/DocumentCountCombiner.java
----------------------------------------------------------------------
diff --git a/blur-command/src/main/java/org/apache/blur/command/DocumentCountCombiner.java
b/blur-command/src/main/java/org/apache/blur/command/DocumentCountCombiner.java
index 45d6cd7..8d0abc2 100644
--- a/blur-command/src/main/java/org/apache/blur/command/DocumentCountCombiner.java
+++ b/blur-command/src/main/java/org/apache/blur/command/DocumentCountCombiner.java
@@ -52,7 +52,7 @@ public class DocumentCountCombiner extends Command implements ClusterCommand<Lon
   }
 
   @Override
-  public Long combine(Map<Shard, Integer> results) throws IOException {
+  public Long combine(ServerContext context, Map<Shard, Integer> results) throws IOException
{
     long total = 0;
     for (Integer i : results.values()) {
       total += i;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java
----------------------------------------------------------------------
diff --git a/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java b/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java
index 477db7f..2530fbe 100644
--- a/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java
+++ b/blur-command/src/main/java/org/apache/blur/command/TermsCommand.java
@@ -13,9 +13,6 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.index.TermsEnum.SeekStatus;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.util.BytesRef;
 
 import com.google.common.collect.Lists;
@@ -37,6 +34,7 @@ import com.google.common.collect.Sets;
  * License for the specific language governing permissions and limitations under
  * the License.
  */
+@SuppressWarnings("serial")
 public class TermsCommand extends Command implements ClusterCommand<List<String>>,
     IndexReadCombiningCommand<List<String>, List<String>> {
   private static final String NAME = "terms";
@@ -44,7 +42,7 @@ public class TermsCommand extends Command implements ClusterCommand<List<String>
   private static final String P_SIZE = "size";
   private static final String P_FIELD = "fieldName";
   private static final String P_START = "startWith";
-      
+
   private static final short DEFAULT_SIZE = 10;
 
   @Override
@@ -58,13 +56,14 @@ public class TermsCommand extends Command implements ClusterCommand<List<String>
   }
 
   @Override
-  public List<String> combine(Map<Shard, List<String>> results) throws
IOException {
+  public List<String> combine(ServerContext context, Map<Shard, List<String>>
results) throws IOException {
     TreeSet<String> terms = Sets.newTreeSet();
-    
-    for(List<String> t: results.values()) {
+
+    for (List<String> t : results.values()) {
       terms.addAll(t);
     }
-    //TODO: Use default until we figure out the requested size from the context.
+    // TODO: Use default until we figure out the requested size from the
+    // context.
     return Lists.newArrayList(terms).subList(0, Math.min(DEFAULT_SIZE, terms.size()));
   }
 
@@ -80,7 +79,7 @@ public class TermsCommand extends Command implements ClusterCommand<List<String>
 
   private static List<String> terms(IndexReader reader, String fieldName, String startWith,
short size)
       throws IOException {
-    
+
     Term term = getTerm(fieldName, startWith);
     List<String> terms = new ArrayList<String>(size);
     AtomicReader areader = BlurUtil.getAtomicReader(reader);
@@ -91,9 +90,9 @@ public class TermsCommand extends Command implements ClusterCommand<List<String>
     }
 
     TermsEnum termEnum = termsAll.iterator(null);
-    
+
     SeekStatus status = termEnum.seekCeil(term.bytes());
-    
+
     if (status == SeekStatus.END) {
       return terms;
     }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-command/src/main/java/org/apache/blur/command/TestBlurObjectCommand.java
----------------------------------------------------------------------
diff --git a/blur-command/src/main/java/org/apache/blur/command/TestBlurObjectCommand.java
b/blur-command/src/main/java/org/apache/blur/command/TestBlurObjectCommand.java
index e7de338..63b11b8 100644
--- a/blur-command/src/main/java/org/apache/blur/command/TestBlurObjectCommand.java
+++ b/blur-command/src/main/java/org/apache/blur/command/TestBlurObjectCommand.java
@@ -20,15 +20,6 @@ import java.io.IOException;
 import java.util.Map;
 import java.util.Map.Entry;
 
-import org.apache.blur.command.Command;
-import org.apache.blur.command.BlurObject;
-import org.apache.blur.command.ClusterCommand;
-import org.apache.blur.command.ClusterContext;
-import org.apache.blur.command.IndexContext;
-import org.apache.blur.command.IndexReadCombiningCommand;
-import org.apache.blur.command.Server;
-import org.apache.blur.command.Shard;
-
 @SuppressWarnings("serial")
 public class TestBlurObjectCommand extends Command implements IndexReadCombiningCommand<BlurObject,
BlurObject>,
     ClusterCommand<BlurObject> {
@@ -41,7 +32,7 @@ public class TestBlurObjectCommand extends Command implements IndexReadCombining
   }
 
   @Override
-  public BlurObject combine(Map<Shard, BlurObject> results) throws IOException {
+  public BlurObject combine(ServerContext context, Map<Shard, BlurObject> results)
throws IOException {
     BlurObject blurObject = new BlurObject();
     long total = 0;
     for (Entry<Shard, BlurObject> e : results.entrySet()) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-core/src/main/java/org/apache/blur/command/ClusterCommand.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/ClusterCommand.java b/blur-core/src/main/java/org/apache/blur/command/ClusterCommand.java
index 7d65c85..38beed0 100644
--- a/blur-core/src/main/java/org/apache/blur/command/ClusterCommand.java
+++ b/blur-core/src/main/java/org/apache/blur/command/ClusterCommand.java
@@ -22,6 +22,6 @@ import java.io.Serializable;
 
 public interface ClusterCommand<T> extends Serializable, Cloneable {
 
-  T clusterExecute(ClusterContext context) throws IOException;
+  T clusterExecute(ClusterContext context) throws IOException, InterruptedException;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java b/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java
index 5b7040f..c140c7f 100644
--- a/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java
+++ b/blur-core/src/main/java/org/apache/blur/command/ClusterContext.java
@@ -6,7 +6,6 @@ import java.util.concurrent.Future;
 
 import org.apache.blur.BlurConfiguration;
 import org.apache.blur.server.TableContext;
-import org.apache.hadoop.conf.Configuration;
 
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java
b/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java
index ea7dbc7..bcb8e74 100644
--- a/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java
+++ b/blur-core/src/main/java/org/apache/blur/command/ControllerClusterContext.java
@@ -27,7 +27,6 @@ import org.apache.blur.thrift.generated.BlurException;
 import org.apache.blur.thrift.generated.Response;
 import org.apache.blur.thrift.generated.TimeoutException;
 import org.apache.blur.thrift.generated.ValueObject;
-import org.apache.hadoop.conf.Configuration;
 
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-core/src/main/java/org/apache/blur/command/ControllerCommandManager.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/ControllerCommandManager.java
b/blur-core/src/main/java/org/apache/blur/command/ControllerCommandManager.java
index cf99473..e33b8be 100644
--- a/blur-core/src/main/java/org/apache/blur/command/ControllerCommandManager.java
+++ b/blur-core/src/main/java/org/apache/blur/command/ControllerCommandManager.java
@@ -58,7 +58,7 @@ public class ControllerCommandManager extends BaseCommandManager {
     });
   }
 
-  private Response executeClusterCommand(ClusterContext context, Command command) throws
IOException {
+  private Response executeClusterCommand(ClusterContext context, Command command) throws
IOException, InterruptedException {
     ClusterCommand<Object> clusterCommand = (ClusterCommand<Object>) command;
     Object object = clusterCommand.clusterExecute(context);
     return Response.createNewAggregateResponse(object);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-core/src/main/java/org/apache/blur/command/IndexContext.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/IndexContext.java b/blur-core/src/main/java/org/apache/blur/command/IndexContext.java
index 02f260f..c1a1c06 100644
--- a/blur-core/src/main/java/org/apache/blur/command/IndexContext.java
+++ b/blur-core/src/main/java/org/apache/blur/command/IndexContext.java
@@ -2,7 +2,6 @@ package org.apache.blur.command;
 
 import org.apache.blur.BlurConfiguration;
 import org.apache.blur.server.TableContext;
-import org.apache.hadoop.conf.Configuration;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.IndexSearcher;
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-core/src/main/java/org/apache/blur/command/IndexReadCombiningCommand.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/IndexReadCombiningCommand.java
b/blur-core/src/main/java/org/apache/blur/command/IndexReadCombiningCommand.java
index 59486a1..f74c080 100644
--- a/blur-core/src/main/java/org/apache/blur/command/IndexReadCombiningCommand.java
+++ b/blur-core/src/main/java/org/apache/blur/command/IndexReadCombiningCommand.java
@@ -21,8 +21,8 @@ import java.util.Map;
 
 public interface IndexReadCombiningCommand<T1, T2> {
 
-  T1 execute(IndexContext context) throws IOException;
+  T1 execute(IndexContext context) throws IOException, InterruptedException;
 
-  T2 combine(Map<Shard, T1> results) throws IOException;
+  T2 combine(ServerContext context, Map<Shard, T1> results) throws IOException, InterruptedException;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-core/src/main/java/org/apache/blur/command/ServerContext.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/ServerContext.java b/blur-core/src/main/java/org/apache/blur/command/ServerContext.java
new file mode 100644
index 0000000..81673b9
--- /dev/null
+++ b/blur-core/src/main/java/org/apache/blur/command/ServerContext.java
@@ -0,0 +1,33 @@
+package org.apache.blur.command;
+
+import java.io.IOException;
+
+import org.apache.blur.BlurConfiguration;
+import org.apache.blur.server.TableContext;
+
+/**
+ * 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.
+ */
+
+public abstract class ServerContext {
+
+  public abstract Args getArgs();
+
+  public abstract TableContext getTableContext(String table) throws IOException;
+
+  public abstract BlurConfiguration getBlurConfiguration(String table) throws IOException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/86f30c9a/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java b/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java
index 731caf4..562f0c9 100644
--- a/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java
+++ b/blur-core/src/main/java/org/apache/blur/command/ShardCommandManager.java
@@ -57,10 +57,31 @@ public class ShardCommandManager extends BaseCommandManager {
           throw new IOException("Command with name [" + commandName + "] not found.");
         }
         if (command instanceof IndexReadCommand || command instanceof IndexReadCombiningCommand)
{
-          return toResponse(executeReadCommand(shardServerContext, command, tableContextFactory,
args), command);
+          return toResponse(executeReadCommand(shardServerContext, command, tableContextFactory,
args), command,
+              getServerContext(args, tableContextFactory));
         }
         throw new IOException("Command type of [" + command.getClass() + "] not supported.");
       }
+
+      private ServerContext getServerContext(final Args args, final TableContextFactory tableContextFactory)
{
+        return new ServerContext() {
+
+          @Override
+          public TableContext getTableContext(String table) throws IOException {
+            return tableContextFactory.getTableContext(table);
+          }
+
+          @Override
+          public Args getArgs() {
+            return args;
+          }
+
+          @Override
+          public BlurConfiguration getBlurConfiguration(String table) throws IOException
{
+            return getTableContext(table).getBlurConfiguration();
+          }
+        };
+      }
     };
     return submitDriverCallable(callable);
   }
@@ -74,10 +95,11 @@ public class ShardCommandManager extends BaseCommandManager {
   }
 
   @SuppressWarnings("unchecked")
-  private Response toResponse(Map<Shard, Object> results, Command command) throws IOException
{
+  private Response toResponse(Map<Shard, Object> results, Command command, ServerContext
serverContext)
+      throws IOException, InterruptedException {
     if (command instanceof IndexReadCombiningCommand) {
       IndexReadCombiningCommand<Object, Object> primitiveCommandAggregator = (IndexReadCombiningCommand<Object,
Object>) command;
-      Object object = primitiveCommandAggregator.combine(results);
+      Object object = primitiveCommandAggregator.combine(serverContext, results);
       return Response.createNewAggregateResponse(object);
     }
     return Response.createNewShardResponse(results);


Mime
View raw message