org.apache.brooklyn.api.mgmt.EntityManager.findEntities()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中org.apache.brooklyn.api.mgmt.EntityManager.findEntities()方法的一些代码示例,展示了EntityManager.findEntities()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.findEntities()方法的具体详情如下:
包路径:org.apache.brooklyn.api.mgmt.EntityManager
类名称:EntityManager
方法名:findEntities

EntityManager.findEntities介绍

[英]All entities under control of this management plane that match the given filter
[中]受此管理平面控制且与给定筛选器匹配的所有实体

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
public Collection<Entity> findEntities(Predicate<? super Entity> filter) {
  if (isInitialManagementContextReal()) {
    return initialManagementContext.getEntityManager().findEntities(filter);
  } else {
    return Collections.emptyList();
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@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));
}

代码示例来源:origin: io.brooklyn.clocker/brooklyn-clocker-docker

@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;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@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)));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

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)");
}

相关文章