enrichers().add(Enrichers.builder().propagating(Startable.SERVICE_UP).from(child).build()); enrichers().add(ServiceStateLogic.newEnricherFromChildrenState() .suppressDuplicates(true) if (Boolean.TRUE.equals(propagate)) { if (sensors.isEmpty()) { enrichers().add(Enrichers.builder().propagatingAllButUsualAnd().from(child).build()); } else { enrichers().add(Enrichers.builder().propagating(sensors).from(child).build());
public PropagatorBuilder propagatingAllBut(Sensor<?>... vals) { return new PropagatorBuilder(true, ImmutableSet.copyOf(vals)); } public PropagatorBuilder propagatingAllBut(Iterable<? extends Sensor<?>> vals) {
@Override public void init() { super.init(); ConfigToAttributes.apply(this, MESOS_SLAVE_ID); EnricherSpec<?> serviceUp = Enrichers.builder() .propagating(ImmutableMap.of(SLAVE_ACTIVE, SERVICE_UP)) .suppressDuplicates(true) .from(this) .build(); enrichers().add(serviceUp); }
.fromMembers() .publishing(DOCKER_CONTAINER_COUNT) .build()); .from(hosts) .build()); enrichers().add(Enrichers.builder() .propagating(ImmutableMap.of(DynamicCluster.GROUP_SIZE, DOCKER_HOST_COUNT)) .from(hosts) .build()); ContainerHeadroomEnricher.DOCKER_CONTAINER_CLUSTER_HOT, ContainerHeadroomEnricher.DOCKER_CONTAINER_CLUSTER_OK) .from(this) .build()); hosts.policies().add(PolicySpec.create(AutoScalerPolicy.class) .configure(AutoScalerPolicy.POOL_COLD_SENSOR, ContainerHeadroomEnricher.DOCKER_CONTAINER_CLUSTER_COLD)
enrichers().add(Enrichers.builder().propagating(Startable.SERVICE_UP).from(child).build()); enrichers().add(ServiceStateLogic.newEnricherFromChildrenState() .suppressDuplicates(true) if (Boolean.TRUE.equals(propagate)) { if (sensors.isEmpty()) { enrichers().add(Enrichers.builder().propagatingAllButUsualAnd().from(child).build()); } else { enrichers().add(Enrichers.builder().propagating(sensors).from(child).build());
app.enrichers().add(Enrichers.builder() .propagating(Sensors.newSensor(Object.class, TestEntity.NAME.getName())) .from(entity) .build()); app.enrichers().add(Enrichers.builder() .propagating(ImmutableMap.of(sourceSensorFromYaml, targetSensor)) .from(app) .build()); EntityAsserts.assertAttributeEqualsEventually(app, targetSensor, entity.sensors().get(TestEntity.NAME)); entity.sensors().set(TestEntity.NAME, "newName");
@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)); }
@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")); }
public PropagatorBuilder propagatingAllBut(Iterable<? extends Sensor<?>> vals) { return new PropagatorBuilder(true, vals); }
@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)); }
public PropagatorBuilder propagating(Iterable<? extends Sensor<?>> vals) { return new PropagatorBuilder(vals); } public PropagatorBuilder propagating(Sensor<?>... vals) {
@Test public void testPropagatesAllBut() { app.enrichers().add(Enrichers.builder() .propagatingAllBut(TestEntity.SEQUENCE) .from(entity) .build()); // name propagated entity.sensors().set(TestEntity.NAME, "foo"); EntityAsserts.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); // sequence not propagated entity.sensors().set(TestEntity.SEQUENCE, 2); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.SEQUENCE, null); }
@Test public void testPropagatesSpecificSensor() { app.enrichers().add(Enrichers.builder() .propagating(TestEntity.NAME) .from(entity) .build()); // name propagated entity.sensors().set(TestEntity.NAME, "foo"); EntityAsserts.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); // sequence not propagated entity.sensors().set(TestEntity.SEQUENCE, 2); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.SEQUENCE, null); }
@Test public void testProducerUsingDeferredSupplier() throws Exception { producer = app.createAndManageChild(EntitySpec.create(TestEntity.class) .configure(TAG, "myproducer")); target = app.createAndManageChild(EntitySpec.create(TestEntity.class)); sensor = new BasicAttributeSensor<Integer>(Integer.class, "int.sensor.a"); app.start(ImmutableList.of(new SimulatedLocation())); producer.sensors().set(sensor, 3); target.enrichers().add(Enrichers.builder() .propagating(sensor) .from(new EntityDeferredSupplier("myproducer").newTask()) .build()); EntityAsserts.assertAttributeEqualsEventually(target, sensor, 3); }
public PropagatorBuilder propagating(Map<? extends Sensor<?>, ? extends Sensor<?>> vals) { return new PropagatorBuilder(vals); } public PropagatorBuilder propagating(Iterable<? extends Sensor<?>> vals) {