use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class AbstractDistributedMasterServiceManager method isServiceAvailable.
@Override
public boolean isServiceAvailable() {
String url = null;
try {
Iterable<Discoverable> discoverables = this.discoveryServiceClient.discover(getDiscoverableName());
for (Discoverable discoverable : discoverables) {
String scheme = Arrays.equals(Constants.Security.SSL_URI_SCHEME.getBytes(), discoverable.getPayload()) ? Constants.Security.SSL_URI_SCHEME : Constants.Security.URI_SCHEME;
url = String.format("%s%s:%d/ping", scheme, discoverable.getSocketAddress().getHostName(), discoverable.getSocketAddress().getPort());
//Ping the discovered service to check its status.
if (checkGetStatus(url).equals(HttpResponseStatus.OK)) {
return true;
}
}
return false;
} catch (IllegalArgumentException e) {
return false;
} catch (Exception e) {
LOG.warn("Unable to ping {} at {} : Reason : {}", serviceName, url, e.getMessage());
return false;
}
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class ResourceBalancerService method createDiscoverable.
private Discoverable createDiscoverable(final String serviceName) {
InetSocketAddress address;
// NOTE: at this moment we are not using port anywhere
int port = Networks.getRandomPort();
try {
address = new InetSocketAddress(InetAddress.getLocalHost(), port);
} catch (UnknownHostException e) {
address = new InetSocketAddress(port);
}
return new Discoverable(serviceName, address);
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class MetadataService method startUp.
@Override
protected void startUp() throws Exception {
LOG.info("Starting Metadata Service");
metadataUpgrader.createOrUpgradeIfNecessary();
httpService = new CommonNettyHttpServiceBuilder(cConf, Constants.Service.METADATA_SERVICE).addHttpHandlers(handlers).setHandlerHooks(ImmutableList.of(new MetricsReporterHook(metricsCollectionService, Constants.Service.METADATA_SERVICE))).setHost(cConf.get(Constants.Metadata.SERVICE_BIND_ADDRESS)).setPort(cConf.getInt(Constants.Metadata.SERVICE_BIND_PORT)).setWorkerThreadPoolSize(cConf.getInt(Constants.Metadata.SERVICE_WORKER_THREADS)).setExecThreadPoolSize(cConf.getInt(Constants.Metadata.SERVICE_EXEC_THREADS)).setConnectionBacklog(20000).build();
httpService.addListener(new ServiceListenerAdapter() {
private Cancellable cancellable;
@Override
public void running() {
final InetSocketAddress socketAddress = httpService.getBindAddress();
LOG.info("Metadata service running at {}", socketAddress);
cancellable = discoveryService.register(ResolvingDiscoverable.of(new Discoverable(Constants.Service.METADATA_SERVICE, socketAddress)));
}
@Override
public void terminated(State from) {
LOG.info("Metadata HTTP service stopped");
cancellable.cancel();
}
@Override
public void failed(State from, Throwable failure) {
LOG.info("Metadata HTTP service stopped with failure.", failure);
cancellable.cancel();
}
}, Threads.SAME_THREAD_EXECUTOR);
httpService.startAndWait();
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class ArtifactHttpHandlerTest method setup.
@BeforeClass
public static void setup() throws IOException {
artifactRepository = getInjector().getInstance(ArtifactRepository.class);
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);
}
use of org.apache.twill.discovery.Discoverable 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();
}
Aggregations