@SuppressWarnings({ "unchecked", "rawtypes" }) protected void addRelations(RebindContext rebindContext, T memento) { for (Map.Entry<String,Set<String>> rEntry : memento.getRelations().entrySet()) { RelationshipType<? extends BrooklynObject, ? extends BrooklynObject> r = EntityRelations.lookup(instance.getManagementContext(), rEntry.getKey()); if (r==null) throw new IllegalStateException("Unsupported relationship -- "+rEntry.getKey() + " -- in "+memento); for (String itemId: rEntry.getValue()) { BrooklynObject item = rebindContext.lookup().lookup(null, itemId); if (item != null) { instance.relations().add((RelationshipType)r, item); } else { LOG.warn("Item not found; discarding item {} relation {} of entity {}({})", new Object[] {itemId, r, memento.getType(), memento.getId()}); rebindContext.getExceptionHandler().onDanglingUntypedItemRef(itemId); } } } }
public void testCustomEntityRelation() { TestEntity t1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity t2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); t1.relations().add(EntityRelations.HAS_TARGET, t2); Assert.assertEquals(t1.relations().getRelations(EntityRelations.HAS_TARGET), Collections.singleton(t2)); Assert.assertEquals(t2.relations().getRelations(EntityRelations.HAS_TARGET), Collections.emptySet()); Assert.assertEquals(t2.relations().getRelations(EntityRelations.TARGETTED_BY), Collections.singleton(t1)); t1.relations().add(EntityRelations.HAS_TARGET, t2); Assert.assertEquals(t1.relations().getRelations(EntityRelations.HAS_TARGET), Collections.singleton(t2)); t1.relations().add(EntityRelations.HAS_TARGET, t1); Assert.assertEquals(t1.relations().getRelations(EntityRelations.HAS_TARGET), MutableSet.of(t1, t2)); }
entity.sensors().set(DockerContainer.DOCKER_CONTAINER_ID, containerId); relations().add(DockerContainer.RUNNING, entity); entity.relations().add(DockerContainer.RUNNING.getInverseRelationshipType(), this);
/** * As {@link RelationSupport#remove(RelationshipType, BrooklynObject)} for the given object. Callers can use either method. * See {@link AbstractBasicRelationSupport} for a discussion of why double dispatch is used and both methods are present. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T extends BrooklynObject,U extends BrooklynObject> void remove(T source, RelationshipType<? super T,? super U> relationship, U target) { ((BrooklynObjectInternal)source).relations().getLocalBackingStore().remove((RelationshipType)relationship, target); if (relationship.getInverseRelationshipType()!=null) ((BrooklynObjectInternal)target).relations().getLocalBackingStore().remove((RelationshipType)relationship.getInverseRelationshipType(), source); }
public void testCustomEntityRelation() throws Exception { TestEntity origT1 = origApp.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity origT2 = origApp.createAndManageChild(EntitySpec.create(TestEntity.class)); origT1.relations().add(EntityRelations.HAS_TARGET, origT2); TestApplication newApp = rebind(); Iterator<Entity> ci = newApp.getChildren().iterator(); Entity t1 = ci.next(); Entity t2 = ci.next(); Assert.assertEquals(t1.relations().getRelations(EntityRelations.HAS_TARGET), Collections.singleton(t2)); Assert.assertEquals(t2.relations().getRelations(EntityRelations.HAS_TARGET), Collections.emptySet()); Assert.assertEquals(t2.relations().getRelations(EntityRelations.TARGETTED_BY), Collections.singleton(t1)); }
/** * As {@link RelationSupport#add(RelationshipType, BrooklynObject)} for the given object. Callers can use either method. * See {@link AbstractBasicRelationSupport} for a discussion of why double dispatch is used and both methods are present. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T extends BrooklynObject,U extends BrooklynObject> void add(T source, RelationshipType<? super T,? super U> relationship, U target) { ((BrooklynObjectInternal)source).relations().getLocalBackingStore().add((RelationshipType)relationship, target); if (relationship.getInverseRelationshipType()!=null) ((BrooklynObjectInternal)target).relations().getLocalBackingStore().add((RelationshipType)relationship.getInverseRelationshipType(), source); }
/** * As {@link RelationSupport#getRelations(RelationshipType)} for the given object. Callers can use either method. * See {@link AbstractBasicRelationSupport} for a discussion of why double dispatch is used and both methods are present. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T extends BrooklynObject,U extends BrooklynObject> Set<U> getRelations(RelationshipType<? super T,U> relationship, T source) { return ((BrooklynObjectInternal)source).relations().getLocalBackingStore().getRelations((RelationshipType)relationship); }
/** * As {@link RelationSupport#getRelationshipTypes()} for the given object. Callers can use either method. * See {@link AbstractBasicRelationSupport} for a discussion of why double dispatch is used and both methods are present. */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T extends BrooklynObject> Set<RelationshipType<? super T,? extends BrooklynObject>> getRelationshipTypes(T source) { return (Set) ((BrooklynObjectInternal)source).relations().getLocalBackingStore().getRelationshipTypes(); }