Java 类com.amazonaws.services.ec2.model.Volume 实例源码

项目:aws-auto-operations-using-lambda    文件:EBSSnapshotFunction.java   
public void createSnapshotFromTagName(TagNameRequest tagNameRequest, Context context) {

        LambdaLogger logger = context.getLogger();
        logger.log("create ebs snapshot from tag name Start. backup target[" + tagNameRequest + "]");

        String regionName = System.getenv("AWS_DEFAULT_REGION");
        AmazonEC2Async client = RegionUtils.getRegion(regionName).createClient(AmazonEC2AsyncClient.class,
                new DefaultAWSCredentialsProviderChain(), cc);

        try {
            List<Volume> volumes = describeBackupVolumes(client, tagNameRequest);

            for (Volume volume : volumes) {
                createSnapshot(volume.getVolumeId(), tagNameRequest.getGenerationCount(), context);
            }
        } finally {
            client.shutdown();
        }
    }
项目:photon-model    文件:AWSTaskStatusChecker.java   
public void start(T type) {
    if (this.expirationTimeMicros > 0 && Utils.getNowMicrosUtc() > this.expirationTimeMicros) {
        String resource = "Compute";
        if (type instanceof Volume) {
            resource = "Volume";
        }

        String msg = String
                .format("%s with instance id %s did not reach desired %s state in the required time interval.",
                        resource, this.instanceId, this.desiredState);
        this.service.logSevere(() -> msg);
        this.taskManager.patchTaskToFailure(new RuntimeException(msg));
        return;
    }

    runSearch(type);
}
项目:photon-model    文件:AWSTaskStatusChecker.java   
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));
    }
}
项目:photon-model    文件:AWSEBSStorageEnumerationAdapterService.java   
/**
 * Method for mapping additionl properties in the EBS volume to the local diskstate. For e.g. snapshotID, iops,
 * encrypted etc.
 */
private void mapCustomProperties(DiskState diskState, Volume volume) {
    diskState.customProperties = new HashMap<>();
    if (volume.getSnapshotId() != null) {
        diskState.customProperties.put(SNAPSHOT_ID, volume.getSnapshotId());
    }
    if (volume.getIops() != null) {
        diskState.customProperties.put(DISK_IOPS, volume.getIops().toString());
    }
    if (volume.getEncrypted() != null) {
        diskState.customProperties.put(DISK_ENCRYPTED_FLAG,
                volume.getEncrypted().toString());
    }
    diskState.customProperties.put(VOLUME_TYPE,
            volume.getVolumeType());
    diskState.customProperties.put(SOURCE_TASK_LINK,
            ResourceEnumerationTaskService.FACTORY_LINK);
}
项目:photon-model    文件:TestProvisionAWSDisk.java   
/**
 * 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<>();
}
项目:photon-model    文件:TestAWSProvisionTask.java   
protected void assertBootDiskConfiguration(AmazonEC2AsyncClient client, Instance awsInstance,
        String diskLink) {
    DiskState diskState = getDiskState(diskLink);

    Volume bootVolume = getVolume(client, awsInstance, awsInstance.getRootDeviceName());

    assertEquals("Boot Disk capacity in diskstate is not matching the boot disk size of the "
            + "vm launched in aws", diskState.capacityMBytes, bootVolume.getSize() * 1024);

    assertEquals(
            "Boot disk type in diskstate is not same as the type of the volume attached to the VM",
            diskState.customProperties.get("volumeType"), bootVolume.getVolumeType());

    assertEquals(
            "Boot disk iops in diskstate is the same as the iops of the volume attached to the VM",
            Integer.parseInt(diskState.customProperties.get("iops")),
            bootVolume.getIops().intValue());

    assertEquals("Boot disk attach status is not matching", DiskService.DiskStatus.ATTACHED, diskState.status);
}
项目:photon-model    文件:TestAWSProvisionTask.java   
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);
}
项目:AWSConfig    文件:EC2UtilsImpl.java   
/**
 * This method returns all the volumes.
 * @return returns list of EBS volumes.
 */
public List<Volume> getAllEBSVolumes() throws AmazonClientException {

    List<Volume> allEBSVolumes;
    try {
        DescribeVolumesResult describeVolumesResult = this.amazonEc2.describeVolumes();
        allEBSVolumes = describeVolumesResult.getVolumes();

    } catch(AmazonClientException e) {
        System.out.println("ERROR : fetching volumes.");
        e.printStackTrace();
        throw e;
    }

    List<String> allVolumesIds = allEBSVolumes.stream().map(e -> e.getVolumeId()).collect(Collectors.toList());
    System.out.println("INFO : All Volumes Ids : " + allVolumesIds);
    return allEBSVolumes;
}
项目:AWSConfig    文件:EC2UtilsImpl.java   
/**
 * This method returns all encrypted EBS volumes.
 * @param allVolumes
 * @return returns list of all encrypted EBS volumes.
 */

public List<Volume> getAllEncryptedEBSVolumes(List<Volume> allEBSVolumes) {

    List<Volume> allEncryptedEBSVolumes = new ArrayList<Volume>();

    if ( allEBSVolumes != null || allEBSVolumes.size() > 0 ) {

        for(Volume volume : allEBSVolumes) {
            if( volume.isEncrypted()) {
                allEncryptedEBSVolumes.add(volume);
            }
        }

        List<String> allEncryptedVolumesIds = allEncryptedEBSVolumes.stream().map(e -> e.getVolumeId()).collect(Collectors.toList());
        System.out.println("INFO : All Encrypted EBS volumes : " + allEncryptedVolumesIds);
    }

    return allEncryptedEBSVolumes;
}
项目:AWSConfig    文件:EC2UtilsImpl.java   
/**
 * This method returns all EBS non root volumes.
 * @return 
 */
public List<Volume> getAllEBSNonRootVolumes(List<Volume> allEBSVolumes, List<Volume> allEBSRootVolumes) {

   List<Volume> allEBSNonRootVolumes = new ArrayList<>();

   if ( allEBSVolumes != null || allEBSVolumes.size() > 0 ) { 

        if (allEBSRootVolumes == null ) {
            allEBSRootVolumes = new ArrayList<>();
        }

        allEBSVolumes.removeAll(allEBSRootVolumes);
        allEBSNonRootVolumes = allEBSVolumes;
        List<String> allEBSNonRootVolumeIds = allEBSNonRootVolumes.stream().map(e -> e.getVolumeId()).collect(Collectors.toList());
        System.out.println("INFO : Number of EBS Non Root Volumes IDs : " + allEBSNonRootVolumeIds.size());
        System.out.println("INFO : EBS Non Root Volumes IDs : " + allEBSNonRootVolumeIds);

   }

   return allEBSNonRootVolumes;
}
项目:AWSConfig    文件:EC2UtilsImpl.java   
/**
 * This method returns list of EBS volumes which are available.
 * @return returns list of EBS volumes which are available.
 */
public List<Volume> getEBSVolumesAvailable(List<Volume> allEBSVolumes) {

    List<Volume> ebsVolumesAvailable = new ArrayList<>();

    for(Volume volume: allEBSVolumes) {
        if(volume.getState().equalsIgnoreCase(VolumeState.Available.toString())) {
            ebsVolumesAvailable.add(volume);
        }
    }

    System.out.println("INFO : Number of EBS volumes not in use : " + ebsVolumesAvailable.size());
    List<String> volumeIds = ebsVolumesAvailable.stream().map(e -> e.getVolumeId()).collect(Collectors.toList());
    System.out.println("INFO: EBS volumes not in use : " + volumeIds);

    return ebsVolumesAvailable;
}
项目:AWSConfig    文件:EBSVolumesAvailable.java   
/**
 * This method returns list of Evaluation objects.
 * @param ebsVolumesAvailable
 * @return List<Evaluation> returns list of Evaluation objects.
 */
private List<Evaluation> createEvaluations(List<Volume> ebsVolumesAvailable) {

    List<Evaluation> evaluations = new ArrayList<>();

    if ( ebsVolumesAvailable == null || ebsVolumesAvailable.size() > 0 ) {

        for(Volume volume: ebsVolumesAvailable) {

            String volumeId = volume.getVolumeId();
            Evaluation evaluation = new Evaluation();
            evaluation.setComplianceResourceId(volumeId);
            evaluation.setComplianceResourceType(COMPLIANCE_RESOURCE_TYPE);
            evaluation.setComplianceType(ComplianceType.NON_COMPLIANT);
            evaluation.setOrderingTimestamp(new Date());
            evaluations.add(evaluation);
        }
    }

    System.out.println("INFO : Number of evaluations : " + evaluations.size());
    return evaluations;
}
项目:AWSConfig    文件:NonEncryptedEBSVolumes.java   
/**
 * This method returns list of Evaluation objects.
 * @param allNonEncryptedVolumes
 * @return List<Evaluation> returns list of Evaluation objects.
 */
private List<Evaluation> createEvaluations(List<Volume> allNonEncryptedEBSVolumes) {

    List<Evaluation> evaluations = new ArrayList<>();

    if ( allNonEncryptedEBSVolumes == null || allNonEncryptedEBSVolumes.size() > 0 ) {

        for(Volume volume: allNonEncryptedEBSVolumes) {

            String volumeId = volume.getVolumeId();
            Evaluation evaluation = new Evaluation();
            evaluation.setComplianceResourceId(volumeId);
            evaluation.setComplianceResourceType(COMPLIANCE_RESOURCE_TYPE);
            evaluation.setComplianceType(ComplianceType.NON_COMPLIANT);
            evaluation.setOrderingTimestamp(new Date());
            evaluations.add(evaluation);
        }
    }

    System.out.println("INFO : Number of evaluations : " + evaluations.size());
    return evaluations;
}
项目:director-aws-plugin    文件:EC2Provider.java   
/**
 * Get EBS volumes attached to the specified virtual instance id.
 *
 * @return list of ebs volumes
 */
@VisibleForTesting
List<Volume> getVolumes(String virtualInstanceId) {
  String ec2InstanceId = getOnlyElement(
      getEC2InstanceIdsByVirtualInstanceId(
          Collections.singletonList(virtualInstanceId)
      ).values()
  );

  InstanceAttribute instanceAttribute =
      describeInstanceAttribute(ec2InstanceId, InstanceAttributeName.BlockDeviceMapping);
  List<InstanceBlockDeviceMapping> blockDeviceMappings =
      instanceAttribute.getBlockDeviceMappings();

  List<String> volumeIds = Lists.newArrayList();
  for (InstanceBlockDeviceMapping mapping : blockDeviceMappings) {
    volumeIds.add(mapping.getEbs().getVolumeId());
  }

  DescribeVolumesResult volumeResults = client.describeVolumes(
      new DescribeVolumesRequest().withVolumeIds(volumeIds)
  );

  return volumeResults.getVolumes();
}
项目:enhanced-snapshots    文件:AWSRestoreVolumeStrategyTaskExecutor.java   
private Volume creationTempVolumeStep(TaskEntry taskEntry, BackupEntry backupEntry) {
    checkThreadInterruption(taskEntry);
    setProgress(taskEntry, TaskProgress.CREATING_TEMP_VOLUME);
    Volume tempVolume;

    LOG.info("Used backup record: {}", backupEntry.getFileName());
    int size = Integer.parseInt(backupEntry.getSizeGiB());
    checkThreadInterruption(taskEntry);
    // creating temporary volume
    if (taskEntry.getTempVolumeType().equals(VolumeType.Io1.toString())) {
        tempVolume = awsCommunication.createIO1Volume(size, taskEntry.getTempVolumeIopsPerGb());
    } else {
        tempVolume = awsCommunication.createVolume(size, VolumeType.fromValue(taskEntry.getTempVolumeType()));
    }
    LOG.info("Created {} volume:{}", taskEntry.getTempVolumeType(), tempVolume.toString());
    checkThreadInterruption(taskEntry);
    awsCommunication.createTemporaryTag(tempVolume.getVolumeId(), backupEntry.getFileName());
    taskEntry.setTempVolumeId(tempVolume.getVolumeId());
    taskRepository.save(taskEntry);

    return tempVolume;
}
项目:enhanced-snapshots    文件:AbstractAWSVolumeTaskExecutor.java   
/**
 * Detach and delete temp volume
 *
 * @param tempVolume
 * @param dto notification transfer object
 */
protected void deleteTempVolume(Volume tempVolume, TaskProgressDto dto) {
    if (tempVolume != null && awsCommunication.volumeExists(tempVolume.getVolumeId())) {
        tempVolume = awsCommunication.syncVolume(tempVolume);
        if (tempVolume.getAttachments().size() != 0) {
            dto.setMessage("Detaching temp volume");
            dto.addProgress(10);
            notificationService.notifyAboutTaskProgress(dto);
            awsCommunication.detachVolume(tempVolume);
        }
        awsCommunication.deleteSnapshot(tempVolume.getSnapshotId());
        dto.setMessage("Deleting temp volume");
        dto.addProgress(10);
        notificationService.notifyAboutTaskProgress(dto);
        awsCommunication.deleteVolume(tempVolume);
    }
}
项目:enhanced-snapshots    文件:VolumeDtoConverter.java   
public static VolumeDto convert(Volume volume) {
    VolumeDto volumeDto = new VolumeDto();
    BeanUtils.copyProperties(volume, volumeDto);
    List<Tag> tags = new ArrayList<>();
    for (Tag tag : volume.getTags()) {
        // check whether volume has Name tag
        if (tag.getKey().equals("Name")) {
            volumeDto.setVolumeName(tag.getValue());
        } else {
            tags.add(tag);
        }
    }
    volumeDto.setTags(tags);
    // check whether volume is attached to instance
    if (volume.getAttachments().size() > 0) {
        volumeDto.setInstanceID(volume.getAttachments().get(0).getInstanceId());
    }
    return volumeDto;
}
项目:enhanced-snapshots    文件:VolumeDtoConverterTest.java   
@Test
public void convertVolumeToVolumeDto() {
    // convert volume without attachments
    Volume volume = createVolume(VOLUME_ID, SNAPSHOT_ID, CREATE_TIME, AVAILABILITY_ZONE, SIZE, STATE, tags, null);
    VolumeDto volumeDto = VolumeDtoConverter.convert(volume);
    assertVolumeDtoFields(volumeDto, VOLUME_ID, SNAPSHOT_ID, CREATE_TIME, AVAILABILITY_ZONE, SIZE, STATE, tags, null);

    // convert attached volume
    volume = createVolume(VOLUME_ID, SNAPSHOT_ID, CREATE_TIME, AVAILABILITY_ZONE, SIZE, STATE, tags, INSTANCE_ID);
    volumeDto = VolumeDtoConverter.convert(volume);
    assertVolumeDtoFields(volumeDto, VOLUME_ID, SNAPSHOT_ID, CREATE_TIME, AVAILABILITY_ZONE, SIZE, STATE, tags, INSTANCE_ID);

    // add field to volume that is missing in VolumeDto object
    volume.setVolumeType(VOLUME_TYPE);
    Assert.assertTrue(volumeDto.equals(VolumeDtoConverter.convert(volume)));
}
项目:enhanced-snapshots    文件:VolumeDtoConverterTest.java   
@Test
public void convertVolumeList() {
    List<Volume> volumeList = new ArrayList<>();
    //with tags
    volumeList.add(createVolume(VOLUME_ID, SNAPSHOT_ID, CREATE_TIME, AVAILABILITY_ZONE, SIZE, STATE, tags, INSTANCE_ID));

    // without tags
    volumeList.add(createVolume(VOLUME_ID + "_", SNAPSHOT_ID + "_", CREATE_TIME, AVAILABILITY_ZONE + "_",
            SIZE + 1, STATE + "_", new ArrayList<Tag>(), INSTANCE_ID + "_"));

    Set<VolumeDto> volumeDtoList = VolumeDtoConverter.convert(volumeList);
    Assert.assertTrue(volumeDtoList.size() == 2);
    assertVolumeDtoFields((VolumeDto) volumeDtoList.toArray()[0], VOLUME_ID, SNAPSHOT_ID, CREATE_TIME, AVAILABILITY_ZONE, SIZE, STATE, tags, INSTANCE_ID);
    assertVolumeDtoFields((VolumeDto) volumeDtoList.toArray()[1], VOLUME_ID + "_", SNAPSHOT_ID + "_", CREATE_TIME, AVAILABILITY_ZONE + "_",
            SIZE + 1, STATE + "_", new ArrayList<Tag>(), INSTANCE_ID + "_");
}
项目:enhanced-snapshots    文件:VolumeDtoConverterTest.java   
private Volume createVolume(String volId, String snapId, Date createDate, String zone, int size, String state, List<Tag> tags, String instance_id) {
    Volume volume = new Volume();
    volume.setVolumeId(volId);
    volume.setSnapshotId(snapId);
    volume.setCreateTime(createDate);
    volume.setAvailabilityZone(zone);
    volume.setState(state);
    volume.setSize(size);
    volume.setTags(tags);
    if (instance_id != null) {
        List<VolumeAttachment> volumeAttachmentList = new ArrayList();
        VolumeAttachment volumeAttachment = new VolumeAttachment();
        volumeAttachment.setInstanceId(instance_id);
        volumeAttachmentList.add(volumeAttachment);
        volume.setAttachments(volumeAttachmentList);
    }
    return volume;
}
项目:primecloud-controller    文件:VolumeConverter.java   
@Override
protected Volume convertObject(VolumeInfo from) {
    Volume to = new Volume();

    to.setVolumeId(from.getVolumeId());

    Integer size = null;
    if (from.getSize() != null && from.getSize().length() != 0) {
        size = Integer.valueOf(from.getSize());
    }
    to.setSize(size);

    to.setSnapshotId(from.getSnapshotId());
    to.setAvailabilityZone(from.getZone());
    to.setState(from.getStatus());
    to.setCreateTime(from.getCreateTime().getTime());
    to.setAttachments(new VolumeAttachmentConverter().convert(from.getAttachmentInfo()));

    // 未実装
    to.setTags(null);

    return to;
}
项目:primecloud-controller    文件:AwsCommonProcess.java   
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);
}
项目:clouck    文件:Ec2Volume.java   
@Override
@SuppressWarnings("rawtypes")
protected boolean isEqual(AbstractResource newResource) {
    Volume oldVolume = this.getResource();
    Ec2Volume newEc2Volume = (Ec2Volume) newResource;
    Volume newVolume = (Volume) newResource.getResource();

    if (notEqual(oldVolume.getVolumeId(), newVolume.getVolumeId())) return false;
    if (notEqual(oldVolume.getSize(), newVolume.getSize())) return false;
    if (notEqual(oldVolume.getSnapshotId(), newVolume.getSnapshotId())) return false;
    if (notEqual(oldVolume.getAvailabilityZone(), newVolume.getAvailabilityZone())) return false;
    if (notEqual(oldVolume.getState(), newVolume.getState())) return false;
    if (notEqual(oldVolume.getCreateTime(), newVolume.getCreateTime())) return false;
    if (notEqualCollection(oldVolume.getAttachments(), newVolume.getAttachments())) return false;
    if (notEqualCollection(oldVolume.getTags(), newVolume.getTags())) return false;
    if (notEqual(oldVolume.getVolumeType(), newVolume.getVolumeType())) return false;
    if (notEqual(oldVolume.getIops(), newVolume.getIops())) return false;
    if (notEqual(this.getAutoEnableIO(), newEc2Volume.getAutoEnableIO())) return false;
    if (notEqualCollection(this.getProductCodes(), newEc2Volume.getProductCodes())) return false;

    return true;
}
项目:clouck    文件:Ec2VolumeComparator.java   
@Override
public Event add(Ec2Volume newResource) {
    Volume volume = newResource.getResource();
    String state = volume.getState();
    switch (state) {
    case "creating":
        return createEvent(null, newResource, EventType.Ec2_Volume_Creating);
    case "available":
    case "in-use":
        return createEvent(null, newResource, EventType.Ec2_Volume_Create);
    case "deleting":
        return createEvent(null, newResource, EventType.Ec2_Volume_Deleting);
    case "error":
        return createEvent(null, newResource, EventType.Ec2_Volume_Error);
    default:
        log.error("not handled instance state:{}", state);
        return createEvent(null, newResource, EventType.Unknown);
    }
}
项目:clouck    文件:Ec2VolumeComparator.java   
private void compareVolumeState(Collection<Event> result, Ec2Volume oldResource, Ec2Volume newResource) {
    Volume oldVolume = oldResource.getResource();
    Volume newVolume = newResource.getResource();
    String oldState = oldVolume.getState();
    String newState = newVolume.getState();
    if (equal(newState, oldState)) {
        return;
    }
    switch (newState) {
    case "deleting":
        result.add(createEvent(oldResource, newResource, EventType.Ec2_Volume_Deleting));
        break;
    case "creating":
    case "available":
    case "in-use":
    case "error":
        break;
    default:
        log.error("not handled volume state:{}", newState);
        result.add(createEvent(oldResource, newResource, EventType.Unknown));
    }
}
项目:clouck    文件:Ec2WrapperImpl.java   
@Override
public List<AbstractResource<?>> describeVolumes(Account account, Region region, DateTime dt, Ec2Filter... filters) {
    AmazonEC2 ec2 = findClient(account, region);

    DescribeVolumesRequest req = new DescribeVolumesRequest();
    for (Ec2Filter filter : filters) {
        Filter f = new Filter().withName(filter.getName()).withValues(filter.getValues());
        req.withFilters(f);
    }
    log.debug("start describing volumes for account:{} in region:{} via api", account.getId() + "=>" + account.getName(), region);
    DescribeVolumesResult res = ec2.describeVolumes(req);

    List<Boolean> autoEnableIOs = new ArrayList<>();
    List<List<ProductCode>> productCodes = new ArrayList<>();
    for (Volume volume : res.getVolumes()) {
        autoEnableIOs.add(findAutoEnableIO(account, region, volume.getVolumeId()));
        productCodes.add(findProductCodes(account, region, volume.getVolumeId()));
    }

    return converter.toEc2Volumes(res.getVolumes(), autoEnableIOs, productCodes, account.getId(), region, dt);
}
项目:aws-mock    文件:BaseTest.java   
/**
 * 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;
}
项目:aws-mock    文件:BaseTest.java   
/**
 * Create Volume.
 *
 * @param availabilityZone the availability zone
 * @param iops the iops
 * @param size the size
 * @param snapshotId the snapshot id
 * @param volumeType the volume type
 * @return Volume
 */
protected final Volume createVolume(final String availabilityZone, final Integer iops, final Integer size, final String snapshotId, final String volumeType) {
    Volume volume = null;

    CreateVolumeRequest req = new CreateVolumeRequest();
    req.setAvailabilityZone(availabilityZone);
    req.setIops(iops);
    req.setSize(size);
    req.setSnapshotId(snapshotId);
    req.setVolumeType(volumeType);

    CreateVolumeResult result = amazonEC2Client.createVolume(req);
    if (result != null) {
        volume = result.getVolume();
    }

    return volume;
}
项目:aws-auto-operations-using-lambda    文件:EBSSnapshotFunction.java   
List<Volume> describeBackupVolumes(AmazonEC2Async client, TagNameRequest target) {

        Filter tagKey = new Filter().withName("tag-key").withValues("Backup");
        Filter tagValue = new Filter().withName("tag-value").withValues(target.getTagName());
        DescribeVolumesRequest req = new DescribeVolumesRequest().withFilters(tagKey, tagValue);
        DescribeVolumesResult result = client.describeVolumes(req);

        return result.getVolumes();
    }
项目:photon-model    文件:AWSDiskService.java   
private Volume getMockVolume() {
    return new Volume()
            .withVolumeId("i-" + UUID.randomUUID())
            .withEncrypted(false)
            .withAvailabilityZone("")
            .withCreateTime(new Date());
}
项目:photon-model    文件:AWSDiskService.java   
private void startStatusChecker(AWSDiskContext context, String volumeId, String status, Consumer<Object> consumer) {

        Runnable proceed = () -> {
            AWSTaskStatusChecker
                    .create(context.client.client, volumeId, status, consumer, context.taskManager,
                            this, context.taskExpirationMicros)
                    .start(new Volume());
        };

        proceed.run();
    }
项目:photon-model    文件:AWSEBSStorageEnumerationAdapterService.java   
/**
 * Update newly identified tags for disk states based on volumes.
 */
private DeferredResult<EBSStorageEnumerationContext> updateTagLinks() {
    if (this.context.volumesToBeUpdated == null
            || this.context.volumesToBeUpdated.size() == 0) {

        return DeferredResult.completed(this.context);
    } else {

        List<DeferredResult<Set<String>>> updateCSTagLinksOps = new ArrayList<>();

        for (String volumeId : this.context.volumesToBeUpdated.keySet()) {
            if (!this.context.diskStatesToBeUpdated.containsKey(volumeId)) {
                continue; // this is not a disk to update
            }
            Volume volume = this.context.volumesToBeUpdated.get(volumeId);
            DiskState existingDiskState = this.context.diskStatesToBeUpdated
                    .get(volumeId);
            Map<String, String> remoteTags = new HashMap<>();
            for (Tag awsVolumeTag : volume.getTags()) {
                if (!awsVolumeTag.getKey().equals(AWSConstants.AWS_TAG_NAME)) {
                    remoteTags.put(awsVolumeTag.getKey(), awsVolumeTag.getValue());
                }
            }
            updateCSTagLinksOps.add(TagsUtil
                    .updateLocalTagStates(this.service, existingDiskState, remoteTags, null));
        }
        return DeferredResult.allOf(updateCSTagLinksOps).thenApply(gnore -> this.context);
    }
}
项目:photon-model    文件:AWSEBSStorageEnumerationAdapterService.java   
/**
 * This method determines if the given EBS volume is currently in "attached" OR "detached" state.
 * The given EBS volume has an "attachment" object associated with it in case the disk is
 * associated with any of the running instances on AWS.
 */
private void mapAttachmentState(DiskState diskState, Volume volume) {
    if (volume.getAttachments().size() > 0) {
        diskState.status = DiskStatus.ATTACHED;
        // TODO VSYM-2341 add logic to update the compute state to be linked to this
        // disk based on the list of attachments
    } else {
        diskState.status = DiskStatus.DETACHED;
    }
}
项目:photon-model    文件:AWSEBSStorageEnumerationAdapterService.java   
/**
 * The disk types available on AWS include
 * - gp2 = general purpose SSD
 * - io1 = provisioned SSD
 * - standard = Magnetic Disk
 * <p>
 * These are mapped to SSD or HDD in the local system.
 */
private void mapDiskType(DiskState diskState, Volume volume) {
    String volumeType = volume.getVolumeType();
    if (volumeType.equalsIgnoreCase(VOLUME_TYPE_GENERAL_PURPOSED_SSD)
            || (volumeType.equalsIgnoreCase(VOLUME_TYPE_PROVISIONED_SSD))) {
        diskState.type = DiskType.SSD;
    } else {
        diskState.type = DiskType.HDD;
    }
}
项目:photon-model    文件:AWSComputeDiskDay2Service.java   
private void startStatusChecker(DiskContext context, String volumeId, String status, Consumer<Object> consumer) {

        Runnable proceed = () -> {
            AWSTaskStatusChecker
                    .create(context.amazonEC2Client, volumeId, status, consumer, context.baseAdapterContext.taskManager,
                            this, context.taskExpirationMicros)
                    .start(new Volume());
        };

        proceed.run();
    }
项目:photon-model    文件:TestAWSSetupUtils.java   
/**
 * Return true if volumeId exists.
 */
public static boolean volumeIdExists(AmazonEC2AsyncClient client, String volumeId) {
    List<Volume> volumes = client.describeVolumes()
            .getVolumes()
            .stream()
            .filter(volume -> volume.getVolumeId().equals(volumeId))
            .collect(Collectors.toList());
    return volumes != null && !volumes.isEmpty();
}
项目:photon-model    文件:TestAWSProvisionTask.java   
protected void assertEbsDiskConfiguration(AmazonEC2AsyncClient client, Instance awsInstance,
        DiskState diskState) {
    assertNotNull("Additional Disk should contain atleast one custom property",
            diskState.customProperties);

    assertTrue("deviceName is missing from the custom properties", diskState
            .customProperties.containsKey(DEVICE_NAME));

    Volume volume = getVolume(client, awsInstance, diskState
            .customProperties.get(DEVICE_NAME));

    assertEquals(
            "Additional disk capacity in diskstate is not matching the volume size in aws",
            diskState.capacityMBytes, volume.getSize() * 1024);

    assertEquals(
            "Additional disk type in diskstate is not same as the type of the volume in aws",
            diskState.customProperties.get(VOLUME_TYPE), volume.getVolumeType());

    //assert encryption status
    assertEquals("Additional disk encryption status is not matching the "
                    + "actual encryption status of the disk on aws", diskState.encrypted,
            volume.getEncrypted());

    if (diskState.customProperties.containsKey(DISK_IOPS)) {
        int requestedIops = Integer.parseInt(diskState.customProperties.get(DISK_IOPS));
        int MAX_SUPPORTED_IOPS = (int) (diskState.capacityMBytes / 1024) * 50;
        int provisionedIops = Math.min(requestedIops, MAX_SUPPORTED_IOPS);
        assertEquals("Disk speeds are not matching", provisionedIops,
                volume.getIops().intValue());
    }

    assertEquals("Additional disk attach status is not matching",
            DiskService.DiskStatus.ATTACHED, diskState.status);
}
项目:AWSConfig    文件:EC2UtilsImpl.java   
/**
 * This method returns all EBS root volumes.
 * @return 
 */
public List<Volume> getAllEBSRootVolumes() {

    List<Instance> allInstances =  getAllInstances();
    List<Volume> allEBSRootVolumes = new ArrayList<>();

    for(Instance instance: allInstances) {

        //We need volumes of type only EBS.
        if ( instance.getRootDeviceType().equalsIgnoreCase(DeviceType.Ebs.toString())) {
            String rootDeviceName = instance.getRootDeviceName();
            List<InstanceBlockDeviceMapping> instanceBlockDeviceMappings = instance.getBlockDeviceMappings();
            for(InstanceBlockDeviceMapping instanceBlockDeviceMapping: instanceBlockDeviceMappings) {
                if(instanceBlockDeviceMapping.getDeviceName().equalsIgnoreCase(rootDeviceName)) {
                    String volumeId = instanceBlockDeviceMapping.getEbs().getVolumeId();
                    Volume volume = new Volume().withVolumeId(volumeId);
                    allEBSRootVolumes.add(volume);
                }
            }
        }
    }

    System.out.println("INFO: Number of EBS Root Volumes : " + allEBSRootVolumes.size());
    List<String> volumeIds = allEBSRootVolumes.stream().map(e -> e.getVolumeId()).collect(Collectors.toList());
    System.out.println("INFO: EBS Root Volumes : " + volumeIds);

    return allEBSRootVolumes;
}
项目:AWSConfig    文件:EC2UtilsImplTest.java   
@Test
public void testGetAllEBSVolumes() {
    Volume volume1 = new Volume();
    Volume volume2 = new Volume();
    DescribeVolumesResult describeVolumesResult = new DescribeVolumesResult();
    describeVolumesResult.setVolumes(Arrays.asList(volume1,volume2));
    AmazonEC2 amazonEc2 = mock(AmazonEC2Client.class);
    when(amazonEc2.describeVolumes()).thenReturn(describeVolumesResult);
    assertEquals(2,describeVolumesResult.getVolumes().size());
}
项目:AWSConfig    文件:EC2UtilsImplTest.java   
@Test
public void testGetAllEncryptedEBSVolumes() {

    EC2UtilsImpl ec2UtilsImpl = new EC2UtilsImpl();
    List<Volume> allEncryptedEBSVolumes = ec2UtilsImpl.getAllEncryptedEBSVolumes(allEBSVolumes);
    assertEquals(2,allEncryptedEBSVolumes.size());

}