org.apache.brooklyn.api.mgmt.EntityManager类的使用及代码示例

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

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

EntityManager介绍

[英]For managing and querying entities.
[中]用于管理和查询实体。

代码示例

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

protected void createApps() {
  for (EntitySpec<? extends Application> spec : appSpecsToManage) {
    Application app = managementContext.getEntityManager().createEntity(spec);
    apps.add(app);
  }
  for (String blueprint : yamlAppsToManage) {
    Application app = EntityManagementUtils.createUnstarted(managementContext, blueprint);
    // Note: BrooklynAssemblyTemplateInstantiator automatically puts applications under management.
    apps.add(app);
  }
}

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

@Override
public Collection<Entity> getEntities() {
  if (isInitialManagementContextReal()) {
    return initialManagementContext.getEntityManager().getEntities();
  } else {
    return Collections.emptyList();
  }
}

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

@Override
protected T customReadBody(String type, Map<Object, Object> values, JsonParser jp, DeserializationContext ctxt) throws IOException {
  Optional<String> entityId = Optional.fromNullable((String) values.get("entityId"));
  Optional<Entity> entity = Optional.fromNullable(entityId.isPresent() ? null: mgmt.getEntityManager().getEntity(entityId.get()));
  String id = (String) values.get("id");
  return getInstanceFromId(entity, id);
}
protected Optional<String> getEntityId(T value) {

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

@Test
public void testEntityManagerQueriesGiveProxies() {
  EntityManager entityManager = mgmt.getEntityManager();
  
  Application retrievedApp = (Application) entityManager.getEntity(app.getId());
  TestEntity retrievedEntity = (TestEntity) entityManager.getEntity(entity.getId());
  assertIsProxy(retrievedApp);
  assertIsProxy(retrievedEntity);
  
  Collection<Entity> entities = entityManager.getEntities();
  for (Entity e : entities) {
    assertIsProxy(e);
  }
  assertEquals(ImmutableSet.copyOf(entities), ImmutableSet.of(app, entity));
}

代码示例来源: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: org.apache.brooklyn/brooklyn-core

mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
  fail();
} catch (Exception e) {
TestEntity e3 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
assertEquals(ImmutableSet.copyOf(mgmt.getEntityManager().getEntities()), ImmutableSet.of(app, e1, e3));

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

final TestApplication app = mgmt().getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
final TestApplication newApp = (TestApplication) mgmt().getEntityManager().getEntity(app.getId());
final RecordingStaticUsageListener newListener = RecordingStaticUsageListener.getLastInstance();
assertNotSame(origListener, newListener);

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

@Test(groups="Broken")
public void testStartsThenChildFailsButWithQuorumCausesAppToSucceed() throws Exception {
  TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
      .configure(StartableApplication.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne())
      .configure(StartableApplication.RUNNING_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne())
      .child(EntitySpec.create(TestEntity.class))
      .child(EntitySpec.create(TestEntity.class)));
  TestEntity child = (TestEntity) Iterables.get(app.getChildren(), 0);
  
  app.start(ImmutableList.<Location>of());
  assertUpAndRunningEventually(app);
  
  for (Entity childr : app.getChildren()) {
    EntityAsserts.assertAttributeEquals(childr, TestEntity.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
  }
  ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(child, "myIndicator", "Simulate not-up of child");
  assertHealthContinually(app, Lifecycle.RUNNING, true);
  mgmt.getEntityManager().unmanage(app);
}

代码示例来源: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-rest-resources

@Override
  public void run() {
    ((EntityInternal)application).destroy();
    mgmt.getEntityManager().unmanage(application);
  }
});

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

@Override
public Collection<Entity> getEntitiesInApplication(Application application) {
  if (isInitialManagementContextReal()) {
    return initialManagementContext.getEntityManager().getEntitiesInApplication(application);
  } else {
    return Collections.emptyList();
  }
}

代码示例来源: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-rest-resources

@Override
  public void run() {
    if (release)
      Entities.destroyCatching(entity);
    else
      mgmt.getEntityManager().unmanage(entity);
  }
});

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

@Test(groups = "Integration")
private void testReadAndWriteDifferentRouters() {
  MongoDBShardedDeployment deployment = makeAndStartDeployment();
  EntityAsserts.assertAttributeEqualsEventually(deployment, Startable.SERVICE_UP, true);
  MongoDBRouter router1 = (MongoDBRouter) Iterables.get(deployment.getRouterCluster().getMembers(), 0);
  MongoDBRouter router2 = (MongoDBRouter) Iterables.get(deployment.getRouterCluster().getMembers(), 1);
  EntityAsserts.assertAttributeEqualsEventually(router1, Startable.SERVICE_UP, true);
  EntityAsserts.assertAttributeEqualsEventually(router2, Startable.SERVICE_UP, true);
  
  String documentId = MongoDBTestHelper.insert(router1, "meaning-of-life", 42);
  DBObject docOut = MongoDBTestHelper.getById(router2, documentId);
  Assert.assertEquals(docOut.get("meaning-of-life"), 42);
  
  for (Entity entity : Iterables.filter(app.getManagementContext().getEntityManager().getEntitiesInApplication(app), AbstractMongoDBServer.class)) {
    EntityAsserts.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, true);
  }
}

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

@Override
public <T extends Entity> T createEntity(EntitySpec<T> spec) {
  if (isInitialManagementContextReal()) {
    return initialManagementContext.getEntityManager().createEntity(spec);
  } else {
    throw new IllegalStateException("Non-deployment context "+this+" (with no initial management context supplied) is not valid for this operation.");
  }
}

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

@Override public void run() {
      Set<FailingEntity> all = ImmutableSet.copyOf(Iterables.filter(mgmt.getEntityManager().getEntities(), FailingEntity.class));
      Set<FailingEntity> replacements = Sets.difference(all, initialMembers);
      assertEquals(replacements.size(), 4);
    }});
}

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

@Override protected Entity getInstanceFromId(String id) { return mgmt.getEntityManager().getEntity(id); }
}

代码示例来源: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-core

public static void unmanage(Entity entity) {
  if (((EntityInternal)entity).getManagementSupport().isDeployed()) {
    ((EntityInternal)entity).getManagementContext().getEntityManager().unmanage(entity);
  }
}

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

@Test
public void testLoadEntityFromClasspath() throws Exception {
  String entityName = ExampleEntity.class.getName();
  Object appSpec = loadApplicationFromClasspathOrParse(entityName);
  assertTrue(appSpec instanceof EntitySpec, "app="+appSpec);
  
  mgmt = LocalManagementContextForTests.newInstance();
  app = (Application) mgmt.getEntityManager().createEntity((EntitySpec<?>)appSpec);
  Collection<Entity> entities = app.getChildren();
  assertEquals(entities.size(), 1, "entities="+entities);
  assertTrue(Iterables.getOnlyElement(entities) instanceof ExampleEntity, "entities="+entities+"; ifs="+Iterables.getOnlyElement(entities).getClass().getInterfaces());
  assertTrue(Iterables.getOnlyElement(entities) instanceof EntityProxy, "entities="+entities);
}

相关文章