use of com.sequenceiq.cloudbreak.validation.ValidationResult in project cloudbreak by hortonworks.
the class EnvironmentValidatorService method validateEncryptionKey.
public ValidationResult validateEncryptionKey(EnvironmentCreationDto creationDto) {
ValidationResultBuilder resultBuilder = ValidationResult.builder();
if (GCP.name().equalsIgnoreCase(creationDto.getCloudPlatform())) {
String encryptionKey = Optional.ofNullable(creationDto.getParameters()).map(parametersDto -> parametersDto.getGcpParametersDto()).map(gcpParametersDto -> gcpParametersDto.getGcpResourceEncryptionParametersDto()).map(gcpREParamsDto -> gcpREParamsDto.getEncryptionKey()).orElse(null);
if (StringUtils.isNotEmpty(encryptionKey)) {
if (!entitlementService.isGcpDiskEncryptionWithCMEKEnabled(creationDto.getAccountId())) {
resultBuilder.error(String.format("You have specified encryption-key to enable encryption for GCP resources with CMEK " + "but that feature is currently not enabled for this account." + " Please get 'CDP_CB_GCP_DISK_ENCRYPTION_WITH_CMEK' enabled for this account."));
} else {
ValidationResult validationResult = encryptionKeyValidator.validateEncryptionKey(encryptionKey);
resultBuilder.merge(validationResult);
}
}
}
return resultBuilder.build();
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNoNetworkCidrAndNetworkId.
@Test
void testValidateDuringRequestWhenNoNetworkCidrAndNetworkId() {
AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true);
NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, 1);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateDuringRequest(networkDto, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
assertFalse(validationResult.hasError());
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkCidrAndNoAzureParams.
@Test
void testValidateDuringRequestWhenNetworkCidrAndNoAzureParams() {
NetworkDto networkDto = NetworkTestUtils.getNetworkDto(null, null, null, null, "0.0.0.0/0", null);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateDuringRequest(networkDto, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
assertFalse(validationResult.hasError(), validationResult.getFormattedErrors());
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult in project cloudbreak by hortonworks.
the class AzureClient method validateNetworkLinkExistenceForDnsZones.
public ValidationResult validateNetworkLinkExistenceForDnsZones(String networkLinkId, List<AzurePrivateDnsZoneServiceEnum> services, String resourceGroupName) {
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
PagedList<PrivateZone> privateDnsZoneList = getPrivateDnsZoneList();
for (AzurePrivateDnsZoneServiceEnum service : services) {
String dnsZoneName = service.getDnsZoneName();
Optional<PrivateZone> privateZoneWithNetworkLink = privateDnsZoneList.stream().filter(privateZone -> !privateZone.resourceGroupName().equalsIgnoreCase(resourceGroupName)).filter(privateZone -> privateZone.name().equalsIgnoreCase(dnsZoneName)).filter(privateZone -> privateZone.provisioningState().equals(SUCCEEDED)).filter(privateZone -> Objects.nonNull(getNetworkLinkByPrivateDnsZone(privateZone.resourceGroupName(), dnsZoneName, networkLinkId))).findFirst();
if (privateZoneWithNetworkLink.isPresent()) {
PrivateZone privateZone = privateZoneWithNetworkLink.get();
String validationMessage = String.format("Network link for the network %s already exists for Private DNS Zone %s in resource group %s. " + "Please ensure that there is no existing network link and try again!", networkLinkId, dnsZoneName, privateZone.resourceGroupName());
LOGGER.warn(validationMessage);
resultBuilder.error(validationMessage);
}
}
return resultBuilder.build();
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult in project cloudbreak by hortonworks.
the class ClusterCreationSetupService method validate.
@Measure(ClusterCreationSetupService.class)
public void validate(ClusterV4Request request, CloudCredential cloudCredential, Stack stack, User user, Workspace workspace, DetailedEnvironmentResponse environment) {
MdcContext.builder().userCrn(user.getUserCrn()).tenant(user.getTenant().getName()).buildMdc();
CloudCredential credential = cloudCredential;
if (credential == null) {
credential = stackUtil.getCloudCredential(stack);
}
fileSystemValidator.validate(stack.cloudPlatform(), credential, request.getCloudStorage(), stack.getWorkspace().getId());
rdsConfigValidator.validateRdsConfigs(request, user, workspace);
ValidationResult.ValidationResultBuilder resultBuilder = ValidationResult.builder();
environmentValidator.validateRdsConfigNames(request.getDatabases(), resultBuilder, stack.getWorkspace().getId());
environmentValidator.validateProxyConfig(request.getProxyConfigCrn(), resultBuilder);
String parentEnvironmentCloudPlatform = environment.getParentEnvironmentCloudPlatform();
environmentValidator.validateAutoTls(request, stack, resultBuilder, parentEnvironmentCloudPlatform);
ValidationResult build = resultBuilder.build();
if (build.hasError()) {
throw new BadRequestException(build.getFormattedErrors());
}
}
Aggregations