Massive change to arguments in the new command platform. Now arguments are passed by annotating fields on the commands themselves. So therefore the Args object was removed.
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/27107abf Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/27107abf Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/27107abf Branch: refs/heads/master Commit: 27107abff9278b06b186ecd26a91b7b82c09ffcc Parents: 9edd0bd Author: Aaron McCurry <[email protected]> Authored: Tue Sep 30 21:49:53 2014 -0400 Committer: Aaron McCurry <[email protected]> Committed: Tue Sep 30 21:49:53 2014 -0400 ---------------------------------------------------------------------- .../org/apache/blur/command/DocumentCount.java | 3 +- .../blur/command/DocumentCountCombiner.java | 5 +- .../DocumentCountDefaultClusterCombine.java | 3 +- .../blur/command/DocumentCountNoCombine.java | 5 +- .../org/apache/blur/command/TermsCommand.java | 59 +++-- .../blur/command/TestBlurObjectCommand.java | 6 +- ...UsingDocumentCountDefaultClusterCombine.java | 10 +- .../blur/command/example/UsingTermCommand.java | 15 +- .../blur/command/CoreTestClusterContext.java | 73 ++---- .../apache/blur/command/CoreTestContext.java | 20 +- .../blur/command/TermsCommandIntTests.java | 16 +- .../apache/blur/command/TermsCommandTest.java | 44 +--- .../blur/command/TestCombiningContext.java | 38 ++- .../blur/command/TestContextArgDecorator.java | 48 ++-- .../main/java/org/apache/blur/command/Args.java | 51 ---- .../apache/blur/command/ArgumentOverlay.java | 82 ++++++ .../apache/blur/command/BaseCommandManager.java | 259 +++++++++++-------- .../org/apache/blur/command/BaseContext.java | 2 +- .../org/apache/blur/command/ClusterContext.java | 18 +- .../blur/command/ClusterExecuteCommand.java | 50 ---- .../ClusterExecuteReadCombiningCommand.java | 67 ----- .../command/ClusterReadCombiningCommand.java | 64 ----- .../apache/blur/command/ClusterReadCommand.java | 63 ----- .../java/org/apache/blur/command/Command.java | 29 +-- .../org/apache/blur/command/CommandRunner.java | 149 +++++------ .../org/apache/blur/command/CommandUtil.java | 78 ++++-- .../blur/command/ControllerClusterContext.java | 84 +++--- .../blur/command/ControllerCommandManager.java | 63 +++-- .../apache/blur/command/IndexReadCombining.java | 27 -- .../blur/command/IndexReadCombiningCommand.java | 54 ---- .../apache/blur/command/IndexReadCommand.java | 62 ----- .../org/apache/blur/command/ServerRead.java | 27 ++ .../blur/command/ShardCommandManager.java | 86 +++--- .../org/apache/blur/command/ShardRoute.java | 28 -- .../org/apache/blur/command/TableRoute.java | 26 -- .../blur/command/annotation/Argument.java | 30 --- .../command/annotation/OptionalArgument.java | 25 ++ .../command/annotation/OptionalArguments.java | 26 -- .../command/annotation/RequiredArgument.java | 25 ++ .../command/annotation/RequiredArguments.java | 26 -- .../commandtype/ClusterExecuteCommand.java | 65 +++++ .../ClusterExecuteServerReadCommand.java | 74 ++++++ ...sterExecuteServerReadCommandSingleTable.java | 77 ++++++ .../commandtype/ClusterIndexReadCommand.java | 68 +++++ .../ClusterIndexReadCommandSingleTable.java | 77 ++++++ .../commandtype/ClusterServerReadCommand.java | 71 +++++ .../ClusterServerReadCommandSingleTable.java | 77 ++++++ .../command/commandtype/IndexReadCommand.java | 68 +++++ .../IndexReadCommandSingleTable.java | 77 ++++++ .../command/commandtype/ServerReadCommand.java | 73 ++++++ .../ServerReadCommandSingleTable.java | 77 ++++++ .../org/apache/blur/server/LayoutFactory.java | 3 +- .../blur/thrift/BlurControllerServer.java | 18 +- .../org/apache/blur/thrift/BlurShardServer.java | 5 +- .../blur/command/ShardCommandManagerTest.java | 48 ++-- .../org/apache/blur/command/ThrowException.java | 12 +- .../org/apache/blur/command/WaitForSeconds.java | 20 +- .../apache/blur/command/test1/TestCommand.java | 4 +- .../org/apache/blur/command/test1/test1.jar | Bin 1607 -> 1620 bytes .../apache/blur/command/test2/TestCommand.java | 4 +- .../org/apache/blur/command/test2/test2.jar | Bin 1607 -> 1620 bytes 61 files changed, 1591 insertions(+), 1173 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/main/java/org/apache/blur/command/DocumentCount.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/java/org/apache/blur/command/DocumentCount.java b/blur-command/src/main/java/org/apache/blur/command/DocumentCount.java index 3dba4d3..e6836c9 100644 --- a/blur-command/src/main/java/org/apache/blur/command/DocumentCount.java +++ b/blur-command/src/main/java/org/apache/blur/command/DocumentCount.java @@ -19,9 +19,10 @@ package org.apache.blur.command; import java.io.IOException; import org.apache.blur.command.annotation.Description; +import org.apache.blur.command.commandtype.IndexReadCommandSingleTable; @Description("Gets the number of visible documents in the index.") -public class DocumentCount extends IndexReadCommand<Integer> { +public class DocumentCount extends IndexReadCommandSingleTable<Integer> { private static final String DOC_COUNT = "docCount"; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/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 060b7bf..403d416 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 @@ -21,9 +21,10 @@ import java.util.Map; import java.util.Map.Entry; import org.apache.blur.command.annotation.Description; +import org.apache.blur.command.commandtype.ClusterExecuteServerReadCommandSingleTable; @Description("Gets the number of visible documents in the index.") -public class DocumentCountCombiner extends ClusterExecuteReadCombiningCommand<Long> { +public class DocumentCountCombiner extends ClusterExecuteServerReadCommandSingleTable<Long> { private static final String DOC_COUNT_AGGREGATE = "docCountAggregate"; @@ -48,7 +49,7 @@ public class DocumentCountCombiner extends ClusterExecuteReadCombiningCommand<Lo @Override public Long clusterExecute(ClusterContext context) throws IOException { - Map<Server, Long> results = context.readServers(null, DocumentCountCombiner.class); + Map<Server, Long> results = context.readServers(this); long total = 0; for (Entry<Server, Long> e : results.entrySet()) { total += e.getValue(); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/main/java/org/apache/blur/command/DocumentCountDefaultClusterCombine.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/java/org/apache/blur/command/DocumentCountDefaultClusterCombine.java b/blur-command/src/main/java/org/apache/blur/command/DocumentCountDefaultClusterCombine.java index e8383f5..023da04 100644 --- a/blur-command/src/main/java/org/apache/blur/command/DocumentCountDefaultClusterCombine.java +++ b/blur-command/src/main/java/org/apache/blur/command/DocumentCountDefaultClusterCombine.java @@ -20,9 +20,10 @@ import java.io.IOException; import java.util.Map; import org.apache.blur.command.annotation.Description; +import org.apache.blur.command.commandtype.ClusterServerReadCommandSingleTable; @Description("Gets the number of visible documents in the index.") -public class DocumentCountDefaultClusterCombine extends ClusterReadCombiningCommand<Long> { +public class DocumentCountDefaultClusterCombine extends ClusterServerReadCommandSingleTable<Long> { private static final String DOC_COUNT_CLUSTER_COMBINE = "docCountClusterCombine"; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/main/java/org/apache/blur/command/DocumentCountNoCombine.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/java/org/apache/blur/command/DocumentCountNoCombine.java b/blur-command/src/main/java/org/apache/blur/command/DocumentCountNoCombine.java index cfd4d25..25092e5 100644 --- a/blur-command/src/main/java/org/apache/blur/command/DocumentCountNoCombine.java +++ b/blur-command/src/main/java/org/apache/blur/command/DocumentCountNoCombine.java @@ -21,9 +21,10 @@ import java.util.Map; import java.util.Map.Entry; import org.apache.blur.command.annotation.Description; +import org.apache.blur.command.commandtype.ClusterIndexReadCommandSingleTable; @Description("Gets the number of visible documents in the index.") -public class DocumentCountNoCombine extends ClusterReadCommand<Integer,Long> { +public class DocumentCountNoCombine extends ClusterIndexReadCommandSingleTable<Integer, Long> { private static final String DOC_COUNT_NO_COMBINE = "docCountNoCombine"; @@ -39,7 +40,7 @@ public class DocumentCountNoCombine extends ClusterReadCommand<Integer,Long> { @Override public Long clusterExecute(ClusterContext context) throws IOException { - Map<Shard, Integer> indexes = context.readIndexes(null, DocumentCountNoCombine.class); + Map<Shard, Integer> indexes = context.readIndexes(this); long total = 0; for (Entry<Shard, Integer> e : indexes.entrySet()) { total += e.getValue(); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/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 968dc96..3b5e116 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 @@ -6,6 +6,8 @@ import java.util.List; import java.util.Map; import java.util.SortedSet; +import org.apache.blur.command.annotation.RequiredArgument; +import org.apache.blur.command.commandtype.ClusterServerReadCommandSingleTable; import org.apache.blur.utils.BlurUtil; import org.apache.lucene.index.AtomicReader; import org.apache.lucene.index.IndexReader; @@ -34,22 +36,20 @@ import com.google.common.collect.Sets; * License for the specific language governing permissions and limitations under * the License. */ -public class TermsCommand extends ClusterReadCombiningCommand<BlurArray> { +public class TermsCommand extends ClusterServerReadCommandSingleTable<BlurArray> { private static final String NAME = "terms"; - private static final String PARAMS = "params"; - 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; + @RequiredArgument + private short size = 10; + + @RequiredArgument + private String fieldName; + + @RequiredArgument + private String startWith = ""; @Override public BlurArray execute(IndexContext context) throws IOException { - BlurObject params = context.getArgs().get(PARAMS); - short size = params.getShort(P_SIZE, DEFAULT_SIZE); - String fieldName = params.get(P_FIELD); - String startWith = params.getString(P_START, ""); - return new BlurArray(terms(context.getIndexReader(), fieldName, startWith, size)); } @@ -58,25 +58,12 @@ public class TermsCommand extends ClusterReadCombiningCommand<BlurArray> { public BlurArray combine(CombiningContext context, Map<? extends Location<?>, BlurArray> results) throws IOException, InterruptedException { SortedSet<String> terms = Sets.newTreeSet(); - for (BlurArray t : results.values()) { terms.addAll((List<String>) t.asList()); } - - short size = getSize(context); - return new BlurArray(Lists.newArrayList(terms).subList(0, Math.min((int) size, terms.size()))); } - private short getSize(CombiningContext context) { - short size = DEFAULT_SIZE; - if ((context.getArgs() != null) && (context.getArgs().containsArg(PARAMS))) { - BlurObject params = context.getArgs().get(PARAMS); - size = params.getShort(P_SIZE, DEFAULT_SIZE); - } - return size; - } - @Override public String getName() { return NAME; @@ -116,8 +103,30 @@ public class TermsCommand extends ClusterReadCombiningCommand<BlurArray> { if (fieldName == null) { throw new NullPointerException("fieldName cannot be null."); } - return new Term(fieldName, value); } + public short getSize() { + return size; + } + + public void setSize(short size) { + this.size = size; + } + + public String getFieldName() { + return fieldName; + } + + public void setFieldName(String fieldName) { + this.fieldName = fieldName; + } + + public String getStartWith() { + return startWith; + } + + public void setStartWith(String startWith) { + this.startWith = startWith; + } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/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 cbc1718..e9be5a6 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,7 +20,9 @@ import java.io.IOException; import java.util.Map; import java.util.Map.Entry; -public class TestBlurObjectCommand extends ClusterExecuteReadCombiningCommand<BlurObject> { +import org.apache.blur.command.commandtype.ClusterExecuteServerReadCommandSingleTable; + +public class TestBlurObjectCommand extends ClusterExecuteServerReadCommandSingleTable<BlurObject> { @Override public BlurObject execute(IndexContext context) throws IOException { @@ -44,7 +46,7 @@ public class TestBlurObjectCommand extends ClusterExecuteReadCombiningCommand<Bl @Override public BlurObject clusterExecute(ClusterContext context) throws IOException { BlurObject blurObject = new BlurObject(); - Map<Server, BlurObject> results = context.readServers(null, TestBlurObjectCommand.class); + Map<Server, BlurObject> results = context.readServers(this); long total = 0; for (Entry<Server, BlurObject> e : results.entrySet()) { BlurObject value = e.getValue(); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/main/java/org/apache/blur/command/example/UsingDocumentCountDefaultClusterCombine.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/java/org/apache/blur/command/example/UsingDocumentCountDefaultClusterCombine.java b/blur-command/src/main/java/org/apache/blur/command/example/UsingDocumentCountDefaultClusterCombine.java index b1329c5..2a45f3f 100644 --- a/blur-command/src/main/java/org/apache/blur/command/example/UsingDocumentCountDefaultClusterCombine.java +++ b/blur-command/src/main/java/org/apache/blur/command/example/UsingDocumentCountDefaultClusterCombine.java @@ -18,7 +18,6 @@ package org.apache.blur.command.example; */ import java.io.IOException; -import org.apache.blur.command.Args; import org.apache.blur.command.DocumentCountDefaultClusterCombine; import org.apache.blur.thirdparty.thrift_0_9_0.TException; import org.apache.blur.thrift.generated.BlurException; @@ -26,14 +25,9 @@ import org.apache.blur.thrift.generated.BlurException; public class UsingDocumentCountDefaultClusterCombine { public static void main(String[] args) throws BlurException, TException, IOException { - DocumentCountDefaultClusterCombine command = new DocumentCountDefaultClusterCombine(); - - Args arguments = new Args(); - arguments.set("table", "test"); - - Long count = command.run(arguments, "localhost:40020"); - + command.setTable("test"); + Long count = command.run("localhost:40020"); System.out.println(count); } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/main/java/org/apache/blur/command/example/UsingTermCommand.java ---------------------------------------------------------------------- diff --git a/blur-command/src/main/java/org/apache/blur/command/example/UsingTermCommand.java b/blur-command/src/main/java/org/apache/blur/command/example/UsingTermCommand.java index c22acab..8962896 100644 --- a/blur-command/src/main/java/org/apache/blur/command/example/UsingTermCommand.java +++ b/blur-command/src/main/java/org/apache/blur/command/example/UsingTermCommand.java @@ -18,9 +18,7 @@ package org.apache.blur.command.example; */ import java.io.IOException; -import org.apache.blur.command.Args; import org.apache.blur.command.BlurArray; -import org.apache.blur.command.BlurObject; import org.apache.blur.command.TermsCommand; import org.apache.blur.thirdparty.thrift_0_9_0.TException; import org.apache.blur.thrift.generated.BlurException; @@ -28,17 +26,10 @@ import org.apache.blur.thrift.generated.BlurException; public class UsingTermCommand { public static void main(String[] args) throws BlurException, TException, IOException { - TermsCommand command = new TermsCommand(); - - Args arguments = new Args(); - arguments.set("table", "test"); - BlurObject params = new BlurObject(); - params.put("fieldName", "fam0.col0"); - arguments.set("params", params); - - BlurArray blurArray = command.run(arguments, "localhost:40020"); - + command.setTable("test"); + command.setFieldName("fam0.col0"); + BlurArray blurArray = command.run("localhost:40020"); System.out.println(blurArray); } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/test/java/org/apache/blur/command/CoreTestClusterContext.java ---------------------------------------------------------------------- diff --git a/blur-command/src/test/java/org/apache/blur/command/CoreTestClusterContext.java b/blur-command/src/test/java/org/apache/blur/command/CoreTestClusterContext.java index 8480cc0..4d4dacd 100644 --- a/blur-command/src/test/java/org/apache/blur/command/CoreTestClusterContext.java +++ b/blur-command/src/test/java/org/apache/blur/command/CoreTestClusterContext.java @@ -9,77 +9,60 @@ 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 - * + * 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. + * 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 CoreTestClusterContext extends ClusterContext { @Override - public Args getArgs() { - // TODO Auto-generated method stub - return null; + public <T> Map<Shard, T> readIndexes(IndexRead<T> command) throws IOException { + throw new RuntimeException("Not implemented."); } @Override - public TableContext getTableContext(String table) throws IOException { - // TODO Auto-generated method stub - return null; + public <T> Map<Shard, Future<T>> readIndexesAsync(IndexRead<T> command) throws IOException { + throw new RuntimeException("Not implemented."); } @Override - public BlurConfiguration getBlurConfiguration(String table) throws IOException { - // TODO Auto-generated method stub - return null; + public <T> T readIndex(IndexRead<T> command) throws IOException { + throw new RuntimeException("Not implemented."); } @Override - public <T> Map<Shard, T> readIndexes(Args args, Class<? extends IndexRead<T>> clazz) throws IOException { - // TODO Auto-generated method stub - return null; + public <T> Future<T> readIndexAsync(IndexRead<T> command) throws IOException { + throw new RuntimeException("Not implemented."); } @Override - public <T> Map<Shard, Future<T>> readIndexesAsync(Args args, Class<? extends IndexRead<T>> clazz) - throws IOException { - // TODO Auto-generated method stub - return null; + public <T> Map<Server, T> readServers(ServerRead<?, T> command) throws IOException { + throw new RuntimeException("Not implemented."); } @Override - public <T> T readIndex(Args args, Class<? extends IndexRead<T>> clazz) throws IOException { - // TODO Auto-generated method stub - return null; + public <T> Map<Server, Future<T>> readServersAsync(ServerRead<?, T> command) throws IOException { + throw new RuntimeException("Not implemented."); } @Override - public <T> Future<T> readIndexAsync(Args args, Class<? extends IndexRead<T>> clazz) throws IOException { - // TODO Auto-generated method stub - return null; - } - - @Override - public <T> Map<Server, T> readServers(Args args, Class<? extends IndexReadCombining<?, T>> clazz) - throws IOException { - // TODO Auto-generated method stub - return null; + public TableContext getTableContext(String table) throws IOException { + throw new RuntimeException("Not implemented."); } @Override - public <T> Map<Server, Future<T>> readServersAsync(Args args, Class<? extends IndexReadCombining<?, T>> clazz) - throws IOException { - // TODO Auto-generated method stub - return null; + public BlurConfiguration getBlurConfiguration(String table) throws IOException { + throw new RuntimeException("Not implemented."); } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/test/java/org/apache/blur/command/CoreTestContext.java ---------------------------------------------------------------------- diff --git a/blur-command/src/test/java/org/apache/blur/command/CoreTestContext.java b/blur-command/src/test/java/org/apache/blur/command/CoreTestContext.java index b564ebd..838b03d 100644 --- a/blur-command/src/test/java/org/apache/blur/command/CoreTestContext.java +++ b/blur-command/src/test/java/org/apache/blur/command/CoreTestContext.java @@ -35,15 +35,14 @@ import org.apache.lucene.util.Version; public class CoreTestContext extends IndexContext { private RAMDirectory directory = new RAMDirectory(); - private Args args = null; private CoreTestContext() { } /** - * Index will contain 26 documents with the following column/values: - * alpha = double-letter a-z (lowercase characters); - * num = 0-25 val = val (constant across all docs) + * Index will contain 26 documents with the following column/values: alpha = + * double-letter a-z (lowercase characters); num = 0-25 val = val (constant + * across all docs) * * New columns may be added so don't rely on the column count in tests. * @@ -64,9 +63,9 @@ public class CoreTestContext extends IndexContext { doc.add(new Field("alpha", alpha + alpha, TextField.TYPE_STORED)); doc.add(new Field("num", Integer.toString(i), TextField.TYPE_STORED)); doc.add(new Field("val", "val", TextField.TYPE_STORED)); - + writer.addDocument(doc); - + writer.commit(); } writer.commit(); @@ -110,8 +109,13 @@ public class CoreTestContext extends IndexContext { } @Override - public Args getArgs() { - return args; + public TableContext getTableContext(String table) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public BlurConfiguration getBlurConfiguration(String table) throws IOException { + throw new RuntimeException("Not implemented."); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/test/java/org/apache/blur/command/TermsCommandIntTests.java ---------------------------------------------------------------------- diff --git a/blur-command/src/test/java/org/apache/blur/command/TermsCommandIntTests.java b/blur-command/src/test/java/org/apache/blur/command/TermsCommandIntTests.java index b08d121..f3b14eb 100644 --- a/blur-command/src/test/java/org/apache/blur/command/TermsCommandIntTests.java +++ b/blur-command/src/test/java/org/apache/blur/command/TermsCommandIntTests.java @@ -35,21 +35,13 @@ public class TermsCommandIntTests extends BaseClusterTest { @Test public void testTermsList() throws BlurException, TException, IOException, InterruptedException { final String tableName = "testTermsList"; - TableGen - .define(tableName) - .cols("test", "col1") - .addRows(100, 20, "r1", "rec-###", "value") - .build(getClient()); + TableGen.define(tableName).cols("test", "col1").addRows(100, 20, "r1", "rec-###", "value").build(getClient()); TermsCommand command = new TermsCommand(); + command.setTable(tableName); + command.setFieldName("test.col1"); - Args arguments = new Args(); - arguments.set("table", tableName); - BlurObject params = new BlurObject(); - params.put("fieldName", "test.col1"); - arguments.set("params", params); - - BlurArray blurArray = command.run(arguments, getClient()); + BlurArray blurArray = command.run(getClient()); List<String> list = Lists.newArrayList("value"); assertEquals(list, blurArray.asList()); } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java ---------------------------------------------------------------------- diff --git a/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java b/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java index 543a2de..b7b74d0 100644 --- a/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java +++ b/blur-command/src/test/java/org/apache/blur/command/TermsCommandTest.java @@ -37,7 +37,7 @@ public class TermsCommandTest { @Test public void basicTermsShouldReturn() throws IOException { - BlurArray returned = getExecuteResult(newContext("val", null, null)); + BlurArray returned = getExecuteResult(ctx, "val", null, null); BlurArray expected = new BlurArray(Lists.newArrayList("val")); assertEquals(expected, returned); @@ -45,7 +45,7 @@ public class TermsCommandTest { @Test public void sizeOfTermsRequestShouldBeRespected() throws IOException { - BlurArray returned = getExecuteResult(newContext("alpha", (short) 7, null)); + BlurArray returned = getExecuteResult(ctx, "alpha", (short) 7, null); BlurArray expected = new BlurArray(Lists.newArrayList("aa", "bb", "cc", "dd", "ee", "ff", "gg")); assertEquals(expected, returned); @@ -53,7 +53,7 @@ public class TermsCommandTest { @Test public void sizeShouldDefaultToTen() throws IOException { - BlurArray returned = getExecuteResult(newContext("alpha", null, null)); + BlurArray returned = getExecuteResult(ctx, "alpha", null, null); BlurArray expected = new BlurArray(Lists.newArrayList("aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj")); assertEquals(expected, returned); @@ -68,10 +68,7 @@ public class TermsCommandTest { BlurArray expected = new BlurArray(Lists.newArrayList("aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj")); TermsCommand cmd = new TermsCommand(); - Args args = new Args(); - BlurObject params = new BlurObject(); - args.set("params", params); - BlurArray returned = cmd.combine(new TestCombiningContext(args), execResults); + BlurArray returned = cmd.combine(new TestCombiningContext(), execResults); assertEquals(expected, returned); } @@ -85,12 +82,8 @@ public class TermsCommandTest { BlurArray expected = new BlurArray(Lists.newArrayList("aa", "bb")); TermsCommand cmd = new TermsCommand(); - Args args = new Args(); - BlurObject params = new BlurObject(); - params.put("size", (short) 2); - args.set("params", params); - - BlurArray returned = cmd.combine(new TestCombiningContext(args), execResults); + cmd.setSize((short) 2); + BlurArray returned = cmd.combine(new TestCombiningContext(), execResults); assertEquals(expected, returned); } @@ -106,25 +99,16 @@ public class TermsCommandTest { assertEquals(expected, returned); } - private BlurArray getExecuteResult(IndexContext context) throws IOException { + private BlurArray getExecuteResult(IndexContext context, String field, Short size, String startsWith) + throws IOException { TermsCommand cmd = new TermsCommand(); - return cmd.execute(context); - } - - private IndexContext newContext(String field, Short size, String startsWith) { - - Args args = new Args(); - BlurObject params = new BlurObject(); - params.put("fieldName", field); - - if (size != null) { - params.put("size", size); - } + cmd.setFieldName(field); if (startsWith != null) { - params.put("startWith", startsWith); + cmd.setStartWith(startsWith); } - args.set("params", params); - - return new TestContextArgDecorator(ctx, args); + if (size != null) { + cmd.setSize(size); + } + return cmd.execute(context); } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/test/java/org/apache/blur/command/TestCombiningContext.java ---------------------------------------------------------------------- diff --git a/blur-command/src/test/java/org/apache/blur/command/TestCombiningContext.java b/blur-command/src/test/java/org/apache/blur/command/TestCombiningContext.java index 84f481f..fbe1a9a 100644 --- a/blur-command/src/test/java/org/apache/blur/command/TestCombiningContext.java +++ b/blur-command/src/test/java/org/apache/blur/command/TestCombiningContext.java @@ -7,32 +7,24 @@ 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 - * + * 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. + * 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 TestCombiningContext extends CombiningContext { - private Args args = new Args(); - - public TestCombiningContext() {} - - public TestCombiningContext(Args a) { - this.args = a; - } - - @Override - public Args getArgs() { - return args; + + public TestCombiningContext() { + } @Override http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-command/src/test/java/org/apache/blur/command/TestContextArgDecorator.java ---------------------------------------------------------------------- diff --git a/blur-command/src/test/java/org/apache/blur/command/TestContextArgDecorator.java b/blur-command/src/test/java/org/apache/blur/command/TestContextArgDecorator.java index efa8da8..295d253 100644 --- a/blur-command/src/test/java/org/apache/blur/command/TestContextArgDecorator.java +++ b/blur-command/src/test/java/org/apache/blur/command/TestContextArgDecorator.java @@ -1,5 +1,7 @@ package org.apache.blur.command; +import java.io.IOException; + import org.apache.blur.BlurConfiguration; import org.apache.blur.server.TableContext; import org.apache.lucene.index.IndexReader; @@ -7,31 +9,29 @@ import org.apache.lucene.search.IndexSearcher; /** * 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 - * + * 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. + * 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 TestContextArgDecorator extends IndexContext { private IndexContext heavyContext; - private Args args; - public TestContextArgDecorator(IndexContext heavyContext, Args args) { + public TestContextArgDecorator(IndexContext heavyContext) { super(); this.heavyContext = heavyContext; - this.args = args; } - public TableContext getTableContext() { + public TableContext getTableContext() throws IOException { return heavyContext.getTableContext(); } @@ -47,18 +47,18 @@ public class TestContextArgDecorator extends IndexContext { return heavyContext.getIndexSearcher(); } - public BlurConfiguration getBlurConfiguration() { + public BlurConfiguration getBlurConfiguration() throws IOException { return heavyContext.getBlurConfiguration(); } @Override - public Args getArgs() { - return this.args; + public TableContext getTableContext(String table) throws IOException { + throw new RuntimeException("Not implemented."); + } + + @Override + public BlurConfiguration getBlurConfiguration(String table) throws IOException { + throw new RuntimeException("Not implemented."); } - - - - - } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/Args.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/Args.java b/blur-core/src/main/java/org/apache/blur/command/Args.java deleted file mode 100644 index e3e98de..0000000 --- a/blur-core/src/main/java/org/apache/blur/command/Args.java +++ /dev/null @@ -1,51 +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.command; - -import java.util.HashMap; -import java.util.Map; - -public class Args { - - private final Map<String, Object> _values = new HashMap<String, Object>(); - - @SuppressWarnings("unchecked") - public <T> T get(String name) { - return (T) _values.get(name); - } - - public <T> T get(String name, T defaultValue) { - T t = get(name); - if (t == null) { - return defaultValue; - } - return t; - } - - public <T> void set(String name, T value) { - _values.put(name, value); - } - - public Map<String, Object> getValues() { - return _values; - } - - public boolean containsArg(String name) { - return _values.containsKey(name); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/ArgumentOverlay.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ArgumentOverlay.java b/blur-core/src/main/java/org/apache/blur/command/ArgumentOverlay.java new file mode 100644 index 0000000..9cf4a6a --- /dev/null +++ b/blur-core/src/main/java/org/apache/blur/command/ArgumentOverlay.java @@ -0,0 +1,82 @@ +/** + * 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.command; + +import java.lang.reflect.Field; + +import org.apache.blur.command.annotation.OptionalArgument; +import org.apache.blur.command.annotation.RequiredArgument; + +public class ArgumentOverlay { + + private BlurObject _args; + + public ArgumentOverlay(BlurObject args) { + _args = args; + } + + public <T> Command<T> setup(Command<T> command) { + Class<?> clazz = command.getClass(); + setupInternal(clazz, command); + + return command; + } + + private void setupInternal(Class<?> clazz, Command<?> command) { + if (clazz.equals(Command.class)) { + return; + } + setupInternal(clazz.getSuperclass(), command); + Field[] declaredFields = clazz.getDeclaredFields(); + for (Field field : declaredFields) { + RequiredArgument requiredArgument = field.getAnnotation(RequiredArgument.class); + if (requiredArgument != null) { + field.setAccessible(true); + String name = field.getName(); + try { + Object o = _args.get(name); + if (o != null) { + field.set(command, o); + } else { + throw new IllegalArgumentException("Field [" + name + "] is required."); + } + } catch (IllegalArgumentException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + OptionalArgument optionalArgument = field.getAnnotation(OptionalArgument.class); + if (optionalArgument != null) { + field.setAccessible(true); + String name = field.getName(); + try { + Object o = _args.get(name); + if (o != null) { + field.set(command, o); + } + } catch (IllegalArgumentException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java b/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java index c4d08e5..4779013 100644 --- a/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java +++ b/blur-core/src/main/java/org/apache/blur/command/BaseCommandManager.java @@ -19,8 +19,6 @@ import java.util.Properties; import java.util.Set; import java.util.Timer; import java.util.TimerTask; -import java.util.TreeMap; -import java.util.TreeSet; import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; @@ -31,14 +29,14 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import org.apache.blur.command.annotation.Argument; import org.apache.blur.command.annotation.Description; -import org.apache.blur.command.annotation.OptionalArguments; -import org.apache.blur.command.annotation.RequiredArguments; +import org.apache.blur.command.commandtype.ClusterExecuteServerReadCommand; +import org.apache.blur.command.commandtype.ServerReadCommand; +import org.apache.blur.command.commandtype.IndexReadCommand; import org.apache.blur.concurrent.Executors; import org.apache.blur.log.Log; import org.apache.blur.log.LogFactory; -import org.apache.blur.server.TableContextFactory; +import org.apache.blur.thrift.generated.Arguments; import org.apache.commons.io.IOUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; @@ -65,7 +63,7 @@ import com.google.common.collect.MapMaker; * the License. */ -public class BaseCommandManager implements Closeable { +public abstract class BaseCommandManager implements Closeable { private static final String META_INF_SERVICES_ORG_APACHE_BLUR_COMMAND_COMMANDS = "META-INF/services/org.apache.blur.command.Commands"; private static final Log LOG = LogFactory.getLog(BaseCommandManager.class); @@ -118,54 +116,63 @@ public class BaseCommandManager implements Closeable { return getArguments(commandName, true); } - @SuppressWarnings("unchecked") protected Map<String, String> getArguments(String commandName, boolean optional) { - Command<?> command = getCommandObject(commandName); - if (command == null) { - return null; - } - Class<Command<?>> clazz = (Class<Command<?>>) command.getClass(); - Map<String, String> arguments = new TreeMap<String, String>(); - Argument[] args = getArgumentArray(clazz, optional); - addArguments(arguments, args); - if (optional) { - if (!(command instanceof ShardRoute)) { - Argument[] argumentArray = getArgumentArray(Command.class, optional); - addArguments(arguments, argumentArray); - } - } else { - if (!(command instanceof TableRoute)) { - Argument[] argumentArray = getArgumentArray(Command.class, optional); - addArguments(arguments, argumentArray); - } - } - return arguments; - } - private void addArguments(Map<String, String> arguments, Argument[] args) { - if (args != null) { - for (Argument argument : args) { - Class<?> type = argument.type(); - arguments.put(argument.name(), ("(" + type.getSimpleName() + ") " + argument.value()).trim()); - } - } + // @RequiredArguments({ @Argument(name = "table", value = + // "The name of the table to execute the document count command.", type = + // String.class) }) + // @OptionalArguments({ @Argument(name = "shard", value = + // "The shard id to execute the document count command.", type = + // String.class) }) + + throw new RuntimeException("not implemented"); + // Command<?> command = getCommandObject(commandName); + // if (command == null) { + // return null; + // } + // Class<Command<?>> clazz = (Class<Command<?>>) command.getClass(); + // Map<String, String> arguments = new TreeMap<String, String>(); + // Argument[] args = getArgumentArray(clazz, optional); + // addArguments(arguments, args); + // if (optional) { + // if (!(command instanceof ShardRoute)) { + // Argument[] argumentArray = getArgumentArray(Command.class, optional); + // addArguments(arguments, argumentArray); + // } + // } else { + // if (!(command instanceof TableRoute)) { + // Argument[] argumentArray = getArgumentArray(Command.class, optional); + // addArguments(arguments, argumentArray); + // } + // } + // return arguments; } - protected Argument[] getArgumentArray(Class<?> clazz, boolean optional) { - if (optional) { - OptionalArguments arguments = clazz.getAnnotation(OptionalArguments.class); - if (arguments == null) { - return null; - } - return arguments.value(); - } else { - RequiredArguments arguments = clazz.getAnnotation(RequiredArguments.class); - if (arguments == null) { - return null; - } - return arguments.value(); - } - } + // private void addArguments(Map<String, String> arguments, Argument[] args) { + // if (args != null) { + // for (Argument argument : args) { + // Class<?> type = argument.type(); + // arguments.put(argument.name(), ("(" + type.getSimpleName() + ") " + + // argument.value()).trim()); + // } + // } + // } + // + // protected Argument[] getArgumentArray(Class<?> clazz, boolean optional) { + // if (optional) { + // OptionalArguments arguments = clazz.getAnnotation(OptionalArguments.class); + // if (arguments == null) { + // return null; + // } + // return arguments.value(); + // } else { + // RequiredArguments arguments = clazz.getAnnotation(RequiredArguments.class); + // if (arguments == null) { + // return null; + // } + // return arguments.value(); + // } + // } protected TimerTask getNewCommandTimerTask() { return new TimerTask() { @@ -379,77 +386,85 @@ public class BaseCommandManager implements Closeable { } } - protected Command<?> getCommandObject(String commandName) { + protected Command<?> getCommandObject(String commandName, ArgumentOverlay argumentOverlay) { Command<?> command = _command.get(commandName); if (command == null) { return null; } - return command.clone(); + Command<?> clone = command.clone(); + if (argumentOverlay == null) { + return clone; + } + return argumentOverlay.setup(clone); } protected String getCommandName(Class<? extends Command<?>> clazz) { return _commandNameLookup.get(clazz); } - protected Map<String, Set<Shard>> getShards(TableContextFactory tableContextFactory, Command<?> command, - final Args args, Set<String> tables) throws IOException { - Map<String, Set<Shard>> shardMap = new TreeMap<String, Set<Shard>>(); - if (command instanceof ShardRoute) { - ShardRoute shardRoute = (ShardRoute) command; - for (String table : tables) { - shardMap.put(table, shardRoute.resolveShards(tableContextFactory.getTableContext(table), args)); - } - } else { - if (tables.size() > 1) { - throw new IOException( - "Cannot route to single shard when multiple tables are specified. Implement ShardRoute on your command."); - } - String singleTable = tables.iterator().next(); - Set<Shard> shardSet = new TreeSet<Shard>(); - String shard = args.get("shard"); - if (shard == null) { - BlurArray shardArray = args.get("shards"); - if (shardArray != null) { - for (int i = 0; i < shardArray.length(); i++) { - shardSet.add(new Shard(singleTable, shardArray.getString(i))); - } - } - } else { - shardSet.add(new Shard(singleTable, shard)); - } - shardMap.put(singleTable, shardSet); - } - return shardMap; - } - - protected Set<String> getTables(Command<?> command, final Args args) throws IOException { - Set<String> tables = new TreeSet<String>(); - if (command instanceof TableRoute) { - TableRoute tableRoute = (TableRoute) command; - tables.addAll(tableRoute.resolveTables(args)); - } else { - if (args == null) { - return tables; - } - String table = args.get("table"); - if (table == null) { - BlurArray tableArray = args.get("tables"); - if (tableArray == null) { - return tables; - } - for (int i = 0; i < tableArray.length(); i++) { - tables.add(tableArray.getString(i)); - } - } else { - tables.add(table); - } - } - return tables; - } + // protected Map<String, Set<Shard>> getShards(TableContextFactory + // tableContextFactory, Command<?> command, + // final Args args, Set<String> tables) throws IOException { + // Map<String, Set<Shard>> shardMap = new TreeMap<String, Set<Shard>>(); + // if (command instanceof ShardRoute) { + // ShardRoute shardRoute = (ShardRoute) command; + // for (String table : tables) { + // shardMap.put(table, + // shardRoute.resolveShards(tableContextFactory.getTableContext(table), + // args)); + // } + // } else { + // if (tables.size() > 1) { + // throw new IOException( + // "Cannot route to single shard when multiple tables are specified. Implement ShardRoute on your command."); + // } + // String singleTable = tables.iterator().next(); + // Set<Shard> shardSet = new TreeSet<Shard>(); + // String shard = args.get("shard"); + // if (shard == null) { + // BlurArray shardArray = args.get("shards"); + // if (shardArray != null) { + // for (int i = 0; i < shardArray.length(); i++) { + // shardSet.add(new Shard(singleTable, shardArray.getString(i))); + // } + // } + // } else { + // shardSet.add(new Shard(singleTable, shard)); + // } + // shardMap.put(singleTable, shardSet); + // } + // return shardMap; + // } + + // protected Set<String> getTables(Command<?> command, final Args args) throws + // IOException { + // Set<String> tables = new TreeSet<String>(); + // if (command instanceof TableRoute) { + // TableRoute tableRoute = (TableRoute) command; + // tables.addAll(tableRoute.resolveTables(args)); + // } else { + // if (args == null) { + // return tables; + // } + // String table = args.get("table"); + // if (table == null) { + // BlurArray tableArray = args.get("tables"); + // if (tableArray == null) { + // return tables; + // } + // for (int i = 0; i < tableArray.length(); i++) { + // tables.add(tableArray.getString(i)); + // } + // } else { + // tables.add(table); + // } + // } + // return tables; + // } @SuppressWarnings("unchecked") public String getDescription(String commandName) { - Command<?> command = getCommandObject(commandName); + Command<?> command = getCommandObject(commandName, null); if (command == null) { return null; } @@ -462,7 +477,7 @@ public class BaseCommandManager implements Closeable { } public String getReturnType(String commandName) { - Command<?> command = getCommandObject(commandName); + Command<?> command = getCommandObject(commandName, null); if (command == null) { return null; } @@ -474,8 +489,8 @@ public class BaseCommandManager implements Closeable { Method method = indexReadCommand.getClass().getMethod("execute", new Class[] { IndexContext.class }); Class<?> returnType = method.getReturnType(); shardServerReturn = "shard->(" + returnType.getSimpleName() + ")"; - } else if (command instanceof IndexReadCombiningCommand) { - IndexReadCombiningCommand<?, ?> indexReadCombiningCommand = (IndexReadCombiningCommand<?, ?>) command; + } else if (command instanceof ServerReadCommand) { + ServerReadCommand<?, ?> indexReadCombiningCommand = (ServerReadCommand<?, ?>) command; Method method = indexReadCombiningCommand.getClass().getMethod("combine", new Class[] { CombiningContext.class, Map.class }); Class<?> returnType = method.getReturnType(); @@ -483,8 +498,8 @@ public class BaseCommandManager implements Closeable { } else { shardServerReturn = null; } - if (command instanceof ClusterExecuteReadCombiningCommand) { - ClusterExecuteReadCombiningCommand<?> clusterCommand = (ClusterExecuteReadCombiningCommand<?>) command; + if (command instanceof ClusterExecuteServerReadCommand) { + ClusterExecuteServerReadCommand<?> clusterCommand = (ClusterExecuteServerReadCommand<?>) command; Method method = clusterCommand.getClass().getMethod("clusterExecute", new Class[] { Map.class }); Class<?> returnType = method.getReturnType(); String clusterReturn = "cluster->(" + returnType.getSimpleName() + ")"; @@ -500,4 +515,20 @@ public class BaseCommandManager implements Closeable { } } + protected Arguments toArguments(Command<?> command) { + return CommandUtil.toArguments(command); + } + + protected void validate(Command<?> command) throws IOException { + String name = command.getName(); + Command<?> cmd = getCommandObject(name, null); + if (cmd == null) { + throw new IOException("Command [" + name + "] not found."); + } + if (cmd.getClass().equals(command.getClass())) { + return; + } + throw new IOException("Command [" + name + "] class does not match class registered."); + } + } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/BaseContext.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/BaseContext.java b/blur-core/src/main/java/org/apache/blur/command/BaseContext.java index 4859cd6..527bc29 100644 --- a/blur-core/src/main/java/org/apache/blur/command/BaseContext.java +++ b/blur-core/src/main/java/org/apache/blur/command/BaseContext.java @@ -24,7 +24,7 @@ import org.apache.blur.server.TableContext; public abstract class BaseContext { - public abstract Args getArgs(); +// public abstract Args getArgs(); public abstract TableContext getTableContext(String table) throws IOException; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/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 1020d07..aa8ffaf 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 @@ -23,19 +23,13 @@ import java.util.concurrent.Future; public abstract class ClusterContext extends BaseContext { - public abstract <T> Map<Shard, T> readIndexes(Args args, Class<? extends IndexRead<T>> clazz) throws IOException; + public abstract <T> Map<Shard, T> readIndexes(IndexRead<T> command) throws IOException; + public abstract <T> Map<Shard, Future<T>> readIndexesAsync(IndexRead<T> command) throws IOException; - public abstract <T> Map<Shard, Future<T>> readIndexesAsync(Args args, Class<? extends IndexRead<T>> clazz) - throws IOException; + public abstract <T> T readIndex(IndexRead<T> command) throws IOException; + public abstract <T> Future<T> readIndexAsync(IndexRead<T> command) throws IOException; - public abstract <T> T readIndex(Args args, Class<? extends IndexRead<T>> clazz) throws IOException; - - public abstract <T> Future<T> readIndexAsync(Args args, Class<? extends IndexRead<T>> clazz) throws IOException; - - public abstract <T> Map<Server, T> readServers(Args args, Class<? extends IndexReadCombining<?, T>> clazz) - throws IOException; - - public abstract <T> Map<Server, Future<T>> readServersAsync(Args args, Class<? extends IndexReadCombining<?, T>> clazz) - throws IOException; + public abstract <T> Map<Server, T> readServers(ServerRead<?, T> command) throws IOException; + public abstract <T> Map<Server, Future<T>> readServersAsync(ServerRead<?, T> command) throws IOException; } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/ClusterExecuteCommand.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ClusterExecuteCommand.java b/blur-core/src/main/java/org/apache/blur/command/ClusterExecuteCommand.java deleted file mode 100644 index 39b954f..0000000 --- a/blur-core/src/main/java/org/apache/blur/command/ClusterExecuteCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.apache.blur.command; - -import java.io.IOException; - -import org.apache.blur.thirdparty.thrift_0_9_0.TException; -import org.apache.blur.thrift.generated.BlurException; - -/** - * 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 ClusterExecuteCommand<T> extends Command<T> { - - public abstract T clusterExecute(ClusterContext context) throws IOException, InterruptedException; - - @Override - public T run(Args arguments) throws IOException { - try { - return CommandRunner.run(this, arguments); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } - - @Override - public T run(Args arguments, String connectionStr) throws IOException { - try { - return CommandRunner.run(this, arguments, connectionStr); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/ClusterExecuteReadCombiningCommand.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ClusterExecuteReadCombiningCommand.java b/blur-core/src/main/java/org/apache/blur/command/ClusterExecuteReadCombiningCommand.java deleted file mode 100644 index 42277bf..0000000 --- a/blur-core/src/main/java/org/apache/blur/command/ClusterExecuteReadCombiningCommand.java +++ /dev/null @@ -1,67 +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.command; - -import java.io.IOException; -import java.util.Map; - -import org.apache.blur.thirdparty.thrift_0_9_0.TException; -import org.apache.blur.thrift.generated.Blur.Iface; -import org.apache.blur.thrift.generated.BlurException; - -public abstract class ClusterExecuteReadCombiningCommand<T> extends Command<T> implements IndexReadCombining<T, T> { - - public abstract T execute(IndexContext context) throws IOException, InterruptedException; - - public abstract T combine(CombiningContext context, Map<? extends Location<?>, T> results) throws IOException, - InterruptedException; - - public abstract T clusterExecute(ClusterContext context) throws IOException, InterruptedException; - - @Override - public T run(Args arguments) throws IOException { - try { - return CommandRunner.run(this, arguments); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } - - @Override - public T run(Args arguments, String connectionStr) throws IOException { - try { - return CommandRunner.run(this, arguments, connectionStr); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } - - @Override - public T run(Args arguments, Iface client) throws IOException { - try { - return CommandRunner.run(this, arguments, client); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/ClusterReadCombiningCommand.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ClusterReadCombiningCommand.java b/blur-core/src/main/java/org/apache/blur/command/ClusterReadCombiningCommand.java deleted file mode 100644 index 7b8b1d4..0000000 --- a/blur-core/src/main/java/org/apache/blur/command/ClusterReadCombiningCommand.java +++ /dev/null @@ -1,64 +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.command; - -import java.io.IOException; -import java.util.Map; - -import org.apache.blur.thirdparty.thrift_0_9_0.TException; -import org.apache.blur.thrift.generated.BlurException; -import org.apache.blur.thrift.generated.Blur.Iface; - -public abstract class ClusterReadCombiningCommand<T> extends Command<T> implements IndexReadCombining<T, T> { - - public abstract T execute(IndexContext context) throws IOException, InterruptedException; - - public abstract T combine(CombiningContext context, Map<? extends Location<?>, T> results) throws IOException, - InterruptedException; - - @Override - public T run(Args arguments) throws IOException { - try { - return CommandRunner.run(this, arguments); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } - - @Override - public T run(Args arguments, String connectionStr) throws IOException { - try { - return CommandRunner.run(this, arguments, connectionStr); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } - @Override - public T run(Args arguments, Iface client) throws IOException { - try { - return CommandRunner.run(this, arguments, client); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/ClusterReadCommand.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/ClusterReadCommand.java b/blur-core/src/main/java/org/apache/blur/command/ClusterReadCommand.java deleted file mode 100644 index 8d8b46e..0000000 --- a/blur-core/src/main/java/org/apache/blur/command/ClusterReadCommand.java +++ /dev/null @@ -1,63 +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.command; - -import java.io.IOException; - -import org.apache.blur.thirdparty.thrift_0_9_0.TException; -import org.apache.blur.thrift.generated.Blur.Iface; -import org.apache.blur.thrift.generated.BlurException; - -public abstract class ClusterReadCommand<T1, T2> extends Command<T2> implements IndexRead<T1> { - - public abstract T1 execute(IndexContext context) throws IOException, InterruptedException; - - public abstract T2 clusterExecute(ClusterContext context) throws IOException, InterruptedException; - - @Override - public T2 run(Args arguments) throws IOException { - try { - return CommandRunner.run(this, arguments); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } - - @Override - public T2 run(Args arguments, String connectionStr) throws IOException { - try { - return CommandRunner.run(this, arguments, connectionStr); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } - - @Override - public T2 run(Args arguments, Iface client) throws IOException { - try { - return CommandRunner.run(this, arguments, client); - } catch (BlurException e) { - throw new IOException(e); - } catch (TException e) { - throw new IOException(e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/Command.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/Command.java b/blur-core/src/main/java/org/apache/blur/command/Command.java index 44c341d..f6f7314 100644 --- a/blur-core/src/main/java/org/apache/blur/command/Command.java +++ b/blur-core/src/main/java/org/apache/blur/command/Command.java @@ -17,32 +17,24 @@ package org.apache.blur.command; import java.io.IOException; +import java.util.HashSet; import java.util.Set; -import org.apache.blur.command.annotation.Argument; -import org.apache.blur.command.annotation.OptionalArguments; -import org.apache.blur.command.annotation.RequiredArguments; import org.apache.blur.thrift.generated.Blur.Iface; -@RequiredArguments({ @Argument(name = "table", value = "The name of the table to execute the document count command.", type = String.class) }) -@OptionalArguments({ @Argument(name = "shard", value = "The shard id to execute the document count command.", type = String.class) }) public abstract class Command<R> implements Cloneable { public abstract String getName(); - public abstract R run(Args arguments) throws IOException; + public abstract R run() throws IOException; - public abstract R run(Args arguments, String connectionStr) throws IOException; - - public abstract R run(Args arguments, Iface client) throws IOException; + public abstract R run(String connectionStr) throws IOException; - public Set<Shard> resolveShards(BaseContext context) { - return null; - } + public abstract R run(Iface client) throws IOException; - public Set<String> resolveTables(BaseContext context) { - return null; - } + public abstract Set<String> routeTables(BaseContext context); + + public abstract Set<Shard> routeShards(BaseContext context, Set<String> tables); @SuppressWarnings({ "unchecked", "rawtypes" }) @Override @@ -53,4 +45,11 @@ public abstract class Command<R> implements Cloneable { throw new RuntimeException(e); } } + + public static <T> Set<T> asSet(T t) { + Set<T> set = new HashSet<T>(); + set.add(t); + return set; + } + } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/command/CommandRunner.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/command/CommandRunner.java b/blur-core/src/main/java/org/apache/blur/command/CommandRunner.java index e572c0b..b9df674 100644 --- a/blur-core/src/main/java/org/apache/blur/command/CommandRunner.java +++ b/blur-core/src/main/java/org/apache/blur/command/CommandRunner.java @@ -25,6 +25,12 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.apache.blur.command.commandtype.ClusterExecuteCommand; +import org.apache.blur.command.commandtype.ClusterExecuteServerReadCommand; +import org.apache.blur.command.commandtype.ClusterServerReadCommand; +import org.apache.blur.command.commandtype.ClusterIndexReadCommand; +import org.apache.blur.command.commandtype.ServerReadCommand; +import org.apache.blur.command.commandtype.IndexReadCommand; import org.apache.blur.thirdparty.thrift_0_9_0.TException; import org.apache.blur.thirdparty.thrift_0_9_0.transport.TTransportException; import org.apache.blur.thrift.BlurClient; @@ -55,142 +61,137 @@ public class CommandRunner { throw new RuntimeException("Unknown client class [" + client.getClass() + "]"); } - public static <T> Map<Shard, T> run(IndexReadCommand<T> command, Args arguments) throws IOException, BlurException, - TException { + public static <T> Map<Shard, T> run(IndexReadCommand<T> command) throws IOException, BlurException, TException { Iface client = BlurClient.getClient(); - return run(command, arguments, getConnection(client)); + return run(command, getConnection(client)); } - public static <T> Map<Shard, T> run(IndexReadCommand<T> command, Args arguments, String connectionStr) - throws IOException, BlurException, TException { + public static <T> Map<Shard, T> run(IndexReadCommand<T> command, String connectionStr) throws IOException, + BlurException, TException { Iface client = BlurClient.getClient(connectionStr); - return run(command, arguments, getConnection(client)); + return run(command, getConnection(client)); } - public static <T> Map<Shard, T> run(IndexReadCommand<T> command, Args arguments, Blur.Iface client) - throws IOException, BlurException, TException { - return run(command, arguments, getConnection(client)); + public static <T> Map<Shard, T> run(IndexReadCommand<T> command, Blur.Iface client) throws IOException, + BlurException, TException { + return run(command, getConnection(client)); } @SuppressWarnings("unchecked") - public static <T> Map<Shard, T> run(IndexReadCommand<T> command, Args arguments, Connection... connection) - throws IOException, BlurException, TException { - return (Map<Shard, T>) runInternal((Command<?>) command, arguments, connection); + public static <T> Map<Shard, T> run(IndexReadCommand<T> command, Connection... connection) throws IOException, + BlurException, TException { + return (Map<Shard, T>) runInternal((Command<?>) command, connection); } - public static <T> Map<Server, T> run(IndexReadCombiningCommand<?, T> command, Args arguments) throws IOException, - BlurException, TException { + public static <T> Map<Server, T> run(ServerReadCommand<?, T> command) throws IOException, BlurException, + TException { Iface client = BlurClient.getClient(); - return run(command, arguments, getConnection(client)); + return run(command, getConnection(client)); } - public static <T> Map<Server, T> run(IndexReadCombiningCommand<?, T> command, Args arguments, String connectionStr) + public static <T> Map<Server, T> run(ServerReadCommand<?, T> command, String connectionStr) throws IOException, BlurException, TException { Iface client = BlurClient.getClient(connectionStr); - return run(command, arguments, getConnection(client)); + return run(command, getConnection(client)); } - public static <T> Map<Server, T> run(IndexReadCombiningCommand<?, T> command, Args arguments, Blur.Iface client) - throws IOException, BlurException, TException { - return run(command, arguments, getConnection(client)); + public static <T> Map<Server, T> run(ServerReadCommand<?, T> command, Blur.Iface client) throws IOException, + BlurException, TException { + return run(command, getConnection(client)); } @SuppressWarnings("unchecked") - public static <T> Map<Server, T> run(IndexReadCombiningCommand<?, T> command, Args arguments, - Connection... connection) throws IOException, BlurException, TException { - return (Map<Server, T>) runInternal((Command<?>) command, arguments, connection); + public static <T> Map<Server, T> run(ServerReadCommand<?, T> command, Connection... connection) + throws IOException, BlurException, TException { + return (Map<Server, T>) runInternal((Command<?>) command, connection); } - public static <T1, T2> T2 run(ClusterReadCommand<T1, T2> command, Args arguments) throws IOException, BlurException, - TException { - return run(command, arguments, getConnection(BlurClient.getClient())); + public static <T1, T2> T2 run(ClusterIndexReadCommand<T1, T2> command) throws IOException, BlurException, TException { + return run(command, getConnection(BlurClient.getClient())); } @SuppressWarnings("unchecked") - public static <T1, T2> T2 run(ClusterReadCommand<T1, T2> command, Args arguments, String connectioStr) - throws IOException, BlurException, TException { - return (T2) runInternal((Command<?>) command, arguments, getConnection(BlurClient.getClient(connectioStr))); + public static <T1, T2> T2 run(ClusterIndexReadCommand<T1, T2> command, String connectioStr) throws IOException, + BlurException, TException { + return (T2) runInternal((Command<?>) command, getConnection(BlurClient.getClient(connectioStr))); } - public static <T1, T2> T2 run(ClusterReadCommand<T1, T2> command, Args arguments, Blur.Iface client) - throws IOException, BlurException, TException { - return run(command, arguments, getConnection(client)); + public static <T1, T2> T2 run(ClusterIndexReadCommand<T1, T2> command, Blur.Iface client) throws IOException, + BlurException, TException { + return run(command, getConnection(client)); } @SuppressWarnings("unchecked") - public static <T1, T2> T2 run(ClusterReadCommand<T1, T2> command, Args arguments, Connection... connection) - throws IOException, BlurException, TException { - return (T2) runInternal((Command<?>) command, arguments, connection); + public static <T1, T2> T2 run(ClusterIndexReadCommand<T1, T2> command, Connection... connection) throws IOException, + BlurException, TException { + return (T2) runInternal((Command<?>) command, connection); } - public static <T> T run(ClusterReadCombiningCommand<T> command, Args arguments) throws IOException, BlurException, - TException { - return run(command, arguments, getConnection(BlurClient.getClient())); + public static <T> T run(ClusterServerReadCommand<T> command) throws IOException, BlurException, TException { + return run(command, getConnection(BlurClient.getClient())); } @SuppressWarnings("unchecked") - public static <T> T run(ClusterReadCombiningCommand<T> command, Args arguments, String connectioStr) - throws IOException, BlurException, TException { - return (T) runInternal((Command<?>) command, arguments, getConnection(BlurClient.getClient(connectioStr))); + public static <T> T run(ClusterServerReadCommand<T> command, String connectioStr) throws IOException, + BlurException, TException { + return (T) runInternal((Command<?>) command, getConnection(BlurClient.getClient(connectioStr))); } - public static <T> T run(ClusterReadCombiningCommand<T> command, Args arguments, Blur.Iface client) - throws IOException, BlurException, TException { - return run(command, arguments, getConnection(client)); + public static <T> T run(ClusterServerReadCommand<T> command, Blur.Iface client) throws IOException, BlurException, + TException { + return run(command, getConnection(client)); } @SuppressWarnings("unchecked") - public static <T> T run(ClusterReadCombiningCommand<T> command, Args arguments, Connection... connection) - throws IOException, BlurException, TException { - return (T) runInternal((Command<?>) command, arguments, connection); + public static <T> T run(ClusterServerReadCommand<T> command, Connection... connection) throws IOException, + BlurException, TException { + return (T) runInternal((Command<?>) command, connection); } - public static <T> T run(ClusterExecuteCommand<T> command, Args arguments) throws IOException, BlurException, - TException { - return run(command, arguments, getConnection(BlurClient.getClient())); + public static <T> T run(ClusterExecuteCommand<T> command) throws IOException, BlurException, TException { + return run(command, getConnection(BlurClient.getClient())); } @SuppressWarnings("unchecked") - public static <T> T run(ClusterExecuteCommand<T> command, Args arguments, String connectioStr) throws IOException, - BlurException, TException { - return (T) runInternal((Command<?>) command, arguments, getConnection(BlurClient.getClient(connectioStr))); + public static <T> T run(ClusterExecuteCommand<T> command, String connectioStr) throws IOException, BlurException, + TException { + return (T) runInternal((Command<?>) command, getConnection(BlurClient.getClient(connectioStr))); } - public static <T> T run(ClusterExecuteCommand<T> command, Args arguments, Blur.Iface client) throws IOException, - BlurException, TException { - return run(command, arguments, getConnection(client)); + public static <T> T run(ClusterExecuteCommand<T> command, Blur.Iface client) throws IOException, BlurException, + TException { + return run(command, getConnection(client)); } @SuppressWarnings("unchecked") - public static <T> T run(ClusterExecuteCommand<T> command, Args arguments, Connection... connection) - throws IOException, BlurException, TException { - return (T) runInternal((Command<?>) command, arguments, connection); + public static <T> T run(ClusterExecuteCommand<T> command, Connection... connection) throws IOException, + BlurException, TException { + return (T) runInternal((Command<?>) command, connection); } - public static <T> T run(ClusterExecuteReadCombiningCommand<T> command, Args arguments) throws IOException, - BlurException, TException { - return run(command, arguments, getConnection(BlurClient.getClient())); + public static <T> T run(ClusterExecuteServerReadCommand<T> command) throws IOException, BlurException, TException { + return run(command, getConnection(BlurClient.getClient())); } @SuppressWarnings("unchecked") - public static <T> T run(ClusterExecuteReadCombiningCommand<T> command, Args arguments, String connectioStr) - throws IOException, BlurException, TException { - return (T) runInternal((Command<?>) command, arguments, getConnection(BlurClient.getClient(connectioStr))); + public static <T> T run(ClusterExecuteServerReadCommand<T> command, String connectioStr) throws IOException, + BlurException, TException { + return (T) runInternal((Command<?>) command, getConnection(BlurClient.getClient(connectioStr))); } - public static <T> T run(ClusterExecuteReadCombiningCommand<T> command, Args arguments, Blur.Iface client) - throws IOException, BlurException, TException { - return run(command, arguments, getConnection(client)); + public static <T> T run(ClusterExecuteServerReadCommand<T> command, Blur.Iface client) throws IOException, + BlurException, TException { + return run(command, getConnection(client)); } @SuppressWarnings("unchecked") - public static <T> T run(ClusterExecuteReadCombiningCommand<T> command, Args arguments, Connection... connection) - throws IOException, BlurException, TException { - return (T) runInternal((Command<?>) command, arguments, connection); + public static <T> T run(ClusterExecuteServerReadCommand<T> command, Connection... connection) throws IOException, + BlurException, TException { + return (T) runInternal((Command<?>) command, connection); } - private static Object runInternal(Command<?> command, Args arguments, Connection... connectionsArray) - throws TTransportException, IOException, BlurException, TimeoutException, TException { + private static Object runInternal(Command<?> command, Connection... connectionsArray) throws TTransportException, + IOException, BlurException, TimeoutException, TException { List<Connection> connections = new ArrayList<Connection>(Arrays.asList(connectionsArray)); Collections.shuffle(connections); for (Connection connection : connections) { @@ -200,7 +201,7 @@ public class CommandRunner { ClientPool clientPool = BlurClientManager.getClientPool(); Client client = clientPool.getClient(connection); try { - Response response = client.execute(command.getName(), CommandUtil.toArguments(arguments)); + Response response = client.execute(command.getName(), CommandUtil.toArguments(command)); return CommandUtil.fromThriftResponseToObject(response); } finally { clientPool.returnClient(connection, client);
