comparison src/main/java/alice/topology/manager/StartTopologyManager.java @ 631:ffaacab84d1a

Merge dispose
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Thu, 30 Nov 2017 19:42:31 +0900
parents 8f71c3e6f11d 4027e55df60d
children 1c93e82e05c6
comparison
equal deleted inserted replaced
604:1fad28f44fec 631:ffaacab84d1a
9 9
10 import org.apache.log4j.Logger; 10 import org.apache.log4j.Logger;
11 11
12 import alice.codesegment.CodeSegment; 12 import alice.codesegment.CodeSegment;
13 import alice.topology.HostMessage; 13 import alice.topology.HostMessage;
14 import alice.topology.fix.ReceiveDisconnectMessage;
14 15
15 import com.alexmerz.graphviz.ParseException; 16 import com.alexmerz.graphviz.ParseException;
16 import com.alexmerz.graphviz.Parser; 17 import com.alexmerz.graphviz.Parser;
17 import com.alexmerz.graphviz.objects.Edge; 18 import com.alexmerz.graphviz.objects.Edge;
18 import com.alexmerz.graphviz.objects.Graph; 19 import com.alexmerz.graphviz.objects.Graph;
19 import com.alexmerz.graphviz.objects.Node; 20 import com.alexmerz.graphviz.objects.Node;
20 21
21 public class StartTopologyManager extends CodeSegment { 22 public class StartTopologyManager extends CodeSegment {
22 23
23 TopologyManagerConfig conf; 24 TopologyManagerConfig conf;
24 Logger logger = Logger.getLogger(StartTopologyManager.class); 25 Logger logger = Logger.getLogger(StartTopologyManager.class);
25 26
26 public StartTopologyManager(TopologyManagerConfig conf) { 27 public StartTopologyManager(TopologyManagerConfig conf) {
27 this.conf = conf; 28 this.conf = conf;
28 } 29 }
29 30
30 @Override 31 @Override
31 public void run() { 32 public void run() {
32 LinkedList<String> nodeNames = new LinkedList<String>(); 33 new CheckComingHost();
33 HashMap<String, LinkedList<NodeInfo>> topology = new HashMap<String, LinkedList<NodeInfo>>(); 34 ods.put("absCookieTable", new HashMap<String, String>());
34 int nodeNum = 0; 35 ods.put("config", conf );
35 try { 36
36 FileReader reader = new FileReader(new File(conf.confFilePath)); 37 if (!conf.dynamic) {
37 Parser parser = new Parser(); 38 LinkedList<String> nodeNames = new LinkedList<String>();
38 parser.parse(reader); 39 HashMap<String, LinkedList<NodeInfo>> topology = new HashMap<String, LinkedList<NodeInfo>>();
39 ArrayList<Graph> graphs = parser.getGraphs(); 40 int nodeNum = 0;
40 for (Graph graph : graphs) { 41 try {
41 ArrayList<Node> nodes = graph.getNodes(false); 42 FileReader reader = new FileReader(new File(conf.confFilePath));
42 nodeNum = nodes.size(); 43 Parser parser = new Parser();
43 for (Node node : nodes) { 44 parser.parse(reader);
44 String nodeName = node.getId().getId(); 45 ArrayList<Graph> graphs = parser.getGraphs();
45 nodeNames.add(nodeName); 46 for (Graph graph : graphs) {
46 topology.put(nodeName, new LinkedList<NodeInfo>()); 47 ArrayList<Node> nodes = graph.getNodes(false);
47 } 48 nodeNum = nodes.size();
48 ArrayList<Edge> edges = graph.getEdges(); 49 for (Node node : nodes) {
49 HashMap<String, NodeInfo> hash = new HashMap<String, NodeInfo>(); 50 String nodeName = node.getId().getId();
50 for (Edge edge : edges) { 51 nodeNames.add(nodeName);
51 String connection = edge.getAttribute("label"); 52 topology.put(nodeName, new LinkedList<NodeInfo>());
52 String source = edge.getSource().getNode().getId().getId(); 53 }
53 String target = edge.getTarget().getNode().getId().getId(); 54 ArrayList<Edge> edges = graph.getEdges();
54 LinkedList<NodeInfo> sources = topology.get(target); 55 HashMap<String, NodeInfo> hash = new HashMap<String, NodeInfo>();
55 NodeInfo nodeInfo = new NodeInfo(source, connection); 56 for (Edge edge : edges) {
56 sources.add(nodeInfo); 57 String connection = edge.getAttribute("label");
57 hash.put(source + "," + target, nodeInfo); 58 String source = edge.getSource().getNode().getId().getId();
58 } 59 String target = edge.getTarget().getNode().getId().getId();
59 for (Edge edge : edges) { 60 LinkedList<NodeInfo> sources = topology.get(target);
60 String connection = edge.getAttribute("label"); 61 NodeInfo nodeInfo = new NodeInfo(source, connection);
61 String source = edge.getSource().getNode().getId().getId(); 62 sources.add(nodeInfo);
62 String target = edge.getTarget().getNode().getId().getId(); 63 hash.put(source + "," + target, nodeInfo);
63 NodeInfo nodeInfo = hash.get(target + "," + source); 64 }
64 if (nodeInfo != null) { 65 for (Edge edge : edges) {
65 nodeInfo.reverseName = connection; 66 String connection = edge.getAttribute("label");
66 } 67 String source = edge.getSource().getNode().getId().getId();
67 } 68 String target = edge.getTarget().getNode().getId().getId();
68 } 69 NodeInfo nodeInfo = hash.get(target + "," + source);
69 70 if (nodeInfo != null) {
70 } catch (FileNotFoundException e) { 71 nodeInfo.reverseName = connection;
71 logger.error("File not found: " + conf.confFilePath); 72 }
72 e.printStackTrace(); 73 }
73 } catch (ParseException e) { 74 }
74 logger.error("File format error: " + conf.confFilePath); 75
75 e.printStackTrace(); 76 } catch (FileNotFoundException e) {
76 } 77 logger.error("File not found: " + conf.confFilePath);
77 HashMap<String, ArrayList<HostMessage>> connectionList = new HashMap<String, ArrayList<HostMessage>>(); 78 e.printStackTrace();
78 ods.put("connection", connectionList); 79 } catch (ParseException e) {
79 ods.put("_ABSIPTABLE" ,new ArrayList<HostMessage>()); 80 logger.error("File format error: " + conf.confFilePath);
80 81 e.printStackTrace();
81 new createABSIPList(); 82 }
82 83
83 IncomingHosts cs1 = new IncomingHosts(topology, nodeNames); 84 // for recode topology information
84 cs1.host.setKey("host"); 85 // cookie List
85 cs1.connection.setKey("connection"); 86 ods.put("running", false);
86 87 ods.put("resultParse", topology);
87 ConfigWaiter cs3 = new ConfigWaiter(nodeNum); 88 ods.put("nodeNames", nodeNames);
88 cs3.done.setKey("local", "done"); 89
89 90 new IncomingHosts();
90 91
91 } 92 ConfigWaiter cs3 = new ConfigWaiter(nodeNum);
93 cs3.done.setKey("local", "done");
94
95 } else {
96 ods.put("running", true);
97
98 HashMap<String, HostMessage> nameTable = new HashMap<String, HostMessage>();
99
100 if (conf.type == TopologyType.Tree) {
101 int cominghostCount = 0;
102 ParentManager manager = new ParentManager(conf.hasChild);
103 ods.put("parentManager", manager);
104 ods.put("nameTable", nameTable);
105 ods.put("hostCount", cominghostCount);
106 new ComingServiceHosts();
107 new ReceiveDisconnectMessage();
108 }
109 }
110
111 ods.put("topology", new HashMap<String, LinkedList<HostMessage>>());
112 ods.put("createdList", new LinkedList<String>());
113 new CreateHash();
114
115 TopologyFinish cs2 = new TopologyFinish();
116 cs2.finish.setKey("local", "finish");
117 }
92 118
93 } 119 }