Search in sources :

Example 1 with GcpEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters 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 2 with GcpEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters in project cloudbreak by hortonworks.

the class InstanceTemplateParameterConverterTest method createDetailedEnvironmentResponseForGcpEncryption.

private DetailedEnvironmentResponse createDetailedEnvironmentResponseForGcpEncryption(boolean withGcp, boolean withResourceEncryption, String encryptionKey) {
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    if (withGcp) {
        GcpEnvironmentParameters parameters = new GcpEnvironmentParameters();
        environment.setGcp(parameters);
        if (withResourceEncryption) {
            GcpResourceEncryptionParameters encryption = new GcpResourceEncryptionParameters();
            parameters.setGcpResourceEncryptionParameters(encryption);
            encryption.setEncryptionKey(encryptionKey);
        }
    }
    return environment;
}
Also used : GcpResourceEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpResourceEncryptionParameters) GcpEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)

Example 3 with GcpEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters in project cloudbreak by hortonworks.

the class CloudStorageManifesterTest method whenEnvironmentHasLoggingEnabledThenShouldApplyAsLogIdentityForGCS.

@Test
public void whenEnvironmentHasLoggingEnabledThenShouldApplyAsLogIdentityForGCS() {
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    mockFileSystemResponseForCloudbreakClient();
    SdxCluster sdxCluster = new SdxCluster();
    SdxClusterRequest sdxClusterRequest = new SdxClusterRequest();
    sdxCluster.setInitiatorUserCrn(USER_CRN);
    sdxCluster.setClusterName("sdx-cluster");
    SdxCloudStorageRequest cloudStorageRequest = new SdxCloudStorageRequest();
    cloudStorageRequest.setBaseLocation("gs://example-path");
    cloudStorageRequest.setFileSystemType(FileSystemType.GCS);
    GcsCloudStorageV1Parameters gcsCloudStorageV1Parameters = new GcsCloudStorageV1Parameters();
    gcsCloudStorageV1Parameters.setServiceAccountEmail(EMAIL);
    cloudStorageRequest.setGcs(gcsCloudStorageV1Parameters);
    sdxClusterRequest.setCloudStorage(cloudStorageRequest);
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setCloudPlatform("GCP");
    TelemetryResponse telemetryResponse = new TelemetryResponse();
    LoggingResponse loggingResponse = new LoggingResponse();
    loggingResponse.setGcs(gcsCloudStorageV1Parameters);
    telemetryResponse.setLogging(loggingResponse);
    GcpEnvironmentParameters gcpEnvironmentParameters = GcpEnvironmentParameters.builder().build();
    environment.setGcp(gcpEnvironmentParameters);
    environment.setTelemetry(telemetryResponse);
    ClusterV4Request clusterV4Request = new ClusterV4Request();
    clusterV4Request.setBlueprintName(exampleBlueprintName);
    CloudStorageRequest cloudStorageConfigReq = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.initCloudStorageRequest(environment, clusterV4Request, sdxCluster, sdxClusterRequest));
    StorageLocationBase singleRequest = cloudStorageConfigReq.getLocations().iterator().next();
    assertEquals(2, cloudStorageConfigReq.getIdentities().size());
    assertEquals(1, cloudStorageConfigReq.getIdentities().stream().filter(r -> r.getType().equals(CloudIdentityType.ID_BROKER)).collect(Collectors.toSet()).size());
    assertEquals(1, cloudStorageConfigReq.getIdentities().stream().filter(r -> r.getType().equals(CloudIdentityType.LOG)).collect(Collectors.toSet()).size());
    assertEquals(2, cloudStorageConfigReq.getIdentities().stream().filter(r -> r.getGcs().getServiceAccountEmail().equals(EMAIL)).collect(Collectors.toSet()).size());
    assertEquals(1, cloudStorageConfigReq.getLocations().size());
    assertEquals(CloudStorageCdpService.RANGER_AUDIT, singleRequest.getType());
    assertEquals("ranger/example-path", singleRequest.getValue());
    verify(storageValidationService).validateCloudStorage("GCP", cloudStorageRequest);
}
Also used : SdxCloudStorageRequest(com.sequenceiq.sdx.api.model.SdxCloudStorageRequest) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) GcpEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Mock(org.mockito.Mock) FileSystemParameterV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.responses.FileSystemParameterV4Responses) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) GcsCloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.GcsCloudStorageV1Parameters) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) ArrayList(java.util.ArrayList) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) FileSystemParameterV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.responses.FileSystemParameterV4Response) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SdxCloudStorageRequest(com.sequenceiq.sdx.api.model.SdxCloudStorageRequest) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) InjectMocks(org.mockito.InjectMocks) RegionAwareInternalCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator) LoggingResponse(com.sequenceiq.common.api.telemetry.response.LoggingResponse) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) S3CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) FileSystemV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.FileSystemV4Endpoint) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Test(org.junit.jupiter.api.Test) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) List(java.util.List) S3GuardRequestParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) FileSystemType(com.sequenceiq.common.model.FileSystemType) CloudIdentityType(com.sequenceiq.common.model.CloudIdentityType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) SdxCloudStorageRequest(com.sequenceiq.sdx.api.model.SdxCloudStorageRequest) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) GcpEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters) LoggingResponse(com.sequenceiq.common.api.telemetry.response.LoggingResponse) SdxClusterRequest(com.sequenceiq.sdx.api.model.SdxClusterRequest) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) GcsCloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.GcsCloudStorageV1Parameters) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Example 4 with GcpEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters 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 GcpEnvironmentParameters

use of com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters in project cloudbreak by hortonworks.

the class EnvironmentApiConverterTest method createGcpRequest.

private GcpEnvironmentParameters createGcpRequest() {
    GcpEnvironmentParameters gcpEnvironmentParameters = new GcpEnvironmentParameters();
    gcpEnvironmentParameters.setGcpResourceEncryptionParameters(GcpResourceEncryptionParameters.builder().withEncryptionKey("dummy-encryption-key").build());
    return gcpEnvironmentParameters;
}
Also used : GcpEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters)

Aggregations

GcpEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters)5 GcpEncryptionV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpEncryptionV4Parameters)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FileSystemV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.FileSystemV4Endpoint)1 FileSystemParameterV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.responses.FileSystemParameterV4Response)1 FileSystemParameterV4Responses (com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.responses.FileSystemParameterV4Responses)1 GcpInstanceTemplateV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.template.GcpInstanceTemplateV4Parameters)1 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 RegionAwareInternalCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator)1 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)1 CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)1 StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)1 GcsCloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.GcsCloudStorageV1Parameters)1 S3CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters)1 LoggingResponse (com.sequenceiq.common.api.telemetry.response.LoggingResponse)1 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)1 CloudIdentityType (com.sequenceiq.common.model.CloudIdentityType)1 CloudStorageCdpService (com.sequenceiq.common.model.CloudStorageCdpService)1