mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: output more server info
This commit is contained in:
parent
7527b31ece
commit
c8a1f536c3
@ -1,6 +1,7 @@
|
|||||||
package tech.powerjob.server.migrate;
|
package tech.powerjob.server.migrate;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import tech.powerjob.common.response.ResultDTO;
|
import tech.powerjob.common.response.ResultDTO;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -29,7 +30,7 @@ public class MigrateController {
|
|||||||
/**
|
/**
|
||||||
* 修复对应 APP 下的任务信息
|
* 修复对应 APP 下的任务信息
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/v4/job")
|
@GetMapping("/v4/job")
|
||||||
public ResultDTO<JSONObject> fixJobInfoFromV3ToV4(@RequestParam Long appId) {
|
public ResultDTO<JSONObject> fixJobInfoFromV3ToV4(@RequestParam Long appId) {
|
||||||
return ResultDTO.success(v3ToV4MigrateService.fixDeprecatedProcessType(appId));
|
return ResultDTO.success(v3ToV4MigrateService.fixDeprecatedProcessType(appId));
|
||||||
}
|
}
|
||||||
@ -37,7 +38,7 @@ public class MigrateController {
|
|||||||
/**
|
/**
|
||||||
* 修复对应 APP 下的工作流信息
|
* 修复对应 APP 下的工作流信息
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/v4/workflow")
|
@GetMapping("/v4/workflow")
|
||||||
public ResultDTO<JSONObject> fixWorkflowInfoFromV3ToV4(@RequestParam Long appId){
|
public ResultDTO<JSONObject> fixWorkflowInfoFromV3ToV4(@RequestParam Long appId){
|
||||||
return ResultDTO.success(v3ToV4MigrateService.fixWorkflowInfoFromV3ToV4(appId));
|
return ResultDTO.success(v3ToV4MigrateService.fixWorkflowInfoFromV3ToV4(appId));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package tech.powerjob.server.remote.server;
|
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.exception.PowerJobException;
|
||||||
import tech.powerjob.common.utils.CommonUtils;
|
import tech.powerjob.common.utils.CommonUtils;
|
||||||
import tech.powerjob.common.utils.NetUtils;
|
import tech.powerjob.common.utils.NetUtils;
|
||||||
@ -33,6 +35,8 @@ public class ServerInfoService {
|
|||||||
|
|
||||||
private final ServerInfoRepository serverInfoRepository;
|
private final ServerInfoRepository serverInfoRepository;
|
||||||
|
|
||||||
|
private String version = "UNKNOWN";
|
||||||
|
|
||||||
private static final long MAX_SERVER_CLUSTER_SIZE = 10000;
|
private static final long MAX_SERVER_CLUSTER_SIZE = 10000;
|
||||||
|
|
||||||
private static final String SERVER_INIT_LOCK = "server_init_lock";
|
private static final String SERVER_INIT_LOCK = "server_init_lock";
|
||||||
@ -42,6 +46,15 @@ public class ServerInfoService {
|
|||||||
return serverId;
|
return serverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getServerIp() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ServerInfoService(LockService lockService, ServerInfoRepository serverInfoRepository) {
|
public ServerInfoService(LockService lockService, ServerInfoRepository serverInfoRepository) {
|
||||||
|
|
||||||
@ -121,4 +134,15 @@ public class ServerInfoService {
|
|||||||
}
|
}
|
||||||
throw new PowerJobException("impossible");
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package tech.powerjob.server.config;
|
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.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.info.BuildProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
@ -12,6 +8,10 @@ import springfox.documentation.service.ApiInfo;
|
|||||||
import springfox.documentation.spi.DocumentationType;
|
import springfox.documentation.spi.DocumentationType;
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
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;
|
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")
|
@ConditionalOnProperty(name = PowerJobServerConfigKey.SWAGGER_UI_ENABLE, havingValue = "true")
|
||||||
public class SwaggerConfig {
|
public class SwaggerConfig {
|
||||||
|
|
||||||
private final BuildProperties buildProperties;
|
@Resource
|
||||||
|
private ServerInfoService serverInfoService;
|
||||||
public SwaggerConfig(@Autowired(required = false) final BuildProperties buildProperties) {
|
|
||||||
this.buildProperties = buildProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Docket createRestApi() {
|
public Docket createRestApi() {
|
||||||
String version = "unknown";
|
|
||||||
if (buildProperties != null) {
|
|
||||||
String pomVersion = buildProperties.getVersion();
|
|
||||||
if (StringUtils.isNotBlank(pomVersion)) {
|
|
||||||
version = pomVersion;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// apiInfo()用来创建该Api的基本信息(这些基本信息会展现在文档页面中
|
// apiInfo()用来创建该Api的基本信息(这些基本信息会展现在文档页面中
|
||||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||||
.title("PowerJob")
|
.title("PowerJob")
|
||||||
.description("Distributed scheduling and computing framework.")
|
.description("Distributed scheduling and computing framework.")
|
||||||
.license("Apache Licence 2")
|
.license("Apache Licence 2")
|
||||||
.termsOfServiceUrl("https://github.com/PowerJob/PowerJob")
|
.termsOfServiceUrl("https://github.com/PowerJob/PowerJob")
|
||||||
.version(version)
|
.version(serverInfoService.getServerVersion())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
@ -6,6 +6,7 @@ import tech.powerjob.common.response.ResultDTO;
|
|||||||
import tech.powerjob.server.common.constants.SwitchableStatus;
|
import tech.powerjob.server.common.constants.SwitchableStatus;
|
||||||
import tech.powerjob.server.persistence.remote.repository.InstanceInfoRepository;
|
import tech.powerjob.server.persistence.remote.repository.InstanceInfoRepository;
|
||||||
import tech.powerjob.server.persistence.remote.repository.JobInfoRepository;
|
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.remote.worker.WorkerClusterQueryService;
|
||||||
import tech.powerjob.server.common.module.WorkerInfo;
|
import tech.powerjob.server.common.module.WorkerInfo;
|
||||||
import tech.powerjob.server.web.response.SystemOverviewVO;
|
import tech.powerjob.server.web.response.SystemOverviewVO;
|
||||||
@ -39,6 +40,8 @@ public class SystemInfoController {
|
|||||||
@Resource
|
@Resource
|
||||||
private InstanceInfoRepository instanceInfoRepository;
|
private InstanceInfoRepository instanceInfoRepository;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ServerInfoService serverInfoService;
|
||||||
@Resource
|
@Resource
|
||||||
private WorkerClusterQueryService workerClusterQueryService;
|
private WorkerClusterQueryService workerClusterQueryService;
|
||||||
|
|
||||||
@ -67,6 +70,9 @@ public class SystemInfoController {
|
|||||||
// 服务器时间
|
// 服务器时间
|
||||||
overview.setServerTime(DateFormatUtils.format(new Date(), OmsConstant.TIME_PATTERN));
|
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);
|
return ResultDTO.success(overview);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package tech.powerjob.server.web.response;
|
package tech.powerjob.server.web.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统概览
|
* 系统概览
|
||||||
@ -10,6 +12,7 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class SystemOverviewVO {
|
public class SystemOverviewVO {
|
||||||
|
|
||||||
private long jobCount;
|
private long jobCount;
|
||||||
private long runningInstanceCount;
|
private long runningInstanceCount;
|
||||||
private long failedInstanceCount;
|
private long failedInstanceCount;
|
||||||
@ -17,4 +20,14 @@ public class SystemOverviewVO {
|
|||||||
private String timezone;
|
private String timezone;
|
||||||
// 服务器时间
|
// 服务器时间
|
||||||
private String serverTime;
|
private String serverTime;
|
||||||
|
|
||||||
|
private CurrentServerInfo currentServerInfo;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class CurrentServerInfo {
|
||||||
|
private final long id;
|
||||||
|
private final String ip;
|
||||||
|
private final String version;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user