多余代码删除,tiklab代码迁移
This commit is contained in:
parent
f0f7a12237
commit
3824daf37b
@ -0,0 +1,10 @@
|
|||||||
|
package cd.casic.ci.common.pipeline.constant;
|
||||||
|
|
||||||
|
public class PipelineDateUtilConstant {
|
||||||
|
public static final String yyyy_MM_dd = "2";
|
||||||
|
public static final String HH_mm_ss = "3";
|
||||||
|
public static final String yyyy_MM_dd_HH_mm_ss = "4";
|
||||||
|
public static final String HH_mm = "5";
|
||||||
|
public static final String yyyy_MM_dd_HH_mm_ss_SSS = "6";
|
||||||
|
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dataObject;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class UrlActionRecord {
|
|
||||||
@Schema(description="主键ID")
|
|
||||||
private Integer id;
|
|
||||||
@Schema(description="操作")
|
|
||||||
private String action;
|
|
||||||
@Schema(description="描述")
|
|
||||||
private String description;
|
|
||||||
@Schema(description="url地址")
|
|
||||||
private String url;
|
|
||||||
@Schema(description="创建时间")
|
|
||||||
private Date createTime;
|
|
||||||
@Schema(description="修改时间")
|
|
||||||
private Date modifyTime;
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dataObject;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class UserPermissionRecord {
|
|
||||||
@Schema(description="主键ID")
|
|
||||||
private Integer id;
|
|
||||||
@Schema(description="过期时间")
|
|
||||||
private Date expireTime;
|
|
||||||
@Schema(description="")
|
|
||||||
private Integer urlActionId;
|
|
||||||
@Schema(description="用户ID")
|
|
||||||
private Integer userId;
|
|
||||||
@Schema(description="创建时间")
|
|
||||||
private Date createTime;
|
|
||||||
@Schema(description="修改时间")
|
|
||||||
private Date modifyTime;
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dataObject;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class UserRecord {
|
|
||||||
@Schema(description="主键ID")
|
|
||||||
private Integer id;
|
|
||||||
@Schema(description="")
|
|
||||||
private String chname;
|
|
||||||
@Schema(description="创建时间")
|
|
||||||
private Date createTime;
|
|
||||||
@Schema(description="email")
|
|
||||||
private String email;
|
|
||||||
@Schema(description="语言")
|
|
||||||
private String lang;
|
|
||||||
@Schema(description="最近登录时间")
|
|
||||||
private Date lastLoginTime;
|
|
||||||
@Schema(description="电话")
|
|
||||||
private String phone;
|
|
||||||
@Schema(description="用户名称")
|
|
||||||
private String username;
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.dataObject;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class UserRoleRecord {
|
|
||||||
@Schema(description="主键ID")
|
|
||||||
private Integer id;
|
|
||||||
@Schema(description="角色ID")
|
|
||||||
private Integer roleId;
|
|
||||||
@Schema(description="用户ID")
|
|
||||||
private Integer userId;
|
|
||||||
@Schema(description="过期时间")
|
|
||||||
private Date expireTime;
|
|
||||||
@Schema(description="创建时间")
|
|
||||||
private Date createTime;
|
|
||||||
@Schema(description="修改时间")
|
|
||||||
private Date modifyTime;
|
|
||||||
}
|
|
@ -1,591 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.control;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.Model;
|
|
||||||
import cd.casic.ci.common.pipeline.container.Container;
|
|
||||||
import cd.casic.ci.common.pipeline.container.Stage;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.BuildStatus;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.CallBackEvent;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.enums.ProjectPipelineCallbackStatus;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.Element;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.event.ProjectPipelineCallBack;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.service.utils.LogUtils;
|
|
||||||
import cd.casic.ci.process.api.engine.pojo.PipelineInfo;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.ProjectPipelineCallBackHistory;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.pipeline.ModelDetail;
|
|
||||||
import cd.casic.ci.process.process.constant.AllocIdGenerateConstant;
|
|
||||||
import cd.casic.ci.process.process.engine.pojo.event.PipelineStreamEnabledEvent;
|
|
||||||
import cd.casic.ci.process.process.service.base.PipelineBuildDetailServiceImpl;
|
|
||||||
import cd.casic.ci.process.process.service.base.engin.service.PipelineRepositoryService;
|
|
||||||
import cd.casic.ci.process.process.service.base.engin.service.ProjectPipelineCallBackService;
|
|
||||||
import cd.casic.ci.process.process.service.base.engin.service.ProjectPipelineCallBackUrlGenerator;
|
|
||||||
import cd.casic.ci.process.process.service.base.pojo.*;
|
|
||||||
import cd.casic.ci.process.process.service.base.pojo.constant.CallbackConstants;
|
|
||||||
import cd.casic.ci.project.service.ServiceAllocIdResource;
|
|
||||||
import cd.casic.framework.commons.util.watcher.Watcher;
|
|
||||||
|
|
||||||
|
|
||||||
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
|
|
||||||
import io.github.resilience4j.circuitbreaker.CircuitBreaker;
|
|
||||||
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry;
|
|
||||||
import io.micrometer.core.instrument.Counter;
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
|
||||||
import io.micrometer.core.instrument.Tags;
|
|
||||||
import okhttp3.*;
|
|
||||||
import org.apache.commons.lang3.tuple.ImmutableTriple;
|
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
|
||||||
import javax.net.ssl.TrustManager;
|
|
||||||
import javax.net.ssl.X509TrustManager;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CallBackControl {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CallBackControl.class);
|
|
||||||
private static final MediaType JSON = MediaType.parse("application/json;charset=utf-8");
|
|
||||||
private static final int MAX_RETRY_COUNT = 3;
|
|
||||||
private static final long DEFAULT_FAILURE_DISABLE_TIME_PERIOD = 12 * 60 * 60 * 1000L;
|
|
||||||
private static final String PIPELINE_CALLBACK_COUNT = "pipeline_callback_count";
|
|
||||||
private static final long connectTimeout = 3L;
|
|
||||||
private static final long readTimeout = 3L;
|
|
||||||
private static final long writeTimeout = 3L;
|
|
||||||
|
|
||||||
private final PipelineBuildDetailServiceImpl pipelineBuildDetailService;
|
|
||||||
private final PipelineRepositoryService pipelineRepositoryService;
|
|
||||||
private final ProjectPipelineCallBackService projectPipelineCallBackService;
|
|
||||||
private final CircuitBreakerRegistry callbackCircuitBreakerRegistry;
|
|
||||||
private final MeterRegistry meterRegistry;
|
|
||||||
private final ProjectPipelineCallBackUrlGenerator projectPipelineCallBackUrlGenerator;
|
|
||||||
private ServiceAllocIdResource serviceAllocIdResource;
|
|
||||||
|
|
||||||
@Value("${callback.failureDisableTimePeriod:#{43200000}}")
|
|
||||||
private long failureDisableTimePeriod = DEFAULT_FAILURE_DISABLE_TIME_PERIOD;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public CallBackControl(
|
|
||||||
PipelineBuildDetailServiceImpl pipelineBuildDetailService,
|
|
||||||
PipelineRepositoryService pipelineRepositoryService,
|
|
||||||
ProjectPipelineCallBackService projectPipelineCallBackService,
|
|
||||||
CircuitBreakerRegistry callbackCircuitBreakerRegistry,
|
|
||||||
MeterRegistry meterRegistry,
|
|
||||||
ProjectPipelineCallBackUrlGenerator projectPipelineCallBackUrlGenerator,
|
|
||||||
ServiceAllocIdResource serviceAllocIdResource
|
|
||||||
) {
|
|
||||||
this.pipelineBuildDetailService = pipelineBuildDetailService;
|
|
||||||
this.pipelineRepositoryService = pipelineRepositoryService;
|
|
||||||
this.projectPipelineCallBackService = projectPipelineCallBackService;
|
|
||||||
this.callbackCircuitBreakerRegistry = callbackCircuitBreakerRegistry;
|
|
||||||
this.meterRegistry = meterRegistry;
|
|
||||||
this.projectPipelineCallBackUrlGenerator = projectPipelineCallBackUrlGenerator;
|
|
||||||
this.serviceAllocIdResource = serviceAllocIdResource;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 静态初始化块
|
|
||||||
private static final SSLSocketFactory anySslSocketFactory;
|
|
||||||
private static final TrustManager[] trustAnyCerts;
|
|
||||||
private static final OkHttpClient callbackClient;
|
|
||||||
|
|
||||||
static {
|
|
||||||
trustAnyCerts = new TrustManager[]{
|
|
||||||
new X509TrustManager() {
|
|
||||||
@Override
|
|
||||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
|
||||||
return new X509Certificate[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
SSLContext sslContext = SSLContext.getInstance("SSL");
|
|
||||||
sslContext.init(null, trustAnyCerts, new java.security.SecureRandom());
|
|
||||||
anySslSocketFactory = sslContext.getSocketFactory();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// throw new RemoteServiceException(e.getMessage()); TODO 添加项目报错
|
|
||||||
throw new RuntimeException(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
callbackClient = new OkHttpClient.Builder()
|
|
||||||
.connectTimeout(connectTimeout, TimeUnit.SECONDS)
|
|
||||||
.readTimeout(readTimeout, TimeUnit.SECONDS)
|
|
||||||
.writeTimeout(writeTimeout, TimeUnit.SECONDS)
|
|
||||||
.sslSocketFactory(anySslSocketFactory, (X509TrustManager) trustAnyCerts[0])
|
|
||||||
.hostnameVerifier((hostname, session) -> true)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pipelineCreateEvent(String projectId, String pipelineId) {
|
|
||||||
callBackPipelineEvent(projectId, pipelineId, CallBackEvent.CREATE_PIPELINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pipelineDeleteEvent(String projectId, String pipelineId) {
|
|
||||||
callBackPipelineEvent(projectId, pipelineId, CallBackEvent.DELETE_PIPELINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pipelineUpdateEvent(String projectId, String pipelineId) {
|
|
||||||
callBackPipelineEvent(projectId, pipelineId, CallBackEvent.UPDATE_PIPELINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pipelineRestoreEvent(String projectId, String pipelineId) {
|
|
||||||
callBackPipelineEvent(projectId, pipelineId, CallBackEvent.RESTORE_PIPELINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void projectCreate(String projectId, String projectName, String userId) {
|
|
||||||
callBackProjectEvent(projectId, projectName, userId, true, CallBackEvent.PROJECT_CREATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void projectUpdate(String projectId, String projectName, String userId) {
|
|
||||||
callBackProjectEvent(projectId, projectName, userId, true, CallBackEvent.PROJECT_UPDATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void projectEnable(String projectId, String projectName, String userId) {
|
|
||||||
callBackProjectEvent(projectId, projectName, userId, true, CallBackEvent.PROJECT_ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void projectDisable(String projectId, String projectName, String userId) {
|
|
||||||
callBackProjectEvent(projectId, projectName, userId, false, CallBackEvent.PROJECT_DISABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pipelineStreamEnabledEvent(PipelineStreamEnabledEvent event) {
|
|
||||||
logger.info(event.getProjectId() + "|STREAM_ENABLED|callback stream enable event");
|
|
||||||
List<ProjectPipelineCallBack> list = projectPipelineCallBackService.listProjectCallBack(
|
|
||||||
event.getProjectId(),
|
|
||||||
CallBackEvent.STREAM_ENABLED.name()
|
|
||||||
);
|
|
||||||
StreamEnabledEvent streamEnabledEvent = new StreamEnabledEvent(
|
|
||||||
event.getUserId(),
|
|
||||||
event.getGitProjectId(),
|
|
||||||
event.getGitProjectUrl(),
|
|
||||||
event.getEnable()
|
|
||||||
);
|
|
||||||
sendToCallBack(new CallBackData<StreamEnabledEvent>(CallBackEvent.STREAM_ENABLED, streamEnabledEvent), list);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void callBackPipelineEvent(String projectId, String pipelineId, CallBackEvent callBackEvent) {
|
|
||||||
logger.info(projectId + "|" + pipelineId + "|" + callBackEvent + "|callback pipeline event");
|
|
||||||
List<ProjectPipelineCallBack> list = projectPipelineCallBackService.listProjectCallBack(
|
|
||||||
projectId,
|
|
||||||
callBackEvent.name()
|
|
||||||
);
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
logger.info("[" + pipelineId + "]|[" + callBackEvent + "]| no callback");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PipelineInfo pipelineInfo = pipelineRepositoryService.getPipelineInfo(
|
|
||||||
projectId,
|
|
||||||
pipelineId,
|
|
||||||
null,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
if (pipelineInfo == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PipelineEvent pipelineEvent = new PipelineEvent(
|
|
||||||
pipelineInfo.getPipelineId(),
|
|
||||||
pipelineInfo.getPipelineName(),
|
|
||||||
pipelineInfo.getLastModifyUser(),
|
|
||||||
pipelineInfo.getUpdateTime(),
|
|
||||||
pipelineInfo.getProjectId()
|
|
||||||
);
|
|
||||||
|
|
||||||
sendToCallBack(new CallBackData<>(callBackEvent, pipelineEvent), list);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void callBackProjectEvent(
|
|
||||||
String projectId,
|
|
||||||
String projectName,
|
|
||||||
String userId,
|
|
||||||
boolean enable,
|
|
||||||
CallBackEvent callBackEvent
|
|
||||||
) {
|
|
||||||
logger.info(projectId + "|" + projectName + "|" + callBackEvent + "|callback project event");
|
|
||||||
List<ProjectPipelineCallBack> list = projectPipelineCallBackService.listProjectCallBack(
|
|
||||||
CallbackConstants.DEVOPS_ALL_PROJECT,
|
|
||||||
callBackEvent.name()
|
|
||||||
);
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
logger.info("no [" + callBackEvent + "] project callback");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ProjectCallbackEvent projectEvent = new ProjectCallbackEvent(
|
|
||||||
projectId,
|
|
||||||
projectName,
|
|
||||||
enable,
|
|
||||||
userId
|
|
||||||
);
|
|
||||||
|
|
||||||
sendToCallBack(new CallBackData<>(callBackEvent, projectEvent), list);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void callBackBuildEvent(PipelineBuildStatusBroadCastEvent event) {
|
|
||||||
String projectId = event.getProjectId();
|
|
||||||
String pipelineId = event.getPipelineId();
|
|
||||||
String buildId = event.getBuildId();
|
|
||||||
if (event.getAtomCode() != null && VmOperateTaskGenerator.isVmAtom(event.getAtomCode())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
CallBackEvent callBackEvent = EventUtils.toEventType(event);
|
|
||||||
if (callBackEvent == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(projectId + "|" + pipelineId + "|" + buildId + "|" + callBackEvent.name() + "|" +
|
|
||||||
event.getStageId() + "|" + event.getTaskId() + "|callback");
|
|
||||||
|
|
||||||
List<ProjectPipelineCallBack> list = new ArrayList<>();
|
|
||||||
list.addAll(projectPipelineCallBackService.listProjectCallBack(
|
|
||||||
projectId,
|
|
||||||
callBackEvent.name()
|
|
||||||
));
|
|
||||||
|
|
||||||
List<ProjectPipelineCallBack> pipelineCallback = projectPipelineCallBackService.getPipelineCallback(
|
|
||||||
projectId,
|
|
||||||
pipelineId,
|
|
||||||
callBackEvent.name()
|
|
||||||
);
|
|
||||||
if (pipelineCallback.isEmpty()) {
|
|
||||||
pipelineCallback = pipelineRepositoryService.getPipelineResourceVersion(
|
|
||||||
projectId,
|
|
||||||
pipelineId,
|
|
||||||
null,
|
|
||||||
false
|
|
||||||
).getModel().getPipelineCallBack(
|
|
||||||
projectId,
|
|
||||||
callBackEvent
|
|
||||||
);
|
|
||||||
if (pipelineCallback == null) {
|
|
||||||
pipelineCallback = Collections.emptyList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!pipelineCallback.isEmpty()) {
|
|
||||||
list.addAll(pipelineCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ModelDetail modelDetail = pipelineBuildDetailService.get(
|
|
||||||
projectId,
|
|
||||||
event.getBuildId(),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
if (modelDetail == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildEvent buildEvent = new BuildEvent(
|
|
||||||
event.getBuildId(),
|
|
||||||
modelDetail.getPipelineId(),
|
|
||||||
modelDetail.getPipelineName(),
|
|
||||||
modelDetail.getUserId(),
|
|
||||||
modelDetail.getTriggerUser(),
|
|
||||||
modelDetail.getCancelUserId(),
|
|
||||||
modelDetail.getStatus(),
|
|
||||||
modelDetail.getStartTime(),
|
|
||||||
modelDetail.getEndTime() != null ? modelDetail.getEndTime() : 0,
|
|
||||||
new SimpleModel(parseModel(modelDetail.getModel())),
|
|
||||||
event.getProjectId(),
|
|
||||||
modelDetail.getTrigger(),
|
|
||||||
event.getStageId(),
|
|
||||||
event.getTaskId(),
|
|
||||||
modelDetail.getBuildNum(),
|
|
||||||
modelDetail.getDebug()
|
|
||||||
);
|
|
||||||
sendToCallBack(new CallBackData<>(callBackEvent, buildEvent), list);
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> void sendToCallBack(CallBackData<T> callBackData, List<ProjectPipelineCallBack> list){
|
|
||||||
String requestBody = com.alibaba.fastjson.JSON.toJSONString(callBackData);
|
|
||||||
|
|
||||||
list.forEach(callBack -> {
|
|
||||||
String uniqueId = "";
|
|
||||||
if (callBackData.getData() instanceof PipelineEvent) {
|
|
||||||
uniqueId = ((PipelineEvent) callBackData.getData()).getPipelineId();
|
|
||||||
} else if (callBackData.getData() instanceof BuildEvent) {
|
|
||||||
uniqueId = ((BuildEvent) callBackData.getData()).getBuildId();
|
|
||||||
}
|
|
||||||
|
|
||||||
Watcher watcher = new Watcher(callBack.getProjectId() + "|" + callBack.getCallBackUrl() +
|
|
||||||
"|" + callBack.getEvents() + "|" + uniqueId);
|
|
||||||
try {
|
|
||||||
logger.info(callBack.getProjectId() + "|" + callBack.getCallBackUrl() + "|" +
|
|
||||||
uniqueId + "|" + callBack.getEvents() + "|send to callback");
|
|
||||||
if (callBack.getCallBackUrl().isBlank()) {
|
|
||||||
logger.warn("[" + callBack.getProjectId() + "]| call back url is empty!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
send(uniqueId, callBack, requestBody);
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("BKSystemErrorMonitor|" + callBack.getProjectId() + "|" +
|
|
||||||
callBack.getCallBackUrl() + "|" + callBack.getEvents() + "|" + e.getMessage(), e);
|
|
||||||
} finally {
|
|
||||||
watcher.stop();
|
|
||||||
LogUtils.printCostTimeWE(watcher, 2000,5000);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void send(String uniqueId, ProjectPipelineCallBack callBack, String requestBody) {
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
Request.Builder builder = new Request.Builder()
|
|
||||||
.url(callBack.getCallBackUrl())
|
|
||||||
.header("X-DEVOPS-WEBHOOK-TOKEN", callBack.getSecretToken() != null ? callBack.getSecretToken() : "NONE")
|
|
||||||
// TODO .header(TraceTag.TRACE_HEADER_DEVOPS_BIZID, TraceTag.buildBiz())
|
|
||||||
.post(RequestBody.create(JSON, requestBody));
|
|
||||||
|
|
||||||
if (callBack.getSecretParam() != null) {
|
|
||||||
callBack.getSecretParam().secret(builder);
|
|
||||||
}
|
|
||||||
|
|
||||||
Request request = builder.build();
|
|
||||||
|
|
||||||
String errorMsg = null;
|
|
||||||
ProjectPipelineCallbackStatus status = ProjectPipelineCallbackStatus.SUCCESS;
|
|
||||||
CircuitBreaker breaker = callbackCircuitBreakerRegistry.circuitBreaker(callBack.getCallBackUrl());
|
|
||||||
try {
|
|
||||||
breaker.executeCallable(() -> {
|
|
||||||
// TODO HttpRetryUtils.retry(MAX_RETRY_COUNT, () -> {
|
|
||||||
// callbackClient.newCall(request).execute().closeQuietly();
|
|
||||||
// });
|
|
||||||
if (callBack.getFailureTime() != null) {
|
|
||||||
projectPipelineCallBackService.updateFailureTime(
|
|
||||||
callBack.getProjectId(),
|
|
||||||
callBack.getId(),
|
|
||||||
null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
} catch (CallNotPermittedException e) {
|
|
||||||
logger.warn(
|
|
||||||
"[" + callBack.getProjectId() + "]|CALL_BACK|url=" + callBack.getCallBackUrl() +
|
|
||||||
"|" + callBack.getEvents() + "|failureRate=" + breaker.getMetrics().getFailureRate() +
|
|
||||||
"|" + e.getMessage()
|
|
||||||
);
|
|
||||||
checkIfNeedDisable(breaker, callBack);
|
|
||||||
errorMsg = e.getMessage();
|
|
||||||
status = ProjectPipelineCallbackStatus.FAILED;
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn(
|
|
||||||
"BKSystemErrorMonitor|[" + callBack.getProjectId() + "]|CALL_BACK|" +
|
|
||||||
"url=" + callBack.getCallBackUrl() + "|" + callBack.getEvents(),
|
|
||||||
e
|
|
||||||
);
|
|
||||||
errorMsg = e.getMessage();
|
|
||||||
status = ProjectPipelineCallbackStatus.FAILED;
|
|
||||||
} finally {
|
|
||||||
String originUrl = projectPipelineCallBackUrlGenerator.decodeCallbackUrl(
|
|
||||||
request.url().toString()
|
|
||||||
);
|
|
||||||
String realUrl = originUrl.substring(originUrl.indexOf("?"));
|
|
||||||
try {
|
|
||||||
String host = new URL(realUrl).getHost();
|
|
||||||
Counter.builder(PIPELINE_CALLBACK_COUNT)
|
|
||||||
.tags(
|
|
||||||
Tags.of("status", status.name())
|
|
||||||
.and("host",host)
|
|
||||||
.and("event", callBack.getEvents())
|
|
||||||
)
|
|
||||||
.register(meterRegistry)
|
|
||||||
.increment();
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
saveHistory(
|
|
||||||
callBack,
|
|
||||||
Collections.singletonList(new ProjectPipelineCallBackHistory.CallBackHeader("X-DEVOPS-WEBHOOK-UNIQUE-ID", uniqueId)),
|
|
||||||
status.name(),
|
|
||||||
errorMsg,
|
|
||||||
startTime,
|
|
||||||
System.currentTimeMillis()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkIfNeedDisable(CircuitBreaker breaker, ProjectPipelineCallBack callBack) {
|
|
||||||
if (breaker.getMetrics().getFailureRate() == 100.0F) {
|
|
||||||
long duration = 0;
|
|
||||||
if (callBack.getFailureTime() != null) {
|
|
||||||
duration = System.currentTimeMillis() - callBack.getFailureTime().atOffset(ZoneOffset.UTC).toInstant().toEpochMilli();
|
|
||||||
} else {
|
|
||||||
projectPipelineCallBackService.updateFailureTime(
|
|
||||||
callBack.getProjectId(),
|
|
||||||
callBack.getId(),
|
|
||||||
LocalDateTime.now()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (duration >= failureDisableTimePeriod) {
|
|
||||||
logger.warn(
|
|
||||||
"disable callbacks because of 100% failure rate|" +
|
|
||||||
"[" + callBack.getProjectId() + "]|CALL_BACK|url=" + callBack.getCallBackUrl() +
|
|
||||||
"|" + callBack.getEvents() + "|duration=" + duration
|
|
||||||
);
|
|
||||||
projectPipelineCallBackService.disable(callBack.getProjectId(), callBack.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveHistory(
|
|
||||||
ProjectPipelineCallBack callBack,
|
|
||||||
List<ProjectPipelineCallBackHistory.CallBackHeader> requestHeaders,
|
|
||||||
String status,
|
|
||||||
String errorMsg,
|
|
||||||
long startTime,
|
|
||||||
long endTime
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
projectPipelineCallBackService.createHistory(
|
|
||||||
new ProjectPipelineCallBackHistory(
|
|
||||||
serviceAllocIdResource.generateSegmentId(AllocIdGenerateConstant.PROJECT_PIPELINE_CALLBACK_HISTORY)
|
|
||||||
,
|
|
||||||
callBack.getProjectId(),
|
|
||||||
callBack.getCallBackUrl(),
|
|
||||||
callBack.getEvents(),
|
|
||||||
status,
|
|
||||||
requestHeaders,
|
|
||||||
"",
|
|
||||||
0,
|
|
||||||
"",
|
|
||||||
errorMsg,
|
|
||||||
null,
|
|
||||||
startTime,
|
|
||||||
endTime
|
|
||||||
// client.get(ServiceAllocIdResource.class)
|
|
||||||
// .generateSegmentId("PROJECT_PIPELINE_CALLBACK_HISTORY").getData()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
logger.error("[" + callBack.getProjectId() + "]|[" + callBack.getCallBackUrl() +
|
|
||||||
"]|[" + callBack.getEvents() + "]|save fail", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<SimpleStage> parseModel(Model model) {
|
|
||||||
List<SimpleStage> stages = new ArrayList<>();
|
|
||||||
for (int pos = 0; pos < model.getStages().size(); pos++) {
|
|
||||||
Stage s = model.getStages().get(pos);
|
|
||||||
List<SimpleJob> jobs = new ArrayList<>();
|
|
||||||
SimpleStage stage = new SimpleStage(
|
|
||||||
"Stage-" + (pos + 1),
|
|
||||||
s.getName() != null ? s.getName() : "",
|
|
||||||
jobs
|
|
||||||
);
|
|
||||||
logger.info("parseModel " + model.getName() + "|" + stage.getStageName() +
|
|
||||||
"|" + stage.getName() + "|");
|
|
||||||
stage.setStartTime(s.getStartEpoch() != null ? s.getStartEpoch() : 0);
|
|
||||||
stages.add(stage);
|
|
||||||
|
|
||||||
Triple<Long, Long, BuildStatus> triple = parseJob(s, jobs);
|
|
||||||
long stageStartTimeMills = triple.getLeft();
|
|
||||||
long stageEndTimeMills = triple.getMiddle();
|
|
||||||
BuildStatus stageStatus = triple.getRight();
|
|
||||||
|
|
||||||
if (stage.getStartTime() == 0L && stageStartTimeMills > 0) {
|
|
||||||
stage.setStartTime(stageStartTimeMills);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stageEndTimeMills > 0) {
|
|
||||||
stage.setEndTime(stageEndTimeMills);
|
|
||||||
}
|
|
||||||
|
|
||||||
stage.setStatus(stageStatus.name());
|
|
||||||
}
|
|
||||||
return stages;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Triple<Long, Long, BuildStatus> parseJob(Stage s, List<SimpleJob> jobs) {
|
|
||||||
long stageStartTimeMills = Long.MAX_VALUE;
|
|
||||||
long stageEndTimeMills = 1L;
|
|
||||||
BuildStatus stageStatus = BuildStatus.QUEUE;
|
|
||||||
for (Container c : s.getContainers()) {
|
|
||||||
BuildStatus jobStatus = BuildStatus.parse(c.getStatus());
|
|
||||||
long jobStartTimeMills = c.getStartEpoch() != null ? c.getStartEpoch() : 0L;
|
|
||||||
long jobEndTimeMills = jobStatus.isFinish() ?
|
|
||||||
jobStartTimeMills + (c.getElementElapsed() != null ? c.getElementElapsed() : 0) +
|
|
||||||
(c.getSystemElapsed() != null ? c.getSystemElapsed() : 0) : 0;
|
|
||||||
|
|
||||||
if (stageStartTimeMills > jobStartTimeMills) {
|
|
||||||
stageStartTimeMills = jobStartTimeMills;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jobEndTimeMills == 0L) {
|
|
||||||
stageStatus = jobStatus;
|
|
||||||
stageEndTimeMills = jobEndTimeMills;
|
|
||||||
} else if (stageEndTimeMills >= 1 && stageEndTimeMills < jobEndTimeMills) {
|
|
||||||
stageEndTimeMills = jobEndTimeMills;
|
|
||||||
if (jobStatus.isFailure()) {
|
|
||||||
stageStatus = jobStatus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
jobs.add(
|
|
||||||
new SimpleJob(
|
|
||||||
c.getName(),
|
|
||||||
jobStatus.name(),
|
|
||||||
jobStartTimeMills,
|
|
||||||
jobEndTimeMills,
|
|
||||||
parseTask(c)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stageEndTimeMills > 0 && !stageStatus.isFinish()) {
|
|
||||||
stageStatus = BuildStatus.SUCCEED;
|
|
||||||
}
|
|
||||||
return new ImmutableTriple<>(stageStartTimeMills, stageEndTimeMills, stageStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<SimpleTask> parseTask(Container c) {
|
|
||||||
List<SimpleTask> tasks = new ArrayList<>();
|
|
||||||
for (Element e : c.getElements()) {
|
|
||||||
long taskStartTimeMills = e.getStartEpoch() != null ? e.getStartEpoch() : 0;
|
|
||||||
BuildStatus taskStatus = BuildStatus.parse(e.getStatus());
|
|
||||||
long taskEndTimeMills = taskStatus.isFinish() ?
|
|
||||||
taskStartTimeMills + (e.getElapsed() != null ? e.getElapsed() : 0) : 0;
|
|
||||||
tasks.add(
|
|
||||||
new SimpleTask(
|
|
||||||
e.getId(),
|
|
||||||
e.getName(),
|
|
||||||
e.getAtomCode(),
|
|
||||||
taskStatus.name(),
|
|
||||||
taskStartTimeMills,
|
|
||||||
taskEndTimeMills
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return tasks;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.listener;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.service.utils.LogUtils;
|
|
||||||
import cd.casic.ci.process.process.engine.control.CallBackControl;
|
|
||||||
import cd.casic.ci.process.process.engine.pojo.event.PipelineCreateEvent;
|
|
||||||
import cd.casic.ci.process.process.engine.service.AgentPipelineRefService;
|
|
||||||
import cd.casic.ci.process.process.engine.service.PipelineAtomStatisticsService;
|
|
||||||
import cd.casic.ci.process.process.engine.service.PipelineWebhookService;
|
|
||||||
import cd.casic.ci.process.process.engine.service.RepoPipelineRefService;
|
|
||||||
import cd.casic.framework.commons.util.watcher.Watcher;
|
|
||||||
import cd.casic.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
|
|
||||||
import com.github.fppt.jedismock.operations.transactions.Watch;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
/**
|
|
||||||
* MQ实现的流水线创建事件
|
|
||||||
*
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class MQPipelineCreateListener extends AbstractRedisStreamMessageListener<PipelineCreateEvent> {
|
|
||||||
private PipelineWebhookService pipelineWebhookService;
|
|
||||||
private PipelineAtomStatisticsService pipelineAtomStatisticsService;
|
|
||||||
private CallBackControl callBackControl;
|
|
||||||
private AgentPipelineRefService agentPipelineRefService;
|
|
||||||
private RepoPipelineRefService repoPipelineRefService;
|
|
||||||
@Override
|
|
||||||
public void onMessage(PipelineCreateEvent event) {
|
|
||||||
String id = String.format("%s|CreatePipeline#%s|%s",
|
|
||||||
event.getTraceId(),event.getPipelineId(),event.getUserId()
|
|
||||||
);
|
|
||||||
Watcher watcher = new Watcher(id);
|
|
||||||
|
|
||||||
watcher.safeAround("callback",()-> {
|
|
||||||
callBackControl.pipelineCreateEvent(event.getProjectId(), event.getPipelineId());
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("updateAtomPipelineNum",()->{
|
|
||||||
pipelineAtomStatisticsService.updateAtomPipelineNum(
|
|
||||||
event.getProjectId(),
|
|
||||||
event.getPipelineId(),
|
|
||||||
event.getVersion()!=null ?event.getVersion(): 1,
|
|
||||||
false,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("updateAgentPipelineRef",()->{
|
|
||||||
agentPipelineRefService.updateAgentPipelineRef(event.getUserId(), "create_pipeline", event.getProjectId(), event.getPipelineId());
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("addWebhook",()-> {
|
|
||||||
pipelineWebhookService.addWebhook(
|
|
||||||
event.getProjectId(),
|
|
||||||
event.getPipelineId(),
|
|
||||||
event.getVersion(),
|
|
||||||
event.getUserId()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("savePipelineRefRepository",()->{
|
|
||||||
repoPipelineRefService.updateRepoPipelineRef(event.getUserId(), "create_pipeline", event.getProjectId(), event.getPipelineId());
|
|
||||||
}) ;
|
|
||||||
|
|
||||||
LogUtils.printCostTimeWE(watcher);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.listener;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.service.utils.LogUtils;
|
|
||||||
import cd.casic.ci.process.process.engine.control.CallBackControl;
|
|
||||||
import cd.casic.ci.process.process.engine.pojo.event.PipelineCreateEvent;
|
|
||||||
import cd.casic.ci.process.process.engine.pojo.event.PipelineDeleteEvent;
|
|
||||||
import cd.casic.ci.process.process.engine.service.*;
|
|
||||||
import cd.casic.framework.commons.util.watcher.Watcher;
|
|
||||||
import cd.casic.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
/**
|
|
||||||
* MQ实现的流水线删除事件
|
|
||||||
*
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class MQPipelineDeleteListener extends AbstractRedisStreamMessageListener<PipelineDeleteEvent> {
|
|
||||||
@Resource
|
|
||||||
private PipelineRuntimeService pipelineRuntimeService;
|
|
||||||
@Resource
|
|
||||||
private PipelineWebhookService pipelineWebhookService;
|
|
||||||
@Resource
|
|
||||||
private PipelineGroupService pipelineGroupService;
|
|
||||||
@Resource
|
|
||||||
private PipelineAtomStatisticsService pipelineAtomStatisticsService;
|
|
||||||
@Resource
|
|
||||||
private CallBackControl callBackControl;
|
|
||||||
@Resource
|
|
||||||
private AgentPipelineRefService agentPipelineRefService;
|
|
||||||
@Resource
|
|
||||||
private RepoPipelineRefService repoPipelineRefService;
|
|
||||||
@Override
|
|
||||||
public void onMessage(PipelineDeleteEvent event) {
|
|
||||||
String id = String.format("%s|DeletePipeline#%s|%s}",
|
|
||||||
event.getTraceId(),
|
|
||||||
event.getPipelineId(),
|
|
||||||
event.isClearUpModel());
|
|
||||||
Watcher watcher = new Watcher(id);
|
|
||||||
final String projectId = event.getProjectId();
|
|
||||||
final String pipelineId = event.getPipelineId();
|
|
||||||
final String userId = event.getUserId();
|
|
||||||
|
|
||||||
watcher.safeAround("cancelPendingTask",()->{
|
|
||||||
pipelineRuntimeService.cancelPendingTask(projectId, pipelineId, userId);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (event.isClearUpModel()) {
|
|
||||||
watcher.safeAround("deleteExt",()-> {
|
|
||||||
pipelineGroupService.deleteAllUserFavorByPipeline(userId, projectId, pipelineId); // 删除收藏该流水线上所有记录
|
|
||||||
pipelineGroupService.deletePipelineLabel(userId, projectId, pipelineId);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
watcher.safeAround("deleteWebhook",()->{
|
|
||||||
pipelineWebhookService.deleteWebhook(projectId, pipelineId, userId);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("updateAgentPipelineRef",()->{
|
|
||||||
agentPipelineRefService.updateAgentPipelineRef(userId, "delete_pipeline", projectId, pipelineId);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("updateAtomPipelineNum",()->{
|
|
||||||
pipelineAtomStatisticsService.updateAtomPipelineNum(
|
|
||||||
event.getProjectId(),
|
|
||||||
event.getPipelineId(),
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("updateAgentPipelineRef",()->{
|
|
||||||
repoPipelineRefService.updateRepoPipelineRef(userId, "delete_pipeline", projectId, pipelineId);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("callback",
|
|
||||||
()->{
|
|
||||||
callBackControl.pipelineDeleteEvent(event.getProjectId(), event.getPipelineId());
|
|
||||||
});
|
|
||||||
|
|
||||||
LogUtils.printCostTimeWE(watcher);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.listener;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.service.utils.LogUtils;
|
|
||||||
import cd.casic.ci.process.process.engine.control.CallBackControl;
|
|
||||||
import cd.casic.ci.process.process.engine.pojo.event.PipelineDeleteEvent;
|
|
||||||
import cd.casic.ci.process.process.engine.pojo.event.PipelineRestoreEvent;
|
|
||||||
import cd.casic.ci.process.process.engine.service.AgentPipelineRefService;
|
|
||||||
import cd.casic.ci.process.process.engine.service.PipelineAtomStatisticsService;
|
|
||||||
import cd.casic.ci.process.process.engine.service.RepoPipelineRefService;
|
|
||||||
import cd.casic.framework.commons.util.watcher.Watcher;
|
|
||||||
import cd.casic.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MQ实现的流水线恢复事件
|
|
||||||
*
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class MQPipelineRestoreListener extends AbstractRedisStreamMessageListener<PipelineRestoreEvent> {
|
|
||||||
@Resource
|
|
||||||
private AgentPipelineRefService agentPipelineRefService;
|
|
||||||
@Resource
|
|
||||||
private PipelineAtomStatisticsService pipelineAtomStatisticsService;
|
|
||||||
@Resource
|
|
||||||
private CallBackControl callBackControl;
|
|
||||||
@Resource
|
|
||||||
private RepoPipelineRefService repoPipelineRefService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(PipelineRestoreEvent event) {
|
|
||||||
String id = String.format("%s|RestorePipeline#%s|%s}",
|
|
||||||
event.getTraceId(),
|
|
||||||
event.getPipelineId(),
|
|
||||||
event.getUserId()
|
|
||||||
) ;
|
|
||||||
Watcher watcher = new Watcher(id);
|
|
||||||
try {
|
|
||||||
watcher.start("updateAgentPipelineRef");
|
|
||||||
String userId = event.getUserId();
|
|
||||||
String projectId = event.getProjectId();
|
|
||||||
String pipelineId = event.getPipelineId();
|
|
||||||
Integer version = event.getVersion();
|
|
||||||
agentPipelineRefService.updateAgentPipelineRef(userId, "restore_pipeline", projectId, pipelineId);
|
|
||||||
|
|
||||||
watcher.stop();
|
|
||||||
watcher.start("updateAtomPipelineNum");
|
|
||||||
pipelineAtomStatisticsService.updateAtomPipelineNum(
|
|
||||||
projectId,
|
|
||||||
pipelineId,
|
|
||||||
version,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
watcher.stop();
|
|
||||||
watcher.start("callback");
|
|
||||||
callBackControl.pipelineRestoreEvent(projectId, pipelineId);
|
|
||||||
repoPipelineRefService.updateRepoPipelineRef(userId, "restore_pipeline", projectId, pipelineId);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
watcher.stop();
|
|
||||||
LogUtils.printCostTimeWE(watcher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.listener;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.service.utils.LogUtils;
|
|
||||||
import cd.casic.ci.process.process.engine.control.CallBackControl;
|
|
||||||
import cd.casic.ci.process.process.engine.pojo.event.PipelineRestoreEvent;
|
|
||||||
import cd.casic.ci.process.process.engine.pojo.event.PipelineStreamEnabledEvent;
|
|
||||||
import cd.casic.framework.commons.util.watcher.Watcher;
|
|
||||||
import cd.casic.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MQ实现的流水线开启Stream事件
|
|
||||||
*
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class MQPipelineStreamEnabledListener extends AbstractRedisStreamMessageListener<PipelineStreamEnabledEvent> {
|
|
||||||
@Resource
|
|
||||||
private CallBackControl callBackControl;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(PipelineStreamEnabledEvent event) {
|
|
||||||
String id = String.format("%s|RestorePipeline#%s|%s}",
|
|
||||||
event.getTraceId(),
|
|
||||||
event.getPipelineId(),
|
|
||||||
event.getUserId()
|
|
||||||
) ;
|
|
||||||
Watcher watcher =new Watcher(id);
|
|
||||||
try {
|
|
||||||
watcher.start("callback");
|
|
||||||
callBackControl.pipelineStreamEnabledEvent(
|
|
||||||
event
|
|
||||||
);
|
|
||||||
watcher.stop();
|
|
||||||
} finally {
|
|
||||||
watcher.stop();
|
|
||||||
LogUtils.printCostTimeWE(watcher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.listener;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.service.utils.LogUtils;
|
|
||||||
import cd.casic.ci.process.process.engine.control.CallBackControl;
|
|
||||||
import cd.casic.ci.process.process.engine.pojo.event.PipelineUpdateEvent;
|
|
||||||
import cd.casic.ci.process.process.engine.service.AgentPipelineRefService;
|
|
||||||
import cd.casic.ci.process.process.engine.service.PipelineAtomStatisticsService;
|
|
||||||
import cd.casic.ci.process.process.engine.service.PipelineWebhookService;
|
|
||||||
import cd.casic.ci.process.process.engine.service.RepoPipelineRefService;
|
|
||||||
import cd.casic.framework.commons.util.watcher.Watcher;
|
|
||||||
import cd.casic.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MQ实现的流水线更新事件
|
|
||||||
*
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class MQPipelineUpdateListener extends AbstractRedisStreamMessageListener<PipelineUpdateEvent> {
|
|
||||||
private PipelineAtomStatisticsService pipelineAtomStatisticsService;
|
|
||||||
private CallBackControl callBackControl;
|
|
||||||
private AgentPipelineRefService agentPipelineRefService;
|
|
||||||
private PipelineWebhookService pipelineWebhookService;
|
|
||||||
private RepoPipelineRefService repoPipelineRefService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMessage(PipelineUpdateEvent event) {
|
|
||||||
String id = String.format("%s|RestorePipeline#%s|%s}",
|
|
||||||
event.getTraceId(),
|
|
||||||
event.getPipelineId(),
|
|
||||||
event.getUserId()
|
|
||||||
) ;
|
|
||||||
Watcher watcher = new Watcher(id);
|
|
||||||
final String projectId = event.getProjectId();
|
|
||||||
final String pipelineId = event.getPipelineId();
|
|
||||||
final String userId = event.getUserId();
|
|
||||||
final Integer version = event.getVersion();
|
|
||||||
|
|
||||||
watcher.safeAround("callback",()->{
|
|
||||||
callBackControl.pipelineUpdateEvent(projectId, pipelineId);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("updateAgentPipelineRef",()->{
|
|
||||||
agentPipelineRefService.updateAgentPipelineRef(userId, "update_pipeline", projectId, pipelineId);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("updateAtomPipelineNum",()->{
|
|
||||||
pipelineAtomStatisticsService.updateAtomPipelineNum(projectId,pipelineId, version,false,false);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("addWebhook",()->{
|
|
||||||
pipelineWebhookService.addWebhook(
|
|
||||||
projectId ,
|
|
||||||
pipelineId ,
|
|
||||||
version ,
|
|
||||||
userId
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
watcher.safeAround("updateAgentPipelineRef",()->{
|
|
||||||
|
|
||||||
repoPipelineRefService.updateRepoPipelineRef(userId, "update_pipeline", projectId, pipelineId);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
LogUtils.printCostTimeWE(watcher);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.pojo.event;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.BuildNo;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.Element;
|
|
||||||
import cd.casic.ci.event.enums.ActionType;
|
|
||||||
import cd.casic.ci.event.pojo.pipeline.IPipelineEvent;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建流水线事件
|
|
||||||
*
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class PipelineCreateEvent extends IPipelineEvent {
|
|
||||||
|
|
||||||
private BuildNo buildNo;
|
|
||||||
private String pipelineName;
|
|
||||||
private Element element;
|
|
||||||
private Integer version;
|
|
||||||
private Map<String, Object> variables;
|
|
||||||
|
|
||||||
public PipelineCreateEvent(
|
|
||||||
String source,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
BuildNo buildNo,
|
|
||||||
String pipelineName,
|
|
||||||
Element element,
|
|
||||||
Integer version,
|
|
||||||
Map<String, Object> variables,
|
|
||||||
ActionType actionType,
|
|
||||||
int delayMills
|
|
||||||
) {
|
|
||||||
super(actionType, source, projectId, pipelineId, userId, delayMills);
|
|
||||||
this.buildNo = buildNo;
|
|
||||||
this.pipelineName = pipelineName;
|
|
||||||
this.element = element;
|
|
||||||
this.version = version;
|
|
||||||
this.variables = variables;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PipelineCreateEvent(
|
|
||||||
String source,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId
|
|
||||||
) {
|
|
||||||
this(source, projectId, pipelineId, userId, null, null, null, 1, null, ActionType.START, 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.pojo.event;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.BuildNo;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.Element;
|
|
||||||
import cd.casic.ci.event.enums.ActionType;
|
|
||||||
import cd.casic.ci.event.pojo.pipeline.IPipelineEvent;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建流水线事件
|
|
||||||
*
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除流水线事件
|
|
||||||
*
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@ToString(callSuper = true)
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
//@Event(StreamBinding.PIPELINE_DELETE)
|
|
||||||
public class PipelineDeleteEvent extends IPipelineEvent {
|
|
||||||
|
|
||||||
private final boolean clearUpModel;
|
|
||||||
|
|
||||||
public PipelineDeleteEvent(
|
|
||||||
String source,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
boolean clearUpModel
|
|
||||||
) {
|
|
||||||
this(source, projectId, pipelineId, userId, clearUpModel, ActionType.START, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PipelineDeleteEvent(
|
|
||||||
String source,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
boolean clearUpModel,
|
|
||||||
ActionType actionType,
|
|
||||||
int delayMills
|
|
||||||
) {
|
|
||||||
super(actionType, source, projectId, pipelineId, userId, delayMills);
|
|
||||||
this.clearUpModel = clearUpModel;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.pojo.event;
|
|
||||||
|
|
||||||
import cd.casic.ci.event.pojo.pipeline.IPipelineEvent;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class PipelineRestoreEvent extends IPipelineEvent {
|
|
||||||
private Integer version;
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.pojo.event;
|
|
||||||
|
|
||||||
import cd.casic.ci.event.pojo.pipeline.IPipelineEvent;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class PipelineStreamEnabledEvent extends IPipelineEvent {
|
|
||||||
private Long gitProjectId;
|
|
||||||
private String gitProjectUrl;
|
|
||||||
private Boolean enable;
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.pojo.event;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.BuildNo;
|
|
||||||
import cd.casic.ci.event.pojo.pipeline.IPipelineEvent;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
/**
|
|
||||||
* 更新流水线事件
|
|
||||||
*
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
public class PipelineUpdateEvent extends IPipelineEvent {
|
|
||||||
private Integer version;
|
|
||||||
private BuildNo buildNo;
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.service;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.Model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建机流水线引用服务接口
|
|
||||||
*/
|
|
||||||
public interface AgentPipelineRefService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新构建机流水线引用
|
|
||||||
*
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @param action 操作类型
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @param pipelineId 流水线ID
|
|
||||||
*/
|
|
||||||
void updateAgentPipelineRef(String userId, String action, String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分析流水线引用并保存
|
|
||||||
*
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @param action 操作类型
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @param pipelineId 流水线ID
|
|
||||||
* @param pipelineModel 流水线模型
|
|
||||||
*/
|
|
||||||
void analysisPipelineRefAndSave(
|
|
||||||
String userId,
|
|
||||||
String action,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Model pipelineModel
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新流水线引用
|
|
||||||
*
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @param pipelineId 流水线ID
|
|
||||||
*/
|
|
||||||
void updatePipelineRef(String userId, String projectId, String pipelineId);
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.service;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 流水线插件统计相关的服务
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
public interface PipelineAtomStatisticsService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新插件对应的流水线数量
|
|
||||||
*/
|
|
||||||
void updateAtomPipelineNum(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer version,
|
|
||||||
Boolean deleteFlag,
|
|
||||||
Boolean restoreFlag
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加流水线数量更新
|
|
||||||
*/
|
|
||||||
void addPipelineNumUpdate(
|
|
||||||
Set<String> modelVersionAtomSet,
|
|
||||||
// List<StoreStatisticPipelineNumUpdate> pipelineNumUpdateList,
|
|
||||||
Boolean incrementFlag
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取版本模型字符串
|
|
||||||
*/
|
|
||||||
String getVersionModelString(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer version
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,114 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.service;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.api.process.pojo.classify.*;
|
|
||||||
import cd.casic.ci.process.process.dataObject.TPipelineFavorRecord;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 流水线分组服务接口
|
|
||||||
*/
|
|
||||||
public interface PipelineGroupService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分组列表
|
|
||||||
*/
|
|
||||||
List<PipelineGroup> getGroups(String userId, String projectId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定流水线的分组列表
|
|
||||||
*/
|
|
||||||
List<PipelineGroupWithLabels> getGroups(String userId, String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加分组
|
|
||||||
*/
|
|
||||||
Boolean addGroup(String userId, PipelineGroupCreate pipelineGroup);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新分组
|
|
||||||
*/
|
|
||||||
Boolean updateGroup(String userId, PipelineGroupUpdate pipelineGroup);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除分组
|
|
||||||
*/
|
|
||||||
Boolean deleteGroup(String userId, String projectId, String groupId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加标签
|
|
||||||
*/
|
|
||||||
Boolean addLabel(String userId, String projectId, PipelineLabelCreate pipelineLabel);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除标签
|
|
||||||
*/
|
|
||||||
Boolean deleteLabel(String userId, String projectId, String labelId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新标签
|
|
||||||
*/
|
|
||||||
Boolean updateLabel(String userId, String projectId, PipelineLabelUpdate pipelineLabel);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除流水线标签
|
|
||||||
*/
|
|
||||||
void deletePipelineLabel(String userId, String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加流水线标签
|
|
||||||
*/
|
|
||||||
void addPipelineLabel(String userId, String projectId, String pipelineId, List<String> labelIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新流水线标签
|
|
||||||
*/
|
|
||||||
void updatePipelineLabel(String userId, String projectId, String pipelineId, List<String> labelIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取视图标签到流水线的映射
|
|
||||||
*/
|
|
||||||
Map<String, List<String>> getViewLabelToPipelinesMap(
|
|
||||||
String projectId,
|
|
||||||
List<String> labels
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分组到标签的映射
|
|
||||||
*/
|
|
||||||
Map<String, List<String>> getGroupToLabelsMap(String projectId, List<String> labels);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 收藏流水线
|
|
||||||
*/
|
|
||||||
Boolean favorPipeline(String userId, String projectId, String pipelineId, Boolean favor);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除流水线相关的所有收藏
|
|
||||||
*/
|
|
||||||
Integer deleteAllUserFavorByPipeline(String userId, String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取收藏的流水线列表
|
|
||||||
*/
|
|
||||||
List<String> getFavorPipelines(String userId, String projectId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取流水线分组标签
|
|
||||||
*/
|
|
||||||
Map<String, List<PipelineGroupLabels>> getPipelinesGroupLabel(
|
|
||||||
Collection<String> pipelineIds,
|
|
||||||
String projectId
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页获取收藏的流水线
|
|
||||||
*/
|
|
||||||
TPipelineFavorRecord getFavorPipelinesPage(
|
|
||||||
String userId,
|
|
||||||
Integer page,
|
|
||||||
Integer pageSize
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,425 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.service;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.Model;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.BuildStatus;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.ChannelCode;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.StartType;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.BuildParameters;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.ErrorInfo;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.time.BuildRecordTimeCost;
|
|
||||||
import cd.casic.ci.process.api.engine.pojo.BuildInfo;
|
|
||||||
import cd.casic.ci.process.api.process.enums.HistorySearchType;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.*;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.app.StartBuildContext;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.pipeline.PipelineLatestBuild;
|
|
||||||
import cd.casic.ci.process.process.dataObject.TPipelineBuildSummaryRecord;
|
|
||||||
import cd.casic.ci.process.process.dataObject.TPipelineInfoRecord;
|
|
||||||
import cd.casic.ci.process.process.pojo.LatestRunningBuild;
|
|
||||||
import cd.casic.ci.process.process.pojo.PipelineFilterParam;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 流水线运行时相关的服务接口
|
|
||||||
*/
|
|
||||||
public interface PipelineRuntimeService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消待处理的任务
|
|
||||||
*/
|
|
||||||
void cancelPendingTask(String projectId, String pipelineId, String userId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建信息
|
|
||||||
*/
|
|
||||||
BuildInfo getBuildInfo(String projectId, String buildId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建信息
|
|
||||||
*/
|
|
||||||
BuildInfo getBuildInfo(String projectId, String pipelineId, String buildId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取运行中的构建数量
|
|
||||||
*/
|
|
||||||
int getRunningBuildCount(String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据并发组获取构建列表
|
|
||||||
*/
|
|
||||||
List<Pair<String, String>> getBuildInfoListByConcurrencyGroup(
|
|
||||||
String projectId,
|
|
||||||
String concurrencyGroup,
|
|
||||||
List<BuildStatus> status
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建号
|
|
||||||
*/
|
|
||||||
Map<String, String> getBuildNoByByPair(Set<String> buildIds, String projectId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建摘要记录
|
|
||||||
*/
|
|
||||||
TPipelineBuildSummaryRecord getBuildSummaryRecord(String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取流水线构建记录
|
|
||||||
*/
|
|
||||||
TPipelineInfoRecord getBuildPipelineRecords(
|
|
||||||
String projectId,
|
|
||||||
ChannelCode channelCode,
|
|
||||||
Collection<String> pipelineIds,
|
|
||||||
PipelineSortType sortType,
|
|
||||||
List<String> favorPipelines,
|
|
||||||
List<String> authPipelines,
|
|
||||||
String viewId,
|
|
||||||
List<PipelineFilterParam> pipelineFilterParamList,
|
|
||||||
Boolean permissionFlag,
|
|
||||||
Integer page,
|
|
||||||
Integer pageSize
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取最新构建
|
|
||||||
*/
|
|
||||||
Map<String, PipelineLatestBuild> getLatestBuild(String projectId, List<String> pipelineIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取流水线构建历史
|
|
||||||
*/
|
|
||||||
List<BuildHistory> listPipelineBuildHistory(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
int offset,
|
|
||||||
int limit,
|
|
||||||
Boolean updateTimeDesc
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取流水线构建历史
|
|
||||||
*/
|
|
||||||
List<BuildHistory> listPipelineBuildHistory(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
int offset,
|
|
||||||
int limit,
|
|
||||||
List<String> materialAlias,
|
|
||||||
String materialUrl,
|
|
||||||
List<String> materialBranch,
|
|
||||||
String materialCommitId,
|
|
||||||
String materialCommitMessage,
|
|
||||||
List<BuildStatus> status,
|
|
||||||
List<StartType> trigger,
|
|
||||||
Long queueTimeStartTime,
|
|
||||||
Long queueTimeEndTime,
|
|
||||||
Long startTimeStartTime,
|
|
||||||
Long startTimeEndTime,
|
|
||||||
Long endTimeStartTime,
|
|
||||||
Long endTimeEndTime,
|
|
||||||
Long totalTimeMin,
|
|
||||||
Long totalTimeMax,
|
|
||||||
String remark,
|
|
||||||
Integer buildNoStart,
|
|
||||||
Integer buildNoEnd,
|
|
||||||
String buildMsg,
|
|
||||||
List<String> startUser,
|
|
||||||
Boolean updateTimeDesc,
|
|
||||||
Boolean debug,
|
|
||||||
List<String> triggerAlias,
|
|
||||||
List<String> triggerBranch,
|
|
||||||
List<String> triggerUser
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新构建备注
|
|
||||||
*/
|
|
||||||
void updateBuildRemark(String projectId, String pipelineId, String buildId, String remark);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取历史条件仓库
|
|
||||||
*/
|
|
||||||
List<String> getHistoryConditionRepo(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer debugVersion,
|
|
||||||
String search,
|
|
||||||
HistorySearchType type
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取历史条件分支
|
|
||||||
*/
|
|
||||||
List<String> getHistoryConditionBranch(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
List<String> aliasList,
|
|
||||||
Integer debugVersion,
|
|
||||||
String search,
|
|
||||||
HistorySearchType type
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建历史
|
|
||||||
*/
|
|
||||||
BuildHistory getBuildHistoryByBuildNum(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer buildNum,
|
|
||||||
Set<BuildStatus> statusSet,
|
|
||||||
Boolean debug
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建基本信息
|
|
||||||
*/
|
|
||||||
Map<String, BuildBasicInfo> getBuildBasicInfoByIds(Set<String> buildIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建历史
|
|
||||||
*/
|
|
||||||
BuildHistory getBuildHistoryById(String projectId, String buildId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取启动用户
|
|
||||||
*/
|
|
||||||
String getStartUser(String projectId, String buildId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建历史
|
|
||||||
*/
|
|
||||||
List<BuildHistory> getBuildHistoryByIds(
|
|
||||||
Set<String> buildIds,
|
|
||||||
String startBeginTime,
|
|
||||||
String endBeginTime,
|
|
||||||
String projectId
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消构建
|
|
||||||
*/
|
|
||||||
Boolean cancelBuild(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String buildId,
|
|
||||||
String userId,
|
|
||||||
int executeCount,
|
|
||||||
BuildStatus buildStatus,
|
|
||||||
Boolean terminateFlag
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 开始构建
|
|
||||||
*/
|
|
||||||
BuildId startBuild(Model fullModel, StartBuildContext context);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新构建号
|
|
||||||
*/
|
|
||||||
void updateBuildNo(String projectId, String pipelineId, int buildNo, Boolean debug);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新执行次数
|
|
||||||
*/
|
|
||||||
void updateExecuteCount(String projectId, String buildId, int executeCount);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 开始最新运行构建
|
|
||||||
*/
|
|
||||||
void startLatestRunningBuild(LatestRunningBuild latestRunningBuild);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 完成最新运行构建
|
|
||||||
*/
|
|
||||||
void finishLatestRunningBuild(
|
|
||||||
LatestRunningBuild latestRunningBuild,
|
|
||||||
BuildStatus currentBuildStatus,
|
|
||||||
List<ErrorInfo> errorInfoList,
|
|
||||||
BuildRecordTimeCost timeCost
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建参数
|
|
||||||
*/
|
|
||||||
List<BuildParameters> getBuildParametersFromStartup(
|
|
||||||
String projectId,
|
|
||||||
String buildId
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取执行时间
|
|
||||||
*/
|
|
||||||
Long getExecuteTime(String projectId, String buildId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取上次构建
|
|
||||||
*/
|
|
||||||
BuildInfo getLastTimeBuild(String projectId, String pipelineId, Boolean debug);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取流水线构建历史数量
|
|
||||||
*/
|
|
||||||
int getPipelineBuildHistoryCount(String projectId, String pipelineId, Integer debugVersion);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建
|
|
||||||
*/
|
|
||||||
List<String> getBuilds(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Set<BuildStatus> buildStatus,
|
|
||||||
Integer debugVersion
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取流水线构建历史数量
|
|
||||||
*/
|
|
||||||
int getPipelineBuildHistoryCount(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
List<String> materialAlias,
|
|
||||||
String materialUrl,
|
|
||||||
List<String> materialBranch,
|
|
||||||
String materialCommitId,
|
|
||||||
String materialCommitMessage,
|
|
||||||
List<BuildStatus> status,
|
|
||||||
List<StartType> trigger,
|
|
||||||
Long queueTimeStartTime,
|
|
||||||
Long queueTimeEndTime,
|
|
||||||
Long startTimeStartTime,
|
|
||||||
Long startTimeEndTime,
|
|
||||||
Long endTimeStartTime,
|
|
||||||
Long endTimeEndTime,
|
|
||||||
Long totalTimeMin,
|
|
||||||
Long totalTimeMax,
|
|
||||||
String remark,
|
|
||||||
Integer buildNoStart,
|
|
||||||
Integer buildNoEnd,
|
|
||||||
String buildMsg,
|
|
||||||
List<String> startUser,
|
|
||||||
Boolean debug,
|
|
||||||
List<String> triggerAlias,
|
|
||||||
List<String> triggerBranch,
|
|
||||||
List<String> triggerUser
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取总构建历史数量
|
|
||||||
*/
|
|
||||||
int getTotalBuildHistoryCount(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
List<BuildStatus> status,
|
|
||||||
Long startTimeEndTime
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有构建号
|
|
||||||
*/
|
|
||||||
Collection<Integer> getAllBuildNum(String projectId, String pipelineId, Integer debugVersion);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取最新构建ID
|
|
||||||
*/
|
|
||||||
String getLatestBuildId(String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取最新完成构建ID
|
|
||||||
*/
|
|
||||||
String getLatestFinishedBuildId(String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取最新成功构建ID
|
|
||||||
*/
|
|
||||||
String getLatestSucceededBuildId(String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取最新失败构建ID
|
|
||||||
*/
|
|
||||||
String getLatestFailedBuildId(String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据构建号获取构建ID
|
|
||||||
*/
|
|
||||||
String getBuildIdByBuildNum(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
int buildNum,
|
|
||||||
Integer debugVersion
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新构建信息状态为排队
|
|
||||||
*/
|
|
||||||
void updateBuildInfoStatus2Queue(String projectId, String buildId, BuildStatus oldStatus, String showMsg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新制品列表
|
|
||||||
*/
|
|
||||||
Boolean updateArtifactList(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String buildId,
|
|
||||||
String artifactListJsonString
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新构建历史阶段状态
|
|
||||||
*/
|
|
||||||
void updateBuildHistoryStageState(String projectId, String buildId, List<BuildStageStatus> allStageStatus);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新推荐版本
|
|
||||||
*/
|
|
||||||
void updateRecommendVersion(String projectId, String buildId, String recommendVersion);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新构建参数
|
|
||||||
*/
|
|
||||||
Boolean updateBuildParameters(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String buildId,
|
|
||||||
Collection<BuildParameters> buildParameters,
|
|
||||||
Boolean debug
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 并发取消构建流水线
|
|
||||||
*/
|
|
||||||
void concurrencyCancelBuildPipeline(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String buildId,
|
|
||||||
String userId,
|
|
||||||
String groupName,
|
|
||||||
String detailUrl
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新异步状态
|
|
||||||
*/
|
|
||||||
void updateAsyncStatus(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String buildId,
|
|
||||||
String taskId,
|
|
||||||
int executeCount,
|
|
||||||
String asyncStatus
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取构建变量服务
|
|
||||||
*/
|
|
||||||
Map<String, String> getBuildVariableService(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String buildId,
|
|
||||||
Set<String> keys
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,118 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.service;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.Model;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.RepositoryConfig;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.ScmType;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.trigger.enums.CodeEventType;
|
|
||||||
import cd.casic.ci.log.scm.dal.pojo.Repository;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.webhook.PipelineWebhook;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.webhook.WebhookTriggerPipeline;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 流水线Webhook服务接口
|
|
||||||
*/
|
|
||||||
public interface PipelineWebhookService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加Webhook
|
|
||||||
*/
|
|
||||||
void addWebhook(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer version,
|
|
||||||
String userId
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册Webhook
|
|
||||||
*/
|
|
||||||
Repository registerWebhook(
|
|
||||||
String projectId,
|
|
||||||
ScmType scmType,
|
|
||||||
RepositoryConfig repositoryConfig,
|
|
||||||
CodeEventType codeEventType,
|
|
||||||
String elementVersion
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除Webhook
|
|
||||||
*/
|
|
||||||
Boolean deleteWebhook(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除指定任务的Webhook
|
|
||||||
*/
|
|
||||||
Boolean deleteWebhook(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String taskId,
|
|
||||||
String userId
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取模型
|
|
||||||
*/
|
|
||||||
Model getModel(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer version
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取触发流水线列表
|
|
||||||
*/
|
|
||||||
List<WebhookTriggerPipeline> getTriggerPipelines(
|
|
||||||
String name,
|
|
||||||
ScmType repositoryType,
|
|
||||||
List<String> yamlPipelineIds
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 列出触发流水线
|
|
||||||
*/
|
|
||||||
List<WebhookTriggerPipeline> listTriggerPipeline(
|
|
||||||
String projectId,
|
|
||||||
String repositoryHashId,
|
|
||||||
String eventType
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取项目名称
|
|
||||||
*/
|
|
||||||
String getProjectName(String projectName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取外部名称
|
|
||||||
*/
|
|
||||||
String getExternalName(ScmType scmType, String projectName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 列出Webhook
|
|
||||||
*/
|
|
||||||
List<PipelineWebhook> listWebhook(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer page,
|
|
||||||
Integer pageSize
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取Webhook
|
|
||||||
*/
|
|
||||||
PipelineWebhook get(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String repositoryHashId,
|
|
||||||
String eventType
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.engine.service;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.Model;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.RepositoryConfig;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.Element;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 流水线代码库使用服务接口
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
public interface RepoPipelineRefService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新代码库流水线引用
|
|
||||||
*
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @param action 操作类型
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @param pipelineId 流水线ID
|
|
||||||
*/
|
|
||||||
void updateRepoPipelineRef(String userId, String action, String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新流水线引用
|
|
||||||
*
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @param pipelineId 流水线ID
|
|
||||||
*/
|
|
||||||
void updatePipelineRef(String userId, String projectId, String pipelineId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新所有流水线引用
|
|
||||||
*
|
|
||||||
* @param projectId 项目ID,可为空
|
|
||||||
*/
|
|
||||||
void updateAllPipelineRef(String projectId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分析流水线引用并保存
|
|
||||||
*
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @param action 操作类型
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @param pipelineId 流水线ID
|
|
||||||
* @param model 流水线模型
|
|
||||||
* @param channel 渠道
|
|
||||||
*/
|
|
||||||
void analysisPipelineRefAndSave(
|
|
||||||
String userId,
|
|
||||||
String action,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Model model,
|
|
||||||
String channel
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取任务参数
|
|
||||||
*
|
|
||||||
* @param element 元素
|
|
||||||
* @return 任务参数Map
|
|
||||||
*/
|
|
||||||
Map<String, Object> getTaskParams(Element element);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取市场构建代码库配置
|
|
||||||
*
|
|
||||||
* @param input 输入参数
|
|
||||||
* @param variables 变量Map
|
|
||||||
* @return 代码库配置
|
|
||||||
*/
|
|
||||||
RepositoryConfig getMarketBuildRepoConfig(Map<?, ?> input, Map<String, String> variables);
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.pojo;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
@Schema(title = "插件参数替换信息")
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class AtomParamReplaceInfo {
|
|
||||||
|
|
||||||
@Schema(title = "被替换插件参数名称", required = true)
|
|
||||||
private String fromParamName;
|
|
||||||
|
|
||||||
@Schema(title = "替换插件参数名称", required = true)
|
|
||||||
private String toParamName;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Schema(title = "替换插件参数值,不传默认用被替换插件参数值替换", required = false)
|
|
||||||
@Builder.Default
|
|
||||||
private Object toParamValue = null;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Schema(title = "替换插件默认参数值,如果没有指定替换插件参数值且被替换插件参数没有值则用该默认值作为替换插件参数值", required = false)
|
|
||||||
@Builder.Default
|
|
||||||
private Object toParamDefaultValue = null;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Schema(title = "参数自定义转换接口url地址,接口参数结构需统一", required = false)
|
|
||||||
@Builder.Default
|
|
||||||
private String paramConvertUrl = null;
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.pojo;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Schema(title = "插件版本替换信息")
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class AtomVersionReplaceInfo {
|
|
||||||
|
|
||||||
@Schema(title = "被替换插件版本", required = true)
|
|
||||||
private String fromAtomVersion;
|
|
||||||
|
|
||||||
@Schema(title = "替换插件版本", required = true)
|
|
||||||
private String toAtomVersion;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Schema(title = "插件参数替换信息", required = false)
|
|
||||||
@Builder.Default
|
|
||||||
private List<AtomParamReplaceInfo> paramReplaceInfoList = null;
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.pojo;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.enums.BuildStatus;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class LatestRunningBuild {
|
|
||||||
private String projectId;
|
|
||||||
private String pipelineId;
|
|
||||||
private String buildId;
|
|
||||||
private int buildNum;
|
|
||||||
private String userId;
|
|
||||||
private BuildStatus status = BuildStatus.RUNNING;
|
|
||||||
private int taskCount = 0;
|
|
||||||
private LocalDateTime endTime;
|
|
||||||
private String currentTaskId;
|
|
||||||
private String currentTaskName;
|
|
||||||
private int executeCount;
|
|
||||||
private boolean debug;
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.pojo;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.api.process.pojo.classify.PipelineViewFilterByLabel;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
@Data
|
|
||||||
public class PipelineFilterByLabelInfo {
|
|
||||||
List<PipelineViewFilterByLabel> filterByLabels;
|
|
||||||
Map<String, List<String>> labelToPipelineMap;
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.pojo;
|
|
||||||
|
|
||||||
import cd.casic.ci.process.api.process.pojo.classify.PipelineViewFilterByCreator;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.classify.PipelineViewFilterByName;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.classify.enums.Logic;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class PipelineFilterParam {
|
|
||||||
private Logic logic;
|
|
||||||
private List<PipelineViewFilterByName> filterByPipelineNames;
|
|
||||||
private List<PipelineViewFilterByCreator> filterByPipelineCreators;
|
|
||||||
private PipelineFilterByLabelInfo filterByLabelInfo;
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.pojo;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Schema(title = "流水线关联标签数据")
|
|
||||||
@Data
|
|
||||||
public class PipelineLabelRelateInfo{
|
|
||||||
@Schema(title = "项目id")
|
|
||||||
private final String projectId;
|
|
||||||
|
|
||||||
@Schema(title = "流水线id")
|
|
||||||
private final String pipelineId;
|
|
||||||
|
|
||||||
@Schema(title = "标签id")
|
|
||||||
private final Long labelId;
|
|
||||||
|
|
||||||
@Schema(title = "标签名称")
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
@Schema(title = "创建者")
|
|
||||||
private final String createUser;
|
|
||||||
|
|
||||||
@Schema(title = "创建时间")
|
|
||||||
private final LocalDateTime createTime;
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.pojo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class PipelineWebHookQueue {
|
|
||||||
private Long id;
|
|
||||||
private String pipelineId;
|
|
||||||
private Long sourceProjectId;
|
|
||||||
private String sourceRepoName;
|
|
||||||
private String sourceBranch;
|
|
||||||
private Long targetProjectId;
|
|
||||||
private String targetRepoName;
|
|
||||||
private String targetBranch;
|
|
||||||
private String buildId;
|
|
||||||
private Long createTime;
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.pojo;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.enums.BuildStatus;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.ErrorType;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.ElementAdditionalOptions;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Map;
|
|
||||||
@Data
|
|
||||||
public class UpdateTaskInfo {
|
|
||||||
private String projectId; // 项目ID
|
|
||||||
private String buildId; // 构建ID
|
|
||||||
private String taskId; // 任务ID
|
|
||||||
private int executeCount;
|
|
||||||
private BuildStatus taskStatus; // 构建状态
|
|
||||||
private String starter; // 启动人
|
|
||||||
private String approver; // 审批人
|
|
||||||
private LocalDateTime startTime; // 开始时间
|
|
||||||
private LocalDateTime endTime; // 结束时间
|
|
||||||
private Long totalTime; // 耗费时间
|
|
||||||
private ElementAdditionalOptions additionalOptions;
|
|
||||||
private Map<String, Object> taskParams;
|
|
||||||
private ErrorType errorType;
|
|
||||||
private Integer errorCode;
|
|
||||||
private String errorMsg;
|
|
||||||
private String platformCode; // 对接平台代码
|
|
||||||
private Integer platformErrorCode; // 对接平台错误码
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.audit;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.model.SQLPage;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.audit.Audit;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.audit.AuditInfo;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.audit.QueryAudit;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
|
|
||||||
public interface AuditService {
|
|
||||||
Long createAudit(Audit audit);
|
|
||||||
|
|
||||||
Pair<SQLPage<AuditInfo>, Boolean> userList(QueryAudit queryAudit, Integer offset, Integer limit);
|
|
||||||
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.audit.impl;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.constant.CommonConstants;
|
|
||||||
import cd.casic.ci.common.pipeline.model.SQLPage;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.audit.Audit;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.audit.AuditInfo;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.audit.QueryAudit;
|
|
||||||
import cd.casic.ci.process.process.constant.AllocIdGenerateConstant;
|
|
||||||
import cd.casic.ci.process.process.dal.audit.AuditDao;
|
|
||||||
import cd.casic.ci.process.process.dataObject.TAuditResourceRecord;
|
|
||||||
import cd.casic.ci.process.process.service.audit.AuditService;
|
|
||||||
import cd.casic.ci.project.service.ServiceAllocIdResource;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class AuditServiceImpl implements AuditService {
|
|
||||||
@Resource
|
|
||||||
private AuditDao auditDao;
|
|
||||||
@Resource
|
|
||||||
private ServiceAllocIdResource serviceAllocIdResource;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Long createAudit(Audit audit) {
|
|
||||||
Long id = serviceAllocIdResource.generateSegmentId(AllocIdGenerateConstant.AUDIT_RESOURCE);
|
|
||||||
return auditDao.create(
|
|
||||||
audit.getResourceType(),
|
|
||||||
audit.getResourceId(),
|
|
||||||
audit.getResourceName(),
|
|
||||||
audit.getUserId(),
|
|
||||||
audit.getAction(),
|
|
||||||
audit.getActionContent(),
|
|
||||||
audit.getProjectId(),
|
|
||||||
id
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Pair<SQLPage<AuditInfo>, Boolean> userList(QueryAudit queryAudit, Integer offset, Integer limit) {
|
|
||||||
Long count = auditDao.countByResourceTye(queryAudit);
|
|
||||||
List<TAuditResourceRecord> auditRecordList = auditDao.listByResourceTye(queryAudit, offset, limit);
|
|
||||||
List<AuditInfo> auditList = auditRecordList.stream().map(it -> {
|
|
||||||
String statusStr = "1".equals(it.getStatus()) ? CommonConstants.SUCCESS : CommonConstants.FAIL;
|
|
||||||
return new AuditInfo(
|
|
||||||
it.getStatus(),
|
|
||||||
it.getResourceType(),
|
|
||||||
it.getResourceId(),
|
|
||||||
it.getResourceName(),
|
|
||||||
it.getUserId(),
|
|
||||||
it.getCreatedTime().getTime(),
|
|
||||||
it.getAction(),
|
|
||||||
it.getActionContent()
|
|
||||||
);
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
return new ImmutablePair<>(new SQLPage<>(count,auditList),true);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,304 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.Model;
|
|
||||||
import cd.casic.ci.common.pipeline.container.Container;
|
|
||||||
import cd.casic.ci.common.pipeline.container.Stage;
|
|
||||||
import cd.casic.ci.process.process.service.base.dispatcher.PipelineEventDispatcher;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.BuildStatus;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.ChannelCode;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.Element;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.BuildStageStatus;
|
|
||||||
import cd.casic.ci.process.process.dal.pipeline.PipelineBuildDao;
|
|
||||||
import cd.casic.ci.process.process.dal.record.BuildDetailDao;
|
|
||||||
import cd.casic.ci.process.process.dataObject.TPipelineBuildDetailRecord;
|
|
||||||
import cd.casic.ci.process.process.service.base.pojo.PipelineBuildWebSocketPushEvent;
|
|
||||||
import cd.casic.ci.process.process.service.base.pojo.enums.RefreshType;
|
|
||||||
import cd.casic.framework.commons.util.watcher.LogUtils;
|
|
||||||
import cd.casic.framework.commons.util.watcher.Watcher;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.assertj.core.util.Preconditions;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static cd.casic.ci.common.pipeline.constant.CommonConstants.*;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class BaseBuildDetailServiceImpl {
|
|
||||||
|
|
||||||
|
|
||||||
protected static final String TRIGGER_STAGE = "stage-1";
|
|
||||||
|
|
||||||
protected PipelineBuildDao pipelineBuildDao;
|
|
||||||
protected BuildDetailDao buildDetailDao;
|
|
||||||
private StageTagServiceImpl stageTagServiceImpl;
|
|
||||||
private PipelineEventDispatcher pipelineEventDispatcher;
|
|
||||||
|
|
||||||
// TODO 更改redis逻辑
|
|
||||||
// protected RedisOperation redisOperation;
|
|
||||||
|
|
||||||
public BaseBuildDetailServiceImpl(
|
|
||||||
PipelineBuildDao pipelineBuildDao,
|
|
||||||
BuildDetailDao buildDetailDao,
|
|
||||||
StageTagServiceImpl stageTagServiceImpl,
|
|
||||||
PipelineEventDispatcher pipelineEventDispatcher
|
|
||||||
// RedisOperation redisOperation
|
|
||||||
) {
|
|
||||||
|
|
||||||
this.pipelineBuildDao = pipelineBuildDao;
|
|
||||||
this.buildDetailDao = buildDetailDao;
|
|
||||||
this.stageTagServiceImpl = stageTagServiceImpl;
|
|
||||||
this.pipelineEventDispatcher = pipelineEventDispatcher;
|
|
||||||
// this.redisOperation = redisOperation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Model getBuildModel(String projectId, String buildId) {
|
|
||||||
var record = buildDetailDao.get(projectId, buildId);
|
|
||||||
if (record == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return JSON.parseObject(record.getModel(), Model.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Model update(
|
|
||||||
String projectId,
|
|
||||||
String buildId,
|
|
||||||
ModelInterface modelInterface,
|
|
||||||
BuildStatus buildStatus,
|
|
||||||
String cancelUser,
|
|
||||||
String operation
|
|
||||||
) {
|
|
||||||
Watcher watcher = new Watcher("updateDetail#" + buildId + "#" + operation);
|
|
||||||
String message = "nothing";
|
|
||||||
TPipelineBuildDetailRecord record = null;
|
|
||||||
// var lock = new PipelineBuildDetailLock(redisOperation, buildId);
|
|
||||||
ReentrantLock lock = new ReentrantLock();
|
|
||||||
try {
|
|
||||||
watcher.start("lock");
|
|
||||||
lock.lock();
|
|
||||||
|
|
||||||
watcher.start("getDetail");
|
|
||||||
record = buildDetailDao.get(projectId, buildId);
|
|
||||||
Preconditions.checkArgument(record != null, "The build detail is not exist");
|
|
||||||
|
|
||||||
watcher.start("model");
|
|
||||||
var model = JSON.parseObject(record.getModel(), Model.class);
|
|
||||||
|
|
||||||
watcher.start("traverseModel");
|
|
||||||
traverseModel(model, modelInterface);
|
|
||||||
watcher.stop();
|
|
||||||
|
|
||||||
String modelStr = null;
|
|
||||||
if (modelInterface.needUpdate()) {
|
|
||||||
watcher.start("toJson");
|
|
||||||
modelStr = JSON.toJSONString(model, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
var statusPair = takeBuildStatus(record, buildStatus);
|
|
||||||
if ((modelStr == null || modelStr.isBlank()) && !statusPair.getFirst()) {
|
|
||||||
message = "Will not update";
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
watcher.start("updateModel");
|
|
||||||
buildDetailDao.update(
|
|
||||||
projectId,
|
|
||||||
buildId,
|
|
||||||
modelStr,
|
|
||||||
statusPair.getSecond(),
|
|
||||||
cancelUser != null ? cancelUser :
|
|
||||||
(buildStatus.isCancel() && record.getCancelUser() == null) ? "System" : null
|
|
||||||
);
|
|
||||||
|
|
||||||
message = "update done";
|
|
||||||
return model;
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
message = ignored.getMessage() != null ? ignored.getMessage() : "";
|
|
||||||
log.warn("[" + buildId + "]| Fail to update the build detail: " + ignored.getMessage(), ignored);
|
|
||||||
watcher.start("getDetail");
|
|
||||||
Preconditions.checkArgument(record != null, "The build detail is not exist");
|
|
||||||
watcher.start("model");
|
|
||||||
return JSON.parseObject(record.getModel(), Model.class);
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
log.info("[" + buildId + "|" + buildStatus + "]|" + operation + "|update_detail_model| " + message);
|
|
||||||
if (message.equals("update done")) {
|
|
||||||
watcher.start("dispatchEvent");
|
|
||||||
pipelineDetailChangeEvent(projectId, buildId);
|
|
||||||
}
|
|
||||||
LogUtils.printCostTimeWE(watcher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<BuildStageStatus> fetchHistoryStageStatus(
|
|
||||||
Model model,
|
|
||||||
BuildStatus buildStatus,
|
|
||||||
List<String> reviewers,
|
|
||||||
String errorMsg,
|
|
||||||
String cancelUser
|
|
||||||
) {
|
|
||||||
Map<String, String> stageTagMap = stageTagServiceImpl.getAllStageTag().stream()
|
|
||||||
.collect(Collectors.toMap(tag -> tag.getId(), tag -> tag.getStageTagName()));
|
|
||||||
|
|
||||||
String statusMessage;
|
|
||||||
String reason;
|
|
||||||
if (buildStatus == BuildStatus.REVIEWING) {
|
|
||||||
statusMessage = BUILD_REVIEWING;
|
|
||||||
reason = reviewers != null ? String.join(",", reviewers) : null;
|
|
||||||
} else if (buildStatus == BuildStatus.STAGE_SUCCESS) {
|
|
||||||
statusMessage = BUILD_STAGE_SUCCESS;
|
|
||||||
reason = null;
|
|
||||||
} else if (buildStatus.isFailure()) {
|
|
||||||
statusMessage = BUILD_FAILED;
|
|
||||||
reason = errorMsg != null ? errorMsg : buildStatus.name();
|
|
||||||
} else if (buildStatus.isCancel()) {
|
|
||||||
statusMessage = BUILD_CANCELED;
|
|
||||||
reason = cancelUser;
|
|
||||||
} else if (buildStatus.isSuccess()) {
|
|
||||||
statusMessage = BUILD_COMPLETED;
|
|
||||||
reason = null;
|
|
||||||
} else {
|
|
||||||
statusMessage = BUILD_RUNNING;
|
|
||||||
reason = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return model.getStages().stream()
|
|
||||||
.map(stage -> new BuildStageStatus(
|
|
||||||
stage.getId(),
|
|
||||||
stage.getName() != null ? stage.getName() : stage.getId(),
|
|
||||||
stage.getStatus(),
|
|
||||||
stage.getTag() != null ? stage.getTag().stream()
|
|
||||||
.map(tag -> stageTagMap.getOrDefault(tag, "null"))
|
|
||||||
.collect(Collectors.toList()) : null,
|
|
||||||
stage.getStartEpoch(),
|
|
||||||
stage.getElapsed(),
|
|
||||||
null,
|
|
||||||
stage.getId().equals(TRIGGER_STAGE) ?
|
|
||||||
"" : null
|
|
||||||
))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Pair<Boolean, BuildStatus> takeBuildStatus(
|
|
||||||
TPipelineBuildDetailRecord record,
|
|
||||||
BuildStatus buildStatus
|
|
||||||
) {
|
|
||||||
var oldStatus = BuildStatus.parse(record.getStatus());
|
|
||||||
if (!oldStatus.isFinish()) {
|
|
||||||
return new Pair<>(true, buildStatus);
|
|
||||||
} else {
|
|
||||||
return new Pair<>(false, oldStatus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void traverseModel(Model model, ModelInterface modelInterface) {
|
|
||||||
for (var stage : model.getStages()) {
|
|
||||||
var traverse = modelInterface.onFindStage(stage, model);
|
|
||||||
if (traverse == Traverse.BREAK) {
|
|
||||||
return;
|
|
||||||
} else if (traverse == Traverse.SKIP) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var container : stage.getContainers()) {
|
|
||||||
var cTraverse = modelInterface.onFindContainer(container, stage);
|
|
||||||
if (cTraverse == Traverse.BREAK) {
|
|
||||||
return;
|
|
||||||
} else if (cTraverse == Traverse.SKIP) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var elements = container.getElements();
|
|
||||||
for (int i = 0; i < elements.size(); i++) {
|
|
||||||
if (modelInterface.onFindElement(i, elements.get(i), container) == Traverse.BREAK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Boolean.TRUE.equals(container.getMatrixGroupFlag())) {
|
|
||||||
var groupContainers = container.fetchGroupContainers();
|
|
||||||
if (groupContainers != null) {
|
|
||||||
for (var groupContainer : groupContainers) {
|
|
||||||
var gTraverse = modelInterface.onFindContainer(groupContainer, stage);
|
|
||||||
if (gTraverse == Traverse.BREAK) {
|
|
||||||
return;
|
|
||||||
} else if (gTraverse == Traverse.SKIP) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var groupElements = groupContainer.getElements();
|
|
||||||
for (int i = 0; i < groupElements.size(); i++) {
|
|
||||||
if (modelInterface.onFindElement(i, groupElements.get(i), groupContainer) == Traverse.BREAK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pipelineDetailChangeEvent(String projectId, String buildId) {
|
|
||||||
var pipelineBuildInfo = pipelineBuildDao.getUserBuildInfo( projectId, buildId);
|
|
||||||
if (pipelineBuildInfo != null && pipelineBuildInfo.getChannelCode() == ChannelCode.GIT) {
|
|
||||||
pipelineEventDispatcher.dispatch(
|
|
||||||
new PipelineBuildWebSocketPushEvent(
|
|
||||||
"recordDetail",
|
|
||||||
pipelineBuildInfo.getProjectId(),
|
|
||||||
pipelineBuildInfo.getPipelineId(),
|
|
||||||
pipelineBuildInfo.getStartUser(),
|
|
||||||
buildId,
|
|
||||||
RefreshType.DETAIL.getBinary() | RefreshType.RECORD.getBinary(),
|
|
||||||
pipelineBuildInfo.getExecuteCount()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected interface ModelInterface {
|
|
||||||
default Traverse onFindStage(Stage stage, Model model) {
|
|
||||||
return Traverse.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
default Traverse onFindContainer(Container container, Stage stage) {
|
|
||||||
return Traverse.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
default Traverse onFindElement(int index, Element e, Container c) {
|
|
||||||
return Traverse.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean needUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Traverse {
|
|
||||||
BREAK,
|
|
||||||
CONTINUE,
|
|
||||||
SKIP
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Pair<A, B> {
|
|
||||||
private final A first;
|
|
||||||
private final B second;
|
|
||||||
|
|
||||||
public Pair(A first, B second) {
|
|
||||||
this.first = first;
|
|
||||||
this.second = second;
|
|
||||||
}
|
|
||||||
|
|
||||||
public A getFirst() {
|
|
||||||
return first;
|
|
||||||
}
|
|
||||||
|
|
||||||
public B getSecond() {
|
|
||||||
return second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,375 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.Model;
|
|
||||||
import cd.casic.ci.common.pipeline.container.Container;
|
|
||||||
import cd.casic.ci.common.pipeline.container.Stage;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.BuildStatus;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.StartType;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.BuildFormProperty;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.Element;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.ElementAdditionalOptions;
|
|
||||||
import cd.casic.ci.process.api.engine.pojo.BuildInfo;
|
|
||||||
import cd.casic.ci.process.api.engine.pojo.PipelineInfo;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.BuildStageStatus;
|
|
||||||
import cd.casic.ci.process.api.process.utils.PipelineVarUtil;
|
|
||||||
import cd.casic.ci.process.process.dal.engin.PipelineTriggerReviewDao;
|
|
||||||
import cd.casic.ci.process.process.dataObject.TPipelineBuildDetailRecord;
|
|
||||||
import cd.casic.ci.process.process.dataObject.TPipelineBuildSummaryRecord;
|
|
||||||
import cd.casic.ci.process.process.service.base.dispatcher.PipelineEventDispatcher;
|
|
||||||
import cd.casic.ci.common.pipeline.utils.ModelUtils;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.pipeline.ModelDetail;
|
|
||||||
import cd.casic.ci.process.process.dal.pipeline.PipelineBuildDao;
|
|
||||||
import cd.casic.ci.process.process.dal.record.BuildDetailDao;
|
|
||||||
import cd.casic.ci.process.process.dal.record.PipelineBuildSummaryDao;
|
|
||||||
import cd.casic.ci.process.process.service.base.engin.service.PipelineRepositoryService;
|
|
||||||
import cd.casic.ci.process.process.service.base.engin.util.ContainerUtils;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.github.fppt.jedismock.operations.RedisOperation;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class PipelineBuildDetailServiceImpl extends BaseBuildDetailServiceImpl {
|
|
||||||
|
|
||||||
@Value("${pipeline.build.retry.limit_days:21}")
|
|
||||||
private int retryLimitDays;
|
|
||||||
|
|
||||||
private final PipelineRepositoryService pipelineRepositoryService;
|
|
||||||
private PipelineBuildSummaryDao pipelineBuildSummaryDao;
|
|
||||||
private final PipelineTriggerReviewDao pipelineTriggerReviewDao;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public PipelineBuildDetailServiceImpl(
|
|
||||||
PipelineRepositoryService pipelineRepositoryService,
|
|
||||||
PipelineBuildSummaryDao pipelineBuildSummaryDao,
|
|
||||||
PipelineTriggerReviewDao pipelineTriggerReviewDao,
|
|
||||||
PipelineBuildDao pipelineBuildDao,
|
|
||||||
BuildDetailDao buildDetailDao,
|
|
||||||
RedisOperation redisOperation,
|
|
||||||
StageTagServiceImpl stageTagServiceImpl,
|
|
||||||
PipelineEventDispatcher pipelineEventDispatcher
|
|
||||||
) {
|
|
||||||
super(pipelineBuildDao, buildDetailDao, stageTagServiceImpl, pipelineEventDispatcher);
|
|
||||||
this.pipelineRepositoryService = pipelineRepositoryService;
|
|
||||||
this.pipelineBuildSummaryDao = pipelineBuildSummaryDao;
|
|
||||||
this.pipelineTriggerReviewDao = pipelineTriggerReviewDao;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkPassDays(Long startTime) {
|
|
||||||
if (retryLimitDays < 0 || startTime == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return (System.currentTimeMillis() - startTime) < TimeUnit.DAYS.toMillis(retryLimitDays);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询ModelDetail
|
|
||||||
* @param projectId 项目Id
|
|
||||||
* @param buildId 构建Id
|
|
||||||
* @param refreshStatus 是否刷新状态
|
|
||||||
*/
|
|
||||||
public ModelDetail get(String projectId, String buildId, boolean refreshStatus) {
|
|
||||||
TPipelineBuildDetailRecord record = buildDetailDao.get(projectId, buildId);
|
|
||||||
if (record == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildInfo buildInfo = pipelineBuildDao.getUserBuildInfo(
|
|
||||||
projectId,
|
|
||||||
buildId
|
|
||||||
);
|
|
||||||
if (buildInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
PipelineInfo pipelineInfo = pipelineRepositoryService.getPipelineInfo(projectId, buildInfo.getPipelineId(),null,false);
|
|
||||||
if (pipelineInfo == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
TPipelineBuildSummaryRecord buildSummaryRecord = pipelineBuildSummaryDao.get(projectId, buildInfo.getPipelineId());
|
|
||||||
Model model = JSON.parseObject(record.getModel(), Model.class);
|
|
||||||
|
|
||||||
if (refreshStatus) {
|
|
||||||
if (checkPassDays(buildInfo.getStartTime())) {
|
|
||||||
ModelUtils.refreshCanRetry(model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var triggerContainer = model.getTriggerContainer();
|
|
||||||
if (triggerContainer.getBuildNo() != null) {
|
|
||||||
triggerContainer.getBuildNo().setCurrentBuildNo(
|
|
||||||
buildSummaryRecord != null ? buildSummaryRecord.getBuildNo() : triggerContainer.getBuildNo().getBuildNo()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BuildFormProperty> params = triggerContainer.getParams();
|
|
||||||
List<BuildFormProperty> newParams = new ArrayList<BuildFormProperty>(params.size());
|
|
||||||
params.forEach(it -> {
|
|
||||||
var newVarName = PipelineVarUtil.oldVarToNewVar(it.getId());
|
|
||||||
if (newVarName != null && !newVarName.isBlank()) {
|
|
||||||
BuildFormProperty buildFormProperty = new BuildFormProperty();
|
|
||||||
BeanUtils.copyProperties(it,buildFormProperty);
|
|
||||||
buildFormProperty.setId(newVarName);
|
|
||||||
newParams.add(buildFormProperty);
|
|
||||||
} else {
|
|
||||||
newParams.add(it);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
triggerContainer.setParams(newParams);
|
|
||||||
|
|
||||||
model.getStages().forEach(stage -> {
|
|
||||||
stage.resetBuildOption(false);
|
|
||||||
stage.getContainers().forEach(container -> {
|
|
||||||
container.setContainerHashId(container.getContainerHashId() != null ?
|
|
||||||
container.getContainerHashId() : container.getContainerId());
|
|
||||||
container.setContainerId(container.getId());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
List<String> triggerReviewers = pipelineTriggerReviewDao.getTriggerReviewers(
|
|
||||||
projectId,
|
|
||||||
pipelineInfo.getPipelineId(),
|
|
||||||
buildId
|
|
||||||
);
|
|
||||||
|
|
||||||
return new ModelDetail(
|
|
||||||
record.getBuildId(),
|
|
||||||
buildInfo.getPipelineId(),
|
|
||||||
model.getName(),
|
|
||||||
record.getStartUser() != null ? record.getStartUser() : "",
|
|
||||||
buildInfo.getTriggerUser(),
|
|
||||||
StartType.toReadableString(
|
|
||||||
buildInfo.getTrigger(),
|
|
||||||
buildInfo.getChannelCode(),
|
|
||||||
""
|
|
||||||
),
|
|
||||||
record.getStartTime() != null ? record.getStartTime().getTime() :
|
|
||||||
LocalDateTime.now().atOffset(ZoneOffset.UTC).toInstant().toEpochMilli(),
|
|
||||||
record.getEndTime() != null ? record.getEndTime().getTime() : null,
|
|
||||||
record.getStatus() != null ? record.getStatus() : "",
|
|
||||||
model,
|
|
||||||
System.currentTimeMillis(),
|
|
||||||
buildInfo.getBuildNum(),
|
|
||||||
record.getCancelUser() != null ? record.getCancelUser() : "",
|
|
||||||
buildInfo.getVersion(),
|
|
||||||
pipelineInfo.getVersion(),
|
|
||||||
buildSummaryRecord != null ? buildSummaryRecord.getBuildNum() : -1,
|
|
||||||
pipelineInfo.getLastModifyUser(),
|
|
||||||
buildInfo.getExecuteTime(),
|
|
||||||
triggerReviewers,
|
|
||||||
buildInfo.isDebug()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateModel(String projectId, String buildId, Model model) {
|
|
||||||
buildDetailDao.update(
|
|
||||||
projectId,
|
|
||||||
buildId,
|
|
||||||
JSON.toJSONString(model, false),
|
|
||||||
BuildStatus.RUNNING,
|
|
||||||
null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void buildCancel(String projectId, String buildId, BuildStatus buildStatus, String cancelUser) {
|
|
||||||
log.info("Cancel the build {} by {}", buildId, cancelUser);
|
|
||||||
update(
|
|
||||||
projectId,
|
|
||||||
buildId,
|
|
||||||
new ModelInterface() {
|
|
||||||
private boolean update = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Traverse onFindStage(Stage stage, Model model) {
|
|
||||||
if (BuildStatus.parse(stage.getStatus()).isRunning()) {
|
|
||||||
stage.setStatus(buildStatus.name());
|
|
||||||
if (stage.getStartEpoch() == null) {
|
|
||||||
stage.setElapsed(0L);
|
|
||||||
} else {
|
|
||||||
stage.setElapsed(System.currentTimeMillis() - stage.getStartEpoch());
|
|
||||||
}
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
return Traverse.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Traverse onFindContainer(Container container, Stage stage) {
|
|
||||||
var status = BuildStatus.parse(container.getStatus());
|
|
||||||
if (status == BuildStatus.PREPARE_ENV) {
|
|
||||||
if (container.getStartEpoch() == null) {
|
|
||||||
container.setSystemElapsed(0L);
|
|
||||||
} else {
|
|
||||||
container.setSystemElapsed(System.currentTimeMillis() - container.getStartEpoch());
|
|
||||||
}
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var refreshFlag = status.isRunning() &&
|
|
||||||
(container.getElements().get(0).getStatus() == null ||
|
|
||||||
container.getElements().get(0).getStatus().isBlank()) &&
|
|
||||||
container.getContainPostTaskFlag() != Boolean.TRUE;
|
|
||||||
|
|
||||||
if (status == BuildStatus.PREPARE_ENV || refreshFlag) {
|
|
||||||
container.setName(ContainerUtils.getClearedQueueContainerName(container.getName()));
|
|
||||||
container.setStatus(buildStatus.name());
|
|
||||||
}
|
|
||||||
return Traverse.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Traverse onFindElement(int index, Element e, Container c) {
|
|
||||||
if (e.getStatus() != null &&
|
|
||||||
(e.getStatus().equals(BuildStatus.RUNNING.name()) ||
|
|
||||||
e.getStatus().equals(BuildStatus.REVIEWING.name()))) {
|
|
||||||
|
|
||||||
String status;
|
|
||||||
if (e.getStatus().equals(BuildStatus.RUNNING.name())) {
|
|
||||||
var runCondition = e.getAdditionalOptions() != null ?
|
|
||||||
e.getAdditionalOptions().getRunCondition() : null;
|
|
||||||
if (runCondition == ElementAdditionalOptions.RunCondition.PRE_TASK_FAILED_EVEN_CANCEL) {
|
|
||||||
status = BuildStatus.RUNNING.name();
|
|
||||||
} else {
|
|
||||||
status = BuildStatus.CANCELED.name();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
status = buildStatus.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
e.setStatus(status);
|
|
||||||
if (c.getContainPostTaskFlag() != Boolean.TRUE) {
|
|
||||||
c.setStatus(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BuildStatus.parse(status).isFinish()) {
|
|
||||||
if (e.getStartEpoch() != null) {
|
|
||||||
e.setElapsed(System.currentTimeMillis() - e.getStartEpoch());
|
|
||||||
}
|
|
||||||
|
|
||||||
long elementElapsed = 0L;
|
|
||||||
for (var element : c.getElements()) {
|
|
||||||
elementElapsed += element.getElapsed() != null ? element.getElapsed() : 0;
|
|
||||||
if (element == e) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.setElementElapsed(elementElapsed);
|
|
||||||
}
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
return Traverse.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean needUpdate() {
|
|
||||||
return update;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
BuildStatus.RUNNING,
|
|
||||||
cancelUser,
|
|
||||||
"buildCancel"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Pair<Model, List<BuildStageStatus>> buildEnd(
|
|
||||||
String projectId,
|
|
||||||
String buildId,
|
|
||||||
BuildStatus buildStatus,
|
|
||||||
String errorMsg
|
|
||||||
) {
|
|
||||||
log.info("[{}]|BUILD_END|buildStatus={}", buildId, buildStatus);
|
|
||||||
final List<BuildStageStatus> allStageStatus = new ArrayList<>();
|
|
||||||
|
|
||||||
var model = update(
|
|
||||||
projectId,
|
|
||||||
buildId,
|
|
||||||
new ModelInterface() {
|
|
||||||
private boolean update = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Traverse onFindContainer(Container container, Stage stage) {
|
|
||||||
if (BuildStatus.parse(container.getStatus()).isRunning()) {
|
|
||||||
container.setStatus(buildStatus.name());
|
|
||||||
update = true;
|
|
||||||
if (container.getStartEpoch() == null) {
|
|
||||||
container.setElementElapsed(0L);
|
|
||||||
} else {
|
|
||||||
container.setElementElapsed(System.currentTimeMillis() - container.getStartEpoch());
|
|
||||||
}
|
|
||||||
container.setName(ContainerUtils.getClearedQueueContainerName(container.getName()));
|
|
||||||
}
|
|
||||||
return Traverse.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Traverse onFindStage(Stage stage, Model model) {
|
|
||||||
if (allStageStatus.isEmpty()) {
|
|
||||||
allStageStatus.addAll(fetchHistoryStageStatus(model, buildStatus,null, errorMsg,null));
|
|
||||||
}
|
|
||||||
if (BuildStatus.parse(stage.getStatus()).isRunning()) {
|
|
||||||
stage.setStatus(buildStatus.name());
|
|
||||||
update = true;
|
|
||||||
if (stage.getStartEpoch() == null) {
|
|
||||||
stage.setElapsed(0L);
|
|
||||||
} else {
|
|
||||||
stage.setElapsed(System.currentTimeMillis() - stage.getStartEpoch());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Traverse.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Traverse onFindElement(int index, Element e, Container c) {
|
|
||||||
if (e.getStatus() != null && !e.getStatus().isBlank() &&
|
|
||||||
BuildStatus.valueOf(e.getStatus()).isRunning()) {
|
|
||||||
e.setStatus(buildStatus.name());
|
|
||||||
update = true;
|
|
||||||
if (e.getStartEpoch() != null) {
|
|
||||||
e.setElapsed(System.currentTimeMillis() - e.getStartEpoch());
|
|
||||||
}
|
|
||||||
|
|
||||||
long elementElapsed = 0L;
|
|
||||||
for (var element : c.getElements()) {
|
|
||||||
elementElapsed += element.getElapsed() != null ? element.getElapsed() : 0;
|
|
||||||
if (element == e) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
c.setElementElapsed(elementElapsed);
|
|
||||||
}
|
|
||||||
return Traverse.CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean needUpdate() {
|
|
||||||
return update;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
buildStatus,null,
|
|
||||||
"buildEnd"
|
|
||||||
);
|
|
||||||
return new Pair<>(model, allStageStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateBuildCancelUser(String projectId, String buildId, String cancelUserId) {
|
|
||||||
buildDetailDao.updateBuildCancelUser(
|
|
||||||
projectId,
|
|
||||||
buildId,
|
|
||||||
cancelUserId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,153 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.UUIDUtil;
|
|
||||||
import cd.casic.ci.common.pipeline.constant.CommonMessageCode;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.PipelineStageTag;
|
|
||||||
import cd.casic.ci.process.process.dal.pipeline.PipelineStageTagDao;
|
|
||||||
import cd.casic.ci.process.process.dataObject.TPipelineStageTagRecord;
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* StageTag为后台插入,更新由平台OP控制,基本不会更新,只需要缓存在内存即可。即使出错也不影响正常逻辑,暂不引入redis
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
|
||||||
public class StageTagServiceImpl {
|
|
||||||
|
|
||||||
private static final String ALL = "ALL";
|
|
||||||
private static final String DEFAULT = "DEFAULT";
|
|
||||||
@Resource
|
|
||||||
private PipelineStageTagDao pipelineStageTagDao;
|
|
||||||
// TODO 不引入缓存
|
|
||||||
// StageTag为后台插入,更新由平台OP控制,不会经常更新,所以只需要缓存在内存即可。即使出错也不影响正常逻辑,暂不引入redis
|
|
||||||
// private LoadingCache<String, PipelineStageTag> defaultTagCache = Caffeine.newBuilder()
|
|
||||||
// .expireAfterWrite(Duration.ofMinutes(1))
|
|
||||||
// .maximumSize(1)
|
|
||||||
// .build(key -> pipelineStageTagDao.getDefaultStageTag());
|
|
||||||
|
|
||||||
// StageTag为后台插入,更新由平台OP控制,不会经常更新,所以只需要缓存在内存即可。即使出错也不影响正常逻辑,暂不引入redis
|
|
||||||
private final LoadingCache<String, List<PipelineStageTag>> allTagCache = Caffeine.newBuilder()
|
|
||||||
.expireAfterWrite(Duration.ofMinutes(1))
|
|
||||||
.maximumSize(1)
|
|
||||||
.build(key -> {
|
|
||||||
List<PipelineStageTag> pipelineStageTagList = new ArrayList<>();
|
|
||||||
List<TPipelineStageTagRecord> allStageTag = pipelineStageTagDao.getAllStageTag();
|
|
||||||
for (int i = 0; i < allStageTag.size(); i++) {
|
|
||||||
pipelineStageTagList.add(PipelineStageTagDao.convert(allStageTag.get(i), i == 0));
|
|
||||||
}
|
|
||||||
return pipelineStageTagList;
|
|
||||||
});
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public StageTagServiceImpl( PipelineStageTagDao pipelineStageTagDao) {
|
|
||||||
|
|
||||||
this.pipelineStageTagDao = pipelineStageTagDao;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有阶段标签信息
|
|
||||||
*/
|
|
||||||
public List<PipelineStageTag> getAllStageTag() {
|
|
||||||
return allTagCache.get(ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 获取默认标签
|
|
||||||
// */
|
|
||||||
// public PipelineStageTag getDefaultStageTag() {
|
|
||||||
// return defaultTagCache.get(DEFAULT);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据id获取阶段标签信息
|
|
||||||
*/
|
|
||||||
public PipelineStageTag getStageTag(String id) {
|
|
||||||
List<PipelineStageTag> all = allTagCache.getIfPresent(ALL);
|
|
||||||
PipelineStageTag data;
|
|
||||||
if (all == null || all.isEmpty()) {
|
|
||||||
TPipelineStageTagRecord pipelineStageTagRecord = pipelineStageTagDao.getStageTag(id);
|
|
||||||
log.info("the pipelineStageTagRecord is :{}", pipelineStageTagRecord);
|
|
||||||
data = pipelineStageTagRecord != null ?
|
|
||||||
PipelineStageTagDao.convert(pipelineStageTagRecord, false) : null;
|
|
||||||
} else {
|
|
||||||
data = all.stream()
|
|
||||||
.filter(tag -> tag.getId().equals(id))
|
|
||||||
.findFirst()
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存阶段标签信息
|
|
||||||
*/
|
|
||||||
public Boolean saveStageTag(String stageTag, int weight) {
|
|
||||||
log.info("the save stageTagName is:{}", stageTag);
|
|
||||||
// 判断阶段标签名称是否存在
|
|
||||||
int count = getCountByNameOrWeight(stageTag, weight);
|
|
||||||
if (count > 0) {
|
|
||||||
// 抛出错误提示
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
String id = UUIDUtil.generate();
|
|
||||||
pipelineStageTagDao.add(id, stageTag, weight);
|
|
||||||
// defaultTagCache.invalidateAll();
|
|
||||||
allTagCache.invalidateAll();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新阶段标签信息
|
|
||||||
*/
|
|
||||||
public Boolean updateStageTag(String id, String stageTagName, int weight) {
|
|
||||||
log.info("the update stageTagName is:{}", stageTagName);
|
|
||||||
// 判断阶段标签代码是否存在
|
|
||||||
if (getCountByNameOrWeight(stageTagName, weight) > 0) {
|
|
||||||
// 判断更新的阶段标签代码是否属于自已
|
|
||||||
TPipelineStageTagRecord pipelineStageTag = pipelineStageTagDao.getStageTag(id);
|
|
||||||
if (pipelineStageTag != null && !stageTagName.equals(pipelineStageTag.getStageTagName())) {
|
|
||||||
// 抛出错误提示
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pipelineStageTagDao.update(id, stageTagName, weight);
|
|
||||||
// defaultTagCache.invalidateAll();
|
|
||||||
// allTagCache.invalidateAll();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除阶段标签信息
|
|
||||||
*/
|
|
||||||
public Boolean deleteStageTag(String id) {
|
|
||||||
log.info("the delete id is :{}", id);
|
|
||||||
pipelineStageTagDao.delete( id);
|
|
||||||
// defaultTagCache.invalidateAll();
|
|
||||||
allTagCache.invalidateAll();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据阶段标签名称和权重查询重复数据库记录数
|
|
||||||
*/
|
|
||||||
private int getCountByNameOrWeight(String stageTagName, int weight) {
|
|
||||||
Integer count = pipelineStageTagDao.countByNameOrWeight(stageTagName, weight);
|
|
||||||
int result = 0;
|
|
||||||
if (count != null) {
|
|
||||||
result = count;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.dispatcher;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.event.pojo.IEvent;
|
|
||||||
|
|
||||||
public interface EventDispatcher <T extends IEvent>{
|
|
||||||
void dispatch(T events);
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.dispatcher;
|
|
||||||
|
|
||||||
import cd.casic.ci.event.pojo.pipeline.IPipelineEvent;
|
|
||||||
|
|
||||||
public interface PipelineEventDispatcher extends EventDispatcher<IPipelineEvent>{
|
|
||||||
}
|
|
@ -1,232 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.engin.service;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.Model;
|
|
||||||
import cd.casic.ci.common.pipeline.dialect.IPipelineDialect;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.BranchVersionAction;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.ChannelCode;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.VersionStatus;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.setting.PipelineSetting;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.transfer.YamlWithVersion;
|
|
||||||
import cd.casic.ci.process.api.engine.pojo.PipelineInfo;
|
|
||||||
import cd.casic.ci.process.api.engine.pojo.PipelineModelTask;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.PipelineCollation;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.PipelineName;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.PipelineSortType;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.pipeline.DeletePipelineResult;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.pipeline.DeployPipelineResult;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.pipeline.PipelineResourceVersion;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.pipeline.PipelineYamlVo;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.setting.PipelineModelVersion;
|
|
||||||
import org.apache.commons.lang3.tuple.Triple;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface PipelineRepositoryService {
|
|
||||||
|
|
||||||
DeployPipelineResult deployPipeline(
|
|
||||||
Model model,
|
|
||||||
String projectId,
|
|
||||||
String signPipelineId,
|
|
||||||
String userId,
|
|
||||||
ChannelCode channelCode,
|
|
||||||
boolean create,
|
|
||||||
YamlWithVersion yaml,
|
|
||||||
Integer baseVersion,
|
|
||||||
Boolean useSubscriptionSettings,
|
|
||||||
Boolean useConcurrencyGroup,
|
|
||||||
String templateId,
|
|
||||||
Boolean updateLastModifyUser,
|
|
||||||
PipelineSetting setting,
|
|
||||||
VersionStatus versionStatus,
|
|
||||||
String branchName,
|
|
||||||
String description,
|
|
||||||
PipelineYamlVo yamlInfo,
|
|
||||||
Boolean pipelineDisable
|
|
||||||
);
|
|
||||||
|
|
||||||
List<PipelineModelTask> initModel(
|
|
||||||
Model model,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
boolean create,
|
|
||||||
VersionStatus versionStatus,
|
|
||||||
ChannelCode channelCode,
|
|
||||||
PipelineYamlVo yamlInfo,
|
|
||||||
IPipelineDialect pipelineDialect
|
|
||||||
);
|
|
||||||
|
|
||||||
PipelineSetting createDefaultSetting(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String pipelineName,
|
|
||||||
ChannelCode channelCode
|
|
||||||
);
|
|
||||||
|
|
||||||
PipelineInfo getPipelineInfo(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
ChannelCode channelCode,
|
|
||||||
Boolean delete
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, Model> listModel(String projectId, Collection<String> pipelineIds);
|
|
||||||
|
|
||||||
Triple<PipelineInfo, PipelineResourceVersion, Boolean> getBuildTriggerInfo(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer version
|
|
||||||
);
|
|
||||||
|
|
||||||
PipelineResourceVersion getPipelineResourceVersion(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer version,
|
|
||||||
Boolean includeDraft
|
|
||||||
);
|
|
||||||
|
|
||||||
PipelineResourceVersion getDraftVersionResource(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId
|
|
||||||
);
|
|
||||||
|
|
||||||
PipelineResourceVersion getBranchVersionResource(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String branchName
|
|
||||||
);
|
|
||||||
|
|
||||||
int getActiveBranchVersionCount(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId
|
|
||||||
);
|
|
||||||
|
|
||||||
PipelineResourceVersion rollbackDraftFromVersion(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
PipelineResourceVersion targetVersion,
|
|
||||||
Boolean ignoreBase
|
|
||||||
);
|
|
||||||
|
|
||||||
DeletePipelineResult deletePipeline(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
ChannelCode channelCode,
|
|
||||||
boolean delete
|
|
||||||
);
|
|
||||||
|
|
||||||
boolean isPipelineExist(
|
|
||||||
String projectId,
|
|
||||||
String pipelineName,
|
|
||||||
ChannelCode channelCode,
|
|
||||||
String excludePipelineId
|
|
||||||
);
|
|
||||||
|
|
||||||
int countByProjectIds(Set<String> projectIds, ChannelCode channelCode);
|
|
||||||
|
|
||||||
Map<String, String> listPipelineNameByIds(
|
|
||||||
String projectId,
|
|
||||||
Set<String> pipelineIds,
|
|
||||||
boolean filterDelete
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, String> listPipelineIdByName(
|
|
||||||
String projectId,
|
|
||||||
Set<String> pipelineNames,
|
|
||||||
boolean filterDelete
|
|
||||||
);
|
|
||||||
|
|
||||||
Integer getBuildNo(String projectId, String pipelineId);
|
|
||||||
|
|
||||||
PipelineSetting getSetting(String projectId, String pipelineId);
|
|
||||||
|
|
||||||
PipelineSetting getSettingByPipelineVersion(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
Integer pipelineVersion
|
|
||||||
);
|
|
||||||
|
|
||||||
PipelineName saveSetting(
|
|
||||||
String userId,
|
|
||||||
PipelineSetting setting,
|
|
||||||
int version,
|
|
||||||
VersionStatus versionStatus,
|
|
||||||
Boolean updateLastModifyUser,
|
|
||||||
boolean isTemplate
|
|
||||||
);
|
|
||||||
|
|
||||||
void batchUpdatePipelineModel(
|
|
||||||
String userId,
|
|
||||||
List<PipelineModelVersion> pipelineModelVersionList
|
|
||||||
);
|
|
||||||
|
|
||||||
List<PipelineInfo> listDeletePipelineIdByProject(
|
|
||||||
String projectId,
|
|
||||||
Long days,
|
|
||||||
Integer offset,
|
|
||||||
Integer limit,
|
|
||||||
PipelineSortType sortType,
|
|
||||||
PipelineCollation collation,
|
|
||||||
String filterByPipelineName
|
|
||||||
);
|
|
||||||
|
|
||||||
PipelineResourceVersion restorePipeline(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
ChannelCode channelCode,
|
|
||||||
Long days
|
|
||||||
);
|
|
||||||
|
|
||||||
int countByPipelineIds(
|
|
||||||
String projectId,
|
|
||||||
ChannelCode channelCode,
|
|
||||||
List<String> pipelineIds
|
|
||||||
);
|
|
||||||
|
|
||||||
void updateModelName(
|
|
||||||
String pipelineId,
|
|
||||||
String projectId,
|
|
||||||
String modelName,
|
|
||||||
String userId
|
|
||||||
);
|
|
||||||
|
|
||||||
int updateMaxConRunningQueueSize(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
int maxConRunningQueueSize
|
|
||||||
);
|
|
||||||
|
|
||||||
DeployPipelineResult updateSettingVersion(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
PipelineSetting savedSetting,
|
|
||||||
Boolean updateLastModifyUser
|
|
||||||
);
|
|
||||||
|
|
||||||
void updatePipelineBranchVersion(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String branchName,
|
|
||||||
BranchVersionAction branchVersionAction
|
|
||||||
);
|
|
||||||
|
|
||||||
boolean updateLocked(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
boolean locked
|
|
||||||
);
|
|
||||||
|
|
||||||
String getPipelineOauthUser(String projectId, String pipelineId);
|
|
||||||
}
|
|
@ -1,142 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.engin.service;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.model.SQLPage;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.event.CallBackNetWorkRegionType;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.event.PipelineCallbackEvent;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.event.ProjectPipelineCallBack;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.secret.ISecretParam;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.CreateCallBackResult;
|
|
||||||
import cd.casic.ci.process.api.process.pojo.ProjectPipelineCallBackHistory;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface ProjectPipelineCallBackService {
|
|
||||||
|
|
||||||
CreateCallBackResult createCallBack(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
String url,
|
|
||||||
CallBackNetWorkRegionType region,
|
|
||||||
String event,
|
|
||||||
String secretToken,
|
|
||||||
ISecretParam secretParam,
|
|
||||||
boolean needCheckPermission
|
|
||||||
);
|
|
||||||
|
|
||||||
List<ProjectPipelineCallBack> listProjectCallBack(
|
|
||||||
String projectId,
|
|
||||||
String events
|
|
||||||
);
|
|
||||||
|
|
||||||
SQLPage<ProjectPipelineCallBack> listByPage(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
int offset,
|
|
||||||
int limit
|
|
||||||
);
|
|
||||||
|
|
||||||
void delete(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
long id,
|
|
||||||
boolean needCheckPermission
|
|
||||||
);
|
|
||||||
|
|
||||||
void disable(
|
|
||||||
String projectId,
|
|
||||||
long id
|
|
||||||
);
|
|
||||||
|
|
||||||
void batchDisable(
|
|
||||||
String projectId,
|
|
||||||
String callbackIds
|
|
||||||
);
|
|
||||||
|
|
||||||
void sendDisableNotifyMessage(
|
|
||||||
String projectId,
|
|
||||||
long id
|
|
||||||
);
|
|
||||||
|
|
||||||
void enable(
|
|
||||||
ProjectPipelineCallBack callBack
|
|
||||||
);
|
|
||||||
|
|
||||||
void enableByIds(
|
|
||||||
String projectId,
|
|
||||||
String callbackIds
|
|
||||||
);
|
|
||||||
|
|
||||||
void updateFailureTime(
|
|
||||||
String projectId,
|
|
||||||
long id,
|
|
||||||
LocalDateTime failureTime
|
|
||||||
);
|
|
||||||
|
|
||||||
List<ProjectPipelineCallBack> getDisableCallbackList(
|
|
||||||
int offset,
|
|
||||||
int limit,
|
|
||||||
String projectId,
|
|
||||||
String url
|
|
||||||
);
|
|
||||||
|
|
||||||
void createHistory(
|
|
||||||
ProjectPipelineCallBackHistory projectPipelineCallBackHistory
|
|
||||||
);
|
|
||||||
|
|
||||||
ProjectPipelineCallBackHistory getHistory(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
long id
|
|
||||||
);
|
|
||||||
|
|
||||||
SQLPage<ProjectPipelineCallBackHistory> listHistory(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
String callBackUrl,
|
|
||||||
String events,
|
|
||||||
Long startTime,
|
|
||||||
Long endTime,
|
|
||||||
int offset,
|
|
||||||
int limit
|
|
||||||
);
|
|
||||||
|
|
||||||
void retry(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
long id
|
|
||||||
);
|
|
||||||
|
|
||||||
void bindPipelineCallBack(
|
|
||||||
String userId,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
PipelineCallbackEvent callbackInfo
|
|
||||||
);
|
|
||||||
|
|
||||||
List<ProjectPipelineCallBack> getPipelineCallback(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String event
|
|
||||||
);
|
|
||||||
|
|
||||||
void checkParam(
|
|
||||||
String userId,
|
|
||||||
String projectId
|
|
||||||
);
|
|
||||||
|
|
||||||
void validAuth(
|
|
||||||
String userId,
|
|
||||||
String projectId
|
|
||||||
);
|
|
||||||
|
|
||||||
void validProjectManager(
|
|
||||||
String userId,
|
|
||||||
String projectId
|
|
||||||
);
|
|
||||||
|
|
||||||
String projectPipelineListUrl(String projectId);
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.engin.service;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.event.CallBackNetWorkRegionType;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface ProjectPipelineCallBackUrlGenerator {
|
|
||||||
|
|
||||||
String generateCallBackUrl(
|
|
||||||
@Nullable CallBackNetWorkRegionType region,
|
|
||||||
String url
|
|
||||||
);
|
|
||||||
|
|
||||||
String encodeCallbackUrl(String url);
|
|
||||||
|
|
||||||
String decodeCallbackUrl(String url);
|
|
||||||
}
|
|
@ -1,141 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.engin.util;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.container.Container;
|
|
||||||
import cd.casic.ci.common.pipeline.container.NormalContainer;
|
|
||||||
import cd.casic.ci.common.pipeline.container.VMBuildContainer;
|
|
||||||
import cd.casic.ci.common.pipeline.enums.BuildStatus;
|
|
||||||
import cd.casic.ci.process.api.process.constant.ProcessMessageCode;
|
|
||||||
|
|
||||||
public class ContainerUtils {
|
|
||||||
|
|
||||||
private ContainerUtils() {
|
|
||||||
// 私有构造函数,防止实例化
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取容器启动键
|
|
||||||
* @param pipelineId 流水线ID
|
|
||||||
* @param buildId 构建ID
|
|
||||||
* @param containerId 容器ID
|
|
||||||
* @return 容器启动键
|
|
||||||
*/
|
|
||||||
public static String getContainerStartupKey(String pipelineId, String buildId, String containerId) {
|
|
||||||
return String.format("container:startup:%s:%s:%s", pipelineId, buildId, containerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取容器运行事件取消任务键
|
|
||||||
* @param pipelineId 流水线ID
|
|
||||||
* @param buildId 构建ID
|
|
||||||
* @param containerId 容器ID
|
|
||||||
* @return 容器运行事件取消任务键
|
|
||||||
*/
|
|
||||||
public static String getContainerRunEvenCancelTaskKey(String pipelineId, String buildId, String containerId) {
|
|
||||||
return String.format("container:taskEvenCancel:%s:%s:%s", pipelineId, buildId, containerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断普通容器是否启用
|
|
||||||
* @param normalContainer 普通容器
|
|
||||||
* @return 是否启用
|
|
||||||
*/
|
|
||||||
public static boolean isNormalContainerEnable(NormalContainer normalContainer) {
|
|
||||||
if (normalContainer.getJobControlOption() != null) {
|
|
||||||
return normalContainer.getJobControlOption().getEnable();
|
|
||||||
}
|
|
||||||
return !normalContainer.getEnableSkip();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断VM构建容器是否启用
|
|
||||||
* @param container VM构建容器
|
|
||||||
* @return 是否启用
|
|
||||||
*/
|
|
||||||
public static boolean isVMBuildContainerEnable(VMBuildContainer container) {
|
|
||||||
return container.getJobControlOption() == null || container.getJobControlOption().getEnable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getMutexPrefix() {
|
|
||||||
return ProcessMessageCode.BK_MUTEX_WAITING;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取互斥固定容器名称
|
|
||||||
* @param containerName 容器名称
|
|
||||||
* @return 处理后的容器名称
|
|
||||||
*/
|
|
||||||
public static String getMutexFixedContainerName(String containerName) {
|
|
||||||
String prefix = getMutexPrefix();
|
|
||||||
if (containerName.startsWith(prefix)) {
|
|
||||||
return containerName.substring(prefix.length());
|
|
||||||
}
|
|
||||||
return containerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取互斥等待名称
|
|
||||||
* @param containerName 容器名称
|
|
||||||
* @return 处理后的容器名称
|
|
||||||
*/
|
|
||||||
public static String getMutexWaitName(String containerName) {
|
|
||||||
String prefix = getMutexPrefix();
|
|
||||||
if (containerName.startsWith(prefix)) {
|
|
||||||
return containerName;
|
|
||||||
}
|
|
||||||
return prefix + containerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getQueuePrefix() {
|
|
||||||
return ProcessMessageCode.BK_QUEUING;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getReviewPrefix() {
|
|
||||||
return ProcessMessageCode.BK_PENDING;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取清除队列容器名称
|
|
||||||
* @param containerName 容器名称
|
|
||||||
* @return 处理后的容器名称
|
|
||||||
*/
|
|
||||||
public static String getClearedQueueContainerName(String containerName) {
|
|
||||||
String queuePrefix = getQueuePrefix();
|
|
||||||
String reviewPrefix = getReviewPrefix();
|
|
||||||
|
|
||||||
if (containerName.startsWith(queuePrefix)) {
|
|
||||||
return containerName.substring(queuePrefix.length());
|
|
||||||
} else if (containerName.startsWith(reviewPrefix)) {
|
|
||||||
return containerName.substring(reviewPrefix.length());
|
|
||||||
}
|
|
||||||
return containerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取排队等待名称
|
|
||||||
* @param containerName 容器名称
|
|
||||||
* @param startBuildStatus 开始构建状态
|
|
||||||
* @return 处理后的容器名称
|
|
||||||
*/
|
|
||||||
public static String getQueuingWaitName(String containerName, BuildStatus startBuildStatus) {
|
|
||||||
String queuePrefix = getQueuePrefix();
|
|
||||||
String reviewPrefix = getReviewPrefix();
|
|
||||||
|
|
||||||
if (containerName.startsWith(queuePrefix) || containerName.startsWith(reviewPrefix)) {
|
|
||||||
return containerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startBuildStatus == BuildStatus.TRIGGER_REVIEWING) {
|
|
||||||
return reviewPrefix + containerName;
|
|
||||||
}
|
|
||||||
return queuePrefix + containerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否为原始矩阵容器
|
|
||||||
* @param container 容器
|
|
||||||
* @return 是否为原始矩阵容器
|
|
||||||
*/
|
|
||||||
public static boolean isOriginMatrixContainer(Container container) {
|
|
||||||
return container.fetchGroupContainers() != null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class BuildEvent {
|
|
||||||
private final String buildId;
|
|
||||||
private final String pipelineId;
|
|
||||||
private final String pipelineName;
|
|
||||||
private final String userId;
|
|
||||||
private final String triggerUser;
|
|
||||||
private final String cancelUserId;
|
|
||||||
private final String status;
|
|
||||||
private final long startTime;
|
|
||||||
private final long endTime;
|
|
||||||
private final SimpleModel model;
|
|
||||||
private final String projectId;
|
|
||||||
private final String trigger;
|
|
||||||
private final String stageId;
|
|
||||||
private final String taskId;
|
|
||||||
private final int buildNo;
|
|
||||||
private final Boolean debug;
|
|
||||||
|
|
||||||
// 构造函数,使用了默认值的设置
|
|
||||||
public BuildEvent(String buildId, String pipelineId, String pipelineName, String userId, String triggerUser, String cancelUserId, String status, long startTime, long endTime, SimpleModel model, String projectId, String trigger, String stageId, String taskId, int buildNo, Boolean debug) {
|
|
||||||
this.buildId = buildId;
|
|
||||||
this.pipelineId = pipelineId;
|
|
||||||
this.pipelineName = pipelineName;
|
|
||||||
this.userId = userId;
|
|
||||||
this.triggerUser = triggerUser;
|
|
||||||
this.cancelUserId = cancelUserId;
|
|
||||||
this.status = status;
|
|
||||||
this.startTime = startTime;
|
|
||||||
this.endTime = endTime;
|
|
||||||
this.model = model;
|
|
||||||
this.projectId = projectId;
|
|
||||||
this.trigger = trigger;
|
|
||||||
this.stageId = stageId;
|
|
||||||
this.taskId = taskId;
|
|
||||||
this.buildNo = buildNo;
|
|
||||||
this.debug = debug;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.enums.CallBackEvent;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class CallBackData<T> {
|
|
||||||
private final CallBackEvent event;
|
|
||||||
private final T data;
|
|
||||||
|
|
||||||
// 构造函数
|
|
||||||
public CallBackData(CallBackEvent event, T data) {
|
|
||||||
this.event = event;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.enums.CallBackEvent;
|
|
||||||
import cd.casic.ci.event.enums.ActionType;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 事件工具类
|
|
||||||
*/
|
|
||||||
public class EventUtils {
|
|
||||||
|
|
||||||
private static final Map<String, CallBackEvent> callBackEventMap = Stream.of(CallBackEvent.values())
|
|
||||||
.collect(Collectors.toMap(Enum::name, event -> event));
|
|
||||||
|
|
||||||
private EventUtils() {
|
|
||||||
// 私有构造函数,防止实例化
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将PipelineBuildStatusBroadCastEvent转换为CallBackEvent
|
|
||||||
* @param event 构建状态广播事件
|
|
||||||
* @return 回调事件类型
|
|
||||||
*/
|
|
||||||
public static CallBackEvent toEventType(PipelineBuildStatusBroadCastEvent event) {
|
|
||||||
if (event.getType() != null && callBackEventMap.containsKey(event.getType().name())) {
|
|
||||||
return callBackEventMap.get(event.getType().name());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getTaskId() != null && !event.getTaskId().isBlank()) {
|
|
||||||
if (event.getActionType() == ActionType.START) {
|
|
||||||
return CallBackEvent.BUILD_TASK_START;
|
|
||||||
}
|
|
||||||
if (event.getActionType() == ActionType.REFRESH) {
|
|
||||||
return CallBackEvent.BUILD_TASK_PAUSE;
|
|
||||||
}
|
|
||||||
if (event.getActionType() == ActionType.END) {
|
|
||||||
return CallBackEvent.BUILD_TASK_END;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getContainerHashId() != null && !event.getContainerHashId().isBlank()) {
|
|
||||||
if (event.getActionType() == ActionType.START) {
|
|
||||||
return CallBackEvent.BUILD_JOB_START;
|
|
||||||
}
|
|
||||||
if (event.getActionType() == ActionType.END) {
|
|
||||||
return CallBackEvent.BUILD_JOB_END;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getStageId() != null && !event.getStageId().isBlank()) {
|
|
||||||
if (event.getActionType() == ActionType.START) {
|
|
||||||
return CallBackEvent.BUILD_STAGE_START;
|
|
||||||
}
|
|
||||||
if (event.getActionType() == ActionType.END) {
|
|
||||||
return CallBackEvent.BUILD_STAGE_END;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((event.getTaskId() == null || event.getTaskId().isBlank()) &&
|
|
||||||
(event.getContainerHashId() == null || event.getContainerHashId().isBlank()) &&
|
|
||||||
(event.getStageId() == null || event.getStageId().isBlank())) {
|
|
||||||
if (event.getActionType() == ActionType.START) {
|
|
||||||
return CallBackEvent.BUILD_START;
|
|
||||||
}
|
|
||||||
if (event.getActionType() == ActionType.END) {
|
|
||||||
return CallBackEvent.BUILD_END;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,213 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.event.enums.ActionType;
|
|
||||||
import cd.casic.ci.event.enums.PipelineBuildStatusBroadCastEventType;
|
|
||||||
|
|
||||||
import cd.casic.ci.event.pojo.pipeline.IPipelineEvent;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建状态的广播事件,用于通知等
|
|
||||||
*/
|
|
||||||
//@Event(destination = StreamBinding.PIPELINE_BUILD_CALL_BACK_FANOUT)
|
|
||||||
public class PipelineBuildStatusBroadCastEvent extends IPipelineEvent {
|
|
||||||
private final String buildId;
|
|
||||||
@Nullable
|
|
||||||
private final String stageId;
|
|
||||||
@Nullable
|
|
||||||
private final String containerHashId;
|
|
||||||
@Nullable
|
|
||||||
private final String jobId;
|
|
||||||
@Nullable
|
|
||||||
private final String taskId;
|
|
||||||
@Nullable
|
|
||||||
private final String stepId;
|
|
||||||
@Nullable
|
|
||||||
private final Integer executeCount;
|
|
||||||
@Nullable
|
|
||||||
private final String buildStatus;
|
|
||||||
@Nullable
|
|
||||||
private final String atomCode;
|
|
||||||
@Nullable
|
|
||||||
private final LocalDateTime eventTime;
|
|
||||||
@Nullable
|
|
||||||
private final PipelineBuildStatusBroadCastEventType type;
|
|
||||||
@Nullable
|
|
||||||
private final Map<String, String> labels;
|
|
||||||
|
|
||||||
public PipelineBuildStatusBroadCastEvent(
|
|
||||||
String source,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
String buildId,
|
|
||||||
@Nullable String stageId,
|
|
||||||
@Nullable String containerHashId,
|
|
||||||
@Nullable String jobId,
|
|
||||||
@Nullable String taskId,
|
|
||||||
@Nullable String stepId,
|
|
||||||
@Nullable Integer executeCount,
|
|
||||||
@Nullable String buildStatus,
|
|
||||||
@Nullable String atomCode,
|
|
||||||
@Nullable LocalDateTime eventTime,
|
|
||||||
@Nullable PipelineBuildStatusBroadCastEventType type,
|
|
||||||
@Nullable Map<String, String> labels,
|
|
||||||
ActionType actionType,
|
|
||||||
int delayMills
|
|
||||||
) {
|
|
||||||
super(actionType, source, projectId, pipelineId, userId, delayMills);
|
|
||||||
this.buildId = buildId;
|
|
||||||
this.stageId = stageId;
|
|
||||||
this.containerHashId = containerHashId;
|
|
||||||
this.jobId = jobId;
|
|
||||||
this.taskId = taskId;
|
|
||||||
this.stepId = stepId;
|
|
||||||
this.executeCount = executeCount;
|
|
||||||
this.buildStatus = buildStatus;
|
|
||||||
this.atomCode = atomCode;
|
|
||||||
this.eventTime = eventTime;
|
|
||||||
this.type = type;
|
|
||||||
this.labels = labels;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PipelineBuildStatusBroadCastEvent(
|
|
||||||
String source,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
String buildId,
|
|
||||||
@Nullable Integer executeCount,
|
|
||||||
@Nullable String buildStatus,
|
|
||||||
ActionType actionType
|
|
||||||
) {
|
|
||||||
this(
|
|
||||||
source,
|
|
||||||
projectId,
|
|
||||||
pipelineId,
|
|
||||||
userId,
|
|
||||||
buildId,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
executeCount,
|
|
||||||
buildStatus,
|
|
||||||
null,
|
|
||||||
LocalDateTime.now(),
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
actionType,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBuildId() {
|
|
||||||
return buildId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getStageId() {
|
|
||||||
return stageId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getContainerHashId() {
|
|
||||||
return containerHashId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getJobId() {
|
|
||||||
return jobId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getTaskId() {
|
|
||||||
return taskId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getStepId() {
|
|
||||||
return stepId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Integer getExecuteCount() {
|
|
||||||
return executeCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getBuildStatus() {
|
|
||||||
return buildStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getAtomCode() {
|
|
||||||
return atomCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public LocalDateTime getEventTime() {
|
|
||||||
return eventTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public PipelineBuildStatusBroadCastEventType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Map<String, String> getLabels() {
|
|
||||||
return labels;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
if (!super.equals(o)) return false;
|
|
||||||
PipelineBuildStatusBroadCastEvent that = (PipelineBuildStatusBroadCastEvent) o;
|
|
||||||
return Objects.equals(buildId, that.buildId) &&
|
|
||||||
Objects.equals(stageId, that.stageId) &&
|
|
||||||
Objects.equals(containerHashId, that.containerHashId) &&
|
|
||||||
Objects.equals(jobId, that.jobId) &&
|
|
||||||
Objects.equals(taskId, that.taskId) &&
|
|
||||||
Objects.equals(stepId, that.stepId) &&
|
|
||||||
Objects.equals(executeCount, that.executeCount) &&
|
|
||||||
Objects.equals(buildStatus, that.buildStatus) &&
|
|
||||||
Objects.equals(atomCode, that.atomCode) &&
|
|
||||||
Objects.equals(eventTime, that.eventTime) &&
|
|
||||||
type == that.type &&
|
|
||||||
Objects.equals(labels, that.labels);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(super.hashCode(), buildId, stageId, containerHashId, jobId, taskId, stepId,
|
|
||||||
executeCount, buildStatus, atomCode, eventTime, type, labels);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "PipelineBuildStatusBroadCastEvent{" +
|
|
||||||
"buildId='" + buildId + '\'' +
|
|
||||||
", stageId='" + stageId + '\'' +
|
|
||||||
", containerHashId='" + containerHashId + '\'' +
|
|
||||||
", jobId='" + jobId + '\'' +
|
|
||||||
", taskId='" + taskId + '\'' +
|
|
||||||
", stepId='" + stepId + '\'' +
|
|
||||||
", executeCount=" + executeCount +
|
|
||||||
", buildStatus='" + buildStatus + '\'' +
|
|
||||||
", atomCode='" + atomCode + '\'' +
|
|
||||||
", eventTime=" + eventTime +
|
|
||||||
", type=" + type +
|
|
||||||
", labels=" + labels +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.event.enums.ActionType;
|
|
||||||
import cd.casic.ci.event.pojo.pipeline.IPipelineEvent;
|
|
||||||
|
|
||||||
//@Event(StreamBinding.PIPELINE_BUILD_WEBSOCKET)
|
|
||||||
public class PipelineBuildWebSocketPushEvent extends IPipelineEvent {
|
|
||||||
|
|
||||||
private final String buildId;
|
|
||||||
private final long refreshTypes; // HISTORY or DETAIL or STATUS 位运算
|
|
||||||
private final Integer executeCount;
|
|
||||||
|
|
||||||
public PipelineBuildWebSocketPushEvent(
|
|
||||||
String source,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
String buildId,
|
|
||||||
long refreshTypes,
|
|
||||||
Integer executeCount,
|
|
||||||
ActionType actionType,
|
|
||||||
int delayMills
|
|
||||||
) {
|
|
||||||
super(actionType, source, projectId, pipelineId, userId, delayMills);
|
|
||||||
this.buildId = buildId;
|
|
||||||
this.refreshTypes = refreshTypes;
|
|
||||||
this.executeCount = executeCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PipelineBuildWebSocketPushEvent(
|
|
||||||
String source,
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String userId,
|
|
||||||
String buildId,
|
|
||||||
long refreshTypes
|
|
||||||
) {
|
|
||||||
this(source, projectId, pipelineId, userId, buildId, refreshTypes, null, ActionType.REFRESH, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PipelineBuildWebSocketPushEvent( String source, String projectId, String pipelineId, String userId, String buildId, long refreshTypes, Integer executeCount) {
|
|
||||||
super(ActionType.REFRESH, source, projectId, pipelineId, userId,0);
|
|
||||||
this.buildId = buildId;
|
|
||||||
this.refreshTypes = refreshTypes;
|
|
||||||
this.executeCount = executeCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBuildId() {
|
|
||||||
return buildId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getRefreshTypes() {
|
|
||||||
return refreshTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getExecuteCount() {
|
|
||||||
return executeCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
if (!super.equals(o)) return false;
|
|
||||||
|
|
||||||
PipelineBuildWebSocketPushEvent that = (PipelineBuildWebSocketPushEvent) o;
|
|
||||||
|
|
||||||
if (refreshTypes != that.refreshTypes) return false;
|
|
||||||
if (!buildId.equals(that.buildId)) return false;
|
|
||||||
return executeCount != null ? executeCount.equals(that.executeCount) : that.executeCount == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = super.hashCode();
|
|
||||||
result = 31 * result + buildId.hashCode();
|
|
||||||
result = 31 * result + (int) (refreshTypes ^ (refreshTypes >>> 32));
|
|
||||||
result = 31 * result + (executeCount != null ? executeCount.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "PipelineBuildWebSocketPushEvent{" +
|
|
||||||
"source='" + getSource() + '\'' +
|
|
||||||
", projectId='" + getProjectId() + '\'' +
|
|
||||||
", pipelineId='" + getPipelineId() + '\'' +
|
|
||||||
", userId='" + getUserId() + '\'' +
|
|
||||||
", buildId='" + buildId + '\'' +
|
|
||||||
", refreshTypes=" + refreshTypes +
|
|
||||||
", executeCount=" + executeCount +
|
|
||||||
", actionType=" + getActionType() +
|
|
||||||
", delayMills=" + getDelayMills() +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class PipelineEvent {
|
|
||||||
private final String pipelineId;
|
|
||||||
private final String pipelineName;
|
|
||||||
private final String userId;
|
|
||||||
private final long updateTime;
|
|
||||||
private final String projectId;
|
|
||||||
|
|
||||||
public PipelineEvent(
|
|
||||||
String pipelineId,
|
|
||||||
String pipelineName,
|
|
||||||
String userId,
|
|
||||||
long updateTime,
|
|
||||||
String projectId
|
|
||||||
) {
|
|
||||||
this.pipelineId = pipelineId;
|
|
||||||
this.pipelineName = pipelineName;
|
|
||||||
this.userId = userId;
|
|
||||||
this.updateTime = updateTime;
|
|
||||||
this.projectId = projectId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPipelineId() {
|
|
||||||
return pipelineId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPipelineName() {
|
|
||||||
return pipelineName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserId() {
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getUpdateTime() {
|
|
||||||
return updateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getProjectId() {
|
|
||||||
return projectId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
PipelineEvent that = (PipelineEvent) o;
|
|
||||||
return updateTime == that.updateTime &&
|
|
||||||
Objects.equals(pipelineId, that.pipelineId) &&
|
|
||||||
Objects.equals(pipelineName, that.pipelineName) &&
|
|
||||||
Objects.equals(userId, that.userId) &&
|
|
||||||
Objects.equals(projectId, that.projectId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(pipelineId, pipelineName, userId, updateTime, projectId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "PipelineEvent{" +
|
|
||||||
"pipelineId='" + pipelineId + '\'' +
|
|
||||||
", pipelineName='" + pipelineName + '\'' +
|
|
||||||
", userId='" + userId + '\'' +
|
|
||||||
", updateTime=" + updateTime +
|
|
||||||
", projectId='" + projectId + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class ProjectCallbackEvent {
|
|
||||||
private final String projectId;
|
|
||||||
private final String projectName;
|
|
||||||
private final boolean enable;
|
|
||||||
private final String userId;
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class SimpleJob {
|
|
||||||
private final String jobName;
|
|
||||||
private final String status;
|
|
||||||
private final long startTime;
|
|
||||||
private final long endTime;
|
|
||||||
private final List<SimpleTask> tasks;
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class SimpleModel {
|
|
||||||
private final List<SimpleStage> stages;
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class SimpleStage {
|
|
||||||
private final String stageName;
|
|
||||||
private final String name;
|
|
||||||
private String status;
|
|
||||||
private long startTime;
|
|
||||||
private long endTime;
|
|
||||||
private final List<SimpleJob> jobs;
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class SimpleTask {
|
|
||||||
private final String taskId;
|
|
||||||
private final String taskName;
|
|
||||||
private final String atomCode;
|
|
||||||
private final String status;
|
|
||||||
private final long startTime;
|
|
||||||
private final long endTime;
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class StreamEnabledEvent {
|
|
||||||
private final String userId;
|
|
||||||
private final long gitProjectId;
|
|
||||||
private final String gitProjectUrl;
|
|
||||||
private final boolean enable;
|
|
||||||
}
|
|
@ -1,94 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import cd.casic.ci.common.pipeline.container.Container;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.ElementAdditionalOptions;
|
|
||||||
import cd.casic.ci.common.pipeline.pojo.element.ElementPostInfo;
|
|
||||||
import cd.casic.ci.process.api.engine.pojo.PipelineBuildTask;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成运行环境操作的插件任务
|
|
||||||
*/
|
|
||||||
@Repository
|
|
||||||
public interface VmOperateTaskGenerator {
|
|
||||||
|
|
||||||
String START_VM_TASK_ATOM = "dispatchVMStartupTaskAtom";
|
|
||||||
String SHUTDOWN_VM_TASK_ATOM = "dispatchVMShutdownTaskAtom";
|
|
||||||
String START_NORMAL_TASK_ATOM = "dispatchBuildLessDockerStartupTaskAtom";
|
|
||||||
String SHUTDOWN_NORMAL_TASK_ATOM = "dispatchBuildLessDockerShutdownTaskAtom";
|
|
||||||
|
|
||||||
static boolean isVmAtom(PipelineBuildTask task) {
|
|
||||||
return isStartVM(task) || isStopVM(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isVmAtom(String atomCode) {
|
|
||||||
return isStartVM(atomCode) || isStopVM(atomCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isStartVM(PipelineBuildTask task) {
|
|
||||||
return START_VM_TASK_ATOM.equals(task.getTaskAtom()) ||
|
|
||||||
START_NORMAL_TASK_ATOM.equals(task.getTaskAtom());
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isStopVM(PipelineBuildTask task) {
|
|
||||||
return SHUTDOWN_VM_TASK_ATOM.equals(task.getTaskAtom()) ||
|
|
||||||
SHUTDOWN_NORMAL_TASK_ATOM.equals(task.getTaskAtom());
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isStartVM(String atomCode) {
|
|
||||||
return atomCode.startsWith(START_VM_TASK_ATOM) ||
|
|
||||||
atomCode.startsWith(START_NORMAL_TASK_ATOM);
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean isStopVM(String atomCode) {
|
|
||||||
return atomCode.startsWith(SHUTDOWN_VM_TASK_ATOM) ||
|
|
||||||
atomCode.startsWith(SHUTDOWN_NORMAL_TASK_ATOM);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成编译环境的开机插件任务
|
|
||||||
*/
|
|
||||||
PipelineBuildTask makeStartVMContainerTask(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String buildId,
|
|
||||||
String stageId,
|
|
||||||
Container container,
|
|
||||||
int taskSeq,
|
|
||||||
String userId,
|
|
||||||
int executeCount
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成准备停机插件任务列表
|
|
||||||
*/
|
|
||||||
List<PipelineBuildTask> makeShutdownVMContainerTasks(
|
|
||||||
String projectId,
|
|
||||||
String pipelineId,
|
|
||||||
String buildId,
|
|
||||||
String stageId,
|
|
||||||
Container container,
|
|
||||||
int containerSeq,
|
|
||||||
int taskSeq,
|
|
||||||
String userId,
|
|
||||||
int executeCount
|
|
||||||
);
|
|
||||||
|
|
||||||
default ElementAdditionalOptions opts(Container container, String taskName, int taskSeq) {
|
|
||||||
return new ElementAdditionalOptions(
|
|
||||||
true, // continueWhenFailed
|
|
||||||
1L, // timeout: 1分钟超时
|
|
||||||
ElementAdditionalOptions.RunCondition.PARENT_TASK_FINISH,
|
|
||||||
new ElementPostInfo(
|
|
||||||
container.getId(),
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
taskName,
|
|
||||||
taskSeq
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo.constant;
|
|
||||||
|
|
||||||
public class CallbackConstants {
|
|
||||||
// 项目级回调标志位
|
|
||||||
public static final String DEVOPS_ALL_PROJECT = "DEVOPS_ALL_PROJECT";
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package cd.casic.ci.process.process.service.base.pojo.enums;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 2进制表示刷新控制位
|
|
||||||
*/
|
|
||||||
public enum RefreshType {
|
|
||||||
HISTORY(2),
|
|
||||||
DETAIL(4),
|
|
||||||
STATUS(8),
|
|
||||||
RECORD(16);
|
|
||||||
|
|
||||||
private final long binary;
|
|
||||||
|
|
||||||
RefreshType(long binary) {
|
|
||||||
this.binary = binary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getBinary() {
|
|
||||||
return binary;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user