Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/967#discussion_r194659942
--- Diff:
rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java
---
@@ -226,6 +276,60 @@ private EntityDetail addSensors(EntityDetail result,
Entity entity, List<Attribu
}
return result;
}
+
+ private EntitySummary addSensorsByGlobs(EntitySummary result, Entity
entity, List<String> extraSensorGlobs) {
+ if (extraSensorGlobs!=null && !extraSensorGlobs.isEmpty()) {
+ Object sensorsO = result.getExtraFields().get("sensors");
+ if (sensorsO==null) {
+ sensorsO = MutableMap.of();
+ result.setExtraField("sensors", sensorsO);
+ }
+ if (!(sensorsO instanceof Map)) {
+ throw new IllegalStateException("sensors field in result
for "+entity+" should be a Map; found: "+sensorsO);
+ }
+ @SuppressWarnings("unchecked")
+ Map<String,Object> sensors = (Map<String, Object>) sensorsO;
+
+ Map<AttributeSensor<?>, Object> svs =
entity.sensors().getAll();
+ svs.entrySet().stream().forEach(kv -> {
+ Object sv = kv.getValue();
+ if (sv!=null) {
+ String name = kv.getKey().getName();
+ if (extraSensorGlobs.stream().anyMatch(sn ->
WildcardGlobs.isGlobMatched(sn, name))) {
+ sv =
resolving(sv).preferJson(true).asJerseyOutermostReturnValue(false).raw(true).context(entity).immediately(true).timeout(Duration.ZERO).resolve();
+ sensors.put(name, sv);
+ }
+ }
+ });
+ }
+ return result;
+ }
+
+ private EntitySummary addConfigByGlobs(EntitySummary result, Entity
entity, List<String> extraConfigGlobs) {
+ if (extraConfigGlobs!=null && !extraConfigGlobs.isEmpty()) {
+ Object configO = result.getExtraFields().get("config");
+ if (configO==null) {
+ configO = MutableMap.of();
+ result.setExtraField("config", configO);
+ }
+ if (!(configO instanceof Map)) {
+ throw new IllegalStateException("config field in result
for "+entity+" should be a Map; found: "+configO);
+ }
+ @SuppressWarnings("unchecked")
+ Map<String,Object> configs = (Map<String, Object>) configO;
+
+ List<Predicate<ConfigKey<?>>> extraConfigPreds =
MutableList.of();
+ extraConfigGlobs.stream().forEach(g -> { extraConfigPreds.add(
ConfigPredicates.nameMatchesGlob(g) ); });
+
entity.config().findKeysDeclared(Predicates.or(extraConfigPreds)).forEach(key
-> {
+ Object v = entity.config().get(key);
+ if (v!=null) {
+ v =
resolving(v).preferJson(true).asJerseyOutermostReturnValue(false).raw(true).context(entity).immediately(true).timeout(Duration.ZERO).resolve();
+ configs.put(key.getName(), v);
--- End diff --
done
---