@Test public void testNewCommandLoading() throws IOException, TimeoutException, InterruptedException, ExceptionCollector { _manager.close(); _tmpPath.mkdirs(); File commandPath = new File(_commandPath); rmr(commandPath); if (commandPath.exists()) { fail("Command path [" + commandPath + "] still exists."); } commandPath.mkdirs(); { InputStream inputStream = getClass().getResourceAsStream("/org/apache/blur/command/test1/test1.jar"); File dest = new File(commandPath, "test1.jar"); FileOutputStream output = new FileOutputStream(dest); IOUtils.copy(inputStream, output); inputStream.close(); output.close(); } ShardCommandManager manager = new ShardCommandManager(getIndexServer(), _tmpPath, _commandPath, 10, 10, 1000, _config, "test"); { BlurObject args = new BlurObject(); args.put("table", "test"); ArgumentOverlay argumentOverlay = new ArgumentOverlay(args, new BlurObjectSerDe()); CommandStatus originalCommandStatusObject = new CommandStatus(null, "test", null, null, null); Response response = manager.execute(getTableContextFactory(), "test", argumentOverlay, originalCommandStatusObject); Map<Shard, Object> shardResults = response.getShardResults(); for (Object o : shardResults.values()) { assertEquals("test1", o); } } { InputStream inputStream = getClass().getResourceAsStream("/org/apache/blur/command/test2/test2.jar"); File dest = new File(commandPath, "test2.jar"); FileOutputStream output = new FileOutputStream(dest); IOUtils.copy(inputStream, output); inputStream.close(); output.close(); } assertEquals(1, manager.commandRefresh()); { BlurObject args = new BlurObject(); args.put("table", "test"); ArgumentOverlay argumentOverlay = new ArgumentOverlay(args, new BlurObjectSerDe()); CommandStatus originalCommandStatusObject = new CommandStatus(null, "test", null, null, null); Response response = manager.execute(getTableContextFactory(), "test", argumentOverlay, originalCommandStatusObject); Map<Shard, Object> shardResults = response.getShardResults(); for (Object o : shardResults.values()) { assertEquals("test2", o); } } _manager = manager; }
public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); }
ShardCommandManager extends BaseCommandManager { public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); } }
ShardCommandManager extends BaseCommandManager { public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); } ShardCommandManager(IndexServer indexServer, File tmpPath, String commandPath, int workerThreadCount,
      int driverThreadCount, long connectionTimeout, Configuration configuration, String serverName); }
ShardCommandManager extends BaseCommandManager { public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); } ShardCommandManager(IndexServer indexServer, File tmpPath, String commandPath, int workerThreadCount,
      int driverThreadCount, long connectionTimeout, Configuration configuration, String serverName); Response execute(final TableContextFactory tableContextFactory, final String commandName,
      final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject); }
ShardCommandManager extends BaseCommandManager { public Response execute(final TableContextFactory tableContextFactory, final String commandName, final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject) throws IOException, TimeoutException, ExceptionCollector { final ShardServerContext shardServerContext = getShardServerContext(); AtomicBoolean running = new AtomicBoolean(true); final Command<?> command = getCommandObject(commandName, argumentOverlay); Callable<Response> callable = new Callable<Response>() { @Override public Response call() throws Exception { if (command == null) { throw new IOException("Command with name [" + commandName + "] not found."); } if (command instanceof IndexRead || command instanceof ServerRead) { return toResponse( executeReadCommand(shardServerContext, command, tableContextFactory, originalCommandStatusObject, running), command, getServerContext(tableContextFactory)); } throw new IOException("Command type of [" + command.getClass() + "] not supported."); } private CombiningContext getServerContext(final TableContextFactory tableContextFactory) { return new CombiningContext() { @Override public TableContext getTableContext(String table) throws IOException { return tableContextFactory.getTableContext(table); } @Override public BlurConfiguration getBlurConfiguration(String table) throws IOException { return getTableContext(table).getBlurConfiguration(); } }; } }; return submitDriverCallable(callable, command, originalCommandStatusObject, running); } ShardCommandManager(IndexServer indexServer, File tmpPath, String commandPath, int workerThreadCount,
      int driverThreadCount, long connectionTimeout, Configuration configuration, String serverName); Response execute(final TableContextFactory tableContextFactory, final String commandName,
      final ArgumentOverlay argumentOverlay, CommandStatus originalCommandStatusObject);  }