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);
}
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());
}
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);
}
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));
}
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());
}
Aggregations