@Override public void install() { DynamicTasks.queueIfPossible(SshTasks.dontRequireTtyForSudo(getMachine(), OnFailingTask.WARN_OR_IF_DYNAMIC_FAIL_MARKING_INESSENTIAL)).orSubmitAndBlock();
tasks); TaskTags.markInessential(invoke); return DynamicTasks.queueIfPossible(invoke).orSubmitAsync(callingEntity).asTask();
.machine(getMachine()) .newTask(); DynamicTasks.queueIfPossible(task).executionContext(getEntity()).orSubmitAndBlock(); int result = task.get(); if (result != 0) throw new IllegalStateException("Error creating image directory: " + name);
DynamicTasks.queueIfPossible( SshEffectorTasks.ssh(cmd).summary("Bespoke BrooklynNode customization script") .requiringExitCodeZero() ) .orSubmitAndBlock(getEntity());
DynamicTasks.queueIfPossible(running).orSubmitAndBlock(this).asTask().getUnchecked(Duration.FIVE_MINUTES); Task<?> hostname = DependentConfiguration.attributeWhenReady(this, Attributes.HOSTNAME, Predicates.notNull()); DynamicTasks.queueIfPossible(hostname).orSubmitAndBlock(this).asTask().getUnchecked(Duration.FIVE_MINUTES); LOG.info("Task {} running on {} successfully", id, getHostname());
OnFailingTask.FAIL)).orSubmitAndBlock(); DynamicTasks.waitForLast();
DynamicTasks.queueIfPossible(parallel).orSubmitAsync(this); Map<Entity, Throwable> errors = waitForTasksOnEntityStart(tasks);
.build(); Boolean result = DynamicTasks.queueIfPossible(sshable) .orSubmitAndBlock() .andWaitForSuccess(); if (!result) { throw new IllegalStateException(format("The entity %s is not sshable after reboot (waited %s)",
.requiringExitCodeZero() .summary("initializing on-box base dir "+base).newTask(); DynamicTasks.queueIfPossible(baseTask).orSubmitAsync(entity); resolvedBase = Strings.getFragmentBetween(baseTask.block().getStdout(), "BASE_DIR_RESULT:", ":BASE_DIR_RESULT");
result = DynamicTasks.queueIfPossible(task.asTask()).orSubmitAsync(delegate).andWaitForSuccess(); } else { result = m.invoke(delegate, nonNullArgs);
@Override public void launch() { DynamicTasks.queueIfPossible(DependentConfiguration.attributeWhenReady(entity, EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER)) .orSubmitAndBlock(entity) .andWaitForSuccess();
ProcessTaskWrapper<Integer> task = SshTasks.newSshExecTaskFactory(origin, "ping -c 1 -t 1 "+hostnameTarget) .summary("checking resolution of "+hostnameTarget).allowingNonZeroExitCode().newTask(); DynamicTasks.queueIfPossible(task).orSubmitAndBlock(entity).asTask().blockUntilEnded(); if (task.asTask().isError()) { log.warn("ping could not be run, at "+entity+" / "+origin+": "+Tasks.getError(task.asTask()));
DynamicTasks.queueIfPossible(invoke).orSubmitAsync(); try { invoke.get();
BasicExecutionManager em = new BasicExecutionManager("tests"); BasicExecutionContext ec = new BasicExecutionContext(em); taskQueueingResult.executionContext(ec); taskQueueingResult.orSubmitAndBlock();
@Override public void expungeMembers(boolean stopFirst) { Set<Entity> members = ImmutableSet.copyOf(getMembers()); RuntimeException exception = null; if (stopFirst) { Map<Entity, Task<?>> tasks = Maps.newLinkedHashMap(); for (Entity member : members) { if (member instanceof Startable) { Task<Void> task = Effectors.invocation(member, Startable.STOP, ImmutableMap.of()).asTask(); tasks.put(member, task); } } DynamicTasks.queueIfPossible(Tasks.parallel("stopping "+tasks.size()+" member"+Strings.s(tasks.size())+" (parallel)", tasks.values())).orSubmitAsync(this); try { waitForTasksOnExpungeMembers(tasks); } catch (RuntimeException e) { Exceptions.propagateIfFatal(e); exception = e; LOG.warn("Problem stopping members of quarantine group "+this+" (rethrowing after unmanaging members): "+e); } } for (Entity member : members) { removeMember(member); Entities.unmanage(member); } if (exception != null) { throw exception; } }
@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(); } }
public static final VirtualNetwork lookupNetwork(final SdnProvider provider, final String networkId) { Task<Boolean> lookup = TaskBuilder.<Boolean> builder() .displayName("Waiting until virtual network is available") .body(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return Repeater.create() .every(Duration.TEN_SECONDS) .until(new Callable<Boolean>() { public Boolean call() { Optional<Entity> found = Iterables.tryFind(provider.sensors().get(SdnProvider.SDN_NETWORKS).getMembers(), EntityPredicates.attributeEqualTo(VirtualNetwork.NETWORK_ID, networkId)); return found.isPresent(); } }) .limitTimeTo(Duration.ONE_MINUTE) .run(); } }) .build(); Boolean result = DynamicTasks.queueIfPossible(lookup) .orSubmitAndBlock() .andWaitForSuccess(); if (!result) { throw new IllegalStateException(String.format("Cannot find virtual network entity for %s", networkId)); } VirtualNetwork network = (VirtualNetwork) Iterables.find(provider.sensors().get(SdnProvider.SDN_NETWORKS).getMembers(), EntityPredicates.attributeEqualTo(VirtualNetwork.NETWORK_ID, networkId)); return network; }
DynamicTasks.queueIfPossible(task).orSubmitAndBlock().getTask().blockUntilEnded(); try { result = task.get();
@Override public String execCommandTimeout(String command, Duration timeout) { AbstractSoftwareProcessSshDriver driver = (AbstractSoftwareProcessSshDriver) getDriver(); if (driver == null) { throw new NullPointerException("No driver for "+this); } ProcessTaskWrapper<String> task = SshEffectorTasks.ssh(command) .environmentVariables(driver.getShellEnvironment()) .requiringZeroAndReturningStdout() .machine(getMachine()) .summary(command) .newTask(); try { String result = DynamicTasks.queueIfPossible(task) .executionContext(this) .orSubmitAsync() .asTask() .get(timeout); return result; } catch (TimeoutException te) { throw new IllegalStateException("Timed out running command: " + command); } catch (Exception e) { Integer exitCode = task.getExitCode(); LOG.warn("Command failed, return code {}: {}", exitCode == null ? -1 : exitCode, task.getStderr()); throw Exceptions.propagate(e); } }
@Override public String execCommandTimeout(String command, Duration timeout) { ProcessTaskWrapper<String> task = SshEffectorTasks.ssh(command) .environmentVariables(((AbstractSoftwareProcessSshDriver) getDriver()).getShellEnvironment()) .configure(SshTool.PROP_ALLOCATE_PTY, true) // TODO configure globally .requiringZeroAndReturningStdout() .machine(getMachine()) .summary(command) .newTask(); try { String result = DynamicTasks.queueIfPossible(task) .executionContext(this) .orSubmitAsync() .asTask() .get(timeout); return result; } catch (TimeoutException te) { throw new IllegalStateException("Timed out running command: " + command); } catch (Exception e) { Integer exitCode = task.getExitCode(); LOG.warn("Command failed, return code {}: {}", exitCode == null ? -1 : exitCode, task.getStderr()); throw Exceptions.propagate(e); } }