DynamicTasks.queueIfPossible(task).orSubmitAndBlock().getTask().blockUntilEnded(); try { result = task.get();
@Override public void launch() { DynamicTasks.queueIfPossible(DependentConfiguration.attributeWhenReady(entity, EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER)) .orSubmitAndBlock(entity) .andWaitForSuccess(); String nodes = String.format("%s=%s", getClusterName(), getClusterUrl()); // Build etcd startup command List<String> commands = Lists.newLinkedList(); commands.add("cd " + getRunDir()); commands.add(format("%s -bind-addr 0.0.0.0:%d --proxy on --initial-cluster \"%s\" > %s 2>&1 < /dev/null &", Os.mergePathsUnix(getExpandedInstallDir(), "etcd"), getEntity().getClientPort(), nodes, getLogFileLocation())); newScript(ImmutableMap.of(USE_PID_FILE, true), LAUNCHING) .body.append(commands) .failOnNonZeroResultCode() .execute(); }
@Override public void install() { DynamicTasks.queueIfPossible(SshTasks.dontRequireTtyForSudo(getMachine(), OnFailingTask.WARN_OR_IF_DYNAMIC_FAIL_MARKING_INESSENTIAL)).orSubmitAndBlock();
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();
.build(); Boolean result = DynamicTasks.queueIfPossible(sshable) .orSubmitAndBlock() .andWaitForSuccess(); if (!result) {
.machine(getMachine()) .newTask(); DynamicTasks.queueIfPossible(task).executionContext(getEntity()).orSubmitAndBlock(); int result = task.get(); if (result != 0) throw new IllegalStateException("Error creating image directory: " + name);
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()));
@Override public void launch() { DynamicTasks.queueIfPossible(DependentConfiguration.attributeWhenReady(entity, EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER)) .orSubmitAndBlock(entity) .andWaitForSuccess();
BasicExecutionContext ec = new BasicExecutionContext(em); taskQueueingResult.executionContext(ec); taskQueueingResult.orSubmitAndBlock();
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; }
@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(); } }
private boolean installFile(InputStream contents, String destName) { String uid = Identifiers.makeRandomId(8); // TODO currently put in /tmp for staging, since run dir may not be accessible to ssh user getMachine().copyTo(contents, "/tmp/"+destName+"_"+uid); DynamicTasks.queueIfPossible(SshEffectorTasks.ssh( "cd "+getRunDir(), "mv /tmp/"+destName+"_"+uid+" "+destName, "chown postgres:postgres "+destName, "chmod 644 "+destName) .runAsRoot().requiringExitCodeZero()) .orSubmitAndBlock(getEntity()).andWaitForSuccess(); return true; } private boolean copyDatabaseCreationScript() {
/** queues the task for execution if we are in a {@link TaskQueueingContext} (e.g. EffectorTaskFactory); * or if we aren't in a queueing context, it will submit the task (assuming there is an {@link ExecutionContext} * _and_ block until completion, throwing on error */ @Beta public Task<Integer> queue() { return DynamicTasks.queueIfPossible(newTask()).orSubmitAndBlock().getTask(); }
/** queues the task for execution if we are in a {@link TaskQueueingContext} (e.g. EffectorTaskFactory); * or if we aren't in a queueing context, it will submit the task (assuming there is an {@link ExecutionContext} * _and_ block until completion, throwing on error */ @Beta public Task<Integer> queue() { return DynamicTasks.queueIfPossible(newTask()).orSubmitAndBlock().getTask(); }
/** convenience for setting {@link #executionContext(ExecutionContext)} then submitting blocking */ public TaskQueueingResult<T> orSubmitAndBlock(Entity entity) { executionContext(entity); return orSubmitAndBlock(); } /** blocks for the task to be completed