From 0570c8ca743678f0e4e091444da038c485151749 Mon Sep 17 00:00:00 2001 From: stylefeng Date: Mon, 11 Nov 2024 22:54:08 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.3.2=E3=80=91=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B1=87=E6=8A=A5=E8=BF=87=E7=A8=8B=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=8E=A5=E5=85=A5=E6=9C=AC=E5=9C=B0=E5=8C=96?= =?UTF-8?q?=E6=B1=87=E6=8A=A5=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scanner/ResourceReportListener.java | 14 ++++++---- .../devops/LocalizedDevOpsReportImpl.java | 6 ++-- .../ProjectResourceAutoConfiguration.java | 28 ------------------- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/ResourceReportListener.java b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/ResourceReportListener.java index abd55f2f1..25dc9d9c5 100644 --- a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/ResourceReportListener.java +++ b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/ResourceReportListener.java @@ -27,7 +27,6 @@ package cn.stylefeng.roses.kernel.scanner; import cn.hutool.core.util.ObjectUtil; import cn.stylefeng.roses.kernel.rule.listener.ApplicationReadyListener; import cn.stylefeng.roses.kernel.scanner.api.DevOpsDetectApi; -import cn.stylefeng.roses.kernel.scanner.api.DevOpsReportApi; import cn.stylefeng.roses.kernel.scanner.api.ResourceCollectorApi; import cn.stylefeng.roses.kernel.scanner.api.ResourceReportApi; import cn.stylefeng.roses.kernel.scanner.api.constants.ScannerConstants; @@ -37,6 +36,8 @@ import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.ReportResourceParam; import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.ResourceDefinition; import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.SysResourcePersistencePojo; import cn.stylefeng.roses.kernel.scanner.api.pojo.scanner.ScannerProperties; +import cn.stylefeng.roses.kernel.scanner.devops.DefaultDevOpsReportImpl; +import cn.stylefeng.roses.kernel.scanner.devops.LocalizedDevOpsReportImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ConfigurableApplicationContext; @@ -90,14 +91,17 @@ public class ResourceReportListener extends ApplicationReadyListener implements } catch (Exception ignored) { } - // 判断是否配置了host或者本地有集成化的devops平台 - if (ObjectUtil.isNotEmpty(devOpsReportProperties.getServerHost()) || devOpsDetectApi != null) { - DevOpsReportApi devOpsReportApi = applicationContext.getBean(DevOpsReportApi.class); + // 如果本地有集成化的devops平台,则直接调用devops平台接口 + if (devOpsDetectApi != null) { + new LocalizedDevOpsReportImpl(devOpsDetectApi).reportResources(devOpsReportProperties, persistencePojos); + } + // 判断是否配置了host或者本地有集成化的devops平台 + else if (ObjectUtil.isNotEmpty(devOpsReportProperties.getServerHost())) { // 异步化汇报给devops CompletableFuture.runAsync(() -> { long beginDevopsReport = System.currentTimeMillis(); - devOpsReportApi.reportResources(devOpsReportProperties, persistencePojos); + new DefaultDevOpsReportImpl().reportResources(devOpsReportProperties, persistencePojos); log.info("向DevOps平台汇报资源信息完成,耗时:{}ms", (System.currentTimeMillis() - beginDevopsReport)); }).exceptionally(ex -> { log.error("向DevOps平台汇报异常出现网络错误,如无法联通DevOps平台可关闭相关配置。", ex); diff --git a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/devops/LocalizedDevOpsReportImpl.java b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/devops/LocalizedDevOpsReportImpl.java index 9a63d47e4..e930e6d2d 100644 --- a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/devops/LocalizedDevOpsReportImpl.java +++ b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/scanner/devops/LocalizedDevOpsReportImpl.java @@ -5,7 +5,6 @@ import cn.stylefeng.roses.kernel.scanner.api.DevOpsReportApi; import cn.stylefeng.roses.kernel.scanner.api.pojo.devops.DevOpsReportProperties; import cn.stylefeng.roses.kernel.scanner.api.pojo.devops.DevOpsReportResourceParam; import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.SysResourcePersistencePojo; -import jakarta.annotation.Resource; import java.util.List; @@ -17,9 +16,12 @@ import java.util.List; */ public class LocalizedDevOpsReportImpl implements DevOpsReportApi { - @Resource private DevOpsDetectApi devOpsDetectApi; + public LocalizedDevOpsReportImpl(DevOpsDetectApi devOpsDetectApi) { + this.devOpsDetectApi = devOpsDetectApi; + } + @Override public void reportResources(DevOpsReportProperties devOpsReportProperties, List sysResourcePersistencePojoList) { diff --git a/kernel-d-scanner/scanner-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/scanner/starter/ProjectResourceAutoConfiguration.java b/kernel-d-scanner/scanner-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/scanner/starter/ProjectResourceAutoConfiguration.java index 5d6a7e3ac..d89ea3559 100644 --- a/kernel-d-scanner/scanner-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/scanner/starter/ProjectResourceAutoConfiguration.java +++ b/kernel-d-scanner/scanner-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/scanner/starter/ProjectResourceAutoConfiguration.java @@ -27,14 +27,10 @@ package cn.stylefeng.roses.kernel.scanner.starter; import cn.hutool.core.util.StrUtil; import cn.stylefeng.roses.kernel.scanner.ApiResourceScanner; import cn.stylefeng.roses.kernel.scanner.DefaultResourceCollector; -import cn.stylefeng.roses.kernel.scanner.api.DevOpsDetectApi; import cn.stylefeng.roses.kernel.scanner.api.ResourceCollectorApi; import cn.stylefeng.roses.kernel.scanner.api.pojo.devops.DevOpsReportProperties; import cn.stylefeng.roses.kernel.scanner.api.pojo.scanner.ScannerProperties; -import cn.stylefeng.roses.kernel.scanner.devops.DefaultDevOpsReportImpl; -import cn.stylefeng.roses.kernel.scanner.devops.LocalizedDevOpsReportImpl; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -116,28 +112,4 @@ public class ProjectResourceAutoConfiguration { return new DefaultResourceCollector(); } - /** - * 向DevOps平台汇报资源,传统方式,远程资源汇报 - * - * @author fengshuonan - * @since 2022/4/2 14:41 - */ - @Bean - @ConditionalOnMissingBean(DevOpsDetectApi.class) - public DefaultDevOpsReportImpl defaultDevOpsReport() { - return new DefaultDevOpsReportImpl(); - } - - /** - * 向DevOps平台汇报资源,新方式,本地化集成运维平台 - * - * @author fengshuonan - * @since 2022/10/18 0:03 - */ - @Bean - @ConditionalOnBean(DevOpsDetectApi.class) - public LocalizedDevOpsReportImpl localizedDevOpsReport() { - return new LocalizedDevOpsReportImpl(); - } - }