Search in sources :

Example 6 with IDefaultNameSpace

use of org.I0Itec.zkclient.IDefaultNameSpace in project databus by linkedin.

the class LeaderElectUtils method startZkServer.

public static ZkServer startZkServer(String zkTestDataRootDir, int machineId, int port, int tickTime) throws IOException {
    File zkTestDataRootDirFile = new File(zkTestDataRootDir);
    zkTestDataRootDirFile.mkdirs();
    String dataPath = zkTestDataRootDir + "/" + machineId + "/" + port + "/data";
    String logPath = zkTestDataRootDir + "/" + machineId + "/" + port + "/log";
    FileUtils.deleteDirectory(new File(dataPath));
    FileUtils.deleteDirectory(new File(logPath));
    IDefaultNameSpace mockDefaultNameSpace = new IDefaultNameSpace() {

        @Override
        public void createDefaultNameSpace(ZkClient zkClient) {
        }
    };
    LOG.info("Starting local zookeeper on port=" + port + "; dataPath=" + dataPath);
    ZkServer zkServer = new ZkServer(dataPath, logPath, mockDefaultNameSpace, port, tickTime);
    zkServer.start();
    return zkServer;
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) IDefaultNameSpace(org.I0Itec.zkclient.IDefaultNameSpace) File(java.io.File) ZkServer(org.I0Itec.zkclient.ZkServer)

Example 7 with IDefaultNameSpace

use of org.I0Itec.zkclient.IDefaultNameSpace in project pinot by linkedin.

the class StartZookeeperCommand method execute.

@Override
public boolean execute() throws IOException {
    LOGGER.info("Executing command: " + toString());
    _tmpdir = createAutoDeleteTempDir();
    File logdir = new File(_tmpdir + File.separator + "translog");
    File datadir = new File(_tmpdir + File.separator + "snapshot");
    IDefaultNameSpace _defaultNameSpace = new IDefaultNameSpace() {

        @Override
        public void createDefaultNameSpace(org.I0Itec.zkclient.ZkClient zkClient) {
        // init any zk paths if needed
        }
    };
    _zookeeperInstance = ZkStarter.startLocalZkServer(_zkPort, datadir.getAbsolutePath());
    LOGGER.info("Start zookeeper at localhost:" + _zkPort + " in thread " + Thread.currentThread().getName());
    savePID(System.getProperty("java.io.tmpdir") + File.separator + ".zooKeeper.pid");
    return true;
}
Also used : IDefaultNameSpace(org.I0Itec.zkclient.IDefaultNameSpace) File(java.io.File)

Example 8 with IDefaultNameSpace

use of org.I0Itec.zkclient.IDefaultNameSpace in project pinot by linkedin.

the class ZookeeperLauncher method start.

public boolean start(int zkPort) {
    IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace() {

        @Override
        public void createDefaultNameSpace(org.I0Itec.zkclient.ZkClient zkClient) {
        // init any zk paths if needed
        }
    };
    LOGGER.info("Starting zookeeper at localhost:{} in thread: {}", zkPort, Thread.currentThread().getName());
    _zkServer = new ZkServer(_dataDir, _logDir, defaultNameSpace, zkPort, 30000, 60000);
    _zkServer.start();
    return true;
}
Also used : IDefaultNameSpace(org.I0Itec.zkclient.IDefaultNameSpace) ZkServer(org.I0Itec.zkclient.ZkServer)

Example 9 with IDefaultNameSpace

use of org.I0Itec.zkclient.IDefaultNameSpace in project helix by apache.

the class LocalZKServer method start.

public void start(int port, String dataDir, String logDir) throws Exception {
    IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace() {

        @Override
        public void createDefaultNameSpace(ZkClient zkClient) {
        }
    };
    ZkServer server = new ZkServer(dataDir, logDir, defaultNameSpace, port);
    server.start();
    Thread.currentThread().join();
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) IDefaultNameSpace(org.I0Itec.zkclient.IDefaultNameSpace) ZkServer(org.I0Itec.zkclient.ZkServer)

Example 10 with IDefaultNameSpace

use of org.I0Itec.zkclient.IDefaultNameSpace in project helix by apache.

the class IntegrationTest method main.

public static void main(String[] args) throws InterruptedException {
    ZkServer server = null;
    ;
    try {
        String baseDir = "/tmp/IntegrationTest/";
        final String dataDir = baseDir + "zk/dataDir";
        final String logDir = baseDir + "/tmp/logDir";
        FileUtils.deleteDirectory(new File(dataDir));
        FileUtils.deleteDirectory(new File(logDir));
        IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace() {

            @Override
            public void createDefaultNameSpace(ZkClient zkClient) {
            }
        };
        int zkPort = 2199;
        final String zkAddress = "localhost:" + zkPort;
        server = new ZkServer(dataDir, logDir, defaultNameSpace, zkPort);
        server.start();
        ClusterSetup setup = new ClusterSetup(zkAddress);
        final String clusterName = "file-store-test";
        setup.deleteCluster(clusterName);
        setup.addCluster(clusterName, true);
        setup.addInstanceToCluster(clusterName, "localhost_12001");
        setup.addInstanceToCluster(clusterName, "localhost_12002");
        setup.addInstanceToCluster(clusterName, "localhost_12003");
        setup.addResourceToCluster(clusterName, "repository", 1, "MasterSlave");
        setup.rebalanceResource(clusterName, "repository", 3);
        // Set the configuration
        final String instanceName1 = "localhost_12001";
        addConfiguration(setup, baseDir, clusterName, instanceName1);
        final String instanceName2 = "localhost_12002";
        addConfiguration(setup, baseDir, clusterName, instanceName2);
        final String instanceName3 = "localhost_12003";
        addConfiguration(setup, baseDir, clusterName, instanceName3);
        Thread thread1 = new Thread(new Runnable() {

            @Override
            public void run() {
                FileStore fileStore = null;
                try {
                    fileStore = new FileStore(zkAddress, clusterName, instanceName1);
                    fileStore.connect();
                } catch (Exception e) {
                    System.err.println("Exception" + e);
                    fileStore.disconnect();
                }
            }
        });
        // START NODES
        Thread thread2 = new Thread(new Runnable() {

            @Override
            public void run() {
                FileStore fileStore = new FileStore(zkAddress, clusterName, instanceName2);
                fileStore.connect();
            }
        });
        // START NODES
        Thread thread3 = new Thread(new Runnable() {

            @Override
            public void run() {
                FileStore fileStore = new FileStore(zkAddress, clusterName, instanceName3);
                fileStore.connect();
            }
        });
        System.out.println("STARTING NODES");
        thread1.start();
        thread2.start();
        thread3.start();
        // Start Controller
        final HelixManager manager = HelixControllerMain.startHelixController(zkAddress, clusterName, "controller", HelixControllerMain.STANDALONE);
        Thread.sleep(5000);
        printStatus(manager);
        listFiles(baseDir);
        System.out.println("Writing files a.txt and b.txt to current master " + baseDir + "localhost_12001" + "/filestore");
        FileUtils.writeStringToFile(new File(baseDir + "localhost_12001" + "/filestore/a.txt"), "some_data in a");
        FileUtils.writeStringToFile(new File(baseDir + "localhost_12001" + "/filestore/b.txt"), "some_data in b");
        Thread.sleep(10000);
        listFiles(baseDir);
        Thread.sleep(5000);
        System.out.println("Stopping the MASTER node:" + "localhost_12001");
        thread1.interrupt();
        Thread.sleep(10000);
        printStatus(manager);
        System.out.println("Writing files c.txt and d.txt to current master " + baseDir + "localhost_12002" + "/filestore");
        FileUtils.writeStringToFile(new File(baseDir + "localhost_12002" + "/filestore/c.txt"), "some_data in c");
        FileUtils.writeStringToFile(new File(baseDir + "localhost_12002" + "/filestore/d.txt"), "some_data in d");
        Thread.sleep(10000);
        listFiles(baseDir);
        System.out.println("Create or modify any files under " + baseDir + "localhost_12002" + "/filestore" + " and it should get replicated to " + baseDir + "localhost_12003" + "/filestore");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (server != null) {
        // server.shutdown();
        }
    }
    Thread.currentThread().join();
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) HelixManager(org.apache.helix.HelixManager) IDefaultNameSpace(org.I0Itec.zkclient.IDefaultNameSpace) ClusterSetup(org.apache.helix.tools.ClusterSetup) IOException(java.io.IOException) File(java.io.File) ZkServer(org.I0Itec.zkclient.ZkServer)

Aggregations

IDefaultNameSpace (org.I0Itec.zkclient.IDefaultNameSpace)12 ZkServer (org.I0Itec.zkclient.ZkServer)11 File (java.io.File)9 ZkClient (org.I0Itec.zkclient.ZkClient)7 IOException (java.io.IOException)3 ClusterSetup (org.apache.helix.tools.ClusterSetup)2 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)1 HelixManager (org.apache.helix.HelixManager)1 ZkClient (org.apache.helix.manager.zk.ZkClient)1