private WinRmToolResponse executePsScript(final WinRmMachineLocation machine, final String psScript) { TaskBuilder<WinRmToolResponse> tb = Tasks.<WinRmToolResponse>builder().displayName("winrm-exec").body( new Callable<WinRmToolResponse>() { @Override public WinRmToolResponse call() throws Exception { // FIXME Do I need COMPUTER_NAME in flags? return machine.executePsScript(psScript); } }); return execute(tb, psScript); }
@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()); }
@Override public Task<Void> call() { return Tasks.<Void>builder().dynamic(false).displayName("periodic-persister").body(new Callable<Void>() { @Override public Void call() { persistNowSafely(); return null; }}).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(); } };
@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(); } };
public static final Task<String> newThrowTask(final Duration timeout) { return Tasks.<String>builder().body(new Callable<String>() { @Override public String call() { Time.sleep(timeout); throw new IllegalStateException("intended, during tests"); }} ).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(); } };
@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(); } };
/** @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()); }
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; }
@Test public void testSingleExecutionContextEntityWithTaskAndExternalFlags() { // 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() .body(new AssertContextRunnable(ImmutableList.of(app))).build(); ImmutableMap<String,?> flags = ImmutableMap.of( "tags", ImmutableList.of(BrooklynTaskTags.tagForContextEntity(entity))); app.getExecutionContext().submit(flags, task).getUnchecked(); }
@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(); } })
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 TaskAdaptable<String> newTask(Entity entity, Effector<String> effector, ConfigBag parameters) { return Tasks.<String>builder().displayName("eat-sleep-rave-repeat").addAll(tasks(0)).build(); } List<Task<Object>> tasks(final int depth) {
@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(); }