[monitor]服务端编译打包脚本

This commit is contained in:
tomsun28
2021-12-26 15:08:54 +08:00
parent 7e41f64491
commit faf5bc7b87
17 changed files with 309 additions and 66 deletions

View File

@@ -113,16 +113,63 @@
</dependencies>
<build>
<finalName>hertz-beat</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.yml</include>
<include>sureness.yml</include>
<include>banner.txt</include>
<include>db/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.13</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<classesDirectory>target/classes/</classesDirectory>
<archive>
<!--生成的jar包不包含maven描述相关文件-->
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<!--项目启动类-->
<mainClass>com.usthe.manager.Manager</mainClass>
<useUniqueVersions>false</useUniqueVersions>
<!--第三方JAR加入类构建的路径maven-dependency-plugin-->
<addClasspath>true</addClasspath>
<!--外部依赖jar包的位置-->
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>. config</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!--关键插件,maven提供的assembly插件,需要放在最后-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>make-zip</id>
<!--绑定的maven操作-->
<phase>package</phase>
<!--运行一次-->
<goals>
<goal>repackage</goal>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>../assembly/server/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>

View File

@@ -94,7 +94,7 @@ public class DispatchAlarm {
}
} else {
// 若是恢复告警 需对监控状态进行恢复
if (alert.getStatus() == 2) {
if (alert.getStatus() == CommonConstants.ALERT_STATUS_CODE_RESTORED) {
monitorService.updateMonitorStatus(alert.getMonitorId(), CommonConstants.AVAILABLE_CODE);
}
}

View File

@@ -0,0 +1,128 @@
package com.usthe.manager.config;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders;
import org.springframework.boot.autoconfigure.web.WebProperties;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
/**
* 同DefaultErrorViewResolver 解决angular静态网站资源前端路由问题 把404的网站请求给angular前端进行路由
* @author tom
* @date 2021/12/24 21:07
*/
@Configuration
public class AngularErrorViewResolver implements ErrorViewResolver, Ordered {
private static final Map<HttpStatus.Series, String> SERIES_VIEWS;
private static final String NOT_FOUND_CODE = "404";
static {
Map<HttpStatus.Series, String> views = new EnumMap<>(HttpStatus.Series.class);
views.put(HttpStatus.Series.CLIENT_ERROR, "4xx");
views.put(HttpStatus.Series.SERVER_ERROR, "5xx");
SERIES_VIEWS = Collections.unmodifiableMap(views);
}
private ApplicationContext applicationContext;
private final WebProperties.Resources resources;
private final TemplateAvailabilityProviders templateAvailabilityProviders;
private int order = Ordered.LOWEST_PRECEDENCE;
public AngularErrorViewResolver(ApplicationContext applicationContext, WebProperties.Resources resources) {
Assert.notNull(applicationContext, "ApplicationContext must not be null");
Assert.notNull(resources, "Resources must not be null");
this.applicationContext = applicationContext;
this.resources = resources;
this.templateAvailabilityProviders = new TemplateAvailabilityProviders(applicationContext);
}
@Override
public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map<String, Object> model) {
ModelAndView modelAndView = resolve(String.valueOf(status.value()), model);
if (modelAndView == null && SERIES_VIEWS.containsKey(status.series())) {
modelAndView = resolve(SERIES_VIEWS.get(status.series()), model);
}
return modelAndView;
}
private ModelAndView resolve(String viewName, Map<String, Object> model) {
String errorViewName = "error/" + viewName;
if (NOT_FOUND_CODE.equals(viewName)) {
errorViewName = "index";
}
TemplateAvailabilityProvider provider = this.templateAvailabilityProviders.getProvider(errorViewName,
this.applicationContext);
if (provider != null) {
return new ModelAndView(errorViewName, model);
}
return resolveResource(errorViewName, model);
}
private ModelAndView resolveResource(String viewName, Map<String, Object> model) {
for (String location : this.resources.getStaticLocations()) {
try {
Resource resource = this.applicationContext.getResource(location);
resource = resource.createRelative(viewName + ".html");
if (resource.exists()) {
return new ModelAndView(new HtmlResourceView(resource), model);
}
}
catch (Exception ex) {
}
}
return null;
}
@Override
public int getOrder() {
return this.order;
}
public void setOrder(int order) {
this.order = order;
}
/**
* {@link View} backed by an HTML resource.
*/
private static class HtmlResourceView implements View {
private Resource resource;
HtmlResourceView(Resource resource) {
this.resource = resource;
}
@Override
public String getContentType() {
return MediaType.TEXT_HTML_VALUE;
}
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.setContentType(getContentType());
FileCopyUtils.copy(this.resource.getInputStream(), response.getOutputStream());
}
}
}

View File

@@ -8,7 +8,6 @@ import com.usthe.manager.pojo.dto.ParamDefineDto;
import com.usthe.manager.pojo.entity.ParamDefine;
import com.usthe.manager.service.AppService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.common.protocol.types.Field;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service;
@@ -18,7 +17,6 @@ import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
@@ -123,12 +121,11 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
public void run(String... args) throws Exception {
// 读取app定义配置加载到内存中 define/app/*.yml
Yaml yaml = new Yaml();
String defineAppPath = "define" + File.separator + "app";
URL url = Thread.currentThread().getContextClassLoader().getResource(defineAppPath);
assert url != null;
File directory = new File(url.toURI());
String classpath = this.getClass().getResource(File.separator).getPath();
String defineAppPath = classpath + File.separator + "define" + File.separator + "app";
File directory = new File(defineAppPath);
if (!directory.exists() || directory.listFiles() == null) {
throw new IllegalArgumentException("define app directory not exist");
throw new IllegalArgumentException("define app directory not exist: " + defineAppPath);
}
for (File appFile : Objects.requireNonNull(directory.listFiles())) {
if (appFile.exists()) {
@@ -142,12 +139,10 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
}
}
// 读取监控参数定义配置加载到数据库中 define/param/*.yml
String defineParamPath = "define" + File.separator + "param";
url = Thread.currentThread().getContextClassLoader().getResource(defineParamPath);
assert url != null;
directory = new File(url.toURI());
String defineParamPath = classpath + File.separator + "define" + File.separator + "param";
directory = new File(defineParamPath);
if (!directory.exists() || directory.listFiles() == null) {
throw new IllegalArgumentException("define param directory not exist");
throw new IllegalArgumentException("define param directory not exist: " + defineParamPath);
}
for (File appFile : Objects.requireNonNull(directory.listFiles())) {
if (appFile.exists()) {

View File

@@ -12,6 +12,8 @@ resourceRole:
excludedResource:
- /account/auth/form===post
- /i18n/**===get
# web ui 静态资源
- /console/**===get
- /**/*.html===get
- /**/*.js===get
- /**/*.css===get
@@ -19,10 +21,11 @@ excludedResource:
- /**/*.ttf===get
- /**/*.png===get
- /**/*.gif===get
- /**/*.png===*
# swagger ui 资源
- /swagger-resources/**===get
- /v2/api-docs===get
- /v3/api-docs===get
- /**/*.png===*
# account info
# there are three account: admin, root, tom