feat: apply source registry changes
This commit is contained in:
@@ -22,6 +22,7 @@ from .service.source_registry_admin import SourceRegistryAdminProvider
|
||||
from .service.workflow_operation_context import context_from_service
|
||||
from .tools import register_broker_tools
|
||||
from ..models import BrokerConfig
|
||||
from ..sdk.adapter import McpSdkAdapter
|
||||
from ..source_registry import FileSourceRegistryStore, SourceRegistryStore
|
||||
|
||||
|
||||
@@ -70,10 +71,18 @@ def workflow_server_from_service(
|
||||
registry_provider = SourceRegistryAdminProvider(
|
||||
source_registry_store=source_registry_store,
|
||||
config_connections=config.connections,
|
||||
connection_service=service.connection_service,
|
||||
config=config,
|
||||
ensure_adapter=lambda connection: service.register_adapter(
|
||||
connection.server, McpSdkAdapter()
|
||||
)
|
||||
if connection.server not in service.adapters
|
||||
else None,
|
||||
)
|
||||
source_registry_admin = WorkflowSourceRegistryApi(
|
||||
provider=registry_provider,
|
||||
mutation_provider=registry_provider,
|
||||
apply_provider=registry_provider,
|
||||
)
|
||||
stores = WorkflowStores(
|
||||
artifact_store=service.artifact_store,
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from collections.abc import Callable, Mapping, Sequence
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
from wf_api.source_registry_admin import WorkflowSourceRegistryMutationProvider
|
||||
|
||||
from ...models import ConnectionConfig
|
||||
from ...models import BrokerConfig, ConnectionConfig
|
||||
from ...source_registry import (
|
||||
McpSourceRegistryEntry,
|
||||
SourceRegistryFile,
|
||||
SourceRegistryStore,
|
||||
)
|
||||
from .connection_service import ConnectionService
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@@ -24,6 +25,9 @@ class SourceRegistryAdminProvider(WorkflowSourceRegistryMutationProvider):
|
||||
|
||||
source_registry_store: SourceRegistryStore
|
||||
config_connections: Sequence[ConnectionConfig] = field(default_factory=tuple)
|
||||
connection_service: ConnectionService | None = None
|
||||
config: BrokerConfig | None = None
|
||||
ensure_adapter: Callable[[ConnectionConfig], None] | None = None
|
||||
|
||||
# -- read helpers -------------------------------------------------------
|
||||
|
||||
@@ -118,3 +122,41 @@ class SourceRegistryAdminProvider(WorkflowSourceRegistryMutationProvider):
|
||||
sources = [s for s in registry.sources if s.id != source_id]
|
||||
self._save(sources)
|
||||
return {"removed": True, "source_id": source_id}
|
||||
|
||||
def apply_registry_changes(self) -> dict[str, Any]:
|
||||
"""Reconcile desired registry state into the live service connection graph.
|
||||
|
||||
This mirrors config reload reconciliation, but it only applies persisted
|
||||
registry state. It does not mutate config files or remount FastMCP proxy
|
||||
providers.
|
||||
"""
|
||||
if self.connection_service is None or self.config is None:
|
||||
raise RuntimeError("source registry apply requires runtime service context")
|
||||
|
||||
before = {connection.id: connection for connection in self.connection_service.list_all()}
|
||||
self.connection_service.sync_connections_from_config(
|
||||
self.config,
|
||||
source_registry_store=self.source_registry_store,
|
||||
)
|
||||
after = {connection.id: connection for connection in self.connection_service.list_all()}
|
||||
|
||||
if self.ensure_adapter is not None:
|
||||
for connection in after.values():
|
||||
self.ensure_adapter(connection)
|
||||
|
||||
before_ids = set(before)
|
||||
after_ids = set(after)
|
||||
updated = sorted(
|
||||
source_id
|
||||
for source_id in before_ids & after_ids
|
||||
if before[source_id] != after[source_id]
|
||||
)
|
||||
registry = self._load()
|
||||
return {
|
||||
"applied": True,
|
||||
"registered": sorted(after_ids - before_ids),
|
||||
"updated": updated,
|
||||
"removed": sorted(before_ids - after_ids),
|
||||
"connection_count": len(after),
|
||||
"registry_entry_count": len(registry.sources),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user