Connector#
Warning
The Connector class is an abstract class not intented to be used.
Defines the abstract base class for device connectors.
Each connector handles deployment and teardown of devices for a specific connector type (e.g., OpenFactory, MTConnect, OPCUA).
Creating a New Connector#
To add a new connector type to OpenFactory, follow these steps:
Create a Schema for Your Connector
Define a Pydantic schema for your connector configuration (e.g.,
MyConnectorSchema).Include all fields required for deployment and teardown, such as IPs, ports, resource limits, or other connector-specific parameters.
Make sure to include a
typefield that matches your connector type string. This field is used as a discriminator when parsing device configurations.Register your schema in the
openfactory.schemas.connectors.types.ConnectorUnion to enable type-based parsing:
Implement the Connector Class
Subclass
Connectorand implement the following methods:deploy(device: Device, yaml_config_file: str) -> NoneRegister the device asset, deploy any required services (agents, producers), and create dependencies (Kafka topics, ksqlDB tables, supervisors).
tear_down(device_uuid: str) -> NoneRemove all deployed resources for the device.
Register Your Connector
Use the
@register_connectordecorator to register your connector class with its schema:@register_connector(MyConnectorSchema) class MyConnector(Connector): def deploy(self, device: Device, yaml_config_file: str): ... def tear_down(self, device_uuid: str): ...
Write Unit Tests
Mock all external dependencies (Docker, Kafka, ksqlDB, user notifications).
Test deployment, teardown, error handling, and service generation logic.
Integrate With OpenFactoryManager
Functions like
deploy_devices_from_config_filewill automatically use your connector as long as it is registered and its schema is correctly referenced in the device configuration.
Minimal Connector Template#
from openfactory.connectors.base_connector import Connector
from openfactory.connectors.registry import register_connector
from openfactory.schemas.connectors.my_connector import MyConnectorSchema
from openfactory.schemas.devices import Device
@register_connector(MyConnectorSchema)
class MyConnector(Connector):
def deploy(self, device: Device, yaml_config_file: str) -> None:
# Implement your deployment logic here
pass
def tear_down(self, device_uuid: str) -> None:
# Implement your teardown logic here
pass