Class ServicesAas

java.lang.Object
de.iip_ecosphere.platform.services.ServicesAas
All Implemented Interfaces:
de.iip_ecosphere.platform.support.iip_aas.AasContributor

public class ServicesAas extends Object implements de.iip_ecosphere.platform.support.iip_aas.AasContributor
Implements the AAS for the services. Container ids used as short AAS ids may be translated into ids that are valid from the perspective of the AAS implementation. All nested elements also carry their original id in NAME_PROP_ID. The created submodels may be used standalone or deployed to a common server. In the second case, parts of the submodels will be complemented incrementally, e.g., the relations by the services started or the resources by the ECS runtime. This class builds the submodel services (NAME_SUBMODEL):
  • A submodel elements collection "services" NAME_COLL_SERVICES containing all declared services with their input and output types using the service id as ID.
  • A submodel elements collection "artifacts" NAME_COLL_ARTIFACTS with all artifacts implementing the services using the artifact id as ID.
  • A submodel elements collection "relations" NAME_COLL_RELATIONS with all relations connecting the services with the channel name as ID. This part is aimed at a quick lookup whether a related service is already there.
Moreover, this class builds the parts of the submodel resources (NAME_SUBMODEL_RESOURCES), containing submodel elements named according to the Unique JVM identifier of this process containing the provided operations. This submodel is complemented by the ECSruntime with more resource specific information.
Author:
Holger Eichelberger, SSE
  • Field Details

  • Constructor Details

    • ServicesAas

      public ServicesAas()
  • Method Details

    • contributeTo

      public de.iip_ecosphere.platform.support.aas.Aas contributeTo(de.iip_ecosphere.platform.support.aas.Aas.AasBuilder aasBuilder, de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator)
      Specified by:
      contributeTo in interface de.iip_ecosphere.platform.support.iip_aas.AasContributor
    • createServiceManagerSubmodelElements

      private void createServiceManagerSubmodelElements(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder builder, de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator)
      Creates the elements representing a service manager.
      Parameters:
      builder - the target builder
      iCreator - the invocables creator for binding (remote) property and operation implementations.
    • createIdOp

      private void createIdOp(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder smB, String name, de.iip_ecosphere.platform.support.aas.InvocablesCreator iCreator, String... otherParams)
      Creates an operation with a String parameter "id" and optional string parameters and a result of type string. The operation name is derived from name applied to getQName(String).
      Parameters:
      smB - the submodel elements collection builder
      name - the operation name
      iCreator - the invocables creator
      otherParams - other String parameters
    • getQName

      public static String getQName(String elementName)
      Returns the qualified name for an operation/property implementation.
      Parameters:
      elementName - the element name
      Returns:
      the qualified name
    • readStringArray

      private static String[] readStringArray(Object[] args, int index)
      Reads all params as string array.
      Parameters:
      args - the arguments
      index - the index of the argument to read from args
      Returns:
      the string array
    • contributeTo

      public void contributeTo(de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder sBuilder)
      Specified by:
      contributeTo in interface de.iip_ecosphere.platform.support.iip_aas.AasContributor
    • getServiceStateCount

      private static int getServiceStateCount(String state)
      Returns the number of service instances in the given state. Preliminarily in here, may be moved into the service manager
      Parameters:
      state - the state
      Returns:
      the number of service instances
    • contributeArtifactTo

      private void contributeArtifactTo(de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder sBuilder)
      Further operation contributions for artifacts.
      Parameters:
      sBuilder - the server protocol builder
    • contributeTaskTo

      private void contributeTaskTo(de.iip_ecosphere.platform.support.aas.ProtocolServerBuilder sBuilder)
      Further task operation contributions.
      Parameters:
      sBuilder - the server protocol builder
    • getKind

      public de.iip_ecosphere.platform.support.iip_aas.AasContributor.Kind getKind()
      Specified by:
      getKind in interface de.iip_ecosphere.platform.support.iip_aas.AasContributor
    • addArtifact

      private static void addArtifact(de.iip_ecosphere.platform.support.aas.Submodel.SubmodelBuilder smB, ArtifactDescriptor desc)
      Adds an artifact to the given submodel builder.
      Parameters:
      smB - represents the submodel in creation
      desc - the descriptor to be added
    • addService

      private static void addService(de.iip_ecosphere.platform.support.aas.Submodel.SubmodelBuilder smB, ServiceDescriptor desc)
      Adds an service to the given submodel builder.
      Parameters:
      smB - represents the submodel in creation
      desc - the descriptor to be added
    • addServiceOperations

      private static void addServiceOperations(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder descriptorBuilder, ServiceDescriptor desc)
      Adds the service operations to descriptorBuilder. Own method as depending on AAS setup may be called twice, once without invokable, once to update the operations then with invokable.
      Parameters:
      descriptorBuilder - the descriptor builder representing desc
      desc - the actual service descriptor to represent
      See Also:
    • defineServiceOperations

      private static void defineServiceOperations(ServiceDescriptor desc, de.iip_ecosphere.platform.support.iip_aas.ActiveAasBase.NotificationMode mode)
      Updates the service operations, e.g., to add information an updated/newly created invokable.
      Parameters:
      desc - the descriptor
      mode - the notification mode, may be null for default
      See Also:
    • addTypedData

      private static void addTypedData(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder builder, String name, List<? extends TypedDataDescriptor> descriptors)
      Adds a typed data submodel elements collection to the given builder.
      Parameters:
      builder - the builder to use as parent
      name - the name of the collection
      descriptors - the descriptors to add to the parent collection
    • addRelationData

      private static void addRelationData(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder builder, List<? extends TypedDataConnectorDescriptor> descriptors, boolean input, de.iip_ecosphere.platform.support.aas.Reference serviceRef)
      Adds data to NAME_COLL_RELATIONS.
      Parameters:
      builder - the builder to use as parent
      descriptors - the descriptors to add to the parent collection
      input - whether we are processing input or output descriptors
      serviceRef - the reference to the using service
    • createAvailabilityPredicate

      public static Predicate<TypedDataConnectorDescriptor> createAvailabilityPredicate(int timeout, int retryDelay, boolean input)
      Returns an availability predicate functor to determine whether typed data connector descriptors do exist in the AAS.
      Parameters:
      timeout - the timeout in ms within the request shall be repeated without directly failing
      retryDelay - time delay in ms after which a failed request shall be re-tried
      input - whether input or output side of the relation shall be queried
      Returns:
      the predictate for testing
    • notifyArtifactAdded

      public static void notifyArtifactAdded(ArtifactDescriptor desc)
      Is called when an artifact is added.
      Parameters:
      desc - the artifact descriptor
    • notifyServiceAdded

      public static void notifyServiceAdded(ServiceDescriptor desc)
      Is called when a service (via app instances) is added.
      Parameters:
      desc - the service descriptor
    • notifyArtifactRemoved

      public static void notifyArtifactRemoved(ArtifactDescriptor desc)
      Is called when an artifact is removed.
      Parameters:
      desc - the artifact descriptor
    • removeArtifact

      private static void removeArtifact(de.iip_ecosphere.platform.support.aas.Submodel sub, ArtifactDescriptor desc)
      Removes the artifact desc from the submodel sub. Removes also all services.
      Parameters:
      sub - the submodel
      desc - the artifact descriptor to remove
    • notifyManagerRemoved

      public static void notifyManagerRemoved()
      Called when the service manager disappears.
    • removeRelations

      private static de.iip_ecosphere.platform.support.aas.SubmodelElementCollection removeRelations(ServiceDescriptor service, de.iip_ecosphere.platform.support.aas.Submodel sub, de.iip_ecosphere.platform.support.aas.SubmodelElementCollection coll)
      Remove the relations for service.
      Parameters:
      service - the service
      sub - the submodel for NAME_SUBMODEL.
      coll - the relations submodel elements collection, may be null then sub is queried for the collection
      Returns:
      coll or the queried collection
    • removeService

      private static void removeService(ServiceDescriptor service, de.iip_ecosphere.platform.support.aas.Submodel sub)
      Removes service.
      Parameters:
      service - the service
      sub - the submodel for NAME_SUBMODEL.
    • deleteSubmodelElement

      private static void deleteSubmodelElement(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection coll, String name, String elt)
      Safely deletes a submodel element in a nested collection.
      Parameters:
      coll - the parent collection
      name - name the child collection
      elt - element the element to delete
    • notifyServiceStateChanged

      public static void notifyServiceStateChanged(de.iip_ecosphere.platform.services.environment.ServiceState old, de.iip_ecosphere.platform.services.environment.ServiceState act, ServiceDescriptor desc)
      Is called when a service state changed.
      Parameters:
      old - the previous state before the change
      act - the actual state after the change
      desc - the service descriptor (depending on implementation, may have the new state or not)
    • notifyServiceStateChanged

      public static void notifyServiceStateChanged(de.iip_ecosphere.platform.services.environment.ServiceState old, de.iip_ecosphere.platform.services.environment.ServiceState act, ServiceDescriptor desc, de.iip_ecosphere.platform.support.iip_aas.ActiveAasBase.NotificationMode mode)
      Is called when a service state changed.
      Parameters:
      old - the previous state before the change
      act - the actual state after the change
      desc - the service descriptor (depending on implementation, may have the new state or not)
      mode - explicit notification mode to be used (if null, use the mode defined in ActiveAasBase)
    • registerMetrics

      private static void registerMetrics(ServiceDescriptor desc, de.iip_ecosphere.platform.support.aas.Submodel sub, de.iip_ecosphere.platform.support.aas.SubmodelElementCollection elt)
      Registers metrics for a changed service.
      Parameters:
      desc - the service descriptor
      sub - the submodel
      elt - the element representing the service
    • registerMetrics

      private static void registerMetrics(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder subB)
      Registers metrics for a service service.
      Parameters:
      subB - the submodel element collection builder representing the service
    • setupRelations

      private static void setupRelations(ServiceDescriptor desc, de.iip_ecosphere.platform.support.aas.Submodel sub, de.iip_ecosphere.platform.support.aas.SubmodelElementCollection elt)
      Sets up the relations for a starting service.
      Parameters:
      desc - the service descriptor
      sub - the submodel
      elt - the element representing the service
    • removeDevice

      public static void removeDevice(String deviceId)
      Removes a specific device.
      Parameters:
      deviceId - the device id
      See Also:
    • removeDevice

      public static void removeDevice(de.iip_ecosphere.platform.support.aas.Submodel sub, String deviceId)
      Removes a specific device from sub.
      Parameters:
      sub - the submodel to delete from
      deviceId - the device id
    • clearRelations

      private static void clearRelations(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection coll, String aasDeviceId, String deviceId)
      Clears a relations collection from elements with the given resource property and value aasDeviceId.
      Parameters:
      coll - the collection to be cleared
      aasDeviceId - the AAS device id
      deviceId - the readable device ID
    • setCleanup

      public static void setCleanup(de.iip_ecosphere.platform.support.aas.Submodel sm, String deviceId)
      Sets the cleanup flag to true.
      Parameters:
      sm - the submodel to set the cleanup flag on
      deviceId - the device ID of the device to set into cleanup
    • deferForCleanup

      public static void deferForCleanup(de.iip_ecosphere.platform.support.aas.SubmodelElementCollection.SubmodelElementCollectionBuilder smBuilder)
      Defers the creation of smBuilder if the device is still in cleanup.
      Parameters:
      smBuilder - the device submodel builder
    • getLogger

      private static de.iip_ecosphere.platform.support.logging.Logger getLogger()
      Returns the logger instance.
      Returns:
      the logger instance
    • isValid

      public boolean isValid()
      Specified by:
      isValid in interface de.iip_ecosphere.platform.support.iip_aas.AasContributor