use of com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest 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.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest 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());
}
use of com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest in project cloudbreak by hortonworks.
the class EnvironmentValidationHandler method validateCloudStorage.
private void validateCloudStorage(Event<EnvironmentValidationDto> environmentDtoEvent, EnvironmentDto environmentDto) {
EnvironmentCloudStorageValidationRequest cloudStorageValidationRequest = new EnvironmentCloudStorageValidationRequest();
cloudStorageValidationRequest.setCredentialCrn(environmentDto.getCredential().getResourceCrn());
TelemetryRequest telemetryRequest = telemetryApiConverter.convertToRequest(environmentDto.getTelemetry());
BackupRequest backupRequest = backupConverter.convertToRequest(environmentDto.getBackup());
cloudStorageValidationRequest.setTelemetry(telemetryRequest);
cloudStorageValidationRequest.setBackup(backupRequest);
ObjectStorageValidateResponse response = null;
try {
response = cloudStorageValidator.validateCloudStorage(environmentDto.getAccountId(), cloudStorageValidationRequest);
} catch (Exception e) {
String message = String.format("Error occured during object storage validation, validation skipped. Error: %s", e.getMessage());
LOGGER.warn(message);
eventSenderService.sendEventAndNotification(environmentDto, ThreadBasedUserCrnProvider.getUserCrn(), ResourceEvent.ENVIRONMENT_VALIDATION_FAILED_AND_SKIPPED, Set.of(e.getMessage()));
}
if (response != null && ResponseStatus.ERROR.equals(response.getStatus())) {
throw new EnvironmentServiceException(response.getError());
}
if (response != null && ResponseStatus.OK.equals(response.getStatus()) && isNotBlank(response.getError())) {
eventSenderService.sendEventAndNotification(environmentDto, ThreadBasedUserCrnProvider.getUserCrn(), ResourceEvent.ENVIRONMENT_VALIDATION_FAILED_AND_SKIPPED, Set.of(response.getError()));
}
}
Aggregations