Search in sources :

Example 6 with ZooKeeperConfig

use of com.ms.silverking.cloud.zookeeper.ZooKeeperConfig in project SilverKing by Morgan-Stanley.

the class StaticDHTCreator method main.

public static void main(String[] args) {
    try {
        StaticDHTCreator sdc;
        StaticDHTCreatorOptions options;
        CmdLineParser parser;
        Set<String> servers;
        String dhtName;
        String gcName;
        int port;
        NamespaceCreationOptions nsCreationOptions;
        UUIDBase uuid;
        options = new StaticDHTCreatorOptions();
        parser = new CmdLineParser(options);
        try {
            parser.parseArgument(args);
        } catch (CmdLineException cle) {
            System.err.println(cle.getMessage());
            parser.printUsage(System.err);
            System.exit(-1);
        }
        if ((options.serverFile == null && options.servers == null) || (options.serverFile != null && options.servers != null)) {
            System.err.println("Exactly one of serverFile and servers should be provided");
            parser.printUsage(System.err);
            System.exit(-1);
        }
        if (options.serverFile != null) {
            servers = ImmutableSet.copyOf(StreamParser.parseFileLines(options.serverFile));
        } else {
            servers = CollectionUtil.parseSet(options.servers, serverDelimiter);
        }
        uuid = new UUIDBase(true);
        if (options.gridConfig != null) {
            gcName = options.gridConfig;
        } else {
            gcName = gcNameBase + uuid.toString();
        }
        if (options.dhtName != null) {
            dhtName = options.dhtName;
        } else {
            dhtName = dhtNameBase + uuid.toString();
        }
        if (options.port == StaticDHTCreatorOptions.defaultPort) {
            port = Util.getFreePort();
        } else {
            port = options.port;
        }
        if (options.nsCreationOptions != null) {
            nsCreationOptions = NamespaceCreationOptions.parse(options.nsCreationOptions);
        } else {
            nsCreationOptions = NamespaceCreationOptions.defaultOptions;
        }
        sdc = new StaticDHTCreator(new ZooKeeperConfig(options.zkEnsemble), servers, options.replication, dhtName, gcName, port, nsCreationOptions, options.gridConfigDir);
        sdc.createStaticDHT(uuid, options.initialHeapSize, options.maxHeapSize, options.skInstanceLogBaseVar, options.dataBaseVar, options.skfsConfigurationFile);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) CmdLineParser(org.kohsuke.args4j.CmdLineParser) UUIDBase(com.ms.silverking.id.UUIDBase) NamespaceCreationOptions(com.ms.silverking.cloud.dht.NamespaceCreationOptions) CmdLineException(org.kohsuke.args4j.CmdLineException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 7 with ZooKeeperConfig

use of com.ms.silverking.cloud.zookeeper.ZooKeeperConfig in project SilverKing by Morgan-Stanley.

the class EmbeddedSK method createEmbeddedSKInstance.

public static ClientDHTConfiguration createEmbeddedSKInstance(String dhtName, String gridConfigName, String ringName, int replication) {
    try {
        int zkPort;
        Path tempDir;
        File zkDir;
        File skDir;
        ZooKeeperConfig zkConfig;
        // 0) Create LWT work pools
        LWTPoolProvider.createDefaultWorkPools();
        // 1) Start an embedded ZooKeeper
        Log.warning("Creating embedded ZooKeeper");
        try {
            tempDir = Files.createTempDirectory(null);
            zkDir = new File(tempDir.toFile(), "zookeeper");
            zkDir.mkdirs();
            skDir = new File(tempDir.toFile(), "silverking");
            skDir.mkdirs();
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
        zkPort = LocalZKImpl.startLocalZK(zkDir.getAbsolutePath());
        zkConfig = new ZooKeeperConfig(InetAddress.getLoopbackAddress().getHostAddress() + ":" + zkPort);
        Log.warning("Embedded ZooKeeper running at: " + zkConfig);
        DHTNodeConfiguration.setDataBasePath(skDir.getAbsolutePath() + "/data");
        // 2) Create ring in ZK
        Log.warning("Creating ring");
        StaticRingCreator.createStaticRing(ringName, zkConfig, ImmutableSet.of(IPAddrUtil.localIPString()), replication);
        Log.warning("Created: " + ringName);
        // 3) Create DHT Config in ZK
        DHTConfiguration dhtConfig;
        MetaClient dhtMC;
        DHTConfigurationZK dhtConfigZK;
        ClientDHTConfiguration clientDHTConfig;
        int dhtPort;
        Log.warning("Creating DHT configuration in ZK");
        if (skPort <= 0) {
            // FIXME
            dhtPort = ThreadLocalRandom.current().nextInt(10000, 20000);
        } else {
            dhtPort = skPort;
        }
        clientDHTConfig = new ClientDHTConfiguration(dhtName, dhtPort, zkConfig);
        dhtMC = new MetaClient(clientDHTConfig);
        dhtConfigZK = new DHTConfigurationZK(dhtMC);
        dhtConfig = DHTConfiguration.emptyTemplate.ringName(ringName).port(dhtPort).passiveNodeHostGroups("").hostGroupToClassVarsMap(new HashMap<String, String>());
        dhtConfigZK.writeToZK(dhtConfig, null);
        Log.warning("Created DHT configuration in ZK");
        // 4) Set cur and target rings
        DHTRingCurTargetZK curTargetZK;
        Log.warning("Setting ring targets");
        curTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
        curTargetZK.setCurRingAndVersionPair(ringName, 0, 0);
        curTargetZK.setTargetRingAndVersionPair(ringName, 0, 0);
        Log.warning("Ring targets set");
        // 4) Start DHTNode
        Log.warning("Starting DHTNode");
        new DHTNode(dhtName, zkConfig, 0, false, false);
        Log.warning("DHTNode started");
        // 5) Return the configuration to the caller
        return clientDHTConfig;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) MetaClient(com.ms.silverking.cloud.dht.meta.MetaClient) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) DHTConfiguration(com.ms.silverking.cloud.dht.meta.DHTConfiguration) IOException(java.io.IOException) DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK) DHTConfigurationZK(com.ms.silverking.cloud.dht.meta.DHTConfigurationZK) DHTNode(com.ms.silverking.cloud.dht.daemon.DHTNode) File(java.io.File)

Example 8 with ZooKeeperConfig

use of com.ms.silverking.cloud.zookeeper.ZooKeeperConfig in project SilverKing by Morgan-Stanley.

the class VersionWatcherTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        if (args.length < 3) {
            System.out.println("<zkConfig> <intervalSeconds> <path...>");
        } else {
            ZooKeeperConfig zkConfig;
            long intervalMillis;
            VersionWatcherTest vwTest;
            zkConfig = new ZooKeeperConfig(args[0]);
            intervalMillis = Integer.parseInt(args[1]) * 1000;
            vwTest = new VersionWatcherTest(new ZooKeeperExtended(zkConfig, 2 * 60 * 1000, null));
            for (int i = 2; i < args.length; i++) {
                vwTest.addWatch(args[i], intervalMillis);
            }
            Thread.sleep(60 * 60 * 1000);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 9 with ZooKeeperConfig

use of com.ms.silverking.cloud.zookeeper.ZooKeeperConfig in project SilverKing by Morgan-Stanley.

the class MetaClient method main.

// for unit testing only
public static void main(String[] args) {
    try {
        if (args.length != 2) {
            System.out.println("args: <cloudConfiguration> <ensemble>");
        } else {
            MetaClient mc;
            ZooKeeperConfig zc;
            CloudConfiguration cloudConfig;
            cloudConfig = CloudConfiguration.parse(args[0]);
            zc = new ZooKeeperConfig(args[1]);
            mc = new MetaClient(cloudConfig, zc);
            mc.test();
        }
    } catch (Exception e) {
        Log.logErrorWarning(e);
    }
}
Also used : ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 10 with ZooKeeperConfig

use of com.ms.silverking.cloud.zookeeper.ZooKeeperConfig in project SilverKing by Morgan-Stanley.

the class NodeCreationWatcherTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        if (args.length < 2) {
            System.out.println("<zkConfig> <path...>");
        } else {
            ZooKeeperConfig zkConfig;
            NodeCreationWatcherTest wTest;
            zkConfig = new ZooKeeperConfig(args[0]);
            wTest = new NodeCreationWatcherTest(new ZooKeeperExtended(zkConfig, 2 * 60 * 1000, null));
            for (int i = 1; i < args.length; i++) {
                wTest.addWatch(args[i]);
            }
            Thread.sleep(60 * 60 * 1000);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) ZooKeeperExtended(com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)

Aggregations

ZooKeeperConfig (com.ms.silverking.cloud.zookeeper.ZooKeeperConfig)14 IOException (java.io.IOException)7 KeeperException (org.apache.zookeeper.KeeperException)6 MetaClient (com.ms.silverking.cloud.dht.meta.MetaClient)2 ZooKeeperExtended (com.ms.silverking.cloud.zookeeper.ZooKeeperExtended)2 CmdLineException (org.kohsuke.args4j.CmdLineException)2 CmdLineParser (org.kohsuke.args4j.CmdLineParser)2 GetOptions (com.ms.silverking.cloud.dht.GetOptions)1 NamespaceCreationOptions (com.ms.silverking.cloud.dht.NamespaceCreationOptions)1 PutOptions (com.ms.silverking.cloud.dht.PutOptions)1 ClientDHTConfiguration (com.ms.silverking.cloud.dht.client.ClientDHTConfiguration)1 DHTClient (com.ms.silverking.cloud.dht.client.DHTClient)1 DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)1 DHTNode (com.ms.silverking.cloud.dht.daemon.DHTNode)1 DHTConfiguration (com.ms.silverking.cloud.dht.meta.DHTConfiguration)1 DHTConfigurationZK (com.ms.silverking.cloud.dht.meta.DHTConfigurationZK)1 DHTRingCurTargetZK (com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK)1 MetaClient (com.ms.silverking.cloud.meta.MetaClient)1 MetaClient (com.ms.silverking.cloud.toporing.meta.MetaClient)1 UUIDBase (com.ms.silverking.id.UUIDBase)1