Example usage for org.apache.zookeeper.server ServerCnxnFactory getLocalPort

List of usage examples for org.apache.zookeeper.server ServerCnxnFactory getLocalPort

Introduction

In this page you can find the example usage for org.apache.zookeeper.server ServerCnxnFactory getLocalPort.

Prototype

public abstract int getLocalPort();

Source Link

Usage

From source file:com.msd.gin.halyard.common.HBaseServerTestInstance.java

License:Apache License

public static synchronized Configuration getInstanceConfig() throws Exception {
    if (conf == null) {
        File zooRoot = File.createTempFile("hbase-zookeeper", "");
        zooRoot.delete();/* ww w. jav  a2  s .  com*/
        ZooKeeperServer zookeper = new ZooKeeperServer(zooRoot, zooRoot, 2000);
        ServerCnxnFactory factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", 0),
                5000);
        factory.startup(zookeper);

        YarnConfiguration yconf = new YarnConfiguration();
        String argLine = System.getProperty("argLine");
        if (argLine != null) {
            yconf.set("yarn.app.mapreduce.am.command-opts", argLine.replace("jacoco.exec", "jacocoMR.exec"));
        }
        yconf.setBoolean(MRConfig.MAPREDUCE_MINICLUSTER_CONTROL_RESOURCE_MONITORING, false);
        yconf.setClass(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class, ResourceScheduler.class);
        MiniMRYarnCluster miniCluster = new MiniMRYarnCluster("testCluster");
        miniCluster.init(yconf);
        yconf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, true);
        miniCluster.start();

        File hbaseRoot = File.createTempFile("hbase-root", "");
        hbaseRoot.delete();
        conf = HBaseConfiguration.create(miniCluster.getConfig());
        conf.set(HConstants.HBASE_DIR, hbaseRoot.toURI().toURL().toString());
        conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, factory.getLocalPort());
        conf.set("hbase.master.hostname", "localhost");
        conf.set("hbase.regionserver.hostname", "localhost");
        conf.setInt("hbase.master.info.port", -1);
        conf.set("hbase.fs.tmp.dir", new File(System.getProperty("java.io.tmpdir")).toURI().toURL().toString());
        LocalHBaseCluster cluster = new LocalHBaseCluster(conf);
        cluster.startup();
    }
    return conf;
}

From source file:zookeeperjunit.ZKInstanceImpl.java

License:Apache License

@Override
public Future<Unit> start() {
    return Future(() -> {
        ZooKeeperServer zkServer = new ZooKeeperServer();
        FileTxnSnapLog log = new FileTxnSnapLog(new File(rootZooDir, "dataDir"),
                new File(rootZooDir, "snapDir"));
        zkServer.setTxnLogFactory(log);/*from   w  w w. j  a  v a2  s. c om*/
        zkServer.setTickTime(2000);
        zkServer.setMinSessionTimeout(10000);
        zkServer.setMaxSessionTimeout(10000);
        ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
        cnxnFactory.configure(new InetSocketAddress(cfgPort), maxClientConnections);
        cnxnFactory.startup(zkServer);
        fileTxnSnapLog = Some(log);
        serverCnxnFactory = Some(cnxnFactory);
        //remember the port. if 0 was provided then ZK will pick a free port
        //it must be remembered for the scenario of restarting this instance
        //in such case we want to get the same port again
        cfgPort = cnxnFactory.getLocalPort();
    });
}