/** * Returns a queued {@link Task} which stops iptables on the given machine. */ public Task<Void> stopIptablesAsync(final SshMachineLocation machine) { return DynamicTasks.queue("stop iptables", new Runnable() { @Override public void run() { stopIptablesImpl(machine); } }); }
/** @see #queueIfPossible(TaskAdaptable) */ public static <T> TaskQueueingResult<T> queueIfPossible(TaskFactory<? extends TaskAdaptable<T>> task) { return queueIfPossible(task.newTask()); }
/** * Submits the task to the ExecutionManager and then waits until the task has completed. * * @param taskAdaptable the TaskAdaptable to submit for execution. */ private void submitTaskAndWait(final TaskAdaptable<?> taskAdaptable) { // Submit the task to the ExecutionManager. DynamicTasks.queue(taskAdaptable); // Block until the task has completed. This will also throw if anything went wrong. DynamicTasks.waitForLast(); }
@Override public String call() { DynamicTasks.markInessential(); stopProcessesAtMachine(); DynamicTasks.waitForLast(); return "Stop processes completed with no errors."; } }
/** As {@link #drain(Duration, boolean)} waiting forever and throwing the first error * (excluding errors in inessential tasks), * then returning the last task in the queue (which is guaranteed to have finished without error, * if this method returns without throwing) */ public static Task<?> waitForLast() { drain(null, true); // this call to last is safe, as the above guarantees everything will have run // (on errors the above will throw so we won't come here) List<Task<?>> q = DynamicTasks.getTaskQueuingContext().getQueue(); return q.isEmpty() ? null : Iterables.getLast(q); }
"/bin/"); DynamicTasks.queueIfPossible(SshTasks.dontRequireTtyForSudo(getMachine(), DynamicTasks.waitForLast(); if (DynamicTasks.queue(SshEffectorTasks.ssh(sudoAsUser("postgres", "ls "+getInstallDir())).allowingNonZeroExitCode() .summary("check postgres user can access install dir")).asTask().getUnchecked()!=0) { log.info("Postgres install dir "+getInstallDir()+" for "+getEntity()+" is not accessible to user 'postgres'; " + "using "+altInstallDir+" instead"); String newRunDir = Urls.mergePaths(altTarget, "apps", getEntity().getApplication().getId(), getEntity().getId()); if (DynamicTasks.queue(SshEffectorTasks.ssh("ls "+altInstallDir+"/pg_ctl").allowingNonZeroExitCode() .summary("check whether "+altInstallDir+" is set up")).asTask().getUnchecked()==0) { DynamicTasks.queue(SshEffectorTasks.ssh( "mkdir -p "+altInstallDir, "rm -rf '"+altInstallDir+"'", .summary("move install dir from user to postgres owned space")); DynamicTasks.waitForLast(); setInstallDir(altInstallDir); setRunDir(newRunDir);
@Override protected String startProcessesAtMachine(Supplier<MachineLocation> machineS) { DynamicTasks.queueIfPossible(StartableMethods.startingChildren(entity(), machineS.get())) .orSubmitAsync(entity()) .getTask() .getUnchecked(); DynamicTasks.waitForLast(); return "children started"; }
StopMode stopProcessMode = parameters.get(StopSoftwareParameters.STOP_PROCESS_MODE); DynamicTasks.queue("pre-stop", new PreStopCustomTask()); Tasks.create("stopping (process)", new StopProcessesAtMachineTask()), Tasks.create("stopping (feeds)", new StopFeedsAtMachineTask())); DynamicTasks.queue(stoppingProcess); .body(stopTask).flags(stopMachineFlags) .build(); stoppingMachine = DynamicTasks.queue(stopMachineTask); DynamicTasks.drain(entity().getConfig(STOP_PROCESS_TIMEOUT), false); DynamicTasks.waitForLast(); if (machine.isPresent()) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPED); DynamicTasks.queue("post-stop", new PostStopCustomTask());
@Override public void undeploy(String targetName) { checkNotNull(targetName, "targetName"); targetName = FILENAME_TO_WEB_CONTEXT_MAPPER.convertDeploymentTargetNameToContext(targetName); // set it up so future nodes get the right wars if (!removeFromWarsByContext(this, targetName)) { DynamicTasks.submit(Tasks.warning("Context "+targetName+" not known at "+this+"; attempting to undeploy regardless", null), this); } log.debug("Undeploying "+targetName+" across cluster "+this+"; WARs now "+getConfig(WARS_BY_CONTEXT)); Iterable<CanDeployAndUndeploy> targets = Iterables.filter(getChildren(), CanDeployAndUndeploy.class); TaskBuilder<Void> tb = Tasks.<Void>builder().parallel(true).displayName("Undeploy "+targetName+" across cluster (size "+Iterables.size(targets)+")"); for (Entity target: targets) { tb.add(whenServiceUp(target, Effectors.invocation(target, UNDEPLOY, MutableMap.of("targetName", targetName)), "Undeploy "+targetName+" at "+target+" when ready")); } DynamicTasks.queueIfPossible(tb.build()).orSubmitAsync(this).asTask().getUnchecked(); // Update attribute Set<String> deployedWars = MutableSet.copyOf(getAttribute(DEPLOYED_WARS)); deployedWars.remove( FILENAME_TO_WEB_CONTEXT_MAPPER.convertDeploymentTargetNameToContext(targetName) ); sensors().set(DEPLOYED_WARS, deployedWars); }
/** see {@link DynamicTasks#waitForLast()} */ protected Task<?> waitForLast() { return DynamicTasks.waitForLast(); }
public static void stopSequentially(Iterable<? extends Startable> entities) { List<Exception> exceptions = Lists.newArrayList(); List<Startable> failedEntities = Lists.newArrayList(); for (final Startable entity : entities) { if (!Entities.isManaged((Entity)entity)) { log.debug("Not stopping {} because it is not managed; continuing", entity); continue; } try { TaskAdaptable<Void> task = TaskTags.markInessential(Effectors.invocation((Entity)entity, Startable.STOP, Collections.emptyMap())); DynamicTasks.submit(task, (Entity)entity).getUnchecked(); } catch (Exception e) { log.warn("Error stopping "+entity+"; continuing with shutdown", e); exceptions.add(e); failedEntities.add(entity); } } if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error stopping "+(failedEntities.size() > 1 ? "entities" : "entity")+": "+failedEntities, exceptions); } }
@Override public T call() { return DynamicTasks.get(t); } }).build());
@Override public void close() { DynamicTasks.drain(null, false); releaseableLatch.release(caller); } }
@Override public String call() { DynamicTasks.markInessential(); stop(ConfigBag.newInstance().configure(StopSoftwareParameters.STOP_MACHINE_MODE, StopMode.IF_NOT_STOPPED)); DynamicTasks.waitForLast(); return "Stop of machine completed with no errors."; } }
/** runs the tasks needed to start, wrapped by setting {@link Attributes#SERVICE_STATE_EXPECTED} appropriately */ public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING); try { startInLocations(locations); DynamicTasks.waitForLast(); ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING); } catch (Throwable t) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.ON_FIRE); throw Exceptions.propagate(t); } }
protected void onServerPoolMemberChanged(final Entity member) { LOG.debug("For {}, considering membership of {} which is in locations {}", new Object[]{ this, member, member.getLocations() }); Map<Entity, String> nodes = MutableMap.copyOf(sensors().get(ETCD_CLUSTER_NODES)); Duration timeout = config().get(BrooklynConfigKeys.START_TIMEOUT); Entity firstNode = AbstractGroup.getFirst(this); if (belongsInServerPool(member) && !nodes.containsKey(member)) { EtcdNode node = (EtcdNode) member; String name = Preconditions.checkNotNull(node.getNodeName()); // Ensure etcd has been installed Task<Boolean> installed = DynamicTasks.submit(DependentConfiguration.attributeWhenReady(member, EtcdNode.ETCD_NODE_INSTALLED), this).asTask(); if (installed.blockUntilEnded(timeout) && installed.getUnchecked()) { // Check if we are first node in the cluster. if (node.equals(firstNode)) { addNode(node, name); } else { // Add node asynchronously Callable<Void> joinCluster = new JoinCluster(firstNode, node, name, timeout); DynamicTasks.submit(Tasks.create("Joining etcd cluster", joinCluster), this); } } } }
@Override public Integer call() { return DynamicTasks.get(x)*y; } }).build();
/** queues the task if possible, otherwise submits it asynchronously; returns the task for callers to * {@link Task#getUnchecked()} or {@link Task#blockUntilEnded()} */ public static <T> Task<T> submit(TaskAdaptable<T> task, Entity entity) { return queueIfPossible(task).orSubmitAsync(entity).asTask(); }
private Result executeDownloadedScript(SshMachineLocation machineLocation, String url, String scriptPath, Map<String, String> env) { TaskFactory<?> install = SshTasks.installFromUrl(ImmutableMap.<String, Object>of(), machineLocation, url, scriptPath); DynamicTasks.queue(install); DynamicTasks.waitForLast(); List<String> commands = ImmutableList.<String>builder() .add("chmod u+x " + scriptPath) .addAll(maybeCdToRunDirCmd()) .add(scriptPath) .build(); return runCommands(machineLocation, commands, env); }