Search in sources :

Example 11 with ValidationResultBuilder

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());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) Test(org.junit.jupiter.api.Test)

Example 12 with ValidationResultBuilder

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());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) Test(org.junit.jupiter.api.Test)

Example 13 with ValidationResultBuilder

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."));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Test(org.junit.jupiter.api.Test)

Example 14 with ValidationResultBuilder

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();
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) AvailabilityZoneId(com.microsoft.azure.management.resources.fluentcore.arm.AvailabilityZoneId) ComputeManager(com.microsoft.azure.management.compute.implementation.ComputeManager) RoleAssignments(com.microsoft.azure.management.graphrbac.RoleAssignments) ProviderAuthenticationFailedException(com.sequenceiq.cloudbreak.client.ProviderAuthenticationFailedException) LoadBalancingRule(com.microsoft.azure.management.network.LoadBalancingRule) PrivateZone(com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone) Azure(com.microsoft.azure.management.Azure) DiskEncryptionSetsInner(com.microsoft.azure.management.compute.implementation.DiskEncryptionSetsInner) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Map(java.util.Map) ProvisioningState(com.microsoft.azure.management.storage.ProvisioningState) AzureAuthExceptionHandler(com.sequenceiq.cloudbreak.cloud.azure.util.AzureAuthExceptionHandler) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) CachingTypes(com.microsoft.azure.management.compute.CachingTypes) Set(java.util.Set) CopyState(com.microsoft.azure.storage.blob.CopyState) StorageAccountSkuType(com.microsoft.azure.management.storage.StorageAccountSkuType) Disk(com.microsoft.azure.management.compute.Disk) InvalidKeyException(java.security.InvalidKeyException) DiskInner(com.microsoft.azure.management.compute.implementation.DiskInner) RoleAssignmentInner(com.microsoft.azure.management.graphrbac.implementation.RoleAssignmentInner) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) Completable(rx.Completable) StorageAccount(com.microsoft.azure.management.storage.StorageAccount) AzureStatusMapper(com.sequenceiq.cloudbreak.cloud.azure.status.AzureStatusMapper) VirtualMachineDataDisk(com.microsoft.azure.management.compute.VirtualMachineDataDisk) OperatingSystemStateTypes(com.microsoft.azure.management.compute.OperatingSystemStateTypes) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Strings(com.google.common.base.Strings) StorageException(com.microsoft.azure.storage.StorageException) LoadBalancer(com.microsoft.azure.management.network.LoadBalancer) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Subscription(com.microsoft.azure.management.resources.Subscription) EncryptionSetIdentity(com.microsoft.azure.management.compute.EncryptionSetIdentity) AzureMarketplaceImage(com.sequenceiq.cloudbreak.cloud.azure.image.marketplace.AzureMarketplaceImage) IOException(java.io.IOException) StorageAccounts(com.microsoft.azure.management.storage.StorageAccounts) SourceVault(com.microsoft.azure.management.compute.SourceVault) MarketplaceOrderingManager(com.microsoft.azure.management.marketplaceordering.v2015_06_01.implementation.MarketplaceOrderingManager) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Identity(com.microsoft.azure.management.msi.Identity) Encryption(com.microsoft.azure.management.compute.Encryption) WithCreate(com.microsoft.azure.management.storage.StorageAccount.DefinitionStages.WithCreate) NetworkSecurityGroups(com.microsoft.azure.management.network.NetworkSecurityGroups) ResourceGroups(com.microsoft.azure.management.resources.ResourceGroups) FrontendIPConfigurationInner(com.microsoft.azure.management.network.implementation.FrontendIPConfigurationInner) STANDARD_LRS(com.microsoft.azure.management.compute.DiskSkuTypes.STANDARD_LRS) DiskEncryptionSetIdentityType(com.microsoft.azure.management.compute.DiskEncryptionSetIdentityType) DeploymentOperations(com.microsoft.azure.management.resources.DeploymentOperations) URI(java.net.URI) Vault(com.microsoft.azure.management.keyvault.Vault) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) AvailabilitySet(com.microsoft.azure.management.compute.AvailabilitySet) LoadBalancerFrontend(com.microsoft.azure.management.network.LoadBalancerFrontend) Collection(java.util.Collection) com.microsoft.azure.management.privatedns.v2018_09_01.implementation.privatednsManager(com.microsoft.azure.management.privatedns.v2018_09_01.implementation.privatednsManager) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) AzureDiskType(com.sequenceiq.cloudbreak.cloud.azure.AzureDiskType) Collectors(java.util.stream.Collectors) DiskStorageAccountTypes(com.microsoft.azure.management.compute.DiskStorageAccountTypes) Objects(java.util.Objects) AgreementTerms(com.microsoft.azure.management.marketplaceordering.v2015_06_01.AgreementTerms) List(java.util.List) VirtualNetworkLinkState(com.microsoft.azure.management.privatedns.v2018_09_01.VirtualNetworkLinkState) IndexableRefreshableWrapperImpl(com.microsoft.azure.management.resources.fluentcore.model.implementation.IndexableRefreshableWrapperImpl) NetworkInterfaces(com.microsoft.azure.management.network.NetworkInterfaces) CloudBlockBlob(com.microsoft.azure.storage.blob.CloudBlockBlob) Optional(java.util.Optional) VirtualMachineCustomImage(com.microsoft.azure.management.compute.VirtualMachineCustomImage) AccessPolicy(com.microsoft.azure.management.keyvault.AccessPolicy) AzurePrivateDnsZoneServiceEnum(com.sequenceiq.cloudbreak.cloud.azure.AzurePrivateDnsZoneServiceEnum) HasId(com.microsoft.azure.management.resources.fluentcore.arm.models.HasId) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) VirtualMachineInstanceView(com.microsoft.azure.management.compute.VirtualMachineInstanceView) Subnet(com.microsoft.azure.management.network.Subnet) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) Kind(com.microsoft.azure.management.storage.Kind) Observable(rx.Observable) HashSet(java.util.HashSet) Network(com.microsoft.azure.management.network.Network) DeploymentMode(com.microsoft.azure.management.resources.DeploymentMode) VirtualNetworkLinkInner(com.microsoft.azure.management.privatedns.v2018_09_01.implementation.VirtualNetworkLinkInner) PREMIUM_LRS(com.microsoft.azure.management.compute.DiskSkuTypes.PREMIUM_LRS) PagedList(com.microsoft.azure.PagedList) DiskEncryptionSetType(com.microsoft.azure.management.compute.DiskEncryptionSetType) KeyPermissions(com.microsoft.azure.management.keyvault.KeyPermissions) AccessPolicyEntry(com.microsoft.azure.management.keyvault.AccessPolicyEntry) Collections.emptyMap(java.util.Collections.emptyMap) Deployment(com.microsoft.azure.management.resources.Deployment) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) DiskSkuTypes(com.microsoft.azure.management.compute.DiskSkuTypes) StorageAccountKey(com.microsoft.azure.management.storage.StorageAccountKey) KeyForDiskEncryptionSet(com.microsoft.azure.management.compute.KeyForDiskEncryptionSet) ULTRA_SSD_LRS(com.microsoft.azure.management.compute.DiskSkuTypes.ULTRA_SSD_LRS) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) CloudException(com.microsoft.azure.CloudException) STANDARD_SSD_LRS(com.microsoft.azure.management.compute.DiskSkuTypes.STANDARD_SSD_LRS) RoleAssignment(com.microsoft.azure.management.graphrbac.RoleAssignment) StorageAccountInner(com.microsoft.azure.management.storage.implementation.StorageAccountInner) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SUCCEEDED(com.microsoft.azure.management.privatedns.v2018_09_01.ProvisioningState.SUCCEEDED) Collections(java.util.Collections) DiskEncryptionSetInner(com.microsoft.azure.management.compute.implementation.DiskEncryptionSetInner) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) AzurePrivateDnsZoneServiceEnum(com.sequenceiq.cloudbreak.cloud.azure.AzurePrivateDnsZoneServiceEnum) PrivateZone(com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone)

Example 15 with ValidationResultBuilder

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());
    }
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

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