protected void setEntityAfterSubscribingProducerChildrenEvents() { for (Entity child : Iterables.filter(producer.getChildren(), entityFilter)) { addProducerChild(child); } }
private static void gatherAllDescendants(Entity e, List<Entity> result) { if (result.add(e)) { for (Entity ee: e.getChildren()) gatherAllDescendants(ee, result); } }
/** walks the hierarchy (depth-first) at root (often an Application) looking for * an entity matching the given ID or name; returns the first such entity, or null if none found **/ public Entity searchForEntityNamed(Entity root, String entity) { if (root.getId().equals(entity) || entity.equals(root.getDisplayName())) return root; for (Entity child: root.getChildren()) { Entity result = searchForEntityNamed(child, entity); if (result!=null) return result; } return null; }
private void addRequiredOpenPortsRecursively(Entity entity, Set<Integer> ports) { ports.addAll(entity.getConfig(SameServerEntity.REQUIRED_OPEN_LOGIN_PORTS)); Boolean portsAutoInfer = entity.getConfig(SameServerEntity.INBOUND_PORTS_AUTO_INFER); String portsRegex = entity.getConfig(SameServerEntity.INBOUND_PORTS_CONFIG_REGEX); ports.addAll(InboundPortsUtils.getRequiredOpenPorts(entity, portsAutoInfer, portsRegex)); LOG.debug("getRequiredOpenPorts detected default {} for {}", ports, entity); for (Entity child : entity.getChildren()) { addRequiredOpenPortsRecursively(child, ports); } }
/** unsubmitted task for restarting children of the given entity */ public static TaskAdaptable<?> restartingChildren(Entity entity, ConfigBag parameters) { return Effectors.invocation(Startable.RESTART, parameters.getAllConfig(), filterStartableManagedEntities(entity.getChildren())); } /** as {@link #restartingChildren(Entity, ConfigBag)} with no parameters */
private void checkGrandchildEntitySpec(Entity createAndStartApplication, String entityName) { Collection<Entity> children = createAndStartApplication.getChildren(); Assert.assertEquals(children.size(), 1); Entity child = Iterables.getOnlyElement(children); Collection<Entity> grandChildren = child.getChildren(); Assert.assertEquals(grandChildren.size(), 1); Entity grandChild = Iterables.getOnlyElement(grandChildren); Assert.assertEquals(grandChild.getDisplayName(), entityName); Assert.assertEquals(grandChild.getEntityType().getName(), BasicEntity.class.getName()); }
@Test public void testDslParent() throws Exception { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.children:", " - type: " + BasicEntity.class.getName(), " brooklyn.config:", " dest: $brooklyn:parent()"); final Entity child = Iterables.getOnlyElement(app.getChildren()); assertEquals(getConfigEventually(child, DEST), app); }
@Test public void testFlagAtRootEntityImpl() throws Exception { Entity app = createAndStartApplication( "services:", "- serviceType: " + TestEntityImpl.class.getName(), " confName: Foo Bar"); Entity testEntity = Iterables.getOnlyElement(app.getChildren()); Assert.assertEquals(testEntity.getConfig(TestEntity.CONF_NAME), "Foo Bar"); }
@Test public void testExplicitFlagsEntityImpl() throws Exception { Entity app = createAndStartApplication( "services:", "- serviceType: " + TestEntityImpl.class.getName(), " brooklyn.flags:", " confName: Foo Bar"); Entity testEntity = Iterables.getOnlyElement(app.getChildren()); Assert.assertEquals(testEntity.getConfig(TestEntity.CONF_NAME), "Foo Bar"); }
@Test public void testWrapsAppIfNameAtTopLevelAndOnApp() throws Exception { String yaml = Joiner.on("\n").join( "name: myTopLevelName", "services:", "- serviceType: org.apache.brooklyn.core.test.entity.TestApplication", " name: myEntityName"); Entity app = createStartWaitAndLogApplication(yaml); assertNull(app.getConfig(EntityManagementUtils.WRAPPER_APP_MARKER)); assertEquals(app.getDisplayName(), "myTopLevelName"); assertEquals(app.getChildren().size(), 0); }
private void checkChildEntitySpec(Entity app, String entityName) { Collection<Entity> children = app.getChildren(); Assert.assertEquals(children.size(), 1); Entity child = Iterables.getOnlyElement(children); Assert.assertEquals(child.getDisplayName(), entityName); Assert.assertEquals(child.getEntityType().getName(), BasicEntity.class.getName()); } }
private void checkChildEntitySpec(Entity app, String entityName) { Collection<Entity> children = app.getChildren(); Assert.assertEquals(children.size(), 1); Entity child = Iterables.getOnlyElement(children); Assert.assertEquals(child.getDisplayName(), entityName); Assert.assertEquals(child.getEntityType().getName(), BasicEntity.class.getName()); }
protected Entity setupAndCheckTestEntityInBasicYamlWith(String ...extras) throws Exception { Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml", extras)); waitForApplicationTasks(app); Entities.dumpInfo(app); Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template"); log.info("App started:"); Entities.dumpInfo(app); Assert.assertTrue(app.getChildren().iterator().hasNext(), "Expected app to have child entity"); Entity entity = app.getChildren().iterator().next(); Assert.assertTrue(entity instanceof TestEntity, "Expected TestEntity, found " + entity.getClass()); return entity; }
@Test public void testEntityTypeAsImpl() throws Exception { String yaml = "services:"+"\n"+ "- type: "+CustomTestEntityImpl.class.getName()+"\n"; Entity app = createStartWaitAndLogApplication(yaml); Entity testEntity = Iterables.getOnlyElement(app.getChildren()); assertEquals(testEntity.getEntityType().getName(), "CustomTestEntityImpl"); }
@Test public void testReferenceAppYamlAsPlatformComponent() throws Exception { Entity app = createAndStartApplication( "services:", "- name: Reference child name", " type: classpath://yaml-ref-app.yaml"); Assert.assertEquals(app.getChildren().size(), 0); Assert.assertEquals(app.getDisplayName(), "Reference child name"); //child is a proxy so equality test won't do Assert.assertEquals(app.getEntityType().getName(), BasicApplication.class.getName()); }
@Test public void testConfigAppliedToCatalogItem() throws Exception { addCatalogOSGiEntity("test", TestEntity.class.getName()); String testName = "test-applies-config-on-catalog-item"; Entity app = createAndStartApplication( "services:", "- type: " + ver("test"), " brooklyn.config:", " test.confName: " + testName); Entity testEntity = Iterables.getOnlyElement(app.getChildren()); assertEquals(testEntity.config().get(TestEntity.CONF_NAME), testName); }
@Test public void testExplicitFlagsAppliesToCatalogItem() throws Exception { addCatalogOSGiEntity("test", TestEntity.class.getName()); String testName = "test-applies-config-on-catalog-item"; Entity app = createAndStartApplication( "services:", "- type: " + ver("test"), " brooklyn.flags:", " confName: " + testName); Entity testEntity = Iterables.getOnlyElement(app.getChildren()); assertEquals(testEntity.config().get(TestEntity.CONF_NAME), testName); }
@Test public void testExplicitFlagsAppliesToCatalogItemImpl() throws Exception { addCatalogOSGiEntity("test", TestEntityImpl.class.getName()); String testName = "test-applies-config-on-catalog-item"; Entity app = createAndStartApplication( "services:", "- type: " + ver("test"), " brooklyn.flags:", " confName: " + testName); Entity testEntity = Iterables.getOnlyElement(app.getChildren()); assertEquals(testEntity.config().get(TestEntity.CONF_NAME), testName); }
@Test public void testRefToSelf() throws Exception { Entity app = createAndStartApplication( "services:", "- type: " + TestEntity.class.getName(), " test.confObject: $brooklyn:self()", " test.confName: $brooklyn:self().attributeWhenReady(\"mysensor\")"); Entity entity = Iterables.getOnlyElement(app.getChildren()); assertEquals(entity.getConfig(TestEntity.CONF_OBJECT), entity); entity.sensors().set(Sensors.newStringSensor("mysensor"), "myval"); assertEquals(entity.getConfig(TestEntity.CONF_NAME), "myval"); }
private void registerAndLaunchAndAssertSimpleEntity(String symbolicName, String serviceType) throws Exception { addCatalogOSGiEntity(symbolicName, serviceType); String yaml = "name: simple-app-yaml\n" + "location: localhost\n" + "services: \n" + " - serviceType: "+ver(symbolicName); Entity app = createAndStartApplication(yaml); Entity simpleEntity = Iterables.getOnlyElement(app.getChildren()); assertEquals(simpleEntity.getEntityType().getName(), SIMPLE_ENTITY_TYPE); deleteCatalogEntity(symbolicName); }