@Override public void init() { Entity delegate = getConfig(DELEGATE_ENTITY); Preconditions.checkNotNull(delegate, "delegate"); // Propagate all sensors from the delegate entity enrichers().add(Enrichers.builder() .propagatingAll() .from(delegate) .build()); // Publish the entity as an attribute for linking sensors().set(DELEGATE_ENTITY, delegate); sensors().set(DELEGATE_ENTITY_LINK, EntityUrl.entityUrl().apply(delegate)); } }
@Test public void testPropagatingAllEnricher() throws Exception { origApp.enrichers().add(Enrichers.builder() .propagatingAll() .from(origEntity) .build()); TestApplication newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); newEntity.sensors().set(METRIC1, "myval"); EntityAsserts.assertAttributeEqualsEventually(newApp, METRIC1, "myval"); }
@Test public void testPropagatesAllSensorsIncludesDynamicallyAdded() { AttributeSensor<String> dynamicAttribute = Sensors.newStringSensor("test.dynamicsensor.strattrib"); BasicNotificationSensor<String> dynamicNotificationSensor = new BasicNotificationSensor<String>(String.class, "test.dynamicsensor.strnotif"); app.enrichers().add(Enrichers.builder() .propagatingAll() .from(entity) .build()); entity.sensors().set(dynamicAttribute, "foo"); EntityAsserts.assertAttributeEqualsEventually(app, dynamicAttribute, "foo"); // notification-sensor propagated final AtomicReference<String> notif = new AtomicReference<String>(); app.subscriptions().subscribe(app, dynamicNotificationSensor, new SensorEventListener<String>() { @Override public void onEvent(SensorEvent<String> event) { notif.set(event.getValue()); }}); entity.sensors().emit(dynamicNotificationSensor, "mynotifval"); Asserts.eventually(AtomicReferences.supplier(notif), Predicates.equalTo("mynotifval")); }
@Test public void testPropagatesAllStaticSensors() { app.enrichers().add(Enrichers.builder() .propagatingAll() .from(entity) .build()); // all attributes propagated entity.sensors().set(TestEntity.NAME, "foo"); entity.sensors().set(TestEntity.SEQUENCE, 2); EntityAsserts.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); EntityAsserts.assertAttributeEqualsEventually(app, TestEntity.SEQUENCE, 2); // notification-sensor propagated final AtomicReference<Integer> notif = new AtomicReference<Integer>(); app.subscriptions().subscribe(app, TestEntity.MY_NOTIF, new SensorEventListener<Integer>() { @Override public void onEvent(SensorEvent<Integer> event) { notif.set(event.getValue()); }}); entity.sensors().emit(TestEntity.MY_NOTIF, 7); Asserts.eventually(AtomicReferences.supplier(notif), Predicates.equalTo(7)); }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { localManagementContext = newPersistingManagementContext(); if (persister==null) { persister = localManagementContext.getRebindManager().getPersister(); } if (objectStore==null && persister instanceof BrooklynMementoPersisterToObjectStore) { objectStore = ((BrooklynMementoPersisterToObjectStore)persister).getObjectStore(); } EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class) .location(LocationSpec.create(SshMachineLocation.class).configure("address", "localhost")); app = localManagementContext.getEntityManager().createEntity(appSpec); location = Iterables.getOnlyElement( app.getLocations() ); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); enricher = app.enrichers().add(Enrichers.builder().propagatingAll().from(entity).build()); policy = app.policies().add(PolicySpec.create(TestPolicy.class)); }