comparison src/main/java/christie/topology/manager/TopologyManager.java @ 64:f884c1bd0d36

fix IncomingHosts and RecordTopology. and refactor.
author akahori
date Thu, 30 Aug 2018 10:55:37 +0900
parents cfd79a71f9cd
children f1f34c3e33d4
comparison
equal deleted inserted replaced
63:c73bb6a17034 64:f884c1bd0d36
1 package christie.topology.manager; 1 package christie.topology.manager;
2 2
3 import christie.annotation.Peek; 3 import christie.annotation.Peek;
4 import christie.annotation.Take;
5 import christie.codegear.CodeGear; 4 import christie.codegear.CodeGear;
6 import christie.codegear.CodeGearManager; 5 import christie.codegear.CodeGearManager;
7 6
8 import java.io.File; 7 import java.io.File;
9 import java.io.FileNotFoundException; 8 import java.io.FileNotFoundException;
36 getLocalDGM().put("absCookieTable", new HashMap<String, String>()); 35 getLocalDGM().put("absCookieTable", new HashMap<String, String>());
37 36
38 // if (!conf.dynamic) は, conf.dynamic = trueの動作がわからないので, 省いた. 37 // if (!conf.dynamic) は, conf.dynamic = trueの動作がわからないので, 省いた.
39 38
40 LinkedList<String> nodeNames = new LinkedList<>(); 39 LinkedList<String> nodeNames = new LinkedList<>();
41 HashMap<String, LinkedList<NodeInfo>> topology = new HashMap<>(); 40 HashMap<String, LinkedList<NodeInfo>> resultParse = new HashMap<>();
42 int nodeNum = 0; 41 int nodeNum = 0;
43 42
44 try { 43 try {
45 FileReader reader = new FileReader(new File(topologyManagerConfig.confFilePath)); 44 FileReader reader = new FileReader(new File(topologyManagerConfig.confFilePath));
46 Parser parser = new Parser(); 45 Parser parser = new Parser();
55 nodeNum = nodes.size(); 54 nodeNum = nodes.size();
56 55
57 for (Node node : nodes) { 56 for (Node node : nodes) {
58 String nodeName = node.getId().getId(); 57 String nodeName = node.getId().getId();
59 nodeNames.add(nodeName); 58 nodeNames.add(nodeName);
60 topology.put(nodeName, new LinkedList<>()); 59 resultParse.put(nodeName, new LinkedList<>());
61 } 60 }
62 61
63 ArrayList<Edge> edges = digraph.getEdges(); 62 ArrayList<Edge> edges = digraph.getEdges();
64 HashMap<String, NodeInfo> hash = new HashMap<>(); 63 HashMap<String, NodeInfo> hash = new HashMap<>();
65 64
72 // まず1回グラフを読み込む 71 // まず1回グラフを読み込む
73 for (Edge edge : edges) { 72 for (Edge edge : edges) {
74 connection = edge.getAttribute("label"); 73 connection = edge.getAttribute("label");
75 source = edge.getSource().getNode().getId().getId(); 74 source = edge.getSource().getNode().getId().getId();
76 target = edge.getTarget().getNode().getId().getId(); 75 target = edge.getTarget().getNode().getId().getId();
77 nodeInfo = new NodeInfo(source, connection); 76 nodeInfo = new NodeInfo(source, connection, target);
78 77
79 topology.get(target).add(nodeInfo); 78 resultParse.get(source).add(nodeInfo);
80 79
81 hash.put(source + "," + target, nodeInfo); 80 //hash.put(source + "," + target, nodeInfo);
82 } 81 }
83 82
84 // hash.get(target + "," + source); をして, グラフを逆にたどって, reverseNameにlabelを入れてる. 83 // hash.get(target + "," + source); をして, グラフを逆にたどって, reverseNameにlabelを入れてる.
84 /*
85 for (Edge edge : edges) { 85 for (Edge edge : edges) {
86 connection = edge.getAttribute("label"); 86 connection = edge.getAttribute("label");
87 source = edge.getSource().getNode().getId().getId(); 87 source = edge.getSource().getNode().getId().getId();
88 target = edge.getTarget().getNode().getId().getId(); 88 target = edge.getTarget().getNode().getId().getId();
89 nodeInfo = hash.get(target + "," + source); 89 nodeInfo = hash.get(target + "," + source);
90 90
91 if (nodeInfo != null) { 91 if (nodeInfo != null) {
92 nodeInfo.reverseName = connection; 92 nodeInfo.reverseName = connection;
93 } 93 }
94 94
95 } 95 }*/
96 } 96 }
97 97
98 } catch (FileNotFoundException e) { 98 } catch (FileNotFoundException e) {
99 logger.error("File not found: " + topologyManagerConfig.confFilePath); 99 logger.error("File not found: " + topologyManagerConfig.confFilePath);
100 e.printStackTrace(); 100 e.printStackTrace();
104 } 104 }
105 105
106 // for recode topology information 106 // for recode topology information
107 // cookie List 107 // cookie List
108 getLocalDGM().put("running", false); 108 getLocalDGM().put("running", false);
109 getLocalDGM().put("resultParse", topology); 109 getLocalDGM().put("resultParse", resultParse);
110 getLocalDGM().put("nodeNames", nodeNames); 110 getLocalDGM().put("nodeNames", nodeNames);
111 getLocalDGM().put("hostInfoMap", new HashMap<String, HostMessage>()); 111 getLocalDGM().put("hostInfoMap", new HashMap<String, HostMessage>());
112 getLocalDGM().put("topology", new HashMap<String, LinkedList<HostMessage>>()); 112 getLocalDGM().put("topology", new HashMap<String, HashMap<String, HostMessage>>());
113 getLocalDGM().put("nodeNum", nodeNum);
114 getLocalDGM().put("createdList", new LinkedList<String>());
113 115
114 cgm.setup(new IncomingHosts()); 116 cgm.setup(new IncomingHosts());
115
116 // Question: この処理何をやっているのかわからない. 一応, その下にそれっぽいコードを書いた.
117 // ConfigWaiter cs3 = new ConfigWaiter(nodeNum);
118 // cs3.done.setKey("local", "done");
119
120 cgm.setup(new ConfigWaiter()); 117 cgm.setup(new ConfigWaiter());
121 getLocalDGM().put("nodeNum", nodeNum);
122
123
124
125 getLocalDGM().put("createdList", new LinkedList<String>());
126 cgm.setup(new CreateHash()); 118 cgm.setup(new CreateHash());
127
128 cgm.setup(new TopologyFinish()); 119 cgm.setup(new TopologyFinish());
129 120
130 } 121 }
131 122
132 123