mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[release] v3.3.3
This commit is contained in:
commit
63cc97024a
Binary file not shown.
Before Width: | Height: | Size: 562 KiB After Width: | Height: | Size: 618 KiB |
@ -10,13 +10,13 @@
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-client</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<version>3.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<junit.version>5.6.1</junit.version>
|
||||
<fastjson.version>1.2.68</fastjson.version>
|
||||
<powerjob.common.version>3.3.2</powerjob.common.version>
|
||||
<powerjob.common.version>3.3.3</powerjob.common.version>
|
||||
|
||||
<mvn.shade.plugin.version>3.2.4</mvn.shade.plugin.version>
|
||||
</properties>
|
||||
|
@ -2,6 +2,7 @@ package com.github.kfcfans.powerjob.client;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.kfcfans.powerjob.common.InstanceStatus;
|
||||
import com.github.kfcfans.powerjob.common.OmsConstant;
|
||||
import com.github.kfcfans.powerjob.common.OpenAPIConstant;
|
||||
import com.github.kfcfans.powerjob.common.PowerJobException;
|
||||
import com.github.kfcfans.powerjob.common.request.http.SaveJobInfoRequest;
|
||||
@ -55,7 +56,7 @@ public class OhMyClient {
|
||||
*/
|
||||
public OhMyClient(List<String> addressList, String appName, String password) {
|
||||
|
||||
CommonUtils.requireNonNull(addressList, "domain can't be null!");
|
||||
CommonUtils.requireNonNull(addressList, "addressList can't be null!");
|
||||
CommonUtils.requireNonNull(appName, "appName can't be null");
|
||||
|
||||
allAddress = addressList;
|
||||
@ -80,7 +81,7 @@ public class OhMyClient {
|
||||
if (StringUtils.isEmpty(currentAddress)) {
|
||||
throw new PowerJobException("no server available");
|
||||
}
|
||||
log.info("[OhMyClient] {}'s oms-client bootstrap successfully, using server: {}", appName, currentAddress);
|
||||
log.info("[OhMyClient] {}'s OhMyClient bootstrap successfully, using server: {}", appName, currentAddress);
|
||||
}
|
||||
|
||||
private static String assertApp(String appName, String password, String url) throws IOException {
|
||||
@ -283,7 +284,7 @@ public class OhMyClient {
|
||||
*/
|
||||
public ResultDTO<Long> saveWorkflow(SaveWorkflowRequest request) throws PowerJobException {
|
||||
request.setAppId(appId);
|
||||
MediaType jsonType = MediaType.parse("application/json; charset=utf-8");
|
||||
MediaType jsonType = MediaType.parse(OmsConstant.JSON_MEDIA_TYPE);
|
||||
// 中坑记录:用 FastJSON 序列化会导致 Server 接收时 pEWorkflowDAG 为 null,无语.jpg
|
||||
String json = JsonUtils.toJSONStringUnsafe(request);
|
||||
String post = postHA(OpenAPIConstant.SAVE_WORKFLOW, RequestBody.create(jsonType, json));
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-common</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<version>3.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
|
@ -15,4 +15,6 @@ public class OmsConstant {
|
||||
|
||||
public static final String COMMA = ",";
|
||||
public static final String LINE_SEPARATOR = "\r\n";
|
||||
|
||||
public static final String JSON_MEDIA_TYPE = "application/json; charset=utf-8";
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
package com.github.kfcfans.powerjob.common.utils;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import com.github.kfcfans.powerjob.common.PowerJobException;
|
||||
import okhttp3.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -32,12 +29,7 @@ public class HttpUtils {
|
||||
.get()
|
||||
.url(url)
|
||||
.build();
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (response.code() == HTTP_SUCCESS_CODE) {
|
||||
return Objects.requireNonNull(response.body()).string();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return execute(request);
|
||||
}
|
||||
|
||||
public static String post(String url, RequestBody requestBody) throws IOException {
|
||||
@ -45,12 +37,22 @@ public class HttpUtils {
|
||||
.post(requestBody)
|
||||
.url(url)
|
||||
.build();
|
||||
return execute(request);
|
||||
}
|
||||
|
||||
private static String execute(Request request) throws IOException {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
if (response.code() == HTTP_SUCCESS_CODE) {
|
||||
return Objects.requireNonNull(response.body()).string();
|
||||
int responseCode = response.code();
|
||||
if (responseCode == HTTP_SUCCESS_CODE) {
|
||||
ResponseBody body = response.body();
|
||||
if (body == null) {
|
||||
return null;
|
||||
}else {
|
||||
return body.string();
|
||||
}
|
||||
}
|
||||
throw new PowerJobException(String.format("http request failed,code=%d", responseCode));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
@ -34,6 +35,10 @@ import static java.util.Collections.emptyList;
|
||||
*/
|
||||
@Slf4j
|
||||
public class NetUtils {
|
||||
|
||||
// returned port range is [30000, 39999]
|
||||
private static final int RND_PORT_START = 30000;
|
||||
private static final int RND_PORT_END = 65535;
|
||||
|
||||
private static volatile String HOST_ADDRESS;
|
||||
private static final String LOCALHOST_VALUE = "127.0.0.1";
|
||||
@ -41,6 +46,10 @@ public class NetUtils {
|
||||
private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$");
|
||||
private static final String ANYHOST_VALUE = "0.0.0.0";
|
||||
|
||||
public static int getRandomPort() {
|
||||
return ThreadLocalRandom.current().nextInt(RND_PORT_START, RND_PORT_END);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本机 IP 地址
|
||||
* @return 本机 IP 地址
|
||||
|
@ -10,13 +10,13 @@
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-server</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<version>3.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<swagger.version>2.9.2</swagger.version>
|
||||
<springboot.version>2.3.4.RELEASE</springboot.version>
|
||||
<powerjob.common.version>3.3.2</powerjob.common.version>
|
||||
<powerjob.common.version>3.3.3</powerjob.common.version>
|
||||
<!-- 数据库驱动版本,使用的是spring-boot-dependencies管理的版本 -->
|
||||
<mysql.version>8.0.19</mysql.version>
|
||||
<ojdbc.version>19.7.0.0</ojdbc.version>
|
||||
|
@ -28,7 +28,7 @@ public class SwaggerConfig {
|
||||
.description("Distributed scheduling and computing framework.")
|
||||
.license("Apache Licence 2")
|
||||
.termsOfServiceUrl("https://github.com/KFCFans/PowerJob")
|
||||
.version("3.1.3")
|
||||
.version("3.3.3")
|
||||
.build();
|
||||
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
|
@ -159,7 +159,7 @@ public class HashedWheelTimer implements Timer {
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return startTime == FINISHED;
|
||||
return status == FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,10 +51,14 @@ public class DingTalkAlarmService implements Alarmable {
|
||||
}
|
||||
Set<String> userIds = Sets.newHashSet();
|
||||
targetUserList.forEach(user -> {
|
||||
String phone = user.getPhone();
|
||||
if (StringUtils.isEmpty(phone)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String userId = mobile2UserIdCache.get(user.getPhone(), () -> {
|
||||
String userId = mobile2UserIdCache.get(phone, () -> {
|
||||
try {
|
||||
return dingTalkUtils.fetchUserIdByMobile(user.getPhone());
|
||||
return dingTalkUtils.fetchUserIdByMobile(phone);
|
||||
} catch (PowerJobException ignore) {
|
||||
return EMPTY_TAG;
|
||||
} catch (Exception ignore) {
|
||||
|
@ -14,6 +14,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 邮件通知服务
|
||||
@ -43,13 +44,13 @@ public class MailAlarmService implements Alarmable {
|
||||
SimpleMailMessage sm = new SimpleMailMessage();
|
||||
try {
|
||||
sm.setFrom(from);
|
||||
sm.setTo(targetUserList.stream().map(UserInfoDO::getEmail).toArray(String[]::new));
|
||||
sm.setTo(targetUserList.stream().map(UserInfoDO::getEmail).filter(Objects::nonNull).toArray(String[]::new));
|
||||
sm.setSubject(alarm.fetchTitle());
|
||||
sm.setText(alarm.fetchContent());
|
||||
|
||||
javaMailSender.send(sm);
|
||||
}catch (Exception e) {
|
||||
log.error("[MailAlarmService] send mail failed, reason is {}", e.getMessage());
|
||||
log.warn("[MailAlarmService] send mail failed, reason is {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.github.kfcfans.powerjob.server.service.alarm.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.kfcfans.powerjob.common.OmsConstant;
|
||||
import com.github.kfcfans.powerjob.common.utils.HttpUtils;
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.model.UserInfoDO;
|
||||
import com.github.kfcfans.powerjob.server.service.alarm.Alarm;
|
||||
import com.github.kfcfans.powerjob.server.service.alarm.Alarmable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* http 回调报警
|
||||
*
|
||||
* @author tjq
|
||||
* @since 11/14/20
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WebHookAlarmService implements Alarmable {
|
||||
|
||||
private static final String HTTP_PROTOCOL_PREFIX = "http://";
|
||||
private static final String HTTPS_PROTOCOL_PREFIX = "https://";
|
||||
|
||||
@Override
|
||||
public void onFailed(Alarm alarm, List<UserInfoDO> targetUserList) {
|
||||
if (CollectionUtils.isEmpty(targetUserList)) {
|
||||
return;
|
||||
}
|
||||
targetUserList.forEach(user -> {
|
||||
String webHook = user.getWebHook();
|
||||
if (StringUtils.isEmpty(webHook)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 自动添加协议头
|
||||
if (!webHook.startsWith(HTTP_PROTOCOL_PREFIX) && !webHook.startsWith(HTTPS_PROTOCOL_PREFIX)) {
|
||||
webHook = HTTP_PROTOCOL_PREFIX + webHook;
|
||||
}
|
||||
|
||||
MediaType jsonType = MediaType.parse(OmsConstant.JSON_MEDIA_TYPE);
|
||||
RequestBody requestBody = RequestBody.create(jsonType, JSONObject.toJSONString(alarm));
|
||||
|
||||
try {
|
||||
String response = HttpUtils.post(webHook, requestBody);
|
||||
log.info("[WebHookAlarmService] invoke webhook[url={}] successfully, response is {}", webHook, response);
|
||||
}catch (Exception e) {
|
||||
log.warn("[WebHookAlarmService] invoke webhook[url={}] failed!", webHook, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import com.github.kfcfans.powerjob.server.service.lock.LockService;
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -20,6 +21,7 @@ import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -37,17 +39,25 @@ public class ServerSelectService {
|
||||
@Resource
|
||||
private AppInfoRepository appInfoRepository;
|
||||
|
||||
@Value("${oms.accurate.select.server.percentage}")
|
||||
private int accurateSelectServerPercentage;
|
||||
|
||||
private static final int RETRY_TIMES = 10;
|
||||
private static final long PING_TIMEOUT_MS = 1000;
|
||||
private static final String SERVER_ELECT_LOCK = "server_elect_%d";
|
||||
|
||||
/**
|
||||
* 获取某个应用对应的Server
|
||||
*
|
||||
* @param appId 应用ID
|
||||
* @return 当前可用的Server
|
||||
*/
|
||||
public String getServer(Long appId) {
|
||||
|
||||
public String getServer(Long appId, String currentServer) {
|
||||
if (!accurate()) {
|
||||
// 如果是本机,就不需要查数据库那么复杂的操作了,直接返回成功
|
||||
if (OhMyServer.getActorSystemAddress().equals(currentServer)) {
|
||||
return currentServer;
|
||||
}
|
||||
}
|
||||
return getServer0(appId);
|
||||
}
|
||||
|
||||
private String getServer0(Long appId) {
|
||||
|
||||
Set<String> downServerCache = Sets.newHashSet();
|
||||
|
||||
@ -95,7 +105,7 @@ public class ServerSelectService {
|
||||
lockService.unlock(lockName);
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("server elect failed for app " + appId);
|
||||
throw new PowerJobException("server elect failed for app " + appId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,6 +123,10 @@ public class ServerSelectService {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OhMyServer.getActorSystemAddress().equals(serverAddress)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Ping ping = new Ping();
|
||||
ping.setCurrentTime(System.currentTimeMillis());
|
||||
|
||||
@ -128,4 +142,8 @@ public class ServerSelectService {
|
||||
downServerCache.add(serverAddress);
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean accurate() {
|
||||
return ThreadLocalRandom.current().nextInt(100) < accurateSelectServerPercentage;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.kfcfans.powerjob.server.web.controller;
|
||||
|
||||
import com.github.kfcfans.powerjob.common.PowerJobException;
|
||||
import com.github.kfcfans.powerjob.common.response.ResultDTO;
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.model.AppInfoDO;
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.repository.AppInfoRepository;
|
||||
@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -50,6 +52,11 @@ public class AppInfoController {
|
||||
appInfoDO.setGmtCreate(new Date());
|
||||
}else {
|
||||
appInfoDO = appInfoRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("can't find appInfo by id:" + id));
|
||||
|
||||
// 对比密码
|
||||
if (!Objects.equals(req.getOldPassword(), appInfoDO.getPassword())) {
|
||||
throw new PowerJobException("The password is incorrect.");
|
||||
}
|
||||
}
|
||||
BeanUtils.copyProperties(req, appInfoDO);
|
||||
appInfoDO.setGmtModified(new Date());
|
||||
|
@ -17,6 +17,7 @@ import com.github.kfcfans.powerjob.server.service.instance.InstanceService;
|
||||
import com.github.kfcfans.powerjob.server.web.request.QueryInstanceRequest;
|
||||
import com.github.kfcfans.powerjob.server.web.response.InstanceDetailVO;
|
||||
import com.github.kfcfans.powerjob.server.web.response.InstanceInfoVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Example;
|
||||
@ -40,6 +41,7 @@ import java.util.stream.Collectors;
|
||||
* @author tjq
|
||||
* @since 2020/4/9
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/instance")
|
||||
public class InstanceController {
|
||||
@ -89,6 +91,7 @@ public class InstanceController {
|
||||
response.sendRedirect(url);
|
||||
return ResultDTO.success(StringPage.simple("redirecting..."));
|
||||
}catch (Exception e) {
|
||||
log.warn("[Instance-{}] redirect request to url[{}] failed, please ensure all server has the same http port!", instanceId, url, e);
|
||||
return ResultDTO.failed(e);
|
||||
}
|
||||
}
|
||||
|
@ -2,26 +2,20 @@ package com.github.kfcfans.powerjob.server.web.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.kfcfans.powerjob.common.PowerJobException;
|
||||
import com.github.kfcfans.powerjob.common.response.ResultDTO;
|
||||
import com.github.kfcfans.powerjob.common.utils.CommonUtils;
|
||||
import com.github.kfcfans.powerjob.common.utils.NetUtils;
|
||||
import com.github.kfcfans.powerjob.server.akka.OhMyServer;
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.model.AppInfoDO;
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.model.JobInfoDO;
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.repository.AppInfoRepository;
|
||||
import com.github.kfcfans.powerjob.server.persistence.core.repository.JobInfoRepository;
|
||||
import com.github.kfcfans.powerjob.server.service.ha.ClusterStatusHolder;
|
||||
import com.github.kfcfans.powerjob.server.service.ha.ServerSelectService;
|
||||
import com.github.kfcfans.powerjob.server.service.ha.WorkerManagerService;
|
||||
import com.taobao.api.internal.cluster.ClusterManager;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@ -40,8 +34,6 @@ public class ServerController {
|
||||
private ServerSelectService serverSelectService;
|
||||
@Resource
|
||||
private AppInfoRepository appInfoRepository;
|
||||
@Resource
|
||||
private JobInfoRepository jobInfoRepository;
|
||||
|
||||
@GetMapping("/assert")
|
||||
public ResultDTO<Long> assertAppName(String appName) {
|
||||
@ -52,13 +44,7 @@ public class ServerController {
|
||||
|
||||
@GetMapping("/acquire")
|
||||
public ResultDTO<String> acquireServer(Long appId, String currentServer) {
|
||||
|
||||
// 如果是本机,就不需要查数据库那么复杂的操作了,直接返回成功
|
||||
if (OhMyServer.getActorSystemAddress().equals(currentServer)) {
|
||||
return ResultDTO.success(currentServer);
|
||||
}
|
||||
String server = serverSelectService.getServer(appId);
|
||||
return ResultDTO.success(server);
|
||||
return ResultDTO.success(serverSelectService.getServer(appId, currentServer));
|
||||
}
|
||||
|
||||
@GetMapping("/hello")
|
||||
|
@ -15,6 +15,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
public class ModifyAppInfoRequest {
|
||||
|
||||
private Long id;
|
||||
private String oldPassword;
|
||||
private String appName;
|
||||
private String password;
|
||||
|
||||
|
@ -15,6 +15,7 @@ public class ModifyUserInfoRequest {
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
private String webHook;
|
||||
|
||||
// 手机号
|
||||
private String phone;
|
||||
|
@ -32,4 +32,7 @@ oms.container.retention.local=1
|
||||
oms.container.retention.remote=-1
|
||||
|
||||
####### 缓存配置 #######
|
||||
oms.instance.metadata.cache.size=1024
|
||||
oms.instance.metadata.cache.size=1024
|
||||
|
||||
####### 精确获取 server 的百分比,0~100,100代表每次 worker 获取 server 都会进行完整的探活流程,不存在脑裂问题,但有性能开销 #######
|
||||
oms.accurate.select.server.percentage = 50
|
@ -32,4 +32,7 @@ oms.container.retention.local=3
|
||||
oms.container.retention.remote=-1
|
||||
|
||||
####### 缓存配置 #######
|
||||
oms.instance.metadata.cache.size=1024
|
||||
oms.instance.metadata.cache.size=1024
|
||||
|
||||
####### 精确获取 server 的百分比,0~100,100代表每次 worker 获取 server 都会进行完整的探活流程,不存在脑裂问题,但有性能开销 #######
|
||||
oms.accurate.select.server.percentage = 50
|
@ -32,4 +32,7 @@ oms.container.retention.local=7
|
||||
oms.container.retention.remote=-1
|
||||
|
||||
####### 缓存配置 #######
|
||||
oms.instance.metadata.cache.size=2048
|
||||
oms.instance.metadata.cache.size=2048
|
||||
|
||||
####### 精确获取 server 的百分比,0~100,100代表每次 worker 获取 server 都会进行完整的探活流程,不存在脑裂问题,但有性能开销 #######
|
||||
oms.accurate.select.server.percentage = 50
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,6 +1,5 @@
|
||||
package com.github.kfcfans.powerjob.server.test;
|
||||
|
||||
import com.github.kfcfans.powerjob.server.OhMyApplication;
|
||||
import com.github.kfcfans.powerjob.server.common.utils.CronExpression;
|
||||
import com.github.kfcfans.powerjob.server.common.utils.timewheel.HashedWheelTimer;
|
||||
import com.github.kfcfans.powerjob.server.common.utils.timewheel.TimerFuture;
|
||||
@ -11,9 +10,11 @@ import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 工具类测试
|
||||
@ -92,4 +93,11 @@ public class UtilsTest {
|
||||
System.out.println(StringUtils.containsWhitespace(goodAppName));
|
||||
System.out.println(StringUtils.containsWhitespace(appName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTest() {
|
||||
List<String> test = Lists.newArrayList("A", "B", null, "C", null);
|
||||
List<String> list = test.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
System.out.println(list);
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,12 @@
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-worker-agent</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<version>3.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
<properties>
|
||||
<powerjob.worker.version>3.3.2</powerjob.worker.version>
|
||||
<powerjob.worker.version>3.3.3</powerjob.worker.version>
|
||||
<logback.version>1.2.3</logback.version>
|
||||
<picocli.version>4.3.2</picocli.version>
|
||||
|
||||
|
@ -10,11 +10,11 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>powerjob-worker-samples</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<version>3.3.3</version>
|
||||
|
||||
<properties>
|
||||
<springboot.version>2.2.6.RELEASE</springboot.version>
|
||||
<powerjob.worker.starter.version>3.3.2</powerjob.worker.starter.version>
|
||||
<powerjob.worker.starter.version>3.3.3</powerjob.worker.starter.version>
|
||||
<fastjson.version>1.2.68</fastjson.version>
|
||||
|
||||
<!-- 部署时跳过该module -->
|
||||
|
@ -10,11 +10,11 @@
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-worker-spring-boot-starter</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<version>3.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<powerjob.worker.version>3.3.2</powerjob.worker.version>
|
||||
<powerjob.worker.version>3.3.3</powerjob.worker.version>
|
||||
<springboot.version>2.2.6.RELEASE</springboot.version>
|
||||
</properties>
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.kfcfans.powerjob.worker.autoconfigure;
|
||||
|
||||
import com.github.kfcfans.powerjob.common.utils.CommonUtils;
|
||||
import com.github.kfcfans.powerjob.common.utils.NetUtils;
|
||||
import com.github.kfcfans.powerjob.worker.OhMyWorker;
|
||||
import com.github.kfcfans.powerjob.worker.common.OhMyConfig;
|
||||
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
|
||||
@ -37,8 +38,14 @@ public class PowerJobAutoConfiguration {
|
||||
|
||||
// 1. 创建配置文件
|
||||
OhMyConfig config = new OhMyConfig();
|
||||
// 可以不显式设置,默认值 27777
|
||||
config.setPort(worker.getAkkaPort());
|
||||
|
||||
// 端口配置,支持随机端口
|
||||
int port = worker.getAkkaPort();
|
||||
if (port <= 0) {
|
||||
port = NetUtils.getRandomPort();
|
||||
}
|
||||
config.setPort(port);
|
||||
|
||||
// appName,需要提前在控制台注册,否则启动报错
|
||||
config.setAppName(worker.getAppName());
|
||||
config.setServerAddress(serverAddress);
|
||||
|
@ -50,60 +50,6 @@
|
||||
"type": "com.github.kfcfans.powerjob.worker.common.constants.StoreStrategy",
|
||||
"description": "本地持久化方式,默认使用磁盘",
|
||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties$Worker"
|
||||
},
|
||||
{
|
||||
"name": "powerjob.akka-port",
|
||||
"type": "java.lang.Integer",
|
||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||
"deprecated": true,
|
||||
"deprecation": {
|
||||
"replacement": "powerjob.worker.akka-port"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "powerjob.app-name",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||
"deprecated": true,
|
||||
"deprecation": {
|
||||
"replacement": "powerjob.worker.app-name"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "powerjob.enable-test-mode",
|
||||
"type": "java.lang.Boolean",
|
||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||
"deprecated": true,
|
||||
"deprecation": {
|
||||
"replacement": "powerjob.worker.enable-test-mode"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "powerjob.max-result-length",
|
||||
"type": "java.lang.Integer",
|
||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||
"deprecated": true,
|
||||
"deprecation": {
|
||||
"replacement": "powerjob.worker.max-result-length"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "powerjob.server-address",
|
||||
"type": "java.lang.String",
|
||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||
"deprecated": true,
|
||||
"deprecation": {
|
||||
"replacement": "powerjob.worker.server-address"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "powerjob.store-strategy",
|
||||
"type": "com.github.kfcfans.powerjob.worker.common.constants.StoreStrategy",
|
||||
"sourceType": "com.github.kfcfans.powerjob.worker.autoconfigure.PowerJobProperties",
|
||||
"deprecated": true,
|
||||
"deprecation": {
|
||||
"replacement": "powerjob.worker.store-strategy"
|
||||
}
|
||||
}
|
||||
],
|
||||
"hints": []
|
||||
|
@ -10,12 +10,12 @@
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>powerjob-worker</artifactId>
|
||||
<version>3.3.2</version>
|
||||
<version>3.3.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<spring.version>5.2.4.RELEASE</spring.version>
|
||||
<powerjob.common.version>3.3.2</powerjob.common.version>
|
||||
<powerjob.common.version>3.3.3</powerjob.common.version>
|
||||
<h2.db.version>1.4.200</h2.db.version>
|
||||
<hikaricp.version>3.4.2</hikaricp.version>
|
||||
<junit.version>5.6.1</junit.version>
|
||||
|
@ -20,7 +20,7 @@ import com.github.kfcfans.powerjob.worker.background.OmsLogHandler;
|
||||
import com.github.kfcfans.powerjob.worker.background.ServerDiscoveryService;
|
||||
import com.github.kfcfans.powerjob.worker.background.WorkerHealthReporter;
|
||||
import com.github.kfcfans.powerjob.worker.common.OhMyConfig;
|
||||
import com.github.kfcfans.powerjob.worker.common.OmsBannerPrinter;
|
||||
import com.github.kfcfans.powerjob.worker.common.PowerBannerPrinter;
|
||||
import com.github.kfcfans.powerjob.worker.common.utils.SpringUtils;
|
||||
import com.github.kfcfans.powerjob.worker.persistence.TaskPersistenceService;
|
||||
import com.google.common.base.Stopwatch;
|
||||
@ -80,7 +80,7 @@ public class OhMyWorker implements ApplicationContextAware, InitializingBean, Di
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
log.info("[OhMyWorker] start to initialize OhMyWorker...");
|
||||
try {
|
||||
OmsBannerPrinter.print();
|
||||
PowerBannerPrinter.print();
|
||||
// 校验 appName
|
||||
if (!config.isEnableTestMode()) {
|
||||
appId = assertAppName();
|
||||
|
@ -5,7 +5,7 @@ import com.github.kfcfans.powerjob.common.RemoteConstant;
|
||||
import com.github.kfcfans.powerjob.common.model.SystemMetrics;
|
||||
import com.github.kfcfans.powerjob.common.request.WorkerHeartbeat;
|
||||
import com.github.kfcfans.powerjob.worker.OhMyWorker;
|
||||
import com.github.kfcfans.powerjob.worker.common.OmsWorkerVersion;
|
||||
import com.github.kfcfans.powerjob.worker.common.PowerJobWorkerVersion;
|
||||
import com.github.kfcfans.powerjob.worker.common.utils.AkkaUtils;
|
||||
import com.github.kfcfans.powerjob.worker.common.utils.SystemInfoUtils;
|
||||
import com.github.kfcfans.powerjob.worker.container.OmsContainerFactory;
|
||||
@ -40,7 +40,7 @@ public class WorkerHealthReporter implements Runnable {
|
||||
heartbeat.setAppName(OhMyWorker.getConfig().getAppName());
|
||||
heartbeat.setAppId(OhMyWorker.getAppId());
|
||||
heartbeat.setHeartbeatTime(System.currentTimeMillis());
|
||||
heartbeat.setVersion(OmsWorkerVersion.getVersion());
|
||||
heartbeat.setVersion(PowerJobWorkerVersion.getVersion());
|
||||
|
||||
// 获取当前加载的容器列表
|
||||
heartbeat.setContainerInfos(OmsContainerFactory.getDeployedContainerInfos());
|
||||
|
@ -4,9 +4,9 @@ import com.github.kfcfans.powerjob.common.RemoteConstant;
|
||||
import com.github.kfcfans.powerjob.worker.common.constants.StoreStrategy;
|
||||
import com.github.kfcfans.powerjob.worker.core.processor.ProcessResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -15,7 +15,8 @@ import java.util.List;
|
||||
* @author tjq
|
||||
* @since 2020/3/16
|
||||
*/
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
public class OhMyConfig {
|
||||
/**
|
||||
* 应用名称
|
||||
|
@ -9,7 +9,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
* @since 2020/5/11
|
||||
*/
|
||||
@Slf4j
|
||||
public final class OmsBannerPrinter {
|
||||
public final class PowerBannerPrinter {
|
||||
|
||||
private static final String BANNER = "" +
|
||||
"\n" +
|
||||
@ -30,7 +30,7 @@ public final class OmsBannerPrinter {
|
||||
public static void print() {
|
||||
log.info(BANNER);
|
||||
|
||||
String version = OmsWorkerVersion.getVersion();
|
||||
String version = PowerJobWorkerVersion.getVersion();
|
||||
version = (version != null) ? " (v" + version + ")" : "";
|
||||
log.info(":: PowerJob Worker :: {}", version);
|
||||
}
|
@ -17,7 +17,7 @@ import java.util.jar.JarFile;
|
||||
* @author tjq
|
||||
* @since 2020/5/11
|
||||
*/
|
||||
public final class OmsWorkerVersion {
|
||||
public final class PowerJobWorkerVersion {
|
||||
|
||||
private static String CACHE = null;
|
||||
|
||||
@ -29,17 +29,17 @@ public final class OmsWorkerVersion {
|
||||
*/
|
||||
public static String getVersion() {
|
||||
if (StringUtils.isEmpty(CACHE)) {
|
||||
CACHE = determineSpringBootVersion();
|
||||
CACHE = determinePowerJobVersion();
|
||||
}
|
||||
return CACHE;
|
||||
}
|
||||
|
||||
private static String determineSpringBootVersion() {
|
||||
String implementationVersion = OmsWorkerVersion.class.getPackage().getImplementationVersion();
|
||||
private static String determinePowerJobVersion() {
|
||||
String implementationVersion = PowerJobWorkerVersion.class.getPackage().getImplementationVersion();
|
||||
if (implementationVersion != null) {
|
||||
return implementationVersion;
|
||||
}
|
||||
CodeSource codeSource = OmsWorkerVersion.class.getProtectionDomain().getCodeSource();
|
||||
CodeSource codeSource = PowerJobWorkerVersion.class.getProtectionDomain().getCodeSource();
|
||||
if (codeSource == null) {
|
||||
return null;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user