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