Class MetricsAasConstructor
java.lang.Object
de.iip_ecosphere.platform.services.environment.metricsProvider.metricsAas.MetricsAasConstructor
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
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceGeneric collection supplier.private static classHolds a received JSON object.private static classImplements a meter getter based onMetricsAasConstructor.JsonObjectHolder.private static classReceives monitoring information via the transport layer.private static classReceives monitoring information via the transport layer.static interfacePredicate to determine whether pushing a meter value shall happen. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MetricsAasConstructor.CollectionSupplierSupplies all collection elements that match thedeviceId.static final MetricsAasConstructor.CollectionSupplierDefault supplier for the submodel identified by the given id.private static Map<String, MetricsAasConstructor.JsonObjectHolder> static final booleanDoes the underlying AAS implementation execute Lambda-Setters for AAS properties.private static de.iip_ecosphere.platform.support.aas.Submodelprivate static booleanstatic final MetricsAasConstructor.PushMeterPredicateDefault push meter predicate which always returns true.static final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddProviderMetricsToAasSubmodel(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.static voidaddServiceMetricsToAasSubmodel(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.static voidclear()Clears temporary data structures.static voidclearProviderMetricsInAasSubmodel(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection sub) Clears provider metrics insubbut does not remove them.static booleancontainsMetrics(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection sub) Tests whether metrics properties do exist onsub.static de.iip_ecosphere.platform.support.aas.PropertycreateProperty(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.private static MetricsAasConstructor.JsonObjectHoldergetHolder(String id, String channel, de.iip_ecosphere.platform.transport.connectors.TransportSetup setup) Returns a JSON object holder associated to a transport connector throughMetricsAasConstructor.MetricsReceptionCallback.private static ObjectgetMeasurement(String json) Extracts the measurement out of the metrics JSON.Returns a (unmodifiable) mapping of monitoring meter names to AAS names.private static de.iip_ecosphere.platform.transport.connectors.TransportConnectorgetTransportConnector(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 givenchannelandsetup.private static voidpushToAas(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 tocoll.static voidpushToAas(String json, String submodel, MetricsAasConstructor.CollectionSupplier cSupplier, boolean update, MetricsAasConstructor.PushMeterPredicate mPredicate) Alternative approach to update the metric values.static voidpushToAas(String json, String submodel, MetricsAasConstructor.CollectionSupplier cSupplier, boolean update, Map<String, String> monMapping, MetricsAasConstructor.PushMeterPredicate mPredicate) Alternative approach to update the metric values.static voidpushToAasAlways(String json, String submodel, MetricsAasConstructor.CollectionSupplier cSupplier, boolean update, MetricsAasConstructor.PushMeterPredicate mPredicate) Alternative approach to update the metric values.static voidremoveProviderMetricsFromAasSubmodel(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection sub) Removes provider metrics and all related elements fromsub.
-
Field Details
-
ALL_ELEMENTS_SUPPLIER
Supplies all collection elements that match thedeviceId. -
DFLT_SUBMODEL_SUPPLIER
Default supplier for the submodel identified by the given id. -
PREDICATE_ALWAYS_TRUE
Default push meter predicate which always returns true. -
LAMBDA_SETTERS_SUPPORTED
public static final boolean LAMBDA_SETTERS_SUPPORTEDDoes 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
-
holders
-
monSubModel
private static de.iip_ecosphere.platform.support.aas.Submodel monSubModel -
monSubModelFailed
private static boolean monSubModelFailed -
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 givenchannelandsetup.- Parameters:
channel- the transport channelsetup- the transport setupcallbackSupplier- supplies the reception callback to use- Returns:
- the (cached) transport connector
-
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 notLAMBDA_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 channelsubmodel- the submodel to update (elements are assumed to be in a submodel elements collection on the next level)cSupplier- collection supplierupdate- whether this is an update or the first callmPredicate- optional predicate to identify whether pushing a value shall happen, may be null thenPREDICATE_ALWAYS_TRUEis 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 notLAMBDA_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 channelsubmodel- the submodel to update (elements are assumed to be in a submodel elements collection on the next level)cSupplier- collection supplierupdate- whether this is an update or the first callmPredicate- optional predicate to identify whether pushing a value shall happen, may be null thenPREDICATE_ALWAYS_TRUEis 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 notLAMBDA_SETTERS_SUPPORTED. Initial approach, not really performant. May have to be throttled.- Parameters:
json- the JSON to be sent to the monitoring channelsubmodel- the submodel to update (elements are assumed to be in a submodel elements collection on the next level)cSupplier- collection supplier withinsubmodelupdate- whether this is an update or the first callmonMapping- the meter-shortId mapping to usemPredicate- optional predicate to identify whether pushing a value shall happen, may be null thenPREDICATE_ALWAYS_TRUEis 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 tocoll.- Parameters:
coll- the collection to push tokey- the name of the metricjson- the measurement of the metricmonMapping- the meter-shortId mapping to usemPredicate- optional predicate to identify whether pushing a value shall happen, may be null thenPREDICATE_ALWAYS_TRUEis used
-
getMeasurement
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 throughMetricsAasConstructor.MetricsReceptionCallback.- Parameters:
id- the id to react onchannel- the transport channelsetup- 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 onsub.- Parameters:
sub- the submodel elements collection to test- Returns:
truefor metrics,falseelse
-
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 buildertype- the type of the propertychannel- the transport channel (ignored if notLAMBDA_SETTERS_SUPPORTED)id- the id to react on (ignored if notLAMBDA_SETTERS_SUPPORTED)setup- the transport setup (ignored if notLAMBDA_SETTERS_SUPPORTED)metricsName- the name of the metrics as defined in theMetricsProvidersemId- 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. IfLAMBDA_SETTERS_SUPPORTED, values are bound against a transport connector receiver.- Parameters:
smBuilder- submodel/elements builder of the AASfilter- metrics filter, may be null for all (currently ignored)channel- the transport channel to listen toid- the metrics provider id to listen tosetup- 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. IfLAMBDA_SETTERS_SUPPORTED, values are bound against a transport connector receiver.- Parameters:
smBuilder- submodel/elements builder of the AASfilter- metrics filter, may be null for all (currently ignored)channel- the transport channel to listen toid- the metrics provider id to listen tosetup- the transport setup
-
removeProviderMetricsFromAasSubmodel
public static void removeProviderMetricsFromAasSubmodel(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection sub) Removes provider metrics and all related elements fromsub.- 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 insubbut does not remove them.- Parameters:
sub- the submodel elements collection to clear the elements within
-