mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
refactor: rename OhMyClient to PowerJobClient
This commit is contained in:
parent
fe439721d0
commit
0a854cd276
@ -27,13 +27,13 @@ import java.util.Objects;
|
|||||||
import static tech.powerjob.client.TypeStore.*;
|
import static tech.powerjob.client.TypeStore.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OhMyClient, the client for OpenAPI.
|
* PowerJobClient, the client for OpenAPI.
|
||||||
*
|
*
|
||||||
* @author tjq
|
* @author tjq
|
||||||
* @since 2020/4/15
|
* @since 2020/4/15
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OhMyClient {
|
public class PowerJobClient {
|
||||||
|
|
||||||
private Long appId;
|
private Long appId;
|
||||||
private String currentAddress;
|
private String currentAddress;
|
||||||
@ -42,25 +42,25 @@ public class OhMyClient {
|
|||||||
private static final String URL_PATTERN = "http://%s%s%s";
|
private static final String URL_PATTERN = "http://%s%s%s";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init OhMyClient with domain, appName and password.
|
* Init PowerJobClient with domain, appName and password.
|
||||||
*
|
*
|
||||||
* @param domain like powerjob-server.apple-inc.com (Intranet Domain)
|
* @param domain like powerjob-server.apple-inc.com (Intranet Domain)
|
||||||
* @param appName name of the application
|
* @param appName name of the application
|
||||||
* @param password password of the application
|
* @param password password of the application
|
||||||
*/
|
*/
|
||||||
public OhMyClient(String domain, String appName, String password) {
|
public PowerJobClient(String domain, String appName, String password) {
|
||||||
this(Lists.newArrayList(domain), appName, password);
|
this(Lists.newArrayList(domain), appName, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init OhMyClient with server address, appName and password.
|
* Init PowerJobClient with server address, appName and password.
|
||||||
*
|
*
|
||||||
* @param addressList IP:Port address list, like 192.168.1.1:7700
|
* @param addressList IP:Port address list, like 192.168.1.1:7700
|
||||||
* @param appName name of the application
|
* @param appName name of the application
|
||||||
* @param password password of the application
|
* @param password password of the application
|
||||||
*/
|
*/
|
||||||
public OhMyClient(List<String> addressList, String appName, String password) {
|
public PowerJobClient(List<String> addressList, String appName, String password) {
|
||||||
|
|
||||||
CommonUtils.requireNonNull(addressList, "addressList can't be null!");
|
CommonUtils.requireNonNull(addressList, "addressList can't be null!");
|
||||||
CommonUtils.requireNonNull(appName, "appName can't be null");
|
CommonUtils.requireNonNull(appName, "appName can't be null");
|
||||||
@ -86,9 +86,9 @@ public class OhMyClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isEmpty(currentAddress)) {
|
if (StringUtils.isEmpty(currentAddress)) {
|
||||||
throw new PowerJobException("no server available for OhMyClient");
|
throw new PowerJobException("no server available for PowerJobClient");
|
||||||
}
|
}
|
||||||
log.info("[OhMyClient] {}'s OhMyClient bootstrap successfully, using server: {}", appName, currentAddress);
|
log.info("[PowerJobClient] {}'s PowerJobClient bootstrap successfully, using server: {}", appName, currentAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String assertApp(String appName, String password, String url) throws IOException {
|
private static String assertApp(String appName, String password, String url) throws IOException {
|
||||||
@ -539,7 +539,7 @@ public class OhMyClient {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warn("[OhMyClient] request url:{} failed, reason is {}.", url, e.toString());
|
log.warn("[PowerJobClient] request url:{} failed, reason is {}.", url, e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 失败,开始重试
|
// 失败,开始重试
|
||||||
@ -551,16 +551,16 @@ public class OhMyClient {
|
|||||||
try {
|
try {
|
||||||
String res = HttpUtils.post(url, requestBody);
|
String res = HttpUtils.post(url, requestBody);
|
||||||
if (StringUtils.isNotEmpty(res)) {
|
if (StringUtils.isNotEmpty(res)) {
|
||||||
log.warn("[OhMyClient] server change: from({}) -> to({}).", currentAddress, addr);
|
log.warn("[PowerJobClient] server change: from({}) -> to({}).", currentAddress, addr);
|
||||||
currentAddress = addr;
|
currentAddress = addr;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warn("[OhMyClient] request url:{} failed, reason is {}.", url, e.toString());
|
log.warn("[PowerJobClient] request url:{} failed, reason is {}.", url, e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.error("[OhMyClient] do post for path: {} failed because of no server available in {}.", path, allAddress);
|
log.error("[PowerJobClient] do post for path: {} failed because of no server available in {}.", path, allAddress);
|
||||||
throw new PowerJobException("no server available when send post request");
|
throw new PowerJobException("no server available when send post request");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package tech.powerjob.client.test;
|
package tech.powerjob.client.test;
|
||||||
|
|
||||||
import tech.powerjob.client.OhMyClient;
|
import tech.powerjob.client.PowerJobClient;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,10 +11,10 @@ import org.junit.jupiter.api.BeforeAll;
|
|||||||
*/
|
*/
|
||||||
public class ClientInitializer {
|
public class ClientInitializer {
|
||||||
|
|
||||||
protected static OhMyClient ohMyClient;
|
protected static PowerJobClient powerJobClient;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void initClient() throws Exception {
|
public static void initClient() throws Exception {
|
||||||
ohMyClient = new OhMyClient("127.0.0.1:7700", "powerjob-agent-test", "123");
|
powerJobClient = new PowerJobClient("127.0.0.1:7700", "powerjob-agent-test", "123");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package tech.powerjob.client.test;
|
package tech.powerjob.client.test;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import tech.powerjob.client.OhMyClient;
|
import tech.powerjob.client.PowerJobClient;
|
||||||
import tech.powerjob.common.enums.ExecuteType;
|
import tech.powerjob.common.enums.ExecuteType;
|
||||||
import tech.powerjob.common.enums.ProcessorType;
|
import tech.powerjob.common.enums.ProcessorType;
|
||||||
import tech.powerjob.common.enums.TimeExpressionType;
|
import tech.powerjob.common.enums.TimeExpressionType;
|
||||||
@ -16,7 +16,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link OhMyClient}
|
* Test cases for {@link PowerJobClient}
|
||||||
*
|
*
|
||||||
* @author tjq
|
* @author tjq
|
||||||
* @author Echo009
|
* @author Echo009
|
||||||
@ -45,86 +45,86 @@ class TestClient extends ClientInitializer {
|
|||||||
newJobInfo.setMinMemorySpace(1.2);
|
newJobInfo.setMinMemorySpace(1.2);
|
||||||
newJobInfo.setMinDiskSpace(1.3);
|
newJobInfo.setMinDiskSpace(1.3);
|
||||||
|
|
||||||
ResultDTO<Long> resultDTO = ohMyClient.saveJob(newJobInfo);
|
ResultDTO<Long> resultDTO = powerJobClient.saveJob(newJobInfo);
|
||||||
System.out.println(JSONObject.toJSONString(resultDTO));
|
System.out.println(JSONObject.toJSONString(resultDTO));
|
||||||
Assertions.assertNotNull(resultDTO);
|
Assertions.assertNotNull(resultDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCopyJob() {
|
void testCopyJob() {
|
||||||
ResultDTO<Long> copyJobRes = ohMyClient.copyJob(JOB_ID);
|
ResultDTO<Long> copyJobRes = powerJobClient.copyJob(JOB_ID);
|
||||||
System.out.println(JSONObject.toJSONString(copyJobRes));
|
System.out.println(JSONObject.toJSONString(copyJobRes));
|
||||||
Assertions.assertNotNull(copyJobRes);
|
Assertions.assertNotNull(copyJobRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFetchJob() {
|
void testFetchJob() {
|
||||||
ResultDTO<JobInfoDTO> fetchJob = ohMyClient.fetchJob(JOB_ID);
|
ResultDTO<JobInfoDTO> fetchJob = powerJobClient.fetchJob(JOB_ID);
|
||||||
System.out.println(JSONObject.toJSONString(fetchJob));
|
System.out.println(JSONObject.toJSONString(fetchJob));
|
||||||
Assertions.assertNotNull(fetchJob);
|
Assertions.assertNotNull(fetchJob);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDisableJob() {
|
void testDisableJob() {
|
||||||
ResultDTO<Void> res = ohMyClient.disableJob(JOB_ID);
|
ResultDTO<Void> res = powerJobClient.disableJob(JOB_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testEnableJob() {
|
void testEnableJob() {
|
||||||
ResultDTO<Void> res = ohMyClient.enableJob(JOB_ID);
|
ResultDTO<Void> res = powerJobClient.enableJob(JOB_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDeleteJob() {
|
void testDeleteJob() {
|
||||||
ResultDTO<Void> res = ohMyClient.deleteJob(JOB_ID);
|
ResultDTO<Void> res = powerJobClient.deleteJob(JOB_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRun() {
|
void testRun() {
|
||||||
ResultDTO<Long> res = ohMyClient.runJob(JOB_ID);
|
ResultDTO<Long> res = powerJobClient.runJob(JOB_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRunJobDelay() {
|
void testRunJobDelay() {
|
||||||
ResultDTO<Long> res = ohMyClient.runJob(JOB_ID, "this is instanceParams", 60000);
|
ResultDTO<Long> res = powerJobClient.runJob(JOB_ID, "this is instanceParams", 60000);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFetchInstanceInfo() {
|
void testFetchInstanceInfo() {
|
||||||
ResultDTO<InstanceInfoDTO> res = ohMyClient.fetchInstanceInfo(205436386851946560L);
|
ResultDTO<InstanceInfoDTO> res = powerJobClient.fetchInstanceInfo(205436386851946560L);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testStopInstance() {
|
void testStopInstance() {
|
||||||
ResultDTO<Void> res = ohMyClient.stopInstance(205436995885858880L);
|
ResultDTO<Void> res = powerJobClient.stopInstance(205436995885858880L);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFetchInstanceStatus() {
|
void testFetchInstanceStatus() {
|
||||||
ResultDTO<Integer> res = ohMyClient.fetchInstanceStatus(205436995885858880L);
|
ResultDTO<Integer> res = powerJobClient.fetchInstanceStatus(205436995885858880L);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCancelInstanceInTimeWheel() {
|
void testCancelInstanceInTimeWheel() {
|
||||||
ResultDTO<Long> startRes = ohMyClient.runJob(JOB_ID, "start by OhMyClient", 20000);
|
ResultDTO<Long> startRes = powerJobClient.runJob(JOB_ID, "start by OhMyClient", 20000);
|
||||||
System.out.println("runJob result: " + JSONObject.toJSONString(startRes));
|
System.out.println("runJob result: " + JSONObject.toJSONString(startRes));
|
||||||
ResultDTO<Void> cancelRes = ohMyClient.cancelInstance(startRes.getData());
|
ResultDTO<Void> cancelRes = powerJobClient.cancelInstance(startRes.getData());
|
||||||
System.out.println("cancelJob result: " + JSONObject.toJSONString(cancelRes));
|
System.out.println("cancelJob result: " + JSONObject.toJSONString(cancelRes));
|
||||||
Assertions.assertTrue(cancelRes.isSuccess());
|
Assertions.assertTrue(cancelRes.isSuccess());
|
||||||
}
|
}
|
||||||
@ -132,20 +132,20 @@ class TestClient extends ClientInitializer {
|
|||||||
@Test
|
@Test
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testCancelInstanceInDatabase() {
|
void testCancelInstanceInDatabase() {
|
||||||
ResultDTO<Long> startRes = ohMyClient.runJob(15L, "start by OhMyClient", 2000000);
|
ResultDTO<Long> startRes = powerJobClient.runJob(15L, "start by OhMyClient", 2000000);
|
||||||
System.out.println("runJob result: " + JSONObject.toJSONString(startRes));
|
System.out.println("runJob result: " + JSONObject.toJSONString(startRes));
|
||||||
|
|
||||||
// Restart server manually and clear all the data in time wheeler.
|
// Restart server manually and clear all the data in time wheeler.
|
||||||
TimeUnit.MINUTES.sleep(1);
|
TimeUnit.MINUTES.sleep(1);
|
||||||
|
|
||||||
ResultDTO<Void> cancelRes = ohMyClient.cancelInstance(startRes.getData());
|
ResultDTO<Void> cancelRes = powerJobClient.cancelInstance(startRes.getData());
|
||||||
System.out.println("cancelJob result: " + JSONObject.toJSONString(cancelRes));
|
System.out.println("cancelJob result: " + JSONObject.toJSONString(cancelRes));
|
||||||
Assertions.assertTrue(cancelRes.isSuccess());
|
Assertions.assertTrue(cancelRes.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRetryInstance() {
|
void testRetryInstance() {
|
||||||
ResultDTO<Void> res = ohMyClient.retryInstance(169557545206153344L);
|
ResultDTO<Void> res = powerJobClient.retryInstance(169557545206153344L);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class TestConcurrencyControl extends ClientInitializer {
|
|||||||
saveJobInfoRequest.setTimeExpressionType(TimeExpressionType.API);
|
saveJobInfoRequest.setTimeExpressionType(TimeExpressionType.API);
|
||||||
saveJobInfoRequest.setMaxInstanceNum(1);
|
saveJobInfoRequest.setMaxInstanceNum(1);
|
||||||
|
|
||||||
Long jobId = ohMyClient.saveJob(saveJobInfoRequest).getData();
|
Long jobId = powerJobClient.saveJob(saveJobInfoRequest).getData();
|
||||||
|
|
||||||
System.out.println("jobId: " + jobId);
|
System.out.println("jobId: " + jobId);
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ class TestConcurrencyControl extends ClientInitializer {
|
|||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
String params = "index-" + i;
|
String params = "index-" + i;
|
||||||
pool.execute(() -> {
|
pool.execute(() -> {
|
||||||
ResultDTO<Long> res = ohMyClient.runJob(jobId, params, 0);
|
ResultDTO<Long> res = powerJobClient.runJob(jobId, params, 0);
|
||||||
System.out.println(params + ": " + res);
|
System.out.println(params + ": " + res);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ class TestQuery extends ClientInitializer {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFetchAllJob() {
|
void testFetchAllJob() {
|
||||||
ResultDTO<List<JobInfoDTO>> allJobRes = ohMyClient.fetchAllJob();
|
ResultDTO<List<JobInfoDTO>> allJobRes = powerJobClient.fetchAllJob();
|
||||||
System.out.println(JSON.toJSONString(allJobRes));
|
System.out.println(JSON.toJSONString(allJobRes));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class TestQuery extends ClientInitializer {
|
|||||||
.setProcessorTypeIn(Lists.newArrayList(ProcessorType.BUILT_IN.getV(), ProcessorType.SHELL.getV(), ProcessorType.EXTERNAL.getV()))
|
.setProcessorTypeIn(Lists.newArrayList(ProcessorType.BUILT_IN.getV(), ProcessorType.SHELL.getV(), ProcessorType.EXTERNAL.getV()))
|
||||||
.setProcessorInfoLike("com.github.kfcfans");
|
.setProcessorInfoLike("com.github.kfcfans");
|
||||||
|
|
||||||
ResultDTO<List<JobInfoDTO>> jobQueryResult = ohMyClient.queryJob(jobInfoQuery);
|
ResultDTO<List<JobInfoDTO>> jobQueryResult = powerJobClient.queryJob(jobInfoQuery);
|
||||||
System.out.println(JSON.toJSONString(jobQueryResult));
|
System.out.println(JSON.toJSONString(jobQueryResult));
|
||||||
System.out.println(jobQueryResult.getData().size());
|
System.out.println(jobQueryResult.getData().size());
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package tech.powerjob.client.test;
|
package tech.powerjob.client.test;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import tech.powerjob.client.OhMyClient;
|
import tech.powerjob.client.PowerJobClient;
|
||||||
import tech.powerjob.common.enums.ExecuteType;
|
import tech.powerjob.common.enums.ExecuteType;
|
||||||
import tech.powerjob.common.enums.ProcessorType;
|
import tech.powerjob.common.enums.ProcessorType;
|
||||||
import tech.powerjob.common.enums.TimeExpressionType;
|
import tech.powerjob.common.enums.TimeExpressionType;
|
||||||
@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for {@link OhMyClient} workflow.
|
* Test cases for {@link PowerJobClient} workflow.
|
||||||
*
|
*
|
||||||
* @author tjq
|
* @author tjq
|
||||||
* @author Echo009
|
* @author Echo009
|
||||||
@ -43,7 +43,7 @@ class TestWorkflow extends ClientInitializer {
|
|||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
SaveJobInfoRequest request = JSONObject.parseObject(JSONObject.toJSONBytes(base), SaveJobInfoRequest.class);
|
SaveJobInfoRequest request = JSONObject.parseObject(JSONObject.toJSONBytes(base), SaveJobInfoRequest.class);
|
||||||
request.setJobName(request.getJobName() + i);
|
request.setJobName(request.getJobName() + i);
|
||||||
ResultDTO<Long> res = ohMyClient.saveJob(request);
|
ResultDTO<Long> res = powerJobClient.saveJob(request);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ class TestWorkflow extends ClientInitializer {
|
|||||||
req.setTimeExpressionType(TimeExpressionType.API);
|
req.setTimeExpressionType(TimeExpressionType.API);
|
||||||
|
|
||||||
System.out.println("req ->" + JSONObject.toJSON(req));
|
System.out.println("req ->" + JSONObject.toJSON(req));
|
||||||
ResultDTO<Long> res = ohMyClient.saveWorkflow(req);
|
ResultDTO<Long> res = powerJobClient.saveWorkflow(req);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ class TestWorkflow extends ClientInitializer {
|
|||||||
saveWorkflowNodeRequest3.setType(WorkflowNodeType.JOB);
|
saveWorkflowNodeRequest3.setType(WorkflowNodeType.JOB);
|
||||||
|
|
||||||
|
|
||||||
List<WorkflowNodeInfoDTO> nodeList = ohMyClient.saveWorkflowNode(Lists.newArrayList(saveWorkflowNodeRequest1,saveWorkflowNodeRequest2,saveWorkflowNodeRequest3)).getData();
|
List<WorkflowNodeInfoDTO> nodeList = powerJobClient.saveWorkflowNode(Lists.newArrayList(saveWorkflowNodeRequest1,saveWorkflowNodeRequest2,saveWorkflowNodeRequest3)).getData();
|
||||||
System.out.println(nodeList);
|
System.out.println(nodeList);
|
||||||
Assertions.assertNotNull(nodeList);
|
Assertions.assertNotNull(nodeList);
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ class TestWorkflow extends ClientInitializer {
|
|||||||
|
|
||||||
// 保存完整信息
|
// 保存完整信息
|
||||||
req.setDag(peWorkflowDAG);
|
req.setDag(peWorkflowDAG);
|
||||||
res = ohMyClient.saveWorkflow(req);
|
res = powerJobClient.saveWorkflow(req);
|
||||||
|
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
@ -113,7 +113,7 @@ class TestWorkflow extends ClientInitializer {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCopyWorkflow() {
|
void testCopyWorkflow() {
|
||||||
ResultDTO<Long> res = ohMyClient.copyWorkflow(WF_ID);
|
ResultDTO<Long> res = powerJobClient.copyWorkflow(WF_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
@ -121,70 +121,70 @@ class TestWorkflow extends ClientInitializer {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDisableWorkflow() {
|
void testDisableWorkflow() {
|
||||||
ResultDTO<Void> res = ohMyClient.disableWorkflow(WF_ID);
|
ResultDTO<Void> res = powerJobClient.disableWorkflow(WF_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDeleteWorkflow() {
|
void testDeleteWorkflow() {
|
||||||
ResultDTO<Void> res = ohMyClient.deleteWorkflow(WF_ID);
|
ResultDTO<Void> res = powerJobClient.deleteWorkflow(WF_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testEnableWorkflow() {
|
void testEnableWorkflow() {
|
||||||
ResultDTO<Void> res = ohMyClient.enableWorkflow(WF_ID);
|
ResultDTO<Void> res = powerJobClient.enableWorkflow(WF_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFetchWorkflowInfo() {
|
void testFetchWorkflowInfo() {
|
||||||
ResultDTO<WorkflowInfoDTO> res = ohMyClient.fetchWorkflow(WF_ID);
|
ResultDTO<WorkflowInfoDTO> res = powerJobClient.fetchWorkflow(WF_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRunWorkflow() {
|
void testRunWorkflow() {
|
||||||
ResultDTO<Long> res = ohMyClient.runWorkflow(WF_ID);
|
ResultDTO<Long> res = powerJobClient.runWorkflow(WF_ID);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testStopWorkflowInstance() {
|
void testStopWorkflowInstance() {
|
||||||
ResultDTO<Void> res = ohMyClient.stopWorkflowInstance(149962433421639744L);
|
ResultDTO<Void> res = powerJobClient.stopWorkflowInstance(149962433421639744L);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRetryWorkflowInstance() {
|
void testRetryWorkflowInstance() {
|
||||||
ResultDTO<Void> res = ohMyClient.retryWorkflowInstance(149962433421639744L);
|
ResultDTO<Void> res = powerJobClient.retryWorkflowInstance(149962433421639744L);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMarkWorkflowNodeAsSuccess() {
|
void testMarkWorkflowNodeAsSuccess() {
|
||||||
ResultDTO<Void> res = ohMyClient.markWorkflowNodeAsSuccess(149962433421639744L, 1L);
|
ResultDTO<Void> res = powerJobClient.markWorkflowNodeAsSuccess(149962433421639744L, 1L);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFetchWfInstanceInfo() {
|
void testFetchWfInstanceInfo() {
|
||||||
ResultDTO<WorkflowInstanceInfoDTO> res = ohMyClient.fetchWorkflowInstanceInfo(149962433421639744L);
|
ResultDTO<WorkflowInstanceInfoDTO> res = powerJobClient.fetchWorkflowInstanceInfo(149962433421639744L);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRunWorkflowPlus() {
|
void testRunWorkflowPlus() {
|
||||||
ResultDTO<Long> res = ohMyClient.runWorkflow(WF_ID, "this is init Params 2", 90000);
|
ResultDTO<Long> res = powerJobClient.runWorkflow(WF_ID, "this is init Params 2", 90000);
|
||||||
System.out.println(res);
|
System.out.println(res);
|
||||||
Assertions.assertNotNull(res);
|
Assertions.assertNotNull(res);
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,6 @@ public class DispatchService {
|
|||||||
private InstanceMetadataService instanceMetadataService;
|
private InstanceMetadataService instanceMetadataService;
|
||||||
@Resource
|
@Resource
|
||||||
private InstanceInfoRepository instanceInfoRepository;
|
private InstanceInfoRepository instanceInfoRepository;
|
||||||
@Resource
|
|
||||||
private DispatchService self;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重新派发任务实例(不考虑实例当前的状态)
|
* 重新派发任务实例(不考虑实例当前的状态)
|
||||||
@ -60,14 +58,14 @@ public class DispatchService {
|
|||||||
* @param jobInfo 任务信息(注意,这里传入的任务信息有可能为“空”)
|
* @param jobInfo 任务信息(注意,这里传入的任务信息有可能为“空”)
|
||||||
* @param instanceId 实例ID
|
* @param instanceId 实例ID
|
||||||
*/
|
*/
|
||||||
|
@UseSegmentLock(type = "redispatch", key = "#jobInfo.getId() ?: 0", concurrencyLevel = 16)
|
||||||
public void redispatch(JobInfoDO jobInfo, long instanceId) {
|
public void redispatch(JobInfoDO jobInfo, long instanceId) {
|
||||||
InstanceInfoDO instance = instanceInfoRepository.findByInstanceId(instanceId);
|
InstanceInfoDO instance = instanceInfoRepository.findByInstanceId(instanceId);
|
||||||
// 将状态重置为等待派发
|
// 将状态重置为等待派发
|
||||||
instance.setStatus(InstanceStatus.WAITING_DISPATCH.getV());
|
instance.setStatus(InstanceStatus.WAITING_DISPATCH.getV());
|
||||||
instance.setGmtModified(new Date());
|
instance.setGmtModified(new Date());
|
||||||
instanceInfoRepository.saveAndFlush(instance);
|
instanceInfoRepository.saveAndFlush(instance);
|
||||||
// support for aop
|
dispatch(jobInfo, instanceId);
|
||||||
self.dispatch(jobInfo, instanceId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import tech.powerjob.common.PowerJobException;
|
import tech.powerjob.common.PowerJobException;
|
||||||
import tech.powerjob.common.enums.TimeExpressionType;
|
import tech.powerjob.common.enums.TimeExpressionType;
|
||||||
|
import tech.powerjob.common.enums.WorkflowNodeType;
|
||||||
import tech.powerjob.common.model.PEWorkflowDAG;
|
import tech.powerjob.common.model.PEWorkflowDAG;
|
||||||
import tech.powerjob.common.request.http.SaveWorkflowNodeRequest;
|
import tech.powerjob.common.request.http.SaveWorkflowNodeRequest;
|
||||||
import tech.powerjob.common.request.http.SaveWorkflowRequest;
|
import tech.powerjob.common.request.http.SaveWorkflowRequest;
|
||||||
@ -134,7 +135,7 @@ public class WorkflowService {
|
|||||||
}
|
}
|
||||||
dag.setNodes(newNodes);
|
dag.setNodes(newNodes);
|
||||||
int deleteCount = workflowNodeInfoRepository.deleteByWorkflowIdAndIdNotIn(wfId, nodeIdList);
|
int deleteCount = workflowNodeInfoRepository.deleteByWorkflowIdAndIdNotIn(wfId, nodeIdList);
|
||||||
log.warn("[WorkflowService-{}]delete {} dissociative nodes of workflow", wfId, deleteCount);
|
log.warn("[WorkflowService-{}] delete {} dissociative nodes of workflow", wfId, deleteCount);
|
||||||
return JSON.toJSONString(dag);
|
return JSON.toJSONString(dag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +283,6 @@ public class WorkflowService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存工作流节点(新增 或者 保存)
|
* 保存工作流节点(新增 或者 保存)
|
||||||
* 允许工作流 ID 为空
|
|
||||||
*
|
*
|
||||||
* @param workflowNodeRequestList 工作流节点
|
* @param workflowNodeRequestList 工作流节点
|
||||||
* @return 更新 或者 创建后的工作流节点信息
|
* @return 更新 或者 创建后的工作流节点信息
|
||||||
@ -307,16 +307,20 @@ public class WorkflowService {
|
|||||||
workflowNodeInfo = new WorkflowNodeInfoDO();
|
workflowNodeInfo = new WorkflowNodeInfoDO();
|
||||||
workflowNodeInfo.setGmtCreate(new Date());
|
workflowNodeInfo.setGmtCreate(new Date());
|
||||||
}
|
}
|
||||||
JobInfoDO jobInfoDO = jobInfoRepository.findById(req.getJobId()).orElseThrow(() -> new IllegalArgumentException("can't find job by id: " + req.getJobId()));
|
|
||||||
if (!jobInfoDO.getAppId().equals(appId)) {
|
// valid job info
|
||||||
throw new PowerJobException("Permission Denied! can't use other app's job!");
|
if (req.getType() == WorkflowNodeType.JOB) {
|
||||||
|
JobInfoDO jobInfoDO = jobInfoRepository.findById(req.getJobId()).orElseThrow(() -> new IllegalArgumentException("can't find job by id: " + req.getJobId()));
|
||||||
|
if (!jobInfoDO.getAppId().equals(appId)) {
|
||||||
|
throw new PowerJobException("Permission Denied! can't use other app's job!");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(workflowNodeInfo.getNodeName())) {
|
||||||
|
workflowNodeInfo.setNodeName(jobInfoDO.getJobName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BeanUtils.copyProperties(req, workflowNodeInfo);
|
BeanUtils.copyProperties(req, workflowNodeInfo);
|
||||||
workflowNodeInfo.setType(req.getType().getCode());
|
workflowNodeInfo.setType(req.getType().getCode());
|
||||||
// 如果名称为空则默认取任务名称
|
|
||||||
if (StringUtils.isEmpty(workflowNodeInfo.getNodeName())) {
|
|
||||||
workflowNodeInfo.setNodeName(jobInfoDO.getJobName());
|
|
||||||
}
|
|
||||||
workflowNodeInfo.setGmtModified(new Date());
|
workflowNodeInfo.setGmtModified(new Date());
|
||||||
workflowNodeInfo = workflowNodeInfoRepository.saveAndFlush(workflowNodeInfo);
|
workflowNodeInfo = workflowNodeInfoRepository.saveAndFlush(workflowNodeInfo);
|
||||||
res.add(workflowNodeInfo);
|
res.add(workflowNodeInfo);
|
||||||
|
@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class V3ToV4MigrateService {
|
public class V3ToV4MigrateService {
|
||||||
|
|
||||||
private static final String MIGRATE_LOCK_TEMPLATE = "migrateLock-%s-%s";
|
private static final String MIGRATE_LOCK_TEMPLATE = "v3to4MigrateLock-%s-%s";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private LockService lockService;
|
private LockService lockService;
|
||||||
@ -252,6 +252,4 @@ public class V3ToV4MigrateService {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user