【8.3.2】更新资源汇报过程,可以接入本地化汇报资源

master
stylefeng 2024-11-11 22:54:08 +08:00
parent 2fa8f9a900
commit 0570c8ca74
3 changed files with 13 additions and 35 deletions

View File

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

View File

@ -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<SysResourcePersistencePojo> sysResourcePersistencePojoList) {

View File

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