Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58e542c

Browse files
committed
Merge branch '4.3.4'
2 parents 00228f3 + 15fa1ab commit 58e542c

File tree

90 files changed

+2202
-498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2202
-498
lines changed

SECURITY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Security notices relating to PowerJob
2+
3+
Please disclose any security issues or vulnerabilities found through [Tidelift's coordinated disclosure system](https://tidelift.com/security) or to the maintainers privately([email protected]).
4+

others/dev/publish_docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ if [ "$startup" = "y" ] || [ "$startup" = "Y" ]; then
9090
echo "================== 准备启动 powerjob-server =================="
9191
docker run -d \
9292
--name powerjob-server \
93-
-p 7700:7700 -p 10086:10086 -p 5001:5005 -p 10001:10000 \
93+
-p 7700:7700 -p 10086:10086 -p 10010:10010 -p 5001:5005 -p 10001:10000 \
9494
-e JVMOPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10000 -Dcom.sun.management.jmxremote.rmi.port=10000 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" \
9595
-e PARAMS="--spring.profiles.active=pre" \
9696
-e TZ="Asia/Shanghai" \

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>tech.powerjob</groupId>
88
<artifactId>powerjob</artifactId>
9-
<version>4.3.3</version>
9+
<version>4.3.4</version>
1010
<packaging>pom</packaging>
1111
<name>powerjob</name>
1212
<url>http://www.powerjob.tech</url>

powerjob-client/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
<parent>
66
<artifactId>powerjob</artifactId>
77
<groupId>tech.powerjob</groupId>
8-
<version>4.3.3</version>
8+
<version>4.3.4</version>
99
</parent>
1010

1111
<modelVersion>4.0.0</modelVersion>
1212
<artifactId>powerjob-client</artifactId>
13-
<version>4.3.3</version>
13+
<version>4.3.4</version>
1414
<packaging>jar</packaging>
1515

1616
<properties>
1717
<junit.version>5.9.1</junit.version>
1818
<fastjson.version>1.2.83</fastjson.version>
19-
<powerjob.common.version>4.3.3</powerjob.common.version>
19+
<powerjob.common.version>4.3.4</powerjob.common.version>
2020

2121
<mvn.shade.plugin.version>3.2.4</mvn.shade.plugin.version>
2222
</properties>

powerjob-common/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<artifactId>powerjob</artifactId>
77
<groupId>tech.powerjob</groupId>
8-
<version>4.3.3</version>
8+
<version>4.3.4</version>
99
</parent>
1010

1111
<modelVersion>4.0.0</modelVersion>
1212
<artifactId>powerjob-common</artifactId>
13-
<version>4.3.3</version>
13+
<version>4.3.4</version>
1414
<packaging>jar</packaging>
1515

1616
<properties>

powerjob-common/src/main/java/tech/powerjob/common/PowerJobDKey.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/**
66
* 通过 JVM 启动参数传入的配置信息
77
*
8-
*
98
* @author tjq
109
* @since 2020/8/8
1110
*/
@@ -16,7 +15,15 @@ public class PowerJobDKey {
1615
*/
1716
public static final String PREFERRED_NETWORK_INTERFACE = "powerjob.network.interface.preferred";
1817

18+
/**
19+
* 绑定地址,一般填写本机网卡地址
20+
*/
1921
public static final String BIND_LOCAL_ADDRESS = "powerjob.network.local.address";
22+
/**
23+
* 外部地址,可选,默认与绑定地址相同。当存在 NAT 等场景时可通过单独传递外部地址来实现通讯
24+
*/
25+
public static final String NT_EXTERNAL_ADDRESS = "powerjob.network.external.address";
26+
public static final String NT_EXTERNAL_PORT = "powerjob.network.external.port";
2027

2128
/**
2229
* Java regular expressions for network interfaces that will be ignored.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package tech.powerjob.common.exception;
2+
3+
/**
4+
* ImpossibleException
5+
*
6+
* @author tjq
7+
* @since 2023/7/12
8+
*/
9+
public class ImpossibleException extends RuntimeException {
10+
}

powerjob-common/src/main/java/tech/powerjob/common/serialize/JsonUtils.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
import lombok.extern.slf4j.Slf4j;
99
import org.apache.commons.lang3.StringUtils;
1010
import org.apache.commons.lang3.exception.ExceptionUtils;
11+
import tech.powerjob.common.exception.ImpossibleException;
1112
import tech.powerjob.common.exception.PowerJobException;
1213

1314
import java.io.IOException;
15+
import java.util.HashMap;
16+
import java.util.Map;
1417

1518
/**
1619
* JSON工具类
@@ -27,6 +30,8 @@ public class JsonUtils {
2730
.configure(JsonParser.Feature.IGNORE_UNDEFINED, true)
2831
.build();
2932

33+
private static final TypeReference<Map<String, Object>> MAP_TYPE_REFERENCE = new TypeReference<Map<String, Object>> () {};
34+
3035
private JsonUtils(){
3136

3237
}
@@ -67,6 +72,18 @@ public static <T> T parseObject(String json, Class<T> clz) throws JsonProcessing
6772
return JSON_MAPPER.readValue(json, clz);
6873
}
6974

75+
public static Map<String, Object> parseMap(String json) {
76+
if (StringUtils.isEmpty(json)) {
77+
return new HashMap<>();
78+
}
79+
try {
80+
return JSON_MAPPER.readValue(json, MAP_TYPE_REFERENCE);
81+
} catch (Exception e) {
82+
ExceptionUtils.rethrow(e);
83+
}
84+
throw new ImpossibleException();
85+
}
86+
7087
public static <T> T parseObject(byte[] b, Class<T> clz) throws IOException {
7188
return JSON_MAPPER.readValue(b, clz);
7289
}

powerjob-common/src/main/java/tech/powerjob/common/utils/NetUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ public static int getRandomPort() {
5656
return ThreadLocalRandom.current().nextInt(RND_PORT_START, RND_PORT_END);
5757
}
5858

59+
/**
60+
* 检测某个 IP 端口是否可用
61+
* @param ip IP
62+
* @param port 端口
63+
* @return 是否可用
64+
*/
65+
public static boolean checkIpPortAvailable(String ip, int port) {
66+
try (Socket socket = new Socket()) {
67+
socket.connect(new InetSocketAddress(ip, port), 1000);
68+
return true;
69+
} catch (Exception e) {
70+
return false;
71+
}
72+
}
73+
5974
/**
6075
* 获取本机 IP 地址
6176
*
@@ -155,6 +170,9 @@ public static NetworkInterface findNetworkInterface() {
155170
log.warn("[Net] findNetworkInterface failed", e);
156171
}
157172

173+
// sort by interface index, the smaller is preferred.
174+
validNetworkInterfaces.sort(Comparator.comparingInt(NetworkInterface::getIndex));
175+
158176
// Try to find the preferred one
159177
for (NetworkInterface networkInterface : validNetworkInterfaces) {
160178
if (isPreferredNetworkInterface(networkInterface)) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package tech.powerjob.common.utils;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
5+
/**
6+
* PropertyUtils
7+
*
8+
* @author tjq
9+
* @since 2023/7/15
10+
*/
11+
public class PropertyUtils {
12+
13+
public static String readProperty(String key, String defaultValue) {
14+
// 从启动参数读取
15+
String property = System.getProperty(key);
16+
if (StringUtils.isNotEmpty(property)) {
17+
return property;
18+
}
19+
20+
// 从 ENV 读取
21+
property= System.getenv(key);
22+
if (StringUtils.isNotEmpty(property)) {
23+
return property;
24+
}
25+
// 部分操作系统不兼容 a.b.c 的环境变量,转换为 a_b_c 再取一次,即 PowerJob 支持 2 种类型的环境变量 key
26+
property = System.getenv(key.replaceAll("\\.", "_"));
27+
if (StringUtils.isNotEmpty(property)) {
28+
return property;
29+
}
30+
return defaultValue;
31+
}
32+
}

0 commit comments

Comments
 (0)