@Override public void run() { String oldDetails = Tasks.setBlockingDetails(description); LOG.debug("{} acquiring permit from {}", this, permit); try { permit.acquire(); hasObtainedPermit.set(true); } catch (InterruptedException e) { throw Exceptions.propagate(e); } finally { Tasks.setBlockingDetails(oldDetails); } } }
@Override public void acquireMutex(String mutexId, String description) throws InterruptedException { SemaphoreWithOwners s = getSemaphore(mutexId, true); if (description!=null) Tasks.setBlockingDetails(description+" - waiting for "+mutexId); if (log.isDebugEnabled()) log.debug("Acquiring mutex: "+mutexId+"@"+this+" - "+description); s.acquire(); if (description!=null) Tasks.setBlockingDetails(null); s.setDescription(description); if (log.isDebugEnabled()) log.debug("Acquired mutex: "+mutexId+"@"+this+" - "+description); }
@Override public Object call() throws Exception { try { Tasks.setBlockingDetails("Retrieving "+ds); return ds.get(); } finally { Tasks.resetBlockingDetails(); } } }; String description = getDescription();
protected void copyResources(String destinationParentDir, Map<String, String> files, Map<String, String> templates) { if (files == null) files = Collections.emptyMap(); if (templates == null) templates = Collections.emptyMap(); final List<TaskAdaptable<?>> tasks = new ArrayList<>(files.size() + templates.size()); applyFnToResourcesAppendToList(files, newCopyResourceFunction(), destinationParentDir, tasks); applyFnToResourcesAppendToList(templates, newCopyTemplateFunction(), destinationParentDir, tasks); if (!tasks.isEmpty()) { String oldBlockingDetails = Tasks.setBlockingDetails("Copying resources"); try { DynamicTasks.queue(Tasks.sequential(tasks)).getUnchecked(); } finally { Tasks.setBlockingDetails(oldBlockingDetails); } } }
@Override public int copyResource(Map<Object, Object> sshFlags, String source, String target, boolean createParentDir) { if (createParentDir) { createDirectory(getDirectory(target), "Creating resource directory"); } InputStream stream = null; try { Tasks.setBlockingDetails("retrieving resource "+source+" for copying across"); stream = resource.getResourceFromUrl(source); Tasks.setBlockingDetails("copying resource "+source+" to server"); return copyTo(stream, target); } catch (Exception e) { throw Exceptions.propagate(e); } finally { Tasks.setBlockingDetails(null); if (stream != null) Streams.closeQuietly(stream); } }
/** {@inheritDoc} */ @Override public String deployArchive(String url) { Tasks.setBlockingDetails("Deploy " + url); try { return getDriver().deployArchive(url); } finally { Tasks.resetBlockingDetails(); } }
String prevBlockingDetails = Tasks.setBlockingDetails("copying resource to server at "+destination); try { result = getMachine().copyTo(flags, source, destination); } finally { Tasks.setBlockingDetails(prevBlockingDetails);
@Override public Void call() throws Exception { log.info("beginning spawned child response "+Tasks.current()+", with tags "+Tasks.current().getTags()); Tasks.setBlockingDetails("spawned child blocking details"); nowWaitingLatch.countDown(); if (!continueFromWaitingLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) { fail("took too long to be told to continue"); } return null; }}); }
@Override protected synchronized void onRequesting() { if (!owningTasks.isEmpty() || !requestingTasks.isEmpty()) { Tasks.setBlockingTask( !requestingTasks.isEmpty() ? Iterables.getLast(requestingTasks) : Iterables.getFirst(owningTasks, null) ); Tasks.setBlockingDetails("Waiting on semaphore "+getName()+" ("+getDescription()+"); " + "queued at "+Time.makeDateString()+" when "+getRequestingThreads().size()+" ahead in queue"); } requestingTasks.addIfNotNull(Tasks.current()); super.onRequesting(); }
public void apply(final Entity source, final Object valueIgnored) { T val = (T) attribute.getValue(); if (!readiness.apply(val)) { log.warn("Skipping {} for {} because attribute {} not ready", new Object[]{description, attribute.getEntity(), attribute.getAttribute()}); return; } final Task<Void> task = TaskBuilder.<Void>builder().displayName(description).body(runnable).build(); DynamicTasks.queueIfPossible(task).orSubmitAsync(source).asTask(); if (blockUntilEnded) { final String originalBlock = Tasks.setBlockingDetails(description); try { task.blockUntilEnded(); } finally { Tasks.setBlockingDetails(originalBlock); } } } }
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); }
Tasks.setBlockingDetails("Copying keystore and truststore to the server."); try { jmxSupport.getMachine().get().copyTo(new ByteArrayInputStream(agentKeyStoreBytes.toByteArray()), getJmxSslKeyStoreFilePath());
@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; } }
/** 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); }
Tasks.setBlockingDetails("Waiting for access to Docker hosts for placement"); acquireMutex(entity.getApplicationId(), "Filtering locations for " + entity); } catch (InterruptedException ie) {
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(); } }
final String msg = String.format("deploying %s to %s:%s", new Object[]{url, getHostname(), dest}); log.info(entity + " " + msg); Tasks.setBlockingDetails(msg); try { final String copyTaskMsg = String.format("copying %s to %s:%s", new Object[]{url, getHostname(), tmpDest});
@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(); } }