/** @deprecated since 0.7.0 use {@link #locationsIncludes(Location)} */ @Deprecated public static <T> Predicate<Entity> withLocation(final Location location) { return locationsIncludes(location); }
@Test public void testWithLocation() throws Exception { entity.addLocations(ImmutableList.of(loc)); assertTrue(EntityPredicates.locationsIncludes(loc).apply(entity)); assertFalse(EntityPredicates.locationsIncludes(loc).apply(app)); }
@Override public List<DockerHostLocation> filterLocations(List<DockerHostLocation> locations, Entity entity) { List<DockerHostLocation> available = Lists.newArrayList(); // Select hosts that satisfy the affinity rules for (DockerHostLocation machine : locations) { Optional<List<String>> entityRules = Optional.fromNullable(entity.config().get(DockerHost.DOCKER_HOST_AFFINITY_RULES)); Optional<List<String>> hostRules = Optional.fromNullable(machine.getOwner().config().get(DockerHost.DOCKER_HOST_AFFINITY_RULES)); Optional<List<String>> infrastructureRules = Optional.fromNullable(machine.getOwner().getInfrastructure().config().get(DockerHost.DOCKER_HOST_AFFINITY_RULES)); Iterable<String> combined = Iterables.concat(Optional.presentInstances(ImmutableList.of(entityRules, hostRules, infrastructureRules))); AffinityRules rules = AffinityRules.rulesFor(entity).parse(combined); Iterable<Entity> entities = getBrooklynManagementContext().getEntityManager().findEntities(EntityPredicates.locationsIncludes(machine)); if (Iterables.isEmpty(entities)) { if (rules.allowEmptyLocations()) { available.add(machine); } } else { Iterable<Entity> filtered = Iterables.filter(entities, rules); if (Iterables.size(filtered) == Iterables.size(entities)) { available.add(machine); } } } if (LOG.isDebugEnabled()) { LOG.debug("Available Docker hosts: {}", Iterables.toString(available)); } return available; }