Search in sources :

Example 1 with ObjectStorageValidateRequest

use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest in project cloudbreak by hortonworks.

the class CloudStorageValidator method validateCloudStorage.

public ObjectStorageValidateResponse validateCloudStorage(String accountId, EnvironmentCloudStorageValidationRequest environmentCloudStorageValidationRequest) {
    Credential credential = credentialService.getByCrnForAccountId(environmentCloudStorageValidationRequest.getCredentialCrn(), accountId, ENVIRONMENT, false);
    String attributes = credential.getAttributes();
    CloudCredential cloudCredential = new CloudCredential(credential.getResourceCrn(), credential.getName(), new Json(attributes).getMap(), credential.getAccountId(), credential.isVerifyPermissions());
    CloudStorageRequest cloudStorageRequest = new CloudStorageRequest();
    TelemetryRequest telemetryRequest = environmentCloudStorageValidationRequest.getTelemetry();
    boolean loggingConfigured = isLoggingConfigured(telemetryRequest);
    if (loggingConfigured) {
        LOGGER.debug("Cloud storage logging is enabled.");
        addLogIdentity(cloudStorageRequest, telemetryRequest);
    }
    ObjectStorageValidateRequest.Builder objectStorageValidateBuilder = ObjectStorageValidateRequest.builder().withCloudPlatform(credential.getCloudPlatform()).withCredential(cloudCredential).withCloudStorageRequest(cloudStorageRequest);
    if (loggingConfigured) {
        objectStorageValidateBuilder.withLogsLocationBase(telemetryRequest.getLogging().getStorageLocation());
    }
    if (environmentCloudStorageValidationRequest.getBackup() != null) {
        objectStorageValidateBuilder.withBackupLocationBase(environmentCloudStorageValidationRequest.getBackup().getStorageLocation());
    }
    ObjectStorageValidateRequest objectStorageValidateRequest = objectStorageValidateBuilder.build();
    return ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> cloudProviderServicesV4Endpoint.validateObjectStorage(objectStorageValidateRequest));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) TelemetryRequest(com.sequenceiq.common.api.telemetry.request.TelemetryRequest) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Json(com.sequenceiq.cloudbreak.common.json.Json) ObjectStorageValidateRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)

Example 2 with ObjectStorageValidateRequest

use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest in project cloudbreak by hortonworks.

the class StorageValidationService method validateObjectStorage.

public ObjectStorageValidateResponse validateObjectStorage(String credentialCrn, SdxCloudStorageRequest sdxCloudStorageRequest, String blueprintName, String clusterName, String dataAccessRole, String rangerAuditRole) {
    CredentialResponse credentialResponse = environmentClientService.getCredentialByCrn(credentialCrn);
    String attributes = secretService.getByResponse(credentialResponse.getAttributes());
    CloudCredential cloudCredential = new CloudCredential(credentialResponse.getCrn(), credentialResponse.getName(), new Json(attributes).getMap(), credentialResponse.getAccountId(), credentialResponse.isVerifyPermissions());
    CloudStorageRequest cloudStorageRequest = cloudStorageManifester.initSdxCloudStorageRequest(credentialResponse.getCloudPlatform(), blueprintName, clusterName, sdxCloudStorageRequest);
    AccountMappingBase accountMapping = new AccountMappingBase();
    Map<String, String> userMapping = getUserMapping(dataAccessRole, rangerAuditRole);
    accountMapping.setUserMappings(userMapping);
    cloudStorageRequest.setAccountMapping(accountMapping);
    ObjectStorageValidateRequest objectStorageValidateRequest = ObjectStorageValidateRequest.builder().withCloudPlatform(credentialResponse.getCloudPlatform()).withCredential(cloudCredential).withCloudStorageRequest(cloudStorageRequest).build();
    return ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> cloudProviderServicesV4Endpoint.validateObjectStorage(objectStorageValidateRequest));
}
Also used : AccountMappingBase(com.sequenceiq.common.api.cloudstorage.AccountMappingBase) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) SdxCloudStorageRequest(com.sequenceiq.sdx.api.model.SdxCloudStorageRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Json(com.sequenceiq.cloudbreak.common.json.Json) ObjectStorageValidateRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)

Example 3 with ObjectStorageValidateRequest

use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest in project cloudbreak by hortonworks.

the class AzureObjectStorageConnectorTest method getRequest.

private ObjectStorageValidateRequest getRequest() {
    ObjectStorageValidateRequest objectStorageValidateRequest = new ObjectStorageValidateRequest();
    CloudCredential credential = new CloudCredential();
    credential.setId("crn:cdp:environments:us-west-1:someone:credential:12345");
    objectStorageValidateRequest.setCredential(credential);
    return objectStorageValidateRequest;
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ObjectStorageValidateRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)

Example 4 with ObjectStorageValidateRequest

use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest in project cloudbreak by hortonworks.

the class CloudStorageValidatorTest method validateCloudStorageSetLocationBaseWhenLoggingIsConfigured.

@Test
public void validateCloudStorageSetLocationBaseWhenLoggingIsConfigured() {
    when(credentialService.getByCrnForAccountId(anyString(), anyString(), any(), anyBoolean())).thenReturn(new Credential());
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    EnvironmentCloudStorageValidationRequest request = new EnvironmentCloudStorageValidationRequest();
    TelemetryRequest telemetryRequest = new TelemetryRequest();
    LoggingRequest loggingRequest = new LoggingRequest();
    loggingRequest.setStorageLocation("s3://mybucket/location");
    S3CloudStorageV1Parameters s3CloudStorageV1Parameters = new S3CloudStorageV1Parameters();
    s3CloudStorageV1Parameters.setInstanceProfile("instanceProfile");
    loggingRequest.setS3(s3CloudStorageV1Parameters);
    telemetryRequest.setLogging(loggingRequest);
    request.setTelemetry(telemetryRequest);
    request.setCredentialCrn("credential");
    ArgumentCaptor<ObjectStorageValidateRequest> requestCaptor = ArgumentCaptor.forClass(ObjectStorageValidateRequest.class);
    when(cloudProviderServicesV4Endpoint.validateObjectStorage(requestCaptor.capture())).thenReturn(ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build());
    ObjectStorageValidateResponse response = underTest.validateCloudStorage("1234", request);
    assertEquals(ResponseStatus.OK, response.getStatus());
    assertNull(response.getError());
    ObjectStorageValidateRequest objectStorageValidateRequest = requestCaptor.getValue();
    assertEquals("s3://mybucket/location", objectStorageValidateRequest.getLogsLocationBase());
    List<StorageIdentityBase> storageIdentities = objectStorageValidateRequest.getCloudStorageRequest().getIdentities();
    assertEquals(1, storageIdentities.size());
    StorageIdentityBase storageIdentity = storageIdentities.get(0);
    assertEquals(CloudIdentityType.LOG, storageIdentity.getType());
    assertEquals("instanceProfile", storageIdentity.getS3().getInstanceProfile());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) TelemetryRequest(com.sequenceiq.common.api.telemetry.request.TelemetryRequest) S3CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters) EnvironmentCloudStorageValidationRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest) ObjectStorageValidateResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse) ObjectStorageValidateRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest) LoggingRequest(com.sequenceiq.common.api.telemetry.request.LoggingRequest) StorageIdentityBase(com.sequenceiq.common.api.cloudstorage.StorageIdentityBase) Test(org.junit.jupiter.api.Test)

Example 5 with ObjectStorageValidateRequest

use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest in project cloudbreak by hortonworks.

the class CloudStorageValidatorTest method validateCloudStorageSkipLocationBaseWhenLoggingIsNotConfigured.

@Test
public void validateCloudStorageSkipLocationBaseWhenLoggingIsNotConfigured() {
    when(credentialService.getByCrnForAccountId(anyString(), anyString(), any(), anyBoolean())).thenReturn(new Credential());
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    EnvironmentCloudStorageValidationRequest request = new EnvironmentCloudStorageValidationRequest();
    request.setCredentialCrn("credential");
    ArgumentCaptor<ObjectStorageValidateRequest> requestCaptor = ArgumentCaptor.forClass(ObjectStorageValidateRequest.class);
    when(cloudProviderServicesV4Endpoint.validateObjectStorage(requestCaptor.capture())).thenReturn(ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build());
    ObjectStorageValidateResponse response = underTest.validateCloudStorage("1234", request);
    assertEquals(ResponseStatus.OK, response.getStatus());
    assertNull(response.getError());
    assertNull(requestCaptor.getValue().getLogsLocationBase());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentCloudStorageValidationRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest) ObjectStorageValidateResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse) ObjectStorageValidateRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectStorageValidateRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)4 ObjectStorageValidateResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse)3 Credential (com.sequenceiq.environment.credential.domain.Credential)3 Json (com.sequenceiq.cloudbreak.common.json.Json)2 CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)2 TelemetryRequest (com.sequenceiq.common.api.telemetry.request.TelemetryRequest)2 EnvironmentCloudStorageValidationRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest)2 Test (org.junit.jupiter.api.Test)2 AccountMappingBase (com.sequenceiq.common.api.cloudstorage.AccountMappingBase)1 StorageIdentityBase (com.sequenceiq.common.api.cloudstorage.StorageIdentityBase)1 S3CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters)1 LoggingRequest (com.sequenceiq.common.api.telemetry.request.LoggingRequest)1 Credential (com.sequenceiq.datalake.entity.Credential)1 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)1 SdxCloudStorageRequest (com.sequenceiq.sdx.api.model.SdxCloudStorageRequest)1