@Test public void testRebootEveryInstancesStarted() { mockDescribeInstancesAllisRebooted(POLLING_LIMIT - 2); ArgumentCaptor<StopInstancesRequest> stopCaptor = ArgumentCaptor.forClass(StopInstancesRequest.class); ArgumentCaptor<StartInstancesRequest> startCaptor = ArgumentCaptor.forClass(StartInstancesRequest.class); List<CloudVmInstanceStatus> result = underTest.reboot(authenticatedContext, inputList); verify(amazonEC2Client, times(2)).stopInstances(stopCaptor.capture()); verify(amazonEC2Client, times(2)).startInstances(startCaptor.capture()); Assert.assertThat(result, hasItem(allOf(hasProperty("status", is(InstanceStatus.STARTED))))); }
@Retryable( value = SdkClientException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000) ) @Override public List<CloudVmInstanceStatus> reboot(AuthenticatedContext ac, List<CloudInstance> vms) { List<CloudVmInstanceStatus> rebootedVmsStatus = new ArrayList<>(); try { if (!vms.isEmpty()) { List<CloudVmInstanceStatus> statuses = check(ac, vms); doStop(ac, getStarted(statuses)); statuses = check(ac, vms); logInvalidStatuses(getNotStopped(statuses), InstanceStatus.STOPPED); rebootedVmsStatus = doStart(ac, getStopped(statuses)); logInvalidStatuses(getNotStarted(statuses), InstanceStatus.STARTED); } } catch (SdkClientException e) { LOGGER.warn("Failed to send reboot request to AWS: ", e); throw e; } return rebootedVmsStatus; }
AwsInstanceConnector implements InstanceConnector { @Retryable( value = SdkClientException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000) ) @Override public List<CloudVmInstanceStatus> reboot(AuthenticatedContext ac, List<CloudInstance> vms) { List<CloudVmInstanceStatus> rebootedVmsStatus = new ArrayList<>(); try { if (!vms.isEmpty()) { List<CloudVmInstanceStatus> statuses = check(ac, vms); doStop(ac, getStarted(statuses)); statuses = check(ac, vms); logInvalidStatuses(getNotStopped(statuses), InstanceStatus.STOPPED); rebootedVmsStatus = doStart(ac, getStopped(statuses)); logInvalidStatuses(getNotStarted(statuses), InstanceStatus.STARTED); } } catch (SdkClientException e) { LOGGER.warn("Failed to send reboot request to AWS: ", e); throw e; } return rebootedVmsStatus; } }
AwsInstanceConnector implements InstanceConnector { @Retryable( value = SdkClientException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000) ) @Override public List<CloudVmInstanceStatus> reboot(AuthenticatedContext ac, List<CloudInstance> vms) { List<CloudVmInstanceStatus> rebootedVmsStatus = new ArrayList<>(); try { if (!vms.isEmpty()) { List<CloudVmInstanceStatus> statuses = check(ac, vms); doStop(ac, getStarted(statuses)); statuses = check(ac, vms); logInvalidStatuses(getNotStopped(statuses), InstanceStatus.STOPPED); rebootedVmsStatus = doStart(ac, getStopped(statuses)); logInvalidStatuses(getNotStarted(statuses), InstanceStatus.STARTED); } } catch (SdkClientException e) { LOGGER.warn("Failed to send reboot request to AWS: ", e); throw e; } return rebootedVmsStatus; }  }
AwsInstanceConnector implements InstanceConnector { @Retryable( value = SdkClientException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000) ) @Override public List<CloudVmInstanceStatus> reboot(AuthenticatedContext ac, List<CloudInstance> vms) { List<CloudVmInstanceStatus> rebootedVmsStatus = new ArrayList<>(); try { if (!vms.isEmpty()) { List<CloudVmInstanceStatus> statuses = check(ac, vms); doStop(ac, getStarted(statuses)); statuses = check(ac, vms); logInvalidStatuses(getNotStopped(statuses), InstanceStatus.STOPPED); rebootedVmsStatus = doStart(ac, getStopped(statuses)); logInvalidStatuses(getNotStarted(statuses), InstanceStatus.STARTED); } } catch (SdkClientException e) { LOGGER.warn("Failed to send reboot request to AWS: ", e); throw e; } return rebootedVmsStatus; }  @Override String getConsoleOutput(AuthenticatedContext authenticatedContext, CloudInstance vm); @Retryable( value = SdkClientException.class, maxAttemptsExpression = "#{${cb.vm.retry.attempt:15}}", backoff = @Backoff(delayExpression = "#{${cb.vm.retry.backoff.delay:1000}}", multiplierExpression = "#{${cb.vm.retry.backoff.multiplier:2}}", maxDelayExpression = "#{${cb.vm.retry.backoff.maxdelay:10000}}") ) @Override List<CloudVmInstanceStatus> start(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms); @Retryable( value = SdkClientException.class, maxAttemptsExpression = "#{${cb.vm.retry.attempt:15}}", backoff = @Backoff(delayExpression = "#{${cb.vm.retry.backoff.delay:1000}}", multiplierExpression = "#{${cb.vm.retry.backoff.multiplier:2}}", maxDelayExpression = "#{${cb.vm.retry.backoff.maxdelay:10000}}") ) @Override List<CloudVmInstanceStatus> stop(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms); @Retryable( value = SdkClientException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000) ) @Override List<CloudVmInstanceStatus> reboot(AuthenticatedContext ac, List<CloudInstance> vms); void logInvalidStatuses(List<CloudVmInstanceStatus> instances, InstanceStatus targetStatus); @Retryable( value = SdkClientException.class, maxAttemptsExpression = "#{${cb.vm.retry.attempt:15}}", backoff = @Backoff(delayExpression = "#{${cb.vm.retry.backoff.delay:1000}}", multiplierExpression = "#{${cb.vm.retry.backoff.multiplier:2}}", maxDelayExpression = "#{${cb.vm.retry.backoff.maxdelay:10000}}") ) @Override List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms); }
AwsInstanceConnector implements InstanceConnector { @Retryable( value = SdkClientException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000) ) @Override public List<CloudVmInstanceStatus> reboot(AuthenticatedContext ac, List<CloudInstance> vms) { List<CloudVmInstanceStatus> rebootedVmsStatus = new ArrayList<>(); try { if (!vms.isEmpty()) { List<CloudVmInstanceStatus> statuses = check(ac, vms); doStop(ac, getStarted(statuses)); statuses = check(ac, vms); logInvalidStatuses(getNotStopped(statuses), InstanceStatus.STOPPED); rebootedVmsStatus = doStart(ac, getStopped(statuses)); logInvalidStatuses(getNotStarted(statuses), InstanceStatus.STARTED); } } catch (SdkClientException e) { LOGGER.warn("Failed to send reboot request to AWS: ", e); throw e; } return rebootedVmsStatus; }  @Override String getConsoleOutput(AuthenticatedContext authenticatedContext, CloudInstance vm); @Retryable( value = SdkClientException.class, maxAttemptsExpression = "#{${cb.vm.retry.attempt:15}}", backoff = @Backoff(delayExpression = "#{${cb.vm.retry.backoff.delay:1000}}", multiplierExpression = "#{${cb.vm.retry.backoff.multiplier:2}}", maxDelayExpression = "#{${cb.vm.retry.backoff.maxdelay:10000}}") ) @Override List<CloudVmInstanceStatus> start(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms); @Retryable( value = SdkClientException.class, maxAttemptsExpression = "#{${cb.vm.retry.attempt:15}}", backoff = @Backoff(delayExpression = "#{${cb.vm.retry.backoff.delay:1000}}", multiplierExpression = "#{${cb.vm.retry.backoff.multiplier:2}}", maxDelayExpression = "#{${cb.vm.retry.backoff.maxdelay:10000}}") ) @Override List<CloudVmInstanceStatus> stop(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms); @Retryable( value = SdkClientException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000) ) @Override List<CloudVmInstanceStatus> reboot(AuthenticatedContext ac, List<CloudInstance> vms); void logInvalidStatuses(List<CloudVmInstanceStatus> instances, InstanceStatus targetStatus); @Retryable( value = SdkClientException.class, maxAttemptsExpression = "#{${cb.vm.retry.attempt:15}}", backoff = @Backoff(delayExpression = "#{${cb.vm.retry.backoff.delay:1000}}", multiplierExpression = "#{${cb.vm.retry.backoff.multiplier:2}}", maxDelayExpression = "#{${cb.vm.retry.backoff.maxdelay:10000}}") ) @Override List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms); static final String INSTANCE_NOT_FOUND_ERROR_CODE; }