@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { if (mgmt != null) Entities.destroyAll(mgmt); mgmt = null; }
/** convenience for starting an entity, esp a new Startable instance which has been created dynamically * (after the application is started) */ public static void start(Entity e, Collection<? extends Location> locations) { if (!isManaged(e) && !manage(e)) { log.warn("Using deprecated discouraged mechanism to start management -- Entities.start(Application, Locations) -- caller should create and use the preferred management context"); startManagement(e); } if (e instanceof Startable) Entities.invokeEffector(e, e, Startable.START, MutableMap.of("locations", locations)).getUnchecked(); }
@Override public void run() { Entities.unmanage(dryRunChild); } }
/** Invokes in parallel if multiple, but otherwise invokes the item directly. */ public static Task<?> invokeEffector(Entity callingEntity, Iterable<? extends Entity> entitiesToCall, final Effector<?> effector, final Map<String,?> parameters) { if (Iterables.size(entitiesToCall)==1) return invokeEffector(callingEntity, entitiesToCall.iterator().next(), effector, parameters); else return invokeEffectorList(callingEntity, entitiesToCall, effector, parameters); }
@Override public void run() { log.debug("destroying app "+app+" (managed? "+isManaged(app)+"; mgmt is "+mgmt+")"); try { destroy(app); log.debug("destroyed app "+app+"; mgmt now "+mgmt); } catch (Exception e) { log.warn("problems destroying app "+app+" (mgmt now "+mgmt+", will rethrow at least one exception): "+e); error.compareAndSet(null, e); } }})); }
public String getNimbusHostname() { String result = entity.getConfig(Storm.NIMBUS_HOSTNAME); if (result != null) return result; Entity nimbus = entity.getConfig(Storm.NIMBUS_ENTITY); if (nimbus == null) { log.warn("No nimbus hostname available; using 'localhost'"); return "localhost"; } return Entities.submit(entity, DependentConfiguration.attributeWhenReady(nimbus, Attributes.HOSTNAME)).getUnchecked(); }
/** Invokes in parallel if multiple, but otherwise invokes the item directly. */ public static Task<?> invokeEffector(Entity callingEntity, Iterable<? extends Entity> entitiesToCall, final Effector<?> effector) { return invokeEffector(callingEntity, entitiesToCall, effector, Collections.<String,Object>emptyMap()); }
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { // Kills the apps before terminating the pool for (TestApplication app : createdApps) { Entities.destroy(app); } if (mgmt != null) { Entities.destroyAll(mgmt); mgmt = null; } }
public static void dumpInfo(Location loc) { try { dumpInfo(loc, new PrintWriter(System.out), "", " "); } catch (IOException exc) { // system.out throwing an exception is odd, so don't have IOException on signature throw new RuntimeException(exc); } } public static void dumpInfo(Location loc, Writer out) throws IOException {
@Override public boolean apply(@Nullable Entity input) { return (input != null) && Entities.isManaged(input); } @Override
/** Same as {@link #destroy(Location)} but catching all errors. */ public static void destroyCatching(Location loc) { try { destroy(loc); } catch (Exception e) { log.warn("ERROR destroying "+loc+" (ignoring): "+e, e); Exceptions.propagateIfFatal(e); } }
@Override public BrooklynObject apply(BrooklynObject obj) { // entities must be deproxied if (obj instanceof Entity) obj = Entities.deproxy((Entity)obj); return obj; } }));
/** * @deprecated since 0.10.0; see {@link #descendantsAndSelf(Entity, Predicate)} */ @Deprecated public static Iterable<Entity> descendants(Entity root, Predicate<? super Entity> matching) { return descendantsAndSelf(root, matching); }
@Test public void testInvokeEffectorListWithEmptyUsingUnmanagedContext() throws Exception { // Previously this threw the IllegalStateException directly, because DynamicTasks called // ((EntityInternal)entity).getManagementSupport().getExecutionContext(); // (so it successfully called getManagementSupport, and then hit the exception. // Now it calls ((EntityInternal)entity).getExecutionContext(), so the exception happens in // the entity-proxy and is thus wrapped. TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class)); Entities.unmanage(entity); try { Entities.invokeEffectorList(entity, ImmutableList.<StartableApplication>of(), Startable.STOP).get(Duration.THIRTY_SECONDS); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { IllegalStateException e2 = Exceptions.getFirstThrowableOfType(e, IllegalStateException.class); if (e2 == null) throw e; Asserts.expectedFailureContains(e2, "no longer managed"); } }
public static <T> Task<List<T>> invokeEffectorListWithMap(Entity callingEntity, Iterable<? extends Entity> entitiesToCall, final Effector<T> effector, final Map<String,?> parameters) { return invokeEffectorList(callingEntity, entitiesToCall, effector, parameters); }
@Test public void testStartManagementOfEntityIsNoop() throws Exception { Entity app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); assertTrue(Entities.isManaged(app2)); Entities.startManagement(app2); assertTrue(Entities.isManaged(app2)); listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, app2))); }
@Test public void testStartManagementFailsIfAppDeleted() throws Exception { TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); Entities.unmanage(app2); try { Entities.startManagement(app2, mgmt); fail("Managed deleted app "+app2+" in "+mgmt); } catch (IllegalStateException e) { if (!(e.toString().contains("No concrete entity known"))) throw e; } }
@Test public void testManageIsNoop() throws Exception { TestEntity child = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class) .parent(app)); Entities.manage(child); assertTrue(Entities.isManaged(child)); listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, child))); }
private void runTestGeneratesCorrectDownloadUrl(String version, String expectedUrl) throws Exception { // TODO Using BrooklynNodeImpl directly, because want to instantiate a BroolynNodeSshDriver. // Really want to make that easier to test, without going through "wrong" code path for creating entity. BrooklynNode entity = app.addChild(EntitySpec.create(BrooklynNode.class) .configure(BrooklynNode.SUGGESTED_VERSION, version)); BrooklynNodeImpl entityImpl = (BrooklynNodeImpl) Entities.deproxy(entity); ConfigToAttributes.apply(entity); BrooklynNodeSshDriver driver = new BrooklynNodeSshDriver(entityImpl, loc); DownloadResolver resolver = Entities.newDownloader(driver); List<String> urls = resolver.getTargets(); System.out.println("urls=" + urls); assertTrue(urls.contains(expectedUrl), "urls=" + urls); }
@Test @SuppressWarnings("deprecation") public void testDescendantsFilteredByType() throws Exception { Asserts.assertEqualsIgnoringOrder(Entities.descendantsAndSelf(app, TestEntity.class), ImmutableList.of(entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(app, TestEntity.class), ImmutableList.of(entity, entity2)); }