Java Code Examples for org.apache.brooklyn.api.entity.Entity#setParent()
The following examples show how to use
org.apache.brooklyn.api.entity.Entity#setParent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChildEntityCustomizer.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override public void customize(JcloudsLocation location, ComputeService computeService, JcloudsMachineLocation machine) { EntitySpec<?> spec = config().get(CHILD_ENTITY_SPEC); Boolean create = config().get(CREATE_CHILD_ENTITY); Duration timeout = config().get(BrooklynConfigKeys.START_TIMEOUT); Entity parent = getCallerContext(machine); if (Boolean.TRUE.equals(create) && spec != null) { LOG.info("Creating child entity for {} in {}", parent, machine); Entity child = getBrooklynManagementContext().getEntityManager().createEntity(spec); child.setParent(parent); Task<Void> start = Entities.invokeEffectorWithArgs(parent, child, Startable.START, ImmutableList.of(machine)); if (!start.blockUntilEnded(timeout)) { throw new IllegalStateException(String.format("Timed out while starting child entity for %s", parent)); } } }
Example 2
Source File: OwnedChildrenDeprecatedTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testParentalLoopForbiddenViaSetParent() { Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class)); Entity e2 = e.addChild(EntitySpec.create(TestEntity.class)); try { e.setParent(e2); Asserts.shouldHaveFailedPreviously(); } catch (Exception ex) { Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalStateException.class); if (cause == null || !cause.toString().contains("loop detected trying to set parent")) { throw ex; } } assertEqualsIgnoringOrder(e.getChildren(), ImmutableList.of(e2)); assertEqualsIgnoringOrder(e2.getChildren(), ImmutableList.of()); assertEquals(e.getParent(), null); assertEquals(e2.getParent(), e); }
Example 3
Source File: OwnedChildrenDeprecatedTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testParentingOneselfForbidden() { Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class)); try { e.setParent(e); Asserts.shouldHaveFailedPreviously(); } catch (Exception ex) { Exception cause = Exceptions.getFirstThrowableOfType(ex, IllegalStateException.class); if (cause == null || !cause.toString().contains("cannot own itself")) { throw ex; } } assertNull(e.getParent()); assertEquals(e.getChildren(), ImmutableList.of()); }
Example 4
Source File: DynamicFabricImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected Entity addCluster(Location location) { String locationName = elvis(location.getDisplayName(), location.getDisplayName(), null); Map creation = Maps.newLinkedHashMap(); creation.putAll(getCustomChildFlags()); if (groovyTruth(getDisplayNamePrefix()) || groovyTruth(getDisplayNameSuffix())) { String displayName = "" + elvis(getDisplayNamePrefix(), "") + elvis(locationName, "unnamed") + elvis(getDisplayNameSuffix(),""); creation.put("displayName", displayName); } logger.info("Creating entity in fabric {} at {}{}", new Object[] {this, location, (creation!=null && !creation.isEmpty() ? ", properties "+creation : "") }); Entity entity = createCluster(location, creation); if (locationName != null) { if (entity.getDisplayName()==null) entity.setDisplayName(entity.getEntityType().getSimpleName() +" ("+locationName+")"); else if (!entity.getDisplayName().contains(locationName)) entity.setDisplayName(entity.getDisplayName() +" ("+locationName+")"); } if (entity.getParent()==null) entity.setParent(this); // Continue to call manage(), because some uses of NodeFactory (in tests) still instantiate the // entity via its constructor Entities.manage(entity); addMember(entity); return entity; }
Example 5
Source File: OwnedChildrenDeprecatedTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testSetParentWhenMatchesParentSetInConstructor() { Entity e = new AbstractEntity(app) {}; e.setParent(app); assertEquals(e.getParent(), app); assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e)); }
Example 6
Source File: OwnedChildrenDeprecatedTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testSetParentWhenDiffersFromParentSetInConstructor() { Entity e = new AbstractEntity(app) {}; Entity e2 = new AbstractEntity() {}; try { e.setParent(e2); Asserts.shouldHaveFailedPreviously(); } catch (Exception ex) { Exception uoe = Exceptions.getFirstThrowableOfType(ex, UnsupportedOperationException.class); if (uoe == null || !uoe.toString().contains("Cannot change parent")) { throw ex; } } }
Example 7
Source File: OwnedChildrenDeprecatedTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@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); }
Example 8
Source File: OwnedChildrenDeprecatedTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testSetParentWhenMatchesParentSetInSpec() { Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app)); e.setParent(app); assertEquals(e.getParent(), app); assertEqualsIgnoringOrder(app.getChildren(), ImmutableList.of(e)); }
Example 9
Source File: OwnedChildrenDeprecatedTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testSetParentWhenDiffersFromParentSetInSpec() { Entity e = mgmt.getEntityManager().createEntity(EntitySpec.create(TestEntity.class).parent(app)); Entity e2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); try { e.setParent(e2); Asserts.shouldHaveFailedPreviously(); } catch (Exception ex) { Exception uoe = Exceptions.getFirstThrowableOfType(ex, UnsupportedOperationException.class); if (uoe == null || !uoe.toString().contains("Cannot change parent")) { throw ex; } } }