Search in sources :

Example 41 with Discoverable

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());
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ResolvingDiscoverable(co.cask.cdap.common.discovery.ResolvingDiscoverable) ServiceLoggingContext(co.cask.cdap.common.logging.ServiceLoggingContext)

Example 42 with Discoverable

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())));
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ResolvingDiscoverable(co.cask.cdap.common.discovery.ResolvingDiscoverable)

Example 43 with Discoverable

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.
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ArrayList(java.util.ArrayList) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) NodeChildren(org.apache.twill.zookeeper.NodeChildren) NodeData(org.apache.twill.zookeeper.NodeData)

Example 44 with Discoverable

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()));
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) SocketAddress(java.net.SocketAddress) Test(org.junit.Test)

Example 45 with Discoverable

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);
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ServerException(co.cask.cdap.common.service.ServerException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

Discoverable (org.apache.twill.discovery.Discoverable)50 ResolvingDiscoverable (co.cask.cdap.common.discovery.ResolvingDiscoverable)17 InetSocketAddress (java.net.InetSocketAddress)14 Test (org.junit.Test)14 RandomEndpointStrategy (co.cask.cdap.common.discovery.RandomEndpointStrategy)10 ServiceLoggingContext (co.cask.cdap.common.logging.ServiceLoggingContext)8 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)7 EndpointStrategy (co.cask.cdap.common.discovery.EndpointStrategy)6 Cancellable (org.apache.twill.common.Cancellable)6 IOException (java.io.IOException)5 CommonNettyHttpServiceBuilder (co.cask.cdap.common.http.CommonNettyHttpServiceBuilder)4 JsonObject (com.google.gson.JsonObject)4 ArrayList (java.util.ArrayList)4 ProgramDescriptor (co.cask.cdap.app.program.ProgramDescriptor)3 ProgramController (co.cask.cdap.app.runtime.ProgramController)3 ServiceDiscoverable (co.cask.cdap.common.service.ServiceDiscoverable)3 ApplicationWithPrograms (co.cask.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms)3 BasicArguments (co.cask.cdap.internal.app.runtime.BasicArguments)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3 ProgramId (co.cask.cdap.proto.id.ProgramId)3