Commit a1710a9d authored by gaozhentao's avatar gaozhentao

拓扑图查询和修改

parent d919d2b5
package com.yingxin.prms.api;
import com.yingxin.prms.domain.FlowLine;
import com.yingxin.prms.domain.FlowNode;
import com.yingxin.prms.dto.SingleHostStatus;
import com.yingxin.prms.service.asyncTask.QueryHostStatusTask;
import com.yingxin.prms.service.business.Manager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
@RestController
......@@ -87,22 +80,31 @@ public class ReliabilityApi {
return manager.selectChart(json);
}
/**
* 获取拓扑图数据
* 获取拓扑图数据
*
* @return 集群信息json字符串
* @return
*/
@PostMapping("selectTopology")
public List<FlowNode> selectTopology(){
@GetMapping("selectTopology")
public Map selectTopology(){
return manager.selectTopology();
}
/**
* 获取拓扑图数据
* 获取拓扑图线数据
*
* @return 集群信息json字符串
* @return
*/
// @PostMapping("selectTopologyLine")
// public List<FlowLine> selectTopologyLine(){
// return manager.selectTopologyLine();
// }
/**
* 保存数据
* @return
*/
@PostMapping("saveTopology")
public Map saveTopology(@RequestBody String json) throws Exception{
return manager.saveTopology();
public Map saveTopology(@RequestBody String json) {
return manager.saveTopology(json);
}
}
......@@ -51,7 +51,9 @@ public class WebConfiguration implements WebMvcConfigurer {
.excludePathPatterns("/img/**")
.excludePathPatterns("/js/**")
.excludePathPatterns("/index.html")
.excludePathPatterns("/rest/rel/login");
.excludePathPatterns("/rest/rel/login")
.excludePathPatterns("/rest/rel/selectTopology")
.excludePathPatterns("/rest/rel/saveTopology");
WebMvcConfigurer.super.addInterceptors(registry);
}
......
package com.yingxin.prms.domain;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.core.mapping.Table;
/**
......@@ -9,13 +11,11 @@ import org.springframework.data.cassandra.core.mapping.Table;
* Datetime: 2021/1/12 9:40
* Author: gaozhentao
*/
@Table(value = "flowNode")
@Table(value = "flowline")
public class FlowLine {
@PrimaryKey
String id; //主键id
@Column("cluster_name_left")
String clusterNameLeft; //左集群名称
String cluster_name_left; //左集群名称
@Column("cluster_name_right")
String clusterNameRight; //右集群名称
@Column("coordinate_left")
......@@ -24,20 +24,12 @@ public class FlowLine {
String coordinateRight; //右坐标
public String getId() {
return id;
public String getCluster_name_left() {
return cluster_name_left;
}
public void setId(String id) {
this.id = id;
}
public String getClusterNameLeft() {
return clusterNameLeft;
}
public void setClusterNameLeft(String clusterNameLeft) {
this.clusterNameLeft = clusterNameLeft;
public void setCluster_name_left(String cluster_name_left) {
this.cluster_name_left = cluster_name_left;
}
public String getClusterNameRight() {
......
package com.yingxin.prms.domain;
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.core.mapping.Table;
/**
......@@ -13,20 +15,20 @@ import org.springframework.data.cassandra.core.mapping.Table;
public class FlowNode {
@PrimaryKey
@Column("cluster_name")
String clusterName; //集群名称
// @Column("cluster_name")
String cluster_name; //集群名称
String coordinate; //坐标
String mark; //标识
@Column("server_path")
String serverPath; //服务路径
String faultCount; //错误数
public String getClusterName() {
return clusterName;
public String getCluster_name() {
return cluster_name;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
public void setCluster_name(String cluster_name) {
this.cluster_name = cluster_name;
}
public String getCoordinate() {
......
package com.yingxin.prms.service.business;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.yingxin.prms.config.filter.TokenInterceptor;
import com.yingxin.prms.domain.*;
import com.yingxin.prms.dto.*;
......@@ -16,20 +15,15 @@ import org.kairosdb.client.builder.*;
import org.kairosdb.client.response.QueryResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static sun.misc.MessageUtils.where;
@Service
public class Manager {
......@@ -39,8 +33,10 @@ public class Manager {
@Value("${tokeTime}")
private long tokeTime;
@Value("${pointNumber}")
private int pointNumber;
private final AuthModeAndHostList authModeAndHostList;
private final CassandraDaoImpl cassandraDao;
......@@ -398,23 +394,34 @@ public class Manager {
return dataPoints;
}
public List<FlowNode> selectTopology(){
public Map selectTopology(){
List<Server_Host_Info> serverHostInfoAll = authModeAndHostList.getClusterBeMonitoredList();
List<FlowNode> flowNodeAll = flowDao.findNodeAll();
Map result = new HashMap();
List<FlowNode> flowNodes = flowDao.findNodeAll();
List<FlowLine> flowLines = flowDao.findLineAll();
List<FlowNode> list = new ArrayList<>();
if(flowNodeAll.size()>0){
list = flowNodeAll;
if(flowNodes.size()>0){
result.put("linkData",flowLines);
for(FlowNode node : flowNodes){
long faultCount=0;
try {
faultCount = getFaultCount(node.getServerPath());
} catch (Exception e) {
faultCount = 0;
}
node.setFaultCount(String.valueOf(faultCount));
}
result.put("nodeData",flowNodes);
}else{
Map<String,String> map = new HashMap();
for(Server_Host_Info hostInfo : serverHostInfoAll){
if(!map.containsKey(hostInfo.getCluster_name())){
map.put(hostInfo.getCluster_name(),hostInfo.getService_path());
FlowNode flowNode = new FlowNode();
flowNode.setClusterName(hostInfo.getCluster_name());
flowNode.setCluster_name(hostInfo.getCluster_name());
flowNode.setServerPath(hostInfo.getService_path());
flowNode.setCoordinate("初始坐标");
long faultCount;
long faultCount=0;
try {
faultCount = getFaultCount(hostInfo.getService_path());
} catch (Exception e) {
......@@ -431,7 +438,7 @@ public class Manager {
}
}
}
return list;
return result;
}
private long getFaultCount(String servicePath) throws IOException, DataFormatException {
......@@ -446,14 +453,35 @@ public class Manager {
return dataPointsDay.size() == 0 ? 0 : dataPointsDay.get(dataPointsDay.size() - 1).longValue();
}
public Map saveTopology() {
List<Server_Host_Info> serverHostInfoAll = authModeAndHostList.getClusterBeMonitoredList();
Map map = new HashMap();
public Map saveTopology(String json) {
JSONObject jsonObject = JSONObject.fromObject(json);
List<Map<String,String>> list = jsonObject.getJSONArray("list");
for(Map<String,String> map : list){
if(map!=null && !map.isEmpty()){
flowDao.updateNode(map.get("clusterName"),map.get("coordinate"), map.get("mark"));
// String id = UUID.randomUUID().toString();
// FlowLine flowLine = new FlowLine();
// flowLine.setClusterNameLeft(map.get("clusterNameLeft"));
// flowLine.setClusterNameRight(map.get("clusterNameRight"));
// flowLine.setCoordinateLeft(map.get("coordinateLeft"));
// flowLine.setCoordinateRight(map.get("coordinateRight"));
// flowDao.insertLine(flowLine);
}
}
Map result = new HashMap();
result.put("state",true);
/*线程池*/
for(Server_Host_Info hostInfo : serverHostInfoAll){
return result;
}
public List<FlowLine> selectTopologyLine() {
List<FlowLine> flowLines = flowDao.findLineAll();
if(flowLines.size()>0){
return null;
}else {
return flowLines;
}
return null;
}
/*
......
package com.yingxin.prms.service.dao;
import com.yingxin.prms.domain.FlowLine;
import com.yingxin.prms.domain.FlowNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.cassandra.core.CassandraTemplate;
......@@ -25,19 +26,28 @@ public class FlowDaoImpl {
public void insertNode(FlowNode flowNode) {
String cql ="INSERT INTO ctid_prof.flownode(cluster_name, server_path)" +
"VALUES('"+flowNode.getClusterName()+"', '"+flowNode.getServerPath()+"');";
"VALUES('"+flowNode.getCluster_name()+"', '"+flowNode.getServerPath()+"');";
template.getCqlOperations().execute(cql);
}
public boolean updateNode(FlowNode flowNode) {
String cql ="UPDATE ctid_prof.flownode set coordinate='"+flowNode.getCoordinate()+"', mark='"+flowNode.getMark()+
"' WHERE cluster_name='"+flowNode.getClusterName()+"'";
public boolean updateNode(String clusterName,String coordinate,String mark) {
String cql ="UPDATE ctid_prof.flownode set coordinate='"+coordinate+"', mark='"+mark+
"' WHERE cluster_name='"+clusterName+"'";
return template.getCqlOperations().execute(cql);
}
public List<FlowNode> findNodeAll() {
String cql ="SELECT * FROM ctid_prof.flownode";
return template.select(cql,FlowNode.class);
}
public List<FlowLine> findLineAll() {
String cql ="SELECT * FROM ctid_prof.flowline";
return template.select(cql,FlowLine.class);
}
public void insertLine(FlowLine flowLine) {
String cql ="update INTO ctid_prof.flowline ( cluster_name_left, cluster_name_right, coordinate_left, coordinate_right)"+
"VALUES( '"+flowLine.getCluster_name_left()+"', '"+flowLine.getClusterNameRight()+"', '"+flowLine.getCoordinateLeft()+"', '"+flowLine.getCoordinateRight()+"');";
template.getCqlOperations().execute(cql);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment