@Override protected Task<?> customReadBody(String type, Map<Object, Object> values, JsonParser jp, DeserializationContext ctxt) throws IOException { return mgmt.getExecutionManager().getTask((String) values.get("id")); } }
public Task<?> destroy(final Application application) { return mgmt.getExecutionManager().submit( MutableMap.of("displayName", "destroying "+application, "description", "REST call to destroy application "+application.getDisplayName()+" ("+application+")"), new Runnable() { @Override public void run() { ((EntityInternal)application).destroy(); mgmt.getEntityManager().unmanage(application); } }); }
private Collection<? extends TaskSummary> getBackgroundedChildren(Task<?> t) { Entity entity = BrooklynTaskTags.getContextEntity(t); List<TaskSummary> result = MutableList.of(); if (entity!=null) { Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), entity); for (Task<?> ti: tasks) { if (t.equals(ti.getSubmittedByTask())) { result.add(TaskTransformer.fromTask(ui.getBaseUriBuilder()).apply(ti)); } } } return result; }
protected Task<?> findTask(final String taskId) { final Task<?> task = mgmt().getExecutionManager().getTask(taskId); if (task == null) { throw WebResourceUtils.notFound("Cannot find task '%s' - possibly garbage collected to save memory", taskId); } checkEntityEntitled(task); return task; }
@Override public TaskSummary getTask(final String application, final String entityToken, String taskId) { // TODO deprecate in favour of ActivityApi.get ? Task<?> t = mgmt().getExecutionManager().getTask(taskId); if (t == null) throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); return TaskTransformer.fromTask(ui.getBaseUriBuilder()).apply(t); }
@Override public void run() { Set<Task<?>> storedTasks = app.getManagementContext().getExecutionManager().getTasksWithAllTags(ImmutableList.of( BrooklynTaskTags.tagForTargetEntity(entity), ManagementContextInternal.EFFECTOR_TAG)); assertEquals(storedTasks, ImmutableSet.of(), "storedTasks="+storedTasks); }});
protected SshPutTaskWrapper submit(final SshPutTaskFactory tf) { SshPutTaskWrapper t = tf.newTask(); mgmt.getExecutionManager().submit(t); return t; }
@Override @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { super.setUp(); app.start(ImmutableList.of(loc)); executionManager = (BasicExecutionManager) app.getManagementContext().getExecutionManager(); }
@Override public void run() { forceGc(); Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(((EntityInternal)entity).getManagementContext().getExecutionManager(), entity); Assert.assertEquals(tasks.size(), expectedCount, "Tasks were "+tasks); }}); }
protected void waitForApplicationTasks(Entity app) { Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(brooklynMgmt.getExecutionManager(), app); getLogger().info("Waiting on " + tasks.size() + " task(s)"); for (Task<?> t : tasks) { t.blockUntilEnded(); } }
@Override public void run() { forceGc(); Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(((EntityInternal)entity).getManagementContext().getExecutionManager(), entity); Assert.assertTrue(tasks.size() <= expectedMaxCount, "Expected tasks count max of " + expectedMaxCount + ". Tasks were "+tasks); }}); }
protected <T> ProcessTaskWrapper<T> submit(final ProcessTaskFactory<T> tf) { ProcessTaskWrapper<T> t = tf.newTask(); mgmt.getExecutionManager().submit(t); return t; }
@Override public void run() { Task<?> entityTask = Iterables.getOnlyElement(entity.getApplication().getManagementContext().getExecutionManager().getTasksWithAllTags( ImmutableList.of(BrooklynTaskTags.EFFECTOR_TAG, BrooklynTaskTags.tagForContextEntity(entity)))); String blockingDetails = getBlockingDetails(entityTask); assertTrue(blockingDetails.contains(blockingDetailsSnippet)); }}); }
protected void waitForApplicationTasks(Entity app) { Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app); getLogger().info("Waiting on " + tasks.size() + " task(s)"); for (Task<?> t : tasks) { t.blockUntilEnded(); } }
@Test(groups="Integration") public void testSshFetch() throws IOException { String fn = Urls.mergePaths(tempDir.getPath(), "f2"); FileUtils.write(new File(fn), "hello fetched world"); SshFetchTaskFactory tf = SshTasks.newSshFetchTaskFactory(host, fn); SshFetchTaskWrapper t = tf.newTask(); mgmt.getExecutionManager().submit(t); t.block(); Assert.assertTrue(t.isDone()); Assert.assertEquals(t.get(), "hello fetched world"); Assert.assertEquals(t.getBytes(), "hello fetched world".getBytes()); }
@Test public void resizeLoggedAsEffectorCall() throws Exception { DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure("memberSpec", EntitySpec.create(TestEntity.class))); app.start(ImmutableList.of(loc)); cluster.resize(1); Set<Task<?>> tasks = app.getManagementContext().getExecutionManager().getTasksWithAllTags(ImmutableList.of( BrooklynTaskTags.tagForContextEntity(cluster),"EFFECTOR")); assertEquals(tasks.size(), 2); assertTrue(Iterables.get(tasks, 0).getDescription().contains("start")); assertTrue(Iterables.get(tasks, 1).getDescription().contains("resize")); }
protected <T> ProcessTaskWrapper<T> submit(final ProcessTaskFactory<T> tf) { tf.machine(host); ProcessTaskWrapper<T> t = tf.newTask(); mgmt.getExecutionManager().submit(t); return t; }
@Override protected void postStop() { super.postStop(); if (isMachineStopped()) { // Don't unmanage in entity's task context as it will self-cancel the task. Wait for the stop effector to complete (and all parent entity tasks). // If this is not enough (still getting Caused by: java.util.concurrent.CancellationException: null) then // we could wait for BrooklynTaskTags.getTasksInEntityContext(ExecutionManager, this).isEmpty(); Task<?> stopEffectorTask = BrooklynTaskTags.getClosestEffectorTask(Tasks.current(), Startable.STOP); Task<?> topEntityTask = getTopEntityTask(stopEffectorTask); getManagementContext().getExecutionManager().submit(new UnmanageTask(topEntityTask, this)); } }
public void testGetTasksAndGcBoringTags() throws Exception { TestEntity e = app.createAndManageChild(EntitySpec.create(TestEntity.class)); final Task<?> task = runEmptyTaskWithNameAndTags(e, "should-be-kept", ManagementContextInternal.NON_TRANSIENT_TASK_TAG); runEmptyTaskWithNameAndTags(e, "should-be-gcd", ManagementContextInternal.TRANSIENT_TASK_TAG); assertTaskCountForEntityEventually(e, 1); Collection<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(app.getManagementContext().getExecutionManager(), e); assertEquals(tasks, ImmutableList.of(task), "Mismatched tasks, got: "+tasks); }
@Test(groups={"Integration", "WIP", "Broken"}) public void testJavaWebWithMemberSpecRebind() throws Exception { Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("test-java-web-app-spec-and-db-with-function.yaml")); AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); final Application app = (Application) mgmt().getEntityManager().getEntity(assembly.getId()); Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app); for (Task<?> t: tasks) t.blockUntilEnded(); Entities.dumpInfo(app); Application app2 = rebind(app); Assert.assertEquals(app2.getChildren().size(), 2); }