Class MetricsAasConstructor


  • public class MetricsAasConstructor
    extends java.lang.Object
    Class that provides an AAS the infrastructure to access the metrics provider.
    This class includes the functionality that adds the metrics exposed by the Metrics Provider as properties of an AAS submodel, as well as providing the implementation required for those properties to correctly retrieve the values
    If we wish to add any custom meters to our AAS, we can also use this class as a class to do so, ensuring that all metrics (custom or not) are accessed in the same way. The original approach aimed at attaching metric results through functor objects to AAS properties. While this basically works, it fails when AAS are deployed remotely as the values of all properties are read out for AAS serialization. As the BaSyx VAB connector is meant to be stateless, it re-creates network connections per each request. Also caching the connectors did not solve the problem. Ultimately, in parallel access cases the AAS even blocked the entire operations of the program. Thus, we turned the approach around and rely now on attached local functors that access a shared object. The shared object is attached through a transport layer callback to a transport layer connector, which is cached/created on demand upon execution of the functors. The functors are serializable, and carry all information required to create a transport connector. Updates to the metric values happen in background to the shared object, while the AAS just accesses the values in its own pace (returning nothing if no metrics data was received so far). Shared objects shall be released when the program shuts down.
    Author:
    Miguel Gomez, Holger Eichelberger, SSE
    • Field Detail

      • LAMBDA_SETTERS_SUPPORTED

        public static final boolean LAMBDA_SETTERS_SUPPORTED
        Does the underlying AAS implementation execute Lambda-Setters for AAS properties. If not, we activate a less performant fallback. Somewhen between BaSyx 1.1 and BaSyx 1.3 we lost this, but this may just depend on the underlying Java version.
        See Also:
        Constant Field Values
      • conns

        private static java.util.Map<java.lang.String,​de.iip_ecosphere.platform.transport.connectors.TransportConnector> conns
      • monSubModel

        private static de.iip_ecosphere.platform.support.aas.Submodel monSubModel
      • monSubModelFailed

        private static boolean monSubModelFailed
      • monMapping

        private static java.util.Map<java.lang.String,​java.lang.String> monMapping
    • Constructor Detail

      • MetricsAasConstructor

        public MetricsAasConstructor()
    • Method Detail

      • clear

        public static void clear()
        Clears temporary data structures.
      • getTransportConnector

        private static de.iip_ecosphere.platform.transport.connectors.TransportConnector getTransportConnector​(java.lang.String channel,
                                                                                                               de.iip_ecosphere.platform.transport.connectors.TransportSetup setup)
        Returns a transport connector for the given channel and setup.
        Parameters:
        channel - the transport channel
        setup - the transport setup
        Returns:
        the (cached) transport connector
      • getMonitoringMapping

        public static java.util.Map<java.lang.String,​java.lang.String> getMonitoringMapping()
        Returns a (unmodifiable) mapping of monitoring meter names to AAS names.
        Returns:
        the default (unmodifiable) monitoring mapping
      • pushToAas

        public static void pushToAas​(java.lang.String json,
                                     java.lang.String submodel,
                                     MetricsAasConstructor.CollectionSupplier cSupplier,
                                     boolean update,
                                     MetricsAasConstructor.PushMeterPredicate mPredicate)
        Alternative approach to update the metric values. Can be called from the regular sending thread. Enabled only if not LAMBDA_SETTERS_SUPPORTED. Uses the default meter-shortId names mapping defined in this class. Initial approach, not really performant. May have to be throttled.
        Parameters:
        json - the JSON to be sent to the monitoring channel
        submodel - the submodel to update (elements are assumed to be in a submodel elements collection on the next level)
        cSupplier - collection supplier
        update - whether this is an update or the first call
        mPredicate - optional predicate to identify whether pushing a value shall happen, may be null then PREDICATE_ALWAYS_TRUE is used
      • pushToAas

        public static void pushToAas​(java.lang.String json,
                                     java.lang.String submodel,
                                     MetricsAasConstructor.CollectionSupplier cSupplier,
                                     boolean update,
                                     java.util.Map<java.lang.String,​java.lang.String> monMapping,
                                     MetricsAasConstructor.PushMeterPredicate mPredicate)
        Alternative approach to update the metric values. Can be called from the regular sending thread. Enabled only if not LAMBDA_SETTERS_SUPPORTED. Initial approach, not really performant. May have to be throttled.
        Parameters:
        json - the JSON to be sent to the monitoring channel
        submodel - the submodel to update (elements are assumed to be in a submodel elements collection on the next level)
        cSupplier - collection supplier within submodel
        update - whether this is an update or the first call
        monMapping - the meter-shortId mapping to use
        mPredicate - optional predicate to identify whether pushing a value shall happen, may be null then PREDICATE_ALWAYS_TRUE is used
      • pushToAas

        private static void pushToAas​(de.iip_ecosphere.platform.support.aas.ElementsAccess coll,
                                      java.util.Map.Entry<java.lang.String,​javax.json.JsonValue> ent,
                                      java.util.Map<java.lang.String,​java.lang.String> monMapping,
                                      MetricsAasConstructor.PushMeterPredicate mPredicate)
        Pushes a JSON metrics entry to coll.
        Parameters:
        coll - the collection to push to
        ent - the metrics entry containing metrics name and measurement
        monMapping - the meter-shortId mapping to use
        mPredicate - optional predicate to identify whether pushing a value shall happen, may be null then PREDICATE_ALWAYS_TRUE is used
      • getMeasurement

        private static java.lang.Object getMeasurement​(java.lang.String json)
        Extracts the measurement out of the metrics JSON.
        Parameters:
        json - the JSON, may be empty or null
        Returns:
        the measurement, may be null
      • getHolder

        private static MetricsAasConstructor.JsonObjectHolder getHolder​(java.lang.String id,
                                                                        java.lang.String channel,
                                                                        de.iip_ecosphere.platform.transport.connectors.TransportSetup setup)
        Returns a JSON object holder associated to a transport connector through MetricsAasConstructor.MetricsReceptionCallback.
        Parameters:
        channel - the transport channel
        id - the id to react on
        setup - the transport setup
        Returns:
        the (shared) object holder instance
      • containsMetrics

        public static boolean containsMetrics​(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection sub)
        Tests whether metrics properties do exist on sub.
        Parameters:
        sub - the submodel elements collection to test
        Returns:
        true for metrics, false else
      • createProperty

        public static de.iip_ecosphere.platform.support.aas.Property createProperty​(de.iip_ecosphere.platform.support.aas.SubmodelElementContainerBuilder smBuilder,
                                                                                    de.iip_ecosphere.platform.support.aas.Type type,
                                                                                    java.lang.String channel,
                                                                                    java.lang.String id,
                                                                                    de.iip_ecosphere.platform.transport.connectors.TransportSetup setup,
                                                                                    java.lang.String metricsName,
                                                                                    java.lang.String semId)
        Creates a monitoring property.
        Parameters:
        smBuilder - the parent submodel builder
        type - the type of the property
        channel - the transport channel (ignored if not LAMBDA_SETTERS_SUPPORTED)
        id - the id to react on (ignored if not LAMBDA_SETTERS_SUPPORTED)
        setup - the transport setup (ignored if not LAMBDA_SETTERS_SUPPORTED)
        metricsName - the name of the metrics as defined in the MetricsProvider
        semId - the optional semantic id (may be null for none)
        Returns:
        the created property
      • addProviderMetricsToAasSubmodel

        public static void addProviderMetricsToAasSubmodel​(de.iip_ecosphere.platform.support.aas.SubmodelElementContainerBuilder smBuilder,
                                                           java.util.function.Predicate<java.lang.String> filter,
                                                           java.lang.String channel,
                                                           java.lang.String id,
                                                           de.iip_ecosphere.platform.transport.connectors.TransportSetup setup)
        Adds system metrics to the submodel/elements. If LAMBDA_SETTERS_SUPPORTED, values are bound against a transport connector receiver.
        Parameters:
        smBuilder - submodel/elements builder of the AAS
        filter - metrics filter, may be null for all (currently ignored)
        channel - the transport channel to listen to
        id - the metrics provider id to listen to
        setup - the transport setup
      • addServiceMetricsToAasSubmodel

        public static void addServiceMetricsToAasSubmodel​(de.iip_ecosphere.platform.support.aas.SubmodelElementContainerBuilder smBuilder,
                                                          java.util.function.Predicate<java.lang.String> filter,
                                                          java.lang.String channel,
                                                          java.lang.String id,
                                                          de.iip_ecosphere.platform.transport.connectors.TransportSetup setup)
        Adds service metrics to the submodel/elements. If LAMBDA_SETTERS_SUPPORTED, values are bound against a transport connector receiver.
        Parameters:
        smBuilder - submodel/elements builder of the AAS
        filter - metrics filter, may be null for all (currently ignored)
        channel - the transport channel to listen to
        id - the metrics provider id to listen to
        setup - the transport setup
      • removeProviderMetricsFromAasSubmodel

        public static void removeProviderMetricsFromAasSubmodel​(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection sub)
        Removes provider metrics and all related elements from sub.
        Parameters:
        sub - the submodel elements collection to remove the elements from