Commit 8546da38 by xmh

<fix> caffeine 版本号

<fix> 更好地获取鉴权信息
<feat> 运维服务注册时的默认IP以及注册信息打印
<fix> 数据概览数据无任务id情况
1 parent 9392020c
...@@ -112,7 +112,6 @@ ...@@ -112,7 +112,6 @@
<dependency> <dependency>
<groupId>com.github.ben-manes.caffeine</groupId> <groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId> <artifactId>caffeine</artifactId>
<version>3.0.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
......
...@@ -13,6 +13,7 @@ import javax.annotation.Resource; ...@@ -13,6 +13,7 @@ import javax.annotation.Resource;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -31,7 +32,7 @@ public class CacheUtils { ...@@ -31,7 +32,7 @@ public class CacheUtils {
@Resource @Resource
private OpsClient opsClient; private OpsClient opsClient;
@LocalCache(value = "task_map", duration = 1) @LocalCache(value = "task_map", duration = 20, timeunit = TimeUnit.SECONDS)
public synchronized Map<String, Task> getTaskMap() { public synchronized Map<String, Task> getTaskMap() {
JsonMessageUtil.JsonMessage<List<Task>> response = null; JsonMessageUtil.JsonMessage<List<Task>> response = null;
try { try {
......
...@@ -23,10 +23,7 @@ import javax.annotation.Resource; ...@@ -23,10 +23,7 @@ import javax.annotation.Resource;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
...@@ -134,12 +131,12 @@ public class AuthorizationFilter implements GlobalFilter { ...@@ -134,12 +131,12 @@ public class AuthorizationFilter implements GlobalFilter {
if (StringUtils.isNotEmpty(token)) { if (StringUtils.isNotEmpty(token)) {
return token; return token;
} }
token = headers.getFirst("authorization"); token = Optional.ofNullable(headers.getFirst("Authorization")).orElse(headers.getFirst("authorization"));
if (StringUtils.isNotBlank(token)) { if (StringUtils.isNotBlank(token)) {
return token; return token;
} }
MultiValueMap<String, String> queryParams = request.getQueryParams(); MultiValueMap<String, String> queryParams = request.getQueryParams();
token = queryParams.getFirst("authorization"); token = Optional.ofNullable(queryParams.getFirst("Authorization")).orElse(queryParams.getFirst("authorization"));
if (StringUtils.isNotBlank(token)) { if (StringUtils.isNotBlank(token)) {
return token; return token;
} }
...@@ -148,7 +145,7 @@ public class AuthorizationFilter implements GlobalFilter { ...@@ -148,7 +145,7 @@ public class AuthorizationFilter implements GlobalFilter {
return token; return token;
} }
MultiValueMap<String, HttpCookie> cookies = request.getCookies(); MultiValueMap<String, HttpCookie> cookies = request.getCookies();
HttpCookie auc = cookies.getFirst("authorization"); HttpCookie auc = Optional.ofNullable(cookies.getFirst("Authorization")).orElse(cookies.getFirst("authorization"));
if (auc != null) { if (auc != null) {
token = auc.getValue(); token = auc.getValue();
if (StringUtils.isNotBlank(token)) { if (StringUtils.isNotBlank(token)) {
......
...@@ -3,10 +3,12 @@ package com.viontech.fanxing.ops.controller.main; ...@@ -3,10 +3,12 @@ package com.viontech.fanxing.ops.controller.main;
import com.viontech.fanxing.commons.base.BaseController; import com.viontech.fanxing.commons.base.BaseController;
import com.viontech.fanxing.ops.model.OpsServer; import com.viontech.fanxing.ops.model.OpsServer;
import com.viontech.fanxing.ops.service.main.OpsServerService; import com.viontech.fanxing.ops.service.main.OpsServerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/** /**
* . * .
...@@ -23,7 +25,10 @@ public class OpsController { ...@@ -23,7 +25,10 @@ public class OpsController {
private OpsServerService opsServerService; private OpsServerService opsServerService;
@PostMapping("register") @PostMapping("register")
public Object register(@RequestBody OpsServer opsServer) { public Object register(@RequestBody OpsServer opsServer, HttpServletRequest httpServletRequest) {
if (StringUtils.isEmpty(opsServer.getIp())) {
opsServer.setIp(httpServletRequest.getRemoteHost());
}
opsServerService.register(opsServer); opsServerService.register(opsServer);
return BaseController.success(); return BaseController.success();
} }
......
...@@ -19,4 +19,12 @@ public class OpsServer { ...@@ -19,4 +19,12 @@ public class OpsServer {
private String name; private String name;
private Long lastHeartBeat; private Long lastHeartBeat;
@Override
public String toString() {
return "OpsServer{" +
"ip='" + ip + '\'' +
", port=" + port +
", name='" + name + '\'' +
'}';
}
} }
...@@ -31,6 +31,7 @@ public class OpsServerService { ...@@ -31,6 +31,7 @@ public class OpsServerService {
private RedissonClient redissonClient; private RedissonClient redissonClient;
public void register(OpsServer opsServer) { public void register(OpsServer opsServer) {
log.info("收到运维注册信息:{}",opsServer.toString());
opsServer.setLastHeartBeat(System.currentTimeMillis()); opsServer.setLastHeartBeat(System.currentTimeMillis());
addOrUpdateOpsServer(opsServer); addOrUpdateOpsServer(opsServer);
} }
......
...@@ -87,13 +87,15 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf ...@@ -87,13 +87,15 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
List<Traffic> traffic = trafficMapper.selectByExample(trafficExample); List<Traffic> traffic = trafficMapper.selectByExample(trafficExample);
for (Traffic t : traffic) { for (Traffic t : traffic) {
DataOverViewModel dov = resultMap.computeIfAbsent(t.getTaskId(), x -> { if (t.getTaskId() != null) {
DataOverViewModel temp = new DataOverViewModel(); DataOverViewModel dov = resultMap.computeIfAbsent(t.getTaskId(), x -> {
temp.setTaskId(x); DataOverViewModel temp = new DataOverViewModel();
temp.setTaskName(taskMap.get(x).getName()); temp.setTaskId(x);
return temp; temp.setTaskName(taskMap.get(x).getName());
}); return temp;
dov.setTraffic(t.getCount()); });
dov.setTraffic(t.getCount());
}
} }
FlowEventExample flowEventExample = new FlowEventExample(); FlowEventExample flowEventExample = new FlowEventExample();
...@@ -106,13 +108,15 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf ...@@ -106,13 +108,15 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
flowEventExample.setOrderByClause("task_id"); flowEventExample.setOrderByClause("task_id");
List<FlowEvent> flowEvents = flowEventService.getMapper().selectByExample(flowEventExample); List<FlowEvent> flowEvents = flowEventService.getMapper().selectByExample(flowEventExample);
for (FlowEvent f : flowEvents) { for (FlowEvent f : flowEvents) {
DataOverViewModel dov = resultMap.computeIfAbsent(f.getTaskId(), x -> { if (f.getTaskId() != null) {
DataOverViewModel temp = new DataOverViewModel(); DataOverViewModel dov = resultMap.computeIfAbsent(f.getTaskId(), x -> {
temp.setTaskId(x); DataOverViewModel temp = new DataOverViewModel();
temp.setTaskName(taskMap.get(x).getName()); temp.setTaskId(x);
return temp; temp.setTaskName(taskMap.get(x).getName());
}); return temp;
dov.setFlow(f.getCount()); });
dov.setFlow(f.getCount());
}
} }
BehaviorExample behaviorExample = new BehaviorExample(); BehaviorExample behaviorExample = new BehaviorExample();
...@@ -125,13 +129,15 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf ...@@ -125,13 +129,15 @@ public class TrafficServiceImpl extends BaseServiceImpl<Traffic> implements Traf
behaviorExample.setOrderByClause("task_id"); behaviorExample.setOrderByClause("task_id");
List<Behavior> behaviors = behaviorService.getMapper().selectByExample(behaviorExample); List<Behavior> behaviors = behaviorService.getMapper().selectByExample(behaviorExample);
for (Behavior b : behaviors) { for (Behavior b : behaviors) {
DataOverViewModel dov = resultMap.computeIfAbsent(b.getTaskId(), x -> { if (b.getTaskId() != null) {
DataOverViewModel temp = new DataOverViewModel(); DataOverViewModel dov = resultMap.computeIfAbsent(b.getTaskId(), x -> {
temp.setTaskId(x); DataOverViewModel temp = new DataOverViewModel();
temp.setTaskName(taskMap.get(x).getName()); temp.setTaskId(x);
return temp; temp.setTaskName(taskMap.get(x).getName());
}); return temp;
dov.setBehavior(b.getCount()); });
dov.setBehavior(b.getCount());
}
} }
Collection<DataOverViewModel> values = resultMap.values(); Collection<DataOverViewModel> values = resultMap.values();
List<DataOverViewModel> collect = values.stream().filter(x -> x.getTaskId() != null).sorted(Comparator.comparingLong(DataOverViewModel::getTaskId)).collect(Collectors.toList()); List<DataOverViewModel> collect = values.stream().filter(x -> x.getTaskId() != null).sorted(Comparator.comparingLong(DataOverViewModel::getTaskId)).collect(Collectors.toList());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!