@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()); }
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(); }
@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)); }
@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 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()); }
/** * Returns a queued {@link Task} which provisions a machine in the given location * and returns that machine. The task can be used as a supplier to subsequent methods. */ protected Task<MachineLocation> provisionAsync(final MachineProvisioningLocation<?> location) { return DynamicTasks.queue(Tasks.<MachineLocation>builder().displayName("provisioning (" + location.getDisplayName() + ")").body( new ProvisionMachineTask(location)).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)); }
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(); }
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> 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(); }
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 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); }
@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(); }
@Override public Map<String, Object> batchConfigRead(String application, String entityToken, Boolean raw) { // TODO: add test Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) { throw WebResourceUtils.forbidden("User '%s' is not authorized to see entity '%s'", Entitlements.getEntitlementContext().user(), entity); } // wrap in a task for better runtime view return Entities.submit(entity, Tasks.<Map<String,Object>>builder().displayName("REST API batch config read").body(new BatchConfigRead(mgmt(), this, entity, raw)).build()).getUnchecked(); }