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

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

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

EntityManager.createEntity介绍

[英]Convenience (particularly for groovy code) to create an entity. Equivalent to createEntity(EntitySpec.create(type).configure(config))
[中]创建实体的便利性(特别是groovy代码)。等效于createEntity(EntitySpec.create(类型))。配置(配置)

代码示例

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

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

@BeforeMethod(alwaysRun=true)
@Override
public void setUp() throws Exception {
  super.setUp();
  app = mgmt.getEntityManager().createEntity(EntitySpec.create(AsyncApplication.class));
}

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

@Test
public void testStartManagementFailsIfAppDeleted() throws Exception {
  TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
  Entities.unmanage(app2);
  
  try {
    Entities.startManagement(app2, mgmt);
    fail("Managed deleted app "+app2+" in "+mgmt);
  } catch (IllegalStateException e) {
    if (!(e.toString().contains("No concrete entity known"))) throw e;
  }
}

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

public void testHappyPathEmptyApp() throws Exception {
  TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
  
  app.start(ImmutableList.<Location>of());
  assertUpAndRunningEventually(app);
}

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

public void testAppFailsCausesAppToFail() throws Exception {
  TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class,
      TestApplicationDoStartFailing.class));
  
  startAndAssertException(app, ImmutableList.<Location>of());
  assertHealthEventually(app, Lifecycle.ON_FIRE, false);
}

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

@Test
public void testSpecDeclaresParent() {
  Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app));
  
  assertEquals(e.getParent(), app);
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
}

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

@Test
public void testNewOrphanedEntityCanBeAddedToChild() throws Exception {
  TestEntity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
  
  app.addChild(e);
  assertTrue(Entities.isManaged(e));
  listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, e)));
}

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

@Test
public void testSetParentInSetterMethod() {
  Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class));
  e.setParent(app);
  
  assertEquals(e.getParent(), app);
  assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e));
  assertEquals(e.getApplication(), app);
}

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

@Test
public void testChildInheritsFromParent() throws Exception {
  EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class)
      .configure("myentity.myconfig", "myval1"));
  EntityInternal child = mgmt.getEntityManager().createEntity(EntitySpec.create(MyChildEntity.class)
      .parent(entity));
  assertEquals(child.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(MyEntity.MY_CONFIG, "myval1"));
  assertEquals(child.config().getBag().getAllConfig(), ImmutableMap.of("myentity.myconfig", "myval1"));
  assertEquals(child.config().getLocalBag().getAllConfig(), ImmutableMap.of());
}

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

@Test
public void testManageIsNoop() throws Exception {
  TestEntity child = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class)
      .parent(app));
  
  Entities.manage(child);
  assertTrue(Entities.isManaged(child));
  listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, child)));
}

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

@Test
public void testConfigBagContainsMatchesForFlagName() throws Exception {
  // Prefers flag-name, over config-key's name
  EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class)
      .configure("myconfigflagname", "myval"));
  
  assertEquals(entity.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(MyEntity.MY_CONFIG_WITH_FLAGNAME, "myval"));
  assertEquals(entity.config().getBag().getAllConfig(), ImmutableMap.of("myentity.myconfigwithflagname", "myval"));
  assertEquals(entity.config().getLocalBag().getAllConfig(), ImmutableMap.of("myentity.myconfigwithflagname", "myval"));
}

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

@Test
public void testConfigBagContainsUnmatched() throws Exception {
  EntityInternal entity = mgmt.getEntityManager().createEntity(EntitySpec.create(MyEntity.class)
      .configure("notThere", "notThereVal"));
  
  assertEquals(entity.config().getBag().getAllConfigAsConfigKeyMap(), ImmutableMap.of(ConfigKeys.newConfigKey(Object.class, "notThere"), "notThereVal"));
  assertEquals(entity.config().getBag().getAllConfig(), ImmutableMap.of("notThere", "notThereVal"));
  assertEquals(entity.config().getLocalBag().getAllConfig(), ImmutableMap.of("notThere", "notThereVal"));
}

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

@Override
protected void setUpApp() {
  EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class, TestApplicationNoEnrichersImpl.class)
      .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, shouldSkipOnBoxBaseDirResolution());
  app = mgmt.getEntityManager().createEntity(appSpec);
}

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

@Test
public void testGetConfigMapWithSubKeys() throws Exception {
  TestEntity entity = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class)
      .configure(TestEntity.CONF_MAP_THING.subKey("mysub"), "myval"));
  
  assertEquals(entity.config().get(TestEntity.CONF_MAP_THING), ImmutableMap.of("mysub", "myval"));
  assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_THING).get(), ImmutableMap.of("mysub", "myval"));
  
  assertEquals(entity.config().get(TestEntity.CONF_MAP_THING.subKey("mysub")), "myval");
  assertEquals(entity.config().getNonBlocking(TestEntity.CONF_MAP_THING.subKey("mysub")).get(), "myval");
}

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

public void testHappyPathWithChild() throws Exception {
  TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
      .child(EntitySpec.create(TestEntity.class)));
  
  app.start(ImmutableList.<Location>of());
  assertUpAndRunningEventually(app);
}

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

public void testOnlyChildFailsToStartCausesAppToFail() throws Exception {
  TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
      .child(EntitySpec.create(FailingEntity.class)
          .configure(FailingEntity.FAIL_ON_START, true)));
  FailingEntity child = (FailingEntity) Iterables.get(app.getChildren(), 0);
  
  startAndAssertException(app, ImmutableList.<Location>of());
  assertHealthEventually(child, Lifecycle.ON_FIRE, false);
  assertHealthEventually(app, Lifecycle.ON_FIRE, false);
}

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

public void testStartsThenSomeChildFailsCausesAppToFail() throws Exception {
  TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
      .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);
  ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(child, "myIndicator", "Simulate not-up of child");
  assertHealthEventually(app, Lifecycle.ON_FIRE, false);
}

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

@DataProvider(name = "brooklynObjects")
public Object[][] createBrooklynObjects() throws Exception {
  EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class)
    .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, shouldSkipOnBoxBaseDirResolution());
  setUp();
  TestApplication app = mgmt.getEntityManager().createEntity(appSpec);
  EntityRequiringConfigKeyInRange entity = app.createAndManageChild(EntitySpec.create(EntityRequiringConfigKeyInRange.class)
      .configure(EntityRequiringConfigKeyInRange.RANGE, 5));
  Policy policy = entity.policies().add(PolicySpec.create(TestPolicy.class));
  Location location = app.newSimulatedLocation();
  return new Object[][]{{entity}, {policy}, {location}};
}

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

public void testSomeChildFailsToStartThenRecoversCausesAppToRecover() throws Exception {
  TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
      .child(EntitySpec.create(TestEntity.class))
      .child(EntitySpec.create(FailingEntity.class)
          .configure(FailingEntity.FAIL_ON_START, true)));
  FailingEntity child = (FailingEntity) Iterables.find(app.getChildren(), Predicates.instanceOf(FailingEntity.class));
  
  startAndAssertException(app, ImmutableList.<Location>of());
  assertHealthEventually(app, Lifecycle.ON_FIRE, false);
  
  child.sensors().set(Attributes.SERVICE_UP, true);
  child.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
  assertUpAndRunningEventually(app);
}

相关文章