public static Task<List<?>> sequential(String name, List<? extends TaskAdaptable<?>> tasks) { return sequential(name, asTasks(Iterables.toArray(tasks, TaskAdaptable.class))); } private static Task<List<?>> sequentialInternal(String name, Task<?>[] tasks) {
public static Task<List<?>> sequential(List<? extends TaskAdaptable<?>> tasks) { return sequential(asTasks(Iterables.toArray(tasks, TaskAdaptable.class))); } public static Task<List<?>> sequential(String name, List<? extends TaskAdaptable<?>> tasks) {
/** as {@link #invocationParallel(Effector, Map, Iterable)} but executing sequentially */ public static TaskAdaptable<List<?>> invocationSequential(Effector<?> eff, Map<?,?> params, Iterable<? extends Entity> entities) { List<TaskAdaptable<?>> tasks = new ArrayList<TaskAdaptable<?>>(); for (Entity e: entities) tasks.add(invocation(e, eff, params)); return Tasks.sequential( "invoking " + eff + " on " + tasks.size() + " node" + (Strings.s(tasks.size())), tasks.toArray(new TaskAdaptable[tasks.size()])); }
protected void copyResources(String destinationParentDir, Map<String, String> files, Map<String, String> templates) { if (files == null) files = Collections.emptyMap(); if (templates == null) templates = Collections.emptyMap(); final List<TaskAdaptable<?>> tasks = new ArrayList<>(files.size() + templates.size()); applyFnToResourcesAppendToList(files, newCopyResourceFunction(), destinationParentDir, tasks); applyFnToResourcesAppendToList(templates, newCopyTemplateFunction(), destinationParentDir, tasks); if (!tasks.isEmpty()) { String oldBlockingDetails = Tasks.setBlockingDetails("Copying resources"); try { DynamicTasks.queue(Tasks.sequential(tasks)).getUnchecked(); } finally { Tasks.setBlockingDetails(oldBlockingDetails); } } }
public static TaskFactory<?> buildChefFile(String runDirectory, String chefDirectory, String phase, Iterable<? extends String> runList, Map<String, Object> optionalAttributes) { // TODO if it's server, try knife first // TODO configure add'l properties String phaseRb = "root = " + "'"+runDirectory+"'" // recommended alternate to runDir is the following, but it is not available in some rubies //+ File.absolute_path(File.dirname(__FILE__))"+ + "\n"+ "file_cache_path root\n"+ // "cookbook_path root + '/cookbooks'\n"; "cookbook_path '"+chefDirectory+"'\n"; Map<String,Object> phaseJsonMap = MutableMap.of(); if (optionalAttributes!=null) phaseJsonMap.putAll(optionalAttributes); if (runList!=null) phaseJsonMap.put("run_list", ImmutableList.copyOf(runList)); Gson json = new GsonBuilder().create(); String phaseJson = json.toJson(phaseJsonMap); return Tasks.sequential("build chef files for "+phase, SshEffectorTasks.put(Urls.mergePaths(runDirectory)+"/"+phase+".rb").contents(phaseRb).createDirectory(), SshEffectorTasks.put(Urls.mergePaths(runDirectory)+"/"+phase+".json").contents(phaseJson)); }
public static TaskFactory<?> buildChefFile(String runDirectory, String chefDirectory, String phase, Iterable<? extends String> runList, Map<String, Object> optionalAttributes) { // TODO if it's server, try knife first // TODO configure add'l properties String phaseRb = "root = " + "'"+runDirectory+"'" // recommended alternate to runDir is the following, but it is not available in some rubies //+ File.absolute_path(File.dirname(__FILE__))"+ + "\n"+ "file_cache_path root\n"+ // "cookbook_path root + '/cookbooks'\n"; "cookbook_path '"+chefDirectory+"'\n"; Map<String,Object> phaseJsonMap = MutableMap.of(); if (optionalAttributes!=null) phaseJsonMap.putAll(optionalAttributes); if (runList!=null) phaseJsonMap.put("run_list", ImmutableList.copyOf(runList)); Gson json = new GsonBuilder().create(); String phaseJson = json.toJson(phaseJsonMap); return Tasks.sequential("build chef files for "+phase, SshEffectorTasks.put(Urls.mergePaths(runDirectory)+"/"+phase+".rb").contents(phaseRb).createDirectory(), SshEffectorTasks.put(Urls.mergePaths(runDirectory)+"/"+phase+".json").contents(phaseJson)); }
@Test public void testComplex() throws Exception { Task<List<?>> t = Tasks.sequential( sayTask("1"), sayTask("2"), Tasks.parallel(sayTask("4"), sayTask("3")), sayTask("5") ); ec.submit(t); Assert.assertEquals(t.get().size(), 4); Asserts.assertEqualsIgnoringOrder((List<?>)t.get().get(2), ImmutableSet.of("3", "4")); Assert.assertTrue(messages.equals(Arrays.asList("1", "2", "3", "4", "5")) || messages.equals(Arrays.asList("1", "2", "4", "3", "5")), "messages="+messages); }
DynamicTasks.submit(Tasks.sequential("Add JMX Sensor " + sensor.getName(), jmxPortTask, jmxFeedTask), entity); } else { throw new IllegalStateException(String.format("Entity %s does not support JMX", entity));
@Test public void testCancelled() throws Exception { Task<List<?>> t = Tasks.sequential( sayTask("1"), sayTask("2a", Duration.THIRTY_SECONDS, "2b"),
@Override public void apply(@SuppressWarnings("deprecation") final org.apache.brooklyn.api.entity.EntityLocal entity) { final AttributeSensor<ReleaseableLatch> sensor = Sensors.newSensor(ReleaseableLatch.class, sensorName); ((EntityInternal) entity).getMutableEntityType().addSensor(sensor); final Task<ReleaseableLatch> resolveValueTask = DependentConfiguration.maxConcurrency(maxConcurrency); class SetValue implements Runnable { @Override public void run() { ReleaseableLatch releaseableLatch = resolveValueTask.getUnchecked(); log.debug(this+" setting sensor "+sensor+" to "+releaseableLatch+" on "+entity); entity.sensors().set(sensor, releaseableLatch); } } Task<ReleaseableLatch> setValueTask = Tasks.<ReleaseableLatch>builder().displayName("Setting " + sensor + " on " + entity).body(new SetValue()).build(); Entities.submit(entity, Tasks.sequential("Resolving and setting " + sensor + " on " + entity, resolveValueTask, setValueTask)); }
@SuppressWarnings("unchecked") @Override public void apply(final EntityLocal entity) { super.apply(entity); class ResolveValue implements Callable<Maybe<T>> { @Override public Maybe<T> call() throws Exception { return Tasks.resolving(value).as((Class<T>)sensor.getType()).timeout(timeout).getMaybe(); } } final Task<Maybe<T>> resolveValue = Tasks.<Maybe<T>>builder().displayName("resolving " + value).body(new ResolveValue()).build(); class SetValue implements Callable<T> { @Override public T call() throws Exception { Maybe<T> v = resolveValue.get(); if (!v.isPresent()) { log.debug(this+" not setting sensor "+sensor+" on "+entity+"; cannot resolve "+value+" after timeout " + timeout); return null; } log.debug(this+" setting sensor "+sensor+" to "+v.get()+" on "+entity); return entity.sensors().set(sensor, v.get()); } } Task<T> setValue = Tasks.<T>builder().displayName("Setting " + sensor + " on " + entity).body(new SetValue()).build(); Entities.submit(entity, Tasks.sequential("Resolving and setting " + sensor + " on " + entity, resolveValue, setValue)); } }
.body(new ObtainPermit(getChildTaskSemaphore(), description, permitObtained)) .build(); toSubmit = Tasks.sequential( "Waiting for permit then running " + effector.getName() + " on " + target, obtainMutex, effectorTask);