Search in sources :

Example 6 with DescribeVolumesRequest

use of com.amazonaws.services.ec2.model.DescribeVolumesRequest in project photon-model by vmware.

the class AWSTaskStatusChecker method runSearch.

private void runSearch(T type) {
    AmazonWebServiceRequest descRequest = buildRequest(type);
    AsyncHandler describeHandler = buildHandler(type);
    if (type instanceof Instance) {
        this.amazonEC2Client.describeInstancesAsync((DescribeInstancesRequest) descRequest, describeHandler);
    } else if (type instanceof NatGateway) {
        this.amazonEC2Client.describeNatGatewaysAsync((DescribeNatGatewaysRequest) descRequest, describeHandler);
    } else if (type instanceof Volume) {
        this.amazonEC2Client.describeVolumesAsync((DescribeVolumesRequest) descRequest, describeHandler);
    } else {
        AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(new IllegalArgumentException("Invalid type " + type));
    }
}
Also used : AsyncHandler(com.amazonaws.handlers.AsyncHandler) Instance(com.amazonaws.services.ec2.model.Instance) Volume(com.amazonaws.services.ec2.model.Volume) DescribeNatGatewaysRequest(com.amazonaws.services.ec2.model.DescribeNatGatewaysRequest) NatGateway(com.amazonaws.services.ec2.model.NatGateway) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest)

Example 7 with DescribeVolumesRequest

use of com.amazonaws.services.ec2.model.DescribeVolumesRequest 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<>();
}
Also used : ArrayList(java.util.ArrayList) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) UnknownHostException(java.net.UnknownHostException) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) TimeoutException(java.util.concurrent.TimeoutException) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception)

Example 8 with DescribeVolumesRequest

use of com.amazonaws.services.ec2.model.DescribeVolumesRequest in project photon-model by vmware.

the class TestAWSProvisionTask method getVolume.

protected Volume getVolume(AmazonEC2AsyncClient client, Instance awsInstance, String deviceName) {
    InstanceBlockDeviceMapping bootDiskMapping = awsInstance.getBlockDeviceMappings().stream().filter(blockDeviceMapping -> blockDeviceMapping.getDeviceName().equals(deviceName)).findAny().orElse(null);
    // The ami used in this test is an ebs-backed AMI
    assertNotNull("Device type should be ebs type", bootDiskMapping.getEbs());
    String bootVolumeId = bootDiskMapping.getEbs().getVolumeId();
    DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest().withVolumeIds(bootVolumeId);
    DescribeVolumesResult describeVolumesResult = client.describeVolumes(describeVolumesRequest);
    return describeVolumesResult.getVolumes().get(0);
}
Also used : InstanceBlockDeviceMapping(com.amazonaws.services.ec2.model.InstanceBlockDeviceMapping) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest)

Aggregations

DescribeVolumesRequest (com.amazonaws.services.ec2.model.DescribeVolumesRequest)6 DescribeVolumesResult (com.amazonaws.services.ec2.model.DescribeVolumesResult)5 Volume (com.amazonaws.services.ec2.model.Volume)3 DescribeNatGatewaysRequest (com.amazonaws.services.ec2.model.DescribeNatGatewaysRequest)2 Instance (com.amazonaws.services.ec2.model.Instance)2 NatGateway (com.amazonaws.services.ec2.model.NatGateway)2 ArrayList (java.util.ArrayList)2 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)1 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 CreateVolumeRequest (com.amazonaws.services.ec2.model.CreateVolumeRequest)1 CreateVolumeResult (com.amazonaws.services.ec2.model.CreateVolumeResult)1 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 Filter (com.amazonaws.services.ec2.model.Filter)1 InstanceBlockDeviceMapping (com.amazonaws.services.ec2.model.InstanceBlockDeviceMapping)1 AWSUtils.getAWSNonTerminatedInstancesFilter (com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getAWSNonTerminatedInstancesFilter)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1