Search in sources :

Example 6 with ZkClient

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

the class GroupLeadershipConnectionFactoryZkClientImpl method getConnection.

/**
   * @see com.linkedin.incubator.mstuart.leaderelect.api.GroupLeadershipConnectionFactory#getConnection()
   */
@Override
public GroupLeadershipConnection getConnection() {
    ZkClient zkClient = new ZkClient(_zkServerList, _sessionTimeoutMillis, _connectTimeoutMillis);
    GroupLeadershipConnection groupLeadershipConnection = new GroupLeadershipConnectionZkClientImpl(zkClient);
    return groupLeadershipConnection;
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) GroupLeadershipConnection(com.linkedin.databus.groupleader.pub.GroupLeadershipConnection)

Example 7 with ZkClient

use of org.I0Itec.zkclient.ZkClient 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 8 with ZkClient

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

the class ZkStarter method startLocalZkServer.

/**
   * Starts a local Zk instance
   * @param port The port to listen on
   * @param dataDirPath The path for the Zk data directory
   */
public static synchronized ZookeeperInstance startLocalZkServer(final int port, final String dataDirPath) {
    // Start the local ZK server
    try {
        final PublicZooKeeperServerMain zookeeperServerMain = new PublicZooKeeperServerMain();
        final String[] args = new String[] { Integer.toString(port), dataDirPath };
        new Thread() {

            @Override
            public void run() {
                try {
                    zookeeperServerMain.initializeAndRun(args);
                } catch (QuorumPeerConfig.ConfigException e) {
                    LOGGER.warn("Caught exception while starting ZK", e);
                } catch (IOException e) {
                    LOGGER.warn("Caught exception while starting ZK", e);
                }
            }
        }.start();
        // Wait until the ZK server is started
        ZkClient client = new ZkClient("localhost:" + port, 10000);
        client.waitUntilConnected(10L, TimeUnit.SECONDS);
        client.close();
        return new ZookeeperInstance(zookeeperServerMain, dataDirPath);
    } catch (Exception e) {
        LOGGER.warn("Caught exception while starting ZK", e);
        throw new RuntimeException(e);
    }
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) IOException(java.io.IOException) IOException(java.io.IOException)

Example 9 with ZkClient

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

the class KafkaStarterUtils method startServer.

public static KafkaServerStartable startServer(final int port, final int brokerId, final String zkStr, final String logDirPath, final Properties configuration) {
    // Create the ZK nodes for Kafka, if needed
    int indexOfFirstSlash = zkStr.indexOf('/');
    if (indexOfFirstSlash != -1) {
        String bareZkUrl = zkStr.substring(0, indexOfFirstSlash);
        String zkNodePath = zkStr.substring(indexOfFirstSlash);
        ZkClient client = new ZkClient(bareZkUrl);
        client.createPersistent(zkNodePath, true);
        client.close();
    }
    File logDir = new File(logDirPath);
    logDir.mkdirs();
    configureKafkaPort(configuration, port);
    configureZkConnectionString(configuration, zkStr);
    configureBrokerId(configuration, brokerId);
    configureKafkaLogDirectory(configuration, logDir);
    configuration.put("zookeeper.session.timeout.ms", "60000");
    KafkaConfig config = new KafkaConfig(configuration);
    KafkaServerStartable serverStartable = new KafkaServerStartable(config);
    serverStartable.startup();
    return serverStartable;
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) KafkaServerStartable(kafka.server.KafkaServerStartable) File(java.io.File) KafkaConfig(kafka.server.KafkaConfig)

Example 10 with ZkClient

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

the class BenchmarkQueryEngine method startPinot.

@Setup
public void startPinot() throws Exception {
    System.out.println("Using table name " + TABLE_NAME);
    System.out.println("Using data directory " + DATA_DIRECTORY);
    System.out.println("Starting pinot");
    PerfBenchmarkDriverConf conf = new PerfBenchmarkDriverConf();
    conf.setStartBroker(true);
    conf.setStartController(true);
    conf.setStartServer(true);
    conf.setStartZookeeper(true);
    conf.setUploadIndexes(false);
    conf.setRunQueries(false);
    conf.setServerInstanceSegmentTarDir(null);
    conf.setServerInstanceDataDir(DATA_DIRECTORY);
    conf.setConfigureResources(false);
    _perfBenchmarkDriver = new PerfBenchmarkDriver(conf);
    _perfBenchmarkDriver.run();
    Set<String> tables = new HashSet<String>();
    File[] segments = new File(DATA_DIRECTORY, TABLE_NAME).listFiles();
    for (File segmentDir : segments) {
        SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(segmentDir);
        if (!tables.contains(segmentMetadata.getTableName())) {
            _perfBenchmarkDriver.configureTable(segmentMetadata.getTableName());
            tables.add(segmentMetadata.getTableName());
        }
        System.out.println("Adding segment " + segmentDir.getAbsolutePath());
        _perfBenchmarkDriver.addSegment(segmentMetadata);
    }
    ZkClient client = new ZkClient("localhost:2191", 10000, 10000, new ZNRecordSerializer());
    ZNRecord record = client.readData("/PinotPerfTestCluster/EXTERNALVIEW/" + TABLE_NAME);
    while (true) {
        System.out.println("record = " + record);
        Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS);
        int onlineSegmentCount = 0;
        for (Map<String, String> instancesAndStates : record.getMapFields().values()) {
            for (String state : instancesAndStates.values()) {
                if (state.equals("ONLINE")) {
                    onlineSegmentCount++;
                    break;
                }
            }
        }
        System.out.println(onlineSegmentCount + " segments online out of " + segments.length);
        if (onlineSegmentCount == segments.length) {
            break;
        }
        record = client.readData("/PinotPerfTestCluster/EXTERNALVIEW/" + TABLE_NAME);
    }
    ranOnce = false;
    System.out.println(_perfBenchmarkDriver.postQuery(QUERY_PATTERNS[queryPattern], optimizationFlags).toString(2));
}
Also used : ZkClient(org.I0Itec.zkclient.ZkClient) PerfBenchmarkDriver(com.linkedin.pinot.tools.perf.PerfBenchmarkDriver) SegmentMetadataImpl(com.linkedin.pinot.core.segment.index.SegmentMetadataImpl) PerfBenchmarkDriverConf(com.linkedin.pinot.tools.perf.PerfBenchmarkDriverConf) File(java.io.File) ZNRecord(org.apache.helix.ZNRecord) HashSet(java.util.HashSet) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

ZkClient (org.I0Itec.zkclient.ZkClient)28 Properties (java.util.Properties)8 ZkUtils (kafka.utils.ZkUtils)7 ZkConnection (org.I0Itec.zkclient.ZkConnection)6 Before (org.junit.Before)6 File (java.io.File)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 KafkaConfig (kafka.server.KafkaConfig)4 DateTime (org.joda.time.DateTime)3 PinotHelixResourceManager (com.linkedin.pinot.controller.helix.core.PinotHelixResourceManager)2 URL (com.weibo.api.motan.rpc.URL)2 ISE (io.druid.java.util.common.ISE)2 TopicExistsException (kafka.common.TopicExistsException)2 MockTime (kafka.utils.MockTime)2 Time (kafka.utils.Time)2 EmbeddedZookeeper (kafka.zk.EmbeddedZookeeper)2 IDefaultNameSpace (org.I0Itec.zkclient.IDefaultNameSpace)2 ZkServer (org.I0Itec.zkclient.ZkServer)2 TestingServer (org.apache.curator.test.TestingServer)2