Search in sources :

Example 1 with CloudPlatform

use of com.sequenceiq.cloudbreak.common.mappable.CloudPlatform in project cloudbreak by hortonworks.

the class DistroXEncryptedVolumeTest method verifyVolumeEncryptionKey.

private void verifyVolumeEncryptionKey(CloudPlatform cloudPlatform, String resourceName, List<String> instanceIds, CloudFunctionality cloudFunctionality, String environmentName, String resourceGroupName) {
    if (CloudPlatform.AWS.equals(cloudPlatform)) {
        String kmsKeyArn = awsCloudProvider.getEncryptionKeyArn(true);
        List<String> volumeKmsKeyIds = new ArrayList<>(cloudFunctionality.listVolumeEncryptionKeyIds(resourceName, null, instanceIds));
        if (volumeKmsKeyIds.stream().noneMatch(keyId -> keyId.equalsIgnoreCase(kmsKeyArn))) {
            LOGGER.error(format("Volume has not been encrypted with '%s' KMS key!", kmsKeyArn));
            throw new TestFailException(format("Volume has not been encrypted with '%s' KMS key!", kmsKeyArn));
        } else {
            LOGGER.info(format("Volume has been encrypted with '%s' KMS key.", kmsKeyArn));
            Log.then(LOGGER, format(" Volume has been encrypted with '%s' KMS key. ", kmsKeyArn));
        }
    } else if (CloudPlatform.AZURE.equals(cloudPlatform)) {
        String desKeyUrl = azureCloudProvider.getEncryptionKeyUrl();
        List<String> volumesDesId = new ArrayList<>(cloudFunctionality.listVolumeEncryptionKeyIds(resourceName, resourceGroupName, instanceIds));
        volumesDesId.forEach(desId -> {
            if (desId.contains("diskEncryptionSets/" + environmentName)) {
                LOGGER.info(format("Volume has been encrypted with '%s' DES key.", desId));
                Log.then(LOGGER, format(" Volume has been encrypted with '%s' DES key. ", desId));
            } else {
                LOGGER.error(format("Volume has not been encrypted with '%s' key!", desKeyUrl));
                throw new TestFailException(format("Volume has not been encrypted with '%s' key!", desKeyUrl));
            }
        });
    } else {
        LOGGER.warn(format("Disk encryption feature is not available at '%s' currently!", cloudPlatform));
    }
}
Also used : AwsCloudProvider(com.sequenceiq.it.cloudbreak.cloud.v4.aws.AwsCloudProvider) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) LoggerFactory(org.slf4j.LoggerFactory) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) StringUtils(org.apache.commons.lang3.StringUtils) Description(com.sequenceiq.it.cloudbreak.context.Description) EnvironmentNetworkTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentNetworkTestDto) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DistroXInstanceGroupsBuilder(com.sequenceiq.it.cloudbreak.dto.distrox.instancegroup.DistroXInstanceGroupsBuilder) SdxUtil(com.sequenceiq.it.cloudbreak.util.SdxUtil) Tunnel(com.sequenceiq.common.api.type.Tunnel) Status(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status) FreeIpaClient(com.sequenceiq.it.cloudbreak.FreeIpaClient) SdxTestDto(com.sequenceiq.it.cloudbreak.dto.sdx.SdxTestDto) OperationState(com.sequenceiq.freeipa.api.v1.operation.model.OperationState) UseSpotInstances(com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances) String.format(java.lang.String.format) List(java.util.List) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) DistroXExternalDatabaseAssertion.validateTemplateContainsExternalDatabaseHostname(com.sequenceiq.it.cloudbreak.assertion.distrox.DistroXExternalDatabaseAssertion.validateTemplateContainsExternalDatabaseHostname) EnvironmentClient(com.sequenceiq.it.cloudbreak.EnvironmentClient) CloudFunctionality(com.sequenceiq.it.cloudbreak.util.CloudFunctionality) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) SdxClusterStatusResponse(com.sequenceiq.sdx.api.model.SdxClusterStatusResponse) CloudbreakClient(com.sequenceiq.it.cloudbreak.CloudbreakClient) FreeIpaUserSyncTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaUserSyncTestDto) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) TelemetryTestDto(com.sequenceiq.it.cloudbreak.dto.telemetry.TelemetryTestDto) DistroXDatabaseAvailabilityType(com.sequenceiq.distrox.api.v1.distrox.model.database.DistroXDatabaseAvailabilityType) AzureCloudFunctionality(com.sequenceiq.it.cloudbreak.util.azure.AzureCloudFunctionality) HashMap(java.util.HashMap) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) AzureCloudProvider(com.sequenceiq.it.cloudbreak.cloud.v4.azure.AzureCloudProvider) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) ResourceGroupTest(com.sequenceiq.it.cloudbreak.ResourceGroupTest) DistroXInstanceGroupTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.instancegroup.DistroXInstanceGroupTestDto) AwsAvailabilityZoneAssertion(com.sequenceiq.it.cloudbreak.assertion.distrox.AwsAvailabilityZoneAssertion) Logger(org.slf4j.Logger) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) MASTER(com.sequenceiq.it.cloudbreak.cloud.HostGroupType.MASTER) Log(com.sequenceiq.it.cloudbreak.log.Log) SdxTestClient(com.sequenceiq.it.cloudbreak.client.SdxTestClient) SshEnaDriverCheckActions(com.sequenceiq.it.cloudbreak.util.ssh.action.SshEnaDriverCheckActions) FreeIpaInstanceUtil(com.sequenceiq.it.cloudbreak.util.FreeIpaInstanceUtil) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) DistroxUtil(com.sequenceiq.it.cloudbreak.util.DistroxUtil) SdxClient(com.sequenceiq.it.cloudbreak.SdxClient) DistroXDatabaseRequest(com.sequenceiq.distrox.api.v1.distrox.model.database.DistroXDatabaseRequest) ArrayList(java.util.ArrayList) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with CloudPlatform

use of com.sequenceiq.cloudbreak.common.mappable.CloudPlatform in project cloudbreak by hortonworks.

the class ExternalDatabaseService method getDatabaseRequest.

private AllocateDatabaseServerV4Request getDatabaseRequest(DetailedEnvironmentResponse environment, DatabaseAvailabilityType externalDatabase, Cluster cluster) {
    AllocateDatabaseServerV4Request req = new AllocateDatabaseServerV4Request();
    req.setEnvironmentCrn(environment.getCrn());
    CloudPlatform cloudPlatform = CloudPlatform.valueOf(environment.getCloudPlatform().toUpperCase(Locale.US));
    String databaseEngineVersion = Optional.ofNullable(cluster).map(Cluster::getStack).map(Stack::getExternalDatabaseEngineVersion).orElse(null);
    req.setDatabaseServer(getDatabaseServerStackRequest(cloudPlatform, externalDatabase, databaseEngineVersion));
    if (cluster.getStack() != null) {
        req.setClusterCrn(cluster.getStack().getResourceCrn());
        req.setTags(getUserDefinedTags(cluster.getStack()));
    }
    return req;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) AllocateDatabaseServerV4Request(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.requests.AllocateDatabaseServerV4Request) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)

Example 3 with CloudPlatform

use of com.sequenceiq.cloudbreak.common.mappable.CloudPlatform in project cloudbreak by hortonworks.

the class SharedServiceValidator method checkCloudPlatform.

private void checkCloudPlatform(StackV4Request request, Long workspaceId, ValidationResultBuilder resultBuilder) {
    Optional<StackView> datalakeStack = stackViewService.findByName(request.getSharedService().getDatalakeName(), workspaceId);
    if (datalakeStack.isEmpty()) {
        resultBuilder.error("Datalake stack with the requested name (in sharedService/sharedClusterName field) was not found.");
    } else {
        CloudPlatform requestedCloudPlatform = request.getCloudPlatform();
        String datalakeCloudPlatform = datalakeStack.get().cloudPlatform();
        if (!datalakeCloudPlatform.equals(requestedCloudPlatform.name())) {
            resultBuilder.error(String.format("Requested cloud platform [%s] does not match with the datalake" + " cluser's cloud platform [%s].", requestedCloudPlatform, datalakeCloudPlatform));
        }
    }
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) StackView(com.sequenceiq.cloudbreak.domain.view.StackView)

Example 4 with CloudPlatform

use of com.sequenceiq.cloudbreak.common.mappable.CloudPlatform in project cloudbreak by hortonworks.

the class StackToCreateFreeIpaRequestConverter method getNetworkRequest.

private NetworkRequest getNetworkRequest(Network network) {
    NetworkRequest request = null;
    if (network != null) {
        request = new NetworkRequest();
        Optional<CloudPlatform> cloudPlatform = Optional.ofNullable(network.cloudPlatform()).or(() -> Optional.ofNullable(network.getAttributes().getValue(NetworkConstants.CLOUD_PLATFORM))).map(CloudPlatform::valueOf);
        request.setNetworkCidrs(network.getNetworkCidrs());
        request.setOutboundInternetTraffic(network.getOutboundInternetTraffic());
        if (cloudPlatform.isPresent()) {
            LOGGER.debug("Network request has cloud platform {}", cloudPlatform.get());
            request.setCloudPlatform(cloudPlatform.get());
            switch(cloudPlatform.get()) {
                case AWS:
                    request.createAws().parse(network.getAttributes().getMap());
                    break;
                case AZURE:
                    request.createAzure().parse(network.getAttributes().getMap());
                    break;
                case GCP:
                    request.createGcp().parse(network.getAttributes().getMap());
                    break;
                case MOCK:
                    request.createMock().parse(network.getAttributes().getMap());
                    break;
                case YARN:
                    request.createYarn().parse(network.getAttributes().getMap());
                    break;
                default:
                    break;
            }
        }
    }
    LOGGER.debug("Created network request {} from network {}", request, network);
    return request;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) InstanceGroupNetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupNetworkRequest) NetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest)

Example 5 with CloudPlatform

use of com.sequenceiq.cloudbreak.common.mappable.CloudPlatform in project cloudbreak by hortonworks.

the class CreateFreeIpaRequestToStackConverter method getRegion.

private String getRegion(CreateFreeIpaRequest source, String cloudPlatform) {
    if (source.getPlacement() == null) {
        return null;
    }
    if (isEmpty(source.getPlacement().getRegion())) {
        Map<Platform, Region> regions = Maps.newHashMap();
        if (isNotEmpty(defaultRegions)) {
            for (String entry : defaultRegions.split(",")) {
                String[] keyValue = entry.split(":");
                regions.put(platform(keyValue[0]), Region.region(keyValue[1]));
            }
            Region platformRegion = regions.get(platform(cloudPlatform));
            if (platformRegion == null || isEmpty(platformRegion.value())) {
                throw new BadRequestException(String.format("No default region specified for: %s. Region cannot be empty.", cloudPlatform));
            }
            return platformRegion.value();
        } else {
            throw new BadRequestException("No default region is specified. Region cannot be empty.");
        }
    }
    return source.getPlacement().getRegion();
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Region(com.sequenceiq.cloudbreak.cloud.model.Region) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Aggregations

CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)43 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)11 Test (org.junit.jupiter.api.Test)11 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)9 SdxDatabaseRequest (com.sequenceiq.sdx.api.model.SdxDatabaseRequest)8 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)7 HashMap (java.util.HashMap)7 List (java.util.List)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Set (java.util.Set)6 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)5 Arrays (java.util.Arrays)5 Collectors (java.util.stream.Collectors)5 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)3 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)3 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)3 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)3 SdxClusterShape (com.sequenceiq.sdx.api.model.SdxClusterShape)3