Mercurial > hg > Database > Christie
changeset 43:ea9657dc8311
add CreateHash SearchHostName TopologyManager
author | akahori |
---|---|
date | Thu, 02 Aug 2018 11:41:29 +0900 |
parents | d7ac4abc0447 |
children | 6664efac18ee |
files | src/main/java/christie/topology/manager/CreateHash.java src/main/java/christie/topology/manager/SearchHostName.java src/main/java/christie/topology/manager/TopologyFinish.java |
diffstat | 3 files changed, 193 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/topology/manager/CreateHash.java Thu Aug 02 11:41:29 2018 +0900 @@ -0,0 +1,73 @@ +package christie.topology.manager; + + +import christie.annotation.Take; +import christie.codegear.CodeGear; + +import christie.codegear.CodeGearManager; +import org.apache.commons.lang3.RandomStringUtils; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.LinkedList; + +public class CreateHash extends CodeGear{ + // this CodeSegment change raw string to MD5 + + // Question: orderHashどこで使われているかわかんない + //@Take + //orderHash; + + @Take + LinkedList<String> createdList; + + + public CreateHash(){ } + + @Override + protected void run(CodeGearManager cgm) { + + boolean checkNewStr = false; + String raw = null; + + while (!checkNewStr){ + raw = RandomStringUtils.randomAscii(10); + // checking raw String has already created + int count = 0; + for (String str : createdList) { + if (raw.equals(str)) break; + count++; + } + + if (count == createdList.size()) checkNewStr = true; + } + createdList.add(raw); + getLocalDGM().put("createdList", createdList); + + try { // convert to MD5 + String MD5 = convertMD5(raw); + + getLocalDGM().put("MD5", MD5); + } catch (NoSuchAlgorithmException e) { + System.out.println("cannot convert MD5"); + + } + cgm.setup(new CreateHash()); + } + + private String convertMD5(String raw) throws NoSuchAlgorithmException{ + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(raw.getBytes()); + byte[] hash = md.digest(); + StringBuilder builder = new StringBuilder(); + for (byte aHash : hash) { + if ((0xff & aHash) < 0x10) { + builder.append("0" + Integer.toHexString((0xff & aHash))); + } else { + builder.append(Integer.toHexString((0xff & aHash))); + } + } + return builder.toString(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/topology/manager/SearchHostName.java Thu Aug 02 11:41:29 2018 +0900 @@ -0,0 +1,89 @@ +package christie.topology.manager; + + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.HostMessage; +import org.msgpack.type.ValueFactory; + +import java.util.HashMap; +import java.util.LinkedList; + +public class SearchHostName extends CodeGear { + + @Take // reconnect NodeInfo + HostMessage reconnectHost; + + @Take + HashMap<String, LinkedList<HostMessage>> topology; + + @Peek + boolean running; + + + public SearchHostName(){ + + } + + @Override + protected void run(CodeGearManager cgm) { + + + // Question: remove処理 どうしようか. いらない気もする. + // DataSegment.remove(hostInfo.absName); + + cgm.createRemoteDGM(reconnectHost.absName, reconnectHost.name, reconnectHost.port); + getDGM(reconnectHost.absName).put("host", reconnectHost.absName); + + // put Host dataSegment on reconnect node + if (topology.containsKey(reconnectHost.absName)) { + + // Question: これはバグ...? + // ods.put(reconnectHost.absName, "dummy"); // this is bug + + if (running){ + getLocalDGM().put(reconnectHost.absName, ValueFactory.createNilValue()); + } + + + LinkedList<HostMessage> hostList = topology.get(reconnectHost.absName); + for (HostMessage host : hostList){ + getLocalDGM().put(reconnectHost.absName, host); + System.out.println("put data in "+ reconnectHost.absName); + } + } + + // update topology information + for (LinkedList<HostMessage> list :topology.values()){ + for (HostMessage host : list){ + + // find and update old info + if (!reconnectHost.absName.equals(host.absName)) continue; + + if (!reconnectHost.name.equals(host.name) || reconnectHost.port != host.port){ + host.name = reconnectHost.name; + host.port = reconnectHost.port; + + getLocalDGM().put(host.remoteAbsName, host); + + } else { + // nothing to do ? + } + } + } + + for (LinkedList<HostMessage> list :topology.values()){ + System.out.print(list.get(0).remoteAbsName+" : "); + for (HostMessage host : list){ + System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.remoteAbsName+" ]"); + } + System.out.println(); + } + + getLocalDGM().put("topology", topology); + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/topology/manager/TopologyFinish.java Thu Aug 02 11:41:29 2018 +0900 @@ -0,0 +1,31 @@ +package christie.topology.manager; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; + + +public class TopologyFinish extends CodeGear { + + + // Question: Finishもどこで使われているかわかんない. + //public Receiver finish = ids.create(CommandType.TAKE); + //cs2.finish.setKey("local", "finish"); + + @Peek + TopologyManagerConfig config; + + @Take + Long startTime; + + @Override + protected void run(CodeGearManager cgm) { + + if (config.showTime) { + System.out.println("TopologymanagerTime = "+ (System.currentTimeMillis()-startTime)); + } + System.exit(0); + } + +}