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