changeset 60:cfd79a71f9cd

refactor topology manager
author akahori
date Tue, 28 Aug 2018 10:49:26 +0900
parents 76b6da075ce0
children 20d4c0cce914
files src/main/java/christie/topology/manager/CreateHash.java src/main/java/christie/topology/manager/IncomingHosts.java src/main/java/christie/topology/manager/SearchHostName.java src/main/java/christie/topology/manager/StartTopologyManager.java src/main/java/christie/topology/manager/TopologyFinish.java src/main/java/christie/topology/manager/TopologyManager.java
diffstat 6 files changed, 29 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/christie/topology/manager/CreateHash.java	Tue Aug 28 09:45:53 2018 +0900
+++ b/src/main/java/christie/topology/manager/CreateHash.java	Tue Aug 28 10:49:26 2018 +0900
@@ -1,6 +1,7 @@
 package christie.topology.manager;
 
 
+import christie.annotation.Peek;
 import christie.annotation.Take;
 import christie.codegear.CodeGear;
 
@@ -14,11 +15,11 @@
 public class CreateHash extends CodeGear{
     // this CodeSegment change raw string to MD5
 
-    // Question: orderHashどこで使われているかわかんない
-    //@Take
-    //orderHash;
+    // Question: orderHashどこで使われているかわかんない. たぶんcheckcominghostでhostが来た時に使う?
+    @Take
+    String orderHash;
 
-    @Take
+    @Peek
     LinkedList<String> createdList;
 
 
@@ -42,7 +43,6 @@
             if (count == createdList.size()) checkNewStr = true;
         }
         createdList.add(raw);
-        getLocalDGM().put("createdList", createdList);
 
         try { // convert to MD5
             String MD5 = convertMD5(raw);
--- a/src/main/java/christie/topology/manager/IncomingHosts.java	Tue Aug 28 09:45:53 2018 +0900
+++ b/src/main/java/christie/topology/manager/IncomingHosts.java	Tue Aug 28 10:49:26 2018 +0900
@@ -13,19 +13,16 @@
 
 public class IncomingHosts extends CodeGear {
 
-    @Take // Topology from parse file
+    @Peek // Topology from parse file
     HashMap<String, LinkedList<NodeInfo>> resultParse;
+    @Peek // nodeName list
+    LinkedList<String> nodeNames;
+    @Peek
+    HashMap<String, String> absCookieTable;
 
-    @Take // nodeName list
-    LinkedList<String> nodeNames;
 
     @Take // new coming host info
     HostMessage newHost;
-
-    //@Take
-    @Peek
-    HashMap<String, String> absCookieTable;
-
     @Take
     String MD5;
 
@@ -43,12 +40,10 @@
 
         // Manager connect to Node
         cgm.createRemoteDGM(nodeName, newHost.hostName, newHost.port);
-        getDGM(nodeName).put( "host", nodeName);
-
 
         absCookieTable.put(MD5, nodeName);
-        //getLocalDGM().put("absCookieTable", absCookieTable);
 
+        getDGM(nodeName).put( "host", nodeName);
         getDGM(nodeName).put("cookie", MD5);
         log.info( "toplology manager connected from " + nodeName);
 
@@ -60,7 +55,6 @@
             hostMessage.remoteAbsName = nodeInfo.sourceNodeName;
 
             getLocalDGM().put("nodeInfo", hostMessage);
-
             getLocalDGM().put("hostInfo", hostMessage);
             log.info(" write to " + nodeInfo.sourceNodeName + " config message =" + hostMessage.toString() + " remain "
                     + Integer.toString((nodeNames.size())));
@@ -76,11 +70,6 @@
                 getLocalDGM().put("hostInfo", new HostMessage("",0,"","")); // end mark
             }
         }
-
-
-        getLocalDGM().put("nodeNames", nodeNames);
-        getLocalDGM().put("resultParse", resultParse);
-
         cgm.setup(new IncomingHosts());
     }
 }
--- a/src/main/java/christie/topology/manager/SearchHostName.java	Tue Aug 28 09:45:53 2018 +0900
+++ b/src/main/java/christie/topology/manager/SearchHostName.java	Tue Aug 28 10:49:26 2018 +0900
@@ -16,7 +16,7 @@
     @Take // reconnect NodeInfo
     HostMessage reconnectHost;
 
-    @Take
+    @Peek
     HashMap<String, LinkedList<HostMessage>> topology;
 
     @Peek
@@ -81,9 +81,6 @@
             }
             System.out.println();
         }
-
-        getLocalDGM().put("topology", topology);
-
     }
 
 }
--- a/src/main/java/christie/topology/manager/StartTopologyManager.java	Tue Aug 28 09:45:53 2018 +0900
+++ b/src/main/java/christie/topology/manager/StartTopologyManager.java	Tue Aug 28 10:49:26 2018 +0900
@@ -4,17 +4,16 @@
 import christie.codegear.StartCodeGear;
 
 public class StartTopologyManager extends StartCodeGear{
-    TopologyManagerConfig conf;
 
-    public StartTopologyManager(CodeGearManager cgm, TopologyManagerConfig conf){
+    public StartTopologyManager(CodeGearManager cgm, TopologyManagerConfig topologyManagerConfig){
         super(cgm);
-        this.conf = conf;
-
+        cgm.getLocalDGM().put("topologyManagerConfig", topologyManagerConfig);
+        cgm.setup(new TopologyManager());
     }
 
     @Override
     protected void run(CodeGearManager cgm) {
-        cgm.setup(new TopologyManager(this.conf));
+
     }
 
 
--- a/src/main/java/christie/topology/manager/TopologyFinish.java	Tue Aug 28 09:45:53 2018 +0900
+++ b/src/main/java/christie/topology/manager/TopologyFinish.java	Tue Aug 28 10:49:26 2018 +0900
@@ -14,7 +14,7 @@
     //cs2.finish.setKey("local", "finish");
 
     @Peek
-    TopologyManagerConfig config;
+    TopologyManagerConfig topologyManagerConfig;
 
     @Take
     Long startTime;
@@ -22,7 +22,7 @@
     @Override
     protected void run(CodeGearManager cgm) {
 
-        if (config.showTime) {
+        if (topologyManagerConfig.showTime) {
             System.out.println("TopologymanagerTime = "+ (System.currentTimeMillis()-startTime));
         }
         //System.exit(0);
--- a/src/main/java/christie/topology/manager/TopologyManager.java	Tue Aug 28 09:45:53 2018 +0900
+++ b/src/main/java/christie/topology/manager/TopologyManager.java	Tue Aug 28 10:49:26 2018 +0900
@@ -1,5 +1,7 @@
 package christie.topology.manager;
 
+import christie.annotation.Peek;
+import christie.annotation.Take;
 import christie.codegear.CodeGear;
 import christie.codegear.CodeGearManager;
 
@@ -19,11 +21,12 @@
 
 public class TopologyManager extends CodeGear {
 
-    private TopologyManagerConfig conf;
+    @Peek
+    TopologyManagerConfig topologyManagerConfig;
+
     private Logger logger = Logger.getLogger(TopologyManager.class);
 
-    public TopologyManager(TopologyManagerConfig conf) {
-        this.conf = conf;
+    public TopologyManager() {
     }
 
     @Override
@@ -31,7 +34,6 @@
         cgm.setup(new CheckComingHost());
 
         getLocalDGM().put("absCookieTable", new HashMap<String, String>());
-        getLocalDGM().put("config", conf );
 
         // if (!conf.dynamic) は, conf.dynamic = trueの動作がわからないので,  省いた.
 
@@ -40,7 +42,7 @@
         int nodeNum = 0;
 
         try {
-            FileReader reader = new FileReader(new File(conf.confFilePath));
+            FileReader reader = new FileReader(new File(topologyManagerConfig.confFilePath));
             Parser parser = new Parser();
             parser.parse(reader);
 
@@ -94,10 +96,10 @@
             }
 
         } catch (FileNotFoundException e) {
-            logger.error("File not found: " + conf.confFilePath);
+            logger.error("File not found: " + topologyManagerConfig.confFilePath);
             e.printStackTrace();
         } catch (ParseException e) {
-            logger.error("File format error: " + conf.confFilePath);
+            logger.error("File format error: " + topologyManagerConfig.confFilePath);
             e.printStackTrace();
         }
 
@@ -106,6 +108,8 @@
         getLocalDGM().put("running", false);
         getLocalDGM().put("resultParse", topology);
         getLocalDGM().put("nodeNames", nodeNames);
+        getLocalDGM().put("hostInfoMap", new HashMap<String, HostMessage>());
+        getLocalDGM().put("topology", new HashMap<String, LinkedList<HostMessage>>());
 
         cgm.setup(new IncomingHosts());
 
@@ -118,7 +122,6 @@
 
 
 
-        getLocalDGM().put("topology", new HashMap<String, LinkedList<HostMessage>>());
         getLocalDGM().put("createdList", new LinkedList<String>());
         cgm.setup(new CreateHash());