diff --git a/common/src/main/java/com/usthe/common/entity/job/Job.java b/common/src/main/java/com/usthe/common/entity/job/Job.java index f87413b..666e99b 100644 --- a/common/src/main/java/com/usthe/common/entity/job/Job.java +++ b/common/src/main/java/com/usthe/common/entity/job/Job.java @@ -80,18 +80,10 @@ public class Job { */ private transient List> priorMetrics; - /** - * collector使用 - 构造初始化标志 - */ - private transient boolean isConstruct = false; - /** * collector使用 - 构造初始化指标组 */ - public synchronized void constructMetrics() { - if (isConstruct) { - return; - } + public synchronized void constructPriorMetrics() { Map> map = metrics.stream() .peek(metric -> { // 判断是否配置aliasFields 没有则配置默认 @@ -134,26 +126,30 @@ public class Job { * 返回有数据集合表示:获取到下一组优先级的指标组任务 */ public synchronized Set getNextCollectMetrics(Metrics metrics, boolean first) { - if (!isConstruct || priorMetrics == null || priorMetrics.isEmpty()) { + if (priorMetrics == null || priorMetrics.isEmpty()) { return null; } Set metricsSet = priorMetrics.get(0); if (first) { - log.error("metrics must has one [availability] metrics at least."); + if (metricsSet.isEmpty()) { + log.error("metrics must has one [availability] metrics at least."); + + } return metricsSet; } if (metrics == null) { log.error("metrics can not null when not first get"); + return null; } - if (metrics != null && !metricsSet.remove(metrics)) { + if (!metricsSet.remove(metrics)) { log.error("Job {} appId {} app {} metrics {} remove empty error in priorMetrics.", id, appId, app, metrics.getName()); } if (metricsSet.isEmpty()) { - if (priorMetrics.size() == 1) { + priorMetrics.remove(0); + if (priorMetrics.size() == 0) { return null; } - priorMetrics.remove(0); return priorMetrics.get(0); } else { return Collections.emptySet(); diff --git a/manager/pom.xml b/manager/pom.xml index 0bf1bcb..75689fe 100644 --- a/manager/pom.xml +++ b/manager/pom.xml @@ -15,4 +15,34 @@ + + + + com.usthe.tancloud + common + 1.0-SNAPSHOT + + + + com.usthe.tancloud + scheduler + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + io.springfox + springfox-boot-starter + + + \ No newline at end of file diff --git a/manager/src/main/java/com/usthe/manager/Manager.java b/manager/src/main/java/com/usthe/manager/Manager.java new file mode 100644 index 0000000..2b95f0e --- /dev/null +++ b/manager/src/main/java/com/usthe/manager/Manager.java @@ -0,0 +1,17 @@ +package com.usthe.manager; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author tomsun28 + * @date 2021/11/11 16:45 + */ + +@SpringBootApplication +public class Manager { + + public static void main(String[] args) { + SpringApplication.run(Manager.class, args); + } +} diff --git a/manager/src/main/java/com/usthe/manager/config/SwaggerConfig.java b/manager/src/main/java/com/usthe/manager/config/SwaggerConfig.java new file mode 100644 index 0000000..4d2b35b --- /dev/null +++ b/manager/src/main/java/com/usthe/manager/config/SwaggerConfig.java @@ -0,0 +1,48 @@ +package com.usthe.manager.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.oas.annotations.EnableOpenApi; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +import java.util.Collections; + +/** + * swagger config + * url: /swagger-ui/ + * @author tomsun28 + * @date 2021/11/11 17:01 + */ +@Configuration +@EnableOpenApi +public class SwaggerConfig { + + @Bean + public Docket docket(){ + return new Docket(DocumentationType.OAS_30) + .apiInfo(apiInfo()) + .enable(true) + .groupName("usthe.com") + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo apiInfo(){ + return new ApiInfo( + "usthe api", + "monitor project", + "v1.0", + "usthe.com", + new Contact("tom", "usthe.com", "tomsun28@outlook.com"), + "Apache 2.0", + "http://www.apache.org/licenses/LICENSE-2.0", + Collections.emptyList()); + } +} diff --git a/manager/src/main/resources/logback-spring.xml b/manager/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..90e6569 --- /dev/null +++ b/manager/src/main/resources/logback-spring.xml @@ -0,0 +1,79 @@ + + + + + + + + + 1-%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger - %msg%n + UTF-8 + + + + + + + + logs/${application_name}-%d{yyyy-MM-dd}.%i.log + + + 200MB + + + + true + + + ===%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n + utf-8 + + + + + + logs/${application_name}-%d{yyyy-MM-dd}-error.%i.log + + 200MB + + + + true + + + ===%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger Line:%-3L - %msg%n + utf-8 + + + + ERROR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 99dc15d..41fec05 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ 1.7.21 2.3.0 1.18.20 + 3.0.0 5.7.0 4.0.2 @@ -44,6 +45,11 @@ jaxb-api ${xml.bind.version} + + io.springfox + springfox-boot-starter + ${swagger.version} +