@Override public boolean apply(Entity input) { Entity delegate = input.getConfig(DelegateEntity.DELEGATE_ENTITY); if (delegate == null) return false; return delegate.equals(member); } });
@Override public boolean apply(@Nullable Entity input) { return (input != null) && Objects.equal(input.getConfig(configKey), val); } };
@Override public boolean apply(@Nullable Entity input) { return (input != null) && condition.apply(input.getConfig(configKey)); } @Override
public static <T> T getRequiredConfig(Entity entity, ConfigKey<T> key) { return Preconditions.checkNotNull( Preconditions.checkNotNull(entity, "Entity must be supplied").getConfig(key), "Key "+key+" is required on "+entity); }
@Override public Object call() { return entities[1].getConfig(TestEntity.CONF_OBJECT); }}).get(); Assert.assertNotNull(object);
@Override public Object call() throws Exception { return testEntity.getConfig(TestEntity.CONF_MAP_PLAIN); } }).build()).get();
public static void waitForServiceUp(final Entity entity) { Duration timeout = entity.getConfig(BrooklynConfigKeys.START_TIMEOUT); waitForServiceUp(entity, timeout); }
/** Fails-fast if value of the given key is null or unresolveable. */ public static String getRequiredUrlConfig(Entity entity, ConfigKey<String> urlKey) { String url = entity.getConfig(urlKey); Preconditions.checkNotNull(url, "Key %s on %s should not be null", urlKey, entity); if (!ResourceUtils.create(entity).doesUrlExist(url)) { throw new IllegalStateException(String.format("Key %s on %s contains unavailable URL %s", urlKey, entity, url)); } return url; }
/** @return provisioning flags for the given entity */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected Map<String,Object> obtainProvisioningFlags(Entity entity, MachineProvisioningLocation location) { Map<String,Object> result = Maps.newLinkedHashMap(); result.putAll(Maps.newLinkedHashMap(location.getProvisioningFlags(ImmutableList.of(entity.getEntityType().getName())))); result.putAll(entity.getConfig(SameServerEntity.PROVISIONING_PROPERTIES)); for (Entity child : entity.getChildren()) { result.putAll(obtainProvisioningFlags(child, location)); } return result; }
/** Logs a warning if an entity has a value for a config key. */ public static void warnOnIgnoringConfig(Entity entity, ConfigKey<?> key) { if (((EntityInternal)entity).config().getRaw(key).isPresentAndNonNull()) log.warn("Ignoring "+key+" set on "+entity+" ("+entity.getConfig(key)+")"); }
@Test public void testConfigKeysInheritance() throws Exception { Entity child = setupBasicInheritanceTest(); Assert.assertNotNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.HERITABLE_BY_DEFAULT)); Assert.assertNotNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.ALWAYS_HERITABLE)); Assert.assertNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.NEVER_INHERIT)); // it's reinheritable unless explicitly declared Assert.assertNotNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.NOT_REINHERITABLE)); app.getMutableEntityType().addConfigKey(MyEntityWithPartiallyHeritableConfig.NOT_REINHERITABLE); Assert.assertNull(child.getConfig(MyEntityWithPartiallyHeritableConfig.NOT_REINHERITABLE)); }
static void addToWarsByContext(Entity entity, String url, String targetName) { targetName = FILENAME_TO_WEB_CONTEXT_MAPPER.convertDeploymentTargetNameToContext(targetName); // TODO a better way to do atomic updates, see comment above synchronized (entity) { Map<String,String> newWarsMap = MutableMap.copyOf(entity.getConfig(WARS_BY_CONTEXT)); newWarsMap.put(targetName, url); entity.config().set(WARS_BY_CONTEXT, newWarsMap); } }
@SuppressWarnings("unchecked") protected <T> T getTestKeyFromEntityMemento(String label, String entityId, Class<T> type) throws Exception { Entity e = loadEntityMemento(label, entityId); return (T) e.getConfig(TEST_KEY); }
@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); }
@Test public void testAddChildrenWithConfig() throws Exception { Entity child = makeAppAndAddChild(true, MutableMap.<String,Object>of(), "blueprint_yaml: |", " services:", " - type: "+BasicEntity.class.getName(), " brooklyn.config:", " p.child: $brooklyn:config(\"p.parent\")"); Assert.assertEquals(child.getConfig(ConfigKeys.newStringConfigKey("p.param1")), "default"); Assert.assertEquals(child.getConfig(ConfigKeys.newStringConfigKey("p.child")), "parent"); }
@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"); }
@Test(enabled=false) public void testSetConfigKeyAsEmptySet() throws Exception { Entity entity2 = app.createAndManageChild(EntitySpec.create(TestEntity.class) .configure(TestEntity.CONF_SET_THING.getName(), ImmutableSet.<String>of())); Entity entity3 = app.createAndManageChild(EntitySpec.create(TestEntity.class) .configure(TestEntity.CONF_SET_THING, ImmutableSet.<String>of())); app.start(locs); assertEquals(entity3.getConfig(TestEntity.CONF_SET_THING), ImmutableSet.of()); assertEquals(entity2.getConfig(TestEntity.CONF_SET_THING), ImmutableSet.of()); }