Search in sources :

Example 61 with ValidationResultBuilder

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

the class EnvironmentValidationHandlerTest method acceptAndSendStartNetworkCreationEventWhenNoValidationErrorFound.

@Test
void acceptAndSendStartNetworkCreationEventWhenNoValidationErrorFound() {
    EnvironmentValidationDto environmentValidationDto = createEnvironmentValidationDto();
    Environment environment = new Environment();
    when(environmentService.findEnvironmentById(anyLong())).thenReturn(Optional.of(environment));
    when(validatorService.validateRegionsAndLocation(any(), any(), eq(environment), any())).thenReturn(new ValidationResultBuilder());
    when(cloudStorageValidator.validateCloudStorage(any(), any())).thenReturn(ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build());
    underTest.accept(Event.wrap(environmentValidationDto));
    verify(eventSender, times(1)).sendEvent(any(EnvCreationEvent.class), any());
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) Test(org.junit.jupiter.api.Test)

Example 62 with ValidationResultBuilder

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

the class AwsCredentialValidatorTest method testKeyBasedToRoleBased.

@Test
public void testKeyBasedToRoleBased() {
    Credential original = new Credential();
    ObjectNode rootOriginal = getAwsAttributes();
    putKeyBased(rootOriginal);
    original.setAttributes(rootOriginal.toString());
    Credential newCred = new Credential();
    ObjectNode rootNew = getAwsAttributes();
    putRoleBased(rootNew);
    newCred.setAttributes(rootNew.toString());
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    ValidationResult result = awsCredentialValidator.validateUpdate(original, newCred, resultBuilder);
    assertEquals(1, result.getErrors().size());
    assertThat(result.getErrors().get(0), CoreMatchers.containsString("Cannot change AWS credential from key based to role based."));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 63 with ValidationResultBuilder

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

the class AwsCredentialValidatorTest method testWithMissingAwsAttributes.

@Test
public void testWithMissingAwsAttributes() {
    Credential original = new Credential();
    ObjectNode rootOriginal = getAwsAttributes();
    putRoleBased(rootOriginal);
    original.setAttributes(rootOriginal.toString());
    Credential newCred = new Credential();
    newCred.setAttributes(objectMapper.createObjectNode().toString());
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    ValidationResult result = awsCredentialValidator.validateUpdate(original, newCred, resultBuilder);
    assertEquals(1, result.getErrors().size());
    assertThat(result.getErrors().get(0), CoreMatchers.containsString("Missing attributes from the JSON!"));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 64 with ValidationResultBuilder

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

the class EnvironmentCreationService method validateCreation.

private void validateCreation(EnvironmentCreationDto creationDto, Environment environment) {
    LOGGER.info("Validating environment creation. CreationDto: '{}', Environment: '{}'.", creationDto, environment);
    ValidationResultBuilder validationBuilder = validatorService.validateNetworkCreation(environment, creationDto.getNetwork());
    validationBuilder.merge(validatorService.validatePublicKey(creationDto.getAuthentication().getPublicKey()));
    validationBuilder.merge(validatorService.validateTags(creationDto));
    if (creationDto.getCloudPlatform() != null) {
        validationBuilder.merge(validateEncryptionKey(creationDto));
    }
    ValidationResult parentChildValidation = validatorService.validateParentChildRelation(environment, creationDto.getParentEnvironmentName());
    validationBuilder.merge(parentChildValidation);
    EnvironmentTelemetry environmentTelemetry = creationDto.getTelemetry();
    if (environmentTelemetry != null && environmentTelemetry.getLogging() != null && environmentTelemetry.getLogging().getStorageLocation() != null) {
        validationBuilder.merge(validatorService.validateStorageLocation(environmentTelemetry.getLogging().getStorageLocation(), "logging"));
    }
    validationBuilder.ifError(() -> isCloudPlatformInvalid(creationDto.getCreator(), creationDto.getCloudPlatform()), "Provisioning in " + creationDto.getCloudPlatform() + " is not enabled for this account.");
    ValidationResult freeIpaCreationValidation = validatorService.validateFreeIpaCreation(creationDto.getFreeIpaCreation());
    validationBuilder.merge(freeIpaCreationValidation);
    ValidationResult validationResult = validationBuilder.build();
    if (validationResult.hasError()) {
        throw new BadRequestException(validationResult.getFormattedErrors());
    }
}
Also used : EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) BadRequestException(javax.ws.rs.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 65 with ValidationResultBuilder

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

the class NetworkService method validate.

public BaseNetwork validate(BaseNetwork originalNetwork, EnvironmentEditDto editDto, Environment environment) {
    CloudPlatform cloudPlatform = CloudPlatform.valueOf(environment.getCloudPlatform());
    if (originalNetwork.getRegistrationType() == RegistrationType.CREATE_NEW) {
        throw new BadRequestException("Subnets of this environment could not be modified, because its network has been created by Cloudera. " + "You need to re-install the environment into an existing VPC/VNet." + getDocLink(cloudPlatform));
    }
    EnvironmentNetworkConverter environmentNetworkConverter = environmentNetworkConverterMap.get(cloudPlatform);
    NetworkDto originalNetworkDto = environmentNetworkConverter.convertToDto(originalNetwork);
    NetworkDto cloneNetworkDto = NetworkDto.builder(originalNetworkDto).withSubnetMetas(editDto.getNetworkDto().getSubnetMetas()).build();
    ValidationResultBuilder validationResultBuilder = networkCreationValidator.validateNetworkEdit(environment, cloneNetworkDto);
    ValidationResult validationResult = validationResultBuilder.build();
    if (validationResult.hasError()) {
        throw new BadRequestException(validationResult.getFormattedErrors());
    }
    return originalNetwork;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)

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