# Multi-Agent Dynamic Fog Service Placement Approach
## 3 Service Placement Orchestrator Implementation
### Dynamic Orchestrator Architecture  
A service placement orchestrator was implemented as a multi-agent system (MAS) Java application using a JADE framework. It allows us to develop MAS applications that comply with FIPA specifications. It offers such features as an agent abstraction, asynchronous messaging, and a service discovery based on the yellow pages method. The orchestrator is implemented as a distributed monitoring, decision making, and execution model, which is available in each fog node within a relevant fog computing system. Continuous resource monitoring and request processing allow us to make informed decisions in a dynamic way. Service distribution among multiple nodes contributes to the enhancement of computational output, power usage, and resilience. A distributed orchestrator is more resilient than a centralized one because of the absence of a single point of failure (SPF). Mobility, changing resource levels, and fog node failures preferably lead to dynamic and distributed decision making.  
Once the fog nodes connect to the same network to form a shared infrastructure, they start monitoring their resources such as CPU, RAM, battery, and security. The Monitoring agent waits for resource-related messages using a cyclic behavior. These messages are classified by use cases and tagged with relevant resource levels. A Request agent is waiting for service request messages. They are also classified by use cases. Due to a security add-on, JADE-S can be either signed, encrypted, or both signed and encrypted. Required security measures and used security measures are identified among involved agents and the messages can be discarded if these requirements are not met. Please see Figure 7 for more architecture details.  
Figure 6: Retrieving credentials in secure communication.  
The Decision Maker agent can obtain messages either from the Request agent, Resource Monitoring agent, or from the Synchronization agent. Messages from a Request agent can be related to a new service request or a current service redeployment. The Monitoring agent keeps its Decision Maker informed if resources are below a required level. There is also a Synchronization agent that keeps resource data synchronized among the involved fog nodes to let a Decision Maker make informed decisions when choosing a local or a remote service distribution. The Decision Maker uses IMOPSO and AHP algorithms to calculate the best deployment based on the objective functions. IMOPSO is used as a primary request processing algorithm for a higher number of options. Once these options are considered by the Decision Maker, a potential solution is further processed with a reference to objective functions. The AHP algorithm uses its criteria matrix to make a final placement decision based on prioritized criteria. Four criteria are used at the moment, but this number can be adjusted as required.  
As soon as a placement decision is made, it is communicated to the Execution agent. It runs a cyclic behavior waiting for its messages. Received messages are classified based on use cases or key words such as \"Decision\" for internal purposes. If there is a local redeployment within the same JADE platform, agents can be moved from one container to another. Agents can not be moved, however, to another platform. When services have to be redeployed remotely, current agents are killed and the other ones with the same parameters are created in a remote platform. Any changes in the fog computing infrastructure, whether they involve a new service placement or a remote redistribution, are synchronized by a Synchronization agent. Additional details about the architecture are available in the publication [54].