mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: update powerjob client,copy job and workflow are supported
This commit is contained in:
parent
0c424b52df
commit
59e3fee086
@ -121,6 +121,22 @@ public class OhMyClient {
|
||||
return JSON.parseObject(post, LONG_RESULT_TYPE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy one Job
|
||||
*
|
||||
* @param jobId Job id
|
||||
* @return Id of job copy
|
||||
*/
|
||||
public ResultDTO<Long> copyJob(Long jobId) {
|
||||
RequestBody body = new FormBody.Builder()
|
||||
.add("jobId", jobId.toString())
|
||||
.add("appId", appId.toString())
|
||||
.build();
|
||||
String post = postHA(OpenAPIConstant.COPY_JOB, body);
|
||||
return JSON.parseObject(post, LONG_RESULT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query JobInfo by jobId
|
||||
*
|
||||
@ -328,6 +344,22 @@ public class OhMyClient {
|
||||
return JSON.parseObject(post, LONG_RESULT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy one workflow
|
||||
*
|
||||
* @param workflowId Workflow id
|
||||
* @return Id of workflow copy
|
||||
*/
|
||||
public ResultDTO<Long> copyWorkflow(Long workflowId) {
|
||||
RequestBody body = new FormBody.Builder()
|
||||
.add("workflowId", workflowId.toString())
|
||||
.add("appId", appId.toString())
|
||||
.build();
|
||||
String post = postHA(OpenAPIConstant.COPY_WORKFLOW, body);
|
||||
return JSON.parseObject(post, LONG_RESULT_TYPE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存工作流 DAG
|
||||
*
|
||||
@ -493,10 +525,10 @@ public class OhMyClient {
|
||||
* mark the workflow node as success
|
||||
*
|
||||
* @param wfInstanceId workflow instanceId
|
||||
* @param nodeId node id
|
||||
* @param nodeId node id
|
||||
* @return Standard return object
|
||||
*/
|
||||
public ResultDTO<Void> markWorkflowNodeAsSuccess(Long wfInstanceId,Long nodeId) {
|
||||
public ResultDTO<Void> markWorkflowNodeAsSuccess(Long wfInstanceId, Long nodeId) {
|
||||
RequestBody body = new FormBody.Builder()
|
||||
.add("wfInstanceId", wfInstanceId.toString())
|
||||
.add("nodeId", nodeId.toString())
|
||||
|
@ -6,8 +6,11 @@ import com.github.kfcfans.powerjob.common.ExecuteType;
|
||||
import com.github.kfcfans.powerjob.common.ProcessorType;
|
||||
import com.github.kfcfans.powerjob.common.TimeExpressionType;
|
||||
import com.github.kfcfans.powerjob.common.request.http.SaveJobInfoRequest;
|
||||
import com.github.kfcfans.powerjob.common.response.InstanceInfoDTO;
|
||||
import com.github.kfcfans.powerjob.common.response.JobInfoDTO;
|
||||
import com.github.kfcfans.powerjob.common.response.ResultDTO;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -16,6 +19,7 @@ import java.util.concurrent.TimeUnit;
|
||||
* Test cases for {@link OhMyClient}
|
||||
*
|
||||
* @author tjq
|
||||
* @author Echo009
|
||||
* @since 2020/4/15
|
||||
*/
|
||||
class TestClient extends ClientInitializer {
|
||||
@ -23,12 +27,12 @@ class TestClient extends ClientInitializer {
|
||||
public static final long JOB_ID = 4L;
|
||||
|
||||
@Test
|
||||
public void testSaveJob() throws Exception {
|
||||
void testSaveJob() {
|
||||
|
||||
SaveJobInfoRequest newJobInfo = new SaveJobInfoRequest();
|
||||
newJobInfo.setId(JOB_ID);
|
||||
newJobInfo.setJobName("omsOpenAPIJobccccc");
|
||||
newJobInfo.setJobDescription("tes OpenAPI");
|
||||
newJobInfo.setJobDescription("test OpenAPI");
|
||||
newJobInfo.setJobParams("{'aa':'bb'}");
|
||||
newJobInfo.setTimeExpressionType(TimeExpressionType.CRON);
|
||||
newJobInfo.setTimeExpression("0 0 * * * ? ");
|
||||
@ -43,64 +47,91 @@ class TestClient extends ClientInitializer {
|
||||
|
||||
ResultDTO<Long> resultDTO = ohMyClient.saveJob(newJobInfo);
|
||||
System.out.println(JSONObject.toJSONString(resultDTO));
|
||||
Assertions.assertNotNull(resultDTO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchJob() throws Exception {
|
||||
void testCopyJob() {
|
||||
ResultDTO<Long> copyJobRes = ohMyClient.copyJob(JOB_ID);
|
||||
System.out.println(JSONObject.toJSONString(copyJobRes));
|
||||
Assertions.assertNotNull(copyJobRes);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchJob() {
|
||||
ResultDTO<JobInfoDTO> fetchJob = ohMyClient.fetchJob(JOB_ID);
|
||||
System.out.println(JSONObject.toJSONString(fetchJob));
|
||||
Assertions.assertNotNull(fetchJob);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisableJob() throws Exception {
|
||||
System.out.println(ohMyClient.disableJob(JOB_ID));
|
||||
void testDisableJob() {
|
||||
ResultDTO<Void> res = ohMyClient.disableJob(JOB_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnableJob() throws Exception {
|
||||
System.out.println(ohMyClient.enableJob(JOB_ID));
|
||||
void testEnableJob() {
|
||||
ResultDTO<Void> res = ohMyClient.enableJob(JOB_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteJob() throws Exception {
|
||||
System.out.println(ohMyClient.deleteJob(JOB_ID));
|
||||
void testDeleteJob() {
|
||||
ResultDTO<Void> res = ohMyClient.deleteJob(JOB_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRun() {
|
||||
System.out.println(ohMyClient.runJob(JOB_ID));
|
||||
void testRun() {
|
||||
ResultDTO<Long> res = ohMyClient.runJob(JOB_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunJobDelay() throws Exception {
|
||||
System.out.println(ohMyClient.runJob(JOB_ID, "this is instanceParams", 60000));
|
||||
void testRunJobDelay() {
|
||||
ResultDTO<Long> res = ohMyClient.runJob(JOB_ID, "this is instanceParams", 60000);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchInstanceInfo() throws Exception {
|
||||
System.out.println(ohMyClient.fetchInstanceInfo(205436386851946560L));
|
||||
void testFetchInstanceInfo() {
|
||||
ResultDTO<InstanceInfoDTO> res = ohMyClient.fetchInstanceInfo(205436386851946560L);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopInstance() throws Exception {
|
||||
void testStopInstance() {
|
||||
ResultDTO<Void> res = ohMyClient.stopInstance(205436995885858880L);
|
||||
System.out.println(res.toString());
|
||||
}
|
||||
@Test
|
||||
public void testFetchInstanceStatus() throws Exception {
|
||||
System.out.println(ohMyClient.fetchInstanceStatus(205436995885858880L));
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCancelInstanceInTimeWheel() throws Exception {
|
||||
void testFetchInstanceStatus() {
|
||||
ResultDTO<Integer> res = ohMyClient.fetchInstanceStatus(205436995885858880L);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCancelInstanceInTimeWheel() {
|
||||
ResultDTO<Long> startRes = ohMyClient.runJob(JOB_ID, "start by OhMyClient", 20000);
|
||||
System.out.println("runJob result: " + JSONObject.toJSONString(startRes));
|
||||
ResultDTO<Void> cancelRes = ohMyClient.cancelInstance(startRes.getData());
|
||||
System.out.println("cancelJob result: " + JSONObject.toJSONString(cancelRes));
|
||||
Assertions.assertTrue(cancelRes.isSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCancelInstanceInDatabase() throws Exception {
|
||||
@SneakyThrows
|
||||
void testCancelInstanceInDatabase() {
|
||||
ResultDTO<Long> startRes = ohMyClient.runJob(15L, "start by OhMyClient", 2000000);
|
||||
System.out.println("runJob result: " + JSONObject.toJSONString(startRes));
|
||||
|
||||
@ -109,11 +140,13 @@ class TestClient extends ClientInitializer {
|
||||
|
||||
ResultDTO<Void> cancelRes = ohMyClient.cancelInstance(startRes.getData());
|
||||
System.out.println("cancelJob result: " + JSONObject.toJSONString(cancelRes));
|
||||
Assertions.assertTrue(cancelRes.isSuccess());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetryInstance() throws Exception {
|
||||
void testRetryInstance() {
|
||||
ResultDTO<Void> res = ohMyClient.retryInstance(169557545206153344L);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,12 @@ import com.github.kfcfans.powerjob.common.ProcessorType;
|
||||
import com.github.kfcfans.powerjob.common.TimeExpressionType;
|
||||
import com.github.kfcfans.powerjob.common.model.PEWorkflowDAG;
|
||||
import com.github.kfcfans.powerjob.common.request.http.*;
|
||||
import com.github.kfcfans.powerjob.common.response.ResultDTO;
|
||||
import com.github.kfcfans.powerjob.common.response.WorkflowInfoDTO;
|
||||
import com.github.kfcfans.powerjob.common.response.WorkflowInstanceInfoDTO;
|
||||
import com.github.kfcfans.powerjob.common.response.WorkflowNodeInfoDTO;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
@ -16,6 +21,7 @@ import java.util.List;
|
||||
* Test cases for {@link OhMyClient} workflow.
|
||||
*
|
||||
* @author tjq
|
||||
* @author Echo009
|
||||
* @since 2020/6/2
|
||||
*/
|
||||
class TestWorkflow extends ClientInitializer {
|
||||
@ -23,7 +29,7 @@ class TestWorkflow extends ClientInitializer {
|
||||
private static final long WF_ID = 1;
|
||||
|
||||
@Test
|
||||
void initTestData() throws Exception {
|
||||
void initTestData() {
|
||||
SaveJobInfoRequest base = new SaveJobInfoRequest();
|
||||
base.setJobName("DAG-Node-");
|
||||
base.setTimeExpressionType(TimeExpressionType.WORKFLOW);
|
||||
@ -34,13 +40,15 @@ class TestWorkflow extends ClientInitializer {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
SaveJobInfoRequest request = JSONObject.parseObject(JSONObject.toJSONBytes(base), SaveJobInfoRequest.class);
|
||||
request.setJobName(request.getJobName() + i);
|
||||
System.out.println(ohMyClient.saveJob(request));
|
||||
ResultDTO<Long> res = ohMyClient.saveJob(request);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSaveWorkflow() throws Exception {
|
||||
|
||||
void testSaveWorkflow() {
|
||||
|
||||
SaveWorkflowRequest req = new SaveWorkflowRequest();
|
||||
|
||||
@ -50,16 +58,27 @@ class TestWorkflow extends ClientInitializer {
|
||||
req.setTimeExpressionType(TimeExpressionType.API);
|
||||
|
||||
System.out.println("req ->" + JSONObject.toJSON(req));
|
||||
System.out.println(ohMyClient.saveWorkflow(req));
|
||||
ResultDTO<Long> res = ohMyClient.saveWorkflow(req);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCopyWorkflow() {
|
||||
ResultDTO<Long> res = ohMyClient.copyWorkflow(WF_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddWorkflowNode() {
|
||||
AddWorkflowNodeRequest addWorkflowNodeRequest = new AddWorkflowNodeRequest();
|
||||
addWorkflowNodeRequest.setJobId(1L);
|
||||
addWorkflowNodeRequest.setWorkflowId(WF_ID);
|
||||
System.out.println(ohMyClient.addWorkflowNode(Lists.newArrayList(addWorkflowNodeRequest)));
|
||||
ResultDTO<List<WorkflowNodeInfoDTO>> res = ohMyClient.addWorkflowNode(Lists.newArrayList(addWorkflowNodeRequest));
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -70,7 +89,9 @@ class TestWorkflow extends ClientInitializer {
|
||||
modifyWorkflowNodeRequest.setNodeAlias("(๑•̀ㅂ•́)و✧");
|
||||
modifyWorkflowNodeRequest.setEnable(false);
|
||||
modifyWorkflowNodeRequest.setSkipWhenFailed(false);
|
||||
System.out.println(ohMyClient.modifyWorkflowNode(modifyWorkflowNodeRequest));
|
||||
ResultDTO<Void> res = ohMyClient.modifyWorkflowNode(modifyWorkflowNodeRequest);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -91,58 +112,79 @@ class TestWorkflow extends ClientInitializer {
|
||||
SaveWorkflowDAGRequest saveWorkflowDAGRequest = new SaveWorkflowDAGRequest();
|
||||
saveWorkflowDAGRequest.setId(WF_ID);
|
||||
saveWorkflowDAGRequest.setDag(peWorkflowDAG);
|
||||
|
||||
System.out.println(ohMyClient.saveWorkflowDag(saveWorkflowDAGRequest));
|
||||
ResultDTO<Void> res = ohMyClient.saveWorkflowDag(saveWorkflowDAGRequest);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testDisableWorkflow() throws Exception {
|
||||
System.out.println(ohMyClient.disableWorkflow(WF_ID));
|
||||
void testDisableWorkflow() {
|
||||
ResultDTO<Void> res = ohMyClient.disableWorkflow(WF_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteWorkflow() throws Exception {
|
||||
System.out.println(ohMyClient.deleteWorkflow(WF_ID));
|
||||
void testDeleteWorkflow() {
|
||||
ResultDTO<Void> res = ohMyClient.deleteWorkflow(WF_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEnableWorkflow() throws Exception {
|
||||
System.out.println(ohMyClient.enableWorkflow(WF_ID));
|
||||
void testEnableWorkflow() {
|
||||
ResultDTO<Void> res = ohMyClient.enableWorkflow(WF_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWorkflowInfo() throws Exception {
|
||||
System.out.println(ohMyClient.fetchWorkflow(WF_ID));
|
||||
void testFetchWorkflowInfo() {
|
||||
ResultDTO<WorkflowInfoDTO> res = ohMyClient.fetchWorkflow(WF_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRunWorkflow() throws Exception {
|
||||
System.out.println(ohMyClient.runWorkflow(WF_ID));
|
||||
void testRunWorkflow() {
|
||||
ResultDTO<Long> res = ohMyClient.runWorkflow(WF_ID);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStopWorkflowInstance() throws Exception {
|
||||
System.out.println(ohMyClient.stopWorkflowInstance(149962433421639744L));
|
||||
void testStopWorkflowInstance() {
|
||||
ResultDTO<Void> res = ohMyClient.stopWorkflowInstance(149962433421639744L);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRetryWorkflowInstance() {
|
||||
System.out.println(ohMyClient.retryWorkflowInstance(149962433421639744L));
|
||||
ResultDTO<Void> res = ohMyClient.retryWorkflowInstance(149962433421639744L);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMarkWorkflowNodeAsSuccess() {
|
||||
System.out.println(ohMyClient.markWorkflowNodeAsSuccess(149962433421639744L, 1L));
|
||||
ResultDTO<Void> res = ohMyClient.markWorkflowNodeAsSuccess(149962433421639744L, 1L);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFetchWfInstanceInfo() throws Exception {
|
||||
System.out.println(ohMyClient.fetchWorkflowInstanceInfo(149962433421639744L));
|
||||
void testFetchWfInstanceInfo() {
|
||||
ResultDTO<WorkflowInstanceInfoDTO> res = ohMyClient.fetchWorkflowInstanceInfo(149962433421639744L);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRunWorkflowPlus() throws Exception {
|
||||
System.out.println(ohMyClient.runWorkflow(WF_ID, "this is init Params 2", 90000));
|
||||
void testRunWorkflowPlus() {
|
||||
ResultDTO<Long> res = ohMyClient.runWorkflow(WF_ID, "this is init Params 2", 90000);
|
||||
System.out.println(res);
|
||||
Assertions.assertNotNull(res);
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +104,9 @@ public class JobService {
|
||||
public JobInfoDO copyJob(Long jobId) {
|
||||
|
||||
JobInfoDO origin = jobInfoRepository.findById(jobId).orElseThrow(() -> new IllegalArgumentException("can't find job by jobId: " + jobId));
|
||||
if (origin.getStatus() == SwitchableStatus.DELETED.getV()) {
|
||||
throw new IllegalStateException("can't copy the job which has been deleted!");
|
||||
}
|
||||
JobInfoDO copyJob = new JobInfoDO();
|
||||
// 值拷贝
|
||||
BeanUtils.copyProperties(origin, copyJob);
|
||||
|
@ -3,21 +3,19 @@ package com.github.kfcfans.powerjob.server.web.controller;
|
||||
import com.github.kfcfans.powerjob.common.InstanceStatus;
|
||||
import com.github.kfcfans.powerjob.common.OpenAPIConstant;
|
||||
import com.github.kfcfans.powerjob.common.PowerQuery;
|
||||
import com.github.kfcfans.powerjob.common.request.http.SaveWorkflowRequest;
|
||||
import com.github.kfcfans.powerjob.common.request.http.*;
|
||||
import com.github.kfcfans.powerjob.common.request.query.JobInfoQuery;
|
||||
import com.github.kfcfans.powerjob.common.response.InstanceInfoDTO;
|
||||
import com.github.kfcfans.powerjob.common.response.JobInfoDTO;
|
||||
import com.github.kfcfans.powerjob.common.response.ResultDTO;
|
||||
import com.github.kfcfans.powerjob.common.response.WorkflowInstanceInfoDTO;
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.model.WorkflowNodeInfoDO;
|
||||
import com.github.kfcfans.powerjob.server.service.AppInfoService;
|
||||
import com.github.kfcfans.powerjob.server.service.CacheService;
|
||||
import com.github.kfcfans.powerjob.server.service.JobService;
|
||||
import com.github.kfcfans.powerjob.server.service.instance.InstanceService;
|
||||
import com.github.kfcfans.powerjob.common.request.http.SaveJobInfoRequest;
|
||||
import com.github.kfcfans.powerjob.server.service.workflow.WorkflowInstanceService;
|
||||
import com.github.kfcfans.powerjob.server.service.workflow.WorkflowService;
|
||||
import com.github.kfcfans.powerjob.common.response.*;
|
||||
import com.github.kfcfans.powerjob.common.request.http.AddWorkflowNodeRequest;
|
||||
import com.github.kfcfans.powerjob.common.request.http.ModifyWorkflowNodeRequest;
|
||||
import com.github.kfcfans.powerjob.common.request.http.SaveWorkflowDAGRequest;
|
||||
import com.github.kfcfans.powerjob.server.web.response.JobInfoVO;
|
||||
import com.github.kfcfans.powerjob.server.web.response.WorkflowInfoVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -66,8 +64,8 @@ public class OpenAPIController {
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.COPY_JOB)
|
||||
public ResultDTO<JobInfoVO> copyJob(Long jobId) {
|
||||
return ResultDTO.success(JobInfoVO.from(jobService.copyJob(jobId)));
|
||||
public ResultDTO<Long> copyJob(Long jobId) {
|
||||
return ResultDTO.success(jobService.copyJob(jobId).getId());
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.FETCH_JOB)
|
||||
|
Loading…
x
Reference in New Issue
Block a user