Search in sources :

Example 1 with ClusterInitializer

use of org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer in project pulsar by apache.

the class LocalBookkeeperEnsemble method runStreamStorage.

public void runStreamStorage(CompositeConfiguration conf) throws Exception {
    String zkServers = "127.0.0.1:" + zkPort;
    String metadataServiceUriStr = "zk://" + zkServers + "/ledgers";
    URI metadataServiceUri = URI.create(metadataServiceUriStr);
    // zookeeper servers
    conf.setProperty("metadataServiceUri", metadataServiceUriStr);
    // dlog settings
    conf.setProperty("dlog.bkcEnsembleSize", 1);
    conf.setProperty("dlog.bkcWriteQuorumSize", 1);
    conf.setProperty("dlog.bkcAckQuorumSize", 1);
    // stream storage port
    conf.setProperty("storageserver.grpc.port", streamStoragePort);
    // storage server settings
    conf.setProperty("storage.range.store.dirs", bkDataDirName + "/ranges/data");
    // initialize the stream storage metadata
    ClusterInitializer initializer = new ZkClusterInitializer(zkServers);
    initializer.initializeCluster(metadataServiceUri, 2);
    // load the stream storage component
    ServerConfiguration serverConf = new ServerConfiguration();
    serverConf.loadConf(conf);
    BookieConfiguration bkConf = new BookieConfiguration(serverConf);
    this.streamStorage = new StreamStorageLifecycleComponent(bkConf, NullStatsLogger.INSTANCE);
    this.streamStorage.start();
    LOG.debug("Local BK stream storage started (port: {})", streamStoragePort);
    // create a default namespace
    try (StorageAdminClient admin = StorageClientBuilder.newBuilder().withSettings(StorageClientSettings.newBuilder().serviceUri("bk://localhost:4181").backoffPolicy(Backoff.Jitter.of(Type.EXPONENTIAL, 1000, 10000, 30)).build()).buildAdmin()) {
        try {
            NamespaceProperties ns = FutureUtils.result(admin.getNamespace("default"));
            LOG.info("'default' namespace for table service : {}", ns);
        } catch (NamespaceNotFoundException nnfe) {
            LOG.info("Creating default namespace");
            try {
                NamespaceProperties ns = FutureUtils.result(admin.createNamespace("default", NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build()));
                LOG.info("Successfully created 'default' namespace :\n{}", ns);
            } catch (NamespaceExistsException nee) {
                // namespace already exists
                LOG.warn("Namespace 'default' already existed.");
            }
        }
    }
}
Also used : StreamStorageLifecycleComponent(org.apache.bookkeeper.stream.server.StreamStorageLifecycleComponent) NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) StorageAdminClient(org.apache.bookkeeper.clients.admin.StorageAdminClient) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) URI(java.net.URI) NamespaceExistsException(org.apache.bookkeeper.clients.exceptions.NamespaceExistsException) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) ClusterInitializer(org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer) BookieConfiguration(org.apache.bookkeeper.server.conf.BookieConfiguration) NamespaceNotFoundException(org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException)

Example 2 with ClusterInitializer

use of org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer in project incubator-pulsar by apache.

the class LocalBookkeeperEnsemble method runStreamStorage.

public void runStreamStorage(CompositeConfiguration conf) throws Exception {
    String zkServers = "127.0.0.1:" + zkPort;
    String metadataServiceUriStr = "zk://" + zkServers + "/ledgers";
    URI metadataServiceUri = URI.create(metadataServiceUriStr);
    // zookeeper servers
    conf.setProperty("metadataServiceUri", metadataServiceUriStr);
    // dlog settings
    conf.setProperty("dlog.bkcEnsembleSize", 1);
    conf.setProperty("dlog.bkcWriteQuorumSize", 1);
    conf.setProperty("dlog.bkcAckQuorumSize", 1);
    // stream storage port
    conf.setProperty("storageserver.grpc.port", streamStoragePort);
    // storage server settings
    conf.setProperty("storage.range.store.dirs", bkDataDirName + "/ranges/data");
    // initialize the stream storage metadata
    ClusterInitializer initializer = new ZkClusterInitializer(zkServers);
    initializer.initializeCluster(metadataServiceUri, 2);
    // load the stream storage component
    ServerConfiguration serverConf = new ServerConfiguration();
    serverConf.loadConf(conf);
    BookieConfiguration bkConf = new BookieConfiguration(serverConf);
    this.streamStorage = new StreamStorageLifecycleComponent(bkConf, NullStatsLogger.INSTANCE);
    this.streamStorage.start();
    LOG.debug("Local BK stream storage started (port: {})", streamStoragePort);
    // create a default namespace
    try (StorageAdminClient admin = StorageClientBuilder.newBuilder().withSettings(StorageClientSettings.newBuilder().serviceUri("bk://localhost:4181").backoffPolicy(Backoff.Jitter.of(Type.EXPONENTIAL, 1000, 10000, 30)).build()).buildAdmin()) {
        try {
            NamespaceProperties ns = FutureUtils.result(admin.getNamespace("default"));
            LOG.info("'default' namespace for table service : {}", ns);
        } catch (NamespaceNotFoundException nnfe) {
            LOG.info("Creating default namespace");
            try {
                NamespaceProperties ns = FutureUtils.result(admin.createNamespace("default", NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build()));
                LOG.info("Successfully created 'default' namespace :\n{}", ns);
            } catch (NamespaceExistsException nee) {
                // namespace already exists
                LOG.warn("Namespace 'default' already existed.");
            }
        }
    }
}
Also used : StreamStorageLifecycleComponent(org.apache.bookkeeper.stream.server.StreamStorageLifecycleComponent) NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) StorageAdminClient(org.apache.bookkeeper.clients.admin.StorageAdminClient) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) URI(java.net.URI) NamespaceExistsException(org.apache.bookkeeper.clients.exceptions.NamespaceExistsException) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) ClusterInitializer(org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer) BookieConfiguration(org.apache.bookkeeper.server.conf.BookieConfiguration) NamespaceNotFoundException(org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException)

Example 3 with ClusterInitializer

use of org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer in project incubator-pulsar by apache.

the class PulsarClusterMetadataSetup method main.

public static void main(String[] args) throws Exception {
    System.setProperty("bookkeeper.metadata.bookie.drivers", PulsarMetadataBookieDriver.class.getName());
    System.setProperty("bookkeeper.metadata.client.drivers", PulsarMetadataClientDriver.class.getName());
    Arguments arguments = new Arguments();
    JCommander jcommander = new JCommander();
    try {
        jcommander.addObject(arguments);
        jcommander.parse(args);
        if (arguments.help) {
            jcommander.usage();
            return;
        }
        if (arguments.generateDocs) {
            CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
            cmd.addCommand("initialize-cluster-metadata", arguments);
            cmd.run(null);
            return;
        }
    } catch (Exception e) {
        jcommander.usage();
        throw e;
    }
    if (arguments.metadataStoreUrl == null && arguments.zookeeper == null) {
        System.err.println("Metadata store address argument is required (--metadata-store)");
        jcommander.usage();
        System.exit(1);
    }
    if (arguments.configurationMetadataStore == null && arguments.configurationStore == null && arguments.globalZookeeper == null) {
        System.err.println("Configuration metadata store address argument is required (--configuration-metadata-store)");
        jcommander.usage();
        System.exit(1);
    }
    if (arguments.configurationMetadataStore != null && (arguments.configurationStore != null || arguments.globalZookeeper != null)) {
        System.err.println("Configuration metadata store argument (--configuration-metadata-store) " + "supersedes the deprecated (--global-zookeeper and --configuration-store) argument");
        jcommander.usage();
        System.exit(1);
    }
    if (arguments.configurationMetadataStore == null) {
        arguments.configurationMetadataStore = arguments.configurationStore == null ? arguments.globalZookeeper : arguments.configurationStore;
    }
    if (arguments.metadataStoreUrl == null) {
        arguments.metadataStoreUrl = ZKMetadataStore.ZK_SCHEME_IDENTIFIER + arguments.zookeeper;
    }
    if (arguments.numTransactionCoordinators <= 0) {
        System.err.println("Number of transaction coordinators must greater than 0");
        System.exit(1);
    }
    log.info("Setting up cluster {} with metadata-store={} configuration-metadata-store={}", arguments.cluster, arguments.metadataStoreUrl, arguments.configurationMetadataStore);
    MetadataStoreExtended localStore = initMetadataStore(arguments.metadataStoreUrl, arguments.zkSessionTimeoutMillis);
    MetadataStoreExtended configStore = initMetadataStore(arguments.configurationMetadataStore, arguments.zkSessionTimeoutMillis);
    final String metadataStoreUrlNoIdentifer = MetadataStoreFactoryImpl.removeIdentifierFromMetadataURL(arguments.metadataStoreUrl);
    // Format BookKeeper ledger storage metadata
    if (arguments.existingBkMetadataServiceUri == null && arguments.bookieMetadataServiceUri == null) {
        ServerConfiguration bkConf = new ServerConfiguration();
        bkConf.setDelimiterParsingDisabled(true);
        bkConf.setMetadataServiceUri("metadata-store:" + arguments.metadataStoreUrl);
        bkConf.setZkTimeout(arguments.zkSessionTimeoutMillis);
        // only format if /ledgers doesn't exist
        if (!localStore.exists(BookKeeperConstants.DEFAULT_ZK_LEDGERS_ROOT_PATH).get() && !BookKeeperAdmin.format(bkConf, false, /* interactive */
        false)) {
            throw new IOException("Failed to initialize BookKeeper metadata");
        }
    }
    if (localStore instanceof ZKMetadataStore && configStore instanceof ZKMetadataStore) {
        String uriStr;
        if (arguments.existingBkMetadataServiceUri != null) {
            uriStr = arguments.existingBkMetadataServiceUri;
        } else if (arguments.bookieMetadataServiceUri != null) {
            uriStr = arguments.bookieMetadataServiceUri;
        } else {
            uriStr = "zk+null://" + metadataStoreUrlNoIdentifer + BookKeeperConstants.DEFAULT_ZK_LEDGERS_ROOT_PATH;
        }
        // initial distributed log metadata
        initialDlogNamespaceMetadata(arguments.configurationMetadataStore, uriStr);
        ServiceURI bkMetadataServiceUri = ServiceURI.create(uriStr);
        // Format BookKeeper stream storage metadata
        if (arguments.numStreamStorageContainers > 0) {
            ClusterInitializer initializer = new ZkClusterInitializer(metadataStoreUrlNoIdentifer);
            initializer.initializeCluster(bkMetadataServiceUri.getUri(), arguments.numStreamStorageContainers);
        }
    }
    if (!localStore.exists(BookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH).get()) {
        createMetadataNode(localStore, BookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, "{}".getBytes());
    }
    PulsarResources resources = new PulsarResources(localStore, configStore);
    ClusterData clusterData = ClusterData.builder().serviceUrl(arguments.clusterWebServiceUrl).serviceUrlTls(arguments.clusterWebServiceUrlTls).brokerServiceUrl(arguments.clusterBrokerServiceUrl).brokerServiceUrlTls(arguments.clusterBrokerServiceUrlTls).build();
    if (!resources.getClusterResources().clusterExists(arguments.cluster)) {
        resources.getClusterResources().createCluster(arguments.cluster, clusterData);
    }
    // Create marker for "global" cluster
    ClusterData globalClusterData = ClusterData.builder().build();
    if (!resources.getClusterResources().clusterExists("global")) {
        resources.getClusterResources().createCluster("global", globalClusterData);
    }
    // Create public tenant, whitelisted to use the this same cluster, along with other clusters
    createTenantIfAbsent(resources, TopicName.PUBLIC_TENANT, arguments.cluster);
    // Create system tenant
    createTenantIfAbsent(resources, NamespaceName.SYSTEM_NAMESPACE.getTenant(), arguments.cluster);
    // Create default namespace
    createNamespaceIfAbsent(resources, NamespaceName.get(TopicName.PUBLIC_TENANT, TopicName.DEFAULT_NAMESPACE), arguments.cluster);
    // Create system namespace
    createNamespaceIfAbsent(resources, NamespaceName.SYSTEM_NAMESPACE, arguments.cluster);
    // Create transaction coordinator assign partitioned topic
    createPartitionedTopic(configStore, SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN, arguments.numTransactionCoordinators);
    localStore.close();
    configStore.close();
    log.info("Cluster metadata for '{}' setup correctly", arguments.cluster);
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) PulsarMetadataBookieDriver(org.apache.pulsar.metadata.bookkeeper.PulsarMetadataBookieDriver) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) IOException(java.io.IOException) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) ServiceURI(org.apache.bookkeeper.common.net.ServiceURI) PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) JCommander(com.beust.jcommander.JCommander) CmdGenerateDocs(org.apache.pulsar.common.util.CmdGenerateDocs) PulsarMetadataClientDriver(org.apache.pulsar.metadata.bookkeeper.PulsarMetadataClientDriver) MetadataStoreExtended(org.apache.pulsar.metadata.api.extended.MetadataStoreExtended) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) ClusterInitializer(org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer)

Example 4 with ClusterInitializer

use of org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer in project pulsar by yahoo.

the class PulsarClusterMetadataSetup method main.

public static void main(String[] args) throws Exception {
    System.setProperty("bookkeeper.metadata.bookie.drivers", PulsarMetadataBookieDriver.class.getName());
    System.setProperty("bookkeeper.metadata.client.drivers", PulsarMetadataClientDriver.class.getName());
    Arguments arguments = new Arguments();
    JCommander jcommander = new JCommander();
    try {
        jcommander.addObject(arguments);
        jcommander.parse(args);
        if (arguments.help) {
            jcommander.usage();
            return;
        }
        if (arguments.generateDocs) {
            CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
            cmd.addCommand("initialize-cluster-metadata", arguments);
            cmd.run(null);
            return;
        }
    } catch (Exception e) {
        jcommander.usage();
        throw e;
    }
    if (arguments.metadataStoreUrl == null && arguments.zookeeper == null) {
        System.err.println("Metadata store address argument is required (--metadata-store)");
        jcommander.usage();
        System.exit(1);
    }
    if (arguments.configurationMetadataStore == null && arguments.configurationStore == null && arguments.globalZookeeper == null) {
        System.err.println("Configuration metadata store address argument is required (--configuration-metadata-store)");
        jcommander.usage();
        System.exit(1);
    }
    if (arguments.configurationMetadataStore != null && (arguments.configurationStore != null || arguments.globalZookeeper != null)) {
        System.err.println("Configuration metadata store argument (--configuration-metadata-store) " + "supersedes the deprecated (--global-zookeeper and --configuration-store) argument");
        jcommander.usage();
        System.exit(1);
    }
    if (arguments.configurationMetadataStore == null) {
        arguments.configurationMetadataStore = arguments.configurationStore == null ? arguments.globalZookeeper : arguments.configurationStore;
    }
    if (arguments.metadataStoreUrl == null) {
        arguments.metadataStoreUrl = ZKMetadataStore.ZK_SCHEME_IDENTIFIER + arguments.zookeeper;
    }
    if (arguments.numTransactionCoordinators <= 0) {
        System.err.println("Number of transaction coordinators must greater than 0");
        System.exit(1);
    }
    log.info("Setting up cluster {} with metadata-store={} configuration-metadata-store={}", arguments.cluster, arguments.metadataStoreUrl, arguments.configurationMetadataStore);
    MetadataStoreExtended localStore = initMetadataStore(arguments.metadataStoreUrl, arguments.zkSessionTimeoutMillis);
    MetadataStoreExtended configStore = initMetadataStore(arguments.configurationMetadataStore, arguments.zkSessionTimeoutMillis);
    final String metadataStoreUrlNoIdentifer = MetadataStoreFactoryImpl.removeIdentifierFromMetadataURL(arguments.metadataStoreUrl);
    // Format BookKeeper ledger storage metadata
    if (arguments.existingBkMetadataServiceUri == null && arguments.bookieMetadataServiceUri == null) {
        ServerConfiguration bkConf = new ServerConfiguration();
        bkConf.setDelimiterParsingDisabled(true);
        bkConf.setMetadataServiceUri("metadata-store:" + arguments.metadataStoreUrl);
        bkConf.setZkTimeout(arguments.zkSessionTimeoutMillis);
        // only format if /ledgers doesn't exist
        if (!localStore.exists(BookKeeperConstants.DEFAULT_ZK_LEDGERS_ROOT_PATH).get() && !BookKeeperAdmin.format(bkConf, false, /* interactive */
        false)) {
            throw new IOException("Failed to initialize BookKeeper metadata");
        }
    }
    if (localStore instanceof ZKMetadataStore && configStore instanceof ZKMetadataStore) {
        String uriStr;
        if (arguments.existingBkMetadataServiceUri != null) {
            uriStr = arguments.existingBkMetadataServiceUri;
        } else if (arguments.bookieMetadataServiceUri != null) {
            uriStr = arguments.bookieMetadataServiceUri;
        } else {
            uriStr = "zk+null://" + metadataStoreUrlNoIdentifer + BookKeeperConstants.DEFAULT_ZK_LEDGERS_ROOT_PATH;
        }
        // initial distributed log metadata
        initialDlogNamespaceMetadata(arguments.configurationMetadataStore, uriStr);
        ServiceURI bkMetadataServiceUri = ServiceURI.create(uriStr);
        // Format BookKeeper stream storage metadata
        if (arguments.numStreamStorageContainers > 0) {
            ClusterInitializer initializer = new ZkClusterInitializer(metadataStoreUrlNoIdentifer);
            initializer.initializeCluster(bkMetadataServiceUri.getUri(), arguments.numStreamStorageContainers);
        }
    }
    if (!localStore.exists(BookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH).get()) {
        createMetadataNode(localStore, BookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, "{}".getBytes());
    }
    PulsarResources resources = new PulsarResources(localStore, configStore);
    ClusterData clusterData = ClusterData.builder().serviceUrl(arguments.clusterWebServiceUrl).serviceUrlTls(arguments.clusterWebServiceUrlTls).brokerServiceUrl(arguments.clusterBrokerServiceUrl).brokerServiceUrlTls(arguments.clusterBrokerServiceUrlTls).build();
    if (!resources.getClusterResources().clusterExists(arguments.cluster)) {
        resources.getClusterResources().createCluster(arguments.cluster, clusterData);
    }
    // Create marker for "global" cluster
    ClusterData globalClusterData = ClusterData.builder().build();
    if (!resources.getClusterResources().clusterExists("global")) {
        resources.getClusterResources().createCluster("global", globalClusterData);
    }
    // Create public tenant, whitelisted to use the this same cluster, along with other clusters
    createTenantIfAbsent(resources, TopicName.PUBLIC_TENANT, arguments.cluster);
    // Create system tenant
    createTenantIfAbsent(resources, NamespaceName.SYSTEM_NAMESPACE.getTenant(), arguments.cluster);
    // Create default namespace
    createNamespaceIfAbsent(resources, NamespaceName.get(TopicName.PUBLIC_TENANT, TopicName.DEFAULT_NAMESPACE), arguments.cluster);
    // Create system namespace
    createNamespaceIfAbsent(resources, NamespaceName.SYSTEM_NAMESPACE, arguments.cluster);
    // Create transaction coordinator assign partitioned topic
    createPartitionedTopic(configStore, SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN, arguments.numTransactionCoordinators);
    localStore.close();
    configStore.close();
    log.info("Cluster metadata for '{}' setup correctly", arguments.cluster);
}
Also used : ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) PulsarMetadataBookieDriver(org.apache.pulsar.metadata.bookkeeper.PulsarMetadataBookieDriver) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) IOException(java.io.IOException) MetadataStoreException(org.apache.pulsar.metadata.api.MetadataStoreException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ClusterData(org.apache.pulsar.common.policies.data.ClusterData) ServiceURI(org.apache.bookkeeper.common.net.ServiceURI) PulsarResources(org.apache.pulsar.broker.resources.PulsarResources) JCommander(com.beust.jcommander.JCommander) CmdGenerateDocs(org.apache.pulsar.common.util.CmdGenerateDocs) PulsarMetadataClientDriver(org.apache.pulsar.metadata.bookkeeper.PulsarMetadataClientDriver) MetadataStoreExtended(org.apache.pulsar.metadata.api.extended.MetadataStoreExtended) ZKMetadataStore(org.apache.pulsar.metadata.impl.ZKMetadataStore) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) ClusterInitializer(org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer)

Example 5 with ClusterInitializer

use of org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer in project pulsar by yahoo.

the class LocalBookkeeperEnsemble method runStreamStorage.

public void runStreamStorage(CompositeConfiguration conf) throws Exception {
    String zkServers = "127.0.0.1:" + zkPort;
    String metadataServiceUriStr = "zk://" + zkServers + "/ledgers";
    URI metadataServiceUri = URI.create(metadataServiceUriStr);
    // zookeeper servers
    conf.setProperty("metadataServiceUri", metadataServiceUriStr);
    // dlog settings
    conf.setProperty("dlog.bkcEnsembleSize", 1);
    conf.setProperty("dlog.bkcWriteQuorumSize", 1);
    conf.setProperty("dlog.bkcAckQuorumSize", 1);
    // stream storage port
    conf.setProperty("storageserver.grpc.port", streamStoragePort);
    // storage server settings
    conf.setProperty("storage.range.store.dirs", bkDataDirName + "/ranges/data");
    // initialize the stream storage metadata
    ClusterInitializer initializer = new ZkClusterInitializer(zkServers);
    initializer.initializeCluster(metadataServiceUri, 2);
    // load the stream storage component
    ServerConfiguration serverConf = new ServerConfiguration();
    serverConf.loadConf(conf);
    BookieConfiguration bkConf = new BookieConfiguration(serverConf);
    this.streamStorage = new StreamStorageLifecycleComponent(bkConf, NullStatsLogger.INSTANCE);
    this.streamStorage.start();
    LOG.debug("Local BK stream storage started (port: {})", streamStoragePort);
    // create a default namespace
    try (StorageAdminClient admin = StorageClientBuilder.newBuilder().withSettings(StorageClientSettings.newBuilder().serviceUri("bk://localhost:4181").backoffPolicy(Backoff.Jitter.of(Type.EXPONENTIAL, 1000, 10000, 30)).build()).buildAdmin()) {
        try {
            NamespaceProperties ns = FutureUtils.result(admin.getNamespace("default"));
            LOG.info("'default' namespace for table service : {}", ns);
        } catch (NamespaceNotFoundException nnfe) {
            LOG.info("Creating default namespace");
            try {
                NamespaceProperties ns = FutureUtils.result(admin.createNamespace("default", NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build()));
                LOG.info("Successfully created 'default' namespace :\n{}", ns);
            } catch (NamespaceExistsException nee) {
                // namespace already exists
                LOG.warn("Namespace 'default' already existed.");
            }
        }
    }
}
Also used : StreamStorageLifecycleComponent(org.apache.bookkeeper.stream.server.StreamStorageLifecycleComponent) NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) ServerConfiguration(org.apache.bookkeeper.conf.ServerConfiguration) StorageAdminClient(org.apache.bookkeeper.clients.admin.StorageAdminClient) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) URI(java.net.URI) NamespaceExistsException(org.apache.bookkeeper.clients.exceptions.NamespaceExistsException) ZkClusterInitializer(org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer) ClusterInitializer(org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer) BookieConfiguration(org.apache.bookkeeper.server.conf.BookieConfiguration) NamespaceNotFoundException(org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException)

Aggregations

ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)6 ClusterInitializer (org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer)6 ZkClusterInitializer (org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer)6 JCommander (com.beust.jcommander.JCommander)3 IOException (java.io.IOException)3 URI (java.net.URI)3 ExecutionException (java.util.concurrent.ExecutionException)3 StorageAdminClient (org.apache.bookkeeper.clients.admin.StorageAdminClient)3 NamespaceExistsException (org.apache.bookkeeper.clients.exceptions.NamespaceExistsException)3 NamespaceNotFoundException (org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException)3 ServiceURI (org.apache.bookkeeper.common.net.ServiceURI)3 BookieConfiguration (org.apache.bookkeeper.server.conf.BookieConfiguration)3 NamespaceProperties (org.apache.bookkeeper.stream.proto.NamespaceProperties)3 StreamStorageLifecycleComponent (org.apache.bookkeeper.stream.server.StreamStorageLifecycleComponent)3 PulsarResources (org.apache.pulsar.broker.resources.PulsarResources)3 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)3 CmdGenerateDocs (org.apache.pulsar.common.util.CmdGenerateDocs)3 MetadataStoreException (org.apache.pulsar.metadata.api.MetadataStoreException)3 MetadataStoreExtended (org.apache.pulsar.metadata.api.extended.MetadataStoreExtended)3 PulsarMetadataBookieDriver (org.apache.pulsar.metadata.bookkeeper.PulsarMetadataBookieDriver)3