Search in sources :

Example 1 with EnvironmentCloudStorageValidationRequest

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());
}
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 2 with EnvironmentCloudStorageValidationRequest

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

Example 3 with EnvironmentCloudStorageValidationRequest

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()));
    }
}
Also used : BackupRequest(com.sequenceiq.common.api.backup.request.BackupRequest) TelemetryRequest(com.sequenceiq.common.api.telemetry.request.TelemetryRequest) EnvironmentCloudStorageValidationRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest) ObjectStorageValidateResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse) EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException) EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

ObjectStorageValidateResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse)3 EnvironmentCloudStorageValidationRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest)3 ObjectStorageValidateRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)2 TelemetryRequest (com.sequenceiq.common.api.telemetry.request.TelemetryRequest)2 Credential (com.sequenceiq.environment.credential.domain.Credential)2 Test (org.junit.jupiter.api.Test)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 BackupRequest (com.sequenceiq.common.api.backup.request.BackupRequest)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 EnvironmentServiceException (com.sequenceiq.environment.exception.EnvironmentServiceException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1