Skip to content

Commit

Permalink
Fix issues raised by reviewers
Browse files Browse the repository at this point in the history
  • Loading branch information
kuangxiang20240501 committed Nov 4, 2024
1 parent 4bc6a33 commit 852f16f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand All @@ -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;

Expand Down Expand Up @@ -135,49 +129,28 @@ public HttpResponse<Paging<TemplateUpgradeReleaseVO>> 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<List<String>> 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")
@GetMapping("/production-upgrade-check")
public HttpResponse<List<String>> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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());
}
}
}

0 comments on commit 852f16f

Please sign in to comment.