Sensoworks Edge/Fog architecture
Overview
The Sensoworks Fog architecture is designed to manage configurations, control flows, and monitor the status of various processes in a distributed environment. This document provides an overview of the architecture, including the main components and their interactions.
Components
1. Configuration Server
The ConfigurationServer
is a Flask-based server that exposes RESTful APIs for managing configurations and controlling flows. It interacts with the ConfigManager
and FlowManager
to handle configuration data and flow commands.
2. ConfigManager
The ConfigManager
handles the storage, retrieval, and manipulation of configuration data. It is responsible for reading configuration files, updating configurations, and providing configuration details to other components.
3. FlowManager
The FlowManager
is responsible for managing the lifecycle of flows. It can start, stop, pause, and resume flows based on the commands received from the ConfigurationServer
. The FlowManager
maintains the status of each flow and interacts with the SensoworksFog
instances to control their execution.
4.Workflow Engine (SensoworksFog class)
The SensoworksFog class represents a single flow instance and acts as the workflow engine. It is initialized with a configuration and is responsible for managing the execution of tasks within the flow. The SensoworksFog class handles triggering tasks based on defined conditions, managing state transitions, and ensuring tasks are executed in the correct order. Each SensoworksFog instance runs in a separate thread to allow concurrent execution of multiple flows.
5.Flows
The Flows component provides a user interface for managing configurations that the workflow engine will execute. This interface enabling users to efficiently set up and control their workflows within the IoT infrastructure. In addition to its configuration management capabilities, the Flows component communicates with the Edge-Broker component to exchange and synchronize information with the platform. This communication ensures that all configurations and workflow instructions are up-to-date and accurately reflect the current state of the system. Furthermore, the Flows component provides detailed information about the node on which it resides. This information is critical for maintaining an accurate and comprehensive view of the network's operational status, enhancing the platform's ability to manage and optimize its resources. By integrating with the Edge-Broker and providing a robust interface for workflow management, the Flows component plays a crucial role in the seamless operation of the IoT system, ensuring that configurations are effectively managed and executed across the network.
Interactions
Initialization
- MainSensoworksFogGateway: This is the main entry point for the application. It initializes the
ConfigManager
,FlowManager
, andConfigurationServer
, and starts the server andWorkflowEngine
instances as background processing threads. - ConfigurationServer: The server starts and listens for incoming API requests.
Configuration Management
- Get All Configurations: The
ConfigurationServer
receives a request to retrieve all configurations. It calls theget_all_configs
method on theConfigManager
, which reads and returns all configuration files. - Get Configuration by ID: The
ConfigurationServer
receives a request to retrieve a specific configuration. It calls theget_config
method on theConfigManager
with theflow_id
, and theConfigManager
returns the corresponding configuration. - Add/Update/Delete Configuration: The
ConfigurationServer
handles requests to add, update, or delete configurations by calling the respective methods on theConfigManager
.
Flow Control
- Start Flow: The
ConfigurationServer
receives a request to start flows. It calls thestart_flows
method on theFlowManager
with the list offlow_ids
. TheFlowManager
initializes and starts aSensoworksFog
instance for each flow. - Stop/Pause/Resume Flow: Similar to starting flows, the
ConfigurationServer
handles requests to stop, pause, or resume flows by calling the respective methods on theFlowManager
.
Status Monitoring
- Get Flow Status: The
ConfigurationServer
receives a request to retrieve the status of all flows or a specific flow. It calls theget_flow_status
method on theFlowManager
, which returns the current status information. - Current Task: The
FlowManager
can also provide details about the current task being executed in a flow.
Data Flow
- Configuration Files: Stored in a specified directory and managed by the
ConfigManager
. - Flow Status: Maintained in a shared dictionary with thread-safe access managed by the
flow_status_lock
. - Commands and Responses: Handled by the
ConfigurationServer
and passed to theFlowManager
for execution.
Example Workflow
- Starting the Server: The
MainSensoworksFogGateway
starts theConfigurationServer
and the background engine flow. - Adding a Configuration: A client sends a POST request to
/flows
with a new configuration. TheConfigurationServer
processes the request and updates the configuration files via theConfigManager
. - Starting a Flow: A client sends a PATCH request to
/flows/commands
with a start command and flow IDs. TheConfigurationServer
forwards the command to theFlowManager
, which initializes and starts theSensoworksFog
instances. - Monitoring Status: A client sends a GET request to
/flows/status
to retrieve the status of all flows. TheConfigurationServer
fetches the status from theFlowManager
and returns it to the client.