use of co.cask.cdap.common.discovery.StickyEndpointStrategy in project cdap by caskdata.
the class UnitTestManager method getQueryClient.
@Override
public Connection getQueryClient(NamespaceId namespace) throws Exception {
// this makes sure the Explore JDBC driver is loaded
Class.forName(ExploreDriver.class.getName());
Discoverable discoverable = new StickyEndpointStrategy(discoveryClient.discover(Constants.Service.EXPLORE_HTTP_USER_SERVICE)).pick();
if (null == discoverable) {
throw new IOException("Explore service could not be discovered.");
}
InetSocketAddress address = discoverable.getSocketAddress();
String host = address.getHostName();
int port = address.getPort();
String connectString = String.format("%s%s:%d?namespace=%s", Constants.Explore.Jdbc.URL_PREFIX, host, port, namespace.getNamespace());
return DriverManager.getConnection(connectString);
}
Aggregations