com.amazonaws.services.ec2.model.DescribeVolumesResult Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.DescribeVolumesResult.
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 |
@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 |
/** * 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 |
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 |
@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 |
@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 |
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: InventoryUtilTest.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch volumet info test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchVolumetInfoTest() throws Exception { mockStatic(AmazonEC2ClientBuilder.class); AmazonEC2 ec2Client = PowerMockito.mock(AmazonEC2.class); AmazonEC2ClientBuilder amazonEC2ClientBuilder = PowerMockito.mock(AmazonEC2ClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonEC2ClientBuilder.standard()).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.withCredentials(anyObject())).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.withRegion(anyString())).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.build()).thenReturn(ec2Client); DescribeVolumesResult describeVolumesResult = new DescribeVolumesResult(); List<Volume> volumeList = new ArrayList<>(); volumeList.add(new Volume()); describeVolumesResult.setVolumes(volumeList); when(ec2Client.describeVolumes()).thenReturn(describeVolumesResult); assertThat(inventoryUtil.fetchVolumetInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
Example #8
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch volumet info. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @param accountName the account name * @return the map */ public static Map<String,List<Volume>> fetchVolumetInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<Volume>> volumeList = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"Volume\" , \"region\":\"" ; for(Region region : RegionUtils.getRegions()){ try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); DescribeVolumesResult rslt = ec2Client.describeVolumes(); // No need to paginate as all volumes will be returned. List<Volume> volumeListTemp = rslt.getVolumes(); if( !volumeListTemp.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : Volume "+region.getName() + " >> "+volumeListTemp.size()); volumeList.put(accountId+delimiter+accountName+delimiter+region.getName(),volumeListTemp); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"volume",e.getMessage()); } } return volumeList; }
Example #9
Source File: PacmanEc2UtilsTest.java From pacbot with Apache License 2.0 | 6 votes |
@SuppressWarnings("static-access") @Test public void collectAllVolumesTest() throws Exception { Volume vol = new Volume(); vol.setVolumeId("123"); Collection<Volume> volumes = new ArrayList<>(); volumes.add(vol); DescribeVolumesResult result = new DescribeVolumesResult(); result.setVolumes(volumes); when(ec2ServiceClient.describeVolumes(anyObject())).thenReturn(result); assertThat(pacmanEc2Utils.collectAllVolumes(ec2ServiceClient,describeVolumesRequest),is(notNullValue())); }
Example #10
Source File: Ec2MachineConfigurator.java From roboconf-platform with Apache License 2.0 | 5 votes |
/** * 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 #11
Source File: AwsVolumeResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
private ResourceStatus getResourceStatus(DescribeVolumesResult result) { try { return result.getVolumes().stream() .peek(volume -> LOGGER.debug("State of volume {} is {}", volume.getVolumeId(), volume.getState())) .map(com.amazonaws.services.ec2.model.Volume::getState) .map(toResourceStatus()) .reduce(ResourceStatus.ATTACHED, resourceStatusReducer()); } catch (AmazonEC2Exception e) { if ("InvalidVolume.NotFound".equals(e.getErrorCode())) { return ResourceStatus.DELETED; } return ResourceStatus.FAILED; } }
Example #12
Source File: PacmanEc2Utils.java From pacbot with Apache License 2.0 | 5 votes |
/** * * @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 #13
Source File: Ec2Utils.java From pacbot with Apache License 2.0 | 5 votes |
/** * 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 #14
Source File: AwsRepairTest.java From cloudbreak with Apache License 2.0 | 5 votes |
private void upscaleStack() throws Exception { AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext(); CloudStack stack = componentTestUtil.getStack(InstanceStatus.CREATE_REQUESTED, InstanceStatus.STARTED); List<CloudResource> cloudResources = List.of( CloudResource.builder() .name(AWS_SUBNET_ID) .type(ResourceType.AWS_SUBNET) .build(), createVolumeResource(VOLUME_ID_1, INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1, CommonStatus.DETACHED), createVolumeResource(VOLUME_ID_2, INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2, CommonStatus.DETACHED), createVolumeResource(VOLUME_ID_3, INSTANCE_ID_3, SIZE_DISK_2, FSTAB_2, CommonStatus.CREATED)); InMemoryStateStore.putStack(1L, PollGroup.POLLABLE); when(amazonCloudFormationRetryClient.describeStackResource(any())) .thenReturn(new DescribeStackResourceResult() .withStackResourceDetail(new StackResourceDetail().withPhysicalResourceId(AUTOSCALING_GROUP_NAME))); when(amazonAutoScalingRetryClient.describeAutoScalingGroups(any())) .thenReturn(new DescribeAutoScalingGroupsResult() .withAutoScalingGroups(new AutoScalingGroup() .withAutoScalingGroupName(AUTOSCALING_GROUP_NAME) .withInstances(List.of( new Instance().withInstanceId(INSTANCE_ID_1).withLifecycleState(LifecycleState.InService), new Instance().withInstanceId(INSTANCE_ID_2).withLifecycleState(LifecycleState.InService))) )); when(amazonEC2Client.describeVolumes(any())) .thenReturn(new DescribeVolumesResult().withVolumes( new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_1).withState(VolumeState.Available), new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_2).withState(VolumeState.Available), new com.amazonaws.services.ec2.model.Volume().withVolumeId(VOLUME_ID_3).withState(VolumeState.InUse) )); when(amazonEC2Client.describeInstances(any())).thenReturn( new DescribeInstancesResult().withReservations( new Reservation().withInstances(new com.amazonaws.services.ec2.model.Instance().withInstanceId("i-instance"))) ); AmazonEC2Waiters waiters = mock(AmazonEC2Waiters.class); when(amazonEC2Client.waiters()).thenReturn(waiters); Waiter<DescribeInstancesRequest> instanceWaiter = mock(Waiter.class); when(waiters.instanceRunning()).thenReturn(instanceWaiter); when(amazonAutoScalingClient.waiters()).thenReturn(asWaiters); when(asWaiters.groupInService()).thenReturn(describeAutoScalingGroupsRequestWaiter); underTest.upscale(authenticatedContext, stack, cloudResources); verify(amazonAutoScalingRetryClient).resumeProcesses(argThat(argument -> AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && argument.getScalingProcesses().contains("Launch"))); verify(amazonAutoScalingRetryClient).updateAutoScalingGroup(argThat(argument -> { Group workerGroup = stack.getGroups().get(1); return AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && workerGroup.getInstancesSize().equals(argument.getMaxSize()) && workerGroup.getInstancesSize().equals(argument.getDesiredCapacity()); })); verify(amazonAutoScalingRetryClient, times(stack.getGroups().size())) .suspendProcesses(argThat(argument -> AUTOSCALING_GROUP_NAME.equals(argument.getAutoScalingGroupName()) && SUSPENDED_PROCESSES.equals(argument.getScalingProcesses()))); ArgumentCaptor<CloudResource> updatedCloudResourceArgumentCaptor = ArgumentCaptor.forClass(CloudResource.class); verify(resourceNotifier, times(4)).notifyUpdate(updatedCloudResourceArgumentCaptor.capture(), any()); assertVolumeResource(updatedCloudResourceArgumentCaptor.getAllValues(), INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1); assertVolumeResource(updatedCloudResourceArgumentCaptor.getAllValues(), INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2); }
Example #15
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * 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 #16
Source File: EbsTableProvider.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
/** * 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 #17
Source File: VolumeImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public boolean load(DescribeVolumesRequest request, ResultCapture<DescribeVolumesResult> extractor) { return resource.load(request, extractor); }
Example #18
Source File: AmazonEc2RetryClient.java From cloudbreak with Apache License 2.0 | 4 votes |
public DescribeVolumesResult describeVolumes(DescribeVolumesRequest request) { return retry.testWith2SecDelayMax15Times(() -> mapThrottlingError(() -> client.describeVolumes(request))); }
Example #19
Source File: AwsRepairTest.java From cloudbreak with Apache License 2.0 | 4 votes |
private void downscaleStack() throws IOException { when(amazonEC2Client.describeVolumes(any())) .thenReturn(new DescribeVolumesResult(). withVolumes(new com.amazonaws.services.ec2.model.Volume() .withVolumeId(VOLUME_ID_1) .withState(VolumeState.InUse), new com.amazonaws.services.ec2.model.Volume() .withVolumeId(VOLUME_ID_2) .withState(VolumeState.InUse) )); when(amazonCloudFormationRetryClient.describeStackResource(any())) .thenReturn(new DescribeStackResourceResult() .withStackResourceDetail(new StackResourceDetail().withPhysicalResourceId(AUTOSCALING_GROUP_NAME))); when(amazonEC2Client.describeInstances(any())) .thenReturn(new DescribeInstancesResult().withReservations(new Reservation().withInstances(List.of()))); AmazonEC2Waiters mockWaiter = mock(AmazonEC2Waiters.class); when(amazonEC2Client.waiters()) .thenReturn(mockWaiter); when(mockWaiter.instanceTerminated()) .thenReturn(mock(Waiter.class)); List<Volume> volumes = List.of(); InstanceTemplate instanceTemplate = new InstanceTemplate("", WORKER_GROUP, 0L, volumes, InstanceStatus.STARTED, Map.of(), 0L, IMAGE_ID); InstanceAuthentication authentication = new InstanceAuthentication("publicKey", "publicKeyId", "cloudbreak"); CloudInstance firstCloudInstance = new CloudInstance(INSTANCE_ID_1, instanceTemplate, authentication); CloudInstance secondCloudInstance = new CloudInstance(INSTANCE_ID_2, instanceTemplate, authentication); List<CloudInstance> cloudInstancesToRemove = List.of(firstCloudInstance, secondCloudInstance); CloudResource instance1VolumeResource = createVolumeResource(VOLUME_ID_1, INSTANCE_ID_1, SIZE_DISK_1, FSTAB_1, CommonStatus.CREATED); CloudResource instance2VolumeResource = createVolumeResource(VOLUME_ID_2, INSTANCE_ID_2, SIZE_DISK_2, FSTAB_2, CommonStatus.CREATED); List<CloudResource> resources = List.of(instance1VolumeResource, instance2VolumeResource); AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext(); CloudStack cloudStack = componentTestUtil.getStack(InstanceStatus.DELETE_REQUESTED, InstanceStatus.CREATE_REQUESTED); underTest.downscale(authenticatedContext, cloudStack, resources, cloudInstancesToRemove, null); verify(persistenceNotifier).notifyUpdate(argThat(cloudResource -> ResourceType.AWS_VOLUMESET.equals(cloudResource.getType()) && VOLUME_ID_1.equals(cloudResource.getName()) && INSTANCE_ID_1.equals(cloudResource.getInstanceId()) && CommonStatus.DETACHED.equals(cloudResource.getStatus()) && cloudResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class).getDeleteOnTermination()), eq(authenticatedContext.getCloudContext())); verify(persistenceNotifier).notifyUpdate(argThat(cloudResource -> ResourceType.AWS_VOLUMESET.equals(cloudResource.getType()) && VOLUME_ID_2.equals(cloudResource.getName()) && INSTANCE_ID_2.equals(cloudResource.getInstanceId()) && CommonStatus.DETACHED.equals(cloudResource.getStatus()) && cloudResource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class).getDeleteOnTermination()), eq(authenticatedContext.getCloudContext())); verify(amazonAutoScalingRetryClient).detachInstances(argThat(argument -> argument.getAutoScalingGroupName().equals(AUTOSCALING_GROUP_NAME) && argument.getShouldDecrementDesiredCapacity() && argument.getInstanceIds().size() == 2 && argument.getInstanceIds().contains(INSTANCE_ID_1) && argument.getInstanceIds().contains(INSTANCE_ID_2) )); verify(amazonEC2Client).terminateInstances(argThat(argument -> argument.getInstanceIds().size() == 2 && argument.getInstanceIds().contains(INSTANCE_ID_1) && argument.getInstanceIds().contains(INSTANCE_ID_2))); verify(amazonAutoScalingRetryClient).updateAutoScalingGroup(argThat(argument -> argument.getAutoScalingGroupName().equals(AUTOSCALING_GROUP_NAME) && argument.getMaxSize().equals(1))); }
Example #20
Source File: Volume.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * 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);