@Override public Collection<Entity> findEntities(Predicate<? super Entity> filter) { if (isInitialManagementContextReal()) { return initialManagementContext.getEntityManager().findEntities(filter); } else { return Collections.emptyList(); } }
@Test public void testGetEntities() { TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity child = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); Asserts.assertEqualsIgnoringOrder(entityManager.getEntitiesInApplication(app), ImmutableList.of(app, entity, child)); Asserts.assertEqualsIgnoringOrder(entityManager.getEntities(), ImmutableList.of(app, entity, child, app2)); Asserts.assertEqualsIgnoringOrder(entityManager.findEntities(Predicates.instanceOf(TestApplication.class)), ImmutableList.of(app, app2)); Asserts.assertEqualsIgnoringOrder(entityManager.findEntitiesInApplication(app, Predicates.instanceOf(TestApplication.class)), ImmutableList.of(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; }
@Test public void testConcurrentAddChild() throws Exception { final int NUM_TASKS = 100; List<ListenableFuture<?>> futures = Lists.newArrayList(); for (int i = 0; i < NUM_TASKS; i++) { ListenableFuture<?> future = executor.submit(new Runnable() { @Override public void run() { entity.addChild(EntitySpec.create(BasicEntity.class)); }}); futures.add(future); } Futures.allAsList(futures).get(); assertEquals(entity.getChildren().size(), NUM_TASKS); Asserts.assertEqualsIgnoringOrder(entity.getChildren(), mgmt.getEntityManager().findEntities(Predicates.instanceOf(BasicEntity.class))); }
protected void assertSize(int targetSize, int quarantineSize) { assertEquals(cluster.getCurrentSize(), (Integer) targetSize, "cluster.currentSize"); assertEquals(cluster.getMembers().size(), targetSize, "cluster.members.size"); assertEquals(cluster.sensors().get(DynamicCluster.QUARANTINE_GROUP).getMembers().size(), quarantineSize, "cluster.quarantine.size"); assertEquals(mgmt.getEntityManager().findEntities(Predicates.instanceOf(EmptySoftwareProcess.class)).size(), targetSize + quarantineSize, "instanceCount(EmptySoftwareProcess)"); }