public static <T> TaskBuilder<T> builder() { return TaskBuilder.<T>builder(); }
SshFetchTaskWrapper(SshFetchTaskFactory factory) { this.remoteFile = Preconditions.checkNotNull(factory.remoteFile, "remoteFile"); this.machine = Preconditions.checkNotNull(factory.machine, "machine"); TaskBuilder<String> tb = TaskBuilder.<String>builder().dynamic(false).displayName("ssh fetch "+factory.remoteFile); task = tb.body(new SshFetchJob()).build(); config = factory.getConfig(); }
@Test public void testDisplayNameSatisfies() throws Exception { Task<Object> task = execManager.submit(TaskBuilder.builder() .body(Callables.<Object>returning("val")) .displayName("myname") .build()); assertTrue(TaskPredicates.displayNameSatisfies(Predicates.equalTo("myname")).apply(task)); assertFalse(TaskPredicates.displayNameSatisfies(Predicates.equalTo("wrong")).apply(task)); }
@Test public void testDisplayNameMatches() throws Exception { Task<Object> task = execManager.submit(TaskBuilder.builder() .body(Callables.<Object>returning("val")) .displayName("myname") .build()); assertTrue(TaskPredicates.displayNameSatisfies(Predicates.equalTo("myname")).apply(task)); assertFalse(TaskPredicates.displayNameSatisfies(Predicates.equalTo("wrong")).apply(task)); }
@Test public void testIsEffector() throws Exception { Task<?> task = app.invoke(TestApplication.START, ImmutableMap.of("locations", ImmutableList.<Location>of())); Task<?> otherTask = execManager.submit(TaskBuilder.<Object>builder() .body(Callables.<Object>returning("val")) .build()); assertTrue(TaskPredicates.isEffector().apply(task)); assertFalse(TaskPredicates.isEffector().apply(otherTask)); }
SshPutTaskWrapper(SshPutTaskFactory constructor) { super(constructor); TaskBuilder<Void> tb = TaskBuilder.<Void>builder().dynamic(false).displayName(getSummary()); task = tb.body(new SshPutJob()).build(); }
@Test public void testDisplayNameEqualTo() throws Exception { Task<Object> task = execManager.submit(TaskBuilder.builder() .body(Callables.<Object>returning("val")) .displayName("myname") .build()); assertTrue(TaskPredicates.displayNameEqualTo("myname").apply(task)); assertFalse(TaskPredicates.displayNameEqualTo("wrong").apply(task)); }
@Test public void testHasTag() throws Exception { Task<?> task = execManager.submit(TaskBuilder.<Object>builder() .body(Callables.<Object>returning("val")) .tag("mytag") .build()); assertTrue(TaskPredicates.hasTag("mytag").apply(task)); assertFalse(TaskPredicates.hasTag("wrongtag").apply(task)); }
@Test public void testIsTransient() throws Exception { Task<?> task = execManager.submit(TaskBuilder.<Object>builder() .body(Callables.<Object>returning("val")) .build()); assertFalse(TaskPredicates.isTransient().apply(task)); BrooklynTaskTags.setTransient(task); assertTrue(TaskPredicates.isTransient().apply(task)); }
@Test public void testIsInessential() throws Exception { Task<?> task = execManager.submit(TaskBuilder.<Object>builder() .body(Callables.<Object>returning("val")) .build()); assertFalse(TaskPredicates.isInessential().apply(task)); BrooklynTaskTags.setInessential(task); assertTrue(TaskPredicates.isInessential().apply(task)); } }
public static Task<Integer> add(final int x, final int y) { return TaskBuilder.<Integer>builder() .displayName("add") .body(new Callable<Integer>() { @Override public Integer call() { return x+y; } }).build(); }
public static Task<Integer> times(final int x, final int y) { return TaskBuilder.<Integer>builder() .displayName("times") .body(new Callable<Integer>() { @Override public Integer call() { return x*y; } }).build(); }
public static Task<Integer> times(final Task<Integer> x, final int y) { return TaskBuilder.<Integer>builder() .displayName("times") .body(new Callable<Integer>() { @Override public Integer call() { return DynamicTasks.get(x)*y; } }).build(); }
@Override public Task<Integer> newTask(final Entity entity, final Effector<Integer> effector, final ConfigBag parameters) { return TaskBuilder.<Integer>builder() .displayName("times") .body(new Callable<Integer>() { @Override public Integer call() { return DynamicTasks.get( x.newTask(entity, effector, parameters) )*y; }}).build(); } };
public static Task<Integer> add(final Task<Integer> x, final int y) { return TaskBuilder.<Integer>builder() .displayName("add") .body(new Callable<Integer>() { @Override public Integer call() { return DynamicTasks.get(x)+y; } }).build(); }
@Override public void onEvent(SensorEvent<Boolean> event) { final MySqlNode node = (MySqlNode) event.getSource(); if (Boolean.TRUE.equals(event.getValue()) && // We are interested in SERVICE_PROCESS_IS_RUNNING only while haven't come online yet. // Probably will get several updates while replication is initialized so an additional // check is needed whether we have already seen this. Boolean.FALSE.equals(node.getAttribute(MySqlNode.SERVICE_UP)) && !Boolean.TRUE.equals(node.getAttribute(NODE_REPLICATION_INITIALIZED))) { // Events executed sequentially so no need to synchronize here. node.sensors().set(NODE_REPLICATION_INITIALIZED, Boolean.TRUE); final Runnable nodeInitTaskBody; if (MySqlClusterUtils.IS_MASTER.apply(node)) { nodeInitTaskBody = new InitMasterTaskBody(cluster, node); } else { nodeInitTaskBody = new InitSlaveTaskBody(cluster, node, lock); } DynamicTasks.submitTopLevelTask(TaskBuilder.builder() .displayName("setup master-slave replication") .body(nodeInitTaskBody) .tag(BrooklynTaskTags.NON_TRANSIENT_TASK_TAG) .build(), node); } }
public void apply(final Entity source, final Object valueIgnored) { T val = (T) attribute.getValue(); if (!readiness.apply(val)) { log.warn("Skipping {} for {} because attribute {} not ready", new Object[]{description, attribute.getEntity(), attribute.getAttribute()}); return; } final Task<Void> task = TaskBuilder.<Void>builder().displayName(description).body(runnable).build(); DynamicTasks.queueIfPossible(task).orSubmitAsync(source).asTask(); if (blockUntilEnded) { final String originalBlock = Tasks.setBlockingDetails(description); try { task.blockUntilEnded(); } finally { Tasks.setBlockingDetails(originalBlock); } } } }
/** creates the TaskBuilder which can be further customized; typically invoked by the initial {@link #newTask()} */ public TaskBuilder<Object> constructCustomizedTaskBuilder() { TaskBuilder<Object> tb = TaskBuilder.builder().dynamic(false).displayName("ssh: "+getSummary()); tb.tag(BrooklynTaskTags.tagForStream(BrooklynTaskTags.STREAM_STDIN, Streams.byteArrayOfString(Strings.join(commands, "\n")))); tb.tag(BrooklynTaskTags.tagForEnvStream(BrooklynTaskTags.STREAM_ENV, shellEnvironment)); return tb; }
public static Task<Integer> addBasic(final Task<Integer> x, final int y) { return TaskBuilder.<Integer>builder() .displayName("add (not dynamic)") .dynamic(false) .body(new Callable<Integer>() { @Override public Integer call() { Preconditions.checkState(x.isSubmitted()); return x.getUnchecked()+y; } }).build(); }
@Override public Task<Entity> newTask() { return TaskBuilder.<Entity>builder() .displayName(toString()) .tag(BrooklynTaskTags.TRANSIENT_TASK_TAG) .body(new Callable<Entity>() { @Override public Entity call() { EntityInternal entity = entity(); Collection<Entity> entitiesToSearch = entity.getManagementContext().getEntityManager().getEntities(); Optional<Entity> result = Iterables.tryFind(entitiesToSearch, EntityPredicates.configEqualTo(TAG, tag)); if (result.isPresent()) { return result.get(); } else { throw new NoSuchElementException("No entity matching id " + tag+" in "+entitiesToSearch); } }}) .build(); } }