Search in sources :

Example 11 with EndpointStrategy

use of co.cask.cdap.common.discovery.EndpointStrategy in project cdap by caskdata.

the class RouterServiceLookup method loadCache.

private EndpointStrategy loadCache(CacheKey cacheKey) throws Exception {
    EndpointStrategy endpointStrategy;
    RouteDestination routeDestination = cacheKey.getRouteDestination();
    if (routeDestination.getServiceName().contains("$HOST")) {
        // Route URLs to host in the header.
        endpointStrategy = discoverService(cacheKey);
        if (endpointStrategy.pick() == null) {
            // Now try default, this matches any host / any port in the host header.
            endpointStrategy = discoverDefaultService(cacheKey);
        }
    } else {
        endpointStrategy = discover(routeDestination);
    }
    if (endpointStrategy.pick() == null) {
        String message = String.format("No discoverable endpoints found for service %s", cacheKey);
        LOG.debug(message);
        throw new Exception(message);
    }
    return endpointStrategy;
}
Also used : UserServiceEndpointStrategy(co.cask.cdap.gateway.discovery.UserServiceEndpointStrategy) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) ExecutionException(java.util.concurrent.ExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 12 with EndpointStrategy

use of co.cask.cdap.common.discovery.EndpointStrategy in project cdap by caskdata.

the class AuthorizationBootstrapperTest method waitForService.

private void waitForService(String discoverableName) throws InterruptedException {
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(discoveryServiceClient.discover(discoverableName));
    Preconditions.checkNotNull(endpointStrategy.pick(10, TimeUnit.SECONDS), "%s service is not up after 10 seconds", discoverableName);
}
Also used : EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Example 13 with EndpointStrategy

use of co.cask.cdap.common.discovery.EndpointStrategy in project cdap by caskdata.

the class MetricsSuiteTestBase method startMetricsService.

public static Injector startMetricsService(CConfiguration conf) {
    Injector injector = Guice.createInjector(Modules.override(new ConfigModule(conf), new NonCustomLocationUnitTestModule().getModule(), new DiscoveryRuntimeModule().getInMemoryModules(), new MetricsHandlerModule(), new MetricsClientRuntimeModule().getInMemoryModules(), new DataFabricModules().getInMemoryModules(), new DataSetsModules().getStandaloneModules(), new DataSetServiceModules().getInMemoryModules(), new ExploreClientModule(), new NamespaceClientRuntimeModule().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule()).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(LogReader.class).to(MockLogReader.class).in(Scopes.SINGLETON);
            bind(Store.class).to(DefaultStore.class);
            bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
            bind(OwnerAdmin.class).to(NoOpOwnerAdmin.class);
        }
    }));
    transactionManager = injector.getInstance(TransactionManager.class);
    transactionManager.startAndWait();
    dsOpService = injector.getInstance(DatasetOpExecutor.class);
    dsOpService.startAndWait();
    datasetService = injector.getInstance(DatasetService.class);
    datasetService.startAndWait();
    metrics = injector.getInstance(MetricsQueryService.class);
    metrics.startAndWait();
    collectionService = injector.getInstance(MetricsCollectionService.class);
    collectionService.startAndWait();
    logReader = injector.getInstance(LogReader.class);
    // initialize the dataset instantiator
    DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
    EndpointStrategy metricsEndPoints = new RandomEndpointStrategy(discoveryClient.discover(Constants.Service.METRICS));
    Discoverable discoverable = metricsEndPoints.pick(1L, TimeUnit.SECONDS);
    Assert.assertNotNull("Could not discover metrics service", discoverable);
    port = discoverable.getSocketAddress().getPort();
    return injector;
}
Also used : NamespaceClientRuntimeModule(co.cask.cdap.common.namespace.guice.NamespaceClientRuntimeModule) DataSetServiceModules(co.cask.cdap.data.runtime.DataSetServiceModules) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) ConfigModule(co.cask.cdap.common.guice.ConfigModule) UGIProvider(co.cask.cdap.security.impersonation.UGIProvider) UnsupportedUGIProvider(co.cask.cdap.security.impersonation.UnsupportedUGIProvider) MetricStore(co.cask.cdap.api.metrics.MetricStore) DefaultStore(co.cask.cdap.internal.app.store.DefaultStore) Store(co.cask.cdap.app.store.Store) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) MetricsClientRuntimeModule(co.cask.cdap.metrics.guice.MetricsClientRuntimeModule) MockLogReader(co.cask.cdap.gateway.handlers.log.MockLogReader) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) Injector(com.google.inject.Injector) DiscoveryRuntimeModule(co.cask.cdap.common.guice.DiscoveryRuntimeModule) Discoverable(org.apache.twill.discovery.Discoverable) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) AuthenticationContextModules(co.cask.cdap.security.auth.context.AuthenticationContextModules) DataSetsModules(co.cask.cdap.data.runtime.DataSetsModules) OwnerAdmin(co.cask.cdap.security.impersonation.OwnerAdmin) NoOpOwnerAdmin(co.cask.cdap.security.impersonation.NoOpOwnerAdmin) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) NonCustomLocationUnitTestModule(co.cask.cdap.common.guice.NonCustomLocationUnitTestModule) AuthorizationTestModule(co.cask.cdap.security.authorization.AuthorizationTestModule) AbstractModule(com.google.inject.AbstractModule) MetricsHandlerModule(co.cask.cdap.metrics.guice.MetricsHandlerModule) ExploreClientModule(co.cask.cdap.explore.guice.ExploreClientModule) TransactionManager(org.apache.tephra.TransactionManager) MockLogReader(co.cask.cdap.gateway.handlers.log.MockLogReader) LogReader(co.cask.cdap.logging.read.LogReader) DataFabricModules(co.cask.cdap.data.runtime.DataFabricModules) AuthorizationEnforcementModule(co.cask.cdap.security.authorization.AuthorizationEnforcementModule) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Example 14 with EndpointStrategy

use of co.cask.cdap.common.discovery.EndpointStrategy in project cdap by caskdata.

the class AppFabricServerTest method startStopServer.

@Test
public void startStopServer() throws Exception {
    Injector injector = AppFabricTestHelper.getInjector();
    AppFabricServer server = injector.getInstance(AppFabricServer.class);
    DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
    Service.State state = server.startAndWait();
    Assert.assertTrue(state == Service.State.RUNNING);
    final EndpointStrategy endpointStrategy = new RandomEndpointStrategy(discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP));
    Assert.assertNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS));
    state = server.stopAndWait();
    Assert.assertTrue(state == Service.State.TERMINATED);
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return endpointStrategy.pick() == null;
        }
    }, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
}
Also used : DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) Injector(com.google.inject.Injector) Service(com.google.common.util.concurrent.Service) IOException(java.io.IOException) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) Test(org.junit.Test)

Example 15 with EndpointStrategy

use of co.cask.cdap.common.discovery.EndpointStrategy in project cdap by caskdata.

the class RemoteNamespaceQueryTest method waitForService.

private static void waitForService(DiscoveryServiceClient discoveryService, String discoverableName) throws InterruptedException {
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(discoveryService.discover(discoverableName));
    Preconditions.checkNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS), "%s service is not up after 5 seconds", discoverableName);
}
Also used : EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Aggregations

EndpointStrategy (co.cask.cdap.common.discovery.EndpointStrategy)19 RandomEndpointStrategy (co.cask.cdap.common.discovery.RandomEndpointStrategy)18 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)8 Discoverable (org.apache.twill.discovery.Discoverable)6 AbstractModule (com.google.inject.AbstractModule)5 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)4 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)4 DatasetOpExecutor (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor)4 Injector (com.google.inject.Injector)4 ConfigModule (co.cask.cdap.common.guice.ConfigModule)3 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)3 UserServiceEndpointStrategy (co.cask.cdap.gateway.discovery.UserServiceEndpointStrategy)3 MetricsQueryService (co.cask.cdap.metrics.query.MetricsQueryService)3 AuthorizationEnforcementModule (co.cask.cdap.security.authorization.AuthorizationEnforcementModule)3 TransactionManager (org.apache.tephra.TransactionManager)3 ServiceDiscovered (org.apache.twill.discovery.ServiceDiscovered)3 ConnectionConfig (co.cask.cdap.client.config.ConnectionConfig)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)2 DataSetServiceModules (co.cask.cdap.data.runtime.DataSetServiceModules)2 DataSetsModules (co.cask.cdap.data.runtime.DataSetsModules)2