use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.
the class AWSTaskStatusChecker method buildRequest.
private AmazonWebServiceRequest buildRequest(T type) {
if (type instanceof Instance) {
DescribeInstancesRequest descRequest = new DescribeInstancesRequest();
List<String> instanceIdList = new ArrayList<>();
instanceIdList.add(this.instanceId);
descRequest.setInstanceIds(instanceIdList);
return descRequest;
} else if (type instanceof NatGateway) {
DescribeNatGatewaysRequest descRequest = new DescribeNatGatewaysRequest();
List<String> instanceIdList = new ArrayList<>();
instanceIdList.add(this.instanceId);
descRequest.setNatGatewayIds(instanceIdList);
return descRequest;
} else if (type instanceof Volume) {
DescribeVolumesRequest descRequest = new DescribeVolumesRequest();
List<String> volumeIdList = new ArrayList<>();
volumeIdList.add(this.instanceId);
descRequest.setVolumeIds(volumeIdList);
return descRequest;
} else {
AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(new IllegalArgumentException("Invalid type " + type));
return null;
}
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.
the class AWSUtils method waitForTransitionCompletion.
public static void waitForTransitionCompletion(ServiceHost host, List<InstanceStateChange> stateChangeList, final String desiredState, AmazonEC2AsyncClient client, BiConsumer<InstanceState, Exception> callback) {
InstanceStateChange stateChange = stateChangeList.get(0);
try {
DescribeInstancesRequest request = new DescribeInstancesRequest();
request.withInstanceIds(stateChange.getInstanceId());
DescribeInstancesResult result = client.describeInstances(request);
Instance instance = result.getReservations().stream().flatMap(r -> r.getInstances().stream()).filter(i -> i.getInstanceId().equalsIgnoreCase(stateChange.getInstanceId())).findFirst().orElseThrow(() -> new IllegalArgumentException(String.format("%s instance not found", stateChange.getInstanceId())));
String state = instance.getState().getName();
if (state.equals(desiredState)) {
callback.accept(instance.getState(), null);
} else {
host.schedule(() -> waitForTransitionCompletion(host, stateChangeList, desiredState, client, callback), 5, TimeUnit.SECONDS);
}
} catch (AmazonServiceException | IllegalArgumentException ase) {
callback.accept(null, ase);
}
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.
the class TestAWSSetupUtils method checkInstancesStarted.
/**
* Checks if all the instances represented by the list of passed in instanceIds have been turned
* ON.
*
* @return
*/
public static void checkInstancesStarted(VerificationHost host, AmazonEC2AsyncClient client, List<String> instanceIds, List<Boolean> provisioningFlags) throws Throwable {
AWSEnumerationAsyncHandler enumerationHandler = new AWSEnumerationAsyncHandler(host, AWSEnumerationAsyncHandler.MODE.CHECK_START, provisioningFlags, null, null, null, null);
DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceIds);
client.describeInstancesAsync(request, enumerationHandler);
host.waitFor("Waiting to get response from AWS ", () -> {
return enumerationHandler.responseReceived;
});
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.
the class TestAWSSetupUtils method checkInstancesDeleted.
/**
* Checks if a newly deleted instance has its status set to terminated.
*
* @return
*/
public static void checkInstancesDeleted(AmazonEC2AsyncClient client, VerificationHost host, List<String> instanceIdsToDelete, ArrayList<Boolean> deletionFlags) throws Throwable {
AWSEnumerationAsyncHandler enumerationHandler = new AWSEnumerationAsyncHandler(host, AWSEnumerationAsyncHandler.MODE.CHECK_TERMINATION, null, deletionFlags, null, null, null);
DescribeInstancesRequest request = new DescribeInstancesRequest().withInstanceIds(instanceIdsToDelete);
client.describeInstancesAsync(request, enumerationHandler);
// Waiting to get a response from AWS before the state computation is done for the list of
// VMs.
host.waitFor("Waiting to get response from AWS ", () -> {
return enumerationHandler.responseReceived;
});
}
use of software.amazon.awssdk.services.ec2.model.DescribeInstancesRequest in project photon-model by vmware.
the class TestAWSSetupUtils method getBaseLineInstanceCount.
/**
* Gets the instance count of non-terminated instances on the AWS endpoint. This is used to run
* the asserts and validate the results for the data that is collected during enumeration.This
* also calculates the compute descriptions that will be used to represent the instances that
* were discovered on the AWS endpoint. Further factoring in the
*
* @throws Throwable
*/
public static BaseLineState getBaseLineInstanceCount(VerificationHost host, AmazonEC2AsyncClient client, List<String> testComputeDescriptions) throws Throwable {
BaseLineState baseLineState = new BaseLineState();
AWSEnumerationAsyncHandler enumerationHandler = new AWSEnumerationAsyncHandler(host, AWSEnumerationAsyncHandler.MODE.GET_COUNT, null, null, null, testComputeDescriptions, baseLineState);
DescribeInstancesRequest request = new DescribeInstancesRequest();
Filter runningInstanceFilter = getAWSNonTerminatedInstancesFilter();
request.getFilters().add(runningInstanceFilter);
client.describeInstancesAsync(request, enumerationHandler);
host.waitFor("Error waiting to get base line instance count from AWS in test ", () -> {
return baseLineState.isCountPopulated;
});
return baseLineState;
}
Aggregations