Search in sources :

Example 11 with RandomEndpointStrategy

use of co.cask.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.

the class AbstractServiceDiscoverer method getServiceURL.

@Override
public URL getServiceURL(String applicationId, String serviceId) {
    String discoveryName = String.format("service.%s.%s.%s", namespaceId, applicationId, serviceId);
    ServiceDiscovered discovered = getDiscoveryServiceClient().discover(discoveryName);
    return createURL(new RandomEndpointStrategy(discovered).pick(1, TimeUnit.SECONDS), applicationId, serviceId);
}
Also used : ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Example 12 with RandomEndpointStrategy

use of co.cask.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.

the class DatasetOpExecutorServiceTest method setUp.

@Before
public void setUp() throws Exception {
    Configuration hConf = new Configuration();
    CConfiguration cConf = CConfiguration.create();
    File datasetDir = new File(TMP_FOLDER.newFolder(), "datasetUser");
    Assert.assertTrue(datasetDir.mkdirs());
    cConf.set(Constants.Dataset.Manager.OUTPUT_DIR, datasetDir.getAbsolutePath());
    cConf.set(Constants.Service.MASTER_SERVICES_BIND_ADDRESS, "localhost");
    cConf.set(Constants.Dataset.Executor.ADDRESS, "localhost");
    cConf.setInt(Constants.Dataset.Executor.PORT, Networks.getRandomPort());
    Injector injector = Guice.createInjector(new ConfigModule(cConf, hConf), new IOModule(), new ZKClientModule(), new KafkaClientModule(), new DiscoveryRuntimeModule().getInMemoryModules(), new NonCustomLocationUnitTestModule().getModule(), new DataFabricModules().getInMemoryModules(), new DataSetsModules().getStandaloneModules(), new DataSetServiceModules().getInMemoryModules(), new TransactionMetricsModule(), new ExploreClientModule(), new NamespaceClientRuntimeModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
        }
    });
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    managerService = injector.getInstance(DatasetService.class);
    managerService.startAndWait();
    dsFramework = injector.getInstance(DatasetFramework.class);
    // find host
    DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
    endpointStrategy = new RandomEndpointStrategy(discoveryClient.discover(Constants.Service.DATASET_MANAGER));
    namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
    namespaceAdmin.create(NamespaceMeta.DEFAULT);
    namespaceAdmin.create(new NamespaceMeta.Builder().setName(bob.getParent()).build());
}
Also used : IOModule(co.cask.cdap.common.guice.IOModule) NamespaceClientRuntimeModule(co.cask.cdap.common.namespace.guice.NamespaceClientRuntimeModule) DataSetServiceModules(co.cask.cdap.data.runtime.DataSetServiceModules) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) CConfiguration(co.cask.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ConfigModule(co.cask.cdap.common.guice.ConfigModule) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) TransactionMetricsModule(co.cask.cdap.data.runtime.TransactionMetricsModule) DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) ZKClientModule(co.cask.cdap.common.guice.ZKClientModule) Injector(com.google.inject.Injector) KafkaClientModule(co.cask.cdap.common.guice.KafkaClientModule) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) DiscoveryRuntimeModule(co.cask.cdap.common.guice.DiscoveryRuntimeModule) UnsupportedUGIProvider(co.cask.cdap.security.impersonation.UnsupportedUGIProvider) AuthenticationContextModules(co.cask.cdap.security.auth.context.AuthenticationContextModules) DataSetsModules(co.cask.cdap.data.runtime.DataSetsModules) NamespaceAdmin(co.cask.cdap.common.namespace.NamespaceAdmin) NonCustomLocationUnitTestModule(co.cask.cdap.common.guice.NonCustomLocationUnitTestModule) DefaultOwnerAdmin(co.cask.cdap.security.impersonation.DefaultOwnerAdmin) CConfiguration(co.cask.cdap.common.conf.CConfiguration) AuthorizationTestModule(co.cask.cdap.security.authorization.AuthorizationTestModule) AbstractModule(com.google.inject.AbstractModule) ExploreClientModule(co.cask.cdap.explore.guice.ExploreClientModule) TransactionManager(org.apache.tephra.TransactionManager) File(java.io.File) DataFabricModules(co.cask.cdap.data.runtime.DataFabricModules) AuthorizationEnforcementModule(co.cask.cdap.security.authorization.AuthorizationEnforcementModule) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) Before(org.junit.Before)

Example 13 with RandomEndpointStrategy

use of co.cask.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.

the class WorkflowClient method getWorkflowStatus.

public void getWorkflowStatus(String namespaceId, String appId, String workflowId, String runId, final Callback callback) throws IOException {
    // determine the service provider for the given path
    String serviceName = String.format("workflow.%s.%s.%s.%s", namespaceId, appId, workflowId, runId);
    Discoverable discoverable = new RandomEndpointStrategy(discoveryServiceClient.discover(serviceName)).pick();
    if (discoverable == null) {
        LOG.debug("No endpoint for service {}", serviceName);
        callback.handle(new Status(Status.Code.NOT_FOUND, ""));
        return;
    }
    // make HTTP call to workflow service.
    InetSocketAddress endpoint = discoverable.getSocketAddress();
    // Construct request
    String scheme = Arrays.equals(Constants.Security.SSL_URI_SCHEME.getBytes(), discoverable.getPayload()) ? Constants.Security.SSL_URI_SCHEME : Constants.Security.URI_SCHEME;
    String url = String.format("%s%s:%d/status", scheme, endpoint.getHostName(), endpoint.getPort());
    Request workflowRequest = new RequestBuilder("GET").setUrl(url).build();
    httpClient.executeRequest(workflowRequest, new AsyncCompletionHandler<Void>() {

        @Override
        public Void onCompleted(Response response) throws Exception {
            callback.handle(new Status(Status.Code.OK, response.getResponseBody(Charsets.UTF_8.name())));
            return null;
        }

        @Override
        public void onThrowable(Throwable t) {
            LOG.warn("Failed to request for workflow status", t);
            callback.handle(new Status(Status.Code.ERROR, ""));
        }
    });
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) RequestBuilder(com.ning.http.client.RequestBuilder) InetSocketAddress(java.net.InetSocketAddress) Request(com.ning.http.client.Request) IOException(java.io.IOException) Response(com.ning.http.client.Response) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Example 14 with RandomEndpointStrategy

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

Example 15 with RandomEndpointStrategy

use of co.cask.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.

the class RouterServiceLookup method discover.

private EndpointStrategy discover(RouteDestination routeDestination) throws ExecutionException {
    LOG.debug("Looking up service name {}", routeDestination);
    // If its a user service, then use DistributionEndpoint Strategy
    String serviceName = routeDestination.getServiceName();
    ServiceDiscovered serviceDiscovered = discoveryServiceClient.discover(serviceName);
    EndpointStrategy endpointStrategy = ServiceDiscoverable.isServiceDiscoverable(serviceName) ? new UserServiceEndpointStrategy(serviceDiscovered, routeStore, ServiceDiscoverable.getId(serviceName), fallbackStrategy, routeDestination.getVersion()) : new RandomEndpointStrategy(serviceDiscovered);
    if (endpointStrategy.pick(300L, TimeUnit.MILLISECONDS) == null) {
        LOG.debug("Discoverable endpoint {} not found", routeDestination);
    }
    return endpointStrategy;
}
Also used : UserServiceEndpointStrategy(co.cask.cdap.gateway.discovery.UserServiceEndpointStrategy) UserServiceEndpointStrategy(co.cask.cdap.gateway.discovery.UserServiceEndpointStrategy) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Aggregations

RandomEndpointStrategy (co.cask.cdap.common.discovery.RandomEndpointStrategy)24 EndpointStrategy (co.cask.cdap.common.discovery.EndpointStrategy)16 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)12 Discoverable (org.apache.twill.discovery.Discoverable)10 ServiceDiscovered (org.apache.twill.discovery.ServiceDiscovered)7 AbstractModule (com.google.inject.AbstractModule)6 Injector (com.google.inject.Injector)6 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)5 TransactionManager (org.apache.tephra.TransactionManager)5 Test (org.junit.Test)5 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)4 ConfigModule (co.cask.cdap.common.guice.ConfigModule)4 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)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 DatasetOpExecutor (co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor)3 ApplicationWithPrograms (co.cask.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms)3 BasicArguments (co.cask.cdap.internal.app.runtime.BasicArguments)3 AuthorizationEnforcementModule (co.cask.cdap.security.authorization.AuthorizationEnforcementModule)3