public Task<?> expunge(final Entity entity, final boolean release) { if (mgmt.getEntitlementManager() .isEntitled( Entitlements.getEntitlementContext(), Entitlements.INVOKE_EFFECTOR, Entitlements.EntityAndItem.of(entity, "expunge"))) { return mgmt.getExecutionManager() .submit( MutableMap.of( "displayName", "expunging " + entity, "description", "REST call to expunge entity " + entity.getDisplayName() + " (" + entity + ")"), new Runnable() { @Override public void run() { if (release) Entities.destroyCatching(entity); else mgmt.getEntityManager().unmanage(entity); } }); } throw WebResourceUtils.unauthorized( "User '%s' is not authorized to expunge entity %s", Entitlements.getEntitlementContext().user(), entity); }
@Test public void testEffectorOnProxyIsRecorded() { Object result = entity.identityEffector("abc"); assertEquals(result, "abc"); Set<Task<?>> tasks = managementContext .getExecutionManager() .getTasksWithAllTags(ImmutableList.of(ManagementContextInternal.EFFECTOR_TAG, entity)); Task<?> task = Iterables.get(tasks, 0); assertEquals(tasks.size(), 1, "tasks=" + tasks); assertTrue(task.getDescription().contains("identityEffector")); }
@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()); }
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); } }); }
protected <T> ProcessTaskWrapper<T> submit(final ProcessTaskFactory<T> tf) { tf.machine(host); ProcessTaskWrapper<T> t = tf.newTask(); mgmt.getExecutionManager().submit(t); return t; }
protected SshPutTaskWrapper submit(final SshPutTaskFactory tf) { SshPutTaskWrapper t = tf.newTask(); mgmt.getExecutionManager().submit(t); return t; }