@Override protected String getDefaultUniqueTag() { if (publishing==null) return null; return "combiner:"+publishing.getName(); } @Override
public <T> T updateWithoutPublishing(AttributeSensor<T> attribute, T newValue) { if (log.isTraceEnabled()) { Object oldValue = getValue(attribute); if (!Objects.equal(oldValue, newValue != null)) { log.trace("setting attribute {} to {} (was {}) on {}", new Object[] {attribute.getName(), newValue, oldValue, entity}); } else { log.trace("setting attribute {} to {} (unchanged) on {}", new Object[] {attribute.getName(), newValue, this}); } } T oldValue = update(attribute.getNameParts(), newValue); return (isNull(oldValue)) ? null : oldValue; }
@Override public String toString() { return "attributeSatisfies("+attribute.getName()+","+condition+")"; } }
@Beta protected MultiBuilder(Iterable<? extends Entity> sources, AttributeSensor<T> sensor, Predicate<? super T> readiness) { builder = new Builder<T,V>(null, sensor); builder.readiness(readiness); for (Entity s : checkNotNull(sources, "sources")) { multiSource.add(new AttributeAndSensorCondition<T>(s, sensor, readiness)); } this.name = "waiting on "+sensor.getName(); this.descriptionBase = "waiting on "+sensor.getName()+" "+readiness +" from "+Iterables.size(sources)+" entit"+Strings.ies(sources); }
@Override public void onFailure(SshPollValue val) { log.error("Chef attribute query did not respond as expected. exitcode={} stdout={} stderr={}", new Object[]{val.getExitStatus(), val.getStdout(), val.getStderr()}); for (AttributeSensor<?> attribute : chefAttributeSensors.values()) { if (!attribute.getName().startsWith(CHEF_ATTRIBUTE_PREFIX)) continue; entity.sensors().set(attribute, null); } }
protected Collection<AttributeSensor<?>> resolveSensorsConfig() { Collection<? extends AttributeSensor<?>> sensors = getConfig(SENSORS); Collection<AttributeSensor<?>> result = Lists.newArrayList(); if (sensors != null) { for (Object s : sensors) { AttributeSensor<?> coercedSensor = TypeCoercions.coerce(s, AttributeSensor.class); AttributeSensor<?> typedSensor = (AttributeSensor<?>) entity.getEntityType().getSensor(coercedSensor.getName()); result.add(typedSensor != null ? typedSensor : coercedSensor); } } return result; }
private Entity entityWithSensorLocal() throws Exception { return setupAndCheckTestEntityInBasicYamlWith( " id: x", " brooklyn.config:", " test.sensor: $brooklyn:sensor(\"" + TestEntity.SEQUENCE.getName() + "\")"); }
@Test public void testAttribute() throws Exception { entity.sensors().set(TestEntity.NAME, "myname"); assertEquals(EntityFunctions.attribute(TestEntity.NAME).apply(entity), "myname"); assertEquals(EntityFunctions.attribute(TestEntity.NAME.getName()).apply(entity), "myname"); assertEquals(EntityFunctions.attribute(TestEntity.NAME, "%s - suffix").apply(entity), "myname - suffix"); assertEquals(EntityFunctions.attribute(TestEntity.NAME.getName(), "%s - suffix").apply(entity), "myname - suffix"); assertNull(EntityFunctions.attribute(TestEntity.SEQUENCE).apply(entity)); }
@Test public void testAttributeEqualTo() throws Exception { entity.sensors().set(TestEntity.NAME, "myname"); assertTrue(EntityPredicates.attributeEqualTo(TestEntity.NAME, "myname").apply(entity)); assertTrue(EntityPredicates.attributeEqualTo(TestEntity.NAME.getName(), "myname").apply(entity)); assertFalse(EntityPredicates.attributeEqualTo(TestEntity.NAME, "wrongname").apply(entity)); assertFalse(EntityPredicates.attributeEqualTo(TestEntity.NAME.getName(), "wrongname").apply(entity)); }
@Test public void testAttributeWhenReadyEmptyImmediatelyDoesNotBlock() throws Exception { BrooklynDslDeferredSupplier<?> dsl = BrooklynDslCommon.attributeWhenReady(TestApplication.MY_ATTRIBUTE.getName()); Maybe<?> actualValue = execDslImmediately(dsl, TestApplication.MY_ATTRIBUTE.getType(), app, true); assertTrue(actualValue.isAbsent()); }
@Test public void testAttributeWhenReadyEmptyDoesNotBlock() throws Exception { BrooklynDslDeferredSupplier<?> dsl = BrooklynDslCommon.attributeWhenReady(TestApplication.MY_ATTRIBUTE.getName()); Maybe<?> actualValue = execDslRealRealQuick(dsl, TestApplication.MY_ATTRIBUTE.getType(), app); assertTrue(actualValue.isAbsent()); }
@Test(dataProvider = "invalidVariants") public <T> void testIgnoresWhenInvalidAttribute(AttributeSensor<T> sensor, T sensorVal) throws Exception { entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1"); entity.sensors().set(sensor, sensorVal); entity.addLocations(ImmutableList.of(machine)); entity.enrichers().add(EnricherSpec.create(OnSubnetNetworkEnricher.class) .configure(OnSubnetNetworkEnricher.SENSORS, ImmutableList.of(sensor))); EntityAsserts.assertAttributeEqualsContinually(ImmutableMap.of("timeout", VERY_SHORT_WAIT), entity, Sensors.newStringSensor(sensor.getName()+".mapped.subnet"), null); }
@Test public <T> void testTransformsDefaultHttps443() throws Exception { entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1"); entity.sensors().set(Attributes.MAIN_URI, URI.create("https://127.0.0.1/my/path")); portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 443); entity.addLocations(ImmutableList.of(machine)); entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class) .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(Attributes.MAIN_URI))); EntityAsserts.assertAttributeEqualsEventually(entity, Sensors.newStringSensor(Attributes.MAIN_URI.getName()+".mapped.public"), "https://mypublichost:5678/my/path"); }
@Test(dataProvider = "invalidVariants") public <T> void testIgnoresWhenInvalidAttribute(AttributeSensor<T> sensor, T sensorVal) throws Exception { entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1"); entity.sensors().set(sensor, sensorVal); portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234); entity.addLocations(ImmutableList.of(machine)); entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class) .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(sensor))); EntityAsserts.assertAttributeEquals(entity, Sensors.newStringSensor(sensor.getName()+".mapped.public"), null); }
@Test public void testIgnoresWithNoPort() throws Exception { // Sensor value does not have any port number entity.sensors().set(Attributes.SUBNET_ADDRESS, "127.0.0.1"); entity.sensors().set(TestEntity.NAME, "myval"); portForwardManager.associate("myPublicIp", HostAndPort.fromParts("mypublichost", 5678), machine, 1234); entity.enrichers().add(EnricherSpec.create(OnPublicNetworkEnricher.class) .configure(OnPublicNetworkEnricher.SENSORS, ImmutableList.of(TestEntity.NAME))); EntityAsserts.assertAttributeEquals(entity, Sensors.newStringSensor(TestEntity.NAME.getName()+".mapped.public"), null); }
@Override public void advertise(EntityAndAttribute<Integer> source, HostAndPort publicEndpoint) { String sourceSensor = source.getAttribute().getName(); Entity entity = source.getEntity(); AttributeSensor<String> mappedSensor = Sensors.newStringSensor("mapped." + sourceSensor); AttributeSensor<String> mappedEndpointSensor = Sensors.newStringSensor("mapped.endpoint." + sourceSensor); AttributeSensor<Integer> mappedPortSensor = Sensors.newIntegerSensor("mapped.portPart." + sourceSensor); String endpoint = publicEndpoint.getHostText() + ":" + publicEndpoint.getPort(); entity.sensors().set(mappedSensor, endpoint); entity.sensors().set(mappedEndpointSensor, endpoint); entity.sensors().set(mappedPortSensor, publicEndpoint.getPort()); } };
@Test(groups="Broken") @SuppressWarnings("deprecation") public void testDefaultJsonPath() throws Exception { HttpRequestSensor<Integer> sensor = new HttpRequestSensor<Integer>(ConfigBag.newInstance() .configure(HttpRequestSensor.SENSOR_PERIOD, Duration.millis(100)) .configure(HttpRequestSensor.SENSOR_NAME, SENSOR_STRING.getName()) .configure(HttpRequestSensor.SENSOR_TYPE, STRING_TARGET_TYPE) .configure(HttpRequestSensor.SENSOR_URI, serverUrl + "/jsonstring")); sensor.apply((org.apache.brooklyn.api.entity.EntityLocal)entity); entity.sensors().set(Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsEventually(entity, SENSOR_STRING, "myValue"); }
private void addSetChangePolicy(AttributeSensor<? extends Collection<?>> sensor, boolean includeOnAdded, boolean includeOnRemoved) { PolicySpec<InvokeEffectorOnCollectionSensorChange> policySpec = PolicySpec.create(InvokeEffectorOnCollectionSensorChange.class) .configure(InvokeEffectorOnCollectionSensorChange.TRIGGER_SENSOR, sensor) .configure(InvokeEffectorOnCollectionSensorChange.IS_BUSY_SENSOR_NAME, IS_BUSY_SENSOR.getName()); if (includeOnAdded) { policySpec.configure(InvokeEffectorOnCollectionSensorChange.ON_ADDED_EFFECTOR_NAME, onAddedEffector.getName()); } if (includeOnRemoved) { policySpec.configure(InvokeEffectorOnCollectionSensorChange.ON_REMOVED_EFFECTOR_NAME, onRemovedEffector.getName()); } testEntity.policies().add(policySpec); }