Mercurial > hg > Database > Alice
annotate src/main/java/alice/topology/manager/StartTopologyManager.java @ 404:fee3efd9257d dispose
add node when application status running
author | sugi |
---|---|
date | Mon, 23 Jun 2014 18:12:57 +0900 |
parents | 539b7f5772c7 |
children | 74e13553e3e3 |
rev | line source |
---|---|
401 | 1 package alice.topology.manager; |
2 | |
3 import java.io.File; | |
4 import java.io.FileNotFoundException; | |
5 import java.io.FileReader; | |
6 import java.util.ArrayList; | |
7 import java.util.HashMap; | |
8 import java.util.LinkedList; | |
9 | |
10 import org.apache.log4j.Logger; | |
11 | |
12 import alice.codesegment.CodeSegment; | |
403
539b7f5772c7
manager in extendTopology mode have parent Information at each node
sugi
parents:
402
diff
changeset
|
13 import alice.topology.HostMessage; |
401 | 14 |
15 import com.alexmerz.graphviz.ParseException; | |
16 import com.alexmerz.graphviz.Parser; | |
17 import com.alexmerz.graphviz.objects.Edge; | |
18 import com.alexmerz.graphviz.objects.Graph; | |
19 import com.alexmerz.graphviz.objects.Node; | |
20 | |
21 public class StartTopologyManager extends CodeSegment { | |
22 | |
23 TopologyManagerConfig conf; | |
24 Logger logger = Logger.getLogger(StartTopologyManager.class); | |
25 | |
26 public StartTopologyManager(TopologyManagerConfig conf) { | |
27 this.conf = conf; | |
28 } | |
29 | |
30 @Override | |
31 public void run() { | |
402 | 32 if (!conf.extendTopology) { |
33 LinkedList<String> nodeNames = new LinkedList<String>(); | |
34 HashMap<String, LinkedList<NodeInfo>> topology = new HashMap<String, LinkedList<NodeInfo>>(); | |
35 int nodeNum = 0; | |
36 try { | |
37 FileReader reader = new FileReader(new File(conf.confFilePath)); | |
38 Parser parser = new Parser(); | |
39 parser.parse(reader); | |
40 ArrayList<Graph> graphs = parser.getGraphs(); | |
41 for (Graph graph : graphs) { | |
42 ArrayList<Node> nodes = graph.getNodes(false); | |
43 nodeNum = nodes.size(); | |
44 for (Node node : nodes) { | |
45 String nodeName = node.getId().getId(); | |
46 nodeNames.add(nodeName); | |
47 topology.put(nodeName, new LinkedList<NodeInfo>()); | |
48 } | |
49 ArrayList<Edge> edges = graph.getEdges(); | |
50 HashMap<String, NodeInfo> hash = new HashMap<String, NodeInfo>(); | |
51 for (Edge edge : edges) { | |
52 String connection = edge.getAttribute("label"); | |
53 String source = edge.getSource().getNode().getId().getId(); | |
54 String target = edge.getTarget().getNode().getId().getId(); | |
55 LinkedList<NodeInfo> sources = topology.get(target); | |
56 NodeInfo nodeInfo = new NodeInfo(source, connection); | |
57 sources.add(nodeInfo); | |
58 hash.put(source + "," + target, nodeInfo); | |
59 } | |
60 for (Edge edge : edges) { | |
61 String connection = edge.getAttribute("label"); | |
62 String source = edge.getSource().getNode().getId().getId(); | |
63 String target = edge.getTarget().getNode().getId().getId(); | |
64 NodeInfo nodeInfo = hash.get(target + "," + source); | |
65 if (nodeInfo != null) { | |
66 nodeInfo.reverseName = connection; | |
67 } | |
401 | 68 } |
69 } | |
402 | 70 |
71 } catch (FileNotFoundException e) { | |
72 logger.error("File not found: " + conf.confFilePath); | |
73 e.printStackTrace(); | |
74 } catch (ParseException e) { | |
75 logger.error("File format error: " + conf.confFilePath); | |
76 e.printStackTrace(); | |
401 | 77 } |
402 | 78 |
79 IncomingHosts cs1 = new IncomingHosts(topology, nodeNames); | |
80 cs1.host.setKey("local", "host"); | |
81 | |
82 ConfigWaiter cs3 = new ConfigWaiter(nodeNum); | |
83 cs3.done.setKey("local", "done"); | |
84 } else { | |
85 System.out.println("mode -t"); | |
404 | 86 HashMap<String,HostMessage> parentInfo = new HashMap<String,HostMessage>(); |
402 | 87 int cominghostCount = 0; |
404 | 88 ods.put("nodeConnectionInfo", parentInfo); |
402 | 89 ods.put("hostCount", cominghostCount); |
90 new ComingServiceHosts(); | |
401 | 91 } |
92 } | |
93 | |
94 } |