Search in sources :

Example 1 with ValidationResult

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();
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) CredentialService(com.sequenceiq.environment.credential.service.CredentialService) EnvironmentResourceService(com.sequenceiq.environment.environment.service.EnvironmentResourceService) TagValidator(com.sequenceiq.environment.environment.validation.validators.TagValidator) PublicKeyValidator(com.sequenceiq.environment.environment.validation.validators.PublicKeyValidator) LoggerFactory(org.slf4j.LoggerFactory) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector) StringUtils(org.apache.commons.lang3.StringUtils) AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) EncryptionKeyArnValidator(com.sequenceiq.environment.environment.validation.validators.EncryptionKeyArnValidator) EncryptionKeyUrlValidator(com.sequenceiq.environment.environment.validation.validators.EncryptionKeyUrlValidator) AWS(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AWS) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) NetworkCreationValidator(com.sequenceiq.environment.environment.validation.validators.NetworkCreationValidator) Matcher(java.util.regex.Matcher) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Map(java.util.Map) FreeIpaCreationAwsSpotParametersDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationAwsSpotParametersDto) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) ENVIRONMENT(com.sequenceiq.common.model.CredentialType.ENVIRONMENT) BadRequestException(javax.ws.rs.BadRequestException) EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EncryptionKeyValidator(com.sequenceiq.environment.environment.validation.validators.EncryptionKeyValidator) Logger(org.slf4j.Logger) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) SecurityGroupSeparator.getSecurityGroupIds(com.sequenceiq.cloudbreak.util.SecurityGroupSeparator.getSecurityGroupIds) PlatformParameterService(com.sequenceiq.environment.platformresource.PlatformParameterService) Set(java.util.Set) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) S3GuardRequestParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) FreeIpaCreationAwsParametersDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationAwsParametersDto) Optional(java.util.Optional) GCP(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.GCP) Pattern(java.util.regex.Pattern) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 2 with ValidationResult

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

Example 3 with ValidationResult

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

Example 4 with ValidationResult

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();
}
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 5 with ValidationResult

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());
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Benchmark.multiCheckedMeasure(com.sequenceiq.cloudbreak.util.Benchmark.multiCheckedMeasure) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Aggregations

ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)305 Test (org.junit.jupiter.api.Test)186 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)69 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)66 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)45 Test (org.junit.Test)45 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)39 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)26 Environment (com.sequenceiq.environment.environment.domain.Environment)24 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)23 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)21 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 SpiFileSystem (com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)16 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)14 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)14 BadRequestException (javax.ws.rs.BadRequestException)14 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)13 SdxClusterResponse (com.sequenceiq.sdx.api.model.SdxClusterResponse)10 PrivateZone (com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone)9 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)8