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);
}
}
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;
}
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));
}
}
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;
}
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;
}
Aggregations