Search in sources :

Example 1 with ConnectionConfig

use of co.cask.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);
    int port = discoverable.getSocketAddress().getPort();
    ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(hostname).setPort(port).build();
    return ClientConfig.builder().setConnectionConfig(connectionConfig).build();
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Example 2 with ConnectionConfig

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

the class ArtifactHttpHandlerTest method setup.

@BeforeClass
public static void setup() throws IOException {
    artifactRepository = getInjector().getInstance(ArtifactRepository.class);
    systemArtifactsDir = getInjector().getInstance(CConfiguration.class).get(Constants.AppFabric.SYSTEM_ARTIFACTS_DIR);
    DiscoveryServiceClient discoveryClient = getInjector().getInstance(DiscoveryServiceClient.class);
    ServiceDiscovered metadataHttpDiscovered = discoveryClient.discover(Constants.Service.METADATA_SERVICE);
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(metadataHttpDiscovered);
    Discoverable discoverable = endpointStrategy.pick(1, TimeUnit.SECONDS);
    Assert.assertNotNull(discoverable);
    String host = "127.0.0.1";
    int port = discoverable.getSocketAddress().getPort();
    ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(host).setPort(port).build();
    clientConfig = ClientConfig.builder().setConnectionConfig(connectionConfig).build();
    metadataClient = new MetadataClient(clientConfig);
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) MetadataClient(co.cask.cdap.client.MetadataClient) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) ArtifactRepository(co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository) ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) BeforeClass(org.junit.BeforeClass)

Example 3 with ConnectionConfig

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

the class QueryClientTest method setUp.

@Before
public void setUp() throws Throwable {
    super.setUp();
    appClient = new ApplicationClient(clientConfig);
    queryClient = new QueryClient(clientConfig);
    programClient = new ProgramClient(clientConfig);
    streamClient = new StreamClient(clientConfig);
    String accessToken = (clientConfig.getAccessToken() == null) ? null : clientConfig.getAccessToken().getValue();
    ConnectionConfig connectionConfig = clientConfig.getConnectionConfig();
    exploreClient = new FixedAddressExploreClient(connectionConfig.getHostname(), connectionConfig.getPort(), accessToken, connectionConfig.isSSLEnabled(), clientConfig.isVerifySSLCert());
    namespaceClient = new NamespaceClient(clientConfig);
}
Also used : ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig) FixedAddressExploreClient(co.cask.cdap.explore.client.FixedAddressExploreClient) Before(org.junit.Before)

Example 4 with ConnectionConfig

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

the class AbstractClientTest method setUp.

@Before
public void setUp() throws Throwable {
    StandaloneTester standalone = getStandaloneTester();
    ConnectionConfig connectionConfig = InstanceURIParser.DEFAULT.parse(standalone.getBaseURI().toString());
    clientConfig = new ClientConfig.Builder().setDefaultReadTimeout(60 * 1000).setUploadReadTimeout(120 * 1000).setConnectionConfig(connectionConfig).build();
}
Also used : StandaloneTester(co.cask.cdap.StandaloneTester) ClientConfig(co.cask.cdap.client.config.ClientConfig) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig) Before(org.junit.Before)

Example 5 with ConnectionConfig

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

the class InstanceURIParser method parse.

public CLIConnectionConfig parse(String uriString) {
    if (!uriString.contains("://")) {
        uriString = DEFAULT_PROTOCOL + "://" + 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(co.cask.cdap.cli.CLIConnectionConfig) NamespaceId(co.cask.cdap.proto.id.NamespaceId) URI(java.net.URI) ConnectionConfig(co.cask.cdap.client.config.ConnectionConfig) CLIConnectionConfig(co.cask.cdap.cli.CLIConnectionConfig)

Aggregations

ConnectionConfig (co.cask.cdap.client.config.ConnectionConfig)12 ClientConfig (co.cask.cdap.client.config.ClientConfig)4 IOException (java.io.IOException)3 UnauthenticatedException (co.cask.cdap.common.UnauthenticatedException)2 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 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 TimeoutException (java.util.concurrent.TimeoutException)2 Discoverable (org.apache.twill.discovery.Discoverable)2 Before (org.junit.Before)2 StandaloneTester (co.cask.cdap.StandaloneTester)1 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)1 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)1 CloseableIterator (co.cask.cdap.api.dataset.lib.CloseableIterator)1 Message (co.cask.cdap.api.messaging.Message)1 MessageFetcher (co.cask.cdap.api.messaging.MessageFetcher)1 MessagingContext (co.cask.cdap.api.messaging.MessagingContext)1