Class MetricsAasConstructor
- java.lang.Object
-
- de.iip_ecosphere.platform.services.environment.metricsProvider.metricsAas.MetricsAasConstructor
-
public class MetricsAasConstructor extends java.lang.ObjectClass 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 throughfunctor objectsto 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 ashared object. The shared object is attached through atransport layer callbackto 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 theshared 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 bereleasedwhen the program shuts down.- Author:
- Miguel Gomez, Holger Eichelberger, SSE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMetricsAasConstructor.CollectionSupplierGeneric collection supplier.private static classMetricsAasConstructor.JsonObjectHolderHolds a received JSON object.private static classMetricsAasConstructor.MeterGetterImplements a meter getter based onMetricsAasConstructor.JsonObjectHolder.private static classMetricsAasConstructor.MetricsReceptionCallbackReceives monitoring information via the transport layer.static interfaceMetricsAasConstructor.PushMeterPredicatePredicate to determine whether pushing a meter value shall happen.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,de.iip_ecosphere.platform.transport.connectors.TransportConnector>connsstatic MetricsAasConstructor.CollectionSupplierDFLT_SUBMODEL_SUPPLIERDefault supplier for the submodel identified by the given id.private static java.util.Map<java.lang.String,MetricsAasConstructor.JsonObjectHolder>holdersstatic booleanLAMBDA_SETTERS_SUPPORTEDDoes the underlying AAS implementation execute Lambda-Setters for AAS properties.private static java.util.Map<java.lang.String,java.lang.String>monMappingprivate static de.iip_ecosphere.platform.support.aas.SubmodelmonSubModelprivate static booleanmonSubModelFailedstatic MetricsAasConstructor.PushMeterPredicatePREDICATE_ALWAYS_TRUEDefault push meter predicate which always returns true.
-
Constructor Summary
Constructors Constructor Description MetricsAasConstructor()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddProviderMetricsToAasSubmodel(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.static voidaddServiceMetricsToAasSubmodel(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.static voidclear()Clears temporary data structures.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, 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.private static MetricsAasConstructor.JsonObjectHoldergetHolder(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 throughMetricsAasConstructor.MetricsReceptionCallback.private static java.lang.ObjectgetMeasurement(java.lang.String json)Extracts the measurement out of the metrics JSON.static java.util.Map<java.lang.String,java.lang.String>getMonitoringMapping()Returns a (unmodifiable) mapping of monitoring meter names to AAS names.private static de.iip_ecosphere.platform.transport.connectors.TransportConnectorgetTransportConnector(java.lang.String channel, de.iip_ecosphere.platform.transport.connectors.TransportSetup setup)Returns a transport connector for the givenchannelandsetup.private static voidpushToAas(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 tocoll.static voidpushToAas(java.lang.String json, java.lang.String submodel, MetricsAasConstructor.CollectionSupplier cSupplier, boolean update, MetricsAasConstructor.PushMeterPredicate mPredicate)Alternative approach to update the metric values.static voidpushToAas(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.static voidremoveProviderMetricsFromAasSubmodel(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection sub)Removes provider metrics and all related elements fromsub.
-
-
-
Field Detail
-
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. 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
-
holders
private static java.util.Map<java.lang.String,MetricsAasConstructor.JsonObjectHolder> holders
-
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
-
-
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 givenchannelandsetup.- Parameters:
channel- the transport channelsetup- 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 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(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 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, 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 tocoll.- Parameters:
coll- the collection to push toent- the metrics entry containing metrics name and measurementmonMapping- the meter-shortId mapping to usemPredicate- optional predicate to identify whether pushing a value shall happen, may be null thenPREDICATE_ALWAYS_TRUEis 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 throughMetricsAasConstructor.MetricsReceptionCallback.- Parameters:
channel- the transport channelid- the id to react onsetup- 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, 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 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, 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. 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, 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. 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
-
-