@Test public void testCheckSdkExceptionRetry() { when(amazonEC2Client.describeInstances(any(DescribeInstancesRequest.class))).thenThrow(new SdkClientException("lamb"), new SdkClientException("sheep"), new SdkClientException("shepherd")).thenReturn(getDescribeInstancesResult("running", 16)); List<CloudInstance> list = getCloudInstances(); List<CloudVmInstanceStatus> result = underTest.check(authenticatedContext, list); verify(amazonEC2Client, times(4)).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> check(AuthenticatedContext ac, List<CloudInstance> vms) { LOGGER.debug("Check instances on aws side: {}", vms); List<CloudInstance> cloudInstancesWithInstanceId = vms.stream() .filter(cloudInstance -> cloudInstance.getInstanceId() != null) .collect(Collectors.toList()); LOGGER.debug("Instances with instanceId: {}", cloudInstancesWithInstanceId); List<String> instanceIds = cloudInstancesWithInstanceId.stream().map(CloudInstance::getInstanceId) .collect(Collectors.toList()); String region = ac.getCloudContext().getLocation().getRegion().value(); try { DescribeInstancesResult result = new AuthenticatedContextView(ac).getAmazonEC2Client() .describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds)); LOGGER.debug("Result from AWS: {}", result); return fillCloudVmInstanceStatuses(ac, cloudInstancesWithInstanceId, region, result); } catch (AmazonEC2Exception e) { handleEC2Exception(vms, e); } catch (SdkClientException e) { LOGGER.warn("Failed to send request to AWS: ", e); throw e; } return Collections.emptyList(); }
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> check(AuthenticatedContext ac, List<CloudInstance> vms) { LOGGER.debug("Check instances on aws side: {}", vms); List<CloudInstance> cloudInstancesWithInstanceId = vms.stream() .filter(cloudInstance -> cloudInstance.getInstanceId() != null) .collect(Collectors.toList()); LOGGER.debug("Instances with instanceId: {}", cloudInstancesWithInstanceId); List<String> instanceIds = cloudInstancesWithInstanceId.stream().map(CloudInstance::getInstanceId) .collect(Collectors.toList()); String region = ac.getCloudContext().getLocation().getRegion().value(); try { DescribeInstancesResult result = new AuthenticatedContextView(ac).getAmazonEC2Client() .describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds)); LOGGER.debug("Result from AWS: {}", result); return fillCloudVmInstanceStatuses(ac, cloudInstancesWithInstanceId, region, result); } catch (AmazonEC2Exception e) { handleEC2Exception(vms, e); } catch (SdkClientException e) { LOGGER.warn("Failed to send request to AWS: ", e); throw e; } return Collections.emptyList(); } }
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> check(AuthenticatedContext ac, List<CloudInstance> vms) { LOGGER.debug("Check instances on aws side: {}", vms); List<CloudInstance> cloudInstancesWithInstanceId = vms.stream() .filter(cloudInstance -> cloudInstance.getInstanceId() != null) .collect(Collectors.toList()); LOGGER.debug("Instances with instanceId: {}", cloudInstancesWithInstanceId); List<String> instanceIds = cloudInstancesWithInstanceId.stream().map(CloudInstance::getInstanceId) .collect(Collectors.toList()); String region = ac.getCloudContext().getLocation().getRegion().value(); try { DescribeInstancesResult result = new AuthenticatedContextView(ac).getAmazonEC2Client() .describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds)); LOGGER.debug("Result from AWS: {}", result); return fillCloudVmInstanceStatuses(ac, cloudInstancesWithInstanceId, region, result); } catch (AmazonEC2Exception e) { handleEC2Exception(vms, e); } catch (SdkClientException e) { LOGGER.warn("Failed to send request to AWS: ", e); throw e; } return Collections.emptyList(); }  }
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> check(AuthenticatedContext ac, List<CloudInstance> vms) { LOGGER.debug("Check instances on aws side: {}", vms); List<CloudInstance> cloudInstancesWithInstanceId = vms.stream() .filter(cloudInstance -> cloudInstance.getInstanceId() != null) .collect(Collectors.toList()); LOGGER.debug("Instances with instanceId: {}", cloudInstancesWithInstanceId); List<String> instanceIds = cloudInstancesWithInstanceId.stream().map(CloudInstance::getInstanceId) .collect(Collectors.toList()); String region = ac.getCloudContext().getLocation().getRegion().value(); try { DescribeInstancesResult result = new AuthenticatedContextView(ac).getAmazonEC2Client() .describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds)); LOGGER.debug("Result from AWS: {}", result); return fillCloudVmInstanceStatuses(ac, cloudInstancesWithInstanceId, region, result); } catch (AmazonEC2Exception e) { handleEC2Exception(vms, e); } catch (SdkClientException e) { LOGGER.warn("Failed to send request to AWS: ", e); throw e; } return Collections.emptyList(); }  @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> check(AuthenticatedContext ac, List<CloudInstance> vms) { LOGGER.debug("Check instances on aws side: {}", vms); List<CloudInstance> cloudInstancesWithInstanceId = vms.stream() .filter(cloudInstance -> cloudInstance.getInstanceId() != null) .collect(Collectors.toList()); LOGGER.debug("Instances with instanceId: {}", cloudInstancesWithInstanceId); List<String> instanceIds = cloudInstancesWithInstanceId.stream().map(CloudInstance::getInstanceId) .collect(Collectors.toList()); String region = ac.getCloudContext().getLocation().getRegion().value(); try { DescribeInstancesResult result = new AuthenticatedContextView(ac).getAmazonEC2Client() .describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceIds)); LOGGER.debug("Result from AWS: {}", result); return fillCloudVmInstanceStatuses(ac, cloudInstancesWithInstanceId, region, result); } catch (AmazonEC2Exception e) { handleEC2Exception(vms, e); } catch (SdkClientException e) { LOGGER.warn("Failed to send request to AWS: ", e); throw e; } return Collections.emptyList(); }  @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; }