38
|
1 package christie.topology.manager;
|
|
2
|
60
|
3 import christie.annotation.Peek;
|
38
|
4 import christie.codegear.CodeGear;
|
|
5 import christie.codegear.CodeGearManager;
|
|
6
|
41
|
7 import java.io.File;
|
|
8 import java.io.FileNotFoundException;
|
|
9 import java.io.FileReader;
|
|
10 import java.util.ArrayList;
|
|
11 import java.util.HashMap;
|
|
12 import java.util.LinkedList;
|
|
13
|
45
|
14 import christie.topology.HostMessage;
|
41
|
15 import org.apache.log4j.Logger;
|
|
16
|
|
17 import com.alexmerz.graphviz.ParseException;
|
|
18 import com.alexmerz.graphviz.Parser;
|
|
19 import com.alexmerz.graphviz.objects.*;
|
|
20
|
38
|
21 public class TopologyManager extends CodeGear {
|
|
22
|
60
|
23 @Peek
|
|
24 TopologyManagerConfig topologyManagerConfig;
|
|
25
|
45
|
26 private Logger logger = Logger.getLogger(TopologyManager.class);
|
41
|
27
|
60
|
28 public TopologyManager() {
|
45
|
29 }
|
41
|
30
|
38
|
31 @Override
|
|
32 protected void run(CodeGearManager cgm) {
|
41
|
33 cgm.setup(new CheckComingHost());
|
38
|
34
|
45
|
35 getLocalDGM().put("absCookieTable", new HashMap<String, String>());
|
|
36
|
41
|
37 // if (!conf.dynamic) は, conf.dynamic = trueの動作がわからないので, 省いた.
|
|
38
|
45
|
39 LinkedList<String> nodeNames = new LinkedList<>();
|
64
|
40 HashMap<String, LinkedList<NodeInfo>> resultParse = new HashMap<>();
|
41
|
41 int nodeNum = 0;
|
|
42
|
|
43 try {
|
60
|
44 FileReader reader = new FileReader(new File(topologyManagerConfig.confFilePath));
|
41
|
45 Parser parser = new Parser();
|
|
46 parser.parse(reader);
|
|
47
|
|
48
|
|
49 ArrayList<Graph> digraphs = parser.getGraphs();
|
|
50
|
|
51
|
|
52 for (Graph digraph : digraphs) {
|
|
53 ArrayList<Node> nodes = digraph.getNodes(false);
|
|
54 nodeNum = nodes.size();
|
|
55
|
|
56 for (Node node : nodes) {
|
|
57 String nodeName = node.getId().getId();
|
|
58 nodeNames.add(nodeName);
|
64
|
59 resultParse.put(nodeName, new LinkedList<>());
|
41
|
60 }
|
|
61
|
|
62 ArrayList<Edge> edges = digraph.getEdges();
|
45
|
63 HashMap<String, NodeInfo> hash = new HashMap<>();
|
41
|
64
|
|
65 String connection;
|
|
66 String source;
|
|
67 String target;
|
|
68
|
|
69 NodeInfo nodeInfo;
|
|
70
|
|
71 // まず1回グラフを読み込む
|
|
72 for (Edge edge : edges) {
|
|
73 connection = edge.getAttribute("label");
|
|
74 source = edge.getSource().getNode().getId().getId();
|
|
75 target = edge.getTarget().getNode().getId().getId();
|
64
|
76 nodeInfo = new NodeInfo(source, connection, target);
|
41
|
77
|
64
|
78 resultParse.get(source).add(nodeInfo);
|
41
|
79
|
64
|
80 //hash.put(source + "," + target, nodeInfo);
|
41
|
81 }
|
|
82
|
|
83 // hash.get(target + "," + source); をして, グラフを逆にたどって, reverseNameにlabelを入れてる.
|
64
|
84 /*
|
41
|
85 for (Edge edge : edges) {
|
|
86 connection = edge.getAttribute("label");
|
|
87 source = edge.getSource().getNode().getId().getId();
|
|
88 target = edge.getTarget().getNode().getId().getId();
|
|
89 nodeInfo = hash.get(target + "," + source);
|
|
90
|
|
91 if (nodeInfo != null) {
|
|
92 nodeInfo.reverseName = connection;
|
|
93 }
|
|
94
|
64
|
95 }*/
|
41
|
96 }
|
|
97
|
|
98 } catch (FileNotFoundException e) {
|
60
|
99 logger.error("File not found: " + topologyManagerConfig.confFilePath);
|
41
|
100 e.printStackTrace();
|
|
101 } catch (ParseException e) {
|
60
|
102 logger.error("File format error: " + topologyManagerConfig.confFilePath);
|
41
|
103 e.printStackTrace();
|
|
104 }
|
|
105
|
|
106 // for recode topology information
|
|
107 // cookie List
|
|
108 getLocalDGM().put("running", false);
|
64
|
109 getLocalDGM().put("resultParse", resultParse);
|
41
|
110 getLocalDGM().put("nodeNames", nodeNames);
|
60
|
111 getLocalDGM().put("hostInfoMap", new HashMap<String, HostMessage>());
|
64
|
112 getLocalDGM().put("topology", new HashMap<String, HashMap<String, HostMessage>>());
|
|
113 getLocalDGM().put("nodeNum", nodeNum);
|
|
114 getLocalDGM().put("createdList", new LinkedList<String>());
|
41
|
115
|
|
116 cgm.setup(new IncomingHosts());
|
|
117 cgm.setup(new ConfigWaiter());
|
45
|
118 cgm.setup(new CreateHash());
|
|
119 cgm.setup(new TopologyFinish());
|
38
|
120
|
|
121 }
|
|
122
|
41
|
123
|
38
|
124 }
|