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

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

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

EntityManager.getEntity介绍

[英]Returns the entity with the given identifier (may be a full instance, or a proxy to one which is remote), or null.
[中]返回具有给定标识符的实体(可以是完整实例,也可以是远程实例的代理)或null。

代码示例

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

@Override
@SuppressWarnings("unchecked")
public <T extends BrooklynObject> T lookup(String id, Class<T> type) {
  Object result;
  result = getEntityManager().getEntity(id);
  if (result!=null && type.isInstance(result)) return (T)result;
  
  result = getLocationManager().getLocation(id);
  if (result!=null && type.isInstance(result)) return (T)result;
  // TODO policies, enrichers, feeds; bundles?
  return null;
}

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

@Override
public Entity getEntity(String id) {
  if (isInitialManagementContextReal()) {
    return initialManagementContext.getEntityManager().getEntity(id);
  } else {
    return null;
  }
}

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

@Override
public InetAddress getNextAgentAddress(String agentId) {
  Entity agent = getManagementContext().getEntityManager().getEntity(agentId);
  String address = agent.sensors().get(CalicoNode.DOCKER_HOST).sensors().get(Attributes.SUBNET_ADDRESS);
  try {
    return InetAddress.getByName(address);
  } catch (UnknownHostException uhe) {
    throw Exceptions.propagate(uhe);
  }
}

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

@Override
public InetAddress getNextAgentAddress(String agentId) {
  Entity agent = getManagementContext().getEntityManager().getEntity(agentId);
  String address = agent.sensors().get(OverlayPlugin.DOCKER_HOST).sensors().get(Attributes.SUBNET_ADDRESS);
  try {
    return InetAddress.getByName(address);
  } catch (UnknownHostException uhe) {
    throw Exceptions.propagate(uhe);
  }
}

代码示例来源: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 testAutoCheckpointsOnUnmanageEntity() throws Exception {
  Entities.unmanage(origE);
  
  newApp = rebind();
  
  // Assert does not container unmanaged entity
  assertEquals(ImmutableList.copyOf(newApp.getChildren()), Collections.emptyList());
  assertNull(((EntityInternal)newApp).getManagementContext().getEntityManager().getEntity(origE.getId()));
}

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

@SuppressWarnings("unchecked")
protected <T extends Entity> T rebind(T entity) throws Exception {
  rebind();
  Entity result = mgmt().getEntityManager().getEntity(entity.getId());
  assertNotNull(result, "no entity found after rebind with id " + entity.getId());
  return (T) result;
}

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

@Test
public void testReplacesMember() throws Exception {
  DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
      .configure("initialSize", 1)
      .configure("memberSpec", EntitySpec.create(TestEntity.class)));
  cluster.start(ImmutableList.of(loc));
  Entity member = Iterables.get(cluster.getMembers(), 0);
  String replacementId = cluster.replaceMember(member.getId());
  Entity replacement = app.getManagementContext().getEntityManager().getEntity(replacementId);
  assertEquals(cluster.getMembers().size(), 1);
  assertFalse(cluster.getMembers().contains(member));
  assertFalse(cluster.getChildren().contains(member));
  assertNotNull(replacement, "replacementId="+replacementId);
  assertTrue(cluster.getMembers().contains(replacement), "replacement="+replacement+"; members="+cluster.getMembers());
  assertTrue(cluster.getChildren().contains(replacement), "replacement="+replacement+"; children="+cluster.getChildren());
}

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

@Test
public void testDslAttributeWhenReady_2016_07() throws Exception {
  String entityId = "klcueb1ide";
  doAddEntityMemento("2016-07", entityId);
  
  rebind();
  Entity newEntity = mgmt().getEntityManager().getEntity(entityId);
  
  String val = newEntity.config().get(attributeWhenReady1);
  assertEquals(val, "myval");
}

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

@Test
public void testDslConfigSupplier_2016_07() throws Exception {
  String entityId = "klcueb1ide";
  doAddEntityMemento("2016-07", entityId);
  
  rebind();
  Entity newEntity = mgmt().getEntityManager().getEntity(entityId);
  
  String val = newEntity.config().get(configSupplier1);
  assertEquals(val, "myval");
}

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

@Test
public void testDslConfigSupplier() throws Exception {
  final Entity app = createAndStartApplication(
      "services:",
      "- type: " + BasicApplication.class.getName(),
      "  brooklyn.config:",
      "    myConfigKeyName: myval",
      "    " + configSupplier1.getName() + ": $brooklyn:config(\"myConfigKeyName\")");
  
  rebind();
  Entity newEntity = mgmt().getEntityManager().getEntity(app.getId());
  
  String val = newEntity.config().get(configSupplier1);
  assertEquals(val, "myval");
}

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

@Test
public void testDslSensorSupplier_2016_07() throws Exception {
  String entityId = "klcueb1ide";
  doAddEntityMemento("2016-07", entityId);
  
  rebind();
  Entity newEntity = mgmt().getEntityManager().getEntity(entityId);
  
  Sensor<?> sensor = newEntity.config().get(sensorSupplier1);
  assertEquals(sensor.getName(), "mySensorName");
}

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

@Test
public void testUsingDeprecatedName() throws Exception {
  MyApp entity = app().addChild(EntitySpec.create(MyApp.class)
      .configure("oldKey1", "myval"));
  assertEquals(entity.config().get(MyApp.KEY_1), "myval");
  
  rebind();
  
  Entity newEntity = mgmt().getEntityManager().getEntity(entity.getId());
  assertEquals(newEntity.config().get(MyApp.KEY_1), "myval");
  
  // Expect the persisted state of the entity to have used the non-deprecated name.
  String allLines = getPersistanceFileContents(BrooklynObjectType.ENTITY, newEntity.getId());
  assertFalse(allLines.contains("oldKey1"), "contains 'oldKey1', allLines="+allLines);
  assertTrue(allLines.contains("key1"), "contains 'key1', allLines="+allLines);
}

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

@Test
public void testDslSensorSupplier() throws Exception {
  final Entity app = createAndStartApplication(
      "services:",
      "- type: " + BasicApplication.class.getName(),
      "  brooklyn.config:",
      "    " + sensorSupplier1.getName() + ": $brooklyn:sensor(\"mySensorName\")");
  
  rebind();
  Entity newEntity = mgmt().getEntityManager().getEntity(app.getId());
  
  Sensor<?> sensor = newEntity.config().get(sensorSupplier1);
  assertEquals(sensor.getName(), "mySensorName");
}

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

@Test
public void testCreateEntitiesWithDuplicateIdFails() {
  TestApplication origApp = app;
  Entity origDeproxiedApp = Entities.deproxy(app);
  
  try {
    TestApplication app2 = ((EntityManagerInternal)entityManager).createEntity(EntitySpec.create(TestApplication.class), Optional.of(app.getId()));
    Asserts.shouldHaveFailedPreviously("app2="+app2);
  } catch (IdAlreadyExistsException e) {
    // success
  }
  
  // Should not have affected the existing app!
  Entity postApp = entityManager.getEntity(app.getId());
  assertSame(postApp, origApp);
  assertSame(Entities.deproxy(postApp), origDeproxiedApp);
}

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

@Test
public void testRebindToMachineEntity() throws Exception {
  MachineEntity entity = origApp.createAndManageChild(EntitySpec.create(MachineEntity.class)
      .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true));
  origApp.start(ImmutableList.of(origMachine));
  EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
  
  rebind();
  
  Entity newEntity = mgmt().getEntityManager().getEntity(entity.getId());
  EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
}

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

@Test
public void testCreateAndManageChild() {
  TestEntity result = entity.createAndManageChild(EntitySpec.create(TestEntity.class));
  assertIsProxy(result);
  assertIsProxy(Iterables.get(entity.getChildren(), 0));
  assertIsProxy(result.getParent());
  assertIsProxy(mgmt.getEntityManager().getEntity(result.getId()));
}

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

@Test(groups={"Integration", "WIP", "Broken"})
public void testJavaWebWithMemberSpecRebind() throws Exception {
  Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("test-java-web-app-spec-and-db-with-function.yaml"));
  AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input);
  Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform);
  final Application app = (Application) mgmt().getEntityManager().getEntity(assembly.getId());
  Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app);
  for (Task<?> t: tasks) t.blockUntilEnded();
  Entities.dumpInfo(app);
  
  Application app2 = rebind(app);
  Assert.assertEquals(app2.getChildren().size(), 2);
}

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

/** as {@link JavaWebAppsIntegrationTest#testWithDbDeploy()} but with rebind */
@Test(groups={"Integration", "WIP", "Broken"})
public void testJavaWebAppDeployAndRebind() throws Exception {
  Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("java-web-app-and-db-with-function.yaml"));
  AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input);
  Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform);
  final Application app = (Application) mgmt().getEntityManager().getEntity(assembly.getId());
  Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app);
  for (Task<?> t: tasks) t.blockUntilEnded();
  Entities.dumpInfo(app);
  Application app2 = rebind(app);
  Assert.assertEquals(app2.getChildren().size(), 2);
}

相关文章