@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(); } };
/** creates the TaskBuilder which can be further customized; typically invoked by the initial {@link #newTask()} */ public TaskBuilder<Object> constructCustomizedTaskBuilder() { TaskBuilder<Object> tb = TaskBuilder.builder().dynamic(false).displayName("ssh: "+getSummary()); tb.tag(BrooklynTaskTags.tagForStream(BrooklynTaskTags.STREAM_STDIN, Streams.byteArrayOfString(Strings.join(commands, "\n")))); tb.tag(BrooklynTaskTags.tagForEnvStream(BrooklynTaskTags.STREAM_ENV, shellEnvironment)); return tb; }
private static Task<List<?>> sequentialInternal(String name, Task<?>[] tasks) { return Tasks.<List<?>>builder().displayName(name).parallel(false).add(tasks).build(); } private static TaskFactory<?> sequentialInternal(final String name, final TaskFactory<?> ...taskFactories) {
public static <T> Task<T> create(String name, Callable<T> job) { return Tasks.<T>builder().displayName(name).body(job).build(); } public static <T> Task<T> create(String name, Runnable job) {
@Test public void testTaskBuilderUsingAddVarargChildren() { Task<String> t = Tasks.<String>builder().dynamic(true) .body(monitorableJob("main")) .add(monitorableTask("1"), monitorableTask("2")) .build(); ec.submit(t); releaseAndWaitForMonitorableJob("1"); releaseAndWaitForMonitorableJob("2"); releaseAndWaitForMonitorableJob("main"); Assert.assertEquals(messages, MutableList.of("1", "2", "main")); }
/** * 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); }
childrenCountString = size+" "+(size!=1 ? "children" : "child"); TaskBuilder<List<String>> taskM = Tasks.<List<String>>builder().displayName("add children") .dynamic(true) .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG) .body(new Callable<List<String>>() { @Override public List<String> call() throws Exception { 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"); taskS.add(Effectors.invocation(child, Startable.START, ImmutableMap.of("locations", ImmutableList.of()))); } else { taskS.add(Tasks.builder().displayName("create").description("Skipping start (not a Startable Entity)") .body(Runnables.doNothing()) .tag(BrooklynTaskTags.tagForTargetEntity(child)) .build()); taskM.add(taskS.build()); Task<List<String>> task = Entities.submit(parent, taskM.build());
final String launchScriptPath = Urls.mergePaths(getRunDir(), getStartScriptName()); Task<Void> installerTask = TaskBuilder.<Void>builder() .displayName("install (service)") .description("Install as a system service") .body(new Runnable() { @Override public void run() { .build(); .requiringExitCodeZero() .newTask(); Task<Void> udpateTask = TaskBuilder.<Void>builder() .displayName("update-launch") .description("Update launch script used by the system service") .add(updateLaunchScriptTask) .add(makeExecutableTask) .build(); Task<Void> updateService = TaskBuilder.<Void>builder() .displayName("update-system-service") .description("Update system service") .add(installerTask) .add(udpateTask) .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG) .build();
tasks.add(builder.build()); final Task<List<V>> parallelTask = Tasks.<List<V>>builder().parallel(true).addAll(tasks) .displayName(name) .description(descriptionBase+ (builder.timeout!=null ? ", timeout "+builder.timeout : "")) .build(); return Tasks.<V2>builder().displayName(name).description(descriptionBase) .tag("attributeWhenReady") .body(new Callable<V2>() { @Override public V2 call() throws Exception { List<V> prePostProgress = DynamicTasks.queue(parallelTask).get(); .build();
DynamicTasks.queue(Tasks.builder().displayName("shutdown node") .add(Effectors.invocation(entity(), BrooklynNode.STOP_NODE_BUT_LEAVE_APPS, ImmutableMap.of(StopSoftwareParameters.STOP_MACHINE_MODE, StopMode.NEVER))) .build()); DynamicTasks.queue(Tasks.builder().displayName("backup old version").body(new Runnable() { @Override public void run() { }).build()); DynamicTasks.queue(Tasks.builder().displayName("reconfigure").body(new Runnable() { @Override public void run() { }).build());
@Test public void testIsEffector() throws Exception { Task<?> task = app.invoke(TestApplication.START, ImmutableMap.of("locations", ImmutableList.<Location>of())); Task<?> otherTask = execManager.submit(TaskBuilder.<Object>builder() .body(Callables.<Object>returning("val")) .build()); assertTrue(TaskPredicates.isEffector().apply(task)); assertFalse(TaskPredicates.isEffector().apply(otherTask)); }
@SuppressWarnings("unchecked") protected ProcessTaskWrapper(AbstractProcessTaskFactory<?,RET> constructor) { super(constructor); TaskBuilder<Object> tb = constructor.constructCustomizedTaskBuilder(); if (stdout!=null) tb.tag(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDOUT, stdout)); if (stderr!=null) tb.tag(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDERR, stderr)); task = (Task<RET>) tb.body(new ProcessTaskInternalJob()).build(); }
.description("Add JMX feed") .body(new Callable<JmxFeed>() { @Override public JmxFeed call() throws Exception { .build(); DynamicTasks.submit(Tasks.sequential("Add JMX Sensor " + sensor.getName(), jmxPortTask, jmxFeedTask), entity); } else {
@Test public void testInvokeEffectorStartFailing_MethodInTask() { Task<Void> task = app.getExecutionContext().submit(Tasks.<Void>builder().dynamic(false).body(new Callable<Void>() { @Override public Void call() throws Exception { testInvokeEffectorStartFailing_Method(); return null; } }).build()); assertTaskSucceeds(task); }
/** @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()); }
@Override public TaskAdaptable<?> newTask() { TaskBuilder<Void> tb = Tasks.<Void>builder().displayName("install cookbook "+cookbookName); log.debug("Assuming TGZ type for chef cookbook url "+cookbookArchiveUrl+"; it will be downloaded as "+destName); tb.add(ArchiveTasks.deploy(null, null, cookbookArchiveUrl, EffectorTasks.findSshMachine(), privateTmpDirContainingUnpackedCookbook, false, null, destName).newTask()); tb.add(SshEffectorTasks.ssh(installCmd).summary("renaming cookbook dir").requiringExitCodeZero().newTask()); return tb.build();
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected <T> Task<T> runAtEntity(Map flags, Entity entity, Callable<T> c) { manageIfNecessary(entity, elvis(Arrays.asList(flags.get("displayName"), flags.get("description"), flags, c))); return runAtEntity(entity, Tasks.<T>builder().dynamic(true).body(c).flags(flags).build()); }
public static TaskFactory<?> installCookbooks(final String chefDirectory, final Map<String,String> cookbooksAndUrls, final boolean force) { return Tasks.<Void>builder().displayName("install "+(cookbooksAndUrls==null ? "0" : cookbooksAndUrls.size())+" cookbook"+Strings.s(cookbooksAndUrls)).body( new Runnable() { @Override public void run() { Entity e = EffectorTasks.findEntity(); if (cookbooksAndUrls==null) throw new IllegalStateException("No cookbooks defined to install at "+e); for (String cookbook: cookbooksAndUrls.keySet()) DynamicTasks.queue(installCookbook(chefDirectory, cookbook, cookbooksAndUrls.get(cookbook), force)); } }).buildFactory(); }
.displayName("install (init.d)") .description("Install init.d service") .add(putServiceTask) .add(installServiceTask) .build();