public static Function<Entity, String> config(String keyName, String format) { return config(ConfigKeys.newConfigKey(Object.class, keyName), format); }
public static Function<Entity, Object> config(String keyName) { return config(ConfigKeys.newConfigKey(Object.class, keyName)); }
@Override public boolean apply(DockerHostLocation input) { Iterable<Entity> deployed = Iterables.filter( Iterables.transform(input.getDockerContainerList(), EntityFunctions.config(DockerContainer.ENTITY.getConfigKey())), Predicates.notNull()); return Iterables.size(deployed) > 0; } }
@Override public boolean apply(DockerHostLocation input) { Iterable<Entity> deployed = Iterables.filter( Iterables.transform(input.getDockerContainerList(), EntityFunctions.config(DockerContainer.ENTITY.getConfigKey())), Predicates.notNull()); Iterable<Entity> sameParent = Iterables.filter(deployed, EntityPredicates.isChildOf(parent)); if (Iterables.isEmpty(sameParent)) { LOG.debug("No entities with parent {} on {}", parent, input ); return false; } else { LOG.debug("Found entities with parent {} on {}", parent, input ); return true; } } }
@Override public boolean apply(DockerHostLocation input) { Iterable<Entity> deployed = Iterables.filter( Iterables.transform(input.getDockerContainerList(), EntityFunctions.config(DockerContainer.ENTITY.getConfigKey())), Predicates.notNull()); Iterable<Entity> sameApplication = Iterables.filter(deployed, EntityPredicates.applicationIdEqualTo(applicationId)); if (Iterables.isEmpty(sameApplication)) { LOG.debug("No entities with application id {} on {}", applicationId, input); return false; } else { LOG.debug("Found entities with application id {} on {}", applicationId, input); return true; } } }
@Test public void testConfig() throws Exception { entity.config().set(TestEntity.CONF_NAME, "myname"); assertEquals(EntityFunctions.config(TestEntity.CONF_NAME).apply(entity), "myname"); assertEquals(EntityFunctions.config(TestEntity.CONF_NAME.getName()).apply(entity), "myname"); assertEquals(EntityFunctions.config(TestEntity.CONF_NAME, "%s - suffix").apply(entity), "myname - suffix"); assertEquals(EntityFunctions.config(TestEntity.CONF_NAME.getName(), "%s - suffix").apply(entity), "myname - suffix"); assertNull(EntityFunctions.config(TestEntity.CONF_OBJECT).apply(entity)); }
private Maybe<Entity> getResolvedConfigInTask(final Entity entity, final ConfigKey<Entity> key) { return Tasks.resolving(Tasks.<Entity>builder().body( Functionals.callable(Suppliers.compose(EntityFunctions.config(key), Suppliers.ofInstance(entity))) ).build()) .as(Entity.class) .context(entity).embedResolutionInTask(true) .getMaybe(); }
@Test public void testErrorsResolvingPropagatesOrSwallowedAllCorrectly() throws Exception { app.config().set(TestEntity.CONF_OBJECT, ValueResolverTest.newThrowTask(Duration.ZERO)); Task<Object> t = Tasks.builder().body(Functionals.callable(EntityFunctions.config(TestEntity.CONF_OBJECT), app)).build(); ValueResolver<Object> v = Tasks.resolving(t).as(Object.class).context(app); ValueResolverTest.assertThrowsOnGetMaybe(v); ValueResolverTest.assertThrowsOnGet(v); v.swallowExceptions(); ValueResolverTest.assertMaybeIsAbsent(v); ValueResolverTest.assertThrowsOnGet(v); v.defaultValue("foo"); ValueResolverTest.assertMaybeIsAbsent(v); assertEquals(v.clone().get(), "foo"); assertResolvesValue(v, Object.class, "foo"); }