...
|
...
|
@@ -2,11 +2,15 @@ package com.ui.ctrl; |
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.ui.common.TagTypeEnum;
|
|
|
import com.ui.contants.HttpUriContants;
|
|
|
import com.ui.http.HttpRestClient;
|
|
|
import com.ui.model.AntvData;
|
|
|
import com.ui.model.AntvNode;
|
|
|
import com.ui.model.BaseResponse;
|
|
|
import com.ui.model.HostGroup;
|
|
|
import com.ui.model.req.HostInfoReq;
|
|
|
import com.ui.model.req.SetHostTagsReq;
|
|
|
import com.ui.model.req.TagReq;
|
...
|
...
|
@@ -18,10 +22,7 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Created by yoho on 2016/6/14.
|
...
|
...
|
@@ -51,9 +52,228 @@ public class HostInfoCtrl { |
|
|
public ModelAndView toHostTopoList() {
|
|
|
ModelAndView mv = new ModelAndView();
|
|
|
mv.setViewName("host/hostTopoList");
|
|
|
|
|
|
//初始化数据
|
|
|
Map<String,List<HostGroup>> initDataMap = tmpConstructData();
|
|
|
|
|
|
int beginx=60;
|
|
|
int beginy=60;
|
|
|
int gap_h=100;
|
|
|
int gap_x=300;
|
|
|
int intval=140;
|
|
|
List<AntvNode> nodes=new ArrayList<>();
|
|
|
List<Map<String,String>> edges=new ArrayList<>();
|
|
|
|
|
|
int count=0;
|
|
|
int maxSize=0;
|
|
|
for (Map.Entry<String, List<HostGroup>> entry : initDataMap.entrySet()) {
|
|
|
String topNode = entry.getKey();
|
|
|
AntvNode node=new AntvNode();
|
|
|
node.setId(topNode);
|
|
|
node.setLabel(topNode);
|
|
|
node.setShape("rect");
|
|
|
node.setX(beginx+(count*gap_x));
|
|
|
node.setY(beginy);
|
|
|
nodes.add(node);
|
|
|
int secondCount=1;
|
|
|
List<HostGroup> ls=entry.getValue();
|
|
|
if(ls.size()>maxSize){
|
|
|
maxSize = ls.size();
|
|
|
}
|
|
|
for(HostGroup secondeNode:ls){
|
|
|
String sndNodeID=""+secondeNode.getId();
|
|
|
AntvNode nodeSnd=new AntvNode();
|
|
|
nodeSnd.setId(sndNodeID);
|
|
|
nodeSnd.setLabel(secondeNode.getGroupName());
|
|
|
nodeSnd.setShape("rect");
|
|
|
nodeSnd.setX(beginx+(count*gap_x)+intval);
|
|
|
nodeSnd.setY(beginy+secondCount*gap_h);
|
|
|
nodes.add(nodeSnd);
|
|
|
|
|
|
secondCount++;
|
|
|
//连线
|
|
|
Map<String,String> edgeMap=new HashMap<>();
|
|
|
edgeMap.put("source",topNode);
|
|
|
edgeMap.put("target",sndNodeID);
|
|
|
edges.add(edgeMap);
|
|
|
|
|
|
}
|
|
|
count++;
|
|
|
}
|
|
|
|
|
|
AntvData data=new AntvData();
|
|
|
data.setNodes(nodes);
|
|
|
data.setEdges(edges);
|
|
|
Gson gson = new Gson();
|
|
|
String jsonString=gson.toJson( data,AntvData.class);
|
|
|
mv.addObject("antvData",jsonString);
|
|
|
mv.addObject("antvHeight",100*(maxSize+1));
|
|
|
return mv;
|
|
|
}
|
|
|
|
|
|
|
|
|
private Map<String,List<HostGroup>> tmpConstructData(){
|
|
|
Map<String,List<HostGroup>> initDataMap=new LinkedHashMap<>();
|
|
|
HostGroup group6=new HostGroup();
|
|
|
group6.setId(1006);
|
|
|
group6.setGroupName("search");
|
|
|
|
|
|
HostGroup group5=new HostGroup();
|
|
|
group5.setId(1005);
|
|
|
group5.setGroupName("mysql");
|
|
|
|
|
|
HostGroup group4=new HostGroup();
|
|
|
group4.setId(1004);
|
|
|
group4.setGroupName("中间件");
|
|
|
|
|
|
HostGroup group3=new HostGroup();
|
|
|
group3.setId(1003);
|
|
|
group3.setGroupName("service");
|
|
|
|
|
|
HostGroup group2=new HostGroup();
|
|
|
group2.setId(1002);
|
|
|
group2.setGroupName("gateway");
|
|
|
|
|
|
HostGroup group1=new HostGroup();
|
|
|
group1.setId(1001);
|
|
|
group1.setGroupName("nginx");
|
|
|
|
|
|
initDataMap.put("前台", Lists.newArrayList(group1,group2,group3,group4,group5,group6));
|
|
|
|
|
|
HostGroup group26=new HostGroup();
|
|
|
group26.setId(2006);
|
|
|
group26.setGroupName("greenplum");
|
|
|
|
|
|
HostGroup group25=new HostGroup();
|
|
|
group25.setId(2005);
|
|
|
group25.setGroupName("mysql");
|
|
|
|
|
|
HostGroup group24=new HostGroup();
|
|
|
group24.setId(2004);
|
|
|
group24.setGroupName("中间件");
|
|
|
|
|
|
HostGroup group22=new HostGroup();
|
|
|
group22.setId(2003);
|
|
|
group22.setGroupName("service");
|
|
|
|
|
|
HostGroup group21=new HostGroup();
|
|
|
group21.setId(2001);
|
|
|
group21.setGroupName("nginx");
|
|
|
initDataMap.put("crm", Lists.newArrayList(group21,group22,group24,group25,group26));
|
|
|
|
|
|
HostGroup group35=new HostGroup();
|
|
|
group35.setId(3005);
|
|
|
group35.setGroupName("mysql");
|
|
|
|
|
|
|
|
|
HostGroup group32=new HostGroup();
|
|
|
group32.setId(3002);
|
|
|
group32.setGroupName("service");
|
|
|
|
|
|
HostGroup group31=new HostGroup();
|
|
|
group31.setId(3001);
|
|
|
group31.setGroupName("nginx");
|
|
|
initDataMap.put("线下店", Lists.newArrayList(group31,group32, group35));
|
|
|
|
|
|
HostGroup group68=new HostGroup();
|
|
|
group68.setId(68);
|
|
|
group68.setGroupName("code-deploy");
|
|
|
|
|
|
HostGroup group67=new HostGroup();
|
|
|
group67.setId(67);
|
|
|
group67.setGroupName("health");
|
|
|
|
|
|
HostGroup group66=new HostGroup();
|
|
|
group66.setId(66);
|
|
|
group66.setGroupName("kafka");
|
|
|
|
|
|
|
|
|
HostGroup group65=new HostGroup();
|
|
|
group65.setId(65);
|
|
|
group65.setGroupName("zabbix");
|
|
|
|
|
|
HostGroup group64=new HostGroup();
|
|
|
group64.setId(64);
|
|
|
group64.setGroupName("gitlab");
|
|
|
|
|
|
HostGroup group63=new HostGroup();
|
|
|
group63.setId(63);
|
|
|
group63.setGroupName("influxdb");
|
|
|
|
|
|
|
|
|
HostGroup group62=new HostGroup();
|
|
|
group62.setId(62);
|
|
|
group62.setGroupName("dns");
|
|
|
|
|
|
HostGroup group61=new HostGroup();
|
|
|
group61.setId(61);
|
|
|
group61.setGroupName("nginx");
|
|
|
initDataMap.put("线下店", Lists.newArrayList(group31,group32, group35));
|
|
|
initDataMap.put("ops", Lists.newArrayList(group61,group62,group63,group64,group65,group66,group67,group68));
|
|
|
|
|
|
|
|
|
HostGroup group75=new HostGroup();
|
|
|
group75.setId(75);
|
|
|
group75.setGroupName("dns");
|
|
|
|
|
|
HostGroup group74=new HostGroup();
|
|
|
group74.setId(74);
|
|
|
group74.setGroupName("mysql");
|
|
|
|
|
|
HostGroup group73=new HostGroup();
|
|
|
group73.setId(73);
|
|
|
group73.setGroupName("search");
|
|
|
|
|
|
|
|
|
HostGroup group72=new HostGroup();
|
|
|
group72.setId(72);
|
|
|
group72.setGroupName("nginx");
|
|
|
|
|
|
HostGroup group71=new HostGroup();
|
|
|
group71.setId(71);
|
|
|
group71.setGroupName("socail");
|
|
|
|
|
|
initDataMap.put("web", Lists.newArrayList(group71,group72,group73,group74,group75));
|
|
|
|
|
|
|
|
|
HostGroup group86=new HostGroup();
|
|
|
group86.setId(86);
|
|
|
group86.setGroupName("containers");
|
|
|
|
|
|
|
|
|
HostGroup group85=new HostGroup();
|
|
|
group85.setId(85);
|
|
|
group85.setGroupName("dns");
|
|
|
|
|
|
HostGroup group84=new HostGroup();
|
|
|
group84.setId(84);
|
|
|
group84.setGroupName("mysql");
|
|
|
|
|
|
HostGroup group83=new HostGroup();
|
|
|
group83.setId(83);
|
|
|
group83.setGroupName("search");
|
|
|
|
|
|
|
|
|
HostGroup group82=new HostGroup();
|
|
|
group82.setId(82);
|
|
|
group82.setGroupName("nginx");
|
|
|
|
|
|
HostGroup group81=new HostGroup();
|
|
|
group81.setId(81);
|
|
|
group81.setGroupName("socail");
|
|
|
initDataMap.put("media", Lists.newArrayList(group81,group82,group83,group84,group85,group86));
|
|
|
|
|
|
HostGroup group92=new HostGroup();
|
|
|
group92.setId(92);
|
|
|
group92.setGroupName("mysql");
|
|
|
|
|
|
HostGroup group91=new HostGroup();
|
|
|
group91.setId(91);
|
|
|
group91.setGroupName("平台端");
|
|
|
initDataMap.put("后台", Lists.newArrayList(group91,group92));
|
|
|
return initDataMap;
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/toHostTopoSub")
|
|
|
public ModelAndView toHostTopoSub(String id) {
|
|
|
ModelAndView mv = new ModelAndView();
|
...
|
...
|
|