use of io.cdap.cdap.common.discovery.URIScheme in project cdap by caskdata.
the class AppFabricServer method startHttpService.
private Cancellable startHttpService(NettyHttpService httpService) throws Exception {
httpService.start();
String announceAddress = cConf.get(Constants.Service.MASTER_SERVICES_ANNOUNCE_ADDRESS, httpService.getBindAddress().getHostName());
int announcePort = cConf.getInt(Constants.AppFabric.SERVER_ANNOUNCE_PORT, httpService.getBindAddress().getPort());
final InetSocketAddress socketAddress = new InetSocketAddress(announceAddress, announcePort);
LOG.info("AppFabric HTTP Service announced at {}", socketAddress);
// Tag the discoverable's payload to mark it as supporting ssl.
URIScheme uriScheme = sslEnabled ? URIScheme.HTTPS : URIScheme.HTTP;
// TODO accept a list of services, and start them here
// When it is running, register it with service discovery
final List<Cancellable> cancellables = new ArrayList<>();
for (final String serviceName : servicesNames) {
cancellables.add(discoveryService.register(ResolvingDiscoverable.of(uriScheme.createDiscoverable(serviceName, socketAddress))));
}
return () -> {
LOG.debug("Stopping AppFabric HTTP service.");
for (Cancellable cancellable : cancellables) {
if (cancellable != null) {
cancellable.cancel();
}
}
try {
httpService.stop();
} catch (Exception e) {
LOG.warn("Exception raised when stopping AppFabric HTTP service", e);
}
LOG.info("AppFabric HTTP service stopped.");
};
}
use of io.cdap.cdap.common.discovery.URIScheme in project cdap by caskdata.
the class DatasetService method startUp.
/**
* Starts this service by starting all dependencies and wait for operation executor to be ready.
*/
private void startUp() {
try {
LOG.info("Starting DatasetService...");
typeService.startAndWait();
httpService.start();
// setting watch for ops executor service that we need to be running to operate correctly
ServiceDiscovered discover = discoveryServiceClient.discover(Constants.Service.DATASET_EXECUTOR);
opExecutorDiscovered = SettableFuture.create();
opExecutorServiceWatch = discover.watchChanges(serviceDiscovered -> {
if (!Iterables.isEmpty(serviceDiscovered)) {
LOG.info("Discovered {} service", Constants.Service.DATASET_EXECUTOR);
opExecutorDiscovered.set(serviceDiscovered);
}
}, MoreExecutors.sameThreadExecutor());
for (DatasetMetricsReporter metricsReporter : metricReporters) {
metricsReporter.start();
}
} catch (Throwable t) {
notifyFailed(t);
return;
}
// Notify that the Service has been started to unblock all startAndWait call on this service
notifyStarted();
try {
waitForOpExecutorToStart();
String announceAddress = cConf.get(Constants.Service.MASTER_SERVICES_ANNOUNCE_ADDRESS, httpService.getBindAddress().getHostName());
int announcePort = cConf.getInt(Constants.Dataset.Manager.ANNOUNCE_PORT, httpService.getBindAddress().getPort());
InetSocketAddress socketAddress = new InetSocketAddress(announceAddress, announcePort);
URIScheme scheme = httpService.isSSLEnabled() ? URIScheme.HTTPS : URIScheme.HTTP;
LOG.info("Announcing DatasetService for discovery...");
// Register the service
cancelDiscovery = discoveryService.register(ResolvingDiscoverable.of(scheme.createDiscoverable(Constants.Service.DATASET_MANAGER, socketAddress)));
LOG.info("DatasetService started successfully on {}", socketAddress);
} catch (Throwable t) {
try {
doShutdown();
} catch (Throwable shutdownError) {
t.addSuppressed(shutdownError);
}
notifyFailed(t);
}
}
use of io.cdap.cdap.common.discovery.URIScheme in project cdap by caskdata.
the class RemoteSparkManager method getServiceURL.
@Override
public URL getServiceURL(long timeout, TimeUnit timeoutUnit) {
try {
Tasks.waitFor(true, () -> {
try {
checkAvailability();
return true;
} catch (ServiceUnavailableException e) {
return false;
}
}, timeout, timeoutUnit);
ConnectionConfig connectionConfig = clientConfig.getConnectionConfig();
URIScheme scheme = connectionConfig.isSSLEnabled() ? URIScheme.HTTPS : URIScheme.HTTP;
return ServiceDiscoverable.createServiceBaseURL(scheme.createDiscoverable("spark", new InetSocketAddress(connectionConfig.getHostname(), connectionConfig.getPort())), programId);
} catch (TimeoutException e) {
return null;
} catch (Exception e) {
LOG.warn("Exception raised when waiting for Spark service to be available", e);
return null;
}
}
use of io.cdap.cdap.common.discovery.URIScheme in project cdap by caskdata.
the class RemoteExecutionDiscoveryService method updateServiceDiscovered.
private void updateServiceDiscovered(DefaultServiceDiscovered serviceDiscovered, CConfiguration cConf, String key) {
String name = serviceDiscovered.getName();
Set<Discoverable> discoverables = Networks.getDiscoverables(cConf, key);
if (discoverables.isEmpty()) {
Discoverable discoverable;
if (name.equals(runtimeMonitorDiscoverable.getName())) {
discoverable = runtimeMonitorDiscoverable;
} else {
// If there is no address from the configuration, assuming it is using the service proxy,
// hence the discovery name is the hostname. Also use port == 0 so that the RemoteExecutionProxySelector
// knows that it need to use service proxy.
URIScheme scheme = cConf.getBoolean(Constants.Security.SSL.INTERNAL_ENABLED) ? URIScheme.HTTPS : URIScheme.HTTP;
discoverable = scheme.createDiscoverable(name, InetSocketAddress.createUnresolved(name, 0));
}
discoverables = Collections.singleton(discoverable);
}
if (LOG.isDebugEnabled()) {
for (Discoverable d : discoverables) {
LOG.debug("Update discoverable {} with address {} and payload {}", d.getName(), d.getSocketAddress(), Bytes.toString(d.getPayload()));
}
}
serviceDiscovered.setDiscoverables(discoverables);
}
Aggregations