Search in sources :

Example 1 with MetaClient

use of com.ms.silverking.cloud.dht.meta.MetaClient in project SilverKing by Morgan-Stanley.

the class MetaTool method doWork.

@Override
protected void doWork(MetaToolOptions options) throws IOException, KeeperException {
    MetaClient mc;
    Tool tool;
    ZooKeeperConfig zkConfig;
    tool = Tool.valueOf(options.tool);
    zkConfig = new ZooKeeperConfig(options.zkConfig);
    mc = new MetaClient(namedDHTConfigurationFor(tool, options.name), zkConfig);
    doWork(options, new MetaToolWorker(getModule(tool, mc)));
}
Also used : ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) MetaClient(com.ms.silverking.cloud.dht.meta.MetaClient)

Example 2 with MetaClient

use of com.ms.silverking.cloud.dht.meta.MetaClient 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 3 with MetaClient

use of com.ms.silverking.cloud.dht.meta.MetaClient in project SilverKing by Morgan-Stanley.

the class DHTClient method openSession.

/**
 * Open a new session to the specified SilverKing DHT instance using the given SessionOptions.
 * @param sessionOptions options specifying the SilverKing DHT instance and the parameters of this session
 * @return a new session to the given instance
 * @throws ClientException
 */
public DHTSession openSession(SessionOptions sessionOptions) throws ClientException {
    ClientDHTConfiguration dhtConfig;
    String preferredServer;
    dhtConfig = sessionOptions.getDHTConfig();
    preferredServer = sessionOptions.getPreferredServer();
    if (preferredServer != null) {
        if (preferredServer.equals(SessionOptions.EMBEDDED_PASSIVE_NODE)) {
            embedPassiveNode(dhtConfig);
            preferredServer = null;
        } else if (preferredServer.equals(SessionOptions.EMBEDDED_KVS)) {
            String gcBase;
            String gcName;
            dhtConfig = embedKVS();
            // FIXME - make user configurable
            gcBase = "/tmp";
            gcName = "GC_" + dhtConfig.getName();
            try {
                Log.warningf("GridConfigBase: %s", gcBase);
                Log.warningf("GridConfigName: %s", gcName);
                StaticDHTCreator.writeGridConfig(dhtConfig, gcBase, gcName);
            } catch (IOException e) {
                throw new ClientException("Error creating embedded kvs", e);
            }
            preferredServer = null;
        }
    }
    sessionCreationLock.lock();
    try {
        DHTSession session;
        if (preferredServer == null) {
            preferredServer = IPAddrUtil.localIPString();
        }
        // session = dhtNameToSessionMap.get(dhtConfig.getName());
        // FUTURE - this forces a new session
        session = null;
        // think about whether we want to use multiple or cache to common
        if (session == null) {
            DHTSession prev;
            int serverPort;
            try {
                if (dhtConfig.hasPort()) {
                    serverPort = dhtConfig.getPort();
                } else {
                    MetaClient mc;
                    MetaPaths mp;
                    long latestConfigVersion;
                    Log.warning("dhtConfig.getZkLocs(): " + dhtConfig.getZKConfig());
                    mc = new MetaClient(dhtConfig);
                    mp = mc.getMetaPaths();
                    Log.warning("getting latest version: " + mp.getInstanceConfigPath());
                    latestConfigVersion = mc.getZooKeeper().getLatestVersion(mp.getInstanceConfigPath());
                    Log.warning("latestConfigVersion: " + latestConfigVersion);
                    serverPort = new DHTConfigurationZK(mc).readFromZK(latestConfigVersion, null).getPort();
                }
            } catch (Exception e) {
                throw new ClientException(e);
            }
            try {
                session = new DHTSessionImpl(dhtConfig, new IPAndPort(IPAddrUtil.serverNameToAddr(preferredServer), serverPort), absMillisTimeSource, serializationRegistry, sessionOptions.getTimeoutController());
            } catch (IOException ioe) {
                throw new ClientException(ioe);
            }
            Log.info("session returned: ", session);
        /*
				prev = dhtNameToSessionMap.put(dhtConfig.getName(), session);
				if (prev != null) {
				    throw new RuntimeException("panic");
				}
				*/
        }
        return session;
    } finally {
        sessionCreationLock.unlock();
    }
}
Also used : IPAndPort(com.ms.silverking.net.IPAndPort) MetaClient(com.ms.silverking.cloud.dht.meta.MetaClient) IOException(java.io.IOException) IOException(java.io.IOException) MetaPaths(com.ms.silverking.cloud.dht.meta.MetaPaths) DHTConfigurationZK(com.ms.silverking.cloud.dht.meta.DHTConfigurationZK) DHTSessionImpl(com.ms.silverking.cloud.dht.client.impl.DHTSessionImpl)

Example 4 with MetaClient

use of com.ms.silverking.cloud.dht.meta.MetaClient in project SilverKing by Morgan-Stanley.

the class DHTSessionImpl method getNSLinkMeta.

private NamespaceLinkMeta getNSLinkMeta() {
    synchronized (this) {
        if (nsLinkMeta == null) {
            try {
                MetaClient mc;
                mc = new MetaClient(dhtConfig.getName(), dhtConfig.getZKConfig());
                nsLinkMeta = new NamespaceLinkMeta(new NamespaceLinksZK(mc));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return nsLinkMeta;
    }
}
Also used : MetaClient(com.ms.silverking.cloud.dht.meta.MetaClient) NamespaceLinksZK(com.ms.silverking.cloud.dht.meta.NamespaceLinksZK) TimeoutException(com.ms.silverking.cloud.dht.common.TimeoutException) NamespaceCreationException(com.ms.silverking.cloud.dht.client.NamespaceCreationException) NamespaceNotCreatedException(com.ms.silverking.cloud.dht.daemon.storage.NamespaceNotCreatedException) IOException(java.io.IOException) NamespaceDeletionException(com.ms.silverking.cloud.dht.client.NamespaceDeletionException) NamespaceRecoverException(com.ms.silverking.cloud.dht.client.NamespaceRecoverException) RetrievalException(com.ms.silverking.cloud.dht.client.RetrievalException)

Example 5 with MetaClient

use of com.ms.silverking.cloud.dht.meta.MetaClient in project SilverKing by Morgan-Stanley.

the class LogStreamConfig method configureLogStreams.

public static void configureLogStreams(SKGridConfiguration gc, String logFileName) throws IOException, KeeperException {
    MetaClient dhtMC;
    DHTConfiguration dhtConfig;
    ClassVarsZK classVarsZK;
    ClassVars defaultClassVars;
    PrintStream logStream;
    File logDir;
    dhtMC = new com.ms.silverking.cloud.dht.meta.MetaClient(gc);
    dhtConfig = dhtMC.getDHTConfiguration();
    classVarsZK = new ClassVarsZK(dhtMC);
    if (dhtConfig.getDefaultClassVars() != null) {
        defaultClassVars = DHTConstants.defaultDefaultClassVars.overrideWith(classVarsZK.getClassVars(dhtConfig.getDefaultClassVars()));
    } else {
        defaultClassVars = DHTConstants.defaultDefaultClassVars;
    }
    logDir = new File(DHTConstants.getSKInstanceLogDir(defaultClassVars, gc));
    Log.warning("Ensuring created: ", logDir);
    logDir.mkdirs();
    logStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(logDir, logFileName))), true);
    System.setOut(logStream);
    System.setErr(logStream);
    Log.setPrintStreams(logStream);
}
Also used : ClassVarsZK(com.ms.silverking.cloud.dht.meta.ClassVarsZK) PrintStream(java.io.PrintStream) MetaClient(com.ms.silverking.cloud.dht.meta.MetaClient) MetaClient(com.ms.silverking.cloud.dht.meta.MetaClient) FileOutputStream(java.io.FileOutputStream) ClassVars(com.ms.silverking.cloud.dht.meta.ClassVars) DHTConfiguration(com.ms.silverking.cloud.dht.meta.DHTConfiguration) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

MetaClient (com.ms.silverking.cloud.dht.meta.MetaClient)6 IOException (java.io.IOException)3 DHTConfiguration (com.ms.silverking.cloud.dht.meta.DHTConfiguration)2 DHTConfigurationZK (com.ms.silverking.cloud.dht.meta.DHTConfigurationZK)2 ZooKeeperConfig (com.ms.silverking.cloud.zookeeper.ZooKeeperConfig)2 File (java.io.File)2 NamespaceCreationException (com.ms.silverking.cloud.dht.client.NamespaceCreationException)1 NamespaceDeletionException (com.ms.silverking.cloud.dht.client.NamespaceDeletionException)1 NamespaceRecoverException (com.ms.silverking.cloud.dht.client.NamespaceRecoverException)1 RetrievalException (com.ms.silverking.cloud.dht.client.RetrievalException)1 DHTSessionImpl (com.ms.silverking.cloud.dht.client.impl.DHTSessionImpl)1 TimeoutException (com.ms.silverking.cloud.dht.common.TimeoutException)1 DHTNode (com.ms.silverking.cloud.dht.daemon.DHTNode)1 NamespaceNotCreatedException (com.ms.silverking.cloud.dht.daemon.storage.NamespaceNotCreatedException)1 ClassVars (com.ms.silverking.cloud.dht.meta.ClassVars)1 ClassVarsZK (com.ms.silverking.cloud.dht.meta.ClassVarsZK)1 DHTRingCurTargetZK (com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK)1 InstanceExclusionZK (com.ms.silverking.cloud.dht.meta.InstanceExclusionZK)1 MetaPaths (com.ms.silverking.cloud.dht.meta.MetaPaths)1 NamespaceLinksZK (com.ms.silverking.cloud.dht.meta.NamespaceLinksZK)1