incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: More API updates, getting close to a final API.
Date Thu, 28 Aug 2014 14:15:24 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/master 42a77a51e -> a63a79a1e


More API updates, getting close to a final API.


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

Branch: refs/heads/master
Commit: a63a79a1e05e2d4a8ef4c11679ed2511b052ca9b
Parents: 42a77a5
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Thu Aug 28 10:15:07 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Thu Aug 28 10:15:07 2014 -0400

----------------------------------------------------------------------
 .../blur/manager/command/CommandAggregator.java | 27 --------
 .../blur/manager/command/CommandContext.java    |  5 +-
 .../command/IndexReadCombiningCommand.java      | 31 ++++++++++
 .../manager/command/IndexReadWriteCommand.java  | 28 ---------
 .../blur/manager/command/IndexWriteCommand.java | 28 +++++++++
 .../org/apache/blur/manager/command/Server.java | 65 ++++++++++++++++++++
 .../org/apache/blur/manager/command/Shard.java  | 64 +++++++++++++++++++
 .../manager/command/ShardCommandManager.java    | 12 ++--
 .../primitive/DocumentCountAggregator.java      | 19 ++++--
 9 files changed, 211 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a63a79a1/blur-core/src/main/java/org/apache/blur/manager/command/CommandAggregator.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/CommandAggregator.java
b/blur-core/src/main/java/org/apache/blur/manager/command/CommandAggregator.java
deleted file mode 100644
index e46b289..0000000
--- a/blur-core/src/main/java/org/apache/blur/manager/command/CommandAggregator.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * 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.blur.manager.command;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Map.Entry;
-
-public interface CommandAggregator<IN, OUT> {
-
-  OUT aggregate(Iterator<Entry<String, IN>> it) throws IOException;
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a63a79a1/blur-core/src/main/java/org/apache/blur/manager/command/CommandContext.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/CommandContext.java b/blur-core/src/main/java/org/apache/blur/manager/command/CommandContext.java
index 145a94b..1ded8cb 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/command/CommandContext.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/command/CommandContext.java
@@ -21,6 +21,9 @@ import java.util.Map;
 
 public abstract class CommandContext {
 
-  public abstract <T> Map<String, T> execute(Args args, String string);
+  public abstract <T> Map<Shard, T> readIndexes(Args args, Class<? extends
IndexReadCommand<T>> clazz);
 
+  public abstract <T> Map<Server, T> readServers(Args args, Class<? extends
IndexReadCombiningCommand<?, T>> clazz);
+
+  public abstract <T> T writeIndex(Args args, Class<? extends IndexWriteCommand<T>>
clazz);
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a63a79a1/blur-core/src/main/java/org/apache/blur/manager/command/IndexReadCombiningCommand.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/IndexReadCombiningCommand.java
b/blur-core/src/main/java/org/apache/blur/manager/command/IndexReadCombiningCommand.java
new file mode 100644
index 0000000..6cf7e9d
--- /dev/null
+++ b/blur-core/src/main/java/org/apache/blur/manager/command/IndexReadCombiningCommand.java
@@ -0,0 +1,31 @@
+/**
+ * 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.blur.manager.command;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.lucene.search.IndexSearcher;
+
+public interface IndexReadCombiningCommand<T1, T2> {
+
+  T1 execute(Args args, IndexSearcher searcher) throws IOException;
+
+  T2 combine(Iterator<Entry<String, T1>> it) throws IOException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a63a79a1/blur-core/src/main/java/org/apache/blur/manager/command/IndexReadWriteCommand.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/IndexReadWriteCommand.java
b/blur-core/src/main/java/org/apache/blur/manager/command/IndexReadWriteCommand.java
deleted file mode 100644
index 4eb5f7e..0000000
--- a/blur-core/src/main/java/org/apache/blur/manager/command/IndexReadWriteCommand.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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.blur.manager.command;
-
-import java.io.IOException;
-
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.search.IndexSearcher;
-
-public interface IndexReadWriteCommand<T> {
-
-  public abstract T execute(Args args, IndexSearcher searcher, IndexWriter writer) throws
IOException;
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a63a79a1/blur-core/src/main/java/org/apache/blur/manager/command/IndexWriteCommand.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/IndexWriteCommand.java
b/blur-core/src/main/java/org/apache/blur/manager/command/IndexWriteCommand.java
new file mode 100644
index 0000000..01e49f6
--- /dev/null
+++ b/blur-core/src/main/java/org/apache/blur/manager/command/IndexWriteCommand.java
@@ -0,0 +1,28 @@
+/**
+ * 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.blur.manager.command;
+
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.search.IndexSearcher;
+
+public interface IndexWriteCommand<T> {
+
+  public abstract T execute(Args args, IndexSearcher searcher, IndexWriter writer) throws
IOException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a63a79a1/blur-core/src/main/java/org/apache/blur/manager/command/Server.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/Server.java b/blur-core/src/main/java/org/apache/blur/manager/command/Server.java
new file mode 100644
index 0000000..64208af
--- /dev/null
+++ b/blur-core/src/main/java/org/apache/blur/manager/command/Server.java
@@ -0,0 +1,65 @@
+package org.apache.blur.manager.command;
+
+/**
+ * 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 class Server implements Comparable<Server> {
+
+  private final String _server;
+
+  public Server(String server) {
+    _server = server;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((_server == null) ? 0 : _server.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Server other = (Server) obj;
+    if (_server == null) {
+      if (other._server != null)
+        return false;
+    } else if (!_server.equals(other._server))
+      return false;
+    return true;
+  }
+
+  public String getServer() {
+    return _server;
+  }
+
+  @Override
+  public int compareTo(Server o) {
+    if (o == null) {
+      return -1;
+    }
+    return _server.compareTo(o._server);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a63a79a1/blur-core/src/main/java/org/apache/blur/manager/command/Shard.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/Shard.java b/blur-core/src/main/java/org/apache/blur/manager/command/Shard.java
new file mode 100644
index 0000000..491cd3e
--- /dev/null
+++ b/blur-core/src/main/java/org/apache/blur/manager/command/Shard.java
@@ -0,0 +1,64 @@
+package org.apache.blur.manager.command;
+
+/**
+ * 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 class Shard  implements Comparable<Shard> {
+  
+  private final String _shard;
+
+  public Shard(String shard) {
+    _shard = shard;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((_shard == null) ? 0 : _shard.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Shard other = (Shard) obj;
+    if (_shard == null) {
+      if (other._shard != null)
+        return false;
+    } else if (!_shard.equals(other._shard))
+      return false;
+    return true;
+  }
+
+  public String getShard() {
+    return _shard;
+  }
+  
+  @Override
+  public int compareTo(Shard o) {
+    if (o == null) {
+      return -1;
+    }
+    return _shard.compareTo(o._shard);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a63a79a1/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java
b/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java
index ad232dc..7bd2e70 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/command/ShardCommandManager.java
@@ -67,24 +67,24 @@ public class ShardCommandManager implements Closeable {
     }
     if (command instanceof IndexReadCommand) {
       return toResponse(executeReadCommand(command, table, args), command);
-    } else if (command instanceof IndexReadWriteCommand) {
-      return toResponse(executeReadWriteCommand((IndexReadWriteCommand<?>) command,
table, args), command);
+    } else if (command instanceof IndexWriteCommand) {
+      return toResponse(executeReadWriteCommand((IndexWriteCommand<?>) command, table,
args), command);
     }
     throw new IOException("Command type of [" + command.getClass() + "] not supported.");
   }
 
   @SuppressWarnings("unchecked")
   private Response toResponse(Map<String, Object> results, BaseCommand command) throws
IOException {
-    if (command instanceof CommandAggregator) {
-      CommandAggregator<Object, Object> primitiveCommandAggregator = (CommandAggregator<Object,
Object>) command;
+    if (command instanceof IndexReadCombiningCommand) {
+      IndexReadCombiningCommand<Object, Object> primitiveCommandAggregator = (IndexReadCombiningCommand<Object,
Object>) command;
       Iterator<Entry<String, Object>> iterator = results.entrySet().iterator();
-      Object object = primitiveCommandAggregator.aggregate(iterator);
+      Object object = primitiveCommandAggregator.combine(iterator);
       return Response.createNewAggregateResponse(object);
     }
     return Response.createNewResponse(results);
   }
 
-  private Map<String, Object> executeReadWriteCommand(IndexReadWriteCommand<?>
command, String table, Args args) {
+  private Map<String, Object> executeReadWriteCommand(IndexWriteCommand<?> command,
String table, Args args) {
     return null;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a63a79a1/blur-core/src/main/java/org/apache/blur/manager/command/primitive/DocumentCountAggregator.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/command/primitive/DocumentCountAggregator.java
b/blur-core/src/main/java/org/apache/blur/manager/command/primitive/DocumentCountAggregator.java
index f876cd1..cf4533e 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/command/primitive/DocumentCountAggregator.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/command/primitive/DocumentCountAggregator.java
@@ -23,12 +23,14 @@ import java.util.Map.Entry;
 
 import org.apache.blur.manager.command.Args;
 import org.apache.blur.manager.command.ClusterCommand;
-import org.apache.blur.manager.command.CommandAggregator;
 import org.apache.blur.manager.command.CommandContext;
+import org.apache.blur.manager.command.IndexReadCombiningCommand;
+import org.apache.blur.manager.command.Server;
+import org.apache.lucene.search.IndexSearcher;
 
 @SuppressWarnings("serial")
-public class DocumentCountAggregator extends DocumentCount implements ClusterCommand<Long>,
-    CommandAggregator<Integer, Long> {
+public class DocumentCountAggregator extends BaseCommand implements ClusterCommand<Long>,
+    IndexReadCombiningCommand<Integer, Long> {
 
   private static final String DOC_COUNT_AGGREGATE = "docCountAggregate";
 
@@ -38,7 +40,12 @@ public class DocumentCountAggregator extends DocumentCount implements ClusterCom
   }
 
   @Override
-  public Long aggregate(Iterator<Entry<String, Integer>> it) throws IOException
{
+  public Integer execute(Args args, IndexSearcher searcher) throws IOException {
+    return (int) searcher.getIndexReader().numDocs();
+  }
+
+  @Override
+  public Long combine(Iterator<Entry<String, Integer>> it) throws IOException
{
     long total = 0;
     while (it.hasNext()) {
       total += it.next().getValue();
@@ -49,9 +56,9 @@ public class DocumentCountAggregator extends DocumentCount implements ClusterCom
   @Override
   public Long clusterExecute(Args args, CommandContext context) {
     // where the key is the server hostname
-    Map<String, Long> results = context.execute(args, DOC_COUNT_AGGREGATE);
+    Map<Server, Long> results = context.readServers(args, DocumentCountAggregator.class);
     long total = 0;
-    for (Entry<String, Long> e : results.entrySet()) {
+    for (Entry<Server, Long> e : results.entrySet()) {
       total += e.getValue();
     }
     return total;


Mime
View raw message