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

The following examples show how to use com.amazonaws.services.ec2.model.CreateVolumeRequest. 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: EncryptedSnapshotService.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private CreateVolumeRequest prepareCreateVolumeRequest(AuthenticatedContext ac, AwsInstanceView awsInstanceView, AmazonEC2 client, CloudStack cloudStack) {
    String availabilityZone = prepareDescribeAvailabilityZonesResult(ac, client);

    TagSpecification tagSpecification = new TagSpecification()
            .withResourceType(com.amazonaws.services.ec2.model.ResourceType.Volume)
            .withTags(prepareTagList(ac, cloudStack, awsInstanceView));

    CreateVolumeRequest createVolumeRequest = new CreateVolumeRequest()
            .withSize(VOLUME_SIZE)
            .withAvailabilityZone(availabilityZone)
            .withTagSpecifications(tagSpecification)
            .withEncrypted(true);
    if (awsInstanceView.isKmsEnabled()) {
        createVolumeRequest = createVolumeRequest.withKmsKeyId(awsInstanceView.getKmsKey());
    }
    return createVolumeRequest;
}
 
Example #2
Source File: BaseTest.java    From aws-mock with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: AwsVolumeResourceBuilderTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private void verifyCreateVolumeRequest(String expectedSnapshotId, Boolean expectedEncrypted, String expectedKmsKeyId) {
    verify(amazonEC2Client).createVolume(createVolumeRequestCaptor.capture());
    CreateVolumeRequest createVolumeRequest = createVolumeRequestCaptor.getValue();
    assertThat(createVolumeRequest).isNotNull();
    assertThat(createVolumeRequest.getAvailabilityZone()).isEqualTo(AVAILABILITY_ZONE);
    assertThat(createVolumeRequest.getSize()).isEqualTo(VOLUME_SIZE);
    assertThat(createVolumeRequest.getSnapshotId()).isEqualTo(expectedSnapshotId);
    assertThat(createVolumeRequest.getVolumeType()).isEqualTo(TYPE_GP2);
    assertThat(createVolumeRequest.getEncrypted()).isEqualTo(expectedEncrypted);
    assertThat(createVolumeRequest.getKmsKeyId()).isEqualTo(expectedKmsKeyId);

    List<TagSpecification> tagSpecifications = createVolumeRequest.getTagSpecifications();
    assertThat(tagSpecifications).isNotNull();
    assertThat(tagSpecifications).hasSize(1);
    TagSpecification tagSpecification = tagSpecifications.get(0);
    assertThat(tagSpecification).isNotNull();
    assertThat(tagSpecification.getResourceType()).isEqualTo(com.amazonaws.services.ec2.model.ResourceType.Volume.toString());
    assertThat(tagSpecification.getTags()).isEqualTo(EC2_TAGS);
}
 
Example #4
Source File: AwsVolumeResourceBuilderTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
void buildTestWhenAttachedVolumesOnlyAndEncryptionWithCustomKeyFast() throws Exception {
    Group group = createGroup(List.of(createVolume(TYPE_GP2)),
            Map.ofEntries(entry(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, true),
                    entry(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name()),
                    entry(InstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, ENCRYPTION_KEY_ARN),
                    entry(AwsInstanceTemplate.FAST_EBS_ENCRYPTION_ENABLED, true)));

    when(encryptedSnapshotService.isEncryptedVolumeRequested(group)).thenReturn(true);
    setUpTaskExecutors();
    when(amazonEC2Client.createVolume(isA(CreateVolumeRequest.class))).thenReturn(createCreateVolumeResult());

    List<CloudResource> result = underTest.build(awsContext, PRIVATE_ID, authenticatedContext, group,
            List.of(createVolumeSet(List.of(createVolumeForVolumeSet(TYPE_GP2)))), cloudStack);

    List<VolumeSetAttributes.Volume> volumes = verifyResultAndGetVolumes(result);
    verifyVolumes(volumes, "/dev/xvdb");
    verifyCreateVolumeRequest(null, true, ENCRYPTION_KEY_ARN);
    verify(encryptedSnapshotService, never()).createSnapshotIfNeeded(authenticatedContext, cloudStack, group, resourceNotifier);
}
 
Example #5
Source File: AwsVolumeResourceBuilderTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
void buildTestWhenAttachedVolumesOnlyAndEncryptionWithDefaultKeyFast() throws Exception {
    Group group = createGroup(List.of(createVolume(TYPE_GP2)),
            Map.ofEntries(entry(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, true),
                    entry(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.DEFAULT.name()),
                    entry(AwsInstanceTemplate.FAST_EBS_ENCRYPTION_ENABLED, true)));

    when(encryptedSnapshotService.isEncryptedVolumeRequested(group)).thenReturn(true);
    setUpTaskExecutors();
    when(amazonEC2Client.createVolume(isA(CreateVolumeRequest.class))).thenReturn(createCreateVolumeResult());

    List<CloudResource> result = underTest.build(awsContext, PRIVATE_ID, authenticatedContext, group,
            List.of(createVolumeSet(List.of(createVolumeForVolumeSet(TYPE_GP2)))), cloudStack);

    List<VolumeSetAttributes.Volume> volumes = verifyResultAndGetVolumes(result);
    verifyVolumes(volumes, "/dev/xvdb");
    verifyCreateVolumeRequest(null, true, null);
    verify(encryptedSnapshotService, never()).createSnapshotIfNeeded(authenticatedContext, cloudStack, group, resourceNotifier);
}
 
Example #6
Source File: AwsVolumeResourceBuilderTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
void buildTestWhenAttachedVolumesOnlyAndEncryptionWithCustomKey() throws Exception {
    Group group = createGroup(List.of(createVolume(TYPE_GP2)),
            Map.ofEntries(entry(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, true),
                    entry(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name()),
                    entry(InstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, ENCRYPTION_KEY_ARN),
                    entry(AwsInstanceTemplate.FAST_EBS_ENCRYPTION_ENABLED, false)));

    when(encryptedSnapshotService.isEncryptedVolumeRequested(group)).thenReturn(true);
    when(encryptedSnapshotService.createSnapshotIfNeeded(authenticatedContext, cloudStack, group, resourceNotifier)).thenReturn(Optional.of(SNAPSHOT_ID));
    setUpTaskExecutors();
    when(amazonEC2Client.createVolume(isA(CreateVolumeRequest.class))).thenReturn(createCreateVolumeResult());

    List<CloudResource> result = underTest.build(awsContext, PRIVATE_ID, authenticatedContext, group,
            List.of(createVolumeSet(List.of(createVolumeForVolumeSet(TYPE_GP2)))), cloudStack);

    List<VolumeSetAttributes.Volume> volumes = verifyResultAndGetVolumes(result);
    verifyVolumes(volumes, "/dev/xvdb");
    verifyCreateVolumeRequest(SNAPSHOT_ID, null, null);
}
 
Example #7
Source File: AwsVolumeResourceBuilderTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
void buildTestWhenAttachedVolumesOnlyAndEncryptionWithDefaultKey() throws Exception {
    Group group = createGroup(List.of(createVolume(TYPE_GP2)),
            Map.ofEntries(entry(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, true),
                    entry(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.DEFAULT.name()),
                    entry(AwsInstanceTemplate.FAST_EBS_ENCRYPTION_ENABLED, false)));

    when(encryptedSnapshotService.isEncryptedVolumeRequested(group)).thenReturn(true);
    when(encryptedSnapshotService.createSnapshotIfNeeded(authenticatedContext, cloudStack, group, resourceNotifier)).thenReturn(Optional.of(SNAPSHOT_ID));
    setUpTaskExecutors();
    when(amazonEC2Client.createVolume(isA(CreateVolumeRequest.class))).thenReturn(createCreateVolumeResult());

    List<CloudResource> result = underTest.build(awsContext, PRIVATE_ID, authenticatedContext, group,
            List.of(createVolumeSet(List.of(createVolumeForVolumeSet(TYPE_GP2)))), cloudStack);

    List<VolumeSetAttributes.Volume> volumes = verifyResultAndGetVolumes(result);
    verifyVolumes(volumes, "/dev/xvdb");
    verifyCreateVolumeRequest(SNAPSHOT_ID, null, null);
}
 
Example #8
Source File: AwsVolumeResourceBuilderTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
void buildTestWhenEphemeralAndAttachedVolumesAndNoEncryption() throws Exception {
    Group group = createGroup(List.of(createVolume(TYPE_EPHEMERAL), createVolume(TYPE_GP2)), Map.of(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, false));

    when(encryptedSnapshotService.isEncryptedVolumeRequested(group)).thenReturn(false);
    setUpTaskExecutors();
    when(amazonEC2Client.createVolume(isA(CreateVolumeRequest.class))).thenReturn(createCreateVolumeResult());

    List<CloudResource> result = underTest.build(awsContext, PRIVATE_ID, authenticatedContext, group,
            List.of(createVolumeSet(List.of(createVolumeForVolumeSet(TYPE_GP2)))), cloudStack);

    List<VolumeSetAttributes.Volume> volumes = verifyResultAndGetVolumes(result);
    verifyVolumes(volumes, "/dev/xvdc");
    verifyCreateVolumeRequest(null, false, null);
    verify(encryptedSnapshotService, never()).createSnapshotIfNeeded(authenticatedContext, cloudStack, group, resourceNotifier);
}
 
Example #9
Source File: AwsVolumeResourceBuilderTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
void buildTestWhenAttachedVolumesOnlyAndNoEncryption() throws Exception {
    Group group = createGroup(List.of(createVolume(TYPE_GP2)), Map.of(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, false));

    when(encryptedSnapshotService.isEncryptedVolumeRequested(group)).thenReturn(false);
    setUpTaskExecutors();
    when(amazonEC2Client.createVolume(isA(CreateVolumeRequest.class))).thenReturn(createCreateVolumeResult());

    List<CloudResource> result = underTest.build(awsContext, PRIVATE_ID, authenticatedContext, group,
            List.of(createVolumeSet(List.of(createVolumeForVolumeSet(TYPE_GP2)))), cloudStack);

    List<VolumeSetAttributes.Volume> volumes = verifyResultAndGetVolumes(result);
    verifyVolumes(volumes, "/dev/xvdb");
    verifyCreateVolumeRequest(null, false, null);
    verify(encryptedSnapshotService, never()).createSnapshotIfNeeded(authenticatedContext, cloudStack, group, resourceNotifier);
}
 
Example #10
Source File: Ec2MachineConfigurator.java    From roboconf-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Creates volume for EBS.
 * @return volume ID of newly created volume
 */
private String createVolume(String storageId, String snapshotId, int size) {
	String volumeType = Ec2IaasHandler.findStorageProperty(this.targetProperties, storageId, VOLUME_TYPE_PREFIX);
	if(volumeType == null) volumeType = "standard";

	CreateVolumeRequest createVolumeRequest = new CreateVolumeRequest()
			.withAvailabilityZone( this.availabilityZone )
			.withVolumeType( volumeType )
			.withSize( size ); // The size of the volume, in gigabytes.

	// EC2 snapshot IDs start with "snap-"...
	if(! Utils.isEmptyOrWhitespaces(snapshotId) && snapshotId.startsWith("snap-"))
		createVolumeRequest.withSnapshotId(snapshotId);

	CreateVolumeResult createVolumeResult = this.ec2Api.createVolume(createVolumeRequest);
	return createVolumeResult.getVolume().getVolumeId();
}
 
Example #11
Source File: AwsVolumeProcess.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
public void createVolume(AwsProcessClient awsProcessClient, Long instanceNo, Long volumeNo) {
    AwsVolume awsVolume = awsVolumeDao.read(volumeNo);
    AwsInstance awsInstance = awsInstanceDao.read(instanceNo);

    // ボリュームの作成
    CreateVolumeRequest request = new CreateVolumeRequest();
    request.withSize(awsVolume.getSize());
    request.withSnapshotId(awsVolume.getSnapshotId());
    request.withAvailabilityZone(awsInstance.getAvailabilityZone());

    String volumeType = Config.getProperty("aws.volumeType");
    if (StringUtils.isNotEmpty(volumeType)) {
        request.withVolumeType(volumeType);
    }

    CreateVolumeResult result = awsProcessClient.getEc2Client().createVolume(request);
    Volume volume = result.getVolume();

    String volumeId = volume.getVolumeId();

    // ログ出力
    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100121", volumeId));
    }

    //イベントログ出力
    Component component = null;
    if (awsVolume.getComponentNo() != null) {
        component = componentDao.read(awsVolume.getComponentNo());
    }
    Instance instance = instanceDao.read(instanceNo);
    processLogger.debug(component, instance, "AwsEbsCreate",
            new Object[] { awsProcessClient.getPlatform().getPlatformName() });

    // データベース更新
    awsVolume.setVolumeId(volume.getVolumeId());
    awsVolume.setStatus(volume.getState());
    awsVolumeDao.update(awsVolume);
}
 
Example #12
Source File: EC2Impl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public Image createVolume(String snapshotId, String availabilityZone,
        ResultCapture<CreateVolumeResult> extractor) {

    CreateVolumeRequest request = new CreateVolumeRequest()
        .withSnapshotId(snapshotId)
        .withAvailabilityZone(availabilityZone);
    return createVolume(request, extractor);
}
 
Example #13
Source File: EC2Impl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public Image createVolume(String availabilityZone, Integer size,
        ResultCapture<CreateVolumeResult> extractor) {

    CreateVolumeRequest request = new CreateVolumeRequest()
        .withAvailabilityZone(availabilityZone)
        .withSize(size);
    return createVolume(request, extractor);
}
 
Example #14
Source File: EC2Impl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public Image createVolume(CreateVolumeRequest request,
        ResultCapture<CreateVolumeResult> extractor) {

    ActionResult result = service.performAction("CreateVolume", request,
            extractor);

    if (result == null) return null;
    return new ImageImpl(result.getResource());
}
 
Example #15
Source File: AmazonEc2RetryClient.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public CreateVolumeResult createVolume(CreateVolumeRequest request) {
    return retry.testWith2SecDelayMax15Times(() -> mapThrottlingError(() -> client.createVolume(request)));
}
 
Example #16
Source File: EC2Impl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public Image createVolume(CreateVolumeRequest request) {
    return createVolume(request, null);
}
 
Example #17
Source File: EC2.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the <code>CreateVolume</code> action and use a ResultCapture to
 * retrieve the low-level client response.
 *
 * <p>
 *
 * @return The <code>Image</code> resource object associated with the result
 *         of this action.
 * @see CreateVolumeRequest
 */
com.amazonaws.resources.ec2.Image createVolume(CreateVolumeRequest request,
        ResultCapture<CreateVolumeResult> extractor);
 
Example #18
Source File: EC2.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the <code>CreateVolume</code> action.
 *
 * <p>
 *
 * @return The <code>Image</code> resource object associated with the result
 *         of this action.
 * @see CreateVolumeRequest
 */
com.amazonaws.resources.ec2.Image createVolume(CreateVolumeRequest request);