Search in sources :

Example 11 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.

the class DefaultSecureStoreServiceTest method waitForService.

private static void waitForService(String service) {
    EndpointStrategy endpointStrategy = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(service));
    Preconditions.checkNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS), "%s service is not up after 5 seconds", service);
}
Also used : RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(io.cdap.cdap.common.discovery.EndpointStrategy) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 12 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.

the class RemoteExecutionDiscoveryServiceTest method testAppDisabled.

@Test
public void testAppDisabled() {
    CConfiguration cConf = CConfiguration.create();
    RemoteExecutionDiscoveryService discoveryService = new RemoteExecutionDiscoveryService(cConf, RuntimeMonitorType.SSH);
    // Discovery of app is disabled. It always return a ServiceDiscovered without endpoint in it
    String name = ServiceDiscoverable.getName(NamespaceId.DEFAULT.app("test").service("service"));
    Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryService.discover(name)).pick(1, TimeUnit.SECONDS);
    Assert.assertNull(discoverable);
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ServiceDiscoverable(io.cdap.cdap.common.service.ServiceDiscoverable) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) Test(org.junit.Test)

Example 13 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.

the class AbstractMasterServiceManager method isServiceAvailable.

@Override
public boolean isServiceAvailable() {
    // Try to ping the endpoint. If any one of them is available, we treat the service as available.
    ServiceDiscovered serviceDiscovered = discoveryClient.discover(serviceName);
    // Block to wait for some endpoint to be available. This is just to compensate initialization.
    // Calls after the first discovery will return immediately.
    new RandomEndpointStrategy(() -> serviceDiscovered).pick(serviceTimeoutSeconds, TimeUnit.SECONDS);
    return StreamSupport.stream(serviceDiscovered.spliterator(), false).anyMatch(this::isEndpointAlive);
}
Also used : ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 14 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy 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();
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(io.cdap.cdap.common.discovery.EndpointStrategy) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 15 with RandomEndpointStrategy

use of io.cdap.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.

the class ZKDiscoveryModuleTest method testMasterDiscovery.

@Test
public void testMasterDiscovery() {
    Injector injector = Guice.createInjector(new ConfigModule(cConf), new ZKClientModule(), new ZKDiscoveryModule());
    ZKClientService zkClient = injector.getInstance(ZKClientService.class);
    zkClient.startAndWait();
    try {
        DiscoveryService discoveryService = injector.getInstance(DiscoveryService.class);
        DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
        // Register a master service
        InetSocketAddress socketAddr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 43210);
        Cancellable cancellable = discoveryService.register(new Discoverable(Constants.Service.APP_FABRIC_HTTP, socketAddr));
        try {
            // Discover the master service
            Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP)).pick(10, TimeUnit.SECONDS);
            Assert.assertNotNull(discoverable);
            Assert.assertEquals(Constants.Service.APP_FABRIC_HTTP, discoverable.getName());
            Assert.assertEquals(socketAddr, discoverable.getSocketAddress());
        } finally {
            cancellable.cancel();
        }
    } finally {
        zkClient.stopAndWait();
    }
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ServiceDiscoverable(io.cdap.cdap.common.service.ServiceDiscoverable) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) ZKClientService(org.apache.twill.zookeeper.ZKClientService) Injector(com.google.inject.Injector) InetSocketAddress(java.net.InetSocketAddress) Cancellable(org.apache.twill.common.Cancellable) ZKDiscoveryService(org.apache.twill.discovery.ZKDiscoveryService) DiscoveryService(org.apache.twill.discovery.DiscoveryService) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) Test(org.junit.Test)

Aggregations

RandomEndpointStrategy (io.cdap.cdap.common.discovery.RandomEndpointStrategy)66 Discoverable (org.apache.twill.discovery.Discoverable)38 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)38 EndpointStrategy (io.cdap.cdap.common.discovery.EndpointStrategy)26 Test (org.junit.Test)22 Injector (com.google.inject.Injector)20 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)12 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)12 DatasetService (io.cdap.cdap.data2.datafabric.dataset.service.DatasetService)12 StructuredTableAdmin (io.cdap.cdap.spi.data.StructuredTableAdmin)12 InetSocketAddress (java.net.InetSocketAddress)12 TransactionManager (org.apache.tephra.TransactionManager)12 ConnectionConfig (io.cdap.cdap.client.config.ConnectionConfig)10 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)10 DatasetOpExecutorService (io.cdap.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutorService)10 URL (java.net.URL)10 Service (com.google.common.util.concurrent.Service)8 AbstractModule (com.google.inject.AbstractModule)8 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)8 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)8