diff --git a/pbs/src/main/java/com/sdm/pbs/config/xxljob/XxlJobConfig.java b/pbs/src/main/java/com/sdm/pbs/config/xxljob/XxlJobConfig.java new file mode 100644 index 00000000..973a24ae --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/config/xxljob/XxlJobConfig.java @@ -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、引入依赖: + * + * org.springframework.cloud + * spring-cloud-commons + * ${version} + * + * + * 2、配置文件,或者容器启动变量 + * spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.' + * + * 3、获取IP + * String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); + */ + + +} \ No newline at end of file diff --git a/pbs/src/main/java/com/sdm/pbs/schedule/hpc/HpcJobStatusSchedule.java b/pbs/src/main/java/com/sdm/pbs/schedule/hpc/HpcJobStatusSchedule.java index 4a6c9d88..8ec51468 100644 --- a/pbs/src/main/java/com/sdm/pbs/schedule/hpc/HpcJobStatusSchedule.java +++ b/pbs/src/main/java/com/sdm/pbs/schedule/hpc/HpcJobStatusSchedule.java @@ -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(); +// } +// } +// } + } diff --git a/pbs/src/main/java/com/sdm/pbs/schedule/hpc/HpcJobStatusScheduleExcutor.java b/pbs/src/main/java/com/sdm/pbs/schedule/hpc/HpcJobStatusScheduleExcutor.java index 404a7a69..397cb00e 100644 --- a/pbs/src/main/java/com/sdm/pbs/schedule/hpc/HpcJobStatusScheduleExcutor.java +++ b/pbs/src/main/java/com/sdm/pbs/schedule/hpc/HpcJobStatusScheduleExcutor.java @@ -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 diff --git a/pbs/src/main/resources/application-dev-190.yml b/pbs/src/main/resources/application-dev-190.yml index 73007488..b8d89e9d 100644 --- a/pbs/src/main/resources/application-dev-190.yml +++ b/pbs/src/main/resources/application-dev-190.yml @@ -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 配置结束 diff --git a/pbs/src/main/resources/application-dev-65.yml b/pbs/src/main/resources/application-dev-65.yml index a919d660..25467db8 100644 --- a/pbs/src/main/resources/application-dev-65.yml +++ b/pbs/src/main/resources/application-dev-65.yml @@ -146,4 +146,33 @@ security: paths: - /pbs/jobFileCallback - /pbs/netTest - - /pbs/adapterSubmitHpcJob \ No newline at end of file + - /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 配置结束 \ No newline at end of file diff --git a/pbs/src/main/resources/application-local.yml b/pbs/src/main/resources/application-local.yml index e56d2025..e5e76c2c 100644 --- a/pbs/src/main/resources/application-local.yml +++ b/pbs/src/main/resources/application-local.yml @@ -93,4 +93,34 @@ hpc: url: http://172.27.3.135/JSONAPI/JSONAPI.ashx #logging: -# config: ./config/logback.xml \ No newline at end of file +# 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 配置结束 \ No newline at end of file diff --git a/pbs/src/main/resources/application-lyric.yml b/pbs/src/main/resources/application-lyric.yml index 38e16ddd..86790438 100644 --- a/pbs/src/main/resources/application-lyric.yml +++ b/pbs/src/main/resources/application-lyric.yml @@ -157,4 +157,33 @@ security: - /getMain - /getProductLine - /getProjectBatch - - /getProjectInfo \ No newline at end of file + - /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 配置结束 \ No newline at end of file diff --git a/pom.xml b/pom.xml index f008c093..ecb8bfe8 100644 --- a/pom.xml +++ b/pom.xml @@ -303,6 +303,14 @@ hutool-all 5.8.38 + + + + com.xuxueli + xxl-job-core + 3.3.2 + +