diff --git a/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/api/v3/TemplateUpgradeV3Controller.java b/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/api/v3/TemplateUpgradeV3Controller.java index 3015cb4b..789952b0 100644 --- a/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/api/v3/TemplateUpgradeV3Controller.java +++ b/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/api/v3/TemplateUpgradeV3Controller.java @@ -10,7 +10,6 @@ import com.consoleconnect.kraken.operator.core.dto.Tuple2; import com.consoleconnect.kraken.operator.core.dto.UnifiedAssetDto; import com.consoleconnect.kraken.operator.core.enums.AssetKindEnum; -import com.consoleconnect.kraken.operator.core.enums.EnvNameEnum; import com.consoleconnect.kraken.operator.core.model.HttpResponse; import com.consoleconnect.kraken.operator.core.service.UnifiedAssetService; import com.consoleconnect.kraken.operator.core.toolkit.AssetsConstants; @@ -21,7 +20,6 @@ import java.util.List; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; import org.springframework.data.domain.Sort; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; @@ -36,10 +34,6 @@ @Tag(name = "Template Upgrade V3", description = "Template Upgrade V3") @Slf4j public class TemplateUpgradeV3Controller { - public static final String UPGRADED = "Upgraded"; - public static final String NOT_UPGRADED = "Not upgraded"; - public static final String UPGRADING = "Upgrading"; - public static final String DEPRECATED = "Deprecated"; private final TemplateUpgradeService templateUpgradeService; private final UnifiedAssetService unifiedAssetService; @@ -135,40 +129,20 @@ public HttpResponse> listTemplateChangeLog( .map(templateUpgradeService::generateTemplateUpgradeReleaseVO) .toList(); // the latest can upgrade - list.stream().findFirst().ifPresent(vo -> this.calculateStatus(vo, true)); - list.stream().skip(1).forEach(vo -> this.calculateStatus(vo, false)); + list.stream().findFirst().ifPresent(vo -> templateUpgradeService.calculateStatus(vo, true)); + list.stream().skip(1).forEach(vo -> templateUpgradeService.calculateStatus(vo, false)); return HttpResponse.ok( PagingHelper.toPageNoSubList( list, assetDtoPaging.getPage(), assetDtoPaging.getSize(), assetDtoPaging.getTotal())); } - protected void calculateStatus(TemplateUpgradeReleaseVO vo, boolean first) { - boolean deployedProduction = - vo.getDeployments().stream() - .anyMatch( - deploy -> deploy.getEnvName().equalsIgnoreCase(EnvNameEnum.PRODUCTION.name())); - if (deployedProduction) { - vo.setStatus(UPGRADED); - return; - } - if (first) { - if (CollectionUtils.isEmpty(vo.getDeployments())) { - vo.setStatus(NOT_UPGRADED); - return; - } - vo.setStatus(UPGRADING); - } else { - vo.setStatus(DEPRECATED); - } - } - @Operation(summary = "stage environment upgrade check") @GetMapping("/stage-upgrade-check") public HttpResponse> checkStageUpgradeCondition( @PathVariable("productId") String productId, @RequestParam(value = "templateUpgradeId", required = false) String templateUpgradeId, - @RequestParam String stageEnvId) { - return HttpResponse.ok(templateUpgradeService.stageCheck(templateUpgradeId, stageEnvId)); + @RequestParam String envId) { + return HttpResponse.ok(templateUpgradeService.stageCheck(templateUpgradeId, envId)); } @Operation(summary = "product environment upgrade check") @@ -176,8 +150,7 @@ public HttpResponse> checkStageUpgradeCondition( public HttpResponse> checkProductionUpgradeCondition( @PathVariable("productId") String productId, @RequestParam(value = "templateUpgradeId", required = false) String templateUpgradeId, - @RequestParam String productionEnvId) { - return HttpResponse.ok( - templateUpgradeService.productionCheck(templateUpgradeId, productionEnvId)); + @RequestParam String envId) { + return HttpResponse.ok(templateUpgradeService.productionCheck(templateUpgradeId, envId)); } } diff --git a/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/enums/TemplateViewStatus.java b/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/enums/TemplateViewStatus.java new file mode 100644 index 00000000..56891c7e --- /dev/null +++ b/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/enums/TemplateViewStatus.java @@ -0,0 +1,14 @@ +package com.consoleconnect.kraken.operator.controller.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum TemplateViewStatus { + UPGRADED("Upgraded"), + NOT_UPGRADED("Not upgraded"), + UPGRADING("Upgrading"), + DEPRECATED("Deprecated"); + private final String status; +} diff --git a/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/service/TemplateUpgradeService.java b/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/service/TemplateUpgradeService.java index d0d9c235..0aa537e3 100644 --- a/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/service/TemplateUpgradeService.java +++ b/kraken-java-sdk/kraken-java-sdk-controller/src/main/java/com/consoleconnect/kraken/operator/controller/service/TemplateUpgradeService.java @@ -8,6 +8,7 @@ import com.consoleconnect.kraken.operator.auth.service.UserService; import com.consoleconnect.kraken.operator.controller.dto.*; import com.consoleconnect.kraken.operator.controller.enums.SystemStateEnum; +import com.consoleconnect.kraken.operator.controller.enums.TemplateViewStatus; import com.consoleconnect.kraken.operator.controller.event.TemplateSynCompletedEvent; import com.consoleconnect.kraken.operator.controller.event.TemplateUpgradeEvent; import com.consoleconnect.kraken.operator.controller.model.*; @@ -1130,4 +1131,24 @@ public boolean checkStageCompatibility(String templateUpgradeId) { SystemInfo systemInfo = systemInfoService.find(); return compatibilityCheckService.check(systemInfo.getStageAppVersion(), productVersion); } + + public void calculateStatus(TemplateUpgradeReleaseVO vo, boolean first) { + boolean deployedProduction = + vo.getDeployments().stream() + .anyMatch( + deploy -> deploy.getEnvName().equalsIgnoreCase(EnvNameEnum.PRODUCTION.name())); + if (deployedProduction) { + vo.setStatus(TemplateViewStatus.UPGRADED.getStatus()); + return; + } + if (first) { + if (CollectionUtils.isEmpty(vo.getDeployments())) { + vo.setStatus(TemplateViewStatus.NOT_UPGRADED.getStatus()); + return; + } + vo.setStatus(TemplateViewStatus.UPGRADING.getStatus()); + } else { + vo.setStatus(TemplateViewStatus.DEPRECATED.getStatus()); + } + } }