@Override public Object call() throws Exception { try { Tasks.setBlockingDetails("Retrieving "+ds); return ds.get(); } finally { Tasks.resetBlockingDetails(); } } }; String description = getDescription();
/** {@inheritDoc} */ @Override public String deployArchive(String url) { Tasks.setBlockingDetails("Deploy " + url); try { return getDriver().deployArchive(url); } finally { Tasks.resetBlockingDetails(); } }
@Override protected synchronized void onRequestFinished() { super.onRequestFinished(); requestingTasks.removeIfNotNull(Tasks.current()); Tasks.resetBlockingDetails(); Tasks.resetBlockingTask(); }
public static int install(ResourceUtils resolver, Map<String, ?> props, SshMachineLocation machine, String urlToInstall, String target, int numAttempts) { if (resolver==null) resolver = ResourceUtils.create(machine); Exception lastError = null; int retriesRemaining = numAttempts; int attemptNum = 0; do { attemptNum++; try { Tasks.setBlockingDetails("Installing "+urlToInstall+" at "+machine); // TODO would be nice to have this in a task (and the things within it!) return machine.installTo(resolver, props, urlToInstall, target); } catch (Exception e) { Exceptions.propagateIfFatal(e); lastError = e; String stack = StackTraceSimplifier.toString(e); if (stack.contains("net.schmizz.sshj.sftp.RemoteFile.write")) { log.warn("Failed to transfer "+urlToInstall+" to "+machine+", retryable error, attempt "+attemptNum+"/"+numAttempts+": "+e); continue; } log.warn("Failed to transfer "+urlToInstall+" to "+machine+", not a retryable error so failing: "+e); throw Exceptions.propagate(e); } finally { Tasks.resetBlockingDetails(); } } while (retriesRemaining --> 0); throw Exceptions.propagate(lastError); }
jmxSupport.getMachine().get().copyTo(new ByteArrayInputStream(agentTrustStoreBytes.toByteArray()), getJmxSslTrustStoreFilePath()); } finally { Tasks.resetBlockingDetails();
/** Waits until the passed entity satisfies the supplied predicate. */ public static void waitFor(Entity entity, Predicate<Entity> condition, Duration timeout) { try { String description = "Waiting for " + condition + " on " + entity; Tasks.setBlockingDetails(description); Repeater repeater = Repeater.create(description) .until(isSatisfied(entity, condition)) .limitTimeTo(timeout) .backoffTo(Duration.ONE_SECOND) .rethrowException(); if (!repeater.run()) { throw new IllegalStateException("Timeout waiting for " + condition + " on " + entity); } } finally { Tasks.resetBlockingDetails(); } log.debug("Detected {} for {}", condition, entity); }
@Override public Boolean call() { ReferenceWithError<Boolean> result; Tasks.setBlockingDetails(repeater.getDescription()); try { result = repeater.runKeepingError(); } finally { Tasks.resetBlockingDetails(); } if (Boolean.TRUE.equals(result.getWithoutError())) return true; if (result.hasError()) throw Exceptions.propagate(result.getError()); if (requireTrue) throw new IllegalStateException("timeout - "+repeater.getDescription()); return false; } }
Tasks.resetBlockingDetails(); TaskTags.markInessential(task); DynamicTasks.queue(task); Tasks.resetBlockingDetails();
private static ReleaseableLatch waitForLatch(EntityInternal entity, ConfigKey<Boolean> configKey) { Maybe<?> rawValue = entity.config().getRaw(configKey); if (rawValue.isAbsent()) { return ReleaseableLatch.NOP; } else { ValueResolverIterator<Boolean> iter = resolveLatchIterator(entity, rawValue.get(), configKey); // The iterator is used to prevent coercion; the value should always be the last one, but iter.last() will return a coerced Boolean Maybe<ReleaseableLatch> releasableLatchMaybe = iter.next(ReleaseableLatch.class); if (releasableLatchMaybe.isPresent()) { ReleaseableLatch latch = releasableLatchMaybe.get(); log.debug("{} finished waiting for {} (value {}); waiting to acquire the latch", new Object[] {entity, configKey, latch}); Tasks.setBlockingDetails("Acquiring " + configKey + " " + latch); try { latch.acquire(entity); } finally { Tasks.resetBlockingDetails(); } log.debug("{} Acquired latch {} (value {}); continuing...", new Object[] {entity, configKey, latch}); return latch; } else { // If iter.next() above returned absent due to a resolve error next line will throw with the cause Boolean val = iter.last().get(); if (rawValue != null) log.debug("{} finished waiting for {} (value {}); continuing...", new Object[] {entity, configKey, val}); return ReleaseableLatch.NOP; } } }
/** installs files needed for JMX, to the runDir given in constructor, assuming the runDir has been created */ public void install() { if (EnumSet.of(JmxAgentModes.JMXMP_AND_RMI, JmxAgentModes.JMXMP, JmxAgentModes.JMX_RMI_CUSTOM_AGENT).contains(getJmxAgentMode())) { Tasks.setBlockingDetails("Copying JMX agent jar to server."); try { getMachine().get().copyTo(ResourceUtils.create(this).getResourceFromUrl( getJmxAgentJarUrl()), getJmxAgentJarDestinationFilePath()); } finally { Tasks.resetBlockingDetails(); } } if (isSecure()) { getJmxSslSupport().install(); } }
v = ((DeferredSupplier<?>) ds).get(); } finally { Tasks.resetBlockingDetails();
@Override public void stop() { sensors().set(SERVICE_UP, Boolean.FALSE); synchronized (this) { try { Tasks.setBlockingDetails("Waiting until all containers are disconnected from " + sensors().get(NETWORK_ID)); Task<?> waiting = DependentConfiguration.attributeWhenReady(this, CONNECTED_CONTAINERS, new Predicate<Set>() { @Override public boolean apply(Set input) { return input.isEmpty(); } }); Task<?> task = DynamicTasks.queueIfPossible(waiting).orSubmitAndBlock(this).asTask(); task.get(Duration.FIVE_MINUTES); } catch (InterruptedException | ExecutionException | TimeoutException e) { LOG.error("Error waiting for containers to disconnect", e); throw Exceptions.propagate(e); } finally { Tasks.resetBlockingDetails(); } // If task is still blocking we would never be able to delete the network NetworkProvisioningExtension provisioner = sensors().get(NETWORK_PROVISIONER); if (provisioner != null) { provisioner.deallocateNetwork(this); } super.stop(); } }
protected MachineDetails inferMachineDetails() { boolean detectionEnabled = getConfig(DETECT_MACHINE_DETAILS); if (!detectionEnabled) { return new BasicMachineDetails(new BasicHardwareDetails(-1, -1), new BasicOsDetails("UNKNOWN", "UNKNOWN", "UNKNOWN")); } else if (!isManaged()) { return new BasicMachineDetails(new BasicHardwareDetails(-1, -1), new BasicOsDetails("UNKNOWN", "UNKNOWN", "UNKNOWN")); } Tasks.setBlockingDetails("Waiting for machine details"); try { return BasicMachineDetails.forSshMachineLocationLive(this); } finally { Tasks.resetBlockingDetails(); } }