dataflow.server_management.base¶
Generic base server manager with full type safety.
This module provides the abstract base class for all server managers in Haive. It uses Python generics to ensure type safety while providing common functionality.
Classes¶
Generic base class for all server managers. |
|
Protocol for server lifecycle operations. |
Module Contents¶
- class dataflow.server_management.base.BaseServerManager(/, **data)¶
Bases:
pydantic.BaseModel
,abc.ABC
,Generic
[ConfigT
,InfoT
]Generic base class for all server managers.
This class provides a type-safe foundation for managing servers of any type. Subclasses should specify the concrete ConfigT and InfoT types.
- Type Parameters:
ConfigT: Server configuration type (must extend BaseServerConfig) InfoT: Server runtime info type (must extend BaseServerInfo)
- Parameters:
data (Any)
- servers¶
Currently running servers mapped by name
- available_configs¶
Available server configurations
- config_class¶
Configuration class for type validation
- info_class¶
Info class for runtime information
- auto_restart¶
Whether to automatically restart failed servers
- max_restart_attempts¶
Maximum restart attempts before giving up
- health_check_interval¶
Seconds between health checks
- restart_tracking¶
Tracks restart attempts per server
Example
Creating a concrete server manager:
class MyServerManager(BaseServerManager[MyConfig, MyInfo]): config_class = Field(default=MyConfig, exclude=True) info_class = Field(default=MyInfo, exclude=True) async def start_server(self, name: str, config: Optional[MyConfig] = None) -> MyInfo: # Implementation pass
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- add_config(name, config)¶
Add or update a server configuration.
- async cleanup()¶
Clean up resources and stop all servers.
- Return type:
None
- get_config(name)¶
Get server configuration by name.
- Parameters:
name (str) – Server name
- Returns:
Configuration object or None if not found
- Return type:
Optional[ConfigT]
- get_server_info(name)¶
Get runtime information for a server.
- Parameters:
name (str) – Server name
- Returns:
Server info or None if not running
- Return type:
Optional[InfoT]
- get_stats()¶
Get server manager statistics.
- Returns:
total_configured: Number of configured servers
total_running: Number of running servers
servers_by_status: Count by status
restart_counts: Restart attempts per server
- Return type:
Dictionary with stats including
- abstractmethod health_check(name)¶
-
Check if server is healthy.
- is_running(name)¶
Check if server is running.
- list_servers(status=None)¶
List servers by status.
- Parameters:
status (Optional[dataflow.server_management.models.ServerStatus]) – Optional status filter
- Returns:
List of server names
- Return type:
List[str]
- model_post_init(__context)¶
Additional initialization after validation.
- Parameters:
__context (Any)
- Return type:
None
- remove_config(name)¶
Remove a server configuration.
- Parameters:
name (str) – Server name
- Returns:
True if removed, False if not found
- Raises:
RuntimeError – If server is currently running
- Return type:
- abstractmethod restart_server(name)¶
- Async:
- Parameters:
name (str)
- Return type:
InfoT
Restart a server.
- Parameters:
name (str) – Server name
- Returns:
New server runtime information
- Return type:
InfoT
- async start_health_monitoring(name)¶
Start health monitoring for a server.
- Parameters:
name (str) – Server name
- Return type:
None
- abstractmethod start_server(name, config=None)¶
- Async:
- Parameters:
name (str)
config (Optional[ConfigT])
- Return type:
InfoT
Start a server with given configuration.
- Parameters:
name (str) – Server name
config (Optional[ConfigT]) – Optional configuration override
- Returns:
Server runtime information
- Raises:
ValueError – If no configuration found
RuntimeError – If server already running
- Return type:
InfoT
- async stop_health_monitoring(name)¶
Stop health monitoring for a server.
- Parameters:
name (str) – Server name
- Return type:
None
- abstractmethod stop_server(name, force=False)¶
-
Stop a running server.
- classmethod validate_config_types(v, info)¶
Ensure all configs are the correct type.
- classmethod validate_info_types(v, info)¶
Ensure all server info objects are the correct type.
- validate_restart_policy()¶
Validate restart configuration consistency.
- Return type:
- validate_server_consistency()¶
Ensure running servers have configurations.
- Return type:
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].