Commit ed98d597 by xmh

<feat> 完善校时配置下发功能

<refactor> 重构导出代码
<fix> 数据概览添加数据量默认值 0
1 parent 884f56a0
......@@ -72,7 +72,6 @@ public class AuthorizationFilter implements GlobalFilter {
}
private ImmutablePair<Boolean, String> checkToken(String token) {
// todo authorize
String username;
try {
Map<String, String> api = new HashMap<>(2);
......
......@@ -3,10 +3,8 @@ package com.viontech.fanxing.ops.controller.main;
import com.viontech.fanxing.commons.base.BaseController;
import com.viontech.fanxing.ops.model.OpsServer;
import com.viontech.fanxing.ops.service.main.OpsServerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
......@@ -30,4 +28,10 @@ public class OpsController {
return BaseController.success();
}
@PostMapping("updateVaServer")
public Object updateVaServer(@RequestParam String[] devIdArr, @RequestParam MultipartFile file) {
opsServerService.updateVaServer(devIdArr, file);
return BaseController.success();
}
}
......@@ -8,7 +8,9 @@ import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.ContentExample;
import com.viontech.fanxing.commons.model.main.ImageKeepConfig;
import com.viontech.fanxing.ops.mapper.ContentMapper;
import com.viontech.fanxing.ops.model.OpsServer;
import com.viontech.fanxing.ops.service.adapter.ContentService;
import com.viontech.fanxing.ops.service.main.OpsServerService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -21,6 +23,8 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont
private static final String NAME_IMAGE_KEEP_CONFIG = "imageKeepConfig";
@Resource
private ContentMapper contentMapper;
@Resource
private OpsServerService opsServerService;
@Override
......@@ -57,7 +61,10 @@ public class ContentServiceImpl extends BaseServiceImpl<Content> implements Cont
contentExample.createCriteria().andTypeEqualTo(TYPE_PLATFORM_CONFIG).andNameEqualTo(NAME_TIMING_CONFIG);
addOrUpdate(TYPE_PLATFORM_CONFIG, NAME_TIMING_CONFIG, jsonObject.toJSONString());
// todo 发给运维服务
List<OpsServer> opsServers = opsServerService.listAll();
for (OpsServer opsServer : opsServers) {
opsServerService.distributeTimingConfig(opsServer, jsonObject);
}
}
......
package com.viontech.fanxing.ops.service.main;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.ops.model.OpsServer;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBucket;
import org.redisson.api.RKeys;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.reactive.function.client.WebClient;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
......@@ -19,6 +24,7 @@ import java.util.List;
*/
@Service
@Slf4j
public class OpsServerService {
@Resource
......@@ -29,7 +35,7 @@ public class OpsServerService {
addOrUpdateOpsServer(opsServer);
}
private List<OpsServer> listAll() {
public List<OpsServer> listAll() {
ArrayList<OpsServer> opsServers = new ArrayList<>();
RKeys keys = redissonClient.getKeys();
Iterable<String> pattern = keys.getKeysByPattern("ops:server:*");
......@@ -39,7 +45,7 @@ public class OpsServerService {
return opsServers;
}
private OpsServer getOpsServerFromRedisByIp(String ip) {
public OpsServer getOpsServerFromRedisByIp(String ip) {
RBucket<OpsServer> bucket = redissonClient.getBucket("ops:server:" + ip);
if (bucket.isExists()) {
OpsServer opsServer = bucket.get();
......@@ -54,6 +60,29 @@ public class OpsServerService {
}
}
public void distributeTimingConfig(OpsServer opsServer, JSONObject jsonObject) {
try {
String ip = opsServer.getIp();
Integer port = opsServer.getPort();
JSONObject nvsResponse = WebClient.create()
.post()
.uri(uriBuilder -> uriBuilder.scheme("http").host(ip).port(port).path("/api/v1/isg/timing").build())
.bodyValue(jsonObject.toJSONString())
.retrieve()
.bodyToMono(JSONObject.class)
.block(Duration.ofSeconds(20));
} catch (Exception e) {
log.error("下发校时配置失败", e);
}
}
public void updateVaServer(String[] devIdArr, MultipartFile file) {
// todo 保存文件到本地,根据 devIdArr 获取对应分析服务,再根据分析服务的 ip 获取对应的运维服务,下发文件地址和升级信息
log.info("收到升级请求,目标服务:{},文件:{}", Arrays.toString(devIdArr), file.getName());
}
private void addOrUpdateOpsServer(OpsServer opsServer) {
RBucket<OpsServer> bucket = redissonClient.getBucket("ops:server:" + opsServer.getIp());
bucket.set(opsServer);
......
......@@ -14,9 +14,9 @@ import lombok.Setter;
@Setter
public class DataOverViewModel {
private Long taskId;
private Long traffic;
private Long flow;
private Long behavior;
private Long traffic = 0L;
private Long flow = 0L;
private Long behavior = 0L;
private Integer hour;
private String taskName;
private Integer effectiveAnalysisTime;
......
......@@ -36,7 +36,7 @@ public class RandomRuntimeConfig implements RuntimeConfig {
@Override
public ImmutablePair<Long, Long> getNextTimeOfExecutionAndTerminal() {
// todo 目前逻辑还未定
// todo 目前逻辑还未定,只有手动启动才会执行一次
long running = TimeUnit.MINUTES.toMillis(runningTime);
Date date = DateUtil.setDayMinTime(new Date());
long time = date.getTime() - running;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!