@Test public void testStopSdkExceptionRetry() { when(amazonEC2Client.describeInstances(any(DescribeInstancesRequest.class))).thenThrow(new SdkClientException("lamb"), new SdkClientException("sheep"), new SdkClientException("shepherd")).thenReturn(getDescribeInstancesResult("stopped", 55)); List<CloudVmInstanceStatus> result = underTest.stop(authenticatedContext, List.of(), inputList); verify(amazonEC2Client, times(5)).describeInstances(any(DescribeInstancesRequest.class)); Assert.assertThat(result, hasSize(2)); }
@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 public List<CloudVmInstanceStatus> stop(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) { return setCloudVmInstanceStatuses(ac, vms, "Stopped", (ec2Client, instances) -> ec2Client.stopInstances(new StopInstancesRequest().withInstanceIds(instances)), "Failed to send stop request to AWS: "); }
AwsInstanceConnector implements InstanceConnector { @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 public List<CloudVmInstanceStatus> stop(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) { return setCloudVmInstanceStatuses(ac, vms, "Stopped", (ec2Client, instances) -> ec2Client.stopInstances(new StopInstancesRequest().withInstanceIds(instances)), "Failed to send stop request to AWS: "); } }
AwsInstanceConnector implements InstanceConnector { @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 public List<CloudVmInstanceStatus> stop(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) { return setCloudVmInstanceStatuses(ac, vms, "Stopped", (ec2Client, instances) -> ec2Client.stopInstances(new StopInstancesRequest().withInstanceIds(instances)), "Failed to send stop request to AWS: "); }  }
AwsInstanceConnector implements InstanceConnector { @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 public List<CloudVmInstanceStatus> stop(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) { return setCloudVmInstanceStatuses(ac, vms, "Stopped", (ec2Client, instances) -> ec2Client.stopInstances(new StopInstancesRequest().withInstanceIds(instances)), "Failed to send stop request to AWS: "); }  @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, 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 public List<CloudVmInstanceStatus> stop(AuthenticatedContext ac, List<CloudResource> resources, List<CloudInstance> vms) { return setCloudVmInstanceStatuses(ac, vms, "Stopped", (ec2Client, instances) -> ec2Client.stopInstances(new StopInstancesRequest().withInstanceIds(instances)), "Failed to send stop request to AWS: "); }  @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; }