private static Task<?>[] asTasks(TaskAdaptable<?> ...tasks) { Task<?>[] result = new Task<?>[tasks.length]; for (int i=0; i<tasks.length; i++) result[i] = tasks[i].asTask(); return result; }
private TaskQueueingResult(TaskAdaptable<T> task, boolean wasQueued) { this.task = task.asTask(); this.wasQueued = wasQueued; } @Override
public static void addTagsDynamically(TaskAdaptable<?> task, final Object tag1, final Object ...tags) { ((BasicTask<?>)task.asTask()).applyTagModifier(new Function<Set<Object>, Void>() { @Override public Void apply(@Nullable Set<Object> input) { input.add(tag1); for (Object tag: tags) input.add(tag); return null; } }); }
public static void addTagDynamically(TaskAdaptable<?> task, final Object tag) { ((BasicTask<?>)task.asTask()).applyTagModifier(new Function<Set<Object>, Void>() { @Override public Void apply(@Nullable Set<Object> input) { input.add(tag); return null; } }); }
public static boolean isQueuedOrSubmitted(TaskAdaptable<?> task) { return ((TaskInternal<?>)task.asTask()).isQueuedOrSubmitted(); }
@Override public T get() { return task.asTask().getUnchecked(); } };
/** * 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; }
@Override public <T> Task<T> submit(Map<?,?> flags, TaskAdaptable<T> task) { if (!(task instanceof Task)) task = task.asTask(); synchronized (task) { if (((TaskInternal<?>)task).getInternalFuture()!=null) return (Task<T>)task; return submitNewTask(flags, (Task<T>) task); } }
@Override public Entity addExistingMachine(MachineLocation machine) { LOG.info("Adding additional machine to {}: {}", this, machine); Entity added = addNode(machine, MutableMap.of(REMOVABLE, false)); Map<String, ?> args = ImmutableMap.of("locations", ImmutableList.of(machine)); Task<Void> task = Effectors.invocation(added, Startable.START, args).asTask(); DynamicTasks.queueIfPossible(task).orSubmitAsync(this); return added; }
@Override public T call(ConfigBag parameters) { TaskAdaptable<T> t = DynamicTasks.queue(effectorTaskFactory.newTask(entity, effector, parameters)); return t.asTask().getUnchecked(); } }).newTask(entity, effector, parameters);
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(); }
protected void submitIfNecessary(TaskAdaptable<?> task) { if (!task.asTask().isSubmitted()) { if (BasicExecutionContext.getCurrentExecutionContext() == null) { throw new IllegalStateException("Compound task ("+task+") launched from "+this+" missing required execution context"); } else { BasicExecutionContext.getCurrentExecutionContext().submit(task); } } }
@Override public boolean isRunning() { return DynamicTasks.queue(getRequiredConfig(IS_RUNNING_TASK)).asTask().getUnchecked(); }
@Override public boolean isRunning() { return DynamicTasks.queue(getRequiredConfig(IS_RUNNING_TASK)).asTask().getUnchecked(); }
private void toggleNodePriority(Entity node, int newPriority) { Integer oldPriority = DynamicTasks.queue( Effectors.invocation( node, BrooklynNode.SET_HIGH_AVAILABILITY_PRIORITY, MutableMap.of(SetHighAvailabilityPriorityEffector.PRIORITY, newPriority)) ).asTask().getUnchecked(); Integer expectedPriority = (newPriority == HA_MASTER_PRIORITY ? HA_STANDBY_PRIORITY : HA_MASTER_PRIORITY); if (oldPriority != expectedPriority) { LOG.warn("The previous HA priority on node " + node.getId() + " was " + oldPriority + ", while the expected value is " + expectedPriority + " (while setting priority " + newPriority + ")."); } }
private void demoteOldMaster(Entity oldMaster, HighAvailabilityMode mode) { ManagementNodeState oldState = DynamicTasks.queue( Effectors.invocation( oldMaster, BrooklynNode.SET_HIGH_AVAILABILITY_MODE, MutableMap.of(SetHighAvailabilityModeEffector.MODE, mode)) ).asTask().getUnchecked(); if (oldState != ManagementNodeState.MASTER) { LOG.warn("The previous HA state on node " + oldMaster.getId() + " was " + oldState + ", while the expected value is " + ManagementNodeState.MASTER + "."); } }
@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(); } };
@Override public Void call(ConfigBag parameters) { Duration timeout = parameters.get(TIMEOUT); ConfigBag stopParameters = ConfigBag.newInstanceCopying(parameters); stopParameters.put(ShutdownEffector.STOP_APPS_FIRST, Boolean.FALSE); stopParameters.putIfAbsent(ShutdownEffector.SHUTDOWN_TIMEOUT, timeout); stopParameters.putIfAbsent(ShutdownEffector.REQUEST_TIMEOUT, timeout); DynamicTasks.queue(Effectors.invocation(entity(), STOP, stopParameters)).asTask().getUnchecked(); return null; } }
@Override public Void call(ConfigBag parameters) { Duration timeout = parameters.get(TIMEOUT); ConfigBag stopParameters = ConfigBag.newInstanceCopying(parameters); stopParameters.put(ShutdownEffector.STOP_APPS_FIRST, Boolean.TRUE); stopParameters.putIfAbsent(ShutdownEffector.SHUTDOWN_TIMEOUT, timeout); stopParameters.putIfAbsent(ShutdownEffector.REQUEST_TIMEOUT, timeout); DynamicTasks.queue(Effectors.invocation(entity(), STOP, stopParameters)).asTask().getUnchecked(); return null; } }