...
|
...
|
@@ -56,40 +56,61 @@ public class HostInfoCtrl { |
|
|
//初始化数据
|
|
|
Map<String,List<HostGroup>> initDataMap = tmpConstructData();
|
|
|
|
|
|
getJsonAntvData(initDataMap,true, mv);
|
|
|
getJsonAntvData(initDataMap,6, mv);
|
|
|
|
|
|
return mv;
|
|
|
}
|
|
|
|
|
|
private void getJsonAntvData(Map<String,List<HostGroup>> initDataMap,boolean setXyFlag,ModelAndView mv){
|
|
|
//numInRow 第二层的节点一排放几个
|
|
|
private void getJsonAntvData(Map<String,List<HostGroup>> initDataMap,int numInRow,ModelAndView mv){
|
|
|
int beginx=60;
|
|
|
int beginy=60;
|
|
|
int gap_h=100;
|
|
|
int gap_x=300;
|
|
|
int intval=140;
|
|
|
|
|
|
int gap_level_top_h=100;
|
|
|
int gap_h=50;
|
|
|
|
|
|
List<AntvNode> nodes=new ArrayList<>();
|
|
|
List<Map<String,String>> edges=new ArrayList<>();
|
|
|
|
|
|
int count=0;
|
|
|
int maxSize=0;
|
|
|
int last_y=0;
|
|
|
for (Map.Entry<String, List<HostGroup>> entry : initDataMap.entrySet()) {
|
|
|
String topNode = entry.getKey();
|
|
|
AntvNode node=new AntvNode();
|
|
|
node.setLevel(0);
|
|
|
node.setId(topNode);
|
|
|
node.setLabel(topNode);
|
|
|
node.setShape("rect");
|
|
|
if(setXyFlag){
|
|
|
node.setX(beginx+(count*gap_x));
|
|
|
node.setY(beginy);
|
|
|
AntvNode nodeLevelTop=new AntvNode();
|
|
|
nodeLevelTop.setLevel(0);
|
|
|
nodeLevelTop.setId(topNode);
|
|
|
nodeLevelTop.setLabel(topNode);
|
|
|
nodeLevelTop.setShape("rect");
|
|
|
|
|
|
int top_node_x=beginx;
|
|
|
int top_node_y;
|
|
|
if(maxSize==0){
|
|
|
top_node_y=beginy;
|
|
|
}else{
|
|
|
top_node_y=last_y+gap_level_top_h;
|
|
|
}
|
|
|
|
|
|
nodes.add(node);
|
|
|
int secondCount=1;
|
|
|
nodeLevelTop.setX(top_node_x);
|
|
|
nodeLevelTop.setY(top_node_y);
|
|
|
nodes.add(nodeLevelTop);
|
|
|
last_y= nodeLevelTop.getY();
|
|
|
|
|
|
maxSize++;
|
|
|
|
|
|
List<HostGroup> ls=entry.getValue();
|
|
|
if(ls.size()>maxSize){
|
|
|
maxSize = ls.size();
|
|
|
if(ls==null||ls.size()<=0){
|
|
|
nodeLevelTop.setLevel(1);
|
|
|
|
|
|
continue;
|
|
|
}else{
|
|
|
double d=ls.size()*1.0/numInRow;
|
|
|
maxSize +=(int)Math.ceil(d);
|
|
|
}
|
|
|
|
|
|
|
|
|
int secondCount=1;
|
|
|
int row=1;
|
|
|
int GAP_BETWEEN_NODE_X=120;
|
|
|
for(HostGroup secondeNode:ls){
|
|
|
String sndNodeID=""+secondeNode.getId();
|
|
|
AntvNode nodeSnd=new AntvNode();
|
...
|
...
|
@@ -97,22 +118,29 @@ public class HostInfoCtrl { |
|
|
nodeSnd.setId(sndNodeID);
|
|
|
nodeSnd.setLabel(secondeNode.getGroupName());
|
|
|
nodeSnd.setShape("rect");
|
|
|
if(setXyFlag){
|
|
|
nodeSnd.setX(beginx+(count*gap_x)+intval);
|
|
|
nodeSnd.setY(beginy+secondCount*gap_h);
|
|
|
}
|
|
|
|
|
|
nodeSnd.setX(top_node_x+row*GAP_BETWEEN_NODE_X);
|
|
|
nodeSnd.setY(top_node_y+secondCount*gap_h);
|
|
|
nodes.add(nodeSnd);
|
|
|
last_y=nodeSnd.getY();
|
|
|
|
|
|
secondCount++;
|
|
|
//连线
|
|
|
Map<String,String> edgeMap=new HashMap<>();
|
|
|
edgeMap.put("source",topNode);
|
|
|
edgeMap.put("target",sndNodeID);
|
|
|
edges.add(edgeMap);
|
|
|
//第二行,不再加连接线
|
|
|
if(secondCount==1){
|
|
|
Map<String,String> edgeMap=new HashMap<>();
|
|
|
edgeMap.put("source",topNode);
|
|
|
edgeMap.put("target",sndNodeID);
|
|
|
edges.add(edgeMap);
|
|
|
}
|
|
|
|
|
|
|
|
|
if(row<numInRow){
|
|
|
row++;
|
|
|
}else{
|
|
|
row = 1;
|
|
|
secondCount++;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
count++;
|
|
|
}
|
|
|
|
|
|
AntvData data=new AntvData();
|
...
|
...
|
@@ -122,7 +150,7 @@ public class HostInfoCtrl { |
|
|
String jsonString=gson.toJson( data,AntvData.class);
|
|
|
|
|
|
mv.addObject("antvData",jsonString);
|
|
|
mv.addObject("antvHeight",100*(maxSize+1));
|
|
|
mv.addObject("antvHeight",last_y+100);
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/toHostTopoSub")
|
...
|
...
|
@@ -132,11 +160,9 @@ public class HostInfoCtrl { |
|
|
|
|
|
//获取子节点(有可能不存在),比如前台-gateway ,有可能存在,前台-service
|
|
|
String parentLabel="前台";
|
|
|
int number=(int)(Math.random()*10);//[0,10]
|
|
|
boolean subNodeFlag=false;
|
|
|
String currentLabel="gateway";
|
|
|
number=2;
|
|
|
if(number%2==0){
|
|
|
if(id!=null&&!id.endsWith("1")){
|
|
|
subNodeFlag=true;
|
|
|
currentLabel="service";
|
|
|
}
|
...
|
...
|
@@ -144,7 +170,7 @@ public class HostInfoCtrl { |
|
|
Map<String,List<HostGroup>> initDataMap =new LinkedHashMap<>();
|
|
|
initDataMap.put(currentLabel,tmpDetailData(subNodeFlag));
|
|
|
|
|
|
getJsonAntvData(initDataMap,false, mv);
|
|
|
getJsonAntvData(initDataMap,3, mv);
|
|
|
|
|
|
mv.addObject("parentLabel",parentLabel);
|
|
|
return mv;
|
...
|
...
|
|