Search in sources :

Example 1 with SdxClusterShape

use of com.sequenceiq.sdx.api.model.SdxClusterShape in project cloudbreak by hortonworks.

the class SdxService method resizeSdx.

public Pair<SdxCluster, FlowIdentifier> resizeSdx(final String userCrn, final String clusterName, final SdxClusterResizeRequest sdxClusterResizeRequest) {
    LOGGER.info("Re-sizing SDX cluster with name {}", clusterName);
    String accountIdFromCrn = getAccountIdFromCrn(userCrn);
    String environmentName = sdxClusterResizeRequest.getEnvironment();
    SdxClusterShape shape = sdxClusterResizeRequest.getClusterShape();
    final SdxCluster sdxCluster = sdxClusterRepository.findByAccountIdAndClusterNameAndDeletedIsNullAndDetachedIsFalse(accountIdFromCrn, clusterName).orElseThrow(() -> notFound("SDX cluster", clusterName).get());
    MDCBuilder.buildMdcContext(sdxCluster);
    validateSdxResizeRequest(sdxCluster, accountIdFromCrn, shape);
    StackV4Response stackV4Response = getDetail(clusterName, Set.of(StackResponseEntries.HARDWARE_INFO.getEntryName(), StackResponseEntries.EVENTS.getEntryName()), accountIdFromCrn);
    DetailedEnvironmentResponse environment = validateAndGetEnvironment(environmentName);
    SdxCluster newSdxCluster = validateAndCreateNewSdxCluster(userCrn, clusterName, sdxCluster.getRuntime(), shape, sdxCluster.isRangerRazEnabled(), sdxCluster.isEnableMultiAz(), environment);
    newSdxCluster.setTags(sdxCluster.getTags());
    newSdxCluster.setCrn(sdxCluster.getCrn());
    CloudPlatform cloudPlatform = CloudPlatform.valueOf(environment.getCloudPlatform());
    if (!StringUtils.isBlank(sdxCluster.getCloudStorageBaseLocation())) {
        newSdxCluster.setCloudStorageBaseLocation(sdxCluster.getCloudStorageBaseLocation());
        newSdxCluster.setCloudStorageFileSystemType(sdxCluster.getCloudStorageFileSystemType());
    } else if (!CloudPlatform.YARN.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.GCP.equalsIgnoreCase(cloudPlatform.name()) && !CloudPlatform.MOCK.equalsIgnoreCase(cloudPlatform.name())) {
        throw new BadRequestException("Cloud storage parameter is required.");
    }
    newSdxCluster.setDatabaseAvailabilityType(sdxCluster.getDatabaseAvailabilityType());
    newSdxCluster.setDatabaseEngineVersion(sdxCluster.getDatabaseEngineVersion());
    StackV4Request stackRequest = getStackRequest(shape, sdxCluster.isRangerRazEnabled(), null, cloudPlatform, sdxCluster.getRuntime(), null);
    if (shape == SdxClusterShape.MEDIUM_DUTY_HA) {
        // This is added to make sure the host name used by Light and Medium duty are not the same.
        CustomDomainSettingsV4Request customDomainSettingsV4Request = new CustomDomainSettingsV4Request();
        customDomainSettingsV4Request.setHostname(sdxCluster.getClusterName() + SDX_RESIZE_NAME_SUFFIX);
        stackRequest.setCustomDomain(customDomainSettingsV4Request);
    }
    prepareCloudStorageForStack(stackRequest, stackV4Response, newSdxCluster, environment);
    prepareDefaultSecurityConfigs(null, stackRequest, cloudPlatform);
    try {
        if (!StringUtils.isBlank(sdxCluster.getStackRequestToCloudbreak())) {
            StackV4Request stackV4RequestOrig = JsonUtil.readValue(sdxCluster.getStackRequestToCloudbreak(), StackV4Request.class);
            stackRequest.setImage(stackV4RequestOrig.getImage());
        }
    } catch (IOException ioException) {
        LOGGER.error("Failed to re-use the image catalog. Will use default catalog", ioException);
    }
    stackRequest.setResourceCrn(newSdxCluster.getCrn());
    newSdxCluster.setStackRequest(stackRequest);
    FlowIdentifier flowIdentifier = sdxReactorFlowManager.triggerSdxResize(sdxCluster.getId(), newSdxCluster);
    return Pair.of(sdxCluster, flowIdentifier);
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) CustomDomainSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.customdomain.CustomDomainSettingsV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) IOException(java.io.IOException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape)

Example 2 with SdxClusterShape

use of com.sequenceiq.sdx.api.model.SdxClusterShape in project cloudbreak by hortonworks.

the class SdxService method validateInternalSdxRequest.

private void validateInternalSdxRequest(StackV4Request stackv4Request, SdxClusterRequest sdxClusterRequest) {
    ValidationResultBuilder validationResultBuilder = ValidationResult.builder();
    if (stackv4Request != null) {
        SdxClusterShape clusterShape = sdxClusterRequest.getClusterShape();
        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.");
        }
        if (CollectionUtils.isNotEmpty(sdxClusterRequest.getCustomInstanceGroups())) {
            validationResultBuilder.error("Custom instance group is not accepted on SDX Internal API.");
        }
    }
    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) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 3 with SdxClusterShape

use of com.sequenceiq.sdx.api.model.SdxClusterShape in project cloudbreak by hortonworks.

the class CDPConfigService method initCdpStackRequests.

@PostConstruct
public void initCdpStackRequests() {
    PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
    try {
        Resource[] resources = pathMatchingResourcePatternResolver.getResources("classpath:duties/*/**/*.json");
        for (Resource resource : resources) {
            Matcher matcher = RESOURCE_TEMPLATE_PATTERN.matcher(resource.getURL().getPath());
            if (matcher.find()) {
                String runtimeVersion = matcher.group(RUNTIME_GROUP);
                if (supportedRuntimes.isEmpty() || supportedRuntimes.contains(runtimeVersion)) {
                    CloudPlatform cloudPlatform = CloudPlatform.valueOf(matcher.group(CLOUDPLATFORM_GROUP).toUpperCase());
                    SdxClusterShape sdxClusterShape = SdxClusterShape.valueOf(matcher.group(CLUSTERSHAPE_GROUP).toUpperCase());
                    CDPConfigKey cdpConfigKey = new CDPConfigKey(cloudPlatform, sdxClusterShape, runtimeVersion);
                    String entitlementString = matcher.group(ENTITLEMENT_GROUP) != null ? StringUtils.substring(matcher.group(ENTITLEMENT_GROUP), 1) : null;
                    Optional<Entitlement> entitlementOptional = Arrays.stream(Entitlement.values()).filter(entitlement -> StringUtils.equals(entitlement.name().toLowerCase(), entitlementString)).findFirst();
                    String templateString = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8.name());
                    if (!cdpStackRequests.containsKey(cdpConfigKey)) {
                        cdpStackRequests.put(cdpConfigKey, Maps.newHashMap());
                    }
                    cdpStackRequests.get(cdpConfigKey).putIfAbsent(entitlementOptional, templateString);
                }
            }
        }
        LOGGER.info("Cdp configs for datalakes: {}", cdpStackRequests);
    } catch (IOException e) {
        LOGGER.error("Can't read CDP template files", e);
        throw new IllegalStateException("Can't read CDP template files", e);
    }
}
Also used : Arrays(java.util.Arrays) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) ImageCatalogService(com.sequenceiq.datalake.service.imagecatalog.ImageCatalogService) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) StringUtils(org.apache.commons.lang3.StringUtils) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Strings(com.google.common.base.Strings) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) CDPConfigKey(com.sequenceiq.datalake.service.sdx.CDPConfigKey) Matcher(java.util.regex.Matcher) Service(org.springframework.stereotype.Service) Map(java.util.Map) AdvertisedRuntime(com.sequenceiq.sdx.api.model.AdvertisedRuntime) Entitlement(com.sequenceiq.cloudbreak.auth.altus.model.Entitlement) Resource(org.springframework.core.io.Resource) MapUtils(org.apache.commons.collections4.MapUtils) Logger(org.slf4j.Logger) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) Predicate(java.util.function.Predicate) Set(java.util.Set) IOException(java.io.IOException) VersionComparator(com.sequenceiq.cloudbreak.util.VersionComparator) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) PostConstruct(javax.annotation.PostConstruct) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Matcher(java.util.regex.Matcher) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Entitlement(com.sequenceiq.cloudbreak.auth.altus.model.Entitlement) CDPConfigKey(com.sequenceiq.datalake.service.sdx.CDPConfigKey) PostConstruct(javax.annotation.PostConstruct)

Example 4 with SdxClusterShape

use of com.sequenceiq.sdx.api.model.SdxClusterShape in project cloudbreak by hortonworks.

the class SdxResizeTests method validateShape.

private SdxInternalTestDto validateShape(SdxInternalTestDto dto) {
    SdxClusterShape newShape = dto.getResponse().getClusterShape();
    Log.log(LOGGER, format(" New shape: %s ", newShape.name()));
    if (!SdxClusterShape.MEDIUM_DUTY_HA.equals(newShape)) {
        throw new TestFailException(" The datalake shape is : " + newShape + " instead of: " + SdxClusterShape.MEDIUM_DUTY_HA.name());
    }
    return dto;
}
Also used : TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape)

Aggregations

SdxClusterShape (com.sequenceiq.sdx.api.model.SdxClusterShape)4 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)2 IOException (java.io.IOException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings (com.google.common.base.Strings)1 Maps (com.google.common.collect.Maps)1 CustomDomainSettingsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.customdomain.CustomDomainSettingsV4Request)1 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)1 Entitlement (com.sequenceiq.cloudbreak.auth.altus.model.Entitlement)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)1 Versioned (com.sequenceiq.cloudbreak.common.type.Versioned)1 VersionComparator (com.sequenceiq.cloudbreak.util.VersionComparator)1 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1