Search in sources :

Example 11 with ConnectionConfig

use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by cdapio.

the class InstanceURIParser method parseInstanceURI.

public CLIConnectionConfig parseInstanceURI(String uriString, String namespaceString) {
    uriString = addScheme(uriString);
    // Having '/' at the end of the path helps java.net.URI to recognise this as a valid URI path
    if (uriString.length() > 0 && !uriString.endsWith("/")) {
        uriString = String.format("%s/", uriString);
    }
    URI uri = URI.create(uriString);
    NamespaceId namespace = (namespaceString == null || namespaceString.isEmpty()) ? NamespaceId.DEFAULT : new NamespaceId(namespaceString);
    String apiPath = uri.getPath();
    if (apiPath != null && apiPath.startsWith("/")) {
        apiPath = apiPath.substring(1);
    }
    ConnectionConfig config = ConnectionConfig.builder().setHostname(uri.getHost()).setPort(uri.getPort() == -1 ? null : uri.getPort()).setSSLEnabled("https".equals(uri.getScheme())).setApiPath(apiPath).build();
    return new CLIConnectionConfig(config, namespace, null);
}
Also used : CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) URI(java.net.URI) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig)

Example 12 with ConnectionConfig

use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by cdapio.

the class UsageHandlerTestRun method doGet.

private <T> T doGet(String path, Type responseType) throws IOException {
    ConnectionConfig connectionConfig = getClientConfig().getConnectionConfig();
    URL url = new URL(String.format("%s://%s:%d%s", connectionConfig.isSSLEnabled() ? "https" : "http", connectionConfig.getHostname(), connectionConfig.getPort(), path));
    HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
    try {
        Assert.assertEquals(200, urlConn.getResponseCode());
        try (Reader reader = new BufferedReader(new InputStreamReader(urlConn.getInputStream(), Charsets.UTF_8))) {
            return GSON.fromJson(reader, responseType);
        }
    } finally {
        urlConn.disconnect();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) URL(java.net.URL)

Example 13 with ConnectionConfig

use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by cdapio.

the class RemoteSparkManager method getServiceURL.

@Override
public URL getServiceURL(long timeout, TimeUnit timeoutUnit) {
    try {
        Tasks.waitFor(true, () -> {
            try {
                checkAvailability();
                return true;
            } catch (ServiceUnavailableException e) {
                return false;
            }
        }, timeout, timeoutUnit);
        ConnectionConfig connectionConfig = clientConfig.getConnectionConfig();
        URIScheme scheme = connectionConfig.isSSLEnabled() ? URIScheme.HTTPS : URIScheme.HTTP;
        return ServiceDiscoverable.createServiceBaseURL(scheme.createDiscoverable("spark", new InetSocketAddress(connectionConfig.getHostname(), connectionConfig.getPort())), programId);
    } catch (TimeoutException e) {
        return null;
    } catch (Exception e) {
        LOG.warn("Exception raised when waiting for Spark service to be available", e);
        return null;
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) URIScheme(io.cdap.cdap.common.discovery.URIScheme) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) TimeoutException(java.util.concurrent.TimeoutException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) UnauthenticatedException(io.cdap.cdap.security.spi.authentication.UnauthenticatedException) NotFoundException(io.cdap.cdap.common.NotFoundException) TimeoutException(java.util.concurrent.TimeoutException)

Example 14 with ConnectionConfig

use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by cdapio.

the class IntegrationTestManager method getQueryClient.

@Override
public Connection getQueryClient(NamespaceId namespace) throws Exception {
    Map<String, String> connParams = new HashMap<>();
    connParams.put(ExploreConnectionParams.Info.NAMESPACE.getName(), namespace.getNamespace());
    AccessToken accessToken = clientConfig.getAccessToken();
    if (accessToken != null) {
        connParams.put(ExploreConnectionParams.Info.EXPLORE_AUTH_TOKEN.getName(), accessToken.getValue());
    }
    connParams.put(ExploreConnectionParams.Info.SSL_ENABLED.getName(), Boolean.toString(clientConfig.getConnectionConfig().isSSLEnabled()));
    connParams.put(ExploreConnectionParams.Info.VERIFY_SSL_CERT.getName(), Boolean.toString(clientConfig.isVerifySSLCert()));
    ConnectionConfig connConfig = clientConfig.getConnectionConfig();
    String url = String.format("%s%s:%d?%s", Constants.Explore.Jdbc.URL_PREFIX, connConfig.getHostname(), connConfig.getPort(), Joiner.on("&").withKeyValueSeparator("=").join(connParams));
    return new ExploreDriver().connect(url, new Properties());
}
Also used : ExploreDriver(io.cdap.cdap.explore.jdbc.ExploreDriver) HashMap(java.util.HashMap) AccessToken(io.cdap.cdap.security.authentication.client.AccessToken) DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) Properties(java.util.Properties) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig)

Example 15 with ConnectionConfig

use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by caskdata.

the class InstanceURIParser method parse.

public CLIConnectionConfig parse(String uriString) {
    uriString = addScheme(uriString);
    URI uri = URI.create(uriString);
    NamespaceId namespace = (uri.getPath() == null || uri.getPath().isEmpty() || "/".equals(uri.getPath())) ? NamespaceId.DEFAULT : new NamespaceId(uri.getPath().substring(1));
    String hostname = uri.getHost();
    boolean sslEnabled = "https".equals(uri.getScheme());
    int port = uri.getPort();
    if (port == -1) {
        port = sslEnabled ? cConf.getInt(Constants.Router.ROUTER_SSL_PORT) : cConf.getInt(Constants.Router.ROUTER_PORT);
    }
    ConnectionConfig config = ConnectionConfig.builder().setHostname(hostname).setPort(port).setSSLEnabled(sslEnabled).build();
    return new CLIConnectionConfig(config, namespace, null);
}
Also used : CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) URI(java.net.URI) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) CLIConnectionConfig(io.cdap.cdap.cli.CLIConnectionConfig)

Aggregations

ConnectionConfig (io.cdap.cdap.client.config.ConnectionConfig)36 ClientConfig (io.cdap.cdap.client.config.ClientConfig)14 RandomEndpointStrategy (io.cdap.cdap.common.discovery.RandomEndpointStrategy)10 Discoverable (org.apache.twill.discovery.Discoverable)10 IOException (java.io.IOException)8 NotFoundException (io.cdap.cdap.common.NotFoundException)6 EndpointStrategy (io.cdap.cdap.common.discovery.EndpointStrategy)6 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)6 InetSocketAddress (java.net.InetSocketAddress)6 URI (java.net.URI)6 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)6 Injector (com.google.inject.Injector)4 DatasetProperties (io.cdap.cdap.api.dataset.DatasetProperties)4 CLIConnectionConfig (io.cdap.cdap.cli.CLIConnectionConfig)4 CsvTableRenderer (io.cdap.cdap.cli.util.table.CsvTableRenderer)4 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)4 URIScheme (io.cdap.cdap.common.discovery.URIScheme)4 RetryStrategy (io.cdap.cdap.common.service.RetryStrategy)4 AccessToken (io.cdap.cdap.security.authentication.client.AccessToken)4 UnauthenticatedException (io.cdap.cdap.security.spi.authentication.UnauthenticatedException)4