Search in sources :

Example 1 with CloudStorageRequest

use of com.sequenceiq.common.api.cloudstorage.CloudStorageRequest in project cloudbreak by hortonworks.

the class CloudStorageValidationUtilTest method testIsCloudStorageConfiguredWhenS3NotNull.

@Test
public void testIsCloudStorageConfiguredWhenS3NotNull() {
    CloudStorageRequest cloudStorageRequest = new CloudStorageRequest();
    StorageIdentityBase storageIdentityBase = new StorageIdentityBase();
    storageIdentityBase.setS3(new S3CloudStorageV1Parameters());
    cloudStorageRequest.setIdentities(List.of(storageIdentityBase));
    cloudStorageRequest.setLocations(List.of(new StorageLocationBase()));
    boolean actual = underTest.isCloudStorageConfigured(cloudStorageRequest);
    Assert.assertTrue(actual);
}
Also used : CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) S3CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters) StorageIdentityBase(com.sequenceiq.common.api.cloudstorage.StorageIdentityBase) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.Test)

Example 2 with CloudStorageRequest

use of com.sequenceiq.common.api.cloudstorage.CloudStorageRequest in project cloudbreak by hortonworks.

the class CloudStorageValidatorTest method validateEnvironmentRequestCloudStorageValidation.

@Test
public void validateEnvironmentRequestCloudStorageValidation() {
    when(environment.getCloudStorageValidation()).thenReturn(CloudStorageValidation.ENABLED);
    when(environment.getCredential()).thenReturn(new CredentialResponse());
    when(secretService.getByResponse(any())).thenReturn("secret");
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(credentialToCloudCredentialConverter.convert(any())).thenReturn(new CloudCredential("id", "name", Map.of("secretKey", "thisshouldnotappearinlog"), "acc", false));
    when(entitlementService.cloudStorageValidationEnabled(any())).thenReturn(true);
    when(cloudProviderServicesV4Endopint.validateObjectStorage(any())).thenReturn(new ObjectStorageValidateResponse());
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validate(new CloudStorageRequest(), environment, validationResultBuilder));
    assertFalse(validationResultBuilder.build().hasError());
}
Also used : CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ObjectStorageValidateResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Test(org.junit.jupiter.api.Test)

Example 3 with CloudStorageRequest

use of com.sequenceiq.common.api.cloudstorage.CloudStorageRequest in project cloudbreak by hortonworks.

the class ClusterToClusterV4RequestConverterTest method testConvertWhenFileSystemNotNullThenExpectedCloudStorageRequestShouldBePlaced.

@Test
public void testConvertWhenFileSystemNotNullThenExpectedCloudStorageRequestShouldBePlaced() {
    FileSystem fileSystem = new FileSystem();
    CloudStorageRequest expected = new CloudStorageRequest();
    when(cluster.getFileSystem()).thenReturn(fileSystem);
    when(cloudStorageConverter.fileSystemToRequest(fileSystem)).thenReturn(expected);
    ClusterV4Request result = underTest.convert(cluster);
    assertEquals(expected, result.getCloudStorage());
    verify(cloudStorageConverter, times(1)).fileSystemToRequest(fileSystem);
}
Also used : ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) Test(org.junit.Test)

Example 4 with CloudStorageRequest

use of com.sequenceiq.common.api.cloudstorage.CloudStorageRequest 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 5 with CloudStorageRequest

use of com.sequenceiq.common.api.cloudstorage.CloudStorageRequest in project cloudbreak by hortonworks.

the class StackV4RequestToTemplatePreparationObjectConverterTest method testStackInputAccountMappings.

@Test
public void testStackInputAccountMappings() {
    when(cloudStorageValidationUtil.isCloudStorageConfigured(any(CloudStorageRequest.class))).thenReturn(true);
    CloudStorageRequest cloudStorage = mock(CloudStorageRequest.class);
    when(cluster.getCloudStorage()).thenReturn(cloudStorage);
    AccountMappingBase accountMapping = new AccountMappingBase();
    accountMapping.setGroupMappings(GROUP_MAPPINGS);
    accountMapping.setUserMappings(USER_MAPPINGS);
    when(cloudStorage.getAccountMapping()).thenReturn(accountMapping);
    TemplatePreparationObject result = underTest.convert(source);
    AccountMappingView accountMappingView = result.getAccountMappingView();
    assertNotNull(accountMappingView);
    assertEquals(GROUP_MAPPINGS, accountMappingView.getGroupMappings());
    assertEquals(USER_MAPPINGS, accountMappingView.getUserMappings());
}
Also used : TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) AccountMappingBase(com.sequenceiq.common.api.cloudstorage.AccountMappingBase) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) AccountMappingView(com.sequenceiq.cloudbreak.template.views.AccountMappingView) Test(org.junit.Test)

Aggregations

CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)53 Test (org.junit.jupiter.api.Test)27 StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)24 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 CloudStorageCdpService (com.sequenceiq.common.model.CloudStorageCdpService)15 SdxCloudStorageRequest (com.sequenceiq.sdx.api.model.SdxCloudStorageRequest)15 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)14 LoggingResponse (com.sequenceiq.common.api.telemetry.response.LoggingResponse)14 ArrayList (java.util.ArrayList)14 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)13 FileSystemType (com.sequenceiq.common.model.FileSystemType)13 List (java.util.List)12 StorageIdentityBase (com.sequenceiq.common.api.cloudstorage.StorageIdentityBase)11 CloudIdentityType (com.sequenceiq.common.model.CloudIdentityType)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)10 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 InjectMocks (org.mockito.InjectMocks)10 Mock (org.mockito.Mock)10 Mockito.when (org.mockito.Mockito.when)10