Search in sources :

Example 1 with ServiceURI

use of org.apache.bookkeeper.common.net.ServiceURI in project bookkeeper by apache.

the class BKCommand method apply.

protected boolean apply(BKFlags bkFlags, CommandFlagsT cmdFlags) {
    ServiceURI serviceURI = null;
    if (null != bkFlags.serviceUri) {
        serviceURI = ServiceURI.create(bkFlags.serviceUri);
        if (!acceptServiceUri(serviceURI)) {
            log.error("Unresolvable service uri by command '{}' : {}", path(), bkFlags.serviceUri);
            return false;
        }
    }
    CompositeConfiguration conf = new CompositeConfiguration();
    if (!Strings.isNullOrEmpty(bkFlags.configFile)) {
        try {
            URL configFileUrl = Paths.get(bkFlags.configFile).toUri().toURL();
            PropertiesConfiguration loadedConf = new PropertiesConfiguration(configFileUrl);
            conf.addConfiguration(loadedConf);
        } catch (MalformedURLException e) {
            log.error("Could not open configuration file : {}", bkFlags.configFile, e);
            throw new IllegalArgumentException(e);
        } catch (ConfigurationException e) {
            log.error("Malformed configuration file : {}", bkFlags.configFile, e);
            throw new IllegalArgumentException(e);
        }
    }
    return apply(serviceURI, conf, bkFlags, cmdFlags);
}
Also used : MalformedURLException(java.net.MalformedURLException) ServiceURI(org.apache.bookkeeper.common.net.ServiceURI) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) URL(java.net.URL)

Example 2 with ServiceURI

use of org.apache.bookkeeper.common.net.ServiceURI in project bookkeeper by apache.

the class BKRegistrationNameResolverProvider method newNameResolver.

@Nullable
@Override
public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
    ServiceURI serviceURI;
    try {
        serviceURI = ServiceURI.create(targetUri);
    } catch (NullPointerException | IllegalArgumentException e) {
        // invalid uri here, so return null to allow grpc to use other name resolvers
        log.info("BKRegistrationNameResolverProvider doesn't know how to resolve {} : cause {}", targetUri, e.getMessage());
        return null;
    }
    MetadataClientDriver clientDriver;
    try {
        clientDriver = MetadataDrivers.getClientDriver(serviceURI.getUri());
        return new BKRegistrationNameResolver(clientDriver, serviceURI.getUri());
    } catch (IllegalArgumentException iae) {
        log.error("Unknown service uri : {}", serviceURI, iae);
        return null;
    }
}
Also used : ServiceURI(org.apache.bookkeeper.common.net.ServiceURI) MetadataClientDriver(org.apache.bookkeeper.meta.MetadataClientDriver) Nullable(javax.annotation.Nullable)

Example 3 with ServiceURI

use of org.apache.bookkeeper.common.net.ServiceURI in project bookkeeper by apache.

the class DLUtils method normalizeURI.

/**
 * Normalize the uri.
 *
 * @param uri the distributedlog uri.
 * @return the normalized uri
 */
public static URI normalizeURI(URI uri) {
    ServiceURI serviceURI = ServiceURI.create(uri);
    checkNotNull(serviceURI.getServiceName(), "Invalid distributedlog uri : " + uri);
    checkArgument(Objects.equal(DistributedLogConstants.SCHEME_PREFIX, serviceURI.getServiceName()), "Unknown distributedlog scheme found : " + uri);
    URI normalizedUri;
    try {
        normalizedUri = new URI(// remove backend info
        serviceURI.getServiceName(), uri.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Invalid distributedlog uri found : " + uri, e);
    }
    return normalizedUri;
}
Also used : ServiceURI(org.apache.bookkeeper.common.net.ServiceURI) URISyntaxException(java.net.URISyntaxException) ServiceURI(org.apache.bookkeeper.common.net.ServiceURI) URI(java.net.URI)

Example 4 with ServiceURI

use of org.apache.bookkeeper.common.net.ServiceURI in project bookkeeper by apache.

the class GrpcChannels method createChannelBuilder.

/**
 * Create a channel builder from <tt>serviceUri</tt> with client <tt>settings</tt>.
 *
 * @param serviceUri service uri
 * @param settings client settings
 * @return managed channel builder
 */
@SuppressWarnings("deprecation")
public static // finalizes their API.
ManagedChannelBuilder createChannelBuilder(String serviceUri, StorageClientSettings settings) {
    ServiceURI uri = ServiceURI.create(serviceUri);
    ManagedChannelBuilder builder;
    if (uri.getServiceInfos().length > 0 && uri.getServiceInfos()[0].equals(BACKEND_INPROCESS)) {
        // this is an inprocess service, so build an inprocess channel.
        String serviceName = uri.getServiceHosts()[0];
        builder = InProcessChannelBuilder.forName(serviceName).directExecutor();
    } else if (null == uri.getServiceName() || ServiceURI.SERVICE_BK.equals(uri.getServiceName())) {
        builder = ManagedChannelBuilder.forTarget(serviceUri).nameResolverFactory(new ServiceNameResolverProvider().toFactory());
    } else {
        NameResolverFactoryProvider provider;
        try {
            provider = ReflectionUtils.newInstance(BK_REG_NAME_RESOLVER_PROVIDER, NameResolverFactoryProvider.class);
        } catch (RuntimeException re) {
            log.error("It seems that you don't have `bk-grpc-name-resolver` in your class path." + " Please make sure you include it as your application's dependency.");
            throw re;
        }
        builder = ManagedChannelBuilder.forTarget(serviceUri).nameResolverFactory(provider.toFactory());
    }
    if (settings.usePlaintext()) {
        builder = builder.usePlaintext();
    }
    return builder;
}
Also used : ServiceURI(org.apache.bookkeeper.common.net.ServiceURI) ServiceNameResolverProvider(org.apache.bookkeeper.common.resolver.ServiceNameResolverProvider) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) NameResolverFactoryProvider(org.apache.bookkeeper.common.resolver.NameResolverFactoryProvider)

Example 5 with ServiceURI

use of org.apache.bookkeeper.common.net.ServiceURI 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

ServiceURI (org.apache.bookkeeper.common.net.ServiceURI)12 IOException (java.io.IOException)5 JCommander (com.beust.jcommander.JCommander)4 ExecutionException (java.util.concurrent.ExecutionException)3 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)3 ClusterInitializer (org.apache.bookkeeper.stream.storage.api.cluster.ClusterInitializer)3 ZkClusterInitializer (org.apache.bookkeeper.stream.storage.impl.cluster.ZkClusterInitializer)3 ConfigurationException (org.apache.commons.configuration.ConfigurationException)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 PulsarMetadataClientDriver (org.apache.pulsar.metadata.bookkeeper.PulsarMetadataClientDriver)3 ZKMetadataStore (org.apache.pulsar.metadata.impl.ZKMetadataStore)3 URI (java.net.URI)2 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)2 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)2 Lists (com.google.common.collect.Lists)1