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.");
}
}
}
}
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.");
}
}
}
}
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);
}
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);
}
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.");
}
}
}
}
Aggregations