Commit 4139936ca4a2a8585997a9e76186adb40611f64e
1 parent
8a86f174
Exists in
master
optimize server
Showing
4 changed files
with
78 additions
and
12 deletions
Show diff stats
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/HeartbeatManagerImpl.java
@@ -142,7 +142,7 @@ public class HeartbeatManagerImpl implements HeartbeatManager { | @@ -142,7 +142,7 @@ public class HeartbeatManagerImpl implements HeartbeatManager { | ||
142 | private void createLog(ServerInstance item) { | 142 | private void createLog(ServerInstance item) { |
143 | try { | 143 | try { |
144 | AnalysisHeartbeatLogEntity log = new AnalysisHeartbeatLogEntity(); | 144 | AnalysisHeartbeatLogEntity log = new AnalysisHeartbeatLogEntity(); |
145 | - log.setServerUrl(item.getLatestUrlWithParam()); | 145 | + log.setServerUrl(item.getInstance().getUrl()); |
146 | log.setInstanceCode(item.getIdentity()); | 146 | log.setInstanceCode(item.getIdentity()); |
147 | if(item.getLatestServerResponse() == null) { | 147 | if(item.getLatestServerResponse() == null) { |
148 | log.setResponse("null"); | 148 | log.setResponse("null"); |
@@ -281,6 +281,7 @@ public class HeartbeatManagerImpl implements HeartbeatManager { | @@ -281,6 +281,7 @@ public class HeartbeatManagerImpl implements HeartbeatManager { | ||
281 | } | 281 | } |
282 | this.analysisHeartbeatInstanceRepository.updateEntityById(form.getSQLUpdateList(), instance.getId(), null); | 282 | this.analysisHeartbeatInstanceRepository.updateEntityById(form.getSQLUpdateList(), instance.getId(), null); |
283 | try { | 283 | try { |
284 | + instance = this.analysisHeartbeatInstanceRepository.findEntityByID(instance.getId(), null); | ||
284 | if(AnalysisHeartbeatInstanceRepository.STATUS_DISABLE == instance.getStatus().intValue()) { | 285 | if(AnalysisHeartbeatInstanceRepository.STATUS_DISABLE == instance.getStatus().intValue()) { |
285 | this.unregistryRuntimeInstance(instance); | 286 | this.unregistryRuntimeInstance(instance); |
286 | }else { | 287 | }else { |
src/main/java/com/taover/bazhuayun/analysis/web/module/heartbeat/bean/ServerInstance.java
@@ -15,16 +15,12 @@ public class ServerInstance implements Instance { | @@ -15,16 +15,12 @@ public class ServerInstance implements Instance { | ||
15 | private int errorServerResponseCount = 0; | 15 | private int errorServerResponseCount = 0; |
16 | private boolean detectNewErrorServerResponse; | 16 | private boolean detectNewErrorServerResponse; |
17 | private boolean isSendNewHeartbeat; | 17 | private boolean isSendNewHeartbeat; |
18 | - private String latestUrlWithParam; | ||
19 | 18 | ||
20 | public ServerInstance(AnalysisHeartbeatInstanceEntity instance) throws Exception { | 19 | public ServerInstance(AnalysisHeartbeatInstanceEntity instance) throws Exception { |
21 | super(); | 20 | super(); |
22 | if(!instance.getUrl().toLowerCase().startsWith("http")) { | 21 | if(!instance.getUrl().toLowerCase().startsWith("http")) { |
23 | throw new Exception("目前只支持http协议的URL"); | 22 | throw new Exception("目前只支持http协议的URL"); |
24 | } | 23 | } |
25 | - if(instance.getFixRateSec() < 60) { | ||
26 | - throw new Exception("固定时间间隔不允许小于60s"); | ||
27 | - } | ||
28 | this.instance = instance; | 24 | this.instance = instance; |
29 | } | 25 | } |
30 | 26 | ||
@@ -43,10 +39,9 @@ public class ServerInstance implements Instance { | @@ -43,10 +39,9 @@ public class ServerInstance implements Instance { | ||
43 | try { | 39 | try { |
44 | this.latestRequestUnixtime = this.serverUnixtimeBaseline; | 40 | this.latestRequestUnixtime = this.serverUnixtimeBaseline; |
45 | this.isSendNewHeartbeat = true; | 41 | this.isSendNewHeartbeat = true; |
46 | - this.latestUrlWithParam = this.instance.getUrl() + this.getUrlParams(); | ||
47 | - UtilLog.infoForMessage("向code["+this.getIdentity()+"],url["+this.latestUrlWithParam+"]发送心跳请求", ServerInstance.class); | 42 | + UtilLog.infoForMessage("向code["+this.getIdentity()+"],url["+this.instance.getUrl()+"]发送心跳请求", ServerInstance.class); |
48 | 43 | ||
49 | - this.latestServerResponse = ServerResponse.createByJSONString(UtilHttpByOkHttp.sendGet(this.latestUrlWithParam, null, this.instance.getMaxWaitSec())); | 44 | + this.latestServerResponse = ServerResponse.createByJSONString(UtilHttpByOkHttp.sendGet(this.instance.getUrl(), null, this.instance.getMaxWaitSec())); |
50 | if(this.latestServerResponse.isCodeOk()) { | 45 | if(this.latestServerResponse.isCodeOk()) { |
51 | this.errorServerResponseCount = 0; | 46 | this.errorServerResponseCount = 0; |
52 | } | 47 | } |
@@ -114,8 +109,4 @@ public class ServerInstance implements Instance { | @@ -114,8 +109,4 @@ public class ServerInstance implements Instance { | ||
114 | public boolean isSendNewHeartbeat() { | 109 | public boolean isSendNewHeartbeat() { |
115 | return isSendNewHeartbeat; | 110 | return isSendNewHeartbeat; |
116 | } | 111 | } |
117 | - | ||
118 | - public String getLatestUrlWithParam() { | ||
119 | - return latestUrlWithParam; | ||
120 | - } | ||
121 | } | 112 | } |
src/main/java/com/taover/bazhuayun/analysis/web/permission/HttpHeaderFilter.java
0 → 100644
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.permission; | ||
2 | + | ||
3 | +import java.io.IOException; | ||
4 | + | ||
5 | +import javax.servlet.Filter; | ||
6 | +import javax.servlet.FilterChain; | ||
7 | +import javax.servlet.FilterConfig; | ||
8 | +import javax.servlet.ServletException; | ||
9 | +import javax.servlet.ServletRequest; | ||
10 | +import javax.servlet.ServletResponse; | ||
11 | +import javax.servlet.http.HttpServletRequest; | ||
12 | +import javax.servlet.http.HttpServletResponse; | ||
13 | + | ||
14 | +import com.taover.util.UtilLog; | ||
15 | + | ||
16 | +public class HttpHeaderFilter implements Filter{ | ||
17 | + @Override | ||
18 | + public void init(FilterConfig filterConfig) throws ServletException { | ||
19 | + UtilLog.infoForMessage("HttpHeaderFilter:init", this.getClass()); | ||
20 | + } | ||
21 | + | ||
22 | + @Override | ||
23 | + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
24 | + throws IOException, ServletException { | ||
25 | + HttpServletResponse httpResponse = (HttpServletResponse) response; | ||
26 | + HttpServletRequest httpRequest = (HttpServletRequest) request; | ||
27 | + | ||
28 | + httpResponse.setHeader("Access-Control-Allow-Origin", httpRequest.getHeader("Origin")); | ||
29 | + httpResponse.setHeader("Access-Control-Allow-Credentials", "true"); | ||
30 | + httpResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD"); | ||
31 | + httpResponse.setHeader("Access-Control-Allow-Headers", "Authorization,content-type"); | ||
32 | + httpResponse.setHeader("Access-Control-Expose-Headers", ""); | ||
33 | + httpResponse.setHeader("Access-Control-Max-Age", "1728000"); | ||
34 | + httpResponse.setHeader("Vary", "Origin"); | ||
35 | + httpResponse.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); | ||
36 | + | ||
37 | + //跨域prelight options请求直接返回 | ||
38 | + if("options".equals(httpRequest.getMethod().toLowerCase())){ | ||
39 | + return; | ||
40 | + } | ||
41 | + chain.doFilter(httpRequest, httpResponse); | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public void destroy() { | ||
46 | + UtilLog.infoForMessage("HttpHeaderFilter:destory", this.getClass()); | ||
47 | + } | ||
48 | +} |
src/main/java/com/taover/bazhuayun/analysis/web/permission/HttpHeaderFilterConfig.java
0 → 100644
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +package com.taover.bazhuayun.analysis.web.permission; | ||
2 | + | ||
3 | +import java.util.EnumSet; | ||
4 | + | ||
5 | +import javax.servlet.DispatcherType; | ||
6 | +import javax.servlet.Filter; | ||
7 | + | ||
8 | +import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
9 | +import org.springframework.context.annotation.Bean; | ||
10 | +import org.springframework.context.annotation.Configuration; | ||
11 | + | ||
12 | +@Configuration | ||
13 | +public class HttpHeaderFilterConfig { | ||
14 | + public static final int ORDER_HTTP_HEADER_FILTER = 0; | ||
15 | + | ||
16 | + @Bean | ||
17 | + public FilterRegistrationBean<Filter> mySsTokenFilter() { | ||
18 | + FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<Filter>(); | ||
19 | + registration.setFilter(new HttpHeaderFilter()); | ||
20 | + registration.setEnabled(true); | ||
21 | + registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class)); | ||
22 | + registration.setOrder(ORDER_HTTP_HEADER_FILTER); | ||
23 | + return registration; | ||
24 | + } | ||
25 | +} | ||
26 | + |