@Override public boolean apply(Task<?> input) { return input != null && matcher.apply(input.getDisplayName()); }
@Override public void customWriteBody(Task<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStringField("id", value.getId()); jgen.writeStringField("displayName", value.getDisplayName()); } @Override
private Task<?> findSshLaunchChild(Task<?> t) { Iterable<Task<?>> children = Tasks.children(t); for (Task<?> c : children) { if (c.getDisplayName().startsWith(SSH_LAUNCH_TASK_PREFIX)) { return c; } } for (Task<?> c : children) { Task<?> launchTask = findSshLaunchChild(c); if (launchTask != null) { return launchTask; } } return null; } }
/** invoked in a task's thread when a task is starting to run (may be some time after submitted), * but before doing any of the task's work, so that we can update bookkeeping and notify callbacks */ protected void internalBeforeStart(Map<?,?> flags, Task<?> task) { int count = activeTaskCount.incrementAndGet(); if (count % 1000==0) { log.warn("High number of active tasks: task #"+count+" is "+task); } //set thread _before_ start time, so we won't get a null thread when there is a start-time if (log.isTraceEnabled()) log.trace(""+this+" beforeStart, task: "+task + " running on thread " + Thread.currentThread().getName()); if (!task.isCancelled()) { Thread thread = Thread.currentThread(); ((TaskInternal<?>)task).setThread(thread); if (RENAME_THREADS) { threadOriginalName.set(thread.getName()); String newThreadName = "brooklyn-" + CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, task.getDisplayName().replace(" ", "")) + "-" + task.getId().substring(0, 8); thread.setName(newThreadName); } PerThreadCurrentTaskHolder.perThreadCurrentTask.set(task); ((TaskInternal<?>)task).setStartTimeUtc(System.currentTimeMillis()); } jitterThreadStart(task); invokeCallback(flags.get("newTaskStartCallback"), task); }
private String taskToVerboseString(Task<?> t) { return MoreObjects.toStringHelper(t) .add("id", t.getId()) .add("displayName", t.getDisplayName()) .add("submitTime", t.getSubmitTimeUtc()) .add("startTime", t.getStartTimeUtc()) .add("endTime", t.getEndTimeUtc()) .add("status", t.getStatusSummary()) .add("tags", t.getTags()) .toString(); }
public static LinkWithMetadata asLink(Task<?> t, UriBuilder ub) { if (t==null) return null; MutableMap<String,Object> data = new MutableMap<String,Object>(); data.put("id", t.getId()); if (t.getDisplayName()!=null) data.put("taskName", t.getDisplayName()); Entity entity = BrooklynTaskTags.getContextEntity(t); if (entity!=null) { data.put("entityId", entity.getId()); if (entity.getDisplayName()!=null) data.put("entityDisplayName", entity.getDisplayName()); } URI taskUri = serviceUriBuilder(ub, ActivityApi.class, "get").build(t.getId()); return new LinkWithMetadata(taskUri.toString(), data); } }
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; }
Task<?> o1s = o1.getSubmittedByTask(); Task<?> o2s = o2.getSubmittedByTask(); if ("start".equals(o1.getDisplayName()) ||"start".equals(o2.getDisplayName())) { weight = 0;
return new TaskSummary(task.getId(), task.getDisplayName(), task.getDescription(), entityId, entityDisplayName, task.getTags(), ifPositive(task.getSubmitTimeUtc()), ifPositive(task.getStartTimeUtc()), ifPositive(task.getEndTimeUtc()), task.getStatusSummary(), result, task.isError(), task.isCancelled(),
public void doTestLatchBlocks(ConfigKey<Boolean> latch, List<String> preLatchEvents, Object latchValue, Function<? super MyService, Void> customAssertFn) throws Exception { final AttributeSensor<Object> latchSensor = Sensors.newSensor(Object.class, "latch"); final MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class) .configure(ConfigKeys.newConfigKey(Object.class, latch.getName()), (Object)DependentConfiguration.attributeWhenReady(app, latchSensor))); final Task<Void> task; final Task<Void> startTask = Entities.invokeEffector(app, app, MyService.START, ImmutableMap.of("locations", ImmutableList.of(loc))); if (latch != SoftwareProcess.STOP_LATCH) { task = startTask; } else { startTask.get(Duration.THIRTY_SECONDS); task = Entities.invokeEffector(app, app, MyService.STOP); } assertEffectorBlockingDetailsEventually(entity, task.getDisplayName(), "Waiting for config " + latch.getName()); assertDriverEventsEquals(entity, preLatchEvents); assertFalse(task.isDone()); app.sensors().set(latchSensor, latchValue); customAssertFn.apply(entity); task.get(Duration.THIRTY_SECONDS); assertDriverEventsEquals(entity, getLatchPostTasks(latch)); }