in software/cm/chef/src/main/java/org/apache/brooklyn/entity/chef/ChefAttributeFeed.java [318:365]
public void onSuccess(SshPollValue val) {
String stdout = val.getStdout();
int jsonStarts = stdout.indexOf('{');
if (jsonStarts > 0)
stdout = stdout.substring(jsonStarts);
JsonElement jsonElement = new Gson().fromJson(stdout, JsonElement.class);
for (Map.Entry<String, AttributeSensor<?>> attribute : chefAttributeSensors.entrySet()) {
String chefAttributeName = attribute.getKey();
AttributeSensor<?> sensor = attribute.getValue();
log.trace("Finding value for attribute sensor " + sensor.getName());
Iterable<String> path = SPLITTER.split(chefAttributeName);
JsonElement elementForSensor = null;
for(String prefix : PREFIXES) {
Iterable<String> prefixedPath = !Strings.isNullOrEmpty(prefix)
? Iterables.concat(ImmutableList.of(prefix), path)
: path;
try {
elementForSensor = getElementByPath(jsonElement.getAsJsonObject(), prefixedPath);
} catch(IllegalArgumentException e) {
log.error("Entity {}: bad Chef attribute {} for sensor {}: {}", new Object[]{
entity.getDisplayName(),
Joiner.on('.').join(prefixedPath),
sensor.getName(),
e.getMessage()});
throw Throwables.propagate(e);
}
if (elementForSensor != null) {
log.debug("Entity {}: apply Chef attribute {} to sensor {} with value {}", new Object[]{
entity.getDisplayName(),
Joiner.on('.').join(prefixedPath),
sensor.getName(),
elementForSensor.getAsString()});
break;
}
}
if (elementForSensor != null) {
entity.sensors().set((AttributeSensor)sensor, TypeCoercions.coerce(elementForSensor.getAsString(), sensor.getTypeToken()));
} else {
log.debug("Entity {}: no Chef attribute matching {}; setting sensor {} to null", new Object[]{
entity.getDisplayName(),
chefAttributeName,
sensor.getName()});
entity.sensors().set(sensor, null);
}
}
}