diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/AdminClientBootstrapConfiguration.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/AdminClientBootstrapConfiguration.java index 4d8d7977d6..b1cc402abd 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/AdminClientBootstrapConfiguration.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/AdminClientBootstrapConfiguration.java @@ -12,6 +12,12 @@ import java.util.concurrent.TimeUnit; +/** + * 配置文件检查和注入 + * + * @author shaokeyibb + * @since 2.3 + */ @Slf4j @Configuration public class AdminClientBootstrapConfiguration { diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/CloudClientProperties.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/CloudClientProperties.java index 3950dcfa13..aa1be1ede2 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/CloudClientProperties.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/CloudClientProperties.java @@ -2,6 +2,12 @@ import lombok.Data; +/** + * 云模式配置文件 + * + * @author shaokeyibb + * @since 2.3 + */ @Data public class CloudClientProperties implements IClientProperties { diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/EnableAdminClient.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/EnableAdminClient.java index 972912b360..e11b756252 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/EnableAdminClient.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/EnableAdminClient.java @@ -6,6 +6,9 @@ /** * 指示此服务作为 solon-admin 客户端,此注解一般用在启动类上。 + * + * @author shaokeyibb + * @since 2.3 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/IClientProperties.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/IClientProperties.java index 194f9486b6..b4902b2ee7 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/IClientProperties.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/IClientProperties.java @@ -1,5 +1,9 @@ package org.noear.solon.admin.client.config; +/** + * @author shaokeyibb + * @since 2.3 + */ public interface IClientProperties { boolean isEnabled(); diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/LocalClientProperties.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/LocalClientProperties.java index eca1ed5fb9..bb54e01283 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/LocalClientProperties.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/config/LocalClientProperties.java @@ -2,6 +2,12 @@ import lombok.Data; +/** + * 本地模式配置文件 + * + * @author shaokeyibb + * @since 2.3 + */ @Data public class LocalClientProperties implements IClientProperties { diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/controller/MonitorController.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/controller/MonitorController.java index 22b707e954..d9d5b97044 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/controller/MonitorController.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/controller/MonitorController.java @@ -10,6 +10,12 @@ import java.util.Collection; +/** + * 监视器 Controller,用于分发客户端监视器信息 + * + * @author shaokeyibb + * @since 2.3 + */ @Controller @Mapping("/api/monitor") public class MonitorController { @@ -20,6 +26,10 @@ public class MonitorController { @Inject private ApplicationRegistrationService applicationRegistrationService; + /** + * 获取所有监视器信息 + * @return 所有监视器信息 + */ @Get @Mapping("/all") public Collection register() { diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/Application.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/Application.java index 395422f045..f34d636c75 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/Application.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/Application.java @@ -5,6 +5,12 @@ import lombok.EqualsAndHashCode; import lombok.ToString; +/** + * 应用程序数据 + * + * @author shaokeyibb + * @since 2.3 + */ @Data @Builder public class Application { @@ -17,10 +23,16 @@ public class Application { @EqualsAndHashCode.Exclude private final String metadata; + /** + * 是否展示敏感信息,如:环境变量 + */ @ToString.Exclude @EqualsAndHashCode.Exclude private final boolean showSecretInformation; + /** + * 环境信息 + */ @ToString.Exclude @EqualsAndHashCode.Exclude private final EnvironmentInformation environmentInformation; diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/ApplicationWebsocketTransfer.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/ApplicationWebsocketTransfer.java index eb7f0b87fe..1626670f22 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/ApplicationWebsocketTransfer.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/ApplicationWebsocketTransfer.java @@ -5,6 +5,13 @@ import lombok.NoArgsConstructor; import org.noear.solon.lang.Nullable; +/** + * 应用程序数据传输 Dto + * + * @param 要传输的数据类型 + * @author shaokeyibb + * @since 2.3 + */ @Data @AllArgsConstructor @NoArgsConstructor diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/Detector.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/Detector.java index 8217f037ea..2339dbd1f5 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/Detector.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/Detector.java @@ -5,6 +5,12 @@ import java.util.Map; +/** + * 监视器数据 + * + * @author shaokeyibb + * @since 2.3 + */ @AllArgsConstructor @Data public class Detector { diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/EnvironmentInformation.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/EnvironmentInformation.java index 840faee3c5..8e9df4e35a 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/EnvironmentInformation.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/data/EnvironmentInformation.java @@ -8,14 +8,23 @@ import java.util.HashMap; import java.util.Map; +/** + * 应用环境信息 + * + * @author shaokeyibb + * @since 2.3 + */ @Data @Value public class EnvironmentInformation { + // 系统环境变量 Map systemEnvironment; + // 系统属性 Map systemProperties; + // 应用配置 Map applicationProperties; public static EnvironmentInformation create() { diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/registration/AutoRegistrationConfiguration.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/registration/AutoRegistrationConfiguration.java index 011fbfd0d0..6a23b8b22f 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/registration/AutoRegistrationConfiguration.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/registration/AutoRegistrationConfiguration.java @@ -13,6 +13,12 @@ import java.util.Timer; import java.util.TimerTask; +/** + * 自动向 Solon Admin Server 注册客户端信息 + * + * @author shaokeyibb + * @since 2.3 + */ @Configuration public class AutoRegistrationConfiguration { @@ -26,12 +32,17 @@ public void afterInjection( @Inject ApplicationRegistrationService applicationRegistrationService ) { if (marked == null) return; + + // 订阅事件 EventBus.subscribe(AppLoadEndEvent.class, e -> onStart(applicationRegistrationService)); EventBus.subscribe(AppPrestopEndEvent.class, e -> onStop(applicationRegistrationService)); } public void onStart(ApplicationRegistrationService applicationRegistrationService) { + // 注册应用程序 applicationRegistrationService.register(); + + // 计划心跳 timer.schedule(new TimerTask() { @Override public void run() { @@ -41,6 +52,7 @@ public void run() { } public void onStop(ApplicationRegistrationService applicationRegistrationService) { + // 取消心跳计时器 timer.cancel(); } } diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/services/ApplicationRegistrationService.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/services/ApplicationRegistrationService.java index e6cc80286c..9e4248aa4e 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/services/ApplicationRegistrationService.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/services/ApplicationRegistrationService.java @@ -13,6 +13,12 @@ import java.net.URL; +/** + * 应用程序注册服务 + * + * @author shaokeyibb + * @since 2.3 + */ @Slf4j @Component public class ApplicationRegistrationService { @@ -31,13 +37,22 @@ private Application.ApplicationBuilder getApplicationBuilder() { .baseUrl(NetworkUtils.getHostAndPort()); } + /** + * 获取当前应用程序信息 + * + * @return 当前应用程序信息 + */ public Application getCurrentApplication() { return getApplicationBuilder().build(); } + /** + * 向 Solon Admin Server 注册当前应用程序 + */ public void register() { log.info("Attempting to register this client as an application with Solon Admin server..."); val serverUrl = this.properties.getServerUrl().replaceAll("/+$", ""); + // 向 Server 发送注册请求 try (Response response = client.newCall(new Request.Builder() .url(new URL(serverUrl + "/api/application/register")) .put(RequestBody.create(MediaType.parse("application/json"), @@ -59,9 +74,13 @@ public void register() { } } + /** + * 向 Solon Admin Server 注销 + */ public void unregister() { log.info("Attempting to unregister this client from Solon Admin server..."); val serverUrl = this.properties.getServerUrl().replaceAll("/+$", ""); + // 向 Server 发送注销请求 try (Response response = client.newCall(new Request.Builder() .url(new URL(serverUrl + "/api/application/unregister")) .delete(RequestBody.create(MediaType.parse("application/json"), @@ -77,9 +96,13 @@ public void unregister() { } } + /** + * 向 Solon Admin Server 发送心跳 + */ public void heartbeat() { log.debug("Attempting to send heartbeat to Solon Admin server..."); val serverUrl = this.properties.getServerUrl().replaceAll("/+$", ""); + // 向 Server 发送心跳请求 try (Response response = client.newCall(new Request.Builder() .url(new URL(serverUrl + "/api/application/heartbeat")) .post(RequestBody.create(MediaType.parse("application/json"), diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/services/MonitorService.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/services/MonitorService.java index f108626626..585615b2d3 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/services/MonitorService.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/services/MonitorService.java @@ -8,10 +8,21 @@ import java.util.Collection; import java.util.stream.Collectors; +/** + * 监视器服务 + * + * @author shaokeyibb + * @since 2.3 + */ @Slf4j @Component public class MonitorService { + /** + * 获取所有监视器信息 + * + * @return 所有监视器信息 + */ public Collection getMonitors() { return DetectorManager.all().parallelStream().map(it -> new Detector(it.getName(), it.getInfo())).collect(Collectors.toSet()); } diff --git a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/utils/NetworkUtils.java b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/utils/NetworkUtils.java index 9cde7a1704..f42aa39cd2 100644 --- a/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/utils/NetworkUtils.java +++ b/solon-projects/solon-tool/solon-admin-client/src/main/java/org/noear/solon/admin/client/utils/NetworkUtils.java @@ -5,6 +5,10 @@ import org.noear.solon.cloud.utils.LocalUtils; import org.noear.solon.core.Signal; +/** + * @author shaokeyibb + * @since 2.3 + */ public class NetworkUtils { public static String getHostAndPort() { diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/AdminServerBootstrapConfiguration.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/AdminServerBootstrapConfiguration.java index ad32bfa029..4b9bdfe16b 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/AdminServerBootstrapConfiguration.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/AdminServerBootstrapConfiguration.java @@ -13,6 +13,12 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; +/** + * 配置文件检查和注入 + * + * @author shaokeyibb + * @since 2.3 + */ @Slf4j @Configuration public class AdminServerBootstrapConfiguration { diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/EnableAdminServer.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/EnableAdminServer.java index 8736882baa..c995ba5d37 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/EnableAdminServer.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/EnableAdminServer.java @@ -6,6 +6,9 @@ /** * 指示此服务作为 solon-admin 服务端,此注解一般用在启动类上。 + * + * @author shaokeyibb + * @since 2.3 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/ServerProperties.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/ServerProperties.java index 9a2e84ea17..34d5f77e21 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/ServerProperties.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/ServerProperties.java @@ -4,6 +4,12 @@ import org.noear.solon.annotation.Configuration; import org.noear.solon.annotation.Inject; +/** + * 配置文件 + * + * @author shaokeyibb + * @since 2.3 + */ @Inject(value = "${solon.admin.server}", required = false) @Configuration @Data diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/WebSocketConfiguration.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/WebSocketConfiguration.java index a9a5eb61a6..ac75139b79 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/WebSocketConfiguration.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/WebSocketConfiguration.java @@ -8,6 +8,12 @@ import java.util.ArrayList; import java.util.List; +/** + * WebSocket 初始化 + * + * @author shaokeyibb + * @since 2.3 + */ @Configuration public class WebSocketConfiguration { diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/XPluginImpl.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/XPluginImpl.java index 6c898def9d..36ebc02a9a 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/XPluginImpl.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/config/XPluginImpl.java @@ -4,6 +4,10 @@ import org.noear.solon.core.AopContext; import org.noear.solon.core.Plugin; +/** + * @author shaokeyibb + * @since 2.3 + */ public class XPluginImpl implements Plugin { @Override public void start(AopContext context) { diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/ApplicationController.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/ApplicationController.java index aebdd4df08..49ac201d0a 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/ApplicationController.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/ApplicationController.java @@ -7,6 +7,12 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; +/** + * 应用程序相关 Controller + * + * @author shaokeyibb + * @since 2.3 + */ @Controller @Mapping("/api/application") public class ApplicationController { @@ -14,24 +20,42 @@ public class ApplicationController { @Inject private ApplicationService applicationService; + /** + * 注册应用程序 + * @param application 应用程序 + */ @Put @Mapping("/register") public void register(@Body Application application) { applicationService.registerApplication(application); } + /** + * 注销应用程序 + * @param application 应用程序 + */ @Delete @Mapping("/unregister") public void unregister(@Body Application application) { applicationService.unregisterApplication(application); } + /** + * 发送一次心跳 + * @param application 应用程序 + */ @Post @Mapping("/heartbeat") public void heartbeat(@Body Application application) { applicationService.heartbeatApplication(application); } + /** + * 获取应用程序信息 + * @param name 应用程序名称 + * @param baseUrl 应用程序 baseUrl + * @return 应用程序信息 + */ @Get @Mapping("/?") public Application getByNameAndBaseUrl(@Param("name") String name, @Param("baseUrl") String baseUrl) throws UnsupportedEncodingException { diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/ApplicationWebsocketController.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/ApplicationWebsocketController.java index b0ae3fe3c8..095845948e 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/ApplicationWebsocketController.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/ApplicationWebsocketController.java @@ -12,6 +12,12 @@ import java.util.List; +/** + * 应用程序 WebSocket Controller + * + * @author shaokeyibb + * @since 2.3 + */ @ServerEndpoint(path = "/ws/application") public class ApplicationWebsocketController implements Listener { @@ -33,6 +39,7 @@ public void onOpen(Session session) { public void onMessage(Session session, Message message) { ApplicationWebsocketTransfer data = JsonUtils.fromJson(message.bodyAsString(), ApplicationWebsocketTransfer.class); + // 获取全部应用程序信息 if (data.getType().equals("getAllApplication")) { session.sendAsync(JsonUtils.toJson(new ApplicationWebsocketTransfer<>( null, diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/UIController.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/UIController.java index c1b66885cc..72f72fb41c 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/UIController.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/controller/UIController.java @@ -12,9 +12,18 @@ import java.io.InputStream; import java.util.Optional; +/** + * 前端 UI Controller + * + * @author shaokeyibb + * @since 2.3 + */ @Controller public class UIController { + /** + * 获取 index.html + */ @Get @Mapping("/") @Produces(MimeType.TEXT_HTML_VALUE) @@ -25,6 +34,9 @@ public InputStream index() throws IOException { return stream; } + /** + * 获取资源文件 + */ @Get @Mapping("/**") public void resources(Context ctx) throws IOException { diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/Application.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/Application.java index ba79c0ef3f..f5a53a0a98 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/Application.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/Application.java @@ -7,6 +7,12 @@ import java.util.Collection; +/** + * 应用程序数据 + * + * @author shaokeyibb + * @since 2.3 + */ @Data @NoArgsConstructor public class Application { diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/ApplicationWebsocketTransfer.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/ApplicationWebsocketTransfer.java index 83ced72161..e2d7d464b8 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/ApplicationWebsocketTransfer.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/ApplicationWebsocketTransfer.java @@ -5,6 +5,13 @@ import lombok.NoArgsConstructor; import org.noear.solon.lang.Nullable; +/** + * 应用程序数据传输 Dto + * + * @param 要传输的数据类型 + * @author shaokeyibb + * @since 2.3 + */ @Data @AllArgsConstructor @NoArgsConstructor diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/Detector.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/Detector.java index 8c16677119..9608deaf33 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/Detector.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/Detector.java @@ -5,6 +5,13 @@ import java.util.Map; +/** + * 监视器数据 + * + * @author shaokeyibb + * @since 2.3 + */ + @NoArgsConstructor @Data public class Detector { diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/EnvironmentInformation.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/EnvironmentInformation.java index 7e1c677124..1f3ceba6b6 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/EnvironmentInformation.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/data/EnvironmentInformation.java @@ -5,6 +5,12 @@ import java.util.Map; +/** + * 应用环境信息 + * + * @author shaokeyibb + * @since 2.3 + */ @Data @Value public class EnvironmentInformation { diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/services/ApplicationService.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/services/ApplicationService.java index 198f4c3612..e498e5ba40 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/services/ApplicationService.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/services/ApplicationService.java @@ -10,10 +10,17 @@ import org.noear.solon.annotation.Inject; import org.noear.solon.core.message.Session; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; +/** + * @author shaokeyibb + * @since 2.3 + */ @Slf4j @Component public class ApplicationService { @@ -36,6 +43,11 @@ public class ApplicationService { @Inject private ClientMonitorService clientMonitorService; + /** + * 注册 Solon Admin Client 应用程序 + * + * @param application 应用程序 + */ public void registerApplication(Application application) { String key = application.toKey(); Application persisted = applications.get(key); @@ -45,18 +57,26 @@ public void registerApplication(Application application) { } applications.put(key, application); + // 计划心跳检测 scheduleHeartbeatCheck(application); + // 向前端发送注册信息 sessions.forEach(it -> it.sendAsync(JsonUtils.toJson(new ApplicationWebsocketTransfer<>( null, "registerApplication", application )))); + // 计划客户端监视器数据获取 scheduleClientMonitor(application); log.info("Application registered: {}", application); } + /** + * 注销 Solon Admin Client 应用程序 + * + * @param application 应用程序 + */ public void unregisterApplication(Application application) { val find = applications.values().stream().filter(it -> it.equals(application)).findFirst(); if (!find.isPresent()) return; @@ -64,6 +84,7 @@ public void unregisterApplication(Application application) { applications.remove(find.get().toKey()); scheduledThreadPoolExecutor.remove(runningHeartbeatTasks.get(find.get())); scheduledThreadPoolExecutor.remove(runningClientMonitorTasks.get(find.get())); + // 向前端发送注销信息 sessions.forEach(it -> it.sendAsync(JsonUtils.toJson(new ApplicationWebsocketTransfer<>( null, "unregisterApplication", @@ -73,17 +94,24 @@ public void unregisterApplication(Application application) { log.info("Application unregistered: {}", find.get()); } + /** + * 心跳 + * + * @param application 应用程序 + */ public void heartbeatApplication(Application application) { val find = applications.values().stream().filter(it -> it.equals(application)).findFirst(); if (!find.isPresent()) return; find.get().setLastHeartbeat(System.currentTimeMillis()); + // 如果应用程序已经是 UP 状态,则不需要再次发送心跳 if (application.getStatus() == Application.Status.UP) return; + // 更新应用程序状态 find.get().setStatus(Application.Status.UP); - find.get().setLastUpTime(System.currentTimeMillis()); + // 向前端发送数据更新 sessions.forEach(it -> it.sendAsync(JsonUtils.toJson(new ApplicationWebsocketTransfer<>( null, "updateApplication", @@ -106,12 +134,14 @@ private void runHeartbeatCheck(Application application) { if (System.currentTimeMillis() - application.getLastHeartbeat() <= serverProperties.getHeartbeatInterval()) return; + // 如果应用程序已经是 DOWN 状态,则不需要再次发送心跳 if (application.getStatus() == Application.Status.DOWN) return; + // 更新应用程序状态 application.setStatus(Application.Status.DOWN); - application.setLastDownTime(System.currentTimeMillis()); + // 向前端发送数据更新 sessions.forEach(it -> it.sendAsync(JsonUtils.toJson(new ApplicationWebsocketTransfer<>( null, "updateApplication", @@ -131,6 +161,7 @@ private void scheduleClientMonitor(Application application) { private void runClientMonitor(Application application) { application.setMonitors(clientMonitorService.getMonitors(application)); + // 向前端发送数据更新 sessions.forEach(it -> it.sendAsync(JsonUtils.toJson(new ApplicationWebsocketTransfer<>( null, "updateApplication", @@ -138,10 +169,22 @@ private void runClientMonitor(Application application) { )))); } + /** + * 获取全部应用程序 + * + * @return 全部应用程序 + */ public Collection getApplications() { return applications.values(); } + /** + * 获取应用程序 + * + * @param name 应用程序名称 + * @param baseUrl 应用程序 baseUrl + * @return 应用程序 + */ public Application getApplication(String name, String baseUrl) { val find = applications.values().stream().filter(it -> it.getName().equals(name) && it.getBaseUrl().equals(baseUrl)).findFirst(); return find.orElse(null); diff --git a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/services/ClientMonitorService.java b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/services/ClientMonitorService.java index 92fb8be3ea..ddc8893ed6 100644 --- a/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/services/ClientMonitorService.java +++ b/solon-projects/solon-tool/solon-admin-server/src/main/java/org/noear/solon/admin/server/services/ClientMonitorService.java @@ -17,6 +17,10 @@ import java.util.List; import java.util.Objects; +/** + * @author shaokeyibb + * @since 2.3 + */ @Slf4j @Component public class ClientMonitorService { @@ -24,6 +28,11 @@ public class ClientMonitorService { @Inject private OkHttpClient client; + /** + * 获取应用程序的监视器 + * @param application 应用程序 + * @return 应用程序的监视器 + */ public Collection getMonitors(Application application) { val clientUrl = application.getBaseUrl().replaceAll("/+$", ""); try (Response response = client.newCall(new Request.Builder()