/** * @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); }
/** * Returns the entities matching the given predicate. * * @see #descendants(Entity, Predicate, boolean) */ public static Iterable<Entity> descendantsAndSelf(Entity root, Predicate<? super Entity> matching) { return Iterables.filter(descendantsAndSelf(root), matching); }
/** * @deprecated since 0.10.0; see {@link #descendantsAndSelf(Entity)} */ @Deprecated public static Iterable<Entity> descendants(Entity root) { return descendantsAndSelf(root); }
/** * @deprecated since 0.10.0; see {@link #descendantsAndSelf(Entity)} */ @Deprecated public static <T extends Entity> Iterable<T> descendants(Entity root, Class<T> ofType) { return descendantsAndSelf(root, ofType); }
/** * Return all descendants of given entity of the given type, potentially including the given root. * * @see #descendants(Entity) * @see Iterables#filter(Iterable, Class) */ public static <T extends Entity> Iterable<T> descendantsAndSelf(Entity root, Class<T> ofType) { return Iterables.filter(descendantsAndSelf(root), ofType); }
private enum ValueMarkers { UNCHANGED, REMOVE; }
@Test public void testTargetGroupCanBeSetInYaml() throws Exception { final String resourceName = "classpath:/" + getClass().getPackage().getName().replace('.', '/') + "/geodns.yaml"; final String blueprint = loadYaml(resourceName); Application app = EntityManagementUtils.createUnstarted(mgmt(), blueprint); GeoscalingDnsService geodns = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, GeoscalingDnsService.class)); DynamicFabric fabric = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, DynamicFabric.class)); assertEquals(geodns.config().get(AbstractGeoDnsService.ENTITY_PROVIDER), fabric); }
protected void deployAndAssertDisplayName(String yaml, String expectedName) throws Exception { Entity app = createAndStartApplication(yaml); Entity entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, TestEntity.class)); assertEquals(entity.getDisplayName(), expectedName); }
@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)); }
@Test @SuppressWarnings("deprecation") public void testDescendants() throws Exception { Asserts.assertEqualsIgnoringOrder(Entities.descendantsAndSelf(app), ImmutableList.of(app, entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(app), ImmutableList.of(app, entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendantsAndSelf(entity), ImmutableList.of(entity)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(entity), ImmutableList.of(entity)); }
@Override public void run() { for (Entity entity : Entities.descendantsAndSelf(app)) { assertNotEquals(entity.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.ON_FIRE); assertNotEquals(entity.getAttribute(Attributes.SERVICE_UP), false); if (entity instanceof SoftwareProcess) { EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_UP, Boolean.TRUE); } } }}); }
@Test @SuppressWarnings("deprecation") public void testDescendantsFilteredByPredicate() throws Exception { Asserts.assertEqualsIgnoringOrder(Entities.descendantsAndSelf(app, Predicates.instanceOf(TestEntity.class)), ImmutableList.of(entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(app, Predicates.instanceOf(TestEntity.class)), ImmutableList.of(entity, entity2)); }
@Test public void testEntityCreatingItsEnricherDoesNotReCreateItUnlessUniqueTagDifferent() throws Exception { TestEntity e1 = origApp.createAndManageChild(EntitySpec.create(TestEntity.class, MyTestEntityWithEnricher.class)); Collection<Enricher> e1e = e1.getEnrichers(); log.info("enrichers1: "+e1e); Entities.dumpInfo(e1); assertEquals(e1e.size(), 5); newApp = rebind(); Entity e2 = Iterables.getOnlyElement( Entities.descendantsAndSelf(newApp, EntityPredicates.idEqualTo(e1.getId())) ); Collection<Enricher> e2e = e2.getEnrichers(); log.info("enrichers2: "+e2e); Entities.dumpInfo(e2); assertEquals(e2e.size(), e1e.size()+1); }
@Test public void testNoWinrm() throws Exception { Entity app = createAndStartApplication( "location: byon:(hosts=\"1.2.3.4\",osFamily=windows)", "services:", "- type: "+EmptyWindowsProcess.class.getName(), " brooklyn.config:", " winrmMonitoring.enabled: false", " onbox.base.dir.skipResolution: true"); waitForApplicationTasks(app); EmptyWindowsProcess entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, EmptyWindowsProcess.class)); EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsContinually(entity, Attributes.SERVICE_UP, true); Iterables.find(entity.getLocations(), Predicates.instanceOf(WinRmMachineLocation.class)); } }
@Test(groups="Integration") public void testNoSshing() throws Exception { Entity app = createAndStartApplication( "location: byon:(hosts=\"1.2.3.4\")", "services:", "- type: "+EmptySoftwareProcess.class.getName(), " brooklyn.config:", " sshMonitoring.enabled: false", " "+BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION.getName()+": true"); waitForApplicationTasks(app); EmptySoftwareProcess entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, EmptySoftwareProcess.class)); EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsContinually(entity, Attributes.SERVICE_UP, true); } }
@Override public boolean apply(Application app) { VanillaWindowsProcess entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, VanillaWindowsProcess.class)); String winRMAddress = entity.getAttribute(AdvertiseWinrmLoginPolicy.VM_USER_CREDENTIALS); String ipPort = Strings.getFirstWordAfter(winRMAddress, "@"); String user = Strings.getFirstWord(winRMAddress); String password = Strings.getFirstWordAfter(winRMAddress, ":"); WinRmTool winRmTool = WinRmTool.Builder.builder(ipPort, user, password).build(); WinRmToolResponse winRmResponse = winRmTool.executePs(ImmutableList.of("(Get-Item \"C:\\\\Program Files\\\\7-Zip\\\\7z.exe\").name")); LOG.info("winRmResponse: code="+winRmResponse.getStatusCode()+"; out="+winRmResponse.getStdOut()+"; err="+winRmResponse.getStdErr()); return "7z.exe\r\n".equals(winRmResponse.getStdOut()); } };
@Test public void testCanDisableFilterForRunningEntities() throws Exception { geoDns.config().set(AbstractGeoDnsService.FILTER_FOR_RUNNING, false); app.start(ImmutableList.of(westChildWithLocation, eastChildWithLocationAndWithPrivateHostname)); publishSensors(2, true, true, true); assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2)); final Map<String, String> targets = ImmutableMap.copyOf(geoDns.sensors().get(AbstractGeoDnsService.TARGETS)); TestEntity problemChild = Iterables.get(Entities.descendantsAndSelf(app, TestEntity.class), 0); problemChild.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); assertAttributeEqualsContinually(geoDns, AbstractGeoDnsService.TARGETS, targets); }
@Test(groups={"Broken"}) public void testFiltersForRunningEntities() { app.start(ImmutableList.of(westChildWithLocation, eastChildWithLocationAndWithPrivateHostname)); publishSensors(2, true, true, true); TestEntity problemChild = Iterables.get(Entities.descendantsAndSelf(app, TestEntity.class), 0); assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2)); problemChild.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(1)); problemChild.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); assertAttributeEventually(geoDns, AbstractGeoDnsService.TARGETS, CollectionFunctionals.<String>mapSizeEquals(2)); }
@Test public void testEntityTags() throws Exception { MyEntity origE = origApp.createAndManageChild(EntitySpec.create(MyEntity.class)); origE.tags().addTag("foo"); origE.tags().addTag(origApp); newApp = rebind(); MyEntity newE = Iterables.getOnlyElement( Entities.descendantsAndSelf(newApp, MyEntity.class) ); assertTrue(newE.tags().containsTag("foo"), "tags are "+newE.tags().getTags()); assertFalse(newE.tags().containsTag("bar")); assertTrue(newE.tags().containsTag(newE.getParent())); assertTrue(newE.tags().containsTag(origApp)); assertEquals(newE.tags().getTags(), MutableSet.of("foo", newE.getParent())); }
@Test(groups = "Integration") public void testResizeAfterRebind() throws Exception { DynamicCluster cluster = app().createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.INITIAL_SIZE, 3) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(EmptySoftwareProcess.class))); app().start(ImmutableList.of(app().newLocalhostProvisioningLocation())); EntityAsserts.assertAttributeEquals(cluster, DynamicCluster.GROUP_SIZE, 3); rebind(RebindOptions.create().terminateOrigManagementContext(true)); cluster = Iterables.getOnlyElement(Entities.descendantsAndSelf(newApp, DynamicCluster.class)); cluster.resize(5); EntityAsserts.assertAttributeEquals(cluster, DynamicCluster.GROUP_SIZE, 5); EntityAsserts.assertAttributeEquals(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); } }