com.amazonaws.services.ec2.model.DescribeVolumesRequest Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.DescribeVolumesRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EbsTableProviderTest.java    From aws-athena-query-federation with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUpRead()
{
    when(mockEc2.describeVolumes(any(DescribeVolumesRequest.class))).thenAnswer((InvocationOnMock invocation) -> {
        DescribeVolumesRequest request = (DescribeVolumesRequest) invocation.getArguments()[0];

        assertEquals(getIdValue(), request.getVolumeIds().get(0));
        DescribeVolumesResult mockResult = mock(DescribeVolumesResult.class);
        List<Volume> values = new ArrayList<>();
        values.add(makeVolume(getIdValue()));
        values.add(makeVolume(getIdValue()));
        values.add(makeVolume("fake-id"));
        when(mockResult.getVolumes()).thenReturn(values);
        return mockResult;
    });
}
 
Example #2
Source File: BaseTest.java    From aws-mock with MIT License 6 votes vote down vote up
/**
 * Describe All Volume.
 *
 * @return Collection Volume
 */
protected final List<Volume> getVolumes() {
    List<Volume> volumes = null;

    DescribeVolumesRequest req = new DescribeVolumesRequest();
    req.setMaxResults(20);
    DescribeVolumesResult result = amazonEC2Client.describeVolumes(req);
    if (result != null && !result.getVolumes().isEmpty()) {
        volumes = result.getVolumes();
        log.info("Page Size : " + volumes.size());
    }

    while(result.getNextToken() != null) { 
        req.setNextToken(result.getNextToken());
        result = amazonEC2Client.describeVolumes(req);
        if (result != null && !result.getVolumes().isEmpty()) {
             volumes = result.getVolumes();
             log.info("Page Size : " + volumes.size());
        }
    }
    
    return volumes;
}
 
Example #3
Source File: AwsLaunchTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private void setupDescribeVolumeResponse() {
    when(amazonEC2Client.describeVolumes(any())).thenAnswer(
            (Answer<DescribeVolumesResult>) invocation -> {
                DescribeVolumesResult describeVolumesResult = new DescribeVolumesResult();
                Object[] args = invocation.getArguments();
                DescribeVolumesRequest describeVolumesRequest = (DescribeVolumesRequest) args[0];
                VolumeState currentVolumeState = getCurrentVolumeState();
                describeVolumesRequest.getVolumeIds().forEach(
                        volume -> describeVolumesResult.withVolumes(
                                new com.amazonaws.services.ec2.model.Volume().withState(currentVolumeState)
                        )
                );
                return describeVolumesResult;
            }
    );
}
 
Example #4
Source File: AwsAttachmentResourceBuilder.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AwsContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {

    AmazonEc2RetryClient client = getAmazonEc2RetryClient(auth);
    List<CloudResource> volumeResources = StreamSupport.stream(resources.spliterator(), false)
            .filter(r -> r.getType().equals(resourceType()))
            .collect(Collectors.toList());
    List<String> volumeIds = volumeResources.stream()
            .map(volumeSetAttributes())
            .map(VolumeSetAttributes::getVolumes)
            .flatMap(List::stream)
            .map(VolumeSetAttributes.Volume::getId)
            .collect(Collectors.toList());

    if (volumeIds.isEmpty()) {
        return collectCloudResourceStatuses(volumeResources, ResourceStatus.CREATED);
    }

    DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest(volumeIds);
    DescribeVolumesResult result = client.describeVolumes(describeVolumesRequest);
    ResourceStatus volumeSetStatus = result.getVolumes().stream()
            .map(com.amazonaws.services.ec2.model.Volume::getState)
            .allMatch("in-use"::equals) ? ResourceStatus.CREATED : ResourceStatus.IN_PROGRESS;
    return collectCloudResourceStatuses(volumeResources, volumeSetStatus);
}
 
Example #5
Source File: AwsVolumeResourceBuilder.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AwsContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
    AmazonEc2RetryClient client = getAmazonEC2Client(auth);
    List<CloudResource> volumeResources = StreamSupport.stream(resources.spliterator(), false)
            .filter(r -> r.getType().equals(resourceType()))
            .collect(Collectors.toList());
    List<String> volumeIds = volumeResources.stream()
            .map(volumeSetAttributes())
            .map(VolumeSetAttributes::getVolumes)
            .flatMap(List::stream)
            .map(VolumeSetAttributes.Volume::getId)
            .collect(Collectors.toList());

    DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest(volumeIds);
    DescribeVolumesResult result = client.describeVolumes(describeVolumesRequest);
    ResourceStatus volumeSetStatus = getResourceStatus(result);
    LOGGER.debug("Reduced resource status for volume set is {}", volumeSetStatus);
    return volumeResources.stream()
            .map(resource -> new CloudResourceStatus(resource, volumeSetStatus))
            .collect(Collectors.toList());
}
 
Example #6
Source File: AwsCommonProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
public Volume describeVolume(AwsProcessClient awsProcessClient, String volumeId) {
    // 単一ボリュームの参照
    DescribeVolumesRequest request = new DescribeVolumesRequest();
    request.withVolumeIds(volumeId);
    DescribeVolumesResult result = awsProcessClient.getEc2Client().describeVolumes(request);
    List<Volume> volumes = result.getVolumes();

    // API実行結果チェック
    if (volumes.size() == 0) {
        // ボリュームが存在しない場合
        throw new AutoException("EPROCESS-000110", volumeId);

    } else if (volumes.size() > 1) {
        // ボリュームを複数参照できた場合
        AutoException exception = new AutoException("EPROCESS-000111", volumeId);
        exception.addDetailInfo("result=" + volumes);
        throw exception;
    }

    return volumes.get(0);
}
 
Example #7
Source File: Ec2MachineConfigurator.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether volume is created.
 * @param volumeId the EBS volume ID
 * @return true if volume created, false otherwise
 */
private boolean volumeCreated(String volumeId) {
	DescribeVolumesRequest dvs = new DescribeVolumesRequest();
	ArrayList<String> volumeIds = new ArrayList<String>();
	volumeIds.add(volumeId);
	dvs.setVolumeIds(volumeIds);
	DescribeVolumesResult dvsresult = null;
	try {
		dvsresult = this.ec2Api.describeVolumes(dvs);
	} catch(Exception e) {
		dvsresult = null;
	}

	return dvsresult != null && "available".equals(dvsresult.getVolumes().get(0).getState());
}
 
Example #8
Source File: EbsTableProvider.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
/**
 * Calls DescribeVolumes on the AWS EC2 Client returning all volumes that match the supplied predicate and attempting
 * to push down certain predicates (namely queries for specific volumes) to EC2.
 *
 * @See TableProvider
 */
@Override
public void readWithConstraint(BlockSpiller spiller, ReadRecordsRequest recordsRequest, QueryStatusChecker queryStatusChecker)
{
    boolean done = false;
    DescribeVolumesRequest request = new DescribeVolumesRequest();

    ValueSet idConstraint = recordsRequest.getConstraints().getSummary().get("id");
    if (idConstraint != null && idConstraint.isSingleValue()) {
        request.setVolumeIds(Collections.singletonList(idConstraint.getSingleValue().toString()));
    }

    while (!done) {
        DescribeVolumesResult response = ec2.describeVolumes(request);

        for (Volume volume : response.getVolumes()) {
            logger.info("readWithConstraint: {}", response);
            instanceToRow(volume, spiller);
        }

        request.setNextToken(response.getNextToken());

        if (response.getNextToken() == null || !queryStatusChecker.isQueryRunning()) {
            done = true;
        }
    }
}
 
Example #9
Source File: BaseTest.java    From aws-mock with MIT License 5 votes vote down vote up
/**
 * Describe Volume.
 *
 * @return Volume
 */
protected final Volume getVolume() {
    Volume volume = null;

    DescribeVolumesRequest req = new DescribeVolumesRequest();
    DescribeVolumesResult result = amazonEC2Client.describeVolumes(req);
    if (result != null && !result.getVolumes().isEmpty()) {
        volume = result.getVolumes().get(0);
    }

    return volume;
}
 
Example #10
Source File: Ec2Utils.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Collect all volumes.
 *
 * @param ec2ServiceClient the ec 2 service client
 * @param region the region
 * @return the list
 */
public static List<Volume> collectAllVolumes(AmazonEC2 ec2ServiceClient,Region region){
	DescribeVolumesRequest request = new DescribeVolumesRequest();
	DescribeVolumesResult result;
	String nextToken;
	List<Volume> volumes=new ArrayList<Volume>();
	do{
		result = ec2ServiceClient.describeVolumes(request);
		volumes.addAll(result.getVolumes());
		nextToken = result.getNextToken();
	    request.setNextToken(nextToken);
	}while(null!=nextToken);
	return volumes;
}
 
Example #11
Source File: PacmanEc2Utils.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param ec2ServiceClient
 * @param request
 * @return
 */
public static List<Volume> collectAllVolumes(AmazonEC2 ec2ServiceClient,
        DescribeVolumesRequest request) {
    DescribeVolumesResult result;
    String nextToken;
    List<Volume> volumes = new ArrayList<>();
    do {
        result = ec2ServiceClient.describeVolumes(request);
        volumes.addAll(result.getVolumes());
        nextToken = result.getNextToken();
        request.setNextToken(nextToken);
    } while (null != nextToken);
    return volumes;
}
 
Example #12
Source File: EC2Impl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public VolumeCollection getVolumes(DescribeVolumesRequest request) {
    ResourceCollectionImpl result = service.getCollection("Volumes",
            request);

    if (result == null) return null;
    return new VolumeCollectionImpl(result);
}
 
Example #13
Source File: InstanceImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public VolumeCollection getVolumes(DescribeVolumesRequest request) {
    ResourceCollectionImpl result = resource.getCollection("Volumes",
            request);

    if (result == null) return null;
    return new VolumeCollectionImpl(result);
}
 
Example #14
Source File: EC2Impl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public VolumeCollection getVolumes() {
    return getVolumes((DescribeVolumesRequest)null);
}
 
Example #15
Source File: PacmanEc2UtilsTest.java    From pacbot with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception{
    ec2ServiceClient = PowerMockito.mock(AmazonEC2.class); 
    describeVolumesRequest = PowerMockito.mock(DescribeVolumesRequest.class); 
    describeFlowLogsRequest = PowerMockito.mock(DescribeFlowLogsRequest.class); 
}
 
Example #16
Source File: VolumeImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public boolean load(DescribeVolumesRequest request,
        ResultCapture<DescribeVolumesResult> extractor) {

    return resource.load(request, extractor);
}
 
Example #17
Source File: AmazonEc2RetryClient.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public DescribeVolumesResult describeVolumes(DescribeVolumesRequest request) {
    return retry.testWith2SecDelayMax15Times(() -> mapThrottlingError(() -> client.describeVolumes(request)));
}
 
Example #18
Source File: EncryptedSnapshotService.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private void checkEbsVolumeStatus(AuthenticatedContext ac, AmazonEC2Client client, String volumeId) {
    Waiter<DescribeVolumesRequest> volumeChecker = client.waiters().volumeAvailable();
    DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest().withVolumeIds(volumeId);
    StackCancellationCheck stackCancellationCheck = new StackCancellationCheck(ac.getCloudContext().getId());
    run(volumeChecker, describeVolumesRequest, stackCancellationCheck);
}
 
Example #19
Source File: VolumeImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public boolean load(DescribeVolumesRequest request) {
    return load(request, null);
}
 
Example #20
Source File: Volume.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Makes a call to the service to load this resource's attributes if they
 * are not loaded yet.
 * The following request parameters will be populated from the data of this
 * <code>Volume</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>VolumeIds.0</code></b>
 *         - mapped from the <code>Id</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return Returns {@code true} if the resource is not yet loaded when this
 *         method was invoked, which indicates that a service call has been
 *         made to retrieve the attributes.
 * @see DescribeVolumesRequest
 */
boolean load(DescribeVolumesRequest request);
 
Example #21
Source File: Volume.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Makes a call to the service to load this resource's attributes if they
 * are not loaded yet, and use a ResultCapture to retrieve the low-level
 * client response
 * The following request parameters will be populated from the data of this
 * <code>Volume</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>VolumeIds.0</code></b>
 *         - mapped from the <code>Id</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return Returns {@code true} if the resource is not yet loaded when this
 *         method was invoked, which indicates that a service call has been
 *         made to retrieve the attributes.
 * @see DescribeVolumesRequest
 */
boolean load(DescribeVolumesRequest request,
        ResultCapture<DescribeVolumesResult> extractor);
 
Example #22
Source File: EC2.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves the Volumes collection referenced by this resource.
 */
VolumeCollection getVolumes(DescribeVolumesRequest request);
 
Example #23
Source File: Instance.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieves the Volumes collection referenced by this resource.
 */
VolumeCollection getVolumes(DescribeVolumesRequest request);