@Override public Task<T> newTask() { return build(); } };
public static Task<Integer> add(final int x, final int y) { return TaskBuilder.<Integer>builder() .displayName("add") .body(new Callable<Integer>() { @Override public Integer call() { return x+y; } }).build(); }
public static Task<Integer> times(final int x, final int y) { return TaskBuilder.<Integer>builder() .displayName("times") .body(new Callable<Integer>() { @Override public Integer call() { return x*y; } }).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 Task<Integer> times(final Task<Integer> x, final int y) { return TaskBuilder.<Integer>builder() .displayName("times") .body(new Callable<Integer>() { @Override public Integer call() { return DynamicTasks.get(x)*y; } }).build(); }
private static <T> Task<T> sleepingTask(final Duration delay, final T result) { return Tasks.<T>builder() .body(new Callable<T>() { @Override public T call() throws Exception { Time.sleep(delay); return result; } }) .build(); }
public static Task<Integer> addBasic(final Task<Integer> x, final int y) { return TaskBuilder.<Integer>builder() .displayName("add (not dynamic)") .dynamic(false) .body(new Callable<Integer>() { @Override public Integer call() { Preconditions.checkState(x.isSubmitted()); return x.getUnchecked()+y; } }).build(); }
@Override public Task<Void> newTask(final Entity entity, final Effector<Void> effector, final ConfigBag parameters) { return Tasks.<Void>builder() .body(new Callable<Void>() { @Override public Void call() throws Exception { EffectorExceptionLoggedTest.this.entity.myEffector(); return null; }}) .build(); } };
@Test public void testDisplayNameMatches() throws Exception { Task<Object> task = execManager.submit(TaskBuilder.builder() .body(Callables.<Object>returning("val")) .displayName("myname") .build()); assertTrue(TaskPredicates.displayNameSatisfies(Predicates.equalTo("myname")).apply(task)); assertFalse(TaskPredicates.displayNameSatisfies(Predicates.equalTo("wrong")).apply(task)); }
@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(); } };
@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)); }
@Override public TaskAdaptable<?> newTask() { TaskBuilder<List<?>> tb = Tasks.<List<?>>builder().displayName(name).parallel(false); for (TaskFactory<?> tf: taskFactories) tb.add(tf.newTask().asTask()); return tb.build(); } };
@Test public void testIsTransient() throws Exception { Task<?> task = execManager.submit(TaskBuilder.<Object>builder() .body(Callables.<Object>returning("val")) .build()); assertFalse(TaskPredicates.isTransient().apply(task)); BrooklynTaskTags.setTransient(task); assertTrue(TaskPredicates.isTransient().apply(task)); }
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; }
public <T> Task<T> submitting(final Task<T> task) { return Tasks.<T>builder().displayName("submitting:"+task.getId()).body(new Callable<T>() { @Override public T call() throws Exception { ec.submit(task); return task.get(); } }).build(); }
@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(); } })
@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); }
protected static Task<?> runEmptyTaskWithNameAndTags(Entity target, String name, Object ...tags) { TaskBuilder<Object> tb = newEmptyTask(name); for (Object tag: tags) tb.tag(tag); Task<?> task = ((EntityInternal)target).getExecutionContext().submit(tb.build()); task.getUnchecked(); return task; }
@Test public void testInvokeEffectorStartFailing_MethodInDynamicTask() { Task<Void> task = app.getExecutionContext().submit(Tasks.<Void>builder().dynamic(true).body(new Callable<Void>() { @Override public Void call() throws Exception { testInvokeEffectorStartFailing_Method(); return null; } }).build()); assertTaskSucceeds(task); assertTaskHasFailedChild(task); }
@Test public void testSingleExecutionContextEntityWithTask() { // Should cause an exception to be thrown in future releases. For now will log a warning. // Until then make sure the task is tagged only with the context of the executor. final TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); Task<Void> task = Tasks.<Void>builder() .tag(BrooklynTaskTags.tagForContextEntity(entity)) .body(new AssertContextRunnable(ImmutableList.of(app))).build(); app.getExecutionContext().submit(task).getUnchecked(); }