From 2e51102734f22a5bb8f94922d05906e6830578c8 Mon Sep 17 00:00:00 2001 From: even <827656971@qq.com> Date: Sat, 10 May 2025 17:16:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E5=88=86=E6=8E=A5=E5=8F=A3mock?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8C=E4=BB=A5=E5=8F=8A=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E4=B8=8E=E8=BF=94=E5=9B=9E=E5=80=BC=E5=AF=B9=E8=B1=A1=EF=BC=8C?= =?UTF-8?q?pom=E6=96=87=E4=BB=B6=E6=B7=BB=E5=8A=A0pipelineCommon=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OpsWebSecurityConfigurerAdapter.java | 1 + .../pipeline/req/agent/AgentQueryReq.java | 22 ++ .../common/pipeline/req/stage/StageReq.java | 54 +++ .../pipeline/req/trigger/TriggerQueryReq.java | 17 + .../pipeline/req/variable/VariableReq.java | 37 ++ .../common/pipeline/resp/agent/AgentResp.java | 22 ++ .../common/pipeline/resp/task/TasksResp.java | 39 ++ .../pipeline/resp/variable/VariableResp.java | 37 ++ ops-server/pom.xml | 4 + .../server/controller/AgentController.java | 45 +++ .../server/controller/StageController.java | 355 ++++++++++++++++++ .../server/controller/TasksController.java | 69 ++++ .../server/controller/TriggerController.java | 53 +++ .../server/controller/VariableController.java | 97 +++++ 14 files changed, 852 insertions(+) create mode 100644 modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/agent/AgentQueryReq.java create mode 100644 modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/stage/StageReq.java create mode 100644 modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/trigger/TriggerQueryReq.java create mode 100644 modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/variable/VariableReq.java create mode 100644 modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/agent/AgentResp.java create mode 100644 modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/task/TasksResp.java create mode 100644 modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/variable/VariableResp.java create mode 100644 ops-server/src/main/java/cd/casic/server/controller/AgentController.java create mode 100644 ops-server/src/main/java/cd/casic/server/controller/StageController.java create mode 100644 ops-server/src/main/java/cd/casic/server/controller/TasksController.java create mode 100644 ops-server/src/main/java/cd/casic/server/controller/TriggerController.java create mode 100644 ops-server/src/main/java/cd/casic/server/controller/VariableController.java diff --git a/framework/spring-boot-starter-biz-data-permission/src/main/java/cd/casic/framework/datapermission/config/OpsWebSecurityConfigurerAdapter.java b/framework/spring-boot-starter-biz-data-permission/src/main/java/cd/casic/framework/datapermission/config/OpsWebSecurityConfigurerAdapter.java index 291462cd..a6c21cde 100644 --- a/framework/spring-boot-starter-biz-data-permission/src/main/java/cd/casic/framework/datapermission/config/OpsWebSecurityConfigurerAdapter.java +++ b/framework/spring-boot-starter-biz-data-permission/src/main/java/cd/casic/framework/datapermission/config/OpsWebSecurityConfigurerAdapter.java @@ -148,6 +148,7 @@ public class OpsWebSecurityConfigurerAdapter { // 添加 Token Filter httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); + return httpSecurity.build(); } diff --git a/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/agent/AgentQueryReq.java b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/agent/AgentQueryReq.java new file mode 100644 index 00000000..44036a1d --- /dev/null +++ b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/agent/AgentQueryReq.java @@ -0,0 +1,22 @@ +package cd.casic.ci.common.pipeline.req.agent; + +import cd.casic.framework.commons.pojo.PageParam; +import lombok.Data; + +import java.util.List; +@Data +public class AgentQueryReq { + private String name; + + private String ip; + + private String tenantId; + + private String address; + + private String businessType; + + private PageParam pageParam= new PageParam(); + +// private List orderParams = OrderBuilders.instance().desc("createTime").get(); +} diff --git a/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/stage/StageReq.java b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/stage/StageReq.java new file mode 100644 index 00000000..9784e8ce --- /dev/null +++ b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/stage/StageReq.java @@ -0,0 +1,54 @@ +package cd.casic.ci.common.pipeline.req.stage; + +import cd.casic.ci.common.pipeline.resp.task.TasksResp; +import lombok.Data; + +import java.util.List; + +@Data +public class StageReq { + //@ApiProperty(name = "stageId",desc="id") + private String stageId; + + //@ApiProperty(name = "stageName",desc="名称") + private String stageName; + + //@ApiProperty(name = "createTime",desc="创建时间") + private String createTime; + + //@ApiProperty(name="pipelineId",desc="流水线id") + private String pipelineId; + + //@ApiProperty(name="stageSort",desc="阶段顺序") + private int stageSort; + + //@ApiProperty(name = "parentId",desc="主阶段") + private String parentId; + + //@ApiProperty(name = "code",desc="是否是源码") + private boolean code = false; + + //@ApiProperty(name = "taskValues",desc="阶段任务") + private List taskValues; + + //@ApiProperty(name = "stageList",desc="阶段") + private List stageList; + + //@ApiProperty(name = "taskType",desc="任务类型") + private String taskType; + + //@ApiProperty(name = "taskId",desc="任务id") + private String taskId; + + //@ApiProperty(name = "values",desc="更新内容") + private Object values; + + //@ApiProperty(name = "taskSort",desc="任务顺序") + private int taskSort; + + //@ApiProperty(name = "parallelName",desc="并行阶段名称") + private String parallelName; + + // 执行实例id + private String instanceId; +} diff --git a/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/trigger/TriggerQueryReq.java b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/trigger/TriggerQueryReq.java new file mode 100644 index 00000000..b3af137c --- /dev/null +++ b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/trigger/TriggerQueryReq.java @@ -0,0 +1,17 @@ +package cd.casic.ci.common.pipeline.req.trigger; + +import lombok.Data; + +@Data +public class TriggerQueryReq { + //@ApiProperty(name = "name",desc="名称") + private String name; + + //@ApiProperty(name = "taskType",desc="类型 81:定时任务") + private int taskType; + + private String pipelineId; + + // 状态 1--未执行 2--已执行 + private String state; +} diff --git a/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/variable/VariableReq.java b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/variable/VariableReq.java new file mode 100644 index 00000000..c966367b --- /dev/null +++ b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/req/variable/VariableReq.java @@ -0,0 +1,37 @@ +package cd.casic.ci.common.pipeline.req.variable; + +import lombok.Data; + +import java.util.List; + +@Data +public class VariableReq { + //@ApiProperty(name="varId",desc="id") + private String varId; + + //@ApiProperty(name="createTime",desc="创建时间") + private String createTime; + + //@ApiProperty(name="varType",desc="类型 str.字符串 single .单选") + private String varType; + + //@ApiProperty(name="type",desc="类型 1.全局 2.项目") + private int type; + + //@ApiProperty(name="taskId",desc="任务id") + private String taskId; + + //@ApiProperty(name="pipelineId",desc="流水线id") + private String pipelineId; + + //@ApiProperty(name = "varKey",desc="名称") + private String varKey; + + //@ApiProperty(name = "varValue",desc="默认值") + private String varValue; + + //@ApiProperty(name = "varValues",desc="值") + private String varValues; + + private List valueList; +} diff --git a/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/agent/AgentResp.java b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/agent/AgentResp.java new file mode 100644 index 00000000..d1e772cb --- /dev/null +++ b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/agent/AgentResp.java @@ -0,0 +1,22 @@ +package cd.casic.ci.common.pipeline.resp.agent; + +import lombok.Data; + +@Data +public class AgentResp { + private String id; + + private String name; + + private String ip; + + private String tenantId; + + private String address; + + private String businessType; + + private String createTime; + + private Boolean isConnect; +} diff --git a/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/task/TasksResp.java b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/task/TasksResp.java new file mode 100644 index 00000000..9429ac4d --- /dev/null +++ b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/task/TasksResp.java @@ -0,0 +1,39 @@ +package cd.casic.ci.common.pipeline.resp.task; + +import lombok.Data; + +@Data +public class TasksResp { + //@ApiProperty(name="taskId",desc="配置id") + private String taskId; + + //@ApiProperty(name="createTime",desc="创建时间") + private String createTime; + + //@ApiProperty(name="taskType",desc= "类型1-10:源码,10-20:测试,20-30:构建,30-40:部署,40-50:代码扫描,50-60:推送制品") + private String taskType; + + //@ApiProperty(name="taskSort",desc="顺序") + private int taskSort; + + //@ApiProperty(name="taskName",desc="顺序") + private String taskName; + + //@ApiProperty(name="values",desc="任务") + private Object values; + + //@ApiProperty(name="pipeline",desc="流水线id",eg="@selectOne") + private String pipelineId; + + //@ApiProperty(name="postprocessId",desc="后置处理id",eg="@selectOne") + private String postprocessId;; + + //@ApiProperty(name="stageId",desc="阶段",eg="@selectOne") + private String stageId; + + //@ApiProperty(name="task",desc="任务",eg="@selectOne") + private Object task; + + // 执行实例id + private String instanceId; +} diff --git a/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/variable/VariableResp.java b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/variable/VariableResp.java new file mode 100644 index 00000000..99ce64bc --- /dev/null +++ b/modules/module-ci-common-pipeline/src/main/java/cd/casic/ci/common/pipeline/resp/variable/VariableResp.java @@ -0,0 +1,37 @@ +package cd.casic.ci.common.pipeline.resp.variable; + +import lombok.Data; + +import java.util.List; + +@Data +public class VariableResp { + //@ApiProperty(name="varId",desc="id") + private String varId; + + //@ApiProperty(name="createTime",desc="创建时间") + private String createTime; + + //@ApiProperty(name="varType",desc="类型 str.字符串 single .单选") + private String varType; + + //@ApiProperty(name="type",desc="类型 1.全局 2.项目") + private int type; + + //@ApiProperty(name="taskId",desc="任务id") + private String taskId; + + //@ApiProperty(name="pipelineId",desc="流水线id") + private String pipelineId; + + //@ApiProperty(name = "varKey",desc="名称") + private String varKey; + + //@ApiProperty(name = "varValue",desc="默认值") + private String varValue; + + //@ApiProperty(name = "varValues",desc="值") + private String varValues; + + private List valueList; +} diff --git a/ops-server/pom.xml b/ops-server/pom.xml index 1c4d2f4f..78063ce6 100644 --- a/ops-server/pom.xml +++ b/ops-server/pom.xml @@ -43,6 +43,10 @@ cd.casic.boot spring-boot-starter-protection + + cd.casic.boot + module-ci-common-pipeline + diff --git a/ops-server/src/main/java/cd/casic/server/controller/AgentController.java b/ops-server/src/main/java/cd/casic/server/controller/AgentController.java new file mode 100644 index 00000000..e61edf94 --- /dev/null +++ b/ops-server/src/main/java/cd/casic/server/controller/AgentController.java @@ -0,0 +1,45 @@ +package cd.casic.server.controller; + +import cd.casic.ci.common.pipeline.req.agent.AgentQueryReq; +import cd.casic.ci.common.pipeline.resp.agent.AgentResp; +import cd.casic.framework.commons.pojo.CommonResult; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import jakarta.annotation.security.PermitAll; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; +@RestController +@RequestMapping("/agent") +public class AgentController { + @PermitAll + @PostMapping(path="/findAgentList") + public CommonResult> findAgentList(@RequestBody @NotNull @Valid AgentQueryReq agentQuery){ + +// List agentList = agentService.findAgentList(agentQuery); + String dataStr ="[\n" + + " {\n" + + " \"id\": \"c9ae1ff534db\",\n" + + " \"name\": \"local\",\n" + + " \"ip\": \"127.0.0.1\",\n" + + " \"tenantId\": \"default\",\n" + + " \"address\": \"local-default\",\n" + + " \"businessType\": \"default\",\n" + + " \"createTime\": \"2025-05-09 15:41:04\",\n" + + " \"displayType\": \"yes\",\n" + + " \"connect\": true\n" + + " }\n" + + "]"; + JSONArray objects = JSON.parseArray(dataStr); + List data = new ArrayList<>(objects.size()); + for (Object object : objects) { + AgentResp agentResp = JSON.parseObject(JSON.toJSONString(object), AgentResp.class); + data.add(agentResp); + } + return CommonResult.success(data); + } +} diff --git a/ops-server/src/main/java/cd/casic/server/controller/StageController.java b/ops-server/src/main/java/cd/casic/server/controller/StageController.java new file mode 100644 index 00000000..f3b9307a --- /dev/null +++ b/ops-server/src/main/java/cd/casic/server/controller/StageController.java @@ -0,0 +1,355 @@ +package cd.casic.server.controller; + +import cd.casic.ci.common.pipeline.req.stage.StageReq; +import cd.casic.ci.common.pipeline.resp.stage.StageResp; +import cd.casic.framework.commons.pojo.CommonResult; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; + +import jakarta.annotation.security.PermitAll; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; + +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + + +import java.util.ArrayList; +import java.util.List; + +/** + * @pi.protocol: http + * @pi.groupName: 流水线多阶段控制器 + */ +@RestController +@RequestMapping("/stage") +public class StageController { + +// @Autowired +// StageService stageService; + + /** + * @pi.name:创建流水线阶段及任务 + * @pi.path:/stage/createStage + * @pi.methodType:post + * @pi.request-type:json + * @pi.param: model=stage + */ + @RequestMapping(path="/createStage",method = RequestMethod.POST) + public CommonResult createStagesOrTask(@RequestBody @Valid @NotNull StageReq stage){ +// String taskId = stageService.createStagesOrTask(stage); + String taskId = ""; + return CommonResult.success(taskId); + } + + /** + * @pi.name:查询流水线阶段信息 + * @pi.path:/stage/finAllStage + * @pi.methodType:post + * @pi.request-type: formdata + * @pi.param: name=pipelineId;dataType=string;value=pipelineId; + */ + @PermitAll + @RequestMapping(path="/finAllStage",method = RequestMethod.POST) + public CommonResult> finAllPipelineTaskOrTask(@NotNull String pipelineId){ +// List tasks = stageService.findAllStagesTask(pipelineId); + String taskStr = "[\n" + + " {\n" + + " \"stageId\": \"36a816ca6cca\",\n" + + " \"stageName\": \"源码\",\n" + + " \"createTime\": \"2024-11-25 11:09:35\",\n" + + " \"pipelineId\": \"a69119cfbbde\",\n" + + " \"stageSort\": 1,\n" + + " \"parentId\": null,\n" + + " \"code\": true,\n" + + " \"taskValues\": null,\n" + + " \"stageList\": [\n" + + " {\n" + + " \"stageId\": \"8cde3a5616e9\",\n" + + " \"stageName\": \"源码\",\n" + + " \"createTime\": \"2024-11-25 11:09:35\",\n" + + " \"pipelineId\": null,\n" + + " \"stageSort\": 1,\n" + + " \"parentId\": \"36a816ca6cca\",\n" + + " \"code\": false,\n" + + " \"taskValues\": [\n" + + " {\n" + + " \"taskId\": \"a68e6052db9f\",\n" + + " \"createTime\": \"2024-11-25 11:09:35\",\n" + + " \"taskType\": \"git\",\n" + + " \"taskSort\": 1,\n" + + " \"taskName\": \"通用Git\",\n" + + " \"values\": null,\n" + + " \"pipelineId\": null,\n" + + " \"postprocessId\": null,\n" + + " \"stageId\": \"8cde3a5616e9\",\n" + + " \"task\": null,\n" + + " \"instanceId\": null\n" + + " }\n" + + " ],\n" + + " \"stageList\": null,\n" + + " \"taskType\": null,\n" + + " \"taskId\": null,\n" + + " \"values\": null,\n" + + " \"taskSort\": 0,\n" + + " \"parallelName\": null,\n" + + " \"instanceId\": null\n" + + " }\n" + + " ],\n" + + " \"taskType\": null,\n" + + " \"taskId\": null,\n" + + " \"values\": null,\n" + + " \"taskSort\": 0,\n" + + " \"parallelName\": null,\n" + + " \"instanceId\": null\n" + + " },\n" + + " {\n" + + " \"stageId\": \"3b1a5fdd9b6c\",\n" + + " \"stageName\": \"阶段-2\",\n" + + " \"createTime\": \"2025-03-10 14:51:43\",\n" + + " \"pipelineId\": \"a69119cfbbde\",\n" + + " \"stageSort\": 2,\n" + + " \"parentId\": null,\n" + + " \"code\": false,\n" + + " \"taskValues\": null,\n" + + " \"stageList\": [\n" + + " {\n" + + " \"stageId\": \"f35b1e576e30\",\n" + + " \"stageName\": \"并行阶段-2-1\",\n" + + " \"createTime\": \"2025-03-10 14:51:43\",\n" + + " \"pipelineId\": null,\n" + + " \"stageSort\": 1,\n" + + " \"parentId\": \"3b1a5fdd9b6c\",\n" + + " \"code\": false,\n" + + " \"taskValues\": [\n" + + " {\n" + + " \"taskId\": \"21a965370481\",\n" + + " \"createTime\": \"2025-03-10 14:51:43\",\n" + + " \"taskType\": \"maven\",\n" + + " \"taskSort\": 1,\n" + + " \"taskName\": \"Maven构建\",\n" + + " \"values\": null,\n" + + " \"pipelineId\": null,\n" + + " \"postprocessId\": null,\n" + + " \"stageId\": \"f35b1e576e30\",\n" + + " \"task\": null,\n" + + " \"instanceId\": null\n" + + " }\n" + + " ],\n" + + " \"stageList\": null,\n" + + " \"taskType\": null,\n" + + " \"taskId\": null,\n" + + " \"values\": null,\n" + + " \"taskSort\": 0,\n" + + " \"parallelName\": null,\n" + + " \"instanceId\": null\n" + + " }\n" + + " ],\n" + + " \"taskType\": null,\n" + + " \"taskId\": null,\n" + + " \"values\": null,\n" + + " \"taskSort\": 0,\n" + + " \"parallelName\": null,\n" + + " \"instanceId\": null\n" + + " },\n" + + " {\n" + + " \"stageId\": \"871c1b69efe0\",\n" + + " \"stageName\": \"阶段-3\",\n" + + " \"createTime\": \"2025-03-10 14:52:27\",\n" + + " \"pipelineId\": \"a69119cfbbde\",\n" + + " \"stageSort\": 3,\n" + + " \"parentId\": null,\n" + + " \"code\": false,\n" + + " \"taskValues\": null,\n" + + " \"stageList\": [\n" + + " {\n" + + " \"stageId\": \"63676c8428e6\",\n" + + " \"stageName\": \"并行阶段-3-1\",\n" + + " \"createTime\": \"2025-03-10 14:52:27\",\n" + + " \"pipelineId\": null,\n" + + " \"stageSort\": 1,\n" + + " \"parentId\": \"871c1b69efe0\",\n" + + " \"code\": false,\n" + + " \"taskValues\": [\n" + + " {\n" + + " \"taskId\": \"b5eaf0832ff1\",\n" + + " \"createTime\": \"2025-03-10 14:52:27\",\n" + + " \"taskType\": \"liunx\",\n" + + " \"taskSort\": 1,\n" + + " \"taskName\": \"主机部署\",\n" + + " \"values\": null,\n" + + " \"pipelineId\": null,\n" + + " \"postprocessId\": null,\n" + + " \"stageId\": \"63676c8428e6\",\n" + + " \"task\": null,\n" + + " \"instanceId\": null\n" + + " },\n" + + " {\n" + + " \"taskId\": \"cf756d646758\",\n" + + " \"createTime\": \"2025-05-10 14:17:52\",\n" + + " \"taskType\": \"script\",\n" + + " \"taskSort\": 2,\n" + + " \"taskName\": \"执行脚本\",\n" + + " \"values\": null,\n" + + " \"pipelineId\": null,\n" + + " \"postprocessId\": null,\n" + + " \"stageId\": \"63676c8428e6\",\n" + + " \"task\": null,\n" + + " \"instanceId\": null\n" + + " }\n" + + " ],\n" + + " \"stageList\": null,\n" + + " \"taskType\": null,\n" + + " \"taskId\": null,\n" + + " \"values\": null,\n" + + " \"taskSort\": 0,\n" + + " \"parallelName\": null,\n" + + " \"instanceId\": null\n" + + " },\n" + + " {\n" + + " \"stageId\": \"e9e4ac139f7b\",\n" + + " \"stageName\": \"并行阶段-3-2\",\n" + + " \"createTime\": \"2025-04-30 20:29:23\",\n" + + " \"pipelineId\": null,\n" + + " \"stageSort\": 2,\n" + + " \"parentId\": \"871c1b69efe0\",\n" + + " \"code\": false,\n" + + " \"taskValues\": [\n" + + " {\n" + + " \"taskId\": \"e46283a4b6d1\",\n" + + " \"createTime\": \"2025-04-30 20:29:23\",\n" + + " \"taskType\": \"script\",\n" + + " \"taskSort\": 1,\n" + + " \"taskName\": \"执行脚本\",\n" + + " \"values\": null,\n" + + " \"pipelineId\": null,\n" + + " \"postprocessId\": null,\n" + + " \"stageId\": \"e9e4ac139f7b\",\n" + + " \"task\": null,\n" + + " \"instanceId\": null\n" + + " },\n" + + " {\n" + + " \"taskId\": \"40740f834ce8\",\n" + + " \"createTime\": \"2025-05-10 14:17:17\",\n" + + " \"taskType\": \"script\",\n" + + " \"taskSort\": 2,\n" + + " \"taskName\": \"执行脚本\",\n" + + " \"values\": null,\n" + + " \"pipelineId\": null,\n" + + " \"postprocessId\": null,\n" + + " \"stageId\": \"e9e4ac139f7b\",\n" + + " \"task\": null,\n" + + " \"instanceId\": null\n" + + " }\n" + + " ],\n" + + " \"stageList\": null,\n" + + " \"taskType\": null,\n" + + " \"taskId\": null,\n" + + " \"values\": null,\n" + + " \"taskSort\": 0,\n" + + " \"parallelName\": null,\n" + + " \"instanceId\": null\n" + + " }\n" + + " ],\n" + + " \"taskType\": null,\n" + + " \"taskId\": null,\n" + + " \"values\": null,\n" + + " \"taskSort\": 0,\n" + + " \"parallelName\": null,\n" + + " \"instanceId\": null\n" + + " }\n" + + "]"; + JSONArray objects = JSON.parseArray(taskStr); + List tasks = new ArrayList<>(objects.size()); + for (int i = 0; i < objects.size(); i++) { + StageResp object = objects.getObject(i, StageResp.class); + tasks.add(object); + } + return CommonResult.success(tasks); + } + +// /** +// * @pi.name:更新流水线阶段任务 +// * @pi.path:/stage/createStage +// * @pi.methodType:post +// * @pi.request-type:json +// * @pi.param: model=stage +// */ +// @RequestMapping(path="/updateStage",method = RequestMethod.POST) +// public Result updateStageTask(@RequestBody @Valid @NotNull Stage stage){ +// stageService.updateStagesTask(stage); +// return Result.ok(); +// } +// +// /** +// * @pi.name:更新流水线阶段名称 +// * @pi.path:/stage/updateStageName +// * @pi.methodType:post +// * @pi.request-type:json +// * @pi.param: model=stage +// */ +// @RequestMapping(path="/updateStageName",method = RequestMethod.POST) +// public Result updateTasksStage(@RequestBody @Valid @NotNull Stage stage){ +// stageService.updateStageName(stage); +// return Result.ok(); +// } +// +// /** +// * @pi.name:删除流水线阶段及任务 +// * @pi.path:/stage/deleteStage +// * @pi.methodType:post +// * @pi.request-type: formdata +// * @pi.param: name=taskId;dataType=string;value=taskId; +// */ +// @RequestMapping(path="/deleteStage",method = RequestMethod.POST) +// public Result deleteTasksOrStage(@NotNull String taskId){ +// stageService.deleteStagesOrTask(taskId); +// return Result.ok(); +// } +// +// /** +// * @pi.name:效验流水线各个配置阶段完整性 +// * @pi.path:/stage/validStagesMustField +// * @pi.methodType:post +// * @pi.request-type: formdata +// * @pi.param: name=pipelineId;dataType=string;value=流水线Id; +// */ +// @RequestMapping(path="/validStagesMustField",method = RequestMethod.POST) +// public Result> validStagesMustField(@NotNull String pipelineId){ +// List list = stageService.validStagesMustField(pipelineId); +// return Result.ok(list); +// } + + + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ops-server/src/main/java/cd/casic/server/controller/TasksController.java b/ops-server/src/main/java/cd/casic/server/controller/TasksController.java new file mode 100644 index 00000000..94f99949 --- /dev/null +++ b/ops-server/src/main/java/cd/casic/server/controller/TasksController.java @@ -0,0 +1,69 @@ +package cd.casic.server.controller; + +import cd.casic.ci.common.pipeline.resp.task.TasksResp; +import cd.casic.framework.commons.pojo.CommonResult; +import com.alibaba.fastjson.JSON; +import jakarta.validation.constraints.NotNull; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +public class TasksController { + /** + * @pi.name:查询任务及任务详情 + * @pi.path:/tasks/findOneTasksOrTask + * @pi.methodType:post + * @pi.request-type: formdata + * @pi.param: name=taskId;dataType=string;value=taskId; + */ + @RequestMapping(path="/findOneTasksOrTask",method = RequestMethod.POST) + public CommonResult findOneTasksOrTask(@NotNull String taskId){ +// Tasks tasksOrTask = tasksService.findOneTasksOrTask(taskId); + String tasksStr = "{\n" + + " \"taskId\": \"842b38734ded\",\n" + + " \"createTime\": \"2025-05-10 16:58:55\",\n" + + " \"taskType\": \"maventest\",\n" + + " \"taskSort\": 1,\n" + + " \"taskName\": \"Maven单元测试\",\n" + + " \"values\": {\n" + + " \"taskId\": \"842b38734ded\",\n" + + " \"testOrder\": \"mvn test\",\n" + + " \"address\": \"${DEFAULT_CODE_ADDRESS}\",\n" + + " \"testSpace\": null,\n" + + " \"testPlan\": null,\n" + + " \"apiEnv\": null,\n" + + " \"appEnv\": null,\n" + + " \"webEnv\": null,\n" + + " \"authId\": null,\n" + + " \"auth\": null,\n" + + " \"type\": null,\n" + + " \"sort\": 0,\n" + + " \"instanceId\": null,\n" + + " \"toolJdk\": null,\n" + + " \"toolMaven\": null\n" + + " },\n" + + " \"pipelineId\": null,\n" + + " \"postprocessId\": null,\n" + + " \"stageId\": \"5656dfdfe90d\",\n" + + " \"task\": {\n" + + " \"taskId\": \"842b38734ded\",\n" + + " \"testOrder\": \"mvn test\",\n" + + " \"address\": \"${DEFAULT_CODE_ADDRESS}\",\n" + + " \"testSpace\": null,\n" + + " \"testPlan\": null,\n" + + " \"apiEnv\": null,\n" + + " \"appEnv\": null,\n" + + " \"webEnv\": null,\n" + + " \"authId\": null,\n" + + " \"auth\": null,\n" + + " \"type\": null,\n" + + " \"sort\": 0,\n" + + " \"instanceId\": null,\n" + + " \"toolJdk\": null,\n" + + " \"toolMaven\": null\n" + + " },\n" + + " \"instanceId\": null\n" + + "}"; + TasksResp tasksResp = JSON.parseObject(tasksStr, TasksResp.class); + return CommonResult.success(tasksResp); + } +} diff --git a/ops-server/src/main/java/cd/casic/server/controller/TriggerController.java b/ops-server/src/main/java/cd/casic/server/controller/TriggerController.java new file mode 100644 index 00000000..eefb07ba --- /dev/null +++ b/ops-server/src/main/java/cd/casic/server/controller/TriggerController.java @@ -0,0 +1,53 @@ +package cd.casic.server.controller; + +import cd.casic.ci.common.pipeline.req.trigger.TriggerQueryReq; +import cd.casic.framework.commons.pojo.CommonResult; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +/** + * @pi.protocol: http + * @pi.groupName: 流水线触发器控制器 + */ +@RestController +@RequestMapping("/trigger") +public class TriggerController { + /** + * @pi.name:条件查询流水线触发器信息 + * @pi.path:/trigger/findAllTrigger + * @pi.methodType:post + * @pi.request-type:json + * @pi.param: model=triggerQuery + */ + @PostMapping(path="/findAllTrigger") + public CommonResult> findAllTrigger(@RequestBody @Valid @NotNull TriggerQueryReq triggerQuery) { +// List list = triggerServer.findAllTrigger(triggerQuery); + String triggers = "[\n" + + " {\n" + + " \"timeId\": \"3e0ef2372dfc\",\n" + + " \"taskType\": 1,\n" + + " \"date\": 1,\n" + + " \"time\": \"16:00\",\n" + + " \"triggerId\": \"9f2ca05e88d4\",\n" + + " \"cron\": \"00 00 16 12 5 ? 2025\",\n" + + " \"weekTime\": \"2025-5-12 16:00:00\",\n" + + " \"execTime\": \"周一 | 周二 | 周三 | 16:00\",\n" + + " \"timeList\": [\n" + + " 1,\n" + + " 2,\n" + + " 3\n" + + " ],\n" + + " \"dayTime\": null,\n" + + " \"type\": 81,\n" + + " \"name\": null,\n" + + " \"state\": \"1\"\n" + + " }\n" + + "]"; + JSONArray objects = JSON.parseArray(triggers); + return CommonResult.success(objects); + } +} diff --git a/ops-server/src/main/java/cd/casic/server/controller/VariableController.java b/ops-server/src/main/java/cd/casic/server/controller/VariableController.java new file mode 100644 index 00000000..e5ee0daa --- /dev/null +++ b/ops-server/src/main/java/cd/casic/server/controller/VariableController.java @@ -0,0 +1,97 @@ +package cd.casic.server.controller; + +import cd.casic.ci.common.pipeline.req.variable.VariableReq; +import cd.casic.ci.common.pipeline.resp.variable.VariableResp; +import cd.casic.framework.commons.pojo.CommonResult; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +/** + * @pi.protocol: http + * @pi.groupName: 流水线变量控制器 + */ +@RestController +@RequestMapping("/pipelineVariable") +public class VariableController { + /** + * @pi.name:创建流水线变量 + * @pi.path:/pipelineVariable/createVariable + * @pi.methodType:post + * @pi.request-type:json + * @pi.param: model=variable + */ + @RequestMapping(path="/createVariable",method = RequestMethod.POST) + public CommonResult createVariable(@RequestBody @NotNull @Valid VariableReq variable){ + String variableId = ""; +// String variableId = variableServer.createVariable(variable); + return CommonResult.success(variableId); + } + + /** + * @pi.name:删除流水线变量 + * @pi.path:/pipelineVariable/deleteVariable + * @pi.methodType:post + * @pi.request-type: formdata + * @pi.param: name=varId;dataType=string;value=varId; + */ + @RequestMapping(path="/deleteVariable",method = RequestMethod.POST) + public CommonResult deleteVariable( @NotNull String varId){ +// variableServer.deleteVariable(varId); + return CommonResult.success(""); + } + + /** + * @pi.name:更新流水线变量 + * @pi.path:/pipelineVariable/createVariable + * @pi.methodType:post + * @pi.request-type:json + * @pi.param: model=variable + */ + @RequestMapping(path="/updateVariable",method = RequestMethod.POST) + public CommonResult updateVariable(@RequestBody @NotNull @Valid VariableReq variable){ +// variableServer.updateVariable(variable); + return CommonResult.success(""); + } + + /** + * @pi.name:查询流水线任务变量 + * @pi.path:/pipelineVariable/findAllVariable + * @pi.methodType:post + * @pi.request-type: formdata + * @pi.param: name=taskId;dataType=string;value=任务id; + */ + @RequestMapping(path="/findAllVariable",method = RequestMethod.POST) + public CommonResult> findAllVariable(@NotNull String taskId){ +// List allVariable = variableServer.findAllVariable(taskId); + String varListStr = "[\n" + + " {\n" + + " \"varId\": \"04b629ce9234\",\n" + + " \"createTime\": \"2025-05-10 14:25:24\",\n" + + " \"varType\": \"str\",\n" + + " \"type\": 1,\n" + + " \"taskId\": \"a69119cfbbde\",\n" + + " \"pipelineId\": null,\n" + + " \"varKey\": \"testVal\",\n" + + " \"varValue\": \"123\",\n" + + " \"varValues\": null,\n" + + " \"valueList\": null\n" + + " }\n" + + "]"; + JSONArray objects = JSON.parseArray(varListStr); + List allVariable = new ArrayList<>(objects.size()); + for (int i = 0; i < objects.size(); i++) { + VariableResp object = objects.getObject(i, VariableResp.class); + allVariable.add(object); + } + return CommonResult.success(allVariable); + } +}