Search in sources :

Example 1 with GcpInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class InstanceTemplateV4RequestToTemplateConverterTest method getSampleGcpRequest.

private InstanceTemplateV4Request getSampleGcpRequest() {
    InstanceTemplateV4Request source = new InstanceTemplateV4Request();
    source.setCloudPlatform(CloudPlatform.GCP);
    source.setRootVolume(getRootVolume(100));
    source.setInstanceType("n1-standard-4");
    GcpInstanceTemplateV4Parameters parameters = new GcpInstanceTemplateV4Parameters();
    GcpEncryptionV4Parameters encryption = new GcpEncryptionV4Parameters();
    encryption.setType(EncryptionType.CUSTOM);
    encryption.setKeyEncryptionMethod(KeyEncryptionMethod.RAW);
    encryption.setKey("myKey");
    parameters.setEncryption(encryption);
    source.setGcp(parameters);
    ProviderParameterCalculator providerParameterCalculator = new ProviderParameterCalculator();
    ReflectionTestUtils.setField(underTest, "providerParameterCalculator", providerParameterCalculator);
    when(missingResourceNameGenerator.generateName(APIResourceType.TEMPLATE)).thenReturn("name");
    return source;
}
Also used : InstanceTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request) GcpInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters) GcpEncryptionV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpEncryptionV4Parameters) ProviderParameterCalculator(com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator)

Example 2 with GcpInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class InstanceTemplateParameterConverter method initGcpEncryptionFromEnvironment.

private void initGcpEncryptionFromEnvironment(GcpInstanceTemplateV4Parameters response, DetailedEnvironmentResponse environment) {
    String encryptionKey = Optional.of(environment).map(DetailedEnvironmentResponse::getGcp).map(GcpEnvironmentParameters::getGcpResourceEncryptionParameters).map(GcpResourceEncryptionParameters::getEncryptionKey).orElse(null);
    if (encryptionKey != null) {
        LOGGER.info("Applying Encryption with CMEK for GCP disks as per environment.");
        GcpEncryptionV4Parameters encryption = new GcpEncryptionV4Parameters();
        encryption.setType(EncryptionType.CUSTOM);
        encryption.setKeyEncryptionMethod(KeyEncryptionMethod.KMS);
        encryption.setKey(encryptionKey);
        response.setEncryption(encryption);
    } else {
        LOGGER.info("Environment has not requested for Customer-Managed Encryption with CMEK for GCP disks.");
    }
}
Also used : GcpEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters) GcpEncryptionV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpEncryptionV4Parameters)

Example 3 with GcpInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class InstanceTemplateParameterConverter method convert.

public GcpInstanceTemplateV4Parameters convert(GcpInstanceTemplateV1Parameters source, DetailedEnvironmentResponse environment) {
    GcpInstanceTemplateV4Parameters response = new GcpInstanceTemplateV4Parameters();
    initGcpEncryptionFromEnvironment(response, environment);
    return response;
}
Also used : GcpInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters)

Example 4 with GcpInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class StackRequestManifester method setupInstanceVolumeEncryptionForGcp.

@VisibleForTesting
void setupInstanceVolumeEncryptionForGcp(StackV4Request stackRequest, DetailedEnvironmentResponse environmentResponse) {
    String encryptionKey = Optional.of(environmentResponse).map(DetailedEnvironmentResponse::getGcp).map(GcpEnvironmentParameters::getGcpResourceEncryptionParameters).map(GcpResourceEncryptionParameters::getEncryptionKey).orElse(null);
    if (encryptionKey != null) {
        stackRequest.getInstanceGroups().forEach(ig -> {
            GcpInstanceTemplateV4Parameters gcp = ig.getTemplate().createGcp();
            GcpEncryptionV4Parameters encryption = gcp.getEncryption();
            if (encryption == null) {
                encryption = new GcpEncryptionV4Parameters();
                gcp.setEncryption(encryption);
            }
            gcp.getEncryption().setType(EncryptionType.CUSTOM);
            gcp.getEncryption().setKey(encryptionKey);
            gcp.getEncryption().setKeyEncryptionMethod(KeyEncryptionMethod.KMS);
        });
    }
}
Also used : GcpEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters) GcpInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters) GcpEncryptionV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpEncryptionV4Parameters) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with GcpInstanceTemplateV4Parameters

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters in project cloudbreak by hortonworks.

the class StackRequestManifesterTest method verifyGcpEncryption.

private void verifyGcpEncryption(InstanceTemplateV4Request instanceTemplateV4Request, EncryptionType expectedEncryptionType, String expectedEncryptionKey) {
    GcpInstanceTemplateV4Parameters gcp = instanceTemplateV4Request.getGcp();
    assertThat(gcp).isNotNull();
    GcpEncryptionV4Parameters encryption = gcp.getEncryption();
    assertThat(encryption).isNotNull();
    assertThat(encryption.getType()).isEqualTo(expectedEncryptionType);
    assertThat(encryption.getKey()).isEqualTo(expectedEncryptionKey);
}
Also used : GcpInstanceTemplateV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters) GcpEncryptionV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpEncryptionV4Parameters)

Aggregations

GcpInstanceTemplateV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters)6 GcpEncryptionV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpEncryptionV4Parameters)5 GcpInstanceTemplateV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.GcpInstanceTemplateV1Parameters)2 GcpEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 InstanceTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request)1 ProviderParameterCalculator (com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator)1 Test (org.junit.jupiter.api.Test)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1