Search in sources :

Example 51 with ValidationResultBuilder

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

the class EnvironmentValidatorService method validateSecurityAccessModification.

public ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment) {
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    resultBuilder.ifError(() -> isNotEmpty(securityAccessDto.getCidr()), "The CIDR could not be updated in the environment");
    resultBuilder.ifError(() -> isNotEmpty(environment.getCidr()) && isAnySecurityGroupMissing(securityAccessDto), "The CIDR can be replaced with the default and knox security groups, please add to the request");
    resultBuilder.ifError(() -> isAllSecurityGroupMissing(securityAccessDto), "Please add the default or knox security groups, we cannot edit with empty value.");
    return resultBuilder.build();
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)

Example 52 with ValidationResultBuilder

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

the class EnvironmentValidatorService method validateAuthenticationModification.

public ValidationResult validateAuthenticationModification(EnvironmentEditDto editDto, Environment environment) {
    ValidationResultBuilder validationResultBuilder = ValidationResult.builder();
    AuthenticationDto authenticationDto = editDto.getAuthentication();
    String publicKeyId = authenticationDto.getPublicKeyId();
    Optional<PublicKeyConnector> publicKeyConnector = environmentResourceService.getPublicKeyConnector(environment.getCloudPlatform());
    if (publicKeyConnector.isEmpty() && isNotEmpty(publicKeyId)) {
        validationResultBuilder.error("The change of publicKeyId is not supported on " + environment.getCloudPlatform());
    } else {
        String publicKey = authenticationDto.getPublicKey();
        if (isNotEmpty(publicKeyId) && isNotEmpty(publicKey)) {
            validationResultBuilder.error("You should define either publicKey or publicKeyId only, but not both.");
        }
        if (StringUtils.isEmpty(publicKeyId) && StringUtils.isEmpty(publicKey)) {
            validationResultBuilder.error("You should define either the publicKey or the publicKeyId.");
        }
        if (isNotEmpty(publicKeyId) && !environmentResourceService.isPublicKeyIdExists(environment, publicKeyId)) {
            validationResultBuilder.error(String.format("The publicKeyId with name of '%s' does not exist on the provider.", publicKeyId));
        }
        if (isNotEmpty(publicKey)) {
            ValidationResult validationResult = publicKeyValidator.validatePublicKey(publicKey);
            validationResultBuilder.merge(validationResult);
        }
    }
    return validationResultBuilder.build();
}
Also used : AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 53 with ValidationResultBuilder

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

the class EnvironmentLogStorageLocationValidator method validateTelemetryLoggingStorageLocation.

/**
 * Validate telemetry related logging storage location.
 * Currently, filter out cloudwatch (or any other cloud logging service) related validations
 */
public ValidationResult validateTelemetryLoggingStorageLocation(Environment environment) {
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    Optional.ofNullable(environment.getTelemetry()).map(EnvironmentTelemetry::getLogging).filter(logging -> isCloudStorageEnabled(logging) && logging.getCloudwatch() == null).map(EnvironmentLogging::getStorageLocation).ifPresent(location -> cloudStorageLocationValidator.validate(location, environment, resultBuilder));
    return resultBuilder.build();
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)

Example 54 with ValidationResultBuilder

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

the class EnvironmentNetworkProviderValidator method validate.

public ValidationResult validate(EnvironmentValidationDto environmentValidationDto) {
    EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
    NetworkDto network = environmentDto.getNetwork();
    String cloudPlatform = environmentDto.getCloudPlatform();
    ValidationResultBuilder resultBuilder = ValidationResult.builder();
    validateNetworkHasTheSamePropertyFilledAsTheDesiredCloudPlatform(network, cloudPlatform, resultBuilder);
    validateNetwork(network, cloudPlatform, resultBuilder, environmentValidationDto);
    validateSecurityGroup(environmentValidationDto, cloudPlatform, resultBuilder);
    return resultBuilder.build();
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)

Example 55 with ValidationResultBuilder

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

the class EnvironmentRegionValidator method validateLocation.

public ValidationResultBuilder validateLocation(String requestedLocation, Set<String> requestedRegions, CloudRegions cloudRegions, String cloudPlatform) {
    ValidationResultBuilder resultBuilder = ValidationResult.builder();
    Set<String> requestedRegionNames = new HashSet<>(requestedRegions);
    if (!requestedRegionNames.isEmpty() && !requestedRegionNames.contains(requestedLocation) && cloudRegions.areRegionsSupported()) {
        if (!CloudPlatform.MOCK.equalsIgnoreCase(cloudPlatform)) {
            resultBuilder.error(String.format("Location [%s] is not one of the regions: [%s].", requestedLocation, String.join(", ", requestedRegionNames)));
        }
    }
    return resultBuilder;
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) HashSet(java.util.HashSet)

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