Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modify default planName #342

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ".";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.arextest.schedule.eventBus;
package com.arextest.schedule.eventbus;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -146,15 +146,15 @@ 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);
}

@Override
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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -462,7 +463,7 @@ private Pair<ReplayPlan, CommonResponse> buildReplayPlan(BuildReplayPlanRequest
}

private boolean isStop(String planId) {
return redisCacheProvider.get(PlanProduceService.buildStopPlanRedisKey(planId)) != null;
return redisCacheProvider.get(RedisKeyBuildUtils.buildStopPlanRedisKey(planId)) != null;
}

private List<ReplayCaseBatchInfo> buildBatchInfoList(ReplayPlan replayPlan) {
Expand Down
Loading
Loading