use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by caskdata.
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 caskdata.
the class CLIMainLinkTest method createCLIConfigWithURIPrefix.
public static CLIConfig createCLIConfigWithURIPrefix(URI standaloneUri) throws Exception {
ConnectionConfig connectionConfig = InstanceURIParser.DEFAULT.parseInstanceURI(standaloneUri.toString(), null);
ClientConfig clientConfig = new ClientConfig.Builder().setConnectionConfig(connectionConfig).build();
clientConfig.setAllTimeouts(60000);
return new CLIConfig(clientConfig, System.out, new CsvTableRenderer());
}
use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by caskdata.
the class AppFabricTestBase method getClientConfig.
private static ClientConfig getClientConfig(DiscoveryServiceClient discoveryClient, String service) {
EndpointStrategy endpointStrategy = new RandomEndpointStrategy(() -> discoveryClient.discover(service));
Discoverable discoverable = endpointStrategy.pick(1, TimeUnit.SECONDS);
Assert.assertNotNull(discoverable);
ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(discoverable.getSocketAddress().getHostName()).setPort(discoverable.getSocketAddress().getPort()).setSSLEnabled(URIScheme.HTTPS.isMatch(discoverable)).build();
return ClientConfig.builder().setVerifySSLCert(false).setConnectionConfig(connectionConfig).build();
}
use of io.cdap.cdap.client.config.ConnectionConfig in project cdap by caskdata.
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 caskdata.
the class UpgradeTool method getClientConfig.
private static ClientConfig getClientConfig(CommandLine commandLine) throws IOException {
String uriStr = commandLine.hasOption("u") ? commandLine.getOptionValue("u") : "localhost:11015";
if (!uriStr.contains("://")) {
uriStr = "http://" + uriStr;
}
URI uri = URI.create(uriStr);
String hostname = uri.getHost();
int port = uri.getPort();
boolean sslEnabled = "https".equals(uri.getScheme());
ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(hostname).setPort(port).setSSLEnabled(sslEnabled).build();
int readTimeout = commandLine.hasOption("t") ? Integer.parseInt(commandLine.getOptionValue("t")) : DEFAULT_READ_TIMEOUT_MILLIS;
ClientConfig.Builder clientConfigBuilder = ClientConfig.builder().setDefaultReadTimeout(readTimeout).setConnectionConfig(connectionConfig);
if (commandLine.hasOption("a")) {
String tokenFilePath = commandLine.getOptionValue("a");
File tokenFile = new File(tokenFilePath);
if (!tokenFile.exists()) {
throw new IllegalArgumentException("Access token file " + tokenFilePath + " does not exist.");
}
if (!tokenFile.isFile()) {
throw new IllegalArgumentException("Access token file " + tokenFilePath + " is not a file.");
}
String tokenValue = new String(Files.readAllBytes(tokenFile.toPath()), StandardCharsets.UTF_8).trim();
AccessToken accessToken = new AccessToken(tokenValue, 82000L, "Bearer");
clientConfigBuilder.setAccessToken(accessToken);
}
return clientConfigBuilder.build();
}
Aggregations