/** * Utility method that will execute the given function on the given nodes. The executions will be done in a parallel. * * @param nodes the nodes to execute the function on. * @param fn the function to execute. * @param <T> the type of node. * @return a new pool of tasks. */ // TODO: Pass the task's name and description as parameter protected <T> Task<List<?>> parallelListenerTask(final Iterable<T> nodes, final Function<T, ?> fn) { List<Task<?>> tasks = Lists.newArrayList(); for (final T node : nodes) { Task<?> t = Tasks.builder() .name(node.toString()) .description("Invocation on " + node.toString()) .body(new FunctionRunningCallable<T>(node, fn)) .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG) .build(); tasks.add(t); } return Tasks.parallel("Parallel invocation of " + fn + " on ambari nodes", tasks); }
@Override public TaskAdaptable<?> newTask() { return Tasks.<Void>builder().displayName("installing "+Urls.getBasename(url)).description("installing "+url+" to "+destPath).body(new Runnable() { @Override public void run() { int result = location.installTo(utils, props, url, destPath); if (result!=0) throw new IllegalStateException("Failed to install '"+url+"' to '"+destPath+"' at "+location+": exit code "+result); } }).build(); } };
/** * Utility method that will execute the given function on the given nodes, only if they have one of the given components * installed on them. The executions will be done in a parallel. * @param nodes the nodes to execute the function on. * @param fn the function to execute. * @param components the list of components for which we want to function to be executed. * @return a new pool of tasks. */ // TODO: Pass the task's name and description as parameter protected Task<List<?>> parallelListenerTask(final Iterable<AmbariAgent> nodes, final Function<AmbariAgent, ?> fn, List<String> components) { Preconditions.checkNotNull(components); List<Task<?>> tasks = Lists.newArrayList(); for (final AmbariAgent ambariAgent : nodes) { Preconditions.checkNotNull(ambariAgent.getAttribute(AmbariAgent.COMPONENTS)); if (!CollectionUtils.containsAny(ambariAgent.getAttribute(AmbariAgent.COMPONENTS), components)) { continue; } Task<?> t = Tasks.builder() .name(ambariAgent.toString()) .description("Invocation on " + ambariAgent.toString()) .body(new FunctionRunningCallable<AmbariAgent>(ambariAgent, fn)) .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG) .build(); tasks.add(t); } return Tasks.parallel("Parallel invocation of " + fn + " on ambari agents", tasks); } }
@Override public TaskAdaptable<?> newTask() { return Tasks.<Void>builder().displayName("deploying "+Urls.getBasename(archiveUrl)).description("installing "+archiveUrl+" and unpacking to "+destDir).body(new Runnable() { @Override public void run() { boolean unpacked = ArchiveUtils.deploy(resolver, props, archiveUrl, machine, destDir, allowNonarchivesOrKeepArchiveAfterDeploy, optionalTmpDir, optionalDestFile); if (!unpacked && !allowNonarchivesOrKeepArchiveAfterDeploy) { throw new IllegalStateException("Unable to unpack archive from "+archiveUrl+"; not able to infer archive type"); } } }).build(); } };
@Override public Task<?> call() { return Tasks.builder().dynamic(false).body(job).displayName("HA poller task").tag(BrooklynTaskTags.TRANSIENT_TASK_TAG) .description("polls HA status to see whether this node should promote").build(); } };
/** @return a {@link TaskBuilder} which tests whether the repeater terminates with success in its configured timeframe, * returning true or false depending on whether repeater succeed */ public static TaskBuilder<Boolean> testing(Repeater repeater) { return Tasks.<Boolean>builder().body(new WaitForRepeaterCallable(repeater, false)) .displayName("waiting for condition") .description("Testing whether " + getTimeoutString(repeater) + ": "+repeater.getDescription()); }
.description("Add JMX feed") .body(new Callable<JmxFeed>() { @Override
/** @return a {@link TaskBuilder} which requires that the repeater terminate with success in its configured timeframe, * throwing if it does not */ public static TaskBuilder<?> requiring(Repeater repeater) { return Tasks.<Boolean>builder().body(new WaitForRepeaterCallable(repeater, true)) .displayName("waiting for condition") .description("Requiring " + getTimeoutString(repeater) + ": " + repeater.getDescription()); }
private Task<List<?>> createParallelTask(String taskName, final Function<ExtraService, ?> fn) { List<Task<?>> tasks = Lists.newArrayList(); for (final ExtraService extraService : getExtraServices()) { Task<?> t = Tasks.builder() .name(extraService.getEntityType().getSimpleName()) .description("pre-cluster-deploy tasks for " + extraService.getEntityType().getName() + " extra service") .body(new FunctionRunningCallable<ExtraService>(extraService, fn)) .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG) .build(); tasks.add(t); } return Tasks.parallel(taskName, tasks); }
.description("Auto-scaler recommending resize from "+currentPoolSize+" to "+targetPoolSize) .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG) .body(new Callable<Void>() {
private static <T> Task<T> newGoneTaskFor(Task<?> task) { Task<T> t = Tasks.<T>builder().dynamic(false).displayName(task.getDisplayName()) .description("Details of the original task "+task+" have been forgotten.") .body(Callables.returning((T)null)).build(); ((BasicTask<T>)t).ignoreIfNotRun(); return t; }
@Override public V2 call() throws Exception { List<V> prePostProgress = DynamicTasks.queue(parallelTask).get(); return DynamicTasks.queue( Tasks.<V2>builder().displayName("post-processing").description("Applying "+postProcessFromMultiple) .body(Functionals.callable(postProcessFromMultiple, prePostProgress)) .build()).get(); } })
return ImmutableList.copyOf(Iterables.transform(children, EntityFunctions.id())); }}) .description("Add and start "+childrenCountString); TaskBuilder<?> taskS = Tasks.builder().parallel(true).displayName("add (parallel)").description("Start each new entity"); } else { taskS.add(Tasks.builder().displayName("create").description("Skipping start (not a Startable Entity)") .body(Runnables.doNothing()) .tag(BrooklynTaskTags.tagForTargetEntity(child))
.description(descriptionBase+ (builder.timeout!=null ? ", timeout "+builder.timeout : "")) .build(); return Tasks.<V2>builder().displayName(name).description(descriptionBase) .tag("attributeWhenReady") .body(new Callable<V2>() {
} else if (x<0.6) { final Duration time = Duration.millis(Math.round(10*1000*random.nextDouble()*random.nextDouble()*random.nextDouble()*random.nextDouble()*random.nextDouble())); t.displayName("sleep").description("Sleeping "+time).body(new Callable<Object>() { public Object call() { Tasks.setBlockingDetails("sleeping "+time); Time.sleep(time);
public Task<V> build() { validate(); return Tasks.<V>builder().dynamic(false) .displayName("waiting on "+sensor.getName()) .description("Waiting on sensor "+sensor.getName()+" from "+source) .tag("attributeWhenReady") .tag(BrooklynTaskTags.TRANSIENT_TASK_TAG) .body(new WaitInTaskForAttributeReady<T,V>(this)) .build(); }
/** * For resolving a {@link StructuredConfigKey}, such as a {@link MapConfigKey}. Here we need to * execute the custom logic, as is done by {@link #get(ConfigKey)}, but non-blocking! */ protected <T> Maybe<T> getNonBlockingResolvingStructuredKey(final ConfigKey<T> key) { Callable<T> job = new Callable<T>() { @Override public T call() { try { return get(key); } catch (RuntimeInterruptedException e) { throw Exceptions.propagate(e); // expected; return gracefully } } }; Task<T> t = Tasks.<T>builder().body(job) .displayName("Resolving dependent value") .description("Resolving "+key.getName()) .tag(BrooklynTaskTags.TRANSIENT_TASK_TAG) .build(); try { return getContext().getImmediately(t); } catch (ImmediateUnsupportedException e) { return Maybe.absent(); } }
} else { Task<?> obtainMutex = Tasks.builder() .description(description) .body(new ObtainPermit(getChildTaskSemaphore(), description, permitObtained)) .build();
try { Entities.submit(entity, Tasks.<Void>builder().displayName("Effector-invoker") .description("Invoke in task") .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG) .body(new Callable<Void>() {
.description("Install init.d service") .add(putServiceTask) .add(installServiceTask)