@Override public T call() throws Exception { ExecutionContext executionContext = ((EntityInternal) entity).getExecutionContext(); return executionContext.submit(Maps.newHashMap(), job).get(); } }
@Override public T call() throws Exception { final ExecutionContext executionContext = ((EntityInternal) entity).getExecutionContext(); return executionContext.submit(Maps.newHashMap(), job).get(); } }
@Override public T call() throws Exception { final ExecutionContext executionContext = ((EntityInternal) entity).getExecutionContext(); return executionContext.submit(Maps.newHashMap(), job).get(); } }
/** * Submits a task to run at the entity. * * @return the task passed in, for fluency */ public static <T extends TaskAdaptable<?>> T submit(final Entity entity, final T task) { final ExecutionContext executionContext = ((EntityInternal)entity).getExecutionContext(); executionContext.submit(task.asTask()); return task; }
@SuppressWarnings("unchecked") protected void schedulePublish(long delay) { if (isRunning() && executorQueued.compareAndSet(false, true)) { long now = System.currentTimeMillis(); delay = Math.max(0, Math.max(delay, (executorTime + MIN_PERIOD_BETWEEN_EXECS_MILLIS) - now)); if (LOG.isTraceEnabled()) LOG.trace("{} scheduling publish in {}ms", this, delay); Runnable job = new PublishJob(); ScheduledTask task = new ScheduledTask(MutableMap.of("delay", Duration.of(delay, TimeUnit.MILLISECONDS)), new BasicTask<Void>(job)); ((EntityInternal)entity).getExecutionContext().submit(task); } }
/** * Convenience for creating and submitted a given shell command against the given mgmt context, * primarily intended for use in the groovy GUI console. */ @Beta public static ProcessTaskWrapper<Integer> shell(ManagementContext mgmt, String command) { ProcessTaskWrapper<Integer> t = SystemTasks.exec(command).newTask(); mgmt.getServerExecutionContext().submit(t).getUnchecked(); System.out.println(t.getStdout()); System.err.println(t.getStderr()); return t; }
@Override public SshPollValue call() throws Exception { ProcessTaskWrapper<?> taskWrapper = taskFactory.newTask(); executionContext.submit(taskWrapper); taskWrapper.block(); Optional<Integer> exitCode = Optional.fromNullable(taskWrapper.getExitCode()); return new SshPollValue(null, exitCode.or(-1), taskWrapper.getStdout(), taskWrapper.getStderr()); }}, new DelegatingPollHandler<SshPollValue>(handlers),
protected void runConcurrentWorker(Supplier<Runnable> taskSupplier) { Collection<Task<?>> results = new ArrayList<>(); for (int i = 0; i < MAX_PARALLEL_RESOLVERS; i++) { Task<?> result = app.getExecutionContext().submit(taskSupplier.get()); results.add(result); } for (Task<?> result : results) { result.getUnchecked(); } }
@Override public SshPollValue call() throws Exception { ProcessTaskWrapper<String> taskWrapper = knifeTaskFactory.newTask(); final ExecutionContext executionContext = ((EntityInternal) entity).getExecutionContext(); log.debug("START: Running knife to query attributes of Chef node {}", nodeName); executionContext.submit(taskWrapper); taskWrapper.block(); log.debug("DONE: Running knife to query attributes of Chef node {}", nodeName); return new SshPollValue(null, taskWrapper.getExitCode(), taskWrapper.getStdout(), taskWrapper.getStderr()); } };
private void checkReferences(final Policy policy, Map<ConfigKey<Entity>, Entity> keyToEntity) throws Exception { for (final ConfigKey<Entity> key : keyToEntity.keySet()) { final Entity entity = keyToEntity.get(key); // Grab an entity whose execution context we can use Entity fromConfig = ((EntityInternal)entity).getExecutionContext().submit(MutableMap.of(), new Callable<Entity>() { @Override public Entity call() throws Exception { return policy.getConfig(key); } }).get(); Assert.assertEquals(fromConfig, keyToEntity.get(key)); } }
@SuppressWarnings("unchecked") protected void doStartPolling() { if (scheduledTask == null || scheduledTask.isDone()) { ScheduledTask task = new ScheduledTask(MutableMap.of("period", getPollPeriod(), "displayName", getTaskName()), pollingTaskFactory); scheduledTask = ((EntityInternal)entity).getExecutionContext().submit(task); } }
@Test public void testSingleExecutionContextEntityWithRunnable() { // 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)); Runnable task = new AssertContextRunnable(ImmutableList.of(app)); ImmutableMap<String,?> flags = ImmutableMap.of( "tags", ImmutableList.of(BrooklynTaskTags.tagForContextEntity(entity))); app.getExecutionContext().submit(flags, task).getUnchecked(); }
protected <T> Task<T> runAtEntity(Entity entity, TaskAdaptable<T> task) { getExecutionContext(entity).submit(task); if (DynamicTasks.getTaskQueuingContext()!=null) { // put it in the queueing context so it appears in the GUI // mark it inessential as this is being invoked from code, // the caller will do 'get' to handle errors TaskTags.markInessential(task); DynamicTasks.getTaskQueuingContext().queue(task.asTask()); } return task.asTask(); }
@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(); }
@Test public void shouldAssertAttributeEventuallyNonNull() throws Exception { EntityAsserts.assertAttributeEquals(entity, TestEntity.NAME, null); Task<?> assertValue = entity.getExecutionContext().submit(new Runnable() { @Override public void run() { EntityAsserts.assertAttributeEventuallyNonNull(entity, TestEntity.NAME); } }); entity.sensors().set(TestEntity.NAME, "something"); assertValue.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); }
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 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(); }
public void testCompletedTaskReturnsResultImmediately() { Task<String> t = newSleepTask(Duration.ZERO, "foo"); app.getExecutionContext().submit(t).getUnchecked(); // Below, we call ValueResolver.getMaybe() from this thread, which has no execution context. // However, the task has already been submitted and we have waited for it to complete. // Therefore the ValueResolver can simply check for task.isDone() and return its result immediately. Maybe<String> result = Tasks.resolving(t).as(String.class).timeout(Duration.ZERO).getMaybe(); Assert.assertEquals(result.get(), "foo"); }