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);
}
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);
}
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);
}
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();
}
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();
}
}
Aggregations