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