OpenFactoryManager#
OpenFactory Manager API.
This module provides the OpenFactoryManager class, which manages the deployment, configuration, and teardown of devices and applications within an OpenFactory environment.
- Core responsibilities:
Deploy MTConnect agents, and OpenFactory applications
Manage Docker-based services via the configured deployment strategy
Register and deregister assets in the OpenFactory environment
Integrate deployed services with Kafka, ksqlDB, and other OpenFactory components
Validate configuration files against the UNS schema
Notify users of deployment results, warnings, and failures
- Key integrations:
Docker for container lifecycle management
Kafka and ksqlDB for data streaming and querying
UNS Schema for configuration validation
User notifications for communicating operational outcomes
Plugin system for selecting deployment strategies
- Usage Example:
from openfactory import OpenFactoryManager from openfactory.kafka.ksql import KSQLDBClient import openfactory.config as config ofa_manager = OpenFactoryManager(ksqlClient=KSQLDBClient(config.KSQLDB_URL)) # deploy some devices ofa_manager.deploy_devices_from_config_file('/path/to/device_config.yml')
- Error handling:
Raises OFAException for critical operational failures
Catches and logs Docker API errors
Skips existing or invalid deployments without stopping other deployments
Important
User requires Docker access on the OpenFactory cluster.
- class openfactory.openfactory_manager.OpenFactoryManager(ksqlClient, bootstrap_servers=None, asset_url=None)[source]#
Bases:
OpenFactoryOpenFactory Manager API.
Allows to deploy services on OpenFactory.
Important
User requires Docker access on the OpenFactory cluster.
- deployment_strategy#
The strategy used to deploy services.
- __init__(ksqlClient, bootstrap_servers=None, asset_url=None)[source]#
Initializes the OpenFactoryManager.
- Parameters:
ksqlClient (KSQLDBClient) – The client for interacting with ksqlDB.
bootstrap_servers (str | None) – Kafka bootstrap server address. If not provided, the value from
openfactory.config.KAFKA_BROKERis used.asset_url (str | None) – URL of the Asset Router. If not provided, the value from
openfactory.config.ASSET_ROUTER_URLis used.
- Raises:
OFAException – If no Asset Router URL is available (neither explicitly provided nor configured via
.ofaenv).
Note
The deployment strategy to use (e.g., swarm or docker) is selected based on
config.DEPLOYMENT_PLATFORM
- deploy_apps_from_config_file(yaml_config_file)[source]#
Deploy OpenFactory applications from a YAML configuration file.
This method loads and validates the UNS schema, parses the application configurations from the specified YAML file, and deploys each application that is not already deployed.
- Return type:
- Parameters:
yaml_config_file (str) – Path to the YAML configuration file containing application definitions.
Note
If the UNS schema is invalid, a failure notification will be triggered, and deployment will abort early.
If application configurations fail to load or validate, deployment will abort early after notifying the user.
Deployment skips applications that are already deployed.
- deploy_devices_from_config_file(yaml_config_file)[source]#
Deploy OpenFactory devices from a YAML configuration file.
This method loads and validates the UNS schema, parses the device configurations from the specified YAML file, and deploys each device that is not already deployed.
Deployment includes registering the device asset, deploying the MTConnect agent, Kafka producer, and KSQLDB tables (if defined).
- Return type:
- Parameters:
yaml_config_file (str) – Path to the YAML configuration file containing device definitions.
Note
If the UNS schema is invalid, a failure notification will be triggered, and deployment will abort early.
If device configurations fail to load or validate, deployment will abort early after notifying the user.
Deployment skips devices that are already deployed.
- deploy_openfactory_application(application)[source]#
Deploy an OpenFactory application.
- Return type:
- Parameters:
application (OpenFactoryAppSchema) – The application configuration.
- Raises:
OFAException – If the application cannot be deployed.
- get_asset_uuid_from_docker_service(docker_service_name)[source]#
Return ASSET_UUID of the asset running on the Docker service docker_service_name.
- shut_down_apps_from_config_file(yaml_config_file)[source]#
Shut down OpenFactory applications based on a config file.
- Return type:
- Parameters:
yaml_config_file (str) – Path to the yaml configuration file.
- Raises:
OFAException – If the application cannot be shut down.
- shut_down_devices_from_config_file(yaml_config_file)[source]#
Shut down devices based on a config file.
- Return type:
- Parameters:
yaml_config_file (str) – Path to the yaml configuration file.
- Raises:
OFAException – If the device cannot be shut down.
- tear_down_application(app_uuid)[source]#
Tear down a deployed OpenFactory application.
- Return type:
- Parameters:
app_uuid (str) – The UUID of the application to be torn down.
- Raises:
OFAException – If the application cannot be torn down.