Search in sources :

Example 1 with URIScheme

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.");
    };
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Cancellable(org.apache.twill.common.Cancellable) URIScheme(io.cdap.cdap.common.discovery.URIScheme) ArrayList(java.util.ArrayList)

Example 2 with URIScheme

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);
    }
}
Also used : Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) HttpsEnabler(io.cdap.cdap.common.security.HttpsEnabler) ResolvingDiscoverable(io.cdap.cdap.common.discovery.ResolvingDiscoverable) ChannelPipelineModifier(io.cdap.http.ChannelPipelineModifier) Inject(com.google.inject.Inject) MetricsReporterHook(io.cdap.cdap.common.metrics.MetricsReporterHook) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) DatasetMetricsReporter(io.cdap.cdap.data2.metrics.DatasetMetricsReporter) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered) SettableFuture(com.google.common.util.concurrent.SettableFuture) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) NettyHttpService(io.cdap.http.NettyHttpService) AbstractService(com.google.common.util.concurrent.AbstractService) Cancellable(org.apache.twill.common.Cancellable) Objects(com.google.common.base.Objects) DiscoveryService(org.apache.twill.discovery.DiscoveryService) HttpRequest(io.netty.handler.codec.http.HttpRequest) Logger(org.slf4j.Logger) URIScheme(io.cdap.cdap.common.discovery.URIScheme) Set(java.util.Set) ChannelPipeline(io.netty.channel.ChannelPipeline) InetSocketAddress(java.net.InetSocketAddress) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Constants(io.cdap.cdap.common.conf.Constants) Collections(java.util.Collections) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) InetSocketAddress(java.net.InetSocketAddress) URIScheme(io.cdap.cdap.common.discovery.URIScheme) DatasetMetricsReporter(io.cdap.cdap.data2.metrics.DatasetMetricsReporter) ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered)

Example 3 with URIScheme

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;
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) URIScheme(io.cdap.cdap.common.discovery.URIScheme) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) ConnectionConfig(io.cdap.cdap.client.config.ConnectionConfig) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) TimeoutException(java.util.concurrent.TimeoutException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) IOException(java.io.IOException) UnauthenticatedException(io.cdap.cdap.security.spi.authentication.UnauthenticatedException) NotFoundException(io.cdap.cdap.common.NotFoundException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with URIScheme

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

Aggregations

URIScheme (io.cdap.cdap.common.discovery.URIScheme)4 InetSocketAddress (java.net.InetSocketAddress)3 TimeoutException (java.util.concurrent.TimeoutException)2 Cancellable (org.apache.twill.common.Cancellable)2 Objects (com.google.common.base.Objects)1 Iterables (com.google.common.collect.Iterables)1 AbstractService (com.google.common.util.concurrent.AbstractService)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 Inject (com.google.inject.Inject)1 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)1 ConnectionConfig (io.cdap.cdap.client.config.ConnectionConfig)1 NotFoundException (io.cdap.cdap.common.NotFoundException)1 ServiceUnavailableException (io.cdap.cdap.common.ServiceUnavailableException)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 Constants (io.cdap.cdap.common.conf.Constants)1 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)1 ResolvingDiscoverable (io.cdap.cdap.common.discovery.ResolvingDiscoverable)1 CommonNettyHttpServiceBuilder (io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder)1 MetricsReporterHook (io.cdap.cdap.common.metrics.MetricsReporterHook)1