Search in sources :

Example 16 with ValidationResultBuilder

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

the class GatewayV4RequestValidator method validate.

@Override
public ValidationResult validate(GatewayV4Request subject) {
    ValidationResultBuilder validationResultBuilder = ValidationResult.builder();
    if (CollectionUtils.isEmpty(subject.getTopologies())) {
        return validationResultBuilder.error("No topology is defined in gateway request. Please define a topology in " + "'gateway.topologies'.").build();
    }
    validateTopologyNames(subject, validationResultBuilder);
    return validationResultBuilder.build();
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)

Example 17 with ValidationResultBuilder

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

the class InstanceTemplateValidator method validate.

@Override
public ValidationResult validate(Template subject) {
    ValidationResultBuilder resultBuilder = ValidationResult.builder();
    if (Objects.isNull(subject)) {
        resultBuilder.error("Template cannot be null in the instance group request.");
    } else {
        resultBuilder.ifError(() -> subject.getRootVolumeSize() != null && subject.getRootVolumeSize() < 1, "Root volume size cannot be smaller than 1 gigabyte.");
    }
    validateNumberOfVolumes(subject, resultBuilder);
    return resultBuilder.build();
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)

Example 18 with ValidationResultBuilder

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

the class EndpointGatewayNetworkValidator method validate.

@Override
public ValidationResult validate(Pair<String, EnvironmentNetworkResponse> subject) {
    String baseSubnetId = subject.getLeft();
    EnvironmentNetworkResponse network = subject.getRight();
    ValidationResultBuilder resultBuilder = ValidationResult.builder();
    if (network == null) {
        LOGGER.debug("No network provided; public endpoint access gateway is disabled.");
    } else {
        if (PublicEndpointAccessGateway.ENABLED.equals(network.getPublicEndpointAccessGateway())) {
            if (Strings.isNullOrEmpty(baseSubnetId)) {
                resultBuilder.error(NO_BASE_SUBNET);
            } else {
                Optional<CloudSubnet> baseSubnet = subnetSelector.findSubnetById(network.getSubnetMetas(), baseSubnetId);
                if (baseSubnet.isEmpty()) {
                    resultBuilder.error(String.format(NO_BASE_SUBNET_META, baseSubnetId));
                } else {
                    String error;
                    if (!MapUtils.isEmpty(network.getGatewayEndpointSubnetMetas())) {
                        LOGGER.debug("Attempting to validate endpoint gateway subnet using provided endpoint subnets.");
                        error = NO_USABLE_SUBNET_IN_ENDPOINT_GATEWAY;
                    } else {
                        LOGGER.debug("Attempting to validate endpoint gateway subnet using cluster subnets.");
                        error = NO_USABLE_SUBNET_IN_CLUSTER;
                    }
                    Optional<CloudSubnet> endpointGatewaySubnet = subnetSelector.chooseSubnetForEndpointGateway(network, baseSubnetId);
                    resultBuilder.ifError(endpointGatewaySubnet::isEmpty, String.format(error, baseSubnet.get().getAvailabilityZone()));
                }
            }
        }
    }
    return resultBuilder.build();
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 19 with ValidationResultBuilder

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

the class GatewayTopologyV4RequestToGatewayTopologyConverterTest method testConvertWithValidationError.

@Test
public void testConvertWithValidationError() {
    GatewayTopologyV4Request gatewayTopologyJson = new GatewayTopologyV4Request();
    gatewayTopologyJson.setExposedServices(Collections.singletonList(exposedService("CLOUDERA_MANAGER_UI").getKnoxService()));
    when(gatewayTopologyV4RequestValidator.validate(any(GatewayTopologyV4Request.class))).thenReturn(new ValidationResultBuilder().error("INVALID").build());
    thrown.expect(BadRequestException.class);
    underTest.convert(gatewayTopologyJson);
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) GatewayTopologyV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request) Test(org.junit.Test)

Example 20 with ValidationResultBuilder

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

the class GatewayTopologyV4RequestToGatewayTopologyConverterTest method testConvert.

@Test
public void testConvert() throws IOException {
    GatewayTopologyV4Request gatewayTopologyJson = new GatewayTopologyV4Request();
    gatewayTopologyJson.setTopologyName(TOPOLOGY_NAME);
    List<String> allServices = Collections.singletonList("ALL");
    ExposedServices exposedServices = new ExposedServices();
    exposedServices.setServices(allServices);
    gatewayTopologyJson.setExposedServices(allServices);
    when(gatewayTopologyV4RequestValidator.validate(any(GatewayTopologyV4Request.class))).thenReturn(new ValidationResultBuilder().build());
    when(gatewayTopologyV4RequestToExposedServicesConverter.convert(any(GatewayTopologyV4Request.class))).thenReturn(exposedServices);
    GatewayTopology result = underTest.convert(gatewayTopologyJson);
    assertEquals(TOPOLOGY_NAME, result.getTopologyName());
    assertTrue(result.getExposedServices().get(ExposedServices.class).getServices().contains("ALL"));
// assertTrue(result.getExposedServices().get(ExposedServices.class).getFullServiceList().containsAll(ExposedService.getAllKnoxExposed()));
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) GatewayTopologyV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request) ExposedServices(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.ExposedServices) GatewayTopology(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.GatewayTopology) Test(org.junit.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