Search in sources :

Example 1 with StickyEndpointStrategy

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);
}
Also used : ExploreDriver(co.cask.cdap.explore.jdbc.ExploreDriver) Discoverable(org.apache.twill.discovery.Discoverable) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) StickyEndpointStrategy(co.cask.cdap.common.discovery.StickyEndpointStrategy)

Aggregations

StickyEndpointStrategy (co.cask.cdap.common.discovery.StickyEndpointStrategy)1 ExploreDriver (co.cask.cdap.explore.jdbc.ExploreDriver)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Discoverable (org.apache.twill.discovery.Discoverable)1