mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
test: add openclient debug log to find problem ##970
This commit is contained in:
parent
c7a71380f2
commit
cbeabd20c9
@ -2,6 +2,7 @@ package tech.powerjob.client.service;
|
|||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
import tech.powerjob.common.enums.MIME;
|
import tech.powerjob.common.enums.MIME;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -13,6 +14,7 @@ import java.util.Map;
|
|||||||
* @since 2024/8/10
|
* @since 2024/8/10
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
|
@ToString
|
||||||
public class PowerRequestBody {
|
public class PowerRequestBody {
|
||||||
|
|
||||||
private MIME mime;
|
private MIME mime;
|
||||||
|
@ -4,12 +4,14 @@ import com.google.common.collect.Maps;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
import tech.powerjob.client.ClientConfig;
|
import tech.powerjob.client.ClientConfig;
|
||||||
import tech.powerjob.client.common.Protocol;
|
import tech.powerjob.client.common.Protocol;
|
||||||
import tech.powerjob.client.service.HttpResponse;
|
import tech.powerjob.client.service.HttpResponse;
|
||||||
import tech.powerjob.client.service.PowerRequestBody;
|
import tech.powerjob.client.service.PowerRequestBody;
|
||||||
import tech.powerjob.common.OmsConstant;
|
import tech.powerjob.common.OmsConstant;
|
||||||
import tech.powerjob.common.serialize.JsonUtils;
|
import tech.powerjob.common.serialize.JsonUtils;
|
||||||
|
import tech.powerjob.common.utils.DebugUtils;
|
||||||
|
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -45,6 +47,11 @@ public class ClusterRequestServiceOkHttp3Impl extends AppAuthClusterRequestServi
|
|||||||
@Override
|
@Override
|
||||||
protected HttpResponse sendHttpRequest(String url, PowerRequestBody powerRequestBody) throws IOException {
|
protected HttpResponse sendHttpRequest(String url, PowerRequestBody powerRequestBody) throws IOException {
|
||||||
|
|
||||||
|
boolean debugMode = DebugUtils.inDebugMode();
|
||||||
|
if (debugMode) {
|
||||||
|
log.info("[ClusterRequestService] try to sendHttpRequest, url: {}, powerRequestBody: {}", url, powerRequestBody);
|
||||||
|
}
|
||||||
|
|
||||||
// 添加公共 header
|
// 添加公共 header
|
||||||
powerRequestBody.addHeaders(config.getDefaultHeaders());
|
powerRequestBody.addHeaders(config.getDefaultHeaders());
|
||||||
|
|
||||||
@ -91,7 +98,19 @@ public class ClusterRequestServiceOkHttp3Impl extends AppAuthClusterRequestServi
|
|||||||
|
|
||||||
httpResponse.setHeaders(respHeaderMap);
|
httpResponse.setHeaders(respHeaderMap);
|
||||||
|
|
||||||
|
if (debugMode) {
|
||||||
|
log.info("[ClusterRequestService] originHttpResponse: {}, convertedResponse: {}", response, httpResponse);
|
||||||
|
}
|
||||||
|
|
||||||
return httpResponse;
|
return httpResponse;
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
if (debugMode) {
|
||||||
|
log.warn("[ClusterRequestService] request[{}] failed!", url, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExceptionUtils.rethrow(e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
|||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import tech.powerjob.client.IPowerJobClient;
|
import tech.powerjob.client.IPowerJobClient;
|
||||||
import tech.powerjob.client.PowerJobClient;
|
import tech.powerjob.client.PowerJobClient;
|
||||||
|
import tech.powerjob.common.PowerJobDKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize OhMyClient
|
* Initialize OhMyClient
|
||||||
@ -17,6 +18,7 @@ public class ClientInitializer {
|
|||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void initClient() throws Exception {
|
public static void initClient() throws Exception {
|
||||||
|
System.setProperty(PowerJobDKey.DEBUG_LEVEL, "INFO");
|
||||||
powerJobClient = new PowerJobClient(Lists.newArrayList("127.0.0.1:7700", "127.0.0.1:7701"), "powerjob-worker-samples", "powerjob123");
|
powerJobClient = new PowerJobClient(Lists.newArrayList("127.0.0.1:7700", "127.0.0.1:7701"), "powerjob-worker-samples", "powerjob123");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package tech.powerjob.client.test;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import tech.powerjob.client.test.utils.TestUtils;
|
||||||
|
import tech.powerjob.common.request.http.SaveJobInfoRequest;
|
||||||
|
import tech.powerjob.common.response.ResultDTO;
|
||||||
|
import tech.powerjob.common.utils.CommonUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TestAnything
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2024/8/19
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class TestAnything extends ClientInitializer {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMultiClientRequest() {
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
log.info("START ================== {} ================== START", i);
|
||||||
|
|
||||||
|
SaveJobInfoRequest saveJobInfoRequest = TestUtils.newSaveJobRequest(null, "TEST-JOB-" + i + "-" + System.currentTimeMillis());
|
||||||
|
ResultDTO<Long> saveJobResult = powerJobClient.saveJob(saveJobInfoRequest);
|
||||||
|
log.info("[testMultiClientRequest] saveJobResult: {}", JSONObject.toJSONString(saveJobResult));
|
||||||
|
|
||||||
|
log.info("END ================== {} ================== END", i);
|
||||||
|
|
||||||
|
CommonUtils.easySleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,9 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import tech.powerjob.client.PowerJobClient;
|
import tech.powerjob.client.PowerJobClient;
|
||||||
import tech.powerjob.common.enums.ExecuteType;
|
import tech.powerjob.client.test.utils.TestUtils;
|
||||||
import tech.powerjob.common.enums.ProcessorType;
|
|
||||||
import tech.powerjob.common.enums.TimeExpressionType;
|
|
||||||
import tech.powerjob.common.request.http.SaveJobInfoRequest;
|
import tech.powerjob.common.request.http.SaveJobInfoRequest;
|
||||||
import tech.powerjob.common.response.InstanceInfoDTO;
|
import tech.powerjob.common.response.InstanceInfoDTO;
|
||||||
import tech.powerjob.common.response.JobInfoDTO;
|
import tech.powerjob.common.response.JobInfoDTO;
|
||||||
@ -27,26 +25,8 @@ class TestClient extends ClientInitializer {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSaveJob() {
|
void testSaveJob() {
|
||||||
|
SaveJobInfoRequest saveJobInfoRequest = TestUtils.newSaveJobRequest(JOB_ID, null);
|
||||||
SaveJobInfoRequest newJobInfo = new SaveJobInfoRequest();
|
ResultDTO<Long> resultDTO = powerJobClient.saveJob(saveJobInfoRequest);
|
||||||
newJobInfo.setId(JOB_ID);
|
|
||||||
newJobInfo.setJobName("omsOpenAPIJobccccc" + System.currentTimeMillis());
|
|
||||||
newJobInfo.setJobDescription("test OpenAPI" + System.currentTimeMillis());
|
|
||||||
newJobInfo.setJobParams("{'aa':'bb'}");
|
|
||||||
newJobInfo.setTimeExpressionType(TimeExpressionType.CRON);
|
|
||||||
newJobInfo.setTimeExpression("0 0 * * * ? ");
|
|
||||||
newJobInfo.setExecuteType(ExecuteType.STANDALONE);
|
|
||||||
newJobInfo.setProcessorType(ProcessorType.BUILT_IN);
|
|
||||||
newJobInfo.setProcessorInfo("tech.powerjob.samples.processors.StandaloneProcessorDemo");
|
|
||||||
newJobInfo.setDesignatedWorkers("");
|
|
||||||
|
|
||||||
newJobInfo.setMinCpuCores(1.1);
|
|
||||||
newJobInfo.setMinMemorySpace(1.2);
|
|
||||||
newJobInfo.setMinDiskSpace(1.3);
|
|
||||||
|
|
||||||
log.info("[TestClient] [testSaveJob] SaveJobInfoRequest: {}", JSONObject.toJSONString(newJobInfo));
|
|
||||||
|
|
||||||
ResultDTO<Long> resultDTO = powerJobClient.saveJob(newJobInfo);
|
|
||||||
log.info("[TestClient] [testSaveJob] result: {}", JSONObject.toJSONString(resultDTO));
|
log.info("[TestClient] [testSaveJob] result: {}", JSONObject.toJSONString(resultDTO));
|
||||||
Assertions.assertNotNull(resultDTO);
|
Assertions.assertNotNull(resultDTO);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package tech.powerjob.client.test.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import tech.powerjob.common.enums.ExecuteType;
|
||||||
|
import tech.powerjob.common.enums.ProcessorType;
|
||||||
|
import tech.powerjob.common.enums.TimeExpressionType;
|
||||||
|
import tech.powerjob.common.request.http.SaveJobInfoRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TestUtils
|
||||||
|
*
|
||||||
|
* @author tjq
|
||||||
|
* @since 2024/8/19
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class TestUtils {
|
||||||
|
|
||||||
|
public static SaveJobInfoRequest newSaveJobRequest(Long jobId, String jobName) {
|
||||||
|
SaveJobInfoRequest newJobInfo = new SaveJobInfoRequest();
|
||||||
|
newJobInfo.setId(jobId);
|
||||||
|
String jobNameF = StringUtils.isEmpty(jobName) ? "OpenApiJob-" + System.currentTimeMillis() : jobName;
|
||||||
|
newJobInfo.setJobName(jobNameF);
|
||||||
|
newJobInfo.setJobDescription("test OpenAPI" + System.currentTimeMillis());
|
||||||
|
newJobInfo.setJobParams("{'aa':'bb'}");
|
||||||
|
newJobInfo.setTimeExpressionType(TimeExpressionType.CRON);
|
||||||
|
newJobInfo.setTimeExpression("0 0 * * * ? ");
|
||||||
|
newJobInfo.setExecuteType(ExecuteType.STANDALONE);
|
||||||
|
newJobInfo.setProcessorType(ProcessorType.BUILT_IN);
|
||||||
|
newJobInfo.setProcessorInfo("tech.powerjob.samples.processors.StandaloneProcessorDemo");
|
||||||
|
newJobInfo.setDesignatedWorkers("");
|
||||||
|
|
||||||
|
newJobInfo.setMinCpuCores(1.1);
|
||||||
|
newJobInfo.setMinMemorySpace(1.2);
|
||||||
|
newJobInfo.setMinDiskSpace(1.3);
|
||||||
|
|
||||||
|
log.info("[TestClient] [testSaveJob] SaveJobInfoRequest: {}", JSONObject.toJSONString(newJobInfo));
|
||||||
|
|
||||||
|
return newJobInfo;
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import tech.powerjob.common.enums.ErrorCodes;
|
|||||||
import tech.powerjob.server.auth.common.PowerJobAuthException;
|
import tech.powerjob.server.auth.common.PowerJobAuthException;
|
||||||
import tech.powerjob.server.auth.common.utils.HttpServletUtils;
|
import tech.powerjob.server.auth.common.utils.HttpServletUtils;
|
||||||
import tech.powerjob.server.auth.jwt.JwtService;
|
import tech.powerjob.server.auth.jwt.JwtService;
|
||||||
|
import tech.powerjob.server.auth.jwt.ParseResult;
|
||||||
import tech.powerjob.server.auth.login.*;
|
import tech.powerjob.server.auth.login.*;
|
||||||
import tech.powerjob.server.auth.service.login.LoginRequest;
|
import tech.powerjob.server.auth.service.login.LoginRequest;
|
||||||
import tech.powerjob.server.auth.service.login.PowerJobLoginService;
|
import tech.powerjob.server.auth.service.login.PowerJobLoginService;
|
||||||
@ -236,7 +237,11 @@ public class PowerJobLoginServiceImpl implements PowerJobLoginService {
|
|||||||
if (StringUtils.isEmpty(jwtStr)) {
|
if (StringUtils.isEmpty(jwtStr)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
final Map<String, Object> jwtBodyMap = jwtService.parse(jwtStr, null).getResult();
|
ParseResult parseResult = jwtService.parse(jwtStr, null);
|
||||||
|
if (ParseResult.Status.EXPIRED.equals(parseResult.getStatus())) {
|
||||||
|
throw new PowerJobAuthException(ErrorCodes.USER_NOT_LOGIN, "LoginExpired");
|
||||||
|
}
|
||||||
|
final Map<String, Object> jwtBodyMap = parseResult.getResult();
|
||||||
|
|
||||||
if (MapUtils.isEmpty(jwtBodyMap)) {
|
if (MapUtils.isEmpty(jwtBodyMap)) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
@ -27,6 +27,7 @@ import tech.powerjob.server.persistence.remote.model.WorkflowInfoDO;
|
|||||||
import tech.powerjob.server.persistence.remote.model.WorkflowNodeInfoDO;
|
import tech.powerjob.server.persistence.remote.model.WorkflowNodeInfoDO;
|
||||||
import tech.powerjob.server.web.response.WorkflowInfoVO;
|
import tech.powerjob.server.web.response.WorkflowInfoVO;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,9 +68,12 @@ public class OpenAPIController {
|
|||||||
* @return 鉴权响应
|
* @return 鉴权响应
|
||||||
*/
|
*/
|
||||||
@PostMapping(OpenAPIConstant.AUTH_APP)
|
@PostMapping(OpenAPIConstant.AUTH_APP)
|
||||||
public PowerResultDTO<AppAuthResult> auth(@RequestBody AppAuthRequest appAuthRequest) {
|
public PowerResultDTO<AppAuthResult> auth(@RequestBody AppAuthRequest appAuthRequest, HttpServletResponse response) {
|
||||||
try {
|
try {
|
||||||
return PowerResultDTO.s(openApiSecurityService.authAppByParam(appAuthRequest));
|
AppAuthResult appAuthResult = openApiSecurityService.authAppByParam(appAuthRequest);
|
||||||
|
// 能顺利返回代表通过了鉴权
|
||||||
|
response.addHeader(OpenAPIConstant.RESPONSE_HEADER_AUTH_STATUS, Boolean.TRUE.toString());
|
||||||
|
return PowerResultDTO.s(appAuthResult);
|
||||||
} catch (PowerJobException pje) {
|
} catch (PowerJobException pje) {
|
||||||
PowerResultDTO<AppAuthResult> f = PowerResultDTO.f(pje.getMessage());
|
PowerResultDTO<AppAuthResult> f = PowerResultDTO.f(pje.getMessage());
|
||||||
f.setCode(pje.getCode());
|
f.setCode(pje.getCode());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user