Search in sources :

Example 6 with ConnectionConfig

use of co.cask.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();
}
Also used : AccessToken(co.cask.cdap.security.authentication.client.AccessToken) ClientConfig(co.cask.cdap.client.config.ClientConfig) URI(java.net.URI) File(java.io.File) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig)

Example 7 with ConnectionConfig

use of co.cask.cdap.client.config.ConnectionConfig in project cdap by caskdata.

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(co.cask.cdap.explore.jdbc.ExploreDriver) HashMap(java.util.HashMap) AccessToken(co.cask.cdap.security.authentication.client.AccessToken) DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) Properties(java.util.Properties) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig)

Example 8 with ConnectionConfig

use of co.cask.cdap.client.config.ConnectionConfig in project cdap by caskdata.

the class IntegrationTestBase method fetchAccessToken.

protected AccessToken fetchAccessToken(String username, String password) throws IOException, TimeoutException, InterruptedException {
    Properties properties = new Properties();
    properties.setProperty("security.auth.client.username", username);
    properties.setProperty("security.auth.client.password", password);
    final AuthenticationClient authClient = new BasicAuthenticationClient();
    authClient.configure(properties);
    ConnectionConfig connectionConfig = getClientConfig().getConnectionConfig();
    authClient.setConnectionInfo(connectionConfig.getHostname(), connectionConfig.getPort(), false);
    checkServicesWithRetry(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return authClient.getAccessToken() != null;
        }
    }, "Unable to connect to Authentication service to obtain access token, Connection info : " + connectionConfig);
    return authClient.getAccessToken();
}
Also used : BasicAuthenticationClient(co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient) Properties(java.util.Properties) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient) BasicAuthenticationClient(co.cask.cdap.security.authentication.client.basic.BasicAuthenticationClient) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig) TimeoutException(java.util.concurrent.TimeoutException) UnauthorizedException(co.cask.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) UnauthenticatedException(co.cask.cdap.common.UnauthenticatedException)

Example 9 with ConnectionConfig

use of co.cask.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("http://%s:%d%s", 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(co.cask.cdap.client.config.ConnectionConfig) URL(java.net.URL)

Example 10 with ConnectionConfig

use of co.cask.cdap.client.config.ConnectionConfig in project cdap by caskdata.

the class CLITestBase method createCLIConfig.

protected static CLIConfig createCLIConfig(URI standaloneUri) throws Exception {
    ConnectionConfig connectionConfig = InstanceURIParser.DEFAULT.parse(standaloneUri.toString());
    ClientConfig clientConfig = new ClientConfig.Builder().setConnectionConfig(connectionConfig).build();
    clientConfig.setAllTimeouts(60000);
    return new CLIConfig(clientConfig, System.out, new CsvTableRenderer());
}
Also used : CsvTableRenderer(co.cask.cdap.cli.util.table.CsvTableRenderer) ClientConfig(co.cask.cdap.client.config.ClientConfig) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig)

Aggregations

ConnectionConfig (co.cask.cdap.client.config.ConnectionConfig)10 ClientConfig (co.cask.cdap.client.config.ClientConfig)3 EndpointStrategy (co.cask.cdap.common.discovery.EndpointStrategy)2 RandomEndpointStrategy (co.cask.cdap.common.discovery.RandomEndpointStrategy)2 AccessToken (co.cask.cdap.security.authentication.client.AccessToken)2 URI (java.net.URI)2 Properties (java.util.Properties)2 Discoverable (org.apache.twill.discovery.Discoverable)2 Before (org.junit.Before)2 StandaloneTester (co.cask.cdap.StandaloneTester)1 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)1 CLIConnectionConfig (co.cask.cdap.cli.CLIConnectionConfig)1 CsvTableRenderer (co.cask.cdap.cli.util.table.CsvTableRenderer)1 MetadataClient (co.cask.cdap.client.MetadataClient)1 UnauthenticatedException (co.cask.cdap.common.UnauthenticatedException)1 FixedAddressExploreClient (co.cask.cdap.explore.client.FixedAddressExploreClient)1 ExploreDriver (co.cask.cdap.explore.jdbc.ExploreDriver)1 ArtifactRepository (co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository)1 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1