OSDir


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] brooklyn-server pull request #967: add an /applications/details endpoint whi...


Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/967#discussion_r192686869
  
    --- 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);
    --- End diff --
    
    Should this be guarded with `Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_SENSOR, new EntityAndItem<String>(entity, name))`


---