use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenPrivateEndpointAndPrivateEndpointNetworkPoliciesDisabled.
@Test
void testValidateDuringFlowWhenPrivateEndpointAndPrivateEndpointNetworkPoliciesDisabled() {
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
AzureParams azureParams = getAzureParams("", "networkResourceGroupName");
NetworkDto networkDto = getNetworkDto(azureParams);
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(false));
when(azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(any())).thenCallRealMethod();
EnvironmentValidationDto environmentValidationDto = environmentValidationDtoWithSingleRg(MY_SINGLE_RG, ResourceGroupUsagePattern.USE_SINGLE);
underTest.validateDuringFlow(environmentValidationDto, networkDto, validationResultBuilder);
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenEnvironmentIsBeingEditedThenPrivateEndpointValidationsSkipped.
@Test
void testValidateDuringFlowWhenEnvironmentIsBeingEditedThenPrivateEndpointValidationsSkipped() {
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
AzureParams azureParams = getAzureParams("", "networkResourceGroupName");
NetworkDto networkDto = getNetworkDto(azureParams);
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(false));
EnvironmentValidationDto environmentDto = environmentValidationDtoWithSingleRg(MY_SINGLE_RG, ResourceGroupUsagePattern.USE_SINGLE);
environmentDto.setValidationType(ValidationType.ENVIRONMENT_EDIT);
underTest.validateDuringFlow(environmentDto, networkDto, validationResultBuilder);
verify(azureNetworkLinkService, never()).validateExistingNetworkLink(any(), any(), any());
verify(azureCloudSubnetParametersService, never()).isPrivateEndpointNetworkPoliciesDisabled(any());
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenTheAzureNetworkParamsDoesNotContainNetworkId.
@Test
void testValidateDuringRequestWhenTheAzureNetworkParamsDoesNotContainNetworkId() {
AzureParams azureParams = NetworkTestUtils.getAzureParams(true, false, true);
NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, 1);
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
underTest.validateDuringRequest(networkDto, validationResultBuilder);
NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("If resourceGroupName is specified, then networkId must be specified too.", "Either the AZURE network id or cidr needs to be defined!", "If subnetIds are specified, then networkId must be specified too."));
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder 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.ValidationResultBuilder in project cloudbreak by hortonworks.
the class SdxService method validateInternalSdxRequest.
private void validateInternalSdxRequest(StackV4Request stackv4Request, SdxClusterShape clusterShape) {
ValidationResultBuilder validationResultBuilder = ValidationResult.builder();
if (stackv4Request != null) {
if (!clusterShape.equals(CUSTOM)) {
validationResultBuilder.error("Cluster shape '" + clusterShape + "' is not accepted on SDX Internal API. Use 'CUSTOM' cluster shape");
}
if (stackv4Request.getCluster() == null) {
validationResultBuilder.error("Cluster cannot be null.");
}
}
ValidationResult validationResult = validationResultBuilder.build();
if (validationResult.hasError()) {
LOGGER.error("Cannot create SDX via internal API: {}", validationResult.getFormattedErrors());
throw new BadRequestException(validationResult.getFormattedErrors());
}
}
Aggregations