Search in sources :

Example 46 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project cdap by caskdata.

the class YarnCheck method run.

@Override
public void run() {
    int yarnConnectTimeout = cConf.getInt(Constants.Startup.YARN_CONNECT_TIMEOUT_SECONDS, 60);
    LOG.info("Checking YARN availability -- may take up to {} seconds.", yarnConnectTimeout);
    final YarnClient yarnClient = YarnClient.createYarnClient();
    yarnClient.init(hConf);
    List<NodeReport> nodeReports;
    // if yarn is not up, yarnClient.start() will hang.
    ExecutorService executorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("startup-checker").build());
    try {
        Future<List<NodeReport>> result = executorService.submit(new Callable<List<NodeReport>>() {

            @Override
            public List<NodeReport> call() throws Exception {
                yarnClient.start();
                return yarnClient.getNodeReports();
            }
        });
        nodeReports = result.get(yarnConnectTimeout, TimeUnit.SECONDS);
        LOG.info("  YARN availability successfully verified.");
    } catch (Exception e) {
        throw new RuntimeException("Unable to get status of YARN nodemanagers. " + "Please check that YARN is running " + "and that the correct Hadoop configuration (core-site.xml, yarn-site.xml) and libraries " + "are included in the CDAP master classpath.", e);
    } finally {
        try {
            yarnClient.stop();
        } catch (Exception e) {
            LOG.warn("Error stopping yarn client.", e);
        } finally {
            executorService.shutdown();
        }
    }
    checkResources(nodeReports);
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) List(java.util.List) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) NodeReport(org.apache.hadoop.yarn.api.records.NodeReport)

Example 47 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project cdap by caskdata.

the class NettyRouter method startUp.

@Override
protected void startUp() throws ServiceBindException {
    ChannelUpstreamHandler connectionTracker = new SimpleChannelUpstreamHandler() {

        @Override
        public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
            channelGroup.add(e.getChannel());
            super.channelOpen(ctx, e);
        }
    };
    tokenValidator.startAndWait();
    timer = new HashedWheelTimer(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("router-idle-event-generator-timer").build());
    bootstrapClient(connectionTracker);
    bootstrapServer(connectionTracker);
}
Also used : SimpleChannelUpstreamHandler(org.jboss.netty.channel.SimpleChannelUpstreamHandler) ChannelUpstreamHandler(org.jboss.netty.channel.ChannelUpstreamHandler) ChannelStateEvent(org.jboss.netty.channel.ChannelStateEvent) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ChannelHandlerContext(org.jboss.netty.channel.ChannelHandlerContext) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) SimpleChannelUpstreamHandler(org.jboss.netty.channel.SimpleChannelUpstreamHandler)

Example 48 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project cdap by caskdata.

the class DatasetUpgrader method upgrade.

@Override
public void upgrade() throws Exception {
    int numThreads = cConf.getInt(Constants.Upgrade.UPGRADE_THREAD_POOL_SIZE);
    ExecutorService executor = Executors.newFixedThreadPool(numThreads, new ThreadFactoryBuilder().setNameFormat("hbase-cmd-executor-%d").setDaemon(true).build());
    try {
        // Upgrade system dataset
        upgradeSystemDatasets(executor);
        // Upgrade all user hbase tables
        upgradeUserTables(executor);
    } finally {
        // We'll have tasks pending in the executor only on an interrupt, when user wants to abort the upgrade.
        // Use shutdownNow() to interrupt the tasks and abort.
        executor.shutdownNow();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder)

Example 49 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project cdap by caskdata.

the class HBaseQueueAdmin method upgrade.

@Override
public void upgrade() throws Exception {
    int numThreads = cConf.getInt(Constants.Upgrade.UPGRADE_THREAD_POOL_SIZE);
    final ExecutorService executor = Executors.newFixedThreadPool(numThreads, new ThreadFactoryBuilder().setNameFormat("hbase-cmd-executor-%d").setDaemon(true).build());
    try {
        final Map<TableId, Future<?>> allFutures = new HashMap<>();
        // For each queue config table and queue data table in each namespace, perform an upgrade
        for (final NamespaceMeta namespaceMeta : namespaceQueryAdmin.list()) {
            impersonator.doAs(namespaceMeta.getNamespaceId(), new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    Map<TableId, Future<?>> futures = upgradeQueues(namespaceMeta, executor);
                    allFutures.putAll(futures);
                    return null;
                }
            });
        }
        // Wait for the queue upgrades to complete
        Map<TableId, Throwable> failed = waitForUpgrade(allFutures);
        if (!failed.isEmpty()) {
            for (Map.Entry<TableId, Throwable> entry : failed.entrySet()) {
                LOG.error("Failed to upgrade queue table {}", entry.getKey(), entry.getValue());
            }
            throw new Exception(String.format("Error upgrading queue tables. %s of %s failed", failed.size(), allFutures.size()));
        }
    } finally {
        // We'll have tasks pending in the executor only on an interrupt, when user wants to abort the upgrade.
        // Use shutdownNow() to interrupt the tasks and abort.
        executor.shutdownNow();
    }
}
Also used : TableId(co.cask.cdap.data2.util.TableId) HashMap(java.util.HashMap) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Future(java.util.concurrent.Future) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 50 with ThreadFactoryBuilder

use of com.google.common.util.concurrent.ThreadFactoryBuilder in project google-cloud-java by GoogleCloudPlatform.

the class WatchdogInterceptor method newDefaultWatchdogInterceptor.

/**
   * Creates a default instance based on the system property {@code
   * com.google.cloud.spanner.watchdogTimeoutSeconds}, or a no-op interceptor if none configured.
   */
@Nullable
static ClientInterceptor newDefaultWatchdogInterceptor() {
    int timeoutSeconds = systemProperty(PROPERTY_TIMEOUT_SECONDS, DEFAULT_TIMEOUT_SECONDS);
    if (timeoutSeconds <= 0) {
        return new ClientInterceptor() {

            @Override
            public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions, Channel channel) {
                return channel.newCall(methodDescriptor, callOptions);
            }
        };
    }
    int periodSeconds = systemProperty(PROPERTY_PERIOD_SECONDS, DEFAULT_PERIOD_SECONDS);
    final WatchdogInterceptor interceptor = new WatchdogInterceptor(timeoutSeconds, TimeUnit.SECONDS);
    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Cloud-Spanner-WatchdogInterceptor-%d").build());
    executor.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            interceptor.tick();
        }
    }, periodSeconds, periodSeconds, TimeUnit.SECONDS);
    logger.log(Level.FINE, "Created watchdog interceptor with activity timeout of {0}s and period {1}s", new Object[] { timeoutSeconds, periodSeconds });
    return interceptor;
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Channel(io.grpc.Channel) ClientInterceptor(io.grpc.ClientInterceptor) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) CallOptions(io.grpc.CallOptions) MethodDescriptor(io.grpc.MethodDescriptor) Nullable(javax.annotation.Nullable)

Aggregations

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)143 ExecutorService (java.util.concurrent.ExecutorService)49 ThreadFactory (java.util.concurrent.ThreadFactory)46 IOException (java.io.IOException)23 Future (java.util.concurrent.Future)19 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)19 ExecutionException (java.util.concurrent.ExecutionException)17 ArrayList (java.util.ArrayList)15 Callable (java.util.concurrent.Callable)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 HashMap (java.util.HashMap)11 Path (org.apache.hadoop.fs.Path)11 LinkedList (java.util.LinkedList)10 Map (java.util.Map)10 HashSet (java.util.HashSet)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)9 Test (org.junit.Test)9 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)8 Before (org.junit.Before)8