changeset 73:f1f34c3e33d4

add FileParser.java
author akahori
date Wed, 05 Sep 2018 09:04:06 +0900
parents 32f6f9de97c1
children e2ce8038815a
files src/main/java/christie/topology/manager/FileParser.java src/main/java/christie/topology/manager/TopologyManager.java
diffstat 2 files changed, 93 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/christie/topology/manager/FileParser.java	Wed Sep 05 09:04:06 2018 +0900
@@ -0,0 +1,87 @@
+package christie.topology.manager;
+
+import christie.annotation.Peek;
+import christie.codegear.CodeGear;
+import christie.codegear.CodeGearManager;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+
+import org.apache.log4j.Logger;
+
+import com.alexmerz.graphviz.ParseException;
+import com.alexmerz.graphviz.Parser;
+import com.alexmerz.graphviz.objects.*;
+
+public class FileParser extends CodeGear {
+
+    @Peek
+    TopologyManagerConfig topologyManagerConfig;
+
+    private Logger logger = Logger.getLogger(TopologyManager.class);
+
+
+    @Override
+    protected void run(CodeGearManager cgm) {
+        LinkedList<String> nodeNames = new LinkedList<>();
+        HashMap<String, LinkedList<NodeInfo>> resultParse = new HashMap<>();
+        int nodeNum = 0;
+
+        try {
+            FileReader reader = new FileReader(new File(topologyManagerConfig.confFilePath));
+            Parser parser = new Parser();
+            parser.parse(reader);
+
+
+            ArrayList<Graph> digraphs = parser.getGraphs();
+
+
+            for (Graph digraph : digraphs) {
+                ArrayList<Node> nodes = digraph.getNodes(false);
+                nodeNum = nodes.size();
+
+                for (Node node : nodes) {
+                    String nodeName = node.getId().getId();
+                    nodeNames.add(nodeName);
+                    resultParse.put(nodeName, new LinkedList<>());
+                }
+
+                ArrayList<Edge> edges = digraph.getEdges();
+                HashMap<String, NodeInfo> hash = new HashMap<>();
+
+                String connection;
+                String source;
+                String target;
+
+                NodeInfo nodeInfo;
+
+                for (Edge edge : edges) {
+                    connection = edge.getAttribute("label");
+                    source = edge.getSource().getNode().getId().getId();
+                    target = edge.getTarget().getNode().getId().getId();
+                    nodeInfo = new NodeInfo(source, connection, target);
+
+                    resultParse.get(source).add(nodeInfo);
+
+                }
+            }
+
+        } catch (FileNotFoundException e) {
+            logger.error("File not found: " + topologyManagerConfig.confFilePath);
+            e.printStackTrace();
+        } catch (ParseException e) {
+            logger.error("File format error: " + topologyManagerConfig.confFilePath);
+            e.printStackTrace();
+        }
+
+        getLocalDGM().put("resultParse", resultParse);
+        getLocalDGM().put("nodeNum", nodeNum);
+        getLocalDGM().put("nodeNames", nodeNames);
+
+
+    }
+}
--- a/src/main/java/christie/topology/manager/TopologyManager.java	Sat Sep 01 10:22:27 2018 +0900
+++ b/src/main/java/christie/topology/manager/TopologyManager.java	Wed Sep 05 09:04:06 2018 +0900
@@ -12,112 +12,28 @@
 import java.util.LinkedList;
 
 import christie.topology.HostMessage;
-import org.apache.log4j.Logger;
-
-import com.alexmerz.graphviz.ParseException;
-import com.alexmerz.graphviz.Parser;
-import com.alexmerz.graphviz.objects.*;
 
 public class TopologyManager extends CodeGear {
 
-    @Peek
-    TopologyManagerConfig topologyManagerConfig;
-
-    private Logger logger = Logger.getLogger(TopologyManager.class);
-
     public TopologyManager() {
     }
 
     @Override
     protected void run(CodeGearManager cgm) {
         cgm.setup(new CheckComingHost());
-
         getLocalDGM().put("absCookieTable", new HashMap<String, String>());
 
-        // if (!conf.dynamic) は, conf.dynamic = trueの動作がわからないので,  省いた.
-
-        LinkedList<String> nodeNames = new LinkedList<>();
-        HashMap<String, LinkedList<NodeInfo>> resultParse = new HashMap<>();
-        int nodeNum = 0;
-
-        try {
-            FileReader reader = new FileReader(new File(topologyManagerConfig.confFilePath));
-            Parser parser = new Parser();
-            parser.parse(reader);
-
-
-            ArrayList<Graph> digraphs = parser.getGraphs();
-
-
-            for (Graph digraph : digraphs) {
-                ArrayList<Node> nodes = digraph.getNodes(false);
-                nodeNum = nodes.size();
-
-                for (Node node : nodes) {
-                    String nodeName = node.getId().getId();
-                    nodeNames.add(nodeName);
-                    resultParse.put(nodeName, new LinkedList<>());
-                }
-
-                ArrayList<Edge> edges = digraph.getEdges();
-                HashMap<String, NodeInfo> hash = new HashMap<>();
-
-                String connection;
-                String source;
-                String target;
-
-                NodeInfo nodeInfo;
-
-                // まず1回グラフを読み込む
-                for (Edge edge : edges) {
-                    connection = edge.getAttribute("label");
-                    source = edge.getSource().getNode().getId().getId();
-                    target = edge.getTarget().getNode().getId().getId();
-                    nodeInfo = new NodeInfo(source, connection, target);
-
-                    resultParse.get(source).add(nodeInfo);
-
-                    //hash.put(source + "," + target, nodeInfo);
-                }
-
-                // hash.get(target + "," + source); をして, グラフを逆にたどって, reverseNameにlabelを入れてる.
-                /*
-                for (Edge edge : edges) {
-                    connection = edge.getAttribute("label");
-                    source = edge.getSource().getNode().getId().getId();
-                    target = edge.getTarget().getNode().getId().getId();
-                    nodeInfo = hash.get(target + "," + source);
-
-                    if (nodeInfo != null) {
-                        nodeInfo.reverseName = connection;
-                    }
-
-                }*/
-            }
-
-        } catch (FileNotFoundException e) {
-            logger.error("File not found: " + topologyManagerConfig.confFilePath);
-            e.printStackTrace();
-        } catch (ParseException e) {
-            logger.error("File format error: " + topologyManagerConfig.confFilePath);
-            e.printStackTrace();
-        }
-
-        // for recode topology information
-        // cookie List
-        getLocalDGM().put("running", false);
-        getLocalDGM().put("resultParse", resultParse);
-        getLocalDGM().put("nodeNames", nodeNames);
-        getLocalDGM().put("hostInfoMap", new HashMap<String, HostMessage>());
-        getLocalDGM().put("topology", new HashMap<String, HashMap<String, HostMessage>>());
-        getLocalDGM().put("nodeNum", nodeNum);
-        getLocalDGM().put("createdList", new LinkedList<String>());
-
+        cgm.setup(new FileParser());
         cgm.setup(new IncomingHosts());
         cgm.setup(new ConfigWaiter());
         cgm.setup(new CreateHash());
         cgm.setup(new TopologyFinish());
 
+        getLocalDGM().put("running", false);
+        getLocalDGM().put("hostInfoMap", new HashMap<String, HostMessage>());
+        getLocalDGM().put("topology", new HashMap<String, HashMap<String, HostMessage>>());
+        getLocalDGM().put("createdList", new LinkedList<String>());
+
     }