diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/common/CommonConstant.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/common/CommonConstant.java index a4998052..a9b55483 100644 --- a/arex-schedule-web-api/src/main/java/com/arextest/schedule/common/CommonConstant.java +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/common/CommonConstant.java @@ -30,6 +30,7 @@ public final class CommonConstant { public static final long CREATE_PLAN_REDIS_EXPIRE = TimeUnit.MINUTES.toSeconds(5); public static final long STOP_PLAN_REDIS_EXPIRE = TimeUnit.DAYS.toSeconds(1); public static final String STOP_PLAN_REDIS_KEY = "arex.stop.plan."; + public static final String PLAN_RUNNING_KEY_FORMAT = "plan_running_%s"; // endregion public static final String DOT = "."; diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/eventBus/PlanAutoRerunEvent.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/eventbus/PlanAutoRerunEvent.java similarity index 78% rename from arex-schedule-web-api/src/main/java/com/arextest/schedule/eventBus/PlanAutoRerunEvent.java rename to arex-schedule-web-api/src/main/java/com/arextest/schedule/eventbus/PlanAutoRerunEvent.java index f218f6cd..83cfe3da 100644 --- a/arex-schedule-web-api/src/main/java/com/arextest/schedule/eventBus/PlanAutoRerunEvent.java +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/eventbus/PlanAutoRerunEvent.java @@ -1,4 +1,4 @@ -package com.arextest.schedule.eventBus; +package com.arextest.schedule.eventbus; import lombok.Data; diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/eventbus/PlanAutoReturnEventService.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/eventbus/PlanAutoReturnEventService.java new file mode 100644 index 00000000..fce92a94 --- /dev/null +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/eventbus/PlanAutoReturnEventService.java @@ -0,0 +1,68 @@ +package com.arextest.schedule.eventbus; + +import com.arextest.schedule.exceptions.PlanRunningException; +import com.arextest.schedule.model.CommonResponse; +import com.arextest.schedule.model.ReplayPlan; +import com.arextest.schedule.model.ReplayStatusType; +import com.arextest.schedule.model.plan.ReRunReplayPlanRequest; +import com.arextest.schedule.progress.ProgressEvent; +import com.arextest.schedule.service.PlanProduceService; +import com.google.common.eventbus.AsyncEventBus; +import com.google.common.eventbus.Subscribe; +import javax.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class PlanAutoReturnEventService implements InitializingBean { + + private static final String AUTO_OPERATOR = "Auto"; + + @Resource + private AsyncEventBus autoRerunAsyncEventBus; + + @Lazy + @Resource + private PlanProduceService planProduceService; + + @Lazy + @Resource + private ProgressEvent progressEvent; + + @Override + public void afterPropertiesSet() throws Exception { + autoRerunAsyncEventBus.register(this); + } + + public void postRerunAsyncEvent(PlanAutoRerunEvent event) { + autoRerunAsyncEventBus.post(event); + } + + @Subscribe + public void planAutoRerun(PlanAutoRerunEvent event) { + ReRunReplayPlanRequest request = new ReRunReplayPlanRequest(); + request.setPlanId(event.getPlanId()); + request.setOperator(AUTO_OPERATOR); + try { + CommonResponse response = planProduceService.reRunPlan(request); + if (response.getResult() != 1) { + LOGGER.error("Auto rerun plan fail, planId: {}", event.getPlanId()); + finishPlan(event.getPlanId()); + } + } catch (PlanRunningException e) { + LOGGER.error("Auto rerun plan fail, planId: {}", event.getPlanId(), e); + finishPlan(event.getPlanId()); + } + } + + private void finishPlan(String planId) { + ReplayPlan replayPlan = new ReplayPlan(); + replayPlan.setId(planId); + progressEvent.onReplayPlanFinish(replayPlan, ReplayStatusType.FINISHED); + } + + +} diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/planexecution/impl/RedisCancelMonitor.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/planexecution/impl/RedisCancelMonitor.java index dc4cefa6..c6993af7 100644 --- a/arex-schedule-web-api/src/main/java/com/arextest/schedule/planexecution/impl/RedisCancelMonitor.java +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/planexecution/impl/RedisCancelMonitor.java @@ -2,7 +2,7 @@ import com.arextest.common.cache.CacheProvider; import com.arextest.schedule.model.ReplayPlan; -import com.arextest.schedule.service.PlanProduceService; +import com.arextest.schedule.utils.RedisKeyBuildUtils; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -23,7 +23,7 @@ boolean isPlanCanceled(ReplayPlan plan) { } private boolean isPlanCanceled(String planId) { - return isCancelled(PlanProduceService.buildStopPlanRedisKey(planId)); + return isCancelled(RedisKeyBuildUtils.buildStopPlanRedisKey(planId)); } private boolean isCancelled(byte[] redisKey) { diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/progress/impl/UpdateResultProgressEventImpl.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/progress/impl/UpdateResultProgressEventImpl.java index aea0daca..416852a2 100644 --- a/arex-schedule-web-api/src/main/java/com/arextest/schedule/progress/impl/UpdateResultProgressEventImpl.java +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/progress/impl/UpdateResultProgressEventImpl.java @@ -5,7 +5,8 @@ import com.arextest.schedule.bizlog.BizLogger; import com.arextest.schedule.dao.mongodb.ReplayPlanActionRepository; import com.arextest.schedule.dao.mongodb.ReplayPlanRepository; -import com.arextest.schedule.eventBus.PlanAutoRerunEvent; +import com.arextest.schedule.eventbus.PlanAutoRerunEvent; +import com.arextest.schedule.eventbus.PlanAutoReturnEventService; import com.arextest.schedule.model.LogType; import com.arextest.schedule.model.ReplayActionItem; import com.arextest.schedule.model.ReplayPlan; @@ -16,11 +17,10 @@ import com.arextest.schedule.model.plan.StageStatusEnum; import com.arextest.schedule.progress.ProgressEvent; import com.arextest.schedule.service.MetricService; -import com.arextest.schedule.service.PlanProduceService; import com.arextest.schedule.service.ReplayReportService; +import com.arextest.schedule.utils.RedisKeyBuildUtils; import com.arextest.schedule.utils.StageUtils; import com.arextest.web.model.contract.contracts.common.PlanStatistic; -import com.google.common.eventbus.AsyncEventBus; import java.util.Date; import java.util.List; import javax.annotation.Resource; @@ -46,7 +46,7 @@ public class UpdateResultProgressEventImpl implements ProgressEvent { @Resource private CacheProvider redisCacheProvider; @Resource - private AsyncEventBus autoRerunAsyncEventBus; + private PlanAutoReturnEventService planAutoReturnEventService; @Value("${auto.rerun.threshold}") private double autoRerunThreshold; @@ -55,7 +55,7 @@ public class UpdateResultProgressEventImpl implements ProgressEvent { public void onReplayPlanReRunException(ReplayPlan plan, Throwable t) { replayReportService.pushPlanStatus(plan.getId(), ReplayStatusType.FAIL_INTERRUPTED, t.getMessage(), true); - redisCacheProvider.remove(PlanProduceService.buildPlanRunningRedisKey(plan.getId())); + redisCacheProvider.remove(RedisKeyBuildUtils.buildPlanRunningRedisKey(plan.getId())); } @Override @@ -87,7 +87,7 @@ public void onCompareConfigLoaded(ReplayPlan replayPlan) { @Override public boolean onBeforeReplayPlanFinish(ReplayPlan replayPlan) { - redisCacheProvider.remove(PlanProduceService.buildPlanRunningRedisKey(replayPlan.getId())); + redisCacheProvider.remove(RedisKeyBuildUtils.buildPlanRunningRedisKey(replayPlan.getId())); // only auto rerun once if (replayPlan.isReRun()) { return true; @@ -121,7 +121,7 @@ public boolean onBeforeReplayPlanFinish(ReplayPlan replayPlan) { public void onReplayPlanAutoRerun(ReplayPlan replayPlan) { PlanAutoRerunEvent event = new PlanAutoRerunEvent(); event.setPlanId(replayPlan.getId()); - autoRerunAsyncEventBus.post(event); + planAutoReturnEventService.postRerunAsyncEvent(event); } @Override @@ -146,7 +146,7 @@ public void onReplayPlanInterrupt(ReplayPlan replayPlan, ReplayStatusType reason replayReportService.pushPlanStatus(planId, reason, replayPlan.getErrorMessage(), replayPlan.isReRun()); recordPlanExecutionTime(replayPlan); - redisCacheProvider.remove(PlanProduceService.buildPlanRunningRedisKey(replayPlan.getId())); + redisCacheProvider.remove(RedisKeyBuildUtils.buildPlanRunningRedisKey(replayPlan.getId())); BizLogger.recordPlanStatusChange(replayPlan, ReplayStatusType.FAIL_INTERRUPTED); } @@ -154,7 +154,7 @@ public void onReplayPlanInterrupt(ReplayPlan replayPlan, ReplayStatusType reason public void onReplayPlanTerminate(String replayId, String reason) { replayPlanRepository.finish(replayId); replayReportService.pushPlanStatus(replayId, ReplayStatusType.CANCELLED, reason, false); - redisCacheProvider.remove(PlanProduceService.buildPlanRunningRedisKey(replayId)); + redisCacheProvider.remove(RedisKeyBuildUtils.buildPlanRunningRedisKey(replayId)); } @Override @@ -185,7 +185,7 @@ public void onReplayPlanStageUpdate(ReplayPlan replayPlan, PlanStageEnum stageTy public void onReplayPlanReRun(ReplayPlan replayPlan) { replayReportService.pushPlanStatus(replayPlan.getId(), ReplayStatusType.RERUNNING, null, replayPlan.isReRun()); - redisCacheProvider.remove(PlanProduceService.buildStopPlanRedisKey(replayPlan.getId())); + redisCacheProvider.remove(RedisKeyBuildUtils.buildStopPlanRedisKey(replayPlan.getId())); addReRunStage(replayPlan.getReplayPlanStageList()); replayPlanRepository.updateStage(replayPlan); } diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/LocalReplayService.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/LocalReplayService.java index be74d87f..88b276fe 100644 --- a/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/LocalReplayService.java +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/LocalReplayService.java @@ -43,6 +43,7 @@ import com.arextest.schedule.sender.ReplaySenderParameters; import com.arextest.schedule.sender.impl.MockCachePreLoader; import com.arextest.schedule.utils.DecodeUtils; +import com.arextest.schedule.utils.RedisKeyBuildUtils; import com.arextest.schedule.utils.ReplayParentBinder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -462,7 +463,7 @@ private Pair buildReplayPlan(BuildReplayPlanRequest } private boolean isStop(String planId) { - return redisCacheProvider.get(PlanProduceService.buildStopPlanRedisKey(planId)) != null; + return redisCacheProvider.get(RedisKeyBuildUtils.buildStopPlanRedisKey(planId)) != null; } private List buildBatchInfoList(ReplayPlan replayPlan) { diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/PlanProduceService.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/PlanProduceService.java index 7d0ec226..4298554e 100644 --- a/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/PlanProduceService.java +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/PlanProduceService.java @@ -4,7 +4,6 @@ import static com.arextest.schedule.common.CommonConstant.ONE_DAY_MILLIS; import static com.arextest.schedule.common.CommonConstant.OPERATION_MAX_CASE_COUNT; import static com.arextest.schedule.common.CommonConstant.STOP_PLAN_REDIS_EXPIRE; -import static com.arextest.schedule.common.CommonConstant.STOP_PLAN_REDIS_KEY; import com.arextest.common.cache.CacheProvider; import com.arextest.common.config.DefaultApplicationConfig; @@ -13,7 +12,6 @@ import com.arextest.schedule.dao.mongodb.ReplayActionCaseItemRepository; import com.arextest.schedule.dao.mongodb.ReplayPlanActionRepository; import com.arextest.schedule.dao.mongodb.ReplayPlanRepository; -import com.arextest.schedule.eventBus.PlanAutoRerunEvent; import com.arextest.schedule.exceptions.PlanRunningException; import com.arextest.schedule.mdc.MDCTracer; import com.arextest.schedule.model.CaseSourceEnvType; @@ -21,7 +19,6 @@ import com.arextest.schedule.model.ReplayActionCaseItem; import com.arextest.schedule.model.ReplayActionItem; import com.arextest.schedule.model.ReplayPlan; -import com.arextest.schedule.model.ReplayStatusType; import com.arextest.schedule.model.deploy.DeploymentVersion; import com.arextest.schedule.model.deploy.ServiceInstance; import com.arextest.schedule.model.plan.BuildReplayFailReasonEnum; @@ -36,16 +33,14 @@ import com.arextest.schedule.plan.builder.ReplayPlanBuilder; import com.arextest.schedule.planexecution.PlanExecutionMonitor; import com.arextest.schedule.progress.ProgressEvent; +import com.arextest.schedule.utils.RedisKeyBuildUtils; import com.arextest.schedule.utils.ReplayParentBinder; import com.arextest.schedule.utils.StageUtils; -import com.google.common.eventbus.AsyncEventBus; -import com.google.common.eventbus.Subscribe; import java.nio.charset.StandardCharsets; -import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; @@ -59,9 +54,9 @@ @Slf4j public class PlanProduceService { - private static final String PLAN_RUNNING_KEY_FORMAT = "plan_running_%s"; + private static final String CASE_SOURCE_TO_OFFSET_MILLIS = "case.source.to.offset.millis"; - private static final String AUTO_OPERATOR = "Auto"; + @Resource private List replayPlanBuilderList; @Resource @@ -85,23 +80,8 @@ public class PlanProduceService { @Resource private ReplayActionCaseItemRepository replayActionCaseItemRepository; @Resource - private AsyncEventBus autoRerunAsyncEventBus; - @Resource private DefaultApplicationConfig defaultConfig; - @PostConstruct - public void init() { - autoRerunAsyncEventBus.register(this); - } - - public static byte[] buildStopPlanRedisKey(String planId) { - return (STOP_PLAN_REDIS_KEY + planId).getBytes(StandardCharsets.UTF_8); - } - - public static byte[] buildPlanRunningRedisKey(String planId) { - return (String.format(PLAN_RUNNING_KEY_FORMAT, planId)).getBytes(StandardCharsets.UTF_8); - } - public CommonResponse createPlan(BuildReplayPlanRequest request) throws PlanRunningException { fillOptionalValueIfRequestMissed(request); progressEvent.onBeforePlanCreate(request); @@ -178,10 +158,6 @@ public void fillOptionalValueIfRequestMissed(BuildReplayPlanRequest request) { if (request.getCaseSourceTo() == null || request.getCaseSourceTo().after(toDate)) { request.setCaseSourceTo(toDate); } - if (StringUtils.isBlank(request.getPlanName())) { - request.setPlanName( - request.getAppId() + "_" + new SimpleDateFormat("MMdd_HH:mm").format(toDate)); - } if (request.getCaseSourceType() == null) { request.setCaseSourceType(CaseSourceEnvType.TEST.getValue()); } @@ -197,12 +173,12 @@ public ReplayPlan build(BuildReplayPlanRequest request, PlanContext planContext) StageStatusEnum.ONGOING, System.currentTimeMillis(), null); replayPlan.setAppId(appId); - replayPlan.setPlanName(request.getPlanName()); DeploymentVersion deploymentVersion = planContext.getTargetVersion(); if (deploymentVersion != null) { replayPlan.setTargetImageId(deploymentVersion.getImageId()); replayPlan.setTargetImageName(deploymentVersion.getImage().getName()); } + List serviceInstances = planContext.targetActiveInstance(); replayPlan.setTargetHost(getIpAddress(serviceInstances)); replayPlan.setTargetEnv(request.getTargetEnv()); @@ -214,12 +190,14 @@ public ReplayPlan build(BuildReplayPlanRequest request, PlanContext planContext) replayPlan.setSourceEnv(request.getSourceEnv()); replayPlan.setSourceHost(getIpAddress(serviceInstances)); } + replayPlan.setPlanCreateTime(new Date()); replayPlan.setOperator(request.getOperator()); replayPlan.setCaseSourceFrom(request.getCaseSourceFrom()); replayPlan.setCaseSourceTo(request.getCaseSourceTo()); replayPlan.setCaseSourceType(request.getCaseSourceType()); replayPlan.setReplayPlanType(request.getReplayPlanType()); + ConfigurationService.Application replayApp = configurationService.application(appId); if (replayApp != null) { replayPlan.setArexCordVersion(replayApp.getAgentVersion()); @@ -227,10 +205,14 @@ public ReplayPlan build(BuildReplayPlanRequest request, PlanContext planContext) replayPlan.setCaseRecordVersion(replayApp.getAgentExtVersion()); replayPlan.setAppName(replayApp.getAppName()); } + replayPlan.setPlanName(getReplayName(request, replayApp)); + ConfigurationService.ScheduleConfiguration schedule = configurationService.schedule(appId); - if (schedule != null) { - replayPlan.setReplaySendMaxQps(schedule.getSendMaxQps()); - } + replayPlan.setReplaySendMaxQps( + Optional.ofNullable(schedule).map(ConfigurationService.ScheduleConfiguration::getSendMaxQps) + .orElse(null) + ); + if (request.getCaseCountLimit() == null || request.getCaseCountLimit() <= 0) { replayPlan.setCaseCountLimit(OPERATION_MAX_CASE_COUNT); } else { @@ -251,6 +233,23 @@ private String getIpAddress(List serviceInstances) { return serviceInstances.stream().map(ServiceInstance::getIp).collect(Collectors.joining(",")); } + private String getReplayName(BuildReplayPlanRequest request, + ConfigurationService.Application appInfo) { + if (StringUtils.isNotBlank(request.getPlanName())) { + return request.getPlanName(); + } + StringBuilder stringBuilder = new StringBuilder(); + if (appInfo != null) { + stringBuilder.append(appInfo.getAppName()).append("_"); + } else { + stringBuilder.append("unknown-appName").append("_"); + } + String currentTimeMillis = String.valueOf(System.currentTimeMillis()); + String lastSixDigits = currentTimeMillis.substring(currentTimeMillis.length() - 6); + stringBuilder.append(lastSixDigits); + return stringBuilder.toString(); + } + public ReplayPlanBuilder select(BuildReplayPlanRequest request) { for (ReplayPlanBuilder replayPlanBuilder : replayPlanBuilderList) { if (replayPlanBuilder.isSupported(request)) { @@ -285,7 +284,7 @@ public void removeCreating(String appId, String targetEnv) { public Boolean isRunning(String planId) { try { - byte[] key = buildPlanRunningRedisKey(planId); + byte[] key = RedisKeyBuildUtils.buildPlanRunningRedisKey(planId); byte[] value = planId.getBytes(StandardCharsets.UTF_8); if (redisCacheProvider.get(key) != null) { return true; @@ -301,7 +300,7 @@ public Boolean isRunning(String planId) { public void stopPlan(String planId, String operator) { try { // set key for other instance to stop internal execution - redisCacheProvider.putIfAbsent(buildStopPlanRedisKey(planId), + redisCacheProvider.putIfAbsent(RedisKeyBuildUtils.buildStopPlanRedisKey(planId), STOP_PLAN_REDIS_EXPIRE, planId.getBytes(StandardCharsets.UTF_8)); // set the canceled status immediately to give quick response to user @@ -337,12 +336,12 @@ public CommonResponse reRunPlan(ReRunReplayPlanRequest request) throws PlanRunni final String planId = request.getPlanId(); final String planItemId = request.getPlanItemId(); ReplayPlan replayPlan = replayPlanRepository.query(planId); - replayPlan.setPlanCreateMillis(System.currentTimeMillis()); - progressEvent.onBeforePlanReRun(replayPlan); if (replayPlan == null) { progressEvent.onReplayPlanReRunException(replayPlan); return CommonResponse.badResponse("target plan not found"); } + replayPlan.setPlanCreateMillis(System.currentTimeMillis()); + progressEvent.onBeforePlanReRun(replayPlan); if (replayPlan.getReplayPlanStageList() == null) { progressEvent.onReplayPlanReRunException(replayPlan); return CommonResponse.badResponse("The plan's version is too old"); @@ -394,27 +393,4 @@ public CommonResponse reRunPlan(ReRunReplayPlanRequest request) throws PlanRunni return CommonResponse.successResponse("ReRun plan success!", new BuildReplayPlanResponse(replayPlan.getId())); } - - @Subscribe - public void planAutoRerun(PlanAutoRerunEvent event) { - ReRunReplayPlanRequest request = new ReRunReplayPlanRequest(); - request.setPlanId(event.getPlanId()); - request.setOperator(AUTO_OPERATOR); - try { - CommonResponse response = this.reRunPlan(request); - if (response.getResult() != 1) { - LOGGER.error("Auto rerun plan fail, planId: {}", event.getPlanId()); - finishPlan(event.getPlanId()); - } - } catch (PlanRunningException e) { - LOGGER.error("Auto rerun plan fail, planId: {}", event.getPlanId(), e); - finishPlan(event.getPlanId()); - } - } - - private void finishPlan(String planId) { - ReplayPlan replayPlan = new ReplayPlan(); - replayPlan.setId(planId); - progressEvent.onReplayPlanFinish(replayPlan, ReplayStatusType.FINISHED); - } } diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/ReplayCompareService.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/ReplayCompareService.java index 16cb8514..9a128c5f 100644 --- a/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/ReplayCompareService.java +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/service/ReplayCompareService.java @@ -1,14 +1,12 @@ package com.arextest.schedule.service; -import static com.arextest.schedule.common.CommonConstant.STOP_PLAN_REDIS_KEY; - import com.arextest.common.cache.CacheProvider; import com.arextest.schedule.client.HttpWepServiceApiClient; import com.arextest.schedule.comparer.ReplayResultComparer; import com.arextest.schedule.mdc.MDCTracer; import com.arextest.schedule.model.CommonResponse; import com.arextest.schedule.model.ReplayActionCaseItem; -import java.nio.charset.StandardCharsets; +import com.arextest.schedule.utils.RedisKeyBuildUtils; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import javax.annotation.Resource; @@ -67,7 +65,7 @@ public boolean compareCaseDistributable(ReplayActionCaseItem caseItem) { private boolean isCancelled(String planId) { try { - byte[] stopKey = (STOP_PLAN_REDIS_KEY + planId).getBytes(StandardCharsets.UTF_8); + byte[] stopKey = RedisKeyBuildUtils.buildStopPlanRedisKey(planId); byte[] bytes = redisCacheProvider.get(stopKey); return bytes != null; } catch (Exception e) { diff --git a/arex-schedule-web-api/src/main/java/com/arextest/schedule/utils/RedisKeyBuildUtils.java b/arex-schedule-web-api/src/main/java/com/arextest/schedule/utils/RedisKeyBuildUtils.java new file mode 100644 index 00000000..c29c7d0b --- /dev/null +++ b/arex-schedule-web-api/src/main/java/com/arextest/schedule/utils/RedisKeyBuildUtils.java @@ -0,0 +1,22 @@ +package com.arextest.schedule.utils; + +import com.arextest.schedule.common.CommonConstant; +import java.nio.charset.StandardCharsets; + +public class RedisKeyBuildUtils { + + private RedisKeyBuildUtils() { + } + + // region Plan Status + public static byte[] buildStopPlanRedisKey(String planId) { + return (CommonConstant.STOP_PLAN_REDIS_KEY + planId).getBytes(StandardCharsets.UTF_8); + } + + public static byte[] buildPlanRunningRedisKey(String planId) { + return (String.format(CommonConstant.PLAN_RUNNING_KEY_FORMAT, planId)).getBytes( + StandardCharsets.UTF_8); + } + // endregion + +}