Search in sources :

Example 46 with Discoverable

use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.

the class MockHttpService 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 47 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 48 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 49 with Discoverable

use of org.apache.twill.discovery.Discoverable in project cdap by caskdata.

the class ResourceBalancerService method startUp.

@Override
protected void startUp() throws Exception {
    LOG.info("Starting ResourceBalancer {} service...", serviceName);
    // We first submit requirement before starting coordinator to make sure all needed paths in ZK are created
    ResourceRequirement requirement = ResourceRequirement.builder(serviceName).addPartitions("", partitionCount, 1).build();
    resourceClient.submitRequirement(requirement).get();
    Discoverable discoverable = createDiscoverable(serviceName);
    cancelDiscoverable = discoveryService.register(ResolvingDiscoverable.of(discoverable));
    election.start();
    resourceClient.startAndWait();
    cancelResourceHandler = resourceClient.subscribe(serviceName, createResourceHandler(discoverable));
    LOG.info("Started ResourceBalancer {} service...", serviceName);
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) ResolvingDiscoverable(co.cask.cdap.common.discovery.ResolvingDiscoverable) ResourceRequirement(co.cask.cdap.common.zookeeper.coordination.ResourceRequirement)

Example 50 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)

Aggregations

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