use of com.amazonaws.waiters.WaiterTimedOutException in project cloudbreak by hortonworks.
the class EC2ClientActions method stopHostGroupInstances.
public void stopHostGroupInstances(List<String> instanceIds) {
AmazonEC2 ec2Client = buildEC2Client();
StopInstancesResult stopInstancesResult = ec2Client.stopInstances(new StopInstancesRequest().withInstanceIds(instanceIds));
for (String instanceId : instanceIds) {
try {
Log.log(LOGGER, format(" EC2 instance [%s] state is [%s] ", instanceId, Objects.requireNonNull(stopInstancesResult.getStoppingInstances().stream().filter(instance -> instance.getInstanceId().equals(instanceId)).findAny().orElse(null)).getCurrentState().getName()));
ec2Client.waiters().instanceStopped().run(new WaiterParameters<DescribeInstancesRequest>(new DescribeInstancesRequest().withInstanceIds(instanceId)).withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(80), new FixedDelayStrategy(30))));
DescribeInstancesResult describeInstanceResult = ec2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId));
InstanceState actualInstanceState = describeInstanceResult.getReservations().get(0).getInstances().get(0).getState();
if (STOPPED_STATE.equals(actualInstanceState.getName())) {
Log.log(LOGGER, format(" EC2 Instance: %s state is: %s ", instanceId, STOPPED_STATE));
} else {
LOGGER.error("EC2 Instance: {} stop has not been successful. So the actual state is: {} ", instanceId, actualInstanceState.getName());
throw new TestFailException(" EC2 Instance: " + instanceId + " stop has not been successful, because of the actual state is: " + actualInstanceState.getName());
}
} catch (WaiterUnrecoverableException e) {
LOGGER.error("EC2 Instance {} stop has not been successful, because of WaiterUnrecoverableException: {}", instanceId, e);
} catch (WaiterTimedOutException e) {
LOGGER.error("EC2 Instance {} stop has not been successful, because of WaiterTimedOutException: {}", instanceId, e);
} catch (EC2UnexpectedException e) {
LOGGER.error("EC2 Instance {} stop has not been successful, because of EC2UnexpectedException: {}", instanceId, e);
}
}
}
use of com.amazonaws.waiters.WaiterTimedOutException in project cloudbreak by hortonworks.
the class AwsAutoScalingService method waitForGroup.
private void waitForGroup(AmazonEc2Client amClient, AmazonAutoScalingClient asClient, String autoScalingGroupName, Integer requiredInstanceCount, Long stackId, List<String> knownInstances) throws AmazonAutoscalingFailed {
Waiter<DescribeAutoScalingGroupsRequest> groupInServiceWaiter = asClient.waiters().groupInService();
PollingStrategy backoff = getBackoffCancellablePollingStrategy(new StackCancellationCheck(stackId));
try {
groupInServiceWaiter.run(new WaiterParameters<>(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(autoScalingGroupName)).withPollingStrategy(backoff));
} catch (Exception e) {
throw new AmazonAutoscalingFailed(e.getMessage(), e);
}
Waiter<DescribeAutoScalingGroupsRequest> instancesInServiceWaiter = customAmazonWaiterProvider.getAutoscalingInstancesInServiceWaiter(asClient, requiredInstanceCount);
try {
instancesInServiceWaiter.run(new WaiterParameters<>(new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(autoScalingGroupName)).withPollingStrategy(backoff));
} catch (WaiterTimedOutException e) {
String message = String.format("Polling timed out. Not all the %s instance(s) reached InService state.", requiredInstanceCount);
throw new AmazonAutoscalingFailed(message, e);
} catch (Exception e) {
throw new AmazonAutoscalingFailed(e.getMessage(), e);
}
List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(asClient, autoScalingGroupName);
List<String> instanceIdsForWait = getInstanceIdsForWait(instanceIds, knownInstances);
if (requiredInstanceCount != 0) {
List<List<String>> partitionedInstanceIdsList = Lists.partition(instanceIdsForWait, MAX_INSTANCE_ID_SIZE);
Waiter<DescribeInstancesRequest> instanceRunningStateWaiter = amClient.waiters().instanceRunning();
for (List<String> partitionedInstanceIds : partitionedInstanceIdsList) {
try {
instanceRunningStateWaiter.run(new WaiterParameters<>(new DescribeInstancesRequest().withInstanceIds(partitionedInstanceIds)).withPollingStrategy(backoff));
} catch (AmazonServiceException e) {
LOGGER.error("Cannot describeInstances", e);
e.setErrorMessage("Cannot describeInstances. " + e.getErrorMessage());
throw e;
} catch (Exception e) {
throw new AmazonAutoscalingFailed("Error occurred in describeInstances: " + e.getMessage(), e);
}
}
}
}
use of com.amazonaws.waiters.WaiterTimedOutException in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testDeleteNetworkWithSubNetsShouldThrowAnExceptionWhenTheStackDeletionFailed.
@Test(expected = CloudConnectorException.class)
public void testDeleteNetworkWithSubNetsShouldThrowAnExceptionWhenTheStackDeletionFailed() {
NetworkDeletionRequest networkDeletionRequest = createNetworkDeletionRequest();
AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(networkDeletionRequest.getRegion()))).thenReturn(cfClient);
when(cfClient.waiters()).thenReturn(cfWaiters);
when(retryService.testWith2SecDelayMax15Times(any())).thenReturn(true);
when(cfWaiters.stackDeleteComplete()).thenReturn(deletionWaiter);
doThrow(new WaiterTimedOutException("fail")).when(deletionWaiter).run(any());
underTest.deleteNetworkWithSubnets(networkDeletionRequest);
verify(cfClient).deleteStack(any(DeleteStackRequest.class));
verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()));
}
use of com.amazonaws.waiters.WaiterTimedOutException in project cloudbreak by hortonworks.
the class EC2ClientActions method deleteHostGroupInstances.
public void deleteHostGroupInstances(List<String> instanceIds) {
AmazonEC2 ec2Client = buildEC2Client();
TerminateInstancesResult terminateInstancesResult = ec2Client.terminateInstances(new TerminateInstancesRequest().withInstanceIds(instanceIds));
for (String instanceId : instanceIds) {
try {
Log.log(LOGGER, format(" EC2 instance [%s] state is [%s] ", instanceId, Objects.requireNonNull(terminateInstancesResult.getTerminatingInstances().stream().filter(instance -> instance.getInstanceId().equals(instanceId)).findAny().orElse(null)).getCurrentState().getName()));
ec2Client.waiters().instanceTerminated().run(new WaiterParameters<DescribeInstancesRequest>(new DescribeInstancesRequest().withInstanceIds(instanceId)).withPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(80), new FixedDelayStrategy(30))));
DescribeInstancesResult describeInstanceResult = ec2Client.describeInstances(new DescribeInstancesRequest().withInstanceIds(instanceId));
InstanceState actualInstanceState = describeInstanceResult.getReservations().get(0).getInstances().get(0).getState();
if (TERMINATED_STATE.equals(actualInstanceState.getName())) {
Log.log(LOGGER, format(" EC2 Instance: %s state is: %s ", instanceId, TERMINATED_STATE));
} else {
LOGGER.error("EC2 Instance: {} termination has not been successful. So the actual state is: {} ", instanceId, actualInstanceState.getName());
throw new TestFailException(" EC2 Instance: " + instanceId + " termination has not been successful, because of the actual state is: " + actualInstanceState.getName());
}
} catch (WaiterUnrecoverableException e) {
LOGGER.error("EC2 Instance {} termination has not been successful, because of WaiterUnrecoverableException: {}", instanceId, e);
} catch (WaiterTimedOutException e) {
LOGGER.error("EC2 Instance {} termination has not been successful, because of WaiterTimedOutException: {}", instanceId, e);
} catch (EC2UnexpectedException e) {
LOGGER.error("EC2 Instance {} termination has not been successful, because of EC2UnexpectedException: {}", instanceId, e);
}
}
}
Aggregations