Search in sources :

Example 71 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class SdxService method validateBaseLocation.

ValidationResult validateBaseLocation(String baseLocation) {
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    if (baseLocation != null) {
        Pattern pattern = Pattern.compile("\\s");
        Matcher matcher = pattern.matcher(baseLocation.trim());
        if (matcher.find()) {
            resultBuilder.error("You have added some whitespace to the base location: " + baseLocation);
        }
    } else {
        LOGGER.debug("Cannot validate the base location, because it's null");
    }
    return resultBuilder.build();
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)

Example 72 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class StackRequestManifester method validateCloudStorageLocation.

private void validateCloudStorageLocation(SdxCluster sdxCluster, DetailedEnvironmentResponse environment) {
    if (FileSystemType.S3.equals(sdxCluster.getCloudStorageFileSystemType()) && !Strings.isNullOrEmpty(sdxCluster.getCloudStorageBaseLocation())) {
        ValidationResultBuilder validationBuilder = new ValidationResultBuilder();
        cloudStorageLocationValidator.validate(sdxCluster.getCloudStorageBaseLocation(), FileSystemType.S3, environment, validationBuilder);
        ValidationResult validationResult = validationBuilder.build();
        if (validationResult.hasError()) {
            throw new BadRequestException(validationResult.getFormattedErrors());
        }
    }
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 73 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class StackRequestManifester method validateCloudStorageAndHandleTimeout.

private void validateCloudStorageAndHandleTimeout(SdxCluster sdxCluster, DetailedEnvironmentResponse environment, StackV4Request stackRequest) {
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    try {
        cloudStorageValidator.validate(stackRequest.getCluster().getCloudStorage(), environment, validationResultBuilder);
    } catch (Exception e) {
        String message = String.format("Error occured during object storage validation, validation skipped. Error: %s", e.getMessage());
        LOGGER.warn(message);
        sdxNotificationService.send(ResourceEvent.SDX_VALIDATION_FAILED_AND_SKIPPED, Set.of(e.getMessage()), sdxCluster);
    }
    ValidationResult validationResult = validationResultBuilder.build();
    if (validationResult.hasError()) {
        throw new BadRequestException(validationResult.getFormattedErrors());
    }
    if (validationResult.hasWarning()) {
        LOGGER.info(validationResult.getFormattedWarnings());
        eventSenderService.sendEventAndNotification(sdxCluster, sdxCluster.getInitiatorUserCrn(), ResourceEvent.SDX_VALIDATION_FAILED_AND_SKIPPED, Set.of(validationResult.getFormattedWarnings()));
        sdxNotificationService.send(ResourceEvent.SDX_VALIDATION_FAILED_AND_SKIPPED, Set.of(validationResult.getFormattedWarnings()), sdxCluster);
    }
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) IdbmmsOperationException(com.sequenceiq.cloudbreak.idbmms.exception.IdbmmsOperationException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 74 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class AwsIamServiceTest method missingInstanceProfile.

@Test
public void missingInstanceProfile() {
    when(iam.getInstanceProfile(any(GetInstanceProfileRequest.class))).thenThrow(NoSuchEntityException.class);
    String instanceProfileArn = "account/missingInstanceProfile";
    ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder();
    InstanceProfile instanceProfile = awsIamService.getInstanceProfile(iam, instanceProfileArn, CloudIdentityType.ID_BROKER, validationRequestBuilder);
    assertThat(instanceProfile).isNull();
    ValidationResult validationResult = validationRequestBuilder.build();
    assertThat(validationResult.hasError()).isTrue();
    assertThat(validationResult.getErrors()).isEqualTo(Collections.singletonList(String.format("Instance profile (%s) doesn't exists on AWS side. " + "Please check if you've used the correct Instance profile when setting up Data Access.", instanceProfileArn)));
}
Also used : GetInstanceProfileRequest(com.amazonaws.services.identitymanagement.model.GetInstanceProfileRequest) InstanceProfile(com.amazonaws.services.identitymanagement.model.InstanceProfile) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 75 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class AwsIamServiceTest method validRole.

@Test
public void validRole() {
    String roleArn = "account/validRole";
    Role expectedRole = new Role().withArn(roleArn);
    GetRoleResult getRoleResult = mock(GetRoleResult.class);
    when(getRoleResult.getRole()).thenReturn(expectedRole);
    when(iam.getRole(any(GetRoleRequest.class))).thenReturn(getRoleResult);
    ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder();
    Role role = awsIamService.getRole(iam, roleArn, validationRequestBuilder);
    assertThat(role.getArn()).isEqualTo(roleArn);
    assertThat(validationRequestBuilder.build().hasError()).isFalse();
}
Also used : Role(com.amazonaws.services.identitymanagement.model.Role) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) GetRoleRequest(com.amazonaws.services.identitymanagement.model.GetRoleRequest) GetRoleResult(com.amazonaws.services.identitymanagement.model.GetRoleResult) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)169 Test (org.junit.jupiter.api.Test)107 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)67 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)62 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)35 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)33 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)33 Test (org.junit.Test)20 SpiFileSystem (com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)16 Environment (com.sequenceiq.environment.environment.domain.Environment)11 ObjectStorageMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)10 ObjectStorageMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse)10 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Credential (com.sequenceiq.environment.credential.domain.Credential)10 Region (com.sequenceiq.environment.environment.domain.Region)9 PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)7 InstanceProfile (com.amazonaws.services.identitymanagement.model.InstanceProfile)6 Role (com.amazonaws.services.identitymanagement.model.Role)6 GatewayTopologyV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request)6