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