Commit a1710a9d authored by gaozhentao's avatar gaozhentao

拓扑图查询和修改

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