新增:pbs服务集成xxljob
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
package com.sdm.pbs.config.xxljob;
|
||||
|
||||
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* xxl-job config
|
||||
*
|
||||
* @author xuxueli 2017-04-28
|
||||
*/
|
||||
@Configuration
|
||||
public class XxlJobConfig {
|
||||
private static final Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
|
||||
|
||||
@Value("${xxl.job.admin.addresses}")
|
||||
private String adminAddresses;
|
||||
|
||||
@Value("${xxl.job.admin.accessToken}")
|
||||
private String accessToken;
|
||||
|
||||
@Value("${xxl.job.admin.timeout}")
|
||||
private int timeout;
|
||||
|
||||
@Value("${xxl.job.executor.enabled}")
|
||||
private Boolean enabled;
|
||||
|
||||
@Value("${xxl.job.executor.appname}")
|
||||
private String appname;
|
||||
|
||||
@Value("${xxl.job.executor.address}")
|
||||
private String address;
|
||||
|
||||
@Value("${xxl.job.executor.ip}")
|
||||
private String ip;
|
||||
|
||||
@Value("${xxl.job.executor.port}")
|
||||
private int port;
|
||||
|
||||
@Value("${xxl.job.executor.logpath}")
|
||||
private String logPath;
|
||||
|
||||
@Value("${xxl.job.executor.logretentiondays}")
|
||||
private int logRetentionDays;
|
||||
|
||||
@Value("${xxl.job.executor.excludedpackage}")
|
||||
private String excludedPackage;
|
||||
|
||||
|
||||
@Bean
|
||||
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||
logger.info(">>>>>>>>>>> xxl-job config init.");
|
||||
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||
xxlJobSpringExecutor.setAccessToken(accessToken);
|
||||
xxlJobSpringExecutor.setTimeout(timeout);
|
||||
xxlJobSpringExecutor.setEnabled(enabled);
|
||||
xxlJobSpringExecutor.setAppname(appname);
|
||||
xxlJobSpringExecutor.setAddress(address);
|
||||
xxlJobSpringExecutor.setIp(ip);
|
||||
xxlJobSpringExecutor.setPort(port);
|
||||
xxlJobSpringExecutor.setLogPath(logPath);
|
||||
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
|
||||
xxlJobSpringExecutor.setExcludedPackage(excludedPackage);
|
||||
|
||||
return xxlJobSpringExecutor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
|
||||
*
|
||||
* 1、引入依赖:
|
||||
* <dependency>
|
||||
* <groupId>org.springframework.cloud</groupId>
|
||||
* <artifactId>spring-cloud-commons</artifactId>
|
||||
* <version>${version}</version>
|
||||
* </dependency>
|
||||
*
|
||||
* 2、配置文件,或者容器启动变量
|
||||
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
|
||||
*
|
||||
* 3、获取IP
|
||||
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
@@ -1,58 +1,63 @@
|
||||
package com.sdm.pbs.schedule.hpc;
|
||||
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
// 后期多节点部署,优化成分布式定时任务
|
||||
@Component
|
||||
public class HpcJobStatusSchedule {
|
||||
|
||||
@Value("${task.schedule.interval:120}")
|
||||
private long interval;
|
||||
|
||||
@Value("${task.schedule.poolSize:1}")
|
||||
private int poolSize;
|
||||
|
||||
private ScheduledExecutorService scheduler;
|
||||
// @Value("${task.schedule.interval:120}")
|
||||
// private long interval;
|
||||
//
|
||||
// @Value("${task.schedule.poolSize:1}")
|
||||
// private int poolSize;
|
||||
//
|
||||
// private ScheduledExecutorService scheduler;
|
||||
|
||||
@Autowired
|
||||
private HpcJobStatusScheduleExcutor hpcJobStatusScheduleService;
|
||||
|
||||
/**
|
||||
* 初始化定时任务:直接提交Service作为任务
|
||||
*/
|
||||
@PostConstruct
|
||||
public void initScheduledTask() {
|
||||
scheduler = Executors.newScheduledThreadPool(poolSize);
|
||||
scheduler.scheduleWithFixedDelay(
|
||||
hpcJobStatusScheduleService,
|
||||
0,
|
||||
interval,
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
// xxljob平台配置定时任务
|
||||
@XxlJob("hpcJobStatusHandler")
|
||||
public void hpcJobStatusHandler() throws Exception {
|
||||
XxlJobHelper.log("XXL-JOB:拉起Hpc任务更新开始");
|
||||
hpcJobStatusScheduleService.run();
|
||||
XxlJobHelper.log("XXL-JOB:拉起Hpc任务更新结束");
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁线程池
|
||||
*/
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
if (scheduler != null) {
|
||||
scheduler.shutdown();
|
||||
try {
|
||||
if (!scheduler.awaitTermination(1, TimeUnit.MINUTES)) {
|
||||
scheduler.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
scheduler.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 初始化定时任务:直接提交Service作为任务
|
||||
// */
|
||||
// @PostConstruct
|
||||
// public void initScheduledTask() {
|
||||
// scheduler = Executors.newScheduledThreadPool(poolSize);
|
||||
// scheduler.scheduleWithFixedDelay(
|
||||
// hpcJobStatusScheduleService,
|
||||
// 0,
|
||||
// interval,
|
||||
// TimeUnit.SECONDS
|
||||
// );
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * 销毁线程池
|
||||
// */
|
||||
// @PreDestroy
|
||||
// public void destroy() {
|
||||
// if (scheduler != null) {
|
||||
// scheduler.shutdown();
|
||||
// try {
|
||||
// if (!scheduler.awaitTermination(1, TimeUnit.MINUTES)) {
|
||||
// scheduler.shutdownNow();
|
||||
// }
|
||||
// } catch (InterruptedException e) {
|
||||
// scheduler.shutdownNow();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class HpcJobStatusScheduleExcutor implements Runnable{
|
||||
public class HpcJobStatusScheduleExcutor {
|
||||
|
||||
//public class HpcJobStatusScheduleExcutor implements Runnable{
|
||||
|
||||
@Autowired
|
||||
private ISimulationJobService simulationJobService;
|
||||
@@ -28,7 +30,7 @@ public class HpcJobStatusScheduleExcutor implements Runnable{
|
||||
@Autowired
|
||||
private HpcJobStatusStrategyFactory strategyFactory;
|
||||
|
||||
@Override
|
||||
// 改成xxljob,普通的service 方法,非本地定时任务线程的方式
|
||||
public void run() {
|
||||
try {
|
||||
// Configuring,Queued,Running,Canceled,Finished,Failed
|
||||
|
||||
@@ -151,3 +151,32 @@ security:
|
||||
testEnStr: ENC(095i92PAFyJQ5kEnkiaCYReMEtw+Dwc8qnS1i7Vx0Y8=)
|
||||
testEnStr1: ENC(AtQcdulLNvaSvboZuWsXIxuCwrHyUoG3oEGtmKfDSbs=)
|
||||
testEnStr2: ENC(+QKYnI6gAYu1SbLaZQTkZA==)
|
||||
|
||||
# xxljob 配置开始
|
||||
xxl:
|
||||
job:
|
||||
admin:
|
||||
# 调度中心地址列表
|
||||
addresses: http://192.168.190.161:7110/xxl-job-admin
|
||||
# 调度中心访问令牌
|
||||
accessToken: default_token
|
||||
# xxl-job 超时时间(秒),默认3秒
|
||||
timeout: 3
|
||||
executor:
|
||||
# 执行器是否启用,默认true
|
||||
enabled: true
|
||||
# 执行器应用名称
|
||||
appname: pbs-job-executor
|
||||
# 执行器注册地址:默认使用address注册,若为null则使用ip:port注册
|
||||
address:
|
||||
# 执行器IP
|
||||
ip:
|
||||
# 执行器端口,为了好记,web服务端口+1000
|
||||
port: 8105
|
||||
# 执行器日志路径
|
||||
logpath: /home/app/pbs/xxljob
|
||||
# 执行器日志保留天数
|
||||
logretentiondays: 14
|
||||
# 执行器排除扫描的包,多个用逗号分隔,如 "org.package01" 或 "org.package01,org.package02"
|
||||
excludedpackage:
|
||||
# xxljob 配置结束
|
||||
|
||||
@@ -146,4 +146,33 @@ security:
|
||||
paths:
|
||||
- /pbs/jobFileCallback
|
||||
- /pbs/netTest
|
||||
- /pbs/adapterSubmitHpcJob
|
||||
- /pbs/adapterSubmitHpcJob
|
||||
|
||||
# xxljob 配置开始
|
||||
xxl:
|
||||
job:
|
||||
admin:
|
||||
# 调度中心地址列表
|
||||
addresses: http://192.168.65.161:7110/xxl-job-admin
|
||||
# 调度中心访问令牌
|
||||
accessToken: default_token
|
||||
# xxl-job 超时时间(秒),默认3秒
|
||||
timeout: 3
|
||||
executor:
|
||||
# 执行器是否启用,默认true
|
||||
enabled: true
|
||||
# 执行器应用名称
|
||||
appname: pbs-job-executor
|
||||
# 执行器注册地址:默认使用address注册,若为null则使用ip:port注册
|
||||
address:
|
||||
# 执行器IP
|
||||
ip:
|
||||
# 执行器端口,为了好记,web服务端口+1000
|
||||
port: 8105
|
||||
# 执行器日志路径
|
||||
logpath: /home/app/pbs/xxljob
|
||||
# 执行器日志保留天数
|
||||
logretentiondays: 14
|
||||
# 执行器排除扫描的包,多个用逗号分隔,如 "org.package01" 或 "org.package01,org.package02"
|
||||
excludedpackage:
|
||||
# xxljob 配置结束
|
||||
@@ -93,4 +93,34 @@ hpc:
|
||||
url: http://172.27.3.135/JSONAPI/JSONAPI.ashx
|
||||
|
||||
#logging:
|
||||
# config: ./config/logback.xml
|
||||
# config: ./config/logback.xml
|
||||
|
||||
# xxljob 配置开始
|
||||
# xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||
xxl:
|
||||
job:
|
||||
admin:
|
||||
# 调度中心地址列表
|
||||
addresses: http://127.0.0.1:7110/xxl-job-admin
|
||||
# 调度中心访问令牌
|
||||
accessToken: default_token
|
||||
# xxl-job 超时时间(秒),默认3秒
|
||||
timeout: 3
|
||||
executor:
|
||||
# 执行器是否启用,默认true
|
||||
enabled: true
|
||||
# 执行器应用名称
|
||||
appname: pbs-job-executor
|
||||
# 执行器注册地址:默认使用address注册,若为null则使用ip:port注册
|
||||
address:
|
||||
# 执行器IP
|
||||
ip:
|
||||
# 执行器端口,为了好记,web服务端口+1000
|
||||
port: 8105
|
||||
# 执行器日志路径
|
||||
logpath: D:\home\app\pbs\xxljob
|
||||
# 执行器日志保留天数
|
||||
logretentiondays: 14
|
||||
# 执行器排除扫描的包,多个用逗号分隔,如 "org.package01" 或 "org.package01,org.package02"
|
||||
excludedpackage:
|
||||
# xxljob 配置结束
|
||||
@@ -157,4 +157,33 @@ security:
|
||||
- /getMain
|
||||
- /getProductLine
|
||||
- /getProjectBatch
|
||||
- /getProjectInfo
|
||||
- /getProjectInfo
|
||||
|
||||
# xxljob 配置开始
|
||||
xxl:
|
||||
job:
|
||||
admin:
|
||||
# 调度中心地址列表
|
||||
addresses: http://192.168.30.148:7110/xxl-job-admin
|
||||
# 调度中心访问令牌
|
||||
accessToken: default_token
|
||||
# xxl-job 超时时间(秒),默认3秒
|
||||
timeout: 3
|
||||
executor:
|
||||
# 执行器是否启用,默认true
|
||||
enabled: true
|
||||
# 执行器应用名称
|
||||
appname: pbs-job-executor
|
||||
# 执行器注册地址:默认使用address注册,若为null则使用ip:port注册
|
||||
address:
|
||||
# 执行器IP
|
||||
ip:
|
||||
# 执行器端口,为了好记,web服务端口+1000
|
||||
port: 8105
|
||||
# 执行器日志路径
|
||||
logpath: /home/app/pbs/xxljob
|
||||
# 执行器日志保留天数
|
||||
logretentiondays: 14
|
||||
# 执行器排除扫描的包,多个用逗号分隔,如 "org.package01" 或 "org.package01,org.package02"
|
||||
excludedpackage:
|
||||
# xxljob 配置结束
|
||||
Reference in New Issue
Block a user