Search in sources :

Example 1 with AbstractConfiguration

use of org.apache.bookkeeper.conf.AbstractConfiguration in project bookkeeper by apache.

the class EtcdMetadataDriverBase method initialize.

/**
 * Initialize metadata driver with provided configuration and <tt>statsLogger</tt>.
 *
 * @param conf configuration to initialize metadata driver
 * @param statsLogger stats logger
 * @throws MetadataException
 */
protected void initialize(AbstractConfiguration<?> conf, StatsLogger statsLogger) throws MetadataException {
    this.conf = conf;
    this.statsLogger = statsLogger;
    final String metadataServiceUriStr;
    try {
        metadataServiceUriStr = conf.getMetadataServiceUri();
    } catch (ConfigurationException ce) {
        log.error("Failed to retrieve metadata service uri from configuration", ce);
        throw new MetadataException(Code.INVALID_METADATA_SERVICE_URI, ce);
    }
    ServiceURI serviceURI = ServiceURI.create(metadataServiceUriStr);
    this.keyPrefix = serviceURI.getServicePath();
    List<String> etcdEndpoints = Lists.newArrayList(serviceURI.getServiceHosts()).stream().map(host -> String.format("http://%s", host)).collect(Collectors.toList());
    log.info("Initializing etcd metadata driver : etcd endpoints = {}, key scope = {}", etcdEndpoints, keyPrefix);
    synchronized (this) {
        this.client = Client.builder().endpoints(etcdEndpoints.toArray(new String[etcdEndpoints.size()])).build();
    }
    this.layoutManager = new EtcdLayoutManager(client, keyPrefix);
}
Also used : MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException) AbstractConfiguration(org.apache.bookkeeper.conf.AbstractConfiguration) Client(io.etcd.jetcd.Client) LayoutManager(org.apache.bookkeeper.meta.LayoutManager) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Code(org.apache.bookkeeper.meta.exceptions.Code) ServiceURI(org.apache.bookkeeper.common.net.ServiceURI) LedgerManagerFactory(org.apache.bookkeeper.meta.LedgerManagerFactory) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Lists(com.google.common.collect.Lists) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ServiceURI(org.apache.bookkeeper.common.net.ServiceURI) ConfigurationException(org.apache.commons.configuration.ConfigurationException) MetadataException(org.apache.bookkeeper.meta.exceptions.MetadataException)

Aggregations

Lists (com.google.common.collect.Lists)1 Client (io.etcd.jetcd.Client)1 IOException (java.io.IOException)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 ServiceURI (org.apache.bookkeeper.common.net.ServiceURI)1 AbstractConfiguration (org.apache.bookkeeper.conf.AbstractConfiguration)1 LayoutManager (org.apache.bookkeeper.meta.LayoutManager)1 LedgerManagerFactory (org.apache.bookkeeper.meta.LedgerManagerFactory)1 Code (org.apache.bookkeeper.meta.exceptions.Code)1 MetadataException (org.apache.bookkeeper.meta.exceptions.MetadataException)1 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1