mirror of https://gitee.com/stylefeng/roses
【8.3.2】更新资源汇报过程,可以接入本地化汇报资源
parent
2fa8f9a900
commit
0570c8ca74
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue