use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class TestAWSSetupUtils method stopVMsUsingEC2Client.
/**
* Stop instances on the AWS endpoint for the set of instance Ids that are passed in.
*
* @param client
* @param host
* @param instanceIdsToStop
* @throws Throwable
*/
public static void stopVMsUsingEC2Client(AmazonEC2AsyncClient client, VerificationHost host, List<String> instanceIdsToStop) throws Throwable {
StopInstancesRequest stopRequest = new StopInstancesRequest(instanceIdsToStop);
AsyncHandler<StopInstancesRequest, StopInstancesResult> stopHandler = new AWSStopHandlerAsync(host);
client.stopInstancesAsync(stopRequest, stopHandler);
waitForInstancesToBeStopped(client, host, instanceIdsToStop);
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient 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 com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class TestAWSSetupUtils method provisionAWSVMWithEC2Client.
/**
* Method to directly provision instances on the AWS endpoint without the knowledge of the local
* system. This is used to spawn instances and to test that the discovery of items not
* provisioned by Xenon happens correctly.
*
* @throws Throwable
*/
public static List<String> provisionAWSVMWithEC2Client(AmazonEC2AsyncClient client, VerificationHost host, int numberOfInstance, String instanceType, String subnetId, String securityGroupId) throws Throwable {
host.log("Provisioning %d instances on the AWS endpoint using the EC2 client.", numberOfInstance);
RunInstancesRequest runInstancesRequest = new RunInstancesRequest().withSubnetId(subnetId).withImageId(EC2_LINUX_AMI).withInstanceType(instanceType).withMinCount(numberOfInstance).withMaxCount(numberOfInstance).withSecurityGroupIds(securityGroupId);
// handler invoked once the EC2 runInstancesAsync commands completes
AWSRunInstancesAsyncHandler creationHandler = new AWSRunInstancesAsyncHandler(host);
client.runInstancesAsync(runInstancesRequest, creationHandler);
host.waitFor("Waiting for instanceIds to be returned from AWS", () -> {
return checkInstanceIdsReturnedFromAWS(numberOfInstance, creationHandler.instanceIds);
});
return creationHandler.instanceIds;
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient 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 com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class TestAWSSetupUtils method getAwsDisksByIds.
/**
* Method to get Disk details directly from Amazon
*/
public static List<Volume> getAwsDisksByIds(AmazonEC2AsyncClient client, VerificationHost host, List<String> diskIds) throws Throwable {
try {
host.log("Getting disks with ids " + diskIds + " from the AWS endpoint using the EC2 client.");
DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest().withVolumeIds(diskIds);
DescribeVolumesResult describeVolumesResult = client.describeVolumes(describeVolumesRequest);
return describeVolumesResult.getVolumes();
} catch (Exception e) {
if (e instanceof AmazonEC2Exception && ((AmazonEC2Exception) e).getErrorCode().equalsIgnoreCase(AWS_INVALID_VOLUME_ID_ERROR_CODE)) {
return null;
}
}
return new ArrayList<>();
}
Aggregations