Search in sources :

Example 1 with ZooKeeperClientFactory

use of com.yahoo.pulsar.zookeeper.ZooKeeperClientFactory in project pulsar by yahoo.

the class DiscoveryServiceServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    log.info("Initializing DiscoveryServiceServlet resource");
    String zookeeperServers = config.getInitParameter("zookeeperServers");
    String zookeeperSessionTimeoutMsStr = config.getInitParameter("zookeeperSessionTimeoutMs");
    int zookeeperSessionTimeoutMs = zookeeperSessionTimeoutMsStr != null ? Integer.valueOf(zookeeperSessionTimeoutMsStr) : 30_000;
    String zookeeperClientFactoryClassName = config.getInitParameter("zookeeperClientFactoryClass");
    if (zookeeperClientFactoryClassName == null) {
        zookeeperClientFactoryClassName = ZookeeperClientFactoryImpl.class.getName();
    }
    log.info("zookeeperServers={} zookeeperClientFactoryClass={}", zookeeperServers, zookeeperClientFactoryClassName);
    try {
        ZooKeeperClientFactory zkClientFactory = (ZooKeeperClientFactory) Class.forName(zookeeperClientFactoryClassName).newInstance();
        zkCache = new ZookeeperCacheLoader(zkClientFactory, zookeeperServers, zookeeperSessionTimeoutMs);
    } catch (Throwable t) {
        throw new ServletException(t);
    }
}
Also used : ServletException(javax.servlet.ServletException) ZookeeperClientFactoryImpl(com.yahoo.pulsar.zookeeper.ZookeeperClientFactoryImpl) ZooKeeperClientFactory(com.yahoo.pulsar.zookeeper.ZooKeeperClientFactory)

Example 2 with ZooKeeperClientFactory

use of com.yahoo.pulsar.zookeeper.ZooKeeperClientFactory in project pulsar by yahoo.

the class PulsarClusterMetadataSetup method main.

public static void main(String[] args) throws Exception {
    Arguments arguments = new Arguments();
    JCommander jcommander = new JCommander();
    try {
        jcommander.addObject(arguments);
        jcommander.parse(args);
        if (arguments.help) {
            jcommander.usage();
            return;
        }
    } catch (Exception e) {
        jcommander.usage();
        return;
    }
    log.info("Setting up cluster {} with zk={} global-zk={}", arguments.cluster, arguments.zookeeper, arguments.globalZookeeper);
    // Format BookKeeper metadata
    ClientConfiguration bkConf = new ClientConfiguration();
    bkConf.setLedgerManagerFactoryClass(HierarchicalLedgerManagerFactory.class);
    bkConf.setZkServers(arguments.zookeeper);
    if (!BookKeeperAdmin.format(bkConf, false, /* interactive */
    false)) {
        throw new IOException("Failed to initialize BookKeeper metadata");
    }
    ZooKeeperClientFactory zkfactory = new ZookeeperClientFactoryImpl();
    ZooKeeper localZk = zkfactory.create(arguments.zookeeper, SessionType.ReadWrite, 30000).get();
    ZooKeeper globalZk = zkfactory.create(arguments.globalZookeeper, SessionType.ReadWrite, 30000).get();
    localZk.create("/managed-ledgers", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    localZk.create("/namespace", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    try {
        ZkUtils.createFullPathOptimistic(globalZk, "/admin/policies", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (NodeExistsException e) {
    // Ignore
    }
    try {
        ZkUtils.createFullPathOptimistic(globalZk, "/admin/clusters", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (NodeExistsException e) {
    // Ignore
    }
    ClusterData clusterData = new ClusterData(arguments.clusterWebServiceUrl, arguments.clusterWebServiceUrlTls, arguments.clusterBrokerServiceUrl, arguments.clusterBrokerServiceUrlTls);
    byte[] clusterDataJson = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(clusterData);
    globalZk.create("/admin/clusters/" + arguments.cluster, clusterDataJson, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    // Create marker for "global" cluster
    ClusterData globalClusterData = new ClusterData(null, null);
    byte[] globalClusterDataJson = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(globalClusterData);
    try {
        globalZk.create("/admin/clusters/global", globalClusterDataJson, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    } catch (NodeExistsException e) {
    // Ignore
    }
    log.info("Cluster metadata for '{}' setup correctly", arguments.cluster);
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) ZookeeperClientFactoryImpl(com.yahoo.pulsar.zookeeper.ZookeeperClientFactoryImpl) JCommander(com.beust.jcommander.JCommander) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) IOException(java.io.IOException) IOException(java.io.IOException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) ZooKeeperClientFactory(com.yahoo.pulsar.zookeeper.ZooKeeperClientFactory)

Aggregations

ZooKeeperClientFactory (com.yahoo.pulsar.zookeeper.ZooKeeperClientFactory)2 ZookeeperClientFactoryImpl (com.yahoo.pulsar.zookeeper.ZookeeperClientFactoryImpl)2 JCommander (com.beust.jcommander.JCommander)1 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)1 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1