diff --git a/LICENSE b/LICENSE index a3f410aa6..d64569567 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,4 @@ + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -186,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright (c) 2017-2023 Ponfee + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/NOTICE b/NOTICE new file mode 100644 index 000000000..56db36c01 --- /dev/null +++ b/NOTICE @@ -0,0 +1,14 @@ +Disjob +Copyright 2022-2024 Ponfee (http://www.ponfee.cn/) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/disjob-common/src/main/java/cn/ponfee/disjob/common/util/Jsons.java b/disjob-common/src/main/java/cn/ponfee/disjob/common/util/Jsons.java index 82a365377..be076240a 100644 --- a/disjob-common/src/main/java/cn/ponfee/disjob/common/util/Jsons.java +++ b/disjob-common/src/main/java/cn/ponfee/disjob/common/util/Jsons.java @@ -76,10 +76,10 @@ public final class Jsons { /** * Jackson ObjectMapper(thread safe) */ - private final ObjectMapper mapper; + private final ObjectMapper objectMapper; private Jsons(JsonInclude.Include include) { - this.mapper = createObjectMapper(include); + this.objectMapper = createObjectMapper(include); } // --------------------------------------------------------serialization @@ -92,7 +92,7 @@ private Jsons(JsonInclude.Include include) { */ public void write(OutputStream output, Object target) { try { - mapper.writeValue(output, target); + objectMapper.writeValue(output, target); } catch (IOException e) { ExceptionUtils.rethrow(e); } @@ -106,7 +106,7 @@ public void write(OutputStream output, Object target) { */ public String string(Object target) { try { - return mapper.writeValueAsString(target); + return objectMapper.writeValueAsString(target); } catch (IOException e) { return ExceptionUtils.rethrow(e); } @@ -120,7 +120,7 @@ public String string(Object target) { */ public byte[] bytes(Object target) { try { - return mapper.writeValueAsBytes(target); + return objectMapper.writeValueAsBytes(target); } catch (IOException e) { return ExceptionUtils.rethrow(e); } @@ -143,7 +143,7 @@ public T parse(String json, JavaType javaType) { return null; } try { - return mapper.readValue(json, javaType); + return objectMapper.readValue(json, javaType); } catch (Exception e) { return ExceptionUtils.rethrow(e); } @@ -161,34 +161,34 @@ public T parse(byte[] json, JavaType javaType) { return null; } try { - return mapper.readValue(json, javaType); + return objectMapper.readValue(json, javaType); } catch (Exception e) { return ExceptionUtils.rethrow(e); } } public T parse(String json, Class target) { - return parse(json, mapper.constructType(target)); + return parse(json, objectMapper.constructType(target)); } public T parse(byte[] json, Class target) { - return parse(json, mapper.constructType(target)); + return parse(json, objectMapper.constructType(target)); } public T parse(String json, Type type) { - return parse(json, mapper.constructType(type)); + return parse(json, objectMapper.constructType(type)); } public T parse(byte[] json, Type type) { - return parse(json, mapper.constructType(type)); + return parse(json, objectMapper.constructType(type)); } public T parse(String json, TypeReference type) { - return parse(json, mapper.constructType(type)); + return parse(json, objectMapper.constructType(type)); } public T parse(byte[] json, TypeReference type) { - return parse(json, mapper.constructType(type)); + return parse(json, objectMapper.constructType(type)); } // ----------------------------------------------------static methods @@ -206,7 +206,7 @@ public static Object[] parseArray(String body, Class... types) { return null; } - ObjectMapper objectMapper = NORMAL.mapper; + ObjectMapper objectMapper = NORMAL.objectMapper; JsonNode rootNode = readTree(objectMapper, body); Assert.isTrue(rootNode.isArray(), "Not array json data."); ArrayNode arrayNode = (ArrayNode) rootNode; @@ -236,7 +236,7 @@ public static Object[] parseMethodArgs(String body, Method method) { return null; } - ObjectMapper objectMapper = NORMAL.mapper; + ObjectMapper objectMapper = NORMAL.objectMapper; JsonNode rootNode = readTree(objectMapper, body); if (rootNode.isArray()) { ArrayNode arrayNode = (ArrayNode) rootNode; @@ -394,20 +394,20 @@ public static void registerJavaTimeModule(ObjectMapper objectMapper) { // -----------------------------------------------------------------------private methods - private static JsonNode readTree(ObjectMapper mapper, String body) { + private static JsonNode readTree(ObjectMapper objectMapper, String body) { try { - return mapper.readTree(body); + return objectMapper.readTree(body); } catch (JsonProcessingException e) { return ExceptionUtils.rethrow(e); } } - private static Object parse(ObjectMapper mapper, JsonNode jsonNode, Type type) { + private static Object parse(ObjectMapper objectMapper, JsonNode jsonNode, Type type) { try { - return mapper - .readerFor(mapper.getTypeFactory().constructType(type)) + return objectMapper + .readerFor(objectMapper.getTypeFactory().constructType(type)) .with(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY) - .readValue(mapper.treeAsTokens(jsonNode)); + .readValue(objectMapper.treeAsTokens(jsonNode)); } catch (IOException e) { return ExceptionUtils.rethrow(e); } diff --git a/disjob-dispatch/disjob-dispatch-api/src/main/java/cn/ponfee/disjob/dispatch/DispatchTaskParam.java b/disjob-dispatch/disjob-dispatch-api/src/main/java/cn/ponfee/disjob/dispatch/DispatchTaskParam.java index 232ec58a8..b670e0967 100644 --- a/disjob-dispatch/disjob-dispatch-api/src/main/java/cn/ponfee/disjob/dispatch/DispatchTaskParam.java +++ b/disjob-dispatch/disjob-dispatch-api/src/main/java/cn/ponfee/disjob/dispatch/DispatchTaskParam.java @@ -46,7 +46,7 @@ public int retried() { public String toString() { return new StringJoiner(", ", DispatchTaskParam.class.getSimpleName() + "[", "]") .add("executeTaskParam=" + executeTaskParam) - .add(group == null ? "group=null" : "group='" + group + "'") + .add("group=" + (group != null ? "'" + group + "'" : "null")) .add("retried=" + retried) .toString(); } diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/ServerMetricsService.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/ServerMetricsService.java index e38077527..be01e659c 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/ServerMetricsService.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/ServerMetricsService.java @@ -138,7 +138,13 @@ private SupervisorMetricsResponse getMetrics(Supervisor supervisor) { LOG.warn("Ping supervisor occur error: {} {}", supervisor, e.getMessage()); } - SupervisorMetricsResponse response = (metrics == null) ? new SupervisorMetricsResponse() : ServerMetricsConverter.INSTANCE.convert(metrics); + SupervisorMetricsResponse response; + if (metrics == null) { + response = new SupervisorMetricsResponse(); + } else { + response = ServerMetricsConverter.INSTANCE.convert(metrics); + } + response.setHost(supervisor.getHost()); response.setPort(supervisor.getPort()); response.setPingTime(pingTime); @@ -159,15 +165,16 @@ private WorkerMetricsResponse getMetrics(Worker worker) { LOG.warn("Ping worker occur error: {} {}", worker, e.getMessage()); } - if (metrics != null && !SchedGroupService.verifyWorkerSignatureToken(metrics.getSignature(), group)) { - metrics = null; + WorkerMetricsResponse response; + if (metrics == null || !SchedGroupService.verifyWorkerSignatureToken(metrics.getSignature(), group)) { + response = new WorkerMetricsResponse(worker.getWorkerId()); + } else { + response = ServerMetricsConverter.INSTANCE.convert(metrics); } - WorkerMetricsResponse response = (metrics == null) ? new WorkerMetricsResponse() : ServerMetricsConverter.INSTANCE.convert(metrics); response.setHost(worker.getHost()); response.setPort(worker.getPort()); response.setPingTime(pingTime); - response.setWorkerId(metrics != null ? metrics.getWorkerId() : worker.getWorkerId()); return response; } diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/response/WorkerMetricsResponse.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/response/WorkerMetricsResponse.java index 51f0f3417..5d6050d74 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/response/WorkerMetricsResponse.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/application/response/WorkerMetricsResponse.java @@ -9,6 +9,7 @@ package cn.ponfee.disjob.supervisor.application.response; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; /** @@ -18,6 +19,7 @@ */ @Getter @Setter +@NoArgsConstructor public class WorkerMetricsResponse extends ServerMetricsResponse { private static final long serialVersionUID = -8325148543854446360L; @@ -34,4 +36,8 @@ public class WorkerMetricsResponse extends ServerMetricsResponse { private Long queueTaskCount; private Long completedTaskCount; + public WorkerMetricsResponse(String workerId) { + this.workerId = workerId; + } + }