@Test public void testUsesCustomWebClusterSpec() { ControlledDynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(ControlledDynamicWebAppCluster.class) .configure("initialSize", 0) .configure(ControlledDynamicWebAppCluster.CONTROLLER_SPEC, EntitySpec.create(TrackingAbstractController.class)) .configure(ControlledDynamicWebAppCluster.WEB_CLUSTER_SPEC, EntitySpec.create(DynamicWebAppCluster.class) .displayName("mydisplayname"))); app.start(locs); assertEquals(cluster.getCluster().getDisplayName(), "mydisplayname"); }
@BeforeMethod(alwaysRun=true) public void setUp() { app = TestApplication.Factory.newManagedInstanceForTests(); /* * Create an entity, using real entity code, but that swaps out the external process * for a JmxService that we can control in the test. */ entity = app.createAndManageChild(EntitySpec.create(SoftwareProcess.class).impl(SubVanillaJavaApp.class) .configure("rmiRegistryPort", 40123) .configure("mxbeanStatsEnabled", false) .configure(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.JMX_RMI_CUSTOM_AGENT)); }
/** * Creates a new {@link EntitySpec} instance for an entity of the given type. The returned * {@link EntitySpec} can then be customized. * * @param type An {@link Entity} interface * @param implType An {@link Entity} implementation, which implements the {@code type} interface */ public static <T extends Entity, U extends T> EntitySpec<T> create(Class<T> type, Class<U> implType) { return new EntitySpec<T>(type).impl(implType); }
public EntitySpec<T> impl(Class<? extends T> val) { checkMutable(); checkIsImplementation(checkNotNull(val, "impl"), getType()); checkIsNewStyleImplementation(val); impl = val; return this; }
protected void createTestEntities() throws Exception { e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("test-one")); e2 = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("test-two")); e3 = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("test-three")); }
public void testSomeChildFailsOnStartCausesAppToFail() 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))); startAndAssertException(app, ImmutableList.<Location>of()); assertHealthEventually(app, Lifecycle.ON_FIRE, false); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private <T extends Entity> org.apache.brooklyn.api.entity.EntitySpec<?> toCoreEntitySpec(Class<T> clazz, String name, Map<String,String> configO, String catalogItemId) { Map<String, String> config = (configO == null) ? Maps.<String,String>newLinkedHashMap() : Maps.newLinkedHashMap(configO); org.apache.brooklyn.api.entity.EntitySpec<? extends Entity> result; if (clazz.isInterface()) { result = org.apache.brooklyn.api.entity.EntitySpec.create(clazz); } else { // If this is a concrete class, particularly for an Application class, we want the proxy // to expose all interfaces it implements. Class interfaceclazz = (Application.class.isAssignableFrom(clazz)) ? Application.class : Entity.class; Set<Class<?>> additionalInterfaceClazzes = Reflections.getInterfacesIncludingClassAncestors(clazz); result = org.apache.brooklyn.api.entity.EntitySpec.create(interfaceclazz).impl(clazz).additionalInterfaces(additionalInterfaceClazzes); } result.catalogItemId(catalogItemId); if (!Strings.isEmpty(name)) result.displayName(name); result.configure( convertFlagsToKeys(result.getImplementation(), config) ); return result; }
private org.apache.brooklyn.api.entity.EntitySpec<? extends Entity> toCoreEntitySpec(org.apache.brooklyn.rest.domain.EntitySpec spec) { String type = spec.getType(); String name = spec.getName(); Map<String, String> config = (spec.getConfig() == null) ? Maps.<String,String>newLinkedHashMap() : Maps.newLinkedHashMap(spec.getConfig()); FindItemAndClass itemAndClass = new FindItemAndClass().inferFrom(type); final Class<? extends Entity> clazz = itemAndClass.clazz; org.apache.brooklyn.api.entity.EntitySpec<? extends Entity> result; if (clazz.isInterface()) { result = org.apache.brooklyn.api.entity.EntitySpec.create(clazz); } else { result = org.apache.brooklyn.api.entity.EntitySpec.create(Entity.class).impl(clazz).additionalInterfaces(Reflections.getAllInterfaces(clazz)); } result.catalogItemId(itemAndClass.catalogItemId); if (!Strings.isEmpty(name)) result.displayName(name); result.configure( convertFlagsToKeys(result.getType(), config) ); configureRenderingMetadata(spec, result); return result; }
protected Entity createCluster(Location location, Map flags) { EntitySpec<?> memberSpec = null; if (getMembers().isEmpty()) memberSpec = getFirstMemberSpec(); if (memberSpec == null) memberSpec = getMemberSpec(); if (memberSpec == null) { throw new IllegalStateException("No member spec nor entity factory supplied for dynamic fabric "+this); } EntitySpec<?> specConfigured = EntitySpec.create(memberSpec).configure(flags); if (location!=null) specConfigured.location(location); return addChild(specConfigured); } }
@Test public void testDisplayNameUsesCustomWhenOverriddenDefault() throws Exception { entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .impl(TestEntityWithDefaultNameImpl.class) .configure(TestEntityWithDefaultNameImpl.DEFAULT_NAME, "myOverriddenDefaultName") .displayName("myEntityName")); assertEquals(entity.getDisplayName(), "myEntityName"); }
private TestApplication newClusterApp(int suffix) { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(EntitySpec.create(TestApplication.class) .displayName("app-"+suffix) .child(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.INITIAL_SIZE, 1) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(BasicStartable.class))))); app.start(ImmutableList.of(app.newLocalhostProvisioningLocation())); return app; }
@Override protected EntitySpec<T> copyFrom(EntitySpec<T> otherSpec) { super.copyFrom(otherSpec) .additionalInterfaces(otherSpec.getAdditionalInterfaces()) .policySpecs(otherSpec.getPolicySpecs()) .policies(otherSpec.getPolicies()) .enricherSpecs(otherSpec.getEnricherSpecs()) .enrichers(otherSpec.getEnrichers()) .addInitializers(otherSpec.getInitializers()) .children(copyFromSpecs(otherSpec.getChildren())) .members(otherSpec.getMembers()) .groups(otherSpec.getGroups()) .locationSpecs(otherSpec.getLocationSpecs()) .locations(otherSpec.getLocations()); if (otherSpec.getParent() != null) parent(otherSpec.getParent()); if (otherSpec.getImplementation() != null) impl(otherSpec.getImplementation()); return this; }
@Test public void testStartsWhenNoStartableChildren() { BasicStartable startable = app.createAndManageChild(EntitySpec.create(BasicStartable.class) .child(EntitySpec.create(BasicEntity.class))); app.start(ImmutableList.of(app.newSimulatedLocation())); EntityAsserts.assertAttributeEquals(startable, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); }
@Override protected void setUpApp() { super.setUpApp(); http = new HttpCallback(); cluster = app.createAndManageChild(EntitySpec.create(BrooklynCluster.class) .location(TestApplication.LOCALHOST_PROVISIONER_SPEC) .configure(BrooklynCluster.MEMBER_SPEC, EntitySpec.create(BrooklynNode.class) .impl(MockBrooklynNode.class) .configure(MockBrooklynNode.HTTP_CLIENT_CALLBACK, http))); }
@Test public void testCreatesProxyImplementingAdditionalInterfaces() throws Exception { EntitySpec<Application> spec = EntitySpec.create(Application.class).impl(MyApplicationImpl.class).additionalInterfaces(MyInterface.class); Application app = factory.createEntity(spec, Optional.absent()); Application proxy = factory.createEntityProxy(spec, app); assertFalse(proxy instanceof MyApplicationImpl, "proxy="+proxy); assertTrue(proxy instanceof Application, "proxy="+proxy); assertTrue(proxy instanceof MyInterface, "proxy="+proxy); assertTrue(proxy instanceof EntityProxy, "proxy="+proxy); }
@Test @SuppressWarnings("deprecation") public void testUsesInitialLocationsFromAppSpec() throws Exception { TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true) .child(EntitySpec.create(DynamicRegionsFabric.class) .configure("memberSpec", EntitySpec.create(TestEntity.class))) .locations(ImmutableList.of(loc1, loc2))); DynamicRegionsFabric fabric2 = (DynamicRegionsFabric) Iterables.getOnlyElement(app2.getChildren()); app2.start(ImmutableList.<Location>of()); assertFabricChildren(fabric2, 2, ImmutableList.of(loc1, loc2)); }
@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()); }