use of com.google.common.util.concurrent.ListenableFuture in project hive by apache.
the class HostExecutor method execInstances.
private List<ListenableFuture<RemoteCommandResult>> execInstances(List<Drone> drones, final String cmd) throws InterruptedException, IOException {
List<ListenableFuture<RemoteCommandResult>> result = Lists.newArrayList();
for (final Drone drone : ImmutableList.copyOf(drones)) {
result.add(mExecutor.submit(new Callable<RemoteCommandResult>() {
@Override
public RemoteCommandResult call() throws Exception {
Map<String, String> templateVariables = Maps.newHashMap(mTemplateDefaults);
templateVariables.put("instanceName", drone.getInstanceName());
templateVariables.put("localDir", drone.getLocalDirectory());
String command = Templates.getTemplateResult(cmd, templateVariables);
SSHResult result = new SSHCommand(mSSHCommandExecutor, drone.getPrivateKey(), drone.getUser(), drone.getHost(), drone.getInstance(), command, true).call();
if (result.getExitCode() != Constants.EXIT_CODE_SUCCESS) {
// return value not checked due to concurrent access
mDrones.remove(drone);
mLogger.error("Aborting drone during exec " + command, new AbortDroneException("Drone " + drone + " exited with " + result.getExitCode() + ": " + result));
return null;
} else {
return result;
}
}
}));
}
return result;
}
use of com.google.common.util.concurrent.ListenableFuture in project hive by apache.
the class Phase method initalizeHosts.
protected List<RemoteCommandResult> initalizeHosts() throws Exception {
List<ListenableFuture<List<RemoteCommandResult>>> futures = Lists.newArrayList();
ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(hostExecutors.size()));
try {
for (final HostExecutor hostExecutor : hostExecutors) {
futures.add(executor.submit(new Callable<List<RemoteCommandResult>>() {
@Override
public List<RemoteCommandResult> call() throws Exception {
return initalizeHost(hostExecutor);
}
}));
}
List<RemoteCommandResult> results = Lists.newArrayList();
for (ListenableFuture<List<RemoteCommandResult>> future : futures) {
List<RemoteCommandResult> result = future.get();
if (result != null) {
results.addAll(result);
}
}
executor.shutdown();
return results;
} finally {
if (executor.isShutdown()) {
executor.shutdownNow();
}
}
}
use of com.google.common.util.concurrent.ListenableFuture in project weave by continuuity.
the class RunningContainers method stopAll.
/**
* Stops all running services. Only called when the AppMaster stops.
*/
void stopAll() {
containerLock.lock();
try {
// Stop it one by one in reverse order of start sequence
Iterator<String> itor = startSequence.descendingIterator();
List<ListenableFuture<ServiceController.State>> futures = Lists.newLinkedList();
while (itor.hasNext()) {
String runnableName = itor.next();
LOG.info("Stopping all instances of " + runnableName);
futures.clear();
// Parallel stops all running containers of the current runnable.
for (WeaveContainerController controller : containers.row(runnableName).values()) {
futures.add(controller.stop());
}
// Wait for containers to stop. Assumes the future returned by Futures.successfulAsList won't throw exception.
Futures.getUnchecked(Futures.successfulAsList(futures));
LOG.info("Terminated all instances of " + runnableName);
}
containers.clear();
runnableInstances.clear();
} finally {
containerLock.unlock();
}
}
use of com.google.common.util.concurrent.ListenableFuture in project buck by facebook.
the class DistBuildClientExecutor method executeAndPrintFailuresToEventBus.
public int executeAndPrintFailuresToEventBus(final WeightedListeningExecutorService executorService, ProjectFilesystem projectFilesystem, FileHashCache fileHashCache, BuckEventBus eventBus) throws IOException, InterruptedException {
BuildJob job = distBuildService.createBuild();
final StampedeId id = job.getStampedeId();
LOG.info("Created job. Build id = " + id.getId());
logDebugInfo(job);
List<ListenableFuture<Void>> asyncJobs = new LinkedList<>();
LOG.info("Uploading local changes.");
asyncJobs.add(distBuildService.uploadMissingFiles(buildJobState.fileHashes, executorService));
LOG.info("Uploading target graph.");
asyncJobs.add(distBuildService.uploadTargetGraph(buildJobState, id, executorService));
LOG.info("Uploading buck dot-files.");
asyncJobs.add(distBuildService.uploadBuckDotFiles(id, projectFilesystem, fileHashCache, executorService));
try {
Futures.allAsList(asyncJobs).get();
} catch (ExecutionException e) {
LOG.error("Upload failed.");
throw new RuntimeException(e);
}
distBuildService.setBuckVersion(id, buckVersion);
LOG.info("Set Buck Version. Build status: " + job.getStatus().toString());
job = distBuildService.startBuild(id);
LOG.info("Started job. Build status: " + job.getStatus().toString());
logDebugInfo(job);
Stopwatch stopwatch = Stopwatch.createStarted();
// Keep polling until the build is complete or failed.
do {
job = distBuildService.getCurrentBuildJobState(id);
LOG.info("Got build status: " + job.getStatus().toString());
DistBuildStatus distBuildStatus = prepareStatusFromJob(job).setETAMillis(MAX_BUILD_DURATION_MILLIS - stopwatch.elapsed(TimeUnit.MILLISECONDS)).build();
eventBus.post(new DistBuildStatusEvent(distBuildStatus));
List<LogLineBatchRequest> newLogLineRequests = distBuildLogStateTracker.createRealtimeLogRequests(job.getSlaveInfoByRunId().values());
MultiGetBuildSlaveRealTimeLogsResponse slaveLogsResponse = distBuildService.fetchSlaveLogLines(job.stampedeId, newLogLineRequests);
distBuildLogStateTracker.processStreamLogs(slaveLogsResponse.getMultiStreamLogs());
try {
// TODO(shivanker): Get rid of sleeps in methods which we want to unit test
Thread.sleep(millisBetweenStatusPoll);
} catch (InterruptedException e) {
LOG.error(e, "BuildStatus polling sleep call has been interrupted unexpectedly.");
}
} while (!(job.getStatus().equals(BuildStatus.FINISHED_SUCCESSFULLY) || job.getStatus().equals(BuildStatus.FAILED)));
try {
MultiGetBuildSlaveLogDirResponse logDirsResponse = distBuildService.fetchBuildSlaveLogDir(job.stampedeId, distBuildLogStateTracker.runIdsToMaterializeLogDirsFor(job.slaveInfoByRunId.values()));
distBuildLogStateTracker.materializeLogDirs(logDirsResponse.getLogDirs());
} catch (IOException ex) {
LOG.error(ex);
}
LOG.info("Build was " + (job.getStatus().equals(BuildStatus.FINISHED_SUCCESSFULLY) ? "" : "not ") + "successful!");
logDebugInfo(job);
DistBuildStatus distBuildStatus = prepareStatusFromJob(job).setETAMillis(0).build();
eventBus.post(new DistBuildStatusEvent(distBuildStatus));
return job.getStatus().equals(BuildStatus.FINISHED_SUCCESSFULLY) ? 0 : 1;
}
use of com.google.common.util.concurrent.ListenableFuture in project buck by facebook.
the class DistBuildFileHashes method ruleKeyComputation.
private static ListenableFuture<ImmutableMap<BuildRule, RuleKey>> ruleKeyComputation(ActionGraph actionGraph, final LoadingCache<ProjectFilesystem, DefaultRuleKeyFactory> ruleKeyFactories, ListeningExecutorService executorService) {
List<ListenableFuture<Map.Entry<BuildRule, RuleKey>>> ruleKeyEntries = new ArrayList<>();
for (final BuildRule rule : actionGraph.getNodes()) {
ruleKeyEntries.add(executorService.submit(() -> Maps.immutableEntry(rule, ruleKeyFactories.get(rule.getProjectFilesystem()).build(rule))));
}
ListenableFuture<List<Map.Entry<BuildRule, RuleKey>>> ruleKeyComputation = Futures.allAsList(ruleKeyEntries);
return Futures.transform(ruleKeyComputation, new Function<List<Map.Entry<BuildRule, RuleKey>>, ImmutableMap<BuildRule, RuleKey>>() {
@Override
public ImmutableMap<BuildRule, RuleKey> apply(List<Map.Entry<BuildRule, RuleKey>> input) {
return ImmutableMap.copyOf(input);
}
}, executorService);
}
Aggregations