Source code for behaviours.SvcACLHandlingBehaviour

import json
import logging
import time

from spade.behaviour import CyclicBehaviour

from logic import Services_utils, Interactions_utils
from utilities.AASarchiveInfo import AASarchiveInfo

_logger = logging.getLogger(__name__)


[docs] class SvcACLHandlingBehaviour(CyclicBehaviour): """ This class implements the behaviour that handles all the ACL messages that the AAS Manager will receive from the others standardized AAS Manager in the I4.0 System. """ def __init__(self, agent_object): """ The constructor method is rewritten to add the object of the agent Args: agent_object (spade.Agent): the SPADE agent object of the AAS Manager agent. """ # The constructor of the inherited class is executed. super().__init__() # The SPADE agent object is stored as a variable of the behaviour class self.myagent = agent_object
[docs] async def on_start(self): """ This method implements the initialization process of this behaviour. """ _logger.info("ACLHandlingBehaviour starting...")
[docs] async def run(self): """ This method implements the logic of the behaviour. """ # Wait for a message with the standard ACL template to arrive. msg = await self.receive(timeout=10) # Timeout set to 10 seconds so as not to continuously execute the behavior. if msg: # TODO modificar el concepto de como gestionar los servicios. En este behaviour (llamemosle a partir de ahora # SvcRequestsHanldingBehaviour) se gestionarán todas las peticiones de servicios via ACL, pero no gestionará # cada servicio individualmente. Por cada servicio añadira otro behaviour al agente (llamemosle # 'SvcHandlingBehaviour') y este sí será el encargado de gestionar ese servicio en concreto. De esta forma, # conseguimos que los servicios se gestionen "en paralelo" (aunque no es 100% paralelo según van llegando # peticiones de servicios se van generando behaviours, así que se van gestionando todos a la vez). Gracias # a esta forma cada behaviour individual es capaz de gestionar mas facilmente su servicio (analizar si # tarda mucho en realizarse, guardar en el log cuando finalice toda la informacion que la tendra en su # propia clase, etc.). Cada behaviour individual será el que se eliminará del agente en cuanto el servicio # se haya completado (self.kill()) # An ACL message has been received by the agent _logger.info(" + Message received on AAS Manager Agent (ACLHandlingBehaviour)") _logger.info(" |___ Message received with content: {}".format(msg.body)) # The msg body will be parsed to a JSON object msg_json_body = json.loads(msg.body) # As the performative is set to CallForProposals, the service type will be analyzed directly match msg_json_body['serviceType']: # TODO esta hecho asi para pruebas, pero hay que pensar el procedimiento a seguir a la hora de gestionar los mensajes ACL case "AssetRelatedService": self.handle_asset_related_svc(msg_json_body) case "AASInfrastructureServices": self.handle_aas_infrastructure_svc(msg_json_body) case "AASservices": self.handle_aas_services(msg_json_body) case "SubmodelServices": self.handle_submodel_services(msg_json_body) case _: _logger.error("Service type not available.") else: _logger.info(" - No message received within 10 seconds on AAS Manager Agent (ACLHandlingBehaviour)")
# ------------------------------------------ # Methods to handle of all types of services # ------------------------------------------
[docs] def handle_aas_infrastructure_svc(self, svc_data): """ This method handles AAS Infrastructure Services. These services are part of I4.0 Infrastructure Services (Systemic relevant). They are necessary to create AASs and make them localizable and are not offered by an AAS, but by the platform (computational infrastructure). These include the AAS Create Service (for creating AASs with unique identifiers), AAS Registry Services (for registering AASs) and AAS Exposure and Discovery Services (for searching for AASs). Args: svc_interaction_id (int): the identifier of the interaction. svc_data (dict): the information of the data in JSON format. """ _logger.info(str(self.agent.interaction_id) + str(svc_data))
[docs] def handle_aas_services(self, svc_data): """ This method handles AAS Services. These services serve for the management of asset-related information through a set of infrastructure services provided by the AAS itself. These include Submodel Registry Services (to list and register submodels), Meta-information Management Services (including Classification Services, to check if the interface complies with the specifications; Contextualization Services, to check if they belong together in a context to build a common function; and Restriction of Use Services, divided between access control and usage control) and Exposure and Discovery Services (to search for submodels or asset related services). Args: svc_interaction_id (int): the identifier of the interaction. svc_data (dict): the information of the data in JSON format. """ _logger.info(str(self.agent.interaction_id) + str(svc_data))
[docs] def handle_submodel_services(self, svc_data): """ This method handles Submodel Services. These services are part of I4.0 Application Component (application relevant). Args: svc_interaction_id (int): the identifier of the interaction. svc_data (dict): the information of the data in JSON format. """ _logger.info(str(self.agent.interaction_id) + str(svc_data))