Browse Source

feat: output more server info

tjq 3 years ago
parent
commit
c8a1f536c3

+ 3 - 2
powerjob-server/powerjob-server-migrate/src/main/java/tech/powerjob/server/migrate/MigrateController.java

@@ -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));
     }

+ 24 - 0
powerjob-server/powerjob-server-remote/src/main/java/tech/powerjob/server/remote/server/ServerInfoService.java

@@ -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;
+        }
+    }
 }

+ 8 - 17
powerjob-server/powerjob-server-starter/src/main/java/tech/powerjob/server/config/SwaggerConfig.java

@@ -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)

+ 6 - 0
powerjob-server/powerjob-server-starter/src/main/java/tech/powerjob/server/web/controller/SystemInfoController.java

@@ -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);
     }
 

+ 13 - 0
powerjob-server/powerjob-server-starter/src/main/java/tech/powerjob/server/web/response/SystemOverviewVO.java

@@ -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;
+    }
 }