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);
}
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());
}
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, ""));
}
});
}
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;
}
}
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;
}
Aggregations