java.lang.Object
de.iip_ecosphere.platform.services.environment.metricsProvider.metricsAas.MetricsAasConstructor

public class MetricsAasConstructor extends 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 Details

    • ALL_ELEMENTS_SUPPLIER

      public static final MetricsAasConstructor.CollectionSupplier ALL_ELEMENTS_SUPPLIER
      Supplies all collection elements that match the deviceId.
    • DFLT_SUBMODEL_SUPPLIER

      public static final MetricsAasConstructor.CollectionSupplier DFLT_SUBMODEL_SUPPLIER
      Default supplier for the submodel identified by the given id.
    • PREDICATE_ALWAYS_TRUE

      public static final MetricsAasConstructor.PushMeterPredicate PREDICATE_ALWAYS_TRUE
      Default push meter predicate which always returns true.
    • 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.
    • RECEIVE_METRICS_FROM_TRANSPORT

      public static final boolean RECEIVE_METRICS_FROM_TRANSPORT
      See Also:
    • conns

      private static Map<String,de.iip_ecosphere.platform.transport.connectors.TransportConnector> conns
    • holders

    • monSubModel

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

      private static boolean monSubModelFailed
    • monMapping

      private static Map<String,String> monMapping
  • Constructor Details

    • MetricsAasConstructor

      public MetricsAasConstructor()
  • Method Details

    • clear

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

      private static de.iip_ecosphere.platform.transport.connectors.TransportConnector getTransportConnector(String channel, de.iip_ecosphere.platform.transport.connectors.TransportSetup setup, Supplier<de.iip_ecosphere.platform.transport.connectors.ReceptionCallback<?>> callbackSupplier)
      Returns a transport connector for the given channel and setup.
      Parameters:
      channel - the transport channel
      setup - the transport setup
      callbackSupplier - supplies the reception callback to use
      Returns:
      the (cached) transport connector
    • getMonitoringMapping

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

      public static void pushToAas(String json, 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
    • pushToAasAlways

      public static void pushToAasAlways(String json, 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(String json, String submodel, MetricsAasConstructor.CollectionSupplier cSupplier, boolean update, Map<String,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, String key, de.iip_ecosphere.platform.support.json.JsonValue json, Map<String,String> monMapping, MetricsAasConstructor.PushMeterPredicate mPredicate)
      Pushes a JSON metrics entry to coll.
      Parameters:
      coll - the collection to push to
      key - the name of the metric
      json - the measurement of the metric
      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 Object getMeasurement(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(String id, String channel, de.iip_ecosphere.platform.transport.connectors.TransportSetup setup)
      Returns a JSON object holder associated to a transport connector through MetricsAasConstructor.MetricsReceptionCallback.
      Parameters:
      id - the id to react on
      channel - the transport channel
      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, String channel, String id, de.iip_ecosphere.platform.transport.connectors.TransportSetup setup, String metricsName, 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, Predicate<String> filter, String channel, 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, Predicate<String> filter, String channel, 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
    • clearProviderMetricsInAasSubmodel

      public static void clearProviderMetricsInAasSubmodel(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection sub)
      Clears provider metrics in sub but does not remove them.
      Parameters:
      sub - the submodel elements collection to clear the elements within