use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class ExploreExecutorService method startUp.
@Override
protected void startUp() throws Exception {
LoggingContextAccessor.setLoggingContext(new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, Constants.Service.EXPLORE_HTTP_USER_SERVICE));
LOG.info("Starting {}...", ExploreExecutorService.class.getSimpleName());
if (!startOnDemand) {
exploreService.startAndWait();
}
httpService.startAndWait();
cancellable = discoveryService.register(ResolvingDiscoverable.of(new Discoverable(Constants.Service.EXPLORE_HTTP_USER_SERVICE, httpService.getBindAddress())));
LOG.info("{} started successfully on {}", ExploreExecutorService.class.getSimpleName(), httpService.getBindAddress());
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class ServerResource method registerServer.
public void registerServer() {
// Register services of test server
LOG.info("Registering service {}", serviceName);
cancelDiscovery = discoveryService.register(ResolvingDiscoverable.of(new Discoverable(serviceName, httpService.getBindAddress())));
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class UpgradeTool method ensureCDAPMasterStopped.
/**
* Checks for appfabric service path on zookeeper, if they exist, CDAP master is still running, so throw
* exception message with information on where its running.
* @throws Exception if at least one master is running
*/
private void ensureCDAPMasterStopped() throws Exception {
String appFabricPath = String.format("/discoverable/%s", Constants.Service.APP_FABRIC_HTTP);
NodeChildren nodeChildren = zkClientService.getChildren(appFabricPath).get();
List<String> runningNodes = new ArrayList<>();
// if no children nodes at appfabric path, all master nodes are stopped
if (!nodeChildren.getChildren().isEmpty()) {
for (String runId : nodeChildren.getChildren()) {
// only one children would be present, as only the active master will be registered at this path
NodeData nodeData = zkClientService.getData(String.format("%s/%s", appFabricPath, runId)).get();
Discoverable discoverable = GSON.fromJson(Bytes.toString(nodeData.getData()), Discoverable.class);
runningNodes.add(discoverable.getSocketAddress().getHostName());
}
String exceptionMessage = String.format("CDAP Master is still running on %s, please stop it before running upgrade.", com.google.common.base.Joiner.on(",").join(runningNodes));
throw new Exception(exceptionMessage);
}
// CDAP-11733 As a future improvement, the upgrade tool can register as a CDAP master to become the leader
// and prevent other masters from starting.
}
use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.
the class ExternalAuthenticationServerTestBase method testServiceRegistration.
/**
* Test that the service is discoverable.
*
* @throws Exception
*/
@Test
public void testServiceRegistration() throws Exception {
Iterable<Discoverable> discoverables = discoveryServiceClient.discover(Constants.Service.EXTERNAL_AUTHENTICATION);
Set<SocketAddress> addresses = Sets.newHashSet();
for (Discoverable discoverable : discoverables) {
addresses.add(discoverable.getSocketAddress());
}
Assert.assertTrue(addresses.contains(server.getSocketAddress()));
}
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);
}
Aggregations