java.lang.Object
de.iip_ecosphere.platform.services.environment.AbstractService
de.iip_ecosphere.platform.services.environment.services.TraceToAasService
All Implemented Interfaces:
ParameterConfigurerProvider, Service, ServiceBase

public class TraceToAasService extends AbstractService
Implements a generic service that maps TraceRecord to an (application) AAS. This service is in development/preliminary. The service does not take any data or produce data, it is just meant to create up the trace record AAS entries. It can be used as a sink. Currently, the service builds up the AAS of an application. However, this functionality shall be moved that the platform is providing the AAS and the service just hooks the traces submodel into. Can optionally send AAS data to a transport channel (see createTransport(BasicSerializerProvider), getAasTransportChannel(), getTransportParameter()).
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • TraceToAasService

      public TraceToAasService(de.iip_ecosphere.platform.support.iip_aas.ApplicationSetup app, YamlService yaml)
      Creates a service instance.
      Parameters:
      app - static information about the application
      yaml - the service description
    • TraceToAasService

      public TraceToAasService(String serviceId, InputStream ymlFile)
      Creates a service instance from a service id and a YAML artifact.
      Parameters:
      serviceId - the service id
      ymlFile - the YML file containing the YAML artifact with the service descriptor
    • TraceToAasService

      private TraceToAasService(TraceToAasService.YamlConstructionInfo info)
      Intermediary constructor based on TraceToAasService.YamlConstructionInfo.
      Parameters:
      info - the information instance
    • TraceToAasService

      public TraceToAasService(YamlArtifact artifact, String serviceId)
      Creates a service instance.
      Parameters:
      artifact - static information about the artifact this service is member of
      serviceId - the id of the service
  • Method Details

    • getGatewayServer

      public de.iip_ecosphere.platform.support.Server getGatewayServer()
      Returns the local gateway server.
      Returns:
      the server instance, may be null for none
    • registerParameterConfigurers

      protected void registerParameterConfigurers()
      Registers own parameter configurers. Called by constructor. Use addParameterConfigurer(ParameterConfigurer) to declare a parameter.
    • createDataRecorder

      protected DataRecorder createDataRecorder()
      Creates an optional data recorder instance.
      Returns:
      the data recorder instance, may be null for none
      See Also:
    • createDataRecorderOrig

      protected final DataRecorder createDataRecorderOrig()
      Creates a default data recorder instance (writes to target in JSON format). Cannot be overriden to be accessible to subclasses although createDataRecorder() is overridden.
      Returns:
      the data recorder instance, may be null for none
      See Also:
    • createConverter

      protected TransportConverter.ConverterInstances<de.iip_ecosphere.platform.transport.status.TraceRecord> createConverter()
      Creates the actual converter instance.
      Returns:
      the converter, the default one goes for web sockets (due to AAS performance problems)
    • setTimeout

      public void setTimeout(long timeout)
      Changes the timeout until trace events are deleted.
      Parameters:
      timeout - the timeout in ms
    • setCleanupTimeout

      public void setCleanupTimeout(long cleanupTimeout)
      Changes the cleanup timeout, i.e., the time between two cleanups.
      Parameters:
      cleanupTimeout - the timeout in ms
    • cleanup

      public boolean cleanup()
      Pursues a cleanup of the (internally known) AAS.
      Returns:
      whether a cleanup process was executed (not whether elements were deleted)
    • getApplicationSetup

      public de.iip_ecosphere.platform.support.iip_aas.ApplicationSetup getApplicationSetup()
      Returns the application setup.
      Returns:
      the application setup
    • addParameterConfigurer

      protected <T> void addParameterConfigurer(ParameterConfigurer<T> configurer)
      Adds a parameter configurer.
      Type Parameters:
      T - the type of the parameter
      Parameters:
      configurer - the configurer instance, ignored if null
    • getAasId

      public String getAasId()
      Returns the AAS idShort of the AAS represented by this service/application.
      Returns:
      the idShort
    • getAasUrn

      public String getAasUrn()
      Returns the AAS URN of the AAS represented by this service/application.
      Returns:
      the URN
    • isAasEnabled

      protected boolean isAasEnabled()
      Returns whether the AAS is enabled and shall be set up (the default) or whether it is intentionally deactivated and shall not be started/modified.
      Returns:
      true for enabled (default), false for disabled
    • mapPayloadType

      protected String mapPayloadType(Class<?> cls)
      Allows for application specific payload type names.
      Parameters:
      cls - the type
      Returns:
      the mapped name
    • composeIdentifier

      protected String composeIdentifier(String specificId)
      Composes an identifier based on getAasUrn() and the given specific identifier.
      Parameters:
      specificId - the specific identifier
      Returns:
      the composed identifier
      See Also:
      • AasUtils.composeIdentifier(String, String)
    • start

      protected ServiceState start() throws ExecutionException
      Description copied from class: AbstractService
      Starts the service and the background process.
      Overrides:
      start in class AbstractService
      Returns:
      the state to transition to, may be null for none
      Throws:
      ExecutionException - if starting the process fails
    • recordData

      protected void recordData(String channel, Object data)
      Allows to record arbitrary data.
      Parameters:
      channel - the channel, may be empty or null
      data - the data to be recorded
    • stop

      protected ServiceState stop()
      Description copied from class: AbstractService
      Stops the service and the background process.
      Overrides:
      stop in class AbstractService
      Returns:
      the state to transition to, may be null for none
    • isAasStarted

      public boolean isAasStarted()
      Returns whether the AAS was started/startup is done.
      Returns:
      true for started, false else
    • getAasTransportChannel

      protected String getAasTransportChannel()
      Returns the AAS transport channel.
      Returns:
      the AAS transport channel (per default, a combination of TRANSPORT_CHANNEL_PREFIX and the ServiceBase.getApplicationId(String)
    • getConfiguredSerializationProvider

      protected de.iip_ecosphere.platform.transport.serialization.BasicSerializerProvider getConfiguredSerializationProvider()
      Returns a pre-configured serialization provider for the output connector. Please consider registering data type implementations rather than data type interfaces.
      Returns:
      the provider
    • setTransportParameter

      public void setTransportParameter(de.iip_ecosphere.platform.transport.connectors.TransportParameter transportParameter)
      Defines the transport parameter for createTransport(BasicSerializerProvider).
      Parameters:
      transportParameter - the transport parameter
    • createTransport

      protected de.iip_ecosphere.platform.transport.connectors.TransportConnector createTransport()
      Returns:
      the connector
    • createTransport

      protected de.iip_ecosphere.platform.transport.connectors.TransportConnector createTransport(de.iip_ecosphere.platform.transport.serialization.BasicSerializerProvider serializationProvider)
      Creates an optional transport connector to pump received data out. [factory]
      Parameters:
      serializationProvider - pre-configured serialization provider
      Returns:
      the transport connector, may be null for none
    • getTransport

      protected de.iip_ecosphere.platform.transport.connectors.TransportConnector getTransport()
      Returns the optional transport connector to pump received data out.
      Returns:
      the transport connector, may be null for none
    • getTransportParameter

      public de.iip_ecosphere.platform.transport.connectors.TransportParameter getTransportParameter()
      Returns the optional transport parameters.
      Returns:
      the transport parameter, may be null for none
    • sendTransportAsync

      protected void sendTransportAsync(String channel, Object data)
      Sends data asynchronously via the optional transport connector. Does nothing if there is no transport connector, createTransport(BasicSerializerProvider).
      Parameters:
      channel - the channel to send to
      data - the data object to send
    • augmentServicesSubmodel

      private void augmentServicesSubmodel(de.iip_ecosphere.platform.support.aas.Submodel.SubmodelBuilder smBuilder)
      Adds elements to the services submodel if available.
      Parameters:
      smBuilder - the submodel builder
    • augmentCommandsSubmodel

      protected void augmentCommandsSubmodel(de.iip_ecosphere.platform.support.aas.Submodel.SubmodelBuilder smBuilder)
      Allows adding application-specific elements to the command submodel, e.g., operations. May not be called if AAS enabled supplier signals that there shall not be an AAS.
      Parameters:
      smBuilder - the builder, do not call Builder.build() in here!
    • migrate

      public void migrate(String resourceId) throws ExecutionException
      Description copied from interface: Service
      Migrates a service. However, it may be required to migrate/move the containing artifact. [adaptation]
      Parameters:
      resourceId - the target resource id, e.g., a device
      Throws:
      ExecutionException - if migration fails
    • update

      public void update(URI location) throws ExecutionException
      Description copied from interface: Service
      Updates the service by the service in the given location. This operation is responsible for stopping the running service (if needed), replacing it, starting the new service.
      Parameters:
      location - the location of the new service, e.g., an URL
      Throws:
      ExecutionException - if the given service cannot be updated for some reason, e.g., because the replacement service is not an evolved version of the running service
    • switchTo

      public void switchTo(String targetId) throws ExecutionException
      Description copied from interface: Service
      Switches to an interface-compatible service. This method cares for stopping the old service, performing a handover if adequate, starting the target service. [adaptation]
      Parameters:
      targetId - the id of the target service
      Throws:
      ExecutionException - if switching the service cannot be performed for some reason
    • getParameterConfigurer

      public ParameterConfigurer<?> getParameterConfigurer(String paramName)
      Description copied from interface: ParameterConfigurerProvider
      Returns the parameter configurer for a given parameter. We need this generic approach to ease code generation and initial setting of parameter values.
      Parameters:
      paramName - the name of the parameter
      Returns:
      the associated parameter configurer or null if there is none
    • retrieveAas

      protected de.iip_ecosphere.platform.support.aas.Aas retrieveAas() throws IOException
      Retrieves the App AAS.
      Returns:
      the AAS
      Throws:
      IOException - if the App AAS cannot be retrieved, in particular if AAS enabled supplier signals that there shall not be an AAS.
    • isTraceInAas

      public boolean isTraceInAas()
      Returns whether traced data is directly stored in the AAS or not.
      Returns:
      true for traced data in AAS, false else