Search in sources :

Example 31 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class DistroXUpgradeV1Controller method upgradeCluster.

private DistroXUpgradeV1Response upgradeCluster(String clusterNameOrCrn, DistroXUpgradeV1Request distroxUpgradeRequest, NameOrCrn nameOrCrn, InternalUpgradeSettings internalUpgradeSettings) {
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    UpgradeV4Request request = upgradeConverter.convert(distroxUpgradeRequest, internalUpgradeSettings);
    Long workspaceId = restRequestThreadLocalService.getRequestedWorkspaceId();
    if (request.isDryRun() || request.isShowAvailableImagesSet()) {
        LOGGER.info("Checking for upgrade for cluster [{}] with request: {}", clusterNameOrCrn, request);
        UpgradeV4Response upgradeV4Response = upgradeAvailabilityService.checkForUpgrade(nameOrCrn, workspaceId, request, userCrn);
        return upgradeConverter.convert(upgradeV4Response);
    } else {
        LOGGER.info("Triggering upgrade for cluster [{}] with request: {}", clusterNameOrCrn, request);
        UpgradeV4Response upgradeV4Response = upgradeService.triggerUpgrade(nameOrCrn, workspaceId, userCrn, request);
        return upgradeConverter.convert(upgradeV4Response);
    }
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)

Example 32 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class StackUpgradeOperations method checkForClusterUpgrade.

public UpgradeV4Response checkForClusterUpgrade(String accountId, @NotNull Stack stack, Long workspaceId, UpgradeV4Request request) {
    MDCBuilder.buildMdcContext(stack);
    stack.setInstanceGroups(instanceGroupService.getByStackAndFetchTemplates(stack.getId()));
    boolean osUpgrade = upgradeService.isOsUpgrade(request);
    boolean replaceVms = determineReplaceVmsParameter(stack, request.getReplaceVms());
    if (replaceVms) {
        StackInstanceCount stackInstanceCount = instanceMetaDataService.countByStackId(stack.getId());
        Integer upgradeNodeCountLimit = limitConfiguration.getUpgradeNodeCountLimit();
        LOGGER.debug("Instance count: {} and limit: [{}]", stackInstanceCount == null ? "null" : stackInstanceCount.asString(), upgradeNodeCountLimit);
        if (stackInstanceCount != null && stackInstanceCount.getInstanceCount() > upgradeNodeCountLimit) {
            throw new BadRequestException(String.format("There are %s nodes in the cluster. Upgrade has a limit of %s nodes, above the limit it is unstable. " + "Please downscale the cluster below the limit and retry the upgrade.", stackInstanceCount.getInstanceCount(), upgradeNodeCountLimit));
        }
    }
    UpgradeV4Response upgradeResponse = clusterUpgradeAvailabilityService.checkForUpgradesByName(stack, osUpgrade, replaceVms, request.getInternalUpgradeSettings());
    if (CollectionUtils.isNotEmpty(upgradeResponse.getUpgradeCandidates())) {
        clusterUpgradeAvailabilityService.filterUpgradeOptions(accountId, upgradeResponse, request, stack.isDatalake());
    }
    validateAttachedDataHubsForDataLake(accountId, workspaceId, stack, upgradeResponse);
    LOGGER.debug("Upgrade response after validations: {}", upgradeResponse);
    return upgradeResponse;
}
Also used : StackInstanceCount(com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) BadRequestException(javax.ws.rs.BadRequestException)

Example 33 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class StackUpgradeOperations method validateAttachedDataHubsForDataLake.

private void validateAttachedDataHubsForDataLake(String accountId, Long workspaceId, Stack stack, UpgradeV4Response upgradeResponse) {
    if (entitlementService.runtimeUpgradeEnabled(accountId) && StackType.DATALAKE == stack.getType()) {
        LOGGER.info("Checking that the attached DataHubs of the Data lake are both in stopped state and upgradeable only in case if " + "Data lake runtime upgrade is enabled in [{}] account on [{}] cluster.", accountId, stack.getName());
        StackViewV4Responses stackViewV4Responses = stackOperations.listByEnvironmentCrn(workspaceId, stack.getEnvironmentCrn(), List.of(StackType.WORKLOAD));
        if (!entitlementService.datahubRuntimeUpgradeEnabled(accountId)) {
            upgradeResponse.appendReason(upgradePreconditionService.checkForNonUpgradeableAttachedClusters(stackViewV4Responses));
        }
        upgradeResponse.appendReason(upgradePreconditionService.checkForRunningAttachedClusters(stackViewV4Responses, stack));
    }
}
Also used : StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses)

Example 34 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeService method filterOnlyPatchUpgradesIfRuntimeUpgradeDisabled.

private UpgradeV4Response filterOnlyPatchUpgradesIfRuntimeUpgradeDisabled(String accountId, String clusterName, SdxUpgradeRequest sdxUpgradeRequest, UpgradeV4Response upgradeV4Response) {
    UpgradeV4Response filteredUpgradeResponse = new UpgradeV4Response(upgradeV4Response.getCurrent(), upgradeV4Response.getUpgradeCandidates(), upgradeV4Response.getReason());
    if (!isRuntimeUpgradeEnabled(accountId)) {
        if (upgradeV4Response.getCurrent() != null) {
            List<ImageInfoV4Response> upgradeCandidates = filteredUpgradeResponse.getUpgradeCandidates();
            String currentCdpVersion = filteredUpgradeResponse.getCurrent().getComponentVersions().getCdp();
            LOGGER.debug("Only patch upgrade is possible on [{}] cluster for [{}] runtime as CDP_RUNTIME_UPGRADE is disabled in [{}] account.", clusterName, currentCdpVersion, accountId);
            upgradeCandidates = upgradeCandidates.stream().filter(upgradeCandidate -> upgradeCandidate.getComponentVersions().getCdp().equals(currentCdpVersion)).collect(Collectors.toList());
            filteredUpgradeResponse.setUpgradeCandidates(upgradeCandidates);
            updatePatchUpgradeReasonIfNeeded(accountId, clusterName, filteredUpgradeResponse, sdxUpgradeRequest, currentCdpVersion);
            LOGGER.debug("Patch upgrade candidates for [{}] cluster: [{}]", clusterName, upgradeCandidates);
        } else {
            String message = String.format("No information about current image, cannot filter patch upgrade candidates based on it on [%s] cluster.", clusterName);
            LOGGER.debug(message);
            filteredUpgradeResponse.appendReason(message);
            filteredUpgradeResponse.setUpgradeCandidates(List.of());
        }
    }
    return filteredUpgradeResponse;
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)

Example 35 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeService method filterBySdxUpgradeRequestParams.

private UpgradeV4Response filterBySdxUpgradeRequestParams(SdxUpgradeRequest upgradeSdxClusterRequest, UpgradeV4Response upgradeV4Response) {
    UpgradeV4Response filteredUpgradeResponse = new UpgradeV4Response(upgradeV4Response.getCurrent(), upgradeV4Response.getUpgradeCandidates(), upgradeV4Response.getReason());
    if (CollectionUtils.isNotEmpty(filteredUpgradeResponse.getUpgradeCandidates())) {
        List<ImageInfoV4Response> upgradeCandidates = filteredUpgradeResponse.getUpgradeCandidates();
        if (SdxUpgradeShowAvailableImages.LATEST_ONLY == upgradeSdxClusterRequest.getShowAvailableImages()) {
            Map<String, Optional<ImageInfoV4Response>> latestImageByRuntime = upgradeCandidates.stream().collect(Collectors.groupingBy(imageInfoV4Response -> imageInfoV4Response.getComponentVersions().getCdp(), Collectors.maxBy(Comparator.comparingLong(ImageInfoV4Response::getCreated))));
            List<ImageInfoV4Response> latestImages = latestImageByRuntime.values().stream().flatMap(Optional::stream).collect(Collectors.toList());
            filteredUpgradeResponse.setUpgradeCandidates(latestImages);
            LOGGER.debug("Filtering for latest image per runtimes {}", latestImageByRuntime.keySet());
        } else if (upgradeSdxClusterRequest.isDryRun()) {
            ImageInfoV4Response latestImage = upgradeCandidates.stream().max(ImageInfoV4Response.creationBasedComparator()).orElseThrow();
            filteredUpgradeResponse.setUpgradeCandidates(List.of(latestImage));
            LOGGER.debug("Choosing latest image with id {} as dry-run is specified", latestImage.getImageId());
        } else {
            filteredUpgradeResponse.setUpgradeCandidates(upgradeCandidates);
        }
    }
    return filteredUpgradeResponse;
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) SdxUpgradeShowAvailableImages(com.sequenceiq.sdx.api.model.SdxUpgradeShowAvailableImages) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) PaywallAccessChecker(com.sequenceiq.cloudbreak.auth.PaywallAccessChecker) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) SdxReactorFlowManager(com.sequenceiq.datalake.flow.SdxReactorFlowManager) LoggerFactory(org.slf4j.LoggerFactory) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) SdxUpgradeClusterConverter(com.sequenceiq.datalake.controller.sdx.SdxUpgradeClusterConverter) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Map(java.util.Map) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxService(com.sequenceiq.datalake.service.sdx.SdxService) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) StackV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint) Logger(org.slf4j.Logger) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Collectors(java.util.stream.Collectors) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Objects(java.util.Objects) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) SdxUpgradeReplaceVms(com.sequenceiq.sdx.api.model.SdxUpgradeReplaceVms) SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest) ClouderaManagerLicenseProvider(com.sequenceiq.cloudbreak.auth.ClouderaManagerLicenseProvider) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) Optional(java.util.Optional) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)

Aggregations

UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)69 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)43 Test (org.junit.jupiter.api.Test)41 UpgradeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)40 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)21 Test (org.junit.Test)16 DisplayName (org.junit.jupiter.api.DisplayName)16 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)13 ImageComponentVersions (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions)10 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)10 ImageFilterResult (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)9 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)9 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)9 ImageFilterParams (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams)9 List (java.util.List)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 InjectMocks (org.mockito.InjectMocks)8 Mock (org.mockito.Mock)8