@Test public void testTagWithDslValue() throws Exception { Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.tags:", " - $brooklyn:literal(\"myval\")"); assertTrue(app.tags().getTags().contains("myval")); }
@Test public void testBrooklynCampSingleTag() throws Exception { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.tags:", " - hi"); assertTrue(app.tags().getTags().contains("hi")); }
@Test public void testBrooklynCampKnowsIntegerTags() throws Exception { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.tags:", " - tag1", " - 3"); assertTrue(app.tags().getTags().contains(3)); assertTrue(app.tags().getTags().contains("tag1")); }
private void unmanageOwnedLocations(Entity e) { for (Location loc : e.getLocations()) { NamedStringTag ownerEntityTag = BrooklynTags.findFirst(BrooklynTags.OWNER_ENTITY_ID, loc.tags().getTags()); if (ownerEntityTag != null) { if (e.getId().equals(ownerEntityTag.getContents())) { managementContext.getLocationManager().unmanage(loc); } else { // A location is "owned" if it was created as part of the EntitySpec of an entity (by Brooklyn). // To share a location between entities create it yourself and pass it to any entities that needs it. log.debug("Unmanaging entity {}, which contains a location {} owned by another entity {}. " + "Not automatically unmanaging the location (it will be unmanaged when its owning " + "entity is unmanaged).", new Object[] {e, loc, ownerEntityTag.getContents()}); } } } }
private void assertNotOwned(Location loc) { NamedStringTag ownerEntityTag = BrooklynTags.findFirst(BrooklynTags.OWNER_ENTITY_ID, loc.tags().getTags()); Assert.assertNull(ownerEntityTag); }
@Test public void testBrooklynCampMultipleTags() throws Exception { final Entity app = createAndStartApplication( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.tags:", " - tag1", " - \"2\"", " - \"- 3\""); assertTrue(app.tags().getTags().contains("tag1")); assertTrue(app.tags().getTags().contains("2")); assertTrue(app.tags().getTags().contains("- 3")); }
@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())); }
@Override public String getSpec(String applicationToken, String entityToken) { Entity entity = brooklyn().getEntity(applicationToken, entityToken); NamedStringTag spec = BrooklynTags.findFirst(BrooklynTags.YAML_SPEC_KIND, entity.tags().getTags()); if (spec == null) return null; return (String) WebResourceUtils.getValueForDisplay(spec.getContents(), false, true); } }
private void testLocationUnmanagedOnStop(LocationSpec<? extends Location> locationSpec) { EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class) .location(locationSpec); BasicApplication app = mgmt.getEntityManager().createEntity(appSpec); app.start(ImmutableList.<Location>of()); Location appLocation = Iterables.getOnlyElement(app.getLocations()); NamedStringTag ownerEntityTag = BrooklynTags.findFirst(BrooklynTags.OWNER_ENTITY_ID, appLocation.tags().getTags()); Assert.assertNotNull(ownerEntityTag); Assert.assertEquals(ownerEntityTag.getContents(), app.getId()); app.stop(); Assert.assertFalse(mgmt.getEntityManager().isManaged(app)); Set<Location> locs = ImmutableSet.copyOf(mgmt.getLocationManager().getLocations()); Assert.assertFalse(locs.contains(appLocation), locs + " should not contain " + appLocation); }
public static String getIconUrl(BrooklynObject object) { if (object==null) return null; NamedStringTag fromTag = BrooklynTags.findFirst(BrooklynTags.ICON_URL, object.tags().getTags()); if (fromTag!=null) return fromTag.getContents(); ManagementContext mgmt = ((BrooklynObjectInternal)object).getManagementContext(); if (mgmt==null) return null; BrooklynTypeRegistry registry = mgmt.getTypeRegistry(); if (registry==null) return null; RegisteredType item = registry.get( object.getCatalogItemId() ); if (item==null) return null; return item.getIconUrl(); }
/** @deprecated since 0.12.0 use {@link RegisteredType} methods instead */ @Deprecated public static CatalogLocationSummary catalogLocationSummary(BrooklynRestResourceUtils b, CatalogItem<? extends Location,LocationSpec<?>> item, UriBuilder ub) { Set<LocationConfigSummary> config = ImmutableSet.of(); return new CatalogLocationSummary(item.getSymbolicName(), item.getVersion(), item.getContainingBundle(), item.getDisplayName(), item.getJavaType(), item.getCatalogItemType().toString(), item.getPlanYaml(), item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), config, item.tags().getTags(), item.isDeprecated(), makeLinks(item, ub)); }
private void assertOwned(BasicApplication app, Location loc) { NamedStringTag ownerEntityTag = BrooklynTags.findFirst(BrooklynTags.OWNER_ENTITY_ID, loc.tags().getTags()); Assert.assertNotNull(ownerEntityTag); Assert.assertEquals(ownerEntityTag.getContents(), app.getId()); }
@Test public void testLocationTags() throws Exception { LocationInternal loc = mgmt.getLocationManager().createLocation(LocationSpec.create(ConcreteLocation.class).tag("x")); assertEquals(loc.tags().getTags(), MutableSet.of("x")); }
private static Set<Object> makeTags(EntitySpec<?> spec, CatalogItem<?, ?> item) { return makeTags(spec, MutableSet.copyOf(item.tags().getTags())); } private static Set<Object> makeTags(EntitySpec<?> spec, Set<Object> tags) {
@Test public void testPolicyTags() throws Exception { Enricher origEnricher = origApp.enrichers().add(EnricherSpec.create(MyEnricher.class)); origEnricher.tags().addTag("foo"); origEnricher.tags().addTag(origApp); newApp = rebind(); Enricher newEnricher = Iterables.getOnlyElement(newApp.enrichers()); Asserts.assertEqualsIgnoringOrder(newEnricher.tags().getTags(), ImmutableSet.of("foo", newApp)); }
@Test public void testLocationTags() throws Exception { Location origLoc = origManagementContext.getLocationManager().createLocation(LocationSpec.create(MyLocation.class)); origLoc.tags().addTag("foo"); origLoc.tags().addTag(origApp); origApp.start(ImmutableList.of(origLoc)); newApp = rebind(); Location newLoc = newManagementContext.getLocationManager().getLocation(origLoc.getId()); Asserts.assertEqualsIgnoringOrder(newLoc.tags().getTags(), ImmutableSet.of("foo", newApp)); }
@Test public void testTagsFromSpec() throws Exception { MyPolicy policy = app.policies().add(PolicySpec.create(MyPolicy.class).tag(99).uniqueTag("x")); assertEquals(policy.tags().getTags(), MutableSet.of("x", 99)); assertEquals(policy.getUniqueTag(), "x"); }
@Test public void testTagsFromSpec() throws Exception { MyEnricher enricher = app.enrichers().add(EnricherSpec.create(MyEnricher.class).tag(99).uniqueTag("x")); assertEquals(enricher.tags().getTags(), MutableSet.of("x", 99)); assertEquals(enricher.getUniqueTag(), "x"); }
@SuppressWarnings("unchecked") @Override public List<Object> listTags(String applicationId, String entityId) { Entity entity = brooklyn().getEntity(applicationId, entityId); return (List<Object>) resolving(MutableList.copyOf(entity.tags().getTags())).preferJson(true).resolve(); }
@Test public void testPolicyTags() throws Exception { Policy origPolicy = origApp.policies().add(PolicySpec.create(MyPolicy.class)); origPolicy.tags().addTag("foo"); origPolicy.tags().addTag(origApp); newApp = rebind(); Policy newPolicy = Iterables.getOnlyElement(newApp.policies()); Asserts.assertEqualsIgnoringOrder(newPolicy.tags().getTags(), ImmutableSet.of("foo", newApp)); }