@Test public void testAppliesFilterWhenAggregatingChildrenOfGroup() { TestEntity p1 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); p1.sensors().set(intSensor, 1); entity.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromChildren() .entityFilter(Predicates.equalTo((Entity)p1)) .build()); EntityAsserts.assertAttributeEqualsEventually(entity, target, 1); TestEntity p2 = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); p2.sensors().set(intSensor, 2); EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), entity, target, 1); }
@Test public void testAppliesFilterWhenAggregatingMembersOfGroup() { BasicGroup group = app.createAndManageChild(EntitySpec.create(BasicGroup.class)); TestEntity p1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity p2 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity p3 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); group.addMember(p1); group.addMember(p2); p1.sensors().set(intSensor, 1); p2.sensors().set(intSensor, 2); p3.sensors().set(intSensor, 4); group.enrichers().add(Enrichers.builder() .aggregating(intSensor) .publishing(target) .computingSum() .fromMembers() .entityFilter(Predicates.equalTo((Entity)p1)) .build()); EntityAsserts.assertAttributeEqualsEventually(group, target, 1); group.addMember(p3); EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), group, target, 1); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void initEnrichers() { super.initEnrichers(); propagateMasterAttribute(MySqlNode.HOSTNAME); propagateMasterAttribute(MySqlNode.ADDRESS); propagateMasterAttribute(MySqlNode.SUBNET_HOSTNAME); propagateMasterAttribute(MySqlNode.SUBNET_ADDRESS); propagateMasterAttribute(MySqlNode.MYSQL_PORT); propagateMasterAttribute(MySqlNode.DATASTORE_URL); enrichers().add(Enrichers.builder() .aggregating(MySqlNode.DATASTORE_URL) .publishing(SLAVE_DATASTORE_URL_LIST) .computing((Function<Collection<String>, List<String>>)(Function)Functions.identity()) .entityFilter(Predicates.not(MySqlClusterUtils.IS_MASTER)) .fromMembers() .build()); enrichers().add(Enrichers.builder() .aggregating(MySqlNode.QUERIES_PER_SECOND_FROM_MYSQL) .publishing(QUERIES_PER_SECOND_FROM_MYSQL_PER_NODE) .fromMembers() .computingAverage() .defaultValueForUnreportedSensors(0d) .build()); }
private <T> void propagateMasterAttribute(AttributeSensor<T> att) { enrichers().add(Enrichers.builder() .aggregating(att) .publishing(att) .computing(IfFunctions.<Collection<T>>ifPredicate(CollectionFunctionals.notEmpty()) .apply(CollectionFunctionals.firstElement()) .defaultValue(null)) .entityFilter(MySqlClusterUtils.IS_MASTER) .build()); }