Merge branch 'v4.0.1' into jenkins_auto_build

This commit is contained in:
tjq 2021-04-05 15:48:53 +08:00
commit 22404847ec
32 changed files with 265 additions and 96 deletions

View File

@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: mvn clean package -Pdev -DskipTests -U -e -pl powerjob-server,powerjob-worker-agent -am && /bin/cp -rf powerjob-server/target/*.jar powerjob-server/docker/powerjob-server.jar && /bin/cp -rf powerjob-worker-agent/target/*.jar powerjob-worker-agent/powerjob-agent.jar
run: mvn clean package -Pdev -DskipTests -U -e && /bin/cp -rf powerjob-server/powerjob-server-starter/target/*.jar powerjob-server/docker/powerjob-server.jar && /bin/cp -rf powerjob-worker-agent/target/*.jar powerjob-worker-agent/powerjob-agent.jar
- uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}

View File

@ -23,7 +23,7 @@ jobs:
- name: Build with Maven
run: mvn -B clean package -Pdev -DskipTests --file pom.xml
- name: upload build result
run: mkdir staging && cp powerjob-server/target/*.jar staging/powerjob-server.jar && cp powerjob-client/target/*.jar staging/powerjob-client.jar && cp powerjob-worker-agent/target/*.jar staging/powerjob-agent.jar
run: mkdir staging && cp powerjob-server/powerjob-server-starter/target/*.jar staging/powerjob-server.jar && cp powerjob-client/target/*.jar staging/powerjob-client.jar && cp powerjob-worker-agent/target/*.jar staging/powerjob-agent.jar
- uses: actions/upload-artifact@v1
with:
name: powerjob-server.jar

View File

@ -11,7 +11,7 @@
Target Server Version : 80021
File Encoding : 65001
Date: 14/03/2021 19:54:37
Date: 05/04/2021 13:15:19
*/
SET NAMES utf8mb4;
@ -68,7 +68,7 @@ CREATE TABLE `instance_info` (
`job_id` bigint DEFAULT NULL,
`job_params` longtext,
`last_report_time` bigint DEFAULT NULL,
`result` longtext,
`result` text,
`running_times` bigint DEFAULT NULL,
`status` int DEFAULT NULL,
`task_tracker_address` varchar(255) DEFAULT NULL,
@ -98,7 +98,7 @@ CREATE TABLE `job_info` (
`instance_time_limit` bigint DEFAULT NULL,
`job_description` varchar(255) DEFAULT NULL,
`job_name` varchar(255) DEFAULT NULL,
`job_params` longtext,
`job_params` text,
`lifecycle` varchar(255) DEFAULT NULL,
`max_instance_num` int DEFAULT NULL,
`max_worker_count` int DEFAULT NULL,
@ -176,7 +176,7 @@ CREATE TABLE `workflow_info` (
`max_wf_instance_num` int DEFAULT NULL,
`next_trigger_time` bigint DEFAULT NULL,
`notify_user_ids` varchar(255) DEFAULT NULL,
`pedag` longtext,
`pedag` text,
`status` int DEFAULT NULL,
`time_expression` varchar(255) DEFAULT NULL,
`time_expression_type` int DEFAULT NULL,
@ -194,15 +194,15 @@ CREATE TABLE `workflow_instance_info` (
`id` bigint NOT NULL AUTO_INCREMENT,
`actual_trigger_time` bigint DEFAULT NULL,
`app_id` bigint DEFAULT NULL,
`dag` longtext,
`dag` text,
`expected_trigger_time` bigint DEFAULT NULL,
`finished_time` bigint DEFAULT NULL,
`gmt_create` datetime(6) DEFAULT NULL,
`gmt_modified` datetime(6) DEFAULT NULL,
`result` longtext,
`result` text,
`status` int DEFAULT NULL,
`wf_context` longtext,
`wf_init_params` longtext,
`wf_context` text,
`wf_init_params` text,
`wf_instance_id` bigint DEFAULT NULL,
`workflow_id` bigint DEFAULT NULL,
PRIMARY KEY (`id`)
@ -216,15 +216,15 @@ CREATE TABLE `workflow_node_info` (
`id` bigint NOT NULL AUTO_INCREMENT,
`app_id` bigint NOT NULL,
`enable` bit(1) NOT NULL,
`extra` longtext,
`extra` text,
`gmt_create` datetime(6) NOT NULL,
`gmt_modified` datetime(6) NOT NULL,
`job_id` bigint DEFAULT NULL,
`node_name` varchar(255) DEFAULT NULL,
`node_params` longtext,
`node_params` text,
`skip_when_failed` bit(1) NOT NULL,
`type` int DEFAULT NULL,
`workflow_id` bigint NOT NULL,
`workflow_id` bigint DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX36t7rhj4mkg2a5pb4ttorscta` (`app_id`),
KEY `IDXacr0i6my8jr002ou8i1gmygju` (`workflow_id`)

View File

@ -10,13 +10,13 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-client</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
<packaging>jar</packaging>
<properties>
<junit.version>5.6.1</junit.version>
<fastjson.version>1.2.68</fastjson.version>
<powerjob.common.version>4.0.0</powerjob.common.version>
<powerjob.common.version>4.0.1</powerjob.common.version>
<mvn.shade.plugin.version>3.2.4</mvn.shade.plugin.version>
</properties>

View File

@ -10,14 +10,14 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-common</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
<packaging>jar</packaging>
<properties>
<slf4j.version>1.7.30</slf4j.version>
<commons.lang.version>3.10</commons.lang.version>
<commons.io.version>2.6</commons.io.version>
<guava.version>29.0-jre</guava.version>
<guava.version>30.1.1-jre</guava.version>
<okhttp.version>3.14.9</okhttp.version>
<akka.version>2.6.12</akka.version>
<kryo.version>5.0.4</kryo.version>

View File

@ -147,6 +147,18 @@ public class CommonUtils {
return OmsConstant.NONE;
}
/**
* 格式化字符串如果是 null 或空则显示 N/A
* @param str 字符串
* @return 结果
*/
public static String formatString(String str) {
if (StringUtils.isEmpty(str)) {
return OmsConstant.NONE;
}
return str;
}
/**
* 生成 UUID
* @return uuid

View File

@ -28,7 +28,7 @@
<!-- 全部 shade 化,避免依赖冲突 -->
<fastjson.version>1.2.68</fastjson.version>
<okhttp.version>3.14.9</okhttp.version>
<guava.version>29.0-jre</guava.version>
<guava.version>30.1.1-jre</guava.version>
<commons.io.version>2.6</commons.io.version>
<commons.lang.version>3.10</commons.lang.version>
</properties>

View File

@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-server</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
<packaging>pom</packaging>
<modules>
@ -27,7 +27,7 @@
<properties>
<swagger.version>2.9.2</swagger.version>
<springboot.version>2.3.4.RELEASE</springboot.version>
<powerjob.common.version>4.0.0</powerjob.common.version>
<powerjob.common.version>4.0.1</powerjob.common.version>
<!-- MySQL version that corresponds to spring-boot-dependencies version. -->
<mysql.version>8.0.19</mysql.version>
<ojdbc.version>19.7.0.0</ojdbc.version>
@ -47,13 +47,6 @@
<!-- skip this module when deploying. -->
<maven.deploy.skip>true</maven.deploy.skip>
<!-- self-internal dependency, generally no need to change the version -->
<powerjob-server-common.version>1.0.0</powerjob-server-common.version>
<powerjob-server-extension.version>1.0.0</powerjob-server-extension.version>
<powerjob-server-remote.version>1.0.0</powerjob-server-remote.version>
<powerjob-server-persistence.version>1.0.0</powerjob-server-persistence.version>
<powerjob-server-core.version>1.0.0</powerjob-server-core.version>
<powerjob-server-migrate.version>1.0.0</powerjob-server-migrate.version>
</properties>
<dependencyManagement>
@ -61,32 +54,37 @@
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-server-common</artifactId>
<version>${powerjob-server-common.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-server-extension</artifactId>
<version>${powerjob-server-extension.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-server-remote</artifactId>
<version>${powerjob-server-remote.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-server-persistence</artifactId>
<version>${powerjob-server-persistence.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-server-core</artifactId>
<version>${powerjob-server-core.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-server-migrate</artifactId>
<version>${powerjob-server-migrate.version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>tech.powerjob</groupId>
<artifactId>powerjob-server-starter</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -5,13 +5,13 @@
<parent>
<artifactId>powerjob-server</artifactId>
<groupId>tech.powerjob</groupId>
<version>4.0.0</version>
<version>4.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-server-common</artifactId>
<version>1.0.0</version>
<version>${project.parent.version}</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -5,13 +5,13 @@
<parent>
<artifactId>powerjob-server</artifactId>
<groupId>tech.powerjob</groupId>
<version>4.0.0</version>
<version>4.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-server-core</artifactId>
<version>1.0.0</version>
<version>${project.parent.version}</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -5,13 +5,13 @@
<parent>
<artifactId>powerjob-server</artifactId>
<groupId>tech.powerjob</groupId>
<version>4.0.0</version>
<version>4.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-server-extension</artifactId>
<version>1.0.0</version>
<version>${project.parent.version}</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -5,13 +5,13 @@
<parent>
<artifactId>powerjob-server</artifactId>
<groupId>tech.powerjob</groupId>
<version>4.0.0</version>
<version>4.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-server-migrate</artifactId>
<version>1.0.0</version>
<version>${project.parent.version}</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -1,6 +1,7 @@
package tech.powerjob.server.migrate;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import tech.powerjob.common.response.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
@ -29,7 +30,7 @@ public class MigrateController {
/**
* 修复对应 APP 下的任务信息
*/
@RequestMapping("/v4/job")
@GetMapping("/v4/job")
public ResultDTO<JSONObject> fixJobInfoFromV3ToV4(@RequestParam Long appId) {
return ResultDTO.success(v3ToV4MigrateService.fixDeprecatedProcessType(appId));
}
@ -37,7 +38,7 @@ public class MigrateController {
/**
* 修复对应 APP 下的工作流信息
*/
@RequestMapping("/v4/workflow")
@GetMapping("/v4/workflow")
public ResultDTO<JSONObject> fixWorkflowInfoFromV3ToV4(@RequestParam Long appId){
return ResultDTO.success(v3ToV4MigrateService.fixWorkflowInfoFromV3ToV4(appId));
}

View File

@ -5,13 +5,13 @@
<parent>
<artifactId>powerjob-server</artifactId>
<groupId>tech.powerjob</groupId>
<version>4.0.0</version>
<version>4.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-server-persistence</artifactId>
<version>1.0.0</version>
<version>${project.parent.version}</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -0,0 +1,66 @@
package tech.powerjob.server.persistence.config;
import com.google.common.collect.Maps;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.*;
/**
* 多重数据源配置
*
* @author Kung Yao
* @since 2020/4/27
*/
@Component
@ConfigurationProperties("spring.datasource")
public class MultiDatasourceProperties {
private DataSourceProperties remote = new DataSourceProperties();
private DataSourceProperties local = new DataSourceProperties();
public static class DataSourceProperties {
private HibernateProperties hibernate = new HibernateProperties();
public void setHibernate(HibernateProperties hibernate) {
this.hibernate = hibernate;
}
public HibernateProperties getHibernate() {
return hibernate;
}
}
public static class HibernateProperties {
private Map<String, String> properties = Maps.newHashMap();
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
public Map<String, String> getProperties() {
return properties;
}
}
public void setLocal(DataSourceProperties local) {
this.local = local;
}
public void setRemote(DataSourceProperties remote) {
this.remote = remote;
}
public DataSourceProperties getLocal() {
return local;
}
public DataSourceProperties getRemote() {
return remote;
}
}

View File

@ -39,10 +39,13 @@ public class RemoteJpaConfig {
@Resource(name = "omsRemoteDatasource")
private DataSource omsRemoteDatasource;
@Resource(name = "multiDatasourceProperties")
private MultiDatasourceProperties properties;
public static final String CORE_PACKAGES = "tech.powerjob.server.persistence.remote";
/**
* 生成配置文件包括 JPA配置文件和Hibernate配置文件相当于下三个配置
* 生成配置文件包括 JPA配置文件和Hibernate配置文件相当于下三个配置
* spring.jpa.show-sql=false
* spring.jpa.open-in-view=false
* spring.jpa.hibernate.ddl-auto=update
@ -67,10 +70,11 @@ public class RemoteJpaConfig {
@Primary
@Bean(name = "remoteEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean initRemoteEntityManagerFactory(EntityManagerFactoryBuilder builder) {
Map<String, Object> datasourceProperties = genDatasourceProperties();
datasourceProperties.putAll(properties.getRemote().getHibernate().getProperties());
return builder
.dataSource(omsRemoteDatasource)
.properties(genDatasourceProperties())
.properties(datasourceProperties)
.packages(CORE_PACKAGES)
.persistenceUnit("remotePersistenceUnit")
.build();

View File

@ -0,0 +1,33 @@
package tech.powerjob.server.persistence.config.dialect;
import org.hibernate.dialect.PostgreSQL10Dialect;
import org.hibernate.type.descriptor.sql.LongVarcharTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import java.sql.Types;
/**
* PostgreSQL 数据库支持需要在 application.properties 中添加以下配置项进行激活
* spring.datasource.remote.hibernate.properties.hibernate.dialect=tech.powerjob.server.persistence.config.dialect.PowerJobPGDialect
*
* @author Kung Yao
* @author Echo009
* 2021/3/24 下午 04:23
* 1074_King
*/
public class PowerJobPGDialect extends PostgreSQL10Dialect {
/**
* 使用 {@link Types#LONGVARCHAR} 覆盖 {@link Types#CLOB} 类型
*
* 注意如果在 PG 库创建表时使用的列类型为 oid 那么这样会导致没法正确读取数据
* PowerJob 中能这样用是因为 PowerJob 的所有实体类中被 @Lob 注解标记的列对应数据库中的字段类型都是 text
* 另外还需要注意数据库版本如果是 10.x 以前的需自行提供一个合适的 Dialect 选择合适的版本继承
*
* 更多内容请关注该 issueshttps://github.com/PowerJob/PowerJob/issues/153
*/
@Override
public SqlTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) {
return Types.CLOB == sqlCode ? LongVarcharTypeDescriptor.INSTANCE : null;
}
}

View File

@ -5,13 +5,13 @@
<parent>
<artifactId>powerjob-server</artifactId>
<groupId>tech.powerjob</groupId>
<version>4.0.0</version>
<version>4.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-server-remote</artifactId>
<version>1.0.0</version>
<version>${project.parent.version}</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -1,5 +1,7 @@
package tech.powerjob.server.remote.server;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.info.BuildProperties;
import tech.powerjob.common.exception.PowerJobException;
import tech.powerjob.common.utils.CommonUtils;
import tech.powerjob.common.utils.NetUtils;
@ -33,6 +35,8 @@ public class ServerInfoService {
private final ServerInfoRepository serverInfoRepository;
private String version = "UNKNOWN";
private static final long MAX_SERVER_CLUSTER_SIZE = 10000;
private static final String SERVER_INIT_LOCK = "server_init_lock";
@ -42,6 +46,15 @@ public class ServerInfoService {
return serverId;
}
public String getServerIp() {
return ip;
}
public String getServerVersion() {
return version;
}
@Autowired
public ServerInfoService(LockService lockService, ServerInfoRepository serverInfoRepository) {
@ -121,4 +134,15 @@ public class ServerInfoService {
}
throw new PowerJobException("impossible");
}
@Autowired(required = false)
public void setBuildProperties(BuildProperties buildProperties) {
if (buildProperties == null) {
return;
}
String pomVersion = buildProperties.getVersion();
if (StringUtils.isNotBlank(pomVersion)) {
version = pomVersion;
}
}
}

View File

@ -93,7 +93,7 @@ public class ServerElectionService {
// 可能上一台机器已经完成了Server选举需要再次判断
AppInfoDO appInfo = appInfoRepository.findById(appId).orElseThrow(() -> new RuntimeException("impossible, unless we just lost our database."));
String address = activeAddress(originServer, downServerCache, protocol);
String address = activeAddress(appInfo.getCurrentServer(), downServerCache, protocol);
if (StringUtils.isNotEmpty(address)) {
return address;
}

View File

@ -1,14 +1,14 @@
package tech.powerjob.server.remote.worker;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.powerjob.common.model.DeployedContainerInfo;
import tech.powerjob.server.common.module.WorkerInfo;
import tech.powerjob.server.extension.WorkerFilter;
import tech.powerjob.server.persistence.remote.model.JobInfoDO;
import tech.powerjob.server.remote.server.redirector.DesignateServer;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
@ -34,6 +34,7 @@ public class WorkerClusterQueryService {
/**
* get worker for job
*
* @param jobInfo job
* @return worker cluster info, sorted by metrics desc
*/
@ -44,7 +45,7 @@ public class WorkerClusterQueryService {
workers.removeIf(workerInfo -> filterWorker(workerInfo, jobInfo));
// 按健康度排序
workers.sort((o1, o2) -> o2 .getSystemMetrics().calculateScore() - o1.getSystemMetrics().calculateScore());
workers.sort((o1, o2) -> o2.getSystemMetrics().calculateScore() - o1.getSystemMetrics().calculateScore());
// 限定集群大小0代表不限制
if (!workers.isEmpty() && jobInfo.getMaxWorkerCount() > 0 && workers.size() > jobInfo.getMaxWorkerCount()) {
@ -56,12 +57,13 @@ public class WorkerClusterQueryService {
@DesignateServer
public List<WorkerInfo> getAllWorkers(Long appId) {
List<WorkerInfo> workers = Lists.newLinkedList(getWorkerInfosByAppId(appId).values());
workers.sort((o1, o2) -> o2 .getSystemMetrics().calculateScore() - o1.getSystemMetrics().calculateScore());
workers.sort((o1, o2) -> o2.getSystemMetrics().calculateScore() - o1.getSystemMetrics().calculateScore());
return workers;
}
/**
* get all alive workers
*
* @param appId appId
* @return alive workers
*/
@ -71,8 +73,22 @@ public class WorkerClusterQueryService {
return workers;
}
/**
* Gets worker info by address.
*
* @param appId the app id
* @param address the address
* @return the worker info by address
*/
public Optional<WorkerInfo> getWorkerInfoByAddress(Long appId, String address) {
return Optional.ofNullable(getWorkerInfosByAppId(appId).get(address));
// this may cause NPE while address value is null .
//return Optional.ofNullable(getWorkerInfosByAppId(appId).get(address));
final Map<String, WorkerInfo> workerInfosByAppId = getWorkerInfosByAppId(appId);
//add null check for both workerInfos Map and address
if (null != workerInfosByAppId && null != address) {
return Optional.ofNullable(workerInfosByAppId.get(address));
}
return Optional.empty();
}
public Map<Long, ClusterStatusHolder> getAppId2ClusterStatus() {
@ -81,7 +97,8 @@ public class WorkerClusterQueryService {
/**
* 获取某个应用容器的部署情况
* @param appId 应用ID
*
* @param appId 应用ID
* @param containerId 容器ID
* @return 部署情况
*/
@ -104,8 +121,9 @@ public class WorkerClusterQueryService {
/**
* filter invalid worker for job
*
* @param workerInfo worker info
* @param jobInfo job info
* @param jobInfo job info
* @return filter this worker when return true
*/
private boolean filterWorker(WorkerInfo workerInfo, JobInfoDO jobInfo) {

View File

@ -5,13 +5,13 @@
<parent>
<artifactId>powerjob-server</artifactId>
<groupId>tech.powerjob</groupId>
<version>4.0.0</version>
<version>4.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-server-starter</artifactId>
<version>1.0.0</version>
<version>${project.parent.version}</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -1,10 +1,6 @@
package tech.powerjob.server.config;
import tech.powerjob.server.common.PowerJobServerConfigKey;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
@ -12,6 +8,10 @@ import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import tech.powerjob.server.common.PowerJobServerConfigKey;
import tech.powerjob.server.remote.server.ServerInfoService;
import javax.annotation.Resource;
import static springfox.documentation.builders.PathSelectors.any;
@ -27,28 +27,19 @@ import static springfox.documentation.builders.PathSelectors.any;
@ConditionalOnProperty(name = PowerJobServerConfigKey.SWAGGER_UI_ENABLE, havingValue = "true")
public class SwaggerConfig {
private final BuildProperties buildProperties;
public SwaggerConfig(@Autowired(required = false) final BuildProperties buildProperties) {
this.buildProperties = buildProperties;
}
@Resource
private ServerInfoService serverInfoService;
@Bean
public Docket createRestApi() {
String version = "unknown";
if (buildProperties != null) {
String pomVersion = buildProperties.getVersion();
if (StringUtils.isNotBlank(pomVersion)) {
version = pomVersion;
}
}
// apiInfo()用来创建该Api的基本信息这些基本信息会展现在文档页面中
ApiInfo apiInfo = new ApiInfoBuilder()
.title("PowerJob")
.description("Distributed scheduling and computing framework.")
.license("Apache Licence 2")
.termsOfServiceUrl("https://github.com/PowerJob/PowerJob")
.version(version)
.version(serverInfoService.getServerVersion())
.build();
return new Docket(DocumentationType.SWAGGER_2)

View File

@ -6,6 +6,7 @@ import tech.powerjob.common.response.ResultDTO;
import tech.powerjob.server.common.constants.SwitchableStatus;
import tech.powerjob.server.persistence.remote.repository.InstanceInfoRepository;
import tech.powerjob.server.persistence.remote.repository.JobInfoRepository;
import tech.powerjob.server.remote.server.ServerInfoService;
import tech.powerjob.server.remote.worker.WorkerClusterQueryService;
import tech.powerjob.server.common.module.WorkerInfo;
import tech.powerjob.server.web.response.SystemOverviewVO;
@ -39,6 +40,8 @@ public class SystemInfoController {
@Resource
private InstanceInfoRepository instanceInfoRepository;
@Resource
private ServerInfoService serverInfoService;
@Resource
private WorkerClusterQueryService workerClusterQueryService;
@ -67,6 +70,9 @@ public class SystemInfoController {
// 服务器时间
overview.setServerTime(DateFormatUtils.format(new Date(), OmsConstant.TIME_PATTERN));
SystemOverviewVO.CurrentServerInfo info = new SystemOverviewVO.CurrentServerInfo(serverInfoService.getServerId(), serverInfoService.getServerIp(), serverInfoService.getServerVersion());
overview.setCurrentServerInfo(info);
return ResultDTO.success(overview);
}

View File

@ -1,6 +1,8 @@
package tech.powerjob.server.web.response;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
/**
* 系统概览
@ -10,6 +12,7 @@ import lombok.Data;
*/
@Data
public class SystemOverviewVO {
private long jobCount;
private long runningInstanceCount;
private long failedInstanceCount;
@ -17,4 +20,14 @@ public class SystemOverviewVO {
private String timezone;
// 服务器时间
private String serverTime;
private CurrentServerInfo currentServerInfo;
@Getter
@AllArgsConstructor
public static class CurrentServerInfo {
private final long id;
private final String ip;
private final String version;
}
}

View File

@ -1,6 +1,7 @@
package tech.powerjob.server.web.response;
import tech.powerjob.common.model.SystemMetrics;
import tech.powerjob.common.utils.CommonUtils;
import tech.powerjob.server.common.module.WorkerInfo;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -24,6 +25,7 @@ public class WorkerStatusVO {
private String protocol;
private String tag;
private String lastActiveTime;
// 1 -> 健康绿色2 -> 一般橙色3 -> 糟糕红色9999 -> 非在线机器
private int status;
@ -40,9 +42,6 @@ public class WorkerStatusVO {
SystemMetrics systemMetrics = workerInfo.getSystemMetrics();
this.protocol = workerInfo.getProtocol();
this.tag = workerInfo.getTag();
this.status = 1;
this.address = workerInfo.getAddress();
this.cpuLoad = String.format(CPU_FORMAT, df.format(systemMetrics.getCpuLoad()), systemMetrics.getCpuProcessors());
@ -69,5 +68,9 @@ public class WorkerStatusVO {
if (workerInfo.timeout()) {
this.status = 9999;
}
this.protocol = workerInfo.getProtocol();
this.tag = CommonUtils.formatString(workerInfo.getTag());
this.lastActiveTime = CommonUtils.formatTime(workerInfo.getLastActiveTime());
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,12 +10,12 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-worker-agent</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
<packaging>jar</packaging>
<properties>
<powerjob.worker.version>4.0.0</powerjob.worker.version>
<powerjob.worker.version>4.0.1</powerjob.worker.version>
<logback.version>1.2.3</logback.version>
<picocli.version>4.3.2</picocli.version>

View File

@ -10,11 +10,11 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-worker-samples</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
<properties>
<springboot.version>2.3.4.RELEASE</springboot.version>
<powerjob.worker.starter.version>4.0.0</powerjob.worker.starter.version>
<powerjob.worker.starter.version>4.0.1</powerjob.worker.starter.version>
<fastjson.version>1.2.68</fastjson.version>
<powerjob.official.processors.version>1.1.0</powerjob.official.processors.version>

View File

@ -10,11 +10,11 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-worker-spring-boot-starter</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
<packaging>jar</packaging>
<properties>
<powerjob.worker.version>4.0.0</powerjob.worker.version>
<powerjob.worker.version>4.0.1</powerjob.worker.version>
<springboot.version>2.3.4.RELEASE</springboot.version>
</properties>

View File

@ -10,12 +10,12 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>powerjob-worker</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
<packaging>jar</packaging>
<properties>
<spring.version>5.2.4.RELEASE</spring.version>
<powerjob.common.version>4.0.0</powerjob.common.version>
<powerjob.common.version>4.0.1</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>