@Override public ExecResponse doCall() { try { return future().get(timeouts.scriptComplete, TimeUnit.MILLISECONDS); } catch (Throwable e) { eventBus.post(new StatementOnNodeFailure(init, node, e)); throw Throwables.propagate(e); } }
@Inject public BlockUntilInitScriptStatusIsZeroThenReturnOutput( @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, EventBus eventBus, ComputeServiceConstants.InitStatusProperties properties, @Assisted SudoAwareInitManager commandRunner) { this(userExecutor, eventBus, Predicates.<String> alwaysTrue(), commandRunner); // this is mutable only until we can determine how to decouple "this" from here notRunningAnymore = loopUntilTrueOrThrowCancellationException(new ExitStatusOfCommandGreaterThanZero( commandRunner), properties.initStatusMaxPeriod, properties.initStatusInitialPeriod, this); }
@Override protected boolean set(ExecResponse value) { eventBus.post(new StatementOnNodeCompletion(getCommandRunner().getStatement(), getCommandRunner().getNode(), value)); return super.set(value); }
public void testExitStatusZeroReturnsExecResponse() throws InterruptedException, ExecutionException { ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction") .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString") .createStrictMock(); InitScript initScript = createMockBuilder(InitScript.class).addMockedMethod("getInstanceName").createStrictMock(); expect(commandRunner.runAction("stdout")).andReturn(new ExecResponse("stdout", "", 0)); expect(commandRunner.runAction("stderr")).andReturn(new ExecResponse("stderr", "", 0)); expect(commandRunner.runAction("exitstatus")).andReturn(new ExecResponse("444\n", "", 0)); toStringAndEventBusExpectations(commandRunner, initScript); replay(commandRunner, initScript); BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( userExecutor, eventBus, notRunningAnymore, commandRunner); future.run(); assertEquals(future.get(), new ExecResponse("stdout", "stderr", 444)); verify(commandRunner, initScript); }
@Override public void run() { try { ExecResponse exec = null; do { notRunningAnymore.apply("status"); String stdout = commandRunner.runAction("stdout").getOutput(); String stderr = commandRunner.runAction("stderr").getOutput(); Integer exitStatus = Ints.tryParse(commandRunner.runAction("exitstatus").getOutput().trim()); exec = new ExecResponse(stdout, stderr, exitStatus == null ? Integer.valueOf(-1) : exitStatus); } while (!isCancelled() && exec.getExitStatus() == -1); logger.debug("<< complete(%s) status(%s)", commandRunner.getStatement().getInstanceName(), exec .getExitStatus()); set(exec); } catch (Exception e) { setException(e); } }
public void testCancelDontInterruptLeavesCommandRunningAndReturnsLastStatus() throws InterruptedException, ExecutionException { ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction") .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString") .createStrictMock(); InitScript initScript = createMockBuilder(InitScript.class).addMockedMethod("getInstanceName").createStrictMock(); expect(commandRunner.runAction("stdout")).andReturn(new ExecResponse("stillrunning", "", 0)); expect(commandRunner.runAction("stderr")).andReturn(new ExecResponse("", "", 0)); expect(commandRunner.runAction("exitstatus")).andReturn(new ExecResponse("", "", 1)); toStringAndEventBusExpectations(commandRunner, initScript); replay(commandRunner, initScript); BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( userExecutor, eventBus, notRunningAnymore, commandRunner); future.cancel(false); // note if this didn't cancel properly, the loop would never end! future.run(); try { future.get(); fail(); } catch (CancellationException e) { } verify(commandRunner, initScript); }
BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( userExecutor, eventBus, notRunningAnymore, commandRunner); future.cancel(true); future.get(); fail(); } catch (CancellationException e) {
public BlockUntilInitScriptStatusIsZeroThenReturnOutput future() { ExecResponse returnVal = super.doCall(); if (returnVal.getExitStatus() != 0) { IllegalStateException e = new IllegalStateException(String.format( "instance: %s on node: %s had non-zero exit status: %s", init.getInstanceName(), getNode().getId(), returnVal)); eventBus.post(new StatementOnNodeFailure(init, node, e)); throw e; } return statusFactory.create(this).init(); }
public void testExitStatusZeroReturnsExecResponse() throws InterruptedException, ExecutionException { ListeningExecutorService userExecutor = MoreExecutors.newDirectExecutorService(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction") .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString") .createStrictMock(); InitScript initScript = createMockBuilder(InitScript.class).addMockedMethod("getInstanceName").createStrictMock(); expect(commandRunner.runAction("stdout")).andReturn(new ExecResponse("stdout", "", 0)); expect(commandRunner.runAction("stderr")).andReturn(new ExecResponse("stderr", "", 0)); expect(commandRunner.runAction("exitstatus")).andReturn(new ExecResponse("444\n", "", 0)); toStringAndEventBusExpectations(commandRunner, initScript); replay(commandRunner, initScript); BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( userExecutor, eventBus, notRunningAnymore, commandRunner); future.run(); assertEquals(future.get(), new ExecResponse("stdout", "stderr", 444)); verify(commandRunner, initScript); }
@Override public void run() { try { ExecResponse exec = null; do { notRunningAnymore.apply("status"); String stdout = commandRunner.runAction("stdout").getOutput(); String stderr = commandRunner.runAction("stderr").getOutput(); Integer exitStatus = Ints.tryParse(commandRunner.runAction("exitstatus").getOutput().trim()); exec = new ExecResponse(stdout, stderr, exitStatus == null ? -1 : exitStatus); } while (!isCancelled() && exec.getExitStatus() == -1); logger.debug("<< complete(%s) status(%s)", commandRunner.getStatement().getInstanceName(), exec .getExitStatus()); set(exec); } catch (Exception e) { setException(e); } }
public void testCancelDontInterruptLeavesCommandRunningAndReturnsLastStatus() throws InterruptedException, ExecutionException { ListeningExecutorService userExecutor = MoreExecutors.newDirectExecutorService(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction") .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString") .createStrictMock(); InitScript initScript = createMockBuilder(InitScript.class).addMockedMethod("getInstanceName").createStrictMock(); expect(commandRunner.runAction("stdout")).andReturn(new ExecResponse("stillrunning", "", 0)); expect(commandRunner.runAction("stderr")).andReturn(new ExecResponse("", "", 0)); expect(commandRunner.runAction("exitstatus")).andReturn(new ExecResponse("", "", 1)); toStringAndEventBusExpectations(commandRunner, initScript); replay(commandRunner, initScript); BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( userExecutor, eventBus, notRunningAnymore, commandRunner); future.cancel(false); // note if this didn't cancel properly, the loop would never end! future.run(); try { future.get(); fail(); } catch (CancellationException e) { } verify(commandRunner, initScript); }
BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( userExecutor, eventBus, notRunningAnymore, commandRunner); future.cancel(true); future.get(); fail(); } catch (CancellationException e) {
public BlockUntilInitScriptStatusIsZeroThenReturnOutput future() { ExecResponse returnVal = super.doCall(); if (returnVal.getExitStatus() != 0) { IllegalStateException e = new IllegalStateException(String.format( "instance: %s on node: %s had non-zero exit status: %s", init.getInstanceName(), getNode().getId(), returnVal)); eventBus.post(new StatementOnNodeFailure(init, node, e)); throw e; } return statusFactory.create(this).init(); }
public void testFirstExitStatusOneButSecondExitStatusZeroReturnsExecResponse() throws InterruptedException, ExecutionException { ListeningExecutorService userExecutor = MoreExecutors.sameThreadExecutor(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction") .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString") .createStrictMock(); InitScript initScript = createMockBuilder(InitScript.class).addMockedMethod("getInstanceName").createStrictMock(); // exit status is 1 means we are still running! expect(commandRunner.runAction("stdout")).andReturn(new ExecResponse("", "", 0)); expect(commandRunner.runAction("stderr")).andReturn(new ExecResponse("", "", 0)); expect(commandRunner.runAction("exitstatus")).andReturn(new ExecResponse("", "", 1)); // second time around, it did stop expect(commandRunner.runAction("stdout")).andReturn(new ExecResponse("stdout", "", 0)); expect(commandRunner.runAction("stderr")).andReturn(new ExecResponse("stderr", "", 0)); expect(commandRunner.runAction("exitstatus")).andReturn(new ExecResponse("444\n", "", 0)); toStringAndEventBusExpectations(commandRunner, initScript); replay(commandRunner, initScript); BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( userExecutor, eventBus, notRunningAnymore, commandRunner); future.run(); assertEquals(future.get(), new ExecResponse("stdout", "stderr", 444)); verify(commandRunner, initScript); }
@Override public void run() { try { ExecResponse exec = null; do { notRunningAnymore.apply("status"); String stdout = commandRunner.runAction("stdout").getOutput(); String stderr = commandRunner.runAction("stderr").getOutput(); Integer exitStatus = Ints.tryParse(commandRunner.runAction("exitstatus").getOutput().trim()); exec = new ExecResponse(stdout, stderr, exitStatus == null ? Integer.valueOf(-1) : exitStatus); } while (!isCancelled() && exec.getExitStatus() == -1); logger.debug("<< complete(%s) status(%s)", commandRunner.getStatement().getInstanceName(), exec .getExitStatus()); set(exec); } catch (Exception e) { setException(e); } }
@Inject public BlockUntilInitScriptStatusIsZeroThenReturnOutput( @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, EventBus eventBus, ComputeServiceConstants.InitStatusProperties properties, @Assisted SudoAwareInitManager commandRunner) { this(userExecutor, eventBus, Predicates.<String> alwaysTrue(), commandRunner); // this is mutable only until we can determine how to decouple "this" from here notRunningAnymore = loopUntilTrueOrThrowCancellationException(new ExitStatusOfCommandGreaterThanZero( commandRunner), properties.initStatusMaxPeriod, properties.initStatusInitialPeriod, this); }
@Override public ExecResponse doCall() { try { return future().get(timeouts.scriptComplete, TimeUnit.MILLISECONDS); } catch (Throwable e) { eventBus.post(new StatementOnNodeFailure(init, node, e)); throw Throwables.propagate(e); } }
@Override protected boolean set(ExecResponse value) { eventBus.post(new StatementOnNodeCompletion(getCommandRunner().getStatement(), getCommandRunner().getNode(), value)); return super.set(value); }
public BlockUntilInitScriptStatusIsZeroThenReturnOutput future() { ExecResponse returnVal = super.doCall(); if (returnVal.getExitStatus() != 0) { IllegalStateException e = new IllegalStateException(String.format( "instance: %s on node: %s had non-zero exit status: %s", init.getInstanceName(), getNode().getId(), returnVal)); eventBus.post(new StatementOnNodeFailure(init, node, e)); throw e; } return statusFactory.create(this).init(); }
public void testFirstExitStatusOneButSecondExitStatusZeroReturnsExecResponse() throws InterruptedException, ExecutionException { ListeningExecutorService userExecutor = MoreExecutors.newDirectExecutorService(); Predicate<String> notRunningAnymore = Predicates.alwaysTrue(); SudoAwareInitManager commandRunner = createMockBuilder(SudoAwareInitManager.class).addMockedMethod("runAction") .addMockedMethod("getStatement").addMockedMethod("getNode").addMockedMethod("toString") .createStrictMock(); InitScript initScript = createMockBuilder(InitScript.class).addMockedMethod("getInstanceName").createStrictMock(); // exit status is 1 means we are still running! expect(commandRunner.runAction("stdout")).andReturn(new ExecResponse("", "", 0)); expect(commandRunner.runAction("stderr")).andReturn(new ExecResponse("", "", 0)); expect(commandRunner.runAction("exitstatus")).andReturn(new ExecResponse("", "", 1)); // second time around, it did stop expect(commandRunner.runAction("stdout")).andReturn(new ExecResponse("stdout", "", 0)); expect(commandRunner.runAction("stderr")).andReturn(new ExecResponse("stderr", "", 0)); expect(commandRunner.runAction("exitstatus")).andReturn(new ExecResponse("444\n", "", 0)); toStringAndEventBusExpectations(commandRunner, initScript); replay(commandRunner, initScript); BlockUntilInitScriptStatusIsZeroThenReturnOutput future = new BlockUntilInitScriptStatusIsZeroThenReturnOutput( userExecutor, eventBus, notRunningAnymore, commandRunner); future.run(); assertEquals(future.get(), new ExecResponse("stdout", "stderr", 444)); verify(commandRunner, initScript); }