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