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