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