@Override protected ExecutionContext getExecutionContext(BrooklynObject bo) { // TODO expose ((AbstractEntityAdjunct)bo).execution ? Entity entity = ((AbstractEntityAdjunct)bo).entity; return (entity != null) ? ((EntityInternal)entity).getExecutionContext() : null; }
/** as {@link #executionContext(ExecutionContext)} but inferring from the entity */ public TaskQueueingResult<T> executionContext(Entity entity) { this.execContext = ((EntityInternal)entity).getExecutionContext(); return this; } private boolean orSubmitInternal() {
/** blocks until the given task completes, submitting if necessary, returning the result of that task; * optional contextMessage is available in status if this is running in a task */ @SuppressWarnings("unchecked") public static <T> T waitForTask(Task<T> t, Entity context, String contextMessage) throws InterruptedException { try { return (T) Tasks.resolveValue(t, Object.class, ((EntityInternal)context).getExecutionContext(), contextMessage); } catch (ExecutionException e) { throw Throwables.propagate(e); } }
@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(); } }
@Override public T call() throws Exception { 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") private Map<String, Object> resolveEnv(MutableMap<String, Object> env) throws ExecutionException, InterruptedException { return (Map<String, Object>) Tasks.resolveDeepValue(env, Object.class, entity().getExecutionContext()); } }
@Override public T get() { try { TypeToken<T> type = new TypeToken<T>(sensor.getType()) {}; return Tasks.resolveValue(task, (Class<T>) type.getRawType(), ((EntityInternal) entity).getExecutionContext(), "attributeSupplierWhenReady"); } catch (Exception e) { throw Exceptions.propagate(e); } } };
protected ExecutionContext getExecutionContext() { // TODO Transformer is cached so on next getConfig call the context could be different - something to watch out for. Entity contextEntity = BrooklynTaskTags.getTargetOrContextEntity(Tasks.current()); if (contextEntity instanceof EntityInternal) { return ((EntityInternal)contextEntity).getExecutionContext(); } else { log.debug("No entity context found, will use global execution context. Could lead to NPE on DSL resolving in location config."); return mgmt.getServerExecutionContext(); } } };
public void setEntity(EntityLocal entity) { if (destroyed.get()) throw new IllegalStateException("Cannot set entity on a destroyed entity adjunct"); this.entity = entity; this.execution = ((EntityInternal) entity).getExecutionContext(); if (entity!=null && getCatalogItemId() == null) { setCatalogItemIdAndSearchPath(entity.getCatalogItemId(), entity.getCatalogItemIdSearchPath()); } }
@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); } }
@Override public ExecutionContext getExecutionContext(Entity e) { // BEC is a thin wrapper around EM so fine to create a new one here; but make sure it gets the real entity if (e instanceof AbstractEntity) { ImmutableSet<Object> tags = ImmutableSet.<Object>of( BrooklynTaskTags.tagForContextEntity(e), this ); return new BasicExecutionContext(MutableMap.of("tags", tags), getExecutionManager()); } else { return ((EntityInternal)e).getExecutionContext(); } }
@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)); } }
private void checkReferences(final Enricher enricher, 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 enricher.getConfig(key); } }).get(); Assert.assertEquals(fromConfig, keyToEntity.get(key)); } }
private static ValueResolverIterator<Boolean> resolveLatchIterator(EntityInternal entity, Object val, ConfigKey<Boolean> key) { return Tasks.resolving(val, Boolean.class) .context(entity.getExecutionContext()) .description("config " + key.getName()) .iterator(); }
@Test public void testConfigEvaluation() throws Exception { app(); Object y1 = parseDslExpression("$brooklyn:config(\"dest\")"); String y2 = Tasks.resolveValue(y1, String.class, ((EntityInternal) find("two")).getExecutionContext()); Assert.assertEquals(y2.toString(), "1"); }
@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); } }
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; }