/** Finds the entity where this task is running * @throws NullPointerException if there is none (no task, or no context entity for that task) */ public static Entity findEntity() { return Preconditions.checkNotNull(BrooklynTasks.getTargetOrContextEntity(Tasks.current()), "This must be executed in a task whose execution context has a target or context entity " + "(i.e. it must be run from within an effector)"); }
@Nullable /** callers should allow this to be null so task can be used outside of an entity */ protected Entity entity() { return BrooklynTasks.getTargetOrContextEntity(Tasks.current()); } protected <T> T entityConfig(ConfigKey<T> key) {
protected EntityInternal entity() { return (EntityInternal) BrooklynTasks.getTargetOrContextEntity(Tasks.current()); }
protected EntityInternal entity() { return (EntityInternal) BrooklynTasks.getTargetOrContextEntity(Tasks.current()); }
@Override public synchronized ProcessTaskWrapper<RET> newTask() { if (machine==null) { if (log.isDebugEnabled()) log.debug("Using an SshEffectorTask not in an effector without any machine; will attempt to infer the machine: "+this); Entity entity = BrooklynTasks.getTargetOrContextEntity(Tasks.current()); if (entity!=null) machine(EffectorTasks.getSshMachine(entity)); } return super.newTask(); }
@Override public SshPutTaskWrapper newTask() { Entity entity = BrooklynTasks.getTargetOrContextEntity(Tasks.current()); if (entity!=null) machine(EffectorTasks.getSshMachine(entity)); return super.newTask(); } }
@Override public SshFetchTaskWrapper newTask() { Entity entity = BrooklynTasks.getTargetOrContextEntity(Tasks.current()); if (entity!=null) machine(EffectorTasks.getSshMachine(entity)); return super.newTask(); } }
TaskInternal<?> current = (TaskInternal<?>) Tasks.current(); if (current == null) throw new IllegalStateException("Should only be invoked in a running task"); Entity entity = BrooklynTasks.getTargetOrContextEntity(current); if (entity == null) throw new IllegalStateException("Should only be invoked in a running task with an entity tag; "+ current+" has no entity tag ("+current.getStatusDetail(false)+")");
.returning(new Function<ProcessTaskWrapper<?>,Boolean>() { public Boolean apply(ProcessTaskWrapper<?> task) { if (task.getExitCode()==0) return true; Entity entity = BrooklynTasks.getTargetOrContextEntity(Tasks.current()); log.warn("Error setting up sudo for "+task.getMachine().getUser()+"@"+task.getMachine().getAddress().getHostName()+" "+ " (exit code "+task.getExitCode()+(entity!=null ? ", entity "+entity : "")+")"); Streams.logStreamTail(log, "STDERR of sudo setup problem", Streams.byteArrayOfString(task.getStderr()), 1024); if (requireSuccess) { throw new IllegalStateException("Passwordless sudo is required for "+task.getMachine().getUser()+"@"+task.getMachine().getAddress().getHostName()+ (entity!=null ? " ("+entity+")" : "")); } return true; } }); }