@Override public boolean apply(@Nullable Entity input) { return (input != null && input.getDisplayName() != null) && input.getDisplayName().matches(regex); } @Override
@Override public boolean apply(@Nullable Entity input) { return (input != null) && Objects.equal(input.getDisplayName(), val); } };
@Override public boolean apply(@Nullable Entity input) { return (input != null) && condition.apply(input.getDisplayName()); } @Override
@Override public boolean apply(@Nullable Entity input) { return input.getDisplayName().toLowerCase(Locale.ENGLISH).contains(parameter.toLowerCase(Locale.ENGLISH)); } };
protected static String shortName(Object x) { if (x instanceof HasShortName) { return ((HasShortName)x).getShortName(); } if (x instanceof Entity) { return ((Entity)x).getDisplayName(); } return x.toString(); }
@Override public boolean apply(Entity input) { return "2".equals(input.getDisplayName()); }})); itemGroup.setContainers(containerGroup);
private String nameOfEntity(Entity entity) { String name = entity.getDisplayName(); if (name.contains(entity.getId())) return name; else return name + " ("+entity.getId()+")"; }
@Override public void onException(Exception exception) { log.error("Detected exception while retrieving Chef attributes from entity " + entity.getDisplayName(), exception); for (AttributeSensor<?> attribute : chefAttributeSensors.values()) { if (!attribute.getName().startsWith(CHEF_ATTRIBUTE_PREFIX)) continue; entity.sensors().set(attribute, null); } }
/** 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; }
@Override public String getDisplayName() { Entity container = sensors().get(DockerContainer.CONTAINER); if (container != null) { return container.getDisplayName(); } else { return "Container"; } }
private List<Map<String, String>> entitiesIdAndNameAsList(Collection<? extends Entity> entities) { List<Map<String, String>> members = Lists.newArrayList(); for (Entity entity : entities) { if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) { members.add(ImmutableMap.of("id", entity.getId(), "name", entity.getDisplayName())); } } return members; }
@Override public void onException(Exception exception) { log.error("Detected exception while retrieving Windows Performance Counters from entity " + entity.getDisplayName(), exception); for (WindowsPerformanceCounterPollConfig<?> config : polls) { entity.sensors().set(Sensors.newSensor(config.getSensor().getClass(), config.getPerformanceCounterName(), config.getDescription()), null); } }
@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()); } }
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 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()); }
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 testSimpleXmlPlanParse() { EntitySpec<? extends Application> appSpec = EntityManagementUtils.createEntitySpecForApplication(mgmt, "<root><a_kid foo=\"bar\"/></root>"); Application app = EntityManagementUtils.createStarting(mgmt, appSpec).get(); Entities.dumpInfo(app); Assert.assertEquals(app.getDisplayName(), "root"); Entity child = Iterables.getOnlyElement(app.getChildren()); Assert.assertEquals(child.getDisplayName(), "a_kid"); Assert.assertEquals(child.config().get(ConfigKeys.newStringConfigKey("foo")), "bar"); }
@Test public void testAppSpecXmlPlanParse() { EntitySpec<? extends Application> appSpec = EntityManagementUtils.createEntitySpecForApplication(mgmt, "<root><a_kid foo=\"bar\"/></root>"); Application app = EntityManagementUtils.createStarting(mgmt, appSpec).get(); Entities.dumpInfo(app); Assert.assertEquals(app.getDisplayName(), "root"); Entity child = Iterables.getOnlyElement(app.getChildren()); Assert.assertEquals(child.getDisplayName(), "a_kid"); Assert.assertEquals(child.config().get(ConfigKeys.newStringConfigKey("foo")), "bar"); }