use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class TransactionHttpService method startUp.
@Override
protected void startUp() throws Exception {
LOG.info("Starting Transaction HTTP Service...");
httpService.start();
// Register the service
cancelDiscovery = discoveryService.register(ResolvingDiscoverable.of(new Discoverable(Constants.Service.TRANSACTION_HTTP, httpService.getBindAddress())));
LOG.info("Transaction HTTP started successfully on {}", httpService.getBindAddress());
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class ThriftHelper method getThriftProtocol.
/**
* generic method to discover a thrift service and start up the
* thrift transport and protocol layer.
*/
public static TProtocol getThriftProtocol(String serviceName, EndpointStrategy endpointStrategy) throws ServerException {
Discoverable endpoint = endpointStrategy.pick();
if (endpoint == null) {
String message = String.format("Service '%s' is not registered in discovery service.", serviceName);
LOG.error(message);
throw new ServerException(message);
}
TTransport transport = new TFramedTransport(new TSocket(endpoint.getSocketAddress().getHostName(), endpoint.getSocketAddress().getPort()));
try {
transport.open();
} catch (TTransportException e) {
String message = String.format("Unable to connect to thrift service %s at %s. Reason: %s", serviceName, endpoint.getSocketAddress(), e.getMessage());
LOG.error(message);
throw new ServerException(message, e);
}
// now try to connect the thrift client
return new TBinaryProtocol(transport);
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class TransactionServiceManager method isServiceAvailable.
@Override
public boolean isServiceAvailable() {
try {
ServiceDiscovered discovered = discoveryServiceClient.discover(serviceName);
Discoverable discoverable = new RandomEndpointStrategy(discovered).pick(discoveryTimeout, TimeUnit.SECONDS);
if (discoverable == null) {
return false;
}
return txClient.status().equals(Constants.Monitor.STATUS_OK);
} catch (IllegalArgumentException e) {
return false;
} catch (Exception e) {
LOG.warn("Unable to ping {} : Reason {} ", serviceName, e.getMessage());
return false;
}
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class AppFabricServer method startHttpService.
private Cancellable startHttpService(final NettyHttpService httpService) throws Exception {
httpService.start();
String announceAddress = cConf.get(Constants.Service.MASTER_SERVICES_ANNOUNCE_ADDRESS, httpService.getBindAddress().getHostName());
int announcePort = cConf.getInt(Constants.AppFabric.SERVER_ANNOUNCE_PORT, httpService.getBindAddress().getPort());
final InetSocketAddress socketAddress = new InetSocketAddress(announceAddress, announcePort);
LOG.info("AppFabric HTTP Service announced at {}", socketAddress);
// Tag the discoverable's payload to mark it as supporting ssl.
byte[] sslPayload = sslEnabled ? Constants.Security.SSL_URI_SCHEME.getBytes() : Bytes.EMPTY_BYTE_ARRAY;
// TODO accept a list of services, and start them here
// When it is running, register it with service discovery
final List<Cancellable> cancellables = new ArrayList<>();
for (final String serviceName : servicesNames) {
cancellables.add(discoveryService.register(ResolvingDiscoverable.of(new Discoverable(serviceName, socketAddress, sslPayload))));
}
return new Cancellable() {
@Override
public void cancel() {
LOG.debug("Stopping AppFabric HTTP service.");
for (Cancellable cancellable : cancellables) {
if (cancellable != null) {
cancellable.cancel();
}
}
try {
httpService.stop();
} catch (Exception e) {
LOG.warn("Exception raised when stopping AppFabric HTTP service", e);
}
LOG.info("AppFabric HTTP service stopped.");
}
};
}
Aggregations