arkhai-compute-provisioning 0.26.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arkhai_compute_provisioning-0.26.0.dist-info/METADATA +18 -0
- arkhai_compute_provisioning-0.26.0.dist-info/RECORD +48 -0
- arkhai_compute_provisioning-0.26.0.dist-info/WHEEL +4 -0
- compute_provisioning/__init__.py +93 -0
- compute_provisioning/adapters.py +96 -0
- compute_provisioning/app.py +73 -0
- compute_provisioning/composition.py +346 -0
- compute_provisioning/definition_documents.py +38 -0
- compute_provisioning/events.py +28 -0
- compute_provisioning/executor_leases.py +48 -0
- compute_provisioning/hosts/__init__.py +12 -0
- compute_provisioning/hosts/connection.py +172 -0
- compute_provisioning/hosts/db.py +68 -0
- compute_provisioning/hosts/definitions.py +273 -0
- compute_provisioning/hosts/execution.py +26 -0
- compute_provisioning/hosts/route_service.py +159 -0
- compute_provisioning/hosts/service.py +545 -0
- compute_provisioning/inventory_views.py +182 -0
- compute_provisioning/job_fulfillment.py +540 -0
- compute_provisioning/jobs/__init__.py +23 -0
- compute_provisioning/jobs/action_request.py +29 -0
- compute_provisioning/jobs/db.py +116 -0
- compute_provisioning/jobs/engine.py +642 -0
- compute_provisioning/jobs/executor.py +123 -0
- compute_provisioning/jobs/executor_mock.py +266 -0
- compute_provisioning/jobs/queue.py +144 -0
- compute_provisioning/jobs/route_service.py +149 -0
- compute_provisioning/jobs/submission.py +127 -0
- compute_provisioning/lease_lifecycle.py +673 -0
- compute_provisioning/leases.py +165 -0
- compute_provisioning/lifecycle.py +33 -0
- compute_provisioning/relays/__init__.py +147 -0
- compute_provisioning/relays/allocator.py +589 -0
- compute_provisioning/relays/composition.py +115 -0
- compute_provisioning/relays/db.py +207 -0
- compute_provisioning/relays/definitions.py +359 -0
- compute_provisioning/relays/execution.py +168 -0
- compute_provisioning/relays/grants.py +104 -0
- compute_provisioning/relays/keys.py +127 -0
- compute_provisioning/relays/pool_relays.py +177 -0
- compute_provisioning/relays/rebinding.py +334 -0
- compute_provisioning/relays/route_service.py +201 -0
- compute_provisioning/relays/service.py +680 -0
- compute_provisioning/relays/variables.py +43 -0
- compute_provisioning/release.py +387 -0
- compute_provisioning/release_effects.py +75 -0
- compute_provisioning/route_errors.py +38 -0
- compute_provisioning/startup.py +146 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: arkhai-compute-provisioning
|
|
3
|
+
Version: 0.26.0
|
|
4
|
+
Summary: Shared helpers for cross-domain compute provisioning services
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Requires-Dist: arkhai-compute-provisioning-contracts>=0.13.0
|
|
8
|
+
Requires-Dist: arkhai-core>=0.4.0
|
|
9
|
+
Requires-Dist: arkhai-kit-config
|
|
10
|
+
Requires-Dist: arkhai-kit-fulfillment>=0.6.0
|
|
11
|
+
Requires-Dist: arkhai-kit-resource-pools-contracts>=0.3.0
|
|
12
|
+
Requires-Dist: arkhai-kit-resource-pools>=0.3.0
|
|
13
|
+
Requires-Dist: arkhai-kit-site>=0.10.0
|
|
14
|
+
Requires-Dist: cryptography>=42.0
|
|
15
|
+
Requires-Dist: pydantic>=2
|
|
16
|
+
Requires-Dist: pyyaml>=6.0
|
|
17
|
+
Requires-Dist: rfc8785>=0.1.4
|
|
18
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
compute_provisioning/__init__.py,sha256=1ljXvkW52MsYWGf9N3YhuOFdGXcdzT3FVg2nyimm1JE,2766
|
|
2
|
+
compute_provisioning/adapters.py,sha256=CIjeWwZBmMEkAM_N-gSsVETQg3tULm8mol6S5ESnMVk,3765
|
|
3
|
+
compute_provisioning/app.py,sha256=dU92_9vHflc6AUMbXoucIE_mGUfq5c0DYy4SH1o3tj8,1976
|
|
4
|
+
compute_provisioning/composition.py,sha256=8Jf66E_GYKrlLwOPW2jzz_9eSyOv28JUge5n5R_Grq8,14456
|
|
5
|
+
compute_provisioning/definition_documents.py,sha256=LaARzaUhq2FbsLhdIWsCMf03FZ9pz3Y-kIQU85-fzuU,1431
|
|
6
|
+
compute_provisioning/events.py,sha256=zH5hSKO17cbjbTHNzif-Fcl_2uh9FHfFLtqiu9HA3dg,938
|
|
7
|
+
compute_provisioning/executor_leases.py,sha256=uDX4XoTnFa7xcNXfXakV-DQ74t8VWzRXmHu694N3-hc,1662
|
|
8
|
+
compute_provisioning/inventory_views.py,sha256=eJWEUVumCX4MFd7MtVsvY0W64oH051HCDeOB_bo7WTw,7342
|
|
9
|
+
compute_provisioning/job_fulfillment.py,sha256=X-77CePBT7w3y7WWKvDNmBDQsFmt1pugWs9iOnVMFBs,20759
|
|
10
|
+
compute_provisioning/lease_lifecycle.py,sha256=be4Ll5mQCexRBGtwXPvd-SH35dBK5C7DUpA7EzL1tOM,27756
|
|
11
|
+
compute_provisioning/leases.py,sha256=Qcf7XyYwXhpxRSnqVCABP2TjJXTF9JaavcrLtrdIDYk,6395
|
|
12
|
+
compute_provisioning/lifecycle.py,sha256=eEIp-L9RwfTmfULgEqNtzhq9Zvg8lB_d_rdwv2TuZSM,959
|
|
13
|
+
compute_provisioning/release.py,sha256=1NsXET-C2S37vXkRYOZuovzm6b1nqhPOVYwuYmwPAMw,15919
|
|
14
|
+
compute_provisioning/release_effects.py,sha256=ZCKzzF5JZB463WNF8UJa4gdmUuaSZw6nHN7FXqJhq8Y,3037
|
|
15
|
+
compute_provisioning/route_errors.py,sha256=NfSRREcAKV438MxiJmOw4NzgcPKfmFui0vuAuAsTKQA,1315
|
|
16
|
+
compute_provisioning/startup.py,sha256=SljnnSYTnGDEcfcYhI2AtpVGubdPR6XIo6E1478TOTE,4560
|
|
17
|
+
compute_provisioning/hosts/__init__.py,sha256=Ov7ILganrPgfoAZZr6TZNQcch9tR1yek9zSqi5eFFP0,317
|
|
18
|
+
compute_provisioning/hosts/connection.py,sha256=egt3wpv_CPuwIr3qxWph5wI7Y3FTF2kzgZSpS9tTC0Q,6654
|
|
19
|
+
compute_provisioning/hosts/db.py,sha256=F6Z6l04T8Yzu3NiGqFo6CWCDXhQ6ICmnD84DBXk9sN4,2790
|
|
20
|
+
compute_provisioning/hosts/definitions.py,sha256=Vly1yk5ryb3hw-tSk0RZIRRx-NBosPmlrYhFvOp5Zmo,10874
|
|
21
|
+
compute_provisioning/hosts/execution.py,sha256=Tj3KNjIqNB6oJHd-zHLMgwY3bwmiHXfIynsoCIWlOwg,706
|
|
22
|
+
compute_provisioning/hosts/route_service.py,sha256=eukWXIkBUuX5LhGG90gkZ_DA4l1LVtsWxsEMwdJNd34,6594
|
|
23
|
+
compute_provisioning/hosts/service.py,sha256=lrBGblLbl3HnHzYAByU7UmfaCsKwe0kd5DWRoHLnHeg,23538
|
|
24
|
+
compute_provisioning/jobs/__init__.py,sha256=kO8VuSmYsR3DDnosA5mMFBmunTGjFqYQRWYPZG0_t4M,444
|
|
25
|
+
compute_provisioning/jobs/action_request.py,sha256=SHrZuI_yORLOVMwUGMqwgvg_OP2pmYWTcm6hTNLWps4,1210
|
|
26
|
+
compute_provisioning/jobs/db.py,sha256=gii9VM6YDpLpYMeIML-KY-TdlOX2XAP3tvOGpinZCn8,4303
|
|
27
|
+
compute_provisioning/jobs/engine.py,sha256=PeNohxwWA8f5YT6wx_DVCb-T6eimDp4GCQ1BoQahVC4,26033
|
|
28
|
+
compute_provisioning/jobs/executor.py,sha256=0sAc5eGsoldnQJK6CaMI3WFb21lxQlPjM1U5siRn6eo,4067
|
|
29
|
+
compute_provisioning/jobs/executor_mock.py,sha256=dHzLyMcGNvQBiQtIRvuo5qU5L4iQMWLgIyibBP7QMho,10101
|
|
30
|
+
compute_provisioning/jobs/queue.py,sha256=J59dyzCFTG_4DS-Add4CaJ74xOpNVFDHiDdtzZrYNeM,5240
|
|
31
|
+
compute_provisioning/jobs/route_service.py,sha256=uhhTTG5dnyKUgBLd-fnQLcRVlgTjlQVCyzBrt0280Oo,5494
|
|
32
|
+
compute_provisioning/jobs/submission.py,sha256=aUHqqYVJ2jT9mmpVa7HRgiwogTxjHlSGAxtUnKozmNc,4571
|
|
33
|
+
compute_provisioning/relays/__init__.py,sha256=7uWLG76obz3g1WxLlt7nQynD3BOgV0Yg9t8-rHLmB0I,4155
|
|
34
|
+
compute_provisioning/relays/allocator.py,sha256=Z_vxhpJOt1X8VLpDqnylEwS1Ar1VwoCEscCJYDebKus,23284
|
|
35
|
+
compute_provisioning/relays/composition.py,sha256=v-PL-eh6WazJ0hl_nADtQX590QqEw-vEggaeCeemGrg,3913
|
|
36
|
+
compute_provisioning/relays/db.py,sha256=GE-R9edq96WivGLbfsJlVIUZoTpJqK_2SQHnpTBUnB8,10064
|
|
37
|
+
compute_provisioning/relays/definitions.py,sha256=wegVNwpPTSl7bOtBbmnSnVqqKdIbKVqJZy4Mak-hGhw,13477
|
|
38
|
+
compute_provisioning/relays/execution.py,sha256=LMmkJPfycJ6veC5eAvneTaAM-4pofDGY0WIf_15hiT8,7713
|
|
39
|
+
compute_provisioning/relays/grants.py,sha256=hVK4BRYglweuvuB9lobnFyV6jqr8U8OQbtMRNOf49TA,3934
|
|
40
|
+
compute_provisioning/relays/keys.py,sha256=rMCI2RI8nZZZnOsxECgS66ksj016Is3Rm_ndsK1btVg,4822
|
|
41
|
+
compute_provisioning/relays/pool_relays.py,sha256=MxZUzb-WTacH__67sQcVpgJ4ERP3iFZ74ouIaV0dTCQ,7016
|
|
42
|
+
compute_provisioning/relays/rebinding.py,sha256=TgAInHmwf7s4BEKIod9AcMb-7Bvvm5vT5sh2WWFSY7w,12365
|
|
43
|
+
compute_provisioning/relays/route_service.py,sha256=W_NOkvBCAVG1vXDuTvvZI1mkFjsr8gqfSUe6av5KGA4,7941
|
|
44
|
+
compute_provisioning/relays/service.py,sha256=VJmv6f-R2cKMx9pRc_gKfPywpNsjb1mvInRGJK8_nF8,25630
|
|
45
|
+
compute_provisioning/relays/variables.py,sha256=0W9E0-FKszdRs-KGZNulpTY7jW5KaCA2HJP_vh0VOA4,1965
|
|
46
|
+
arkhai_compute_provisioning-0.26.0.dist-info/METADATA,sha256=zbMERMlM2BV-yKi3ctcz24dqW8Qbv1Sli8QWXFYDfPE,658
|
|
47
|
+
arkhai_compute_provisioning-0.26.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
48
|
+
arkhai_compute_provisioning-0.26.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Shared compute provisioning service helpers."""
|
|
2
|
+
|
|
3
|
+
from .adapters import (
|
|
4
|
+
JobExecutorResolver,
|
|
5
|
+
JobExecutorTable,
|
|
6
|
+
UnsupportedExecutorActionError,
|
|
7
|
+
)
|
|
8
|
+
from .jobs.executor import (
|
|
9
|
+
JobExecutor,
|
|
10
|
+
JobFailure,
|
|
11
|
+
JobOutcome,
|
|
12
|
+
JobRetryPolicy,
|
|
13
|
+
JobRun,
|
|
14
|
+
JobSuccess,
|
|
15
|
+
)
|
|
16
|
+
from .composition import (
|
|
17
|
+
ComposedComputeAdapters,
|
|
18
|
+
ExecutorAdapterBundle,
|
|
19
|
+
ExecutorAdapterContribution,
|
|
20
|
+
compose_adapter_bundles,
|
|
21
|
+
)
|
|
22
|
+
from .definition_documents import DefinitionDocumentContribution
|
|
23
|
+
from .events import IdempotentLifecycleEventSink, LifecycleEventSink
|
|
24
|
+
from .release_effects import ReleaseEffect, ReleaseEffects, reservation_is_released
|
|
25
|
+
from .inventory_views import (
|
|
26
|
+
InventoryPoolContext,
|
|
27
|
+
InventoryViewProjection,
|
|
28
|
+
InventoryViews,
|
|
29
|
+
ResourceViews,
|
|
30
|
+
compose_inventory_views,
|
|
31
|
+
)
|
|
32
|
+
from .app import (
|
|
33
|
+
DEFAULT_COMPUTE_PROVISIONING_DESCRIPTION,
|
|
34
|
+
ComputeProvisioningAppConfig,
|
|
35
|
+
ComputeProvisioningMiddlewareMount,
|
|
36
|
+
ComputeProvisioningRouterMount,
|
|
37
|
+
build_compute_provisioning_app,
|
|
38
|
+
)
|
|
39
|
+
from .lifecycle import cancel_background_tasks, create_background_task
|
|
40
|
+
from .startup import (
|
|
41
|
+
ComputeProvisioningBackgroundTask,
|
|
42
|
+
ComputeProvisioningRuntime,
|
|
43
|
+
ComputeProvisioningShutdownStep,
|
|
44
|
+
ComputeProvisioningStartupStep,
|
|
45
|
+
run_compute_provisioning_shutdown_steps,
|
|
46
|
+
run_compute_provisioning_startup_steps,
|
|
47
|
+
start_compute_provisioning_background_task,
|
|
48
|
+
start_compute_provisioning_runtime,
|
|
49
|
+
stop_compute_provisioning_runtime,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
"ComposedComputeAdapters",
|
|
54
|
+
"ExecutorAdapterBundle",
|
|
55
|
+
"ExecutorAdapterContribution",
|
|
56
|
+
"compose_adapter_bundles",
|
|
57
|
+
"compose_inventory_views",
|
|
58
|
+
"DefinitionDocumentContribution",
|
|
59
|
+
"ReleaseEffect",
|
|
60
|
+
"ReleaseEffects",
|
|
61
|
+
"reservation_is_released",
|
|
62
|
+
"InventoryPoolContext",
|
|
63
|
+
"InventoryViewProjection",
|
|
64
|
+
"InventoryViews",
|
|
65
|
+
"ResourceViews",
|
|
66
|
+
"JobExecutor",
|
|
67
|
+
"JobExecutorResolver",
|
|
68
|
+
"JobFailure",
|
|
69
|
+
"JobOutcome",
|
|
70
|
+
"JobRetryPolicy",
|
|
71
|
+
"JobRun",
|
|
72
|
+
"JobSuccess",
|
|
73
|
+
"JobExecutorTable",
|
|
74
|
+
"IdempotentLifecycleEventSink",
|
|
75
|
+
"LifecycleEventSink",
|
|
76
|
+
"UnsupportedExecutorActionError",
|
|
77
|
+
"DEFAULT_COMPUTE_PROVISIONING_DESCRIPTION",
|
|
78
|
+
"ComputeProvisioningAppConfig",
|
|
79
|
+
"ComputeProvisioningMiddlewareMount",
|
|
80
|
+
"ComputeProvisioningRouterMount",
|
|
81
|
+
"ComputeProvisioningBackgroundTask",
|
|
82
|
+
"ComputeProvisioningRuntime",
|
|
83
|
+
"ComputeProvisioningShutdownStep",
|
|
84
|
+
"ComputeProvisioningStartupStep",
|
|
85
|
+
"build_compute_provisioning_app",
|
|
86
|
+
"cancel_background_tasks",
|
|
87
|
+
"create_background_task",
|
|
88
|
+
"run_compute_provisioning_shutdown_steps",
|
|
89
|
+
"run_compute_provisioning_startup_steps",
|
|
90
|
+
"start_compute_provisioning_background_task",
|
|
91
|
+
"start_compute_provisioning_runtime",
|
|
92
|
+
"stop_compute_provisioning_runtime",
|
|
93
|
+
]
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""The job executors domains contribute, resolved by offering mode and action."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Protocol
|
|
6
|
+
|
|
7
|
+
from .jobs.executor import JobExecutor
|
|
8
|
+
from .jobs.executor_mock import executor_is_mocked
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class UnsupportedExecutorActionError(LookupError):
|
|
12
|
+
"""No job executor is registered for an offering mode and action."""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class JobExecutorResolver(Protocol):
|
|
16
|
+
def resolve(self, offering_mode: str, action: str) -> JobExecutor:
|
|
17
|
+
"""Return the executor that runs ``action`` for ``offering_mode``, or
|
|
18
|
+
raise ``UnsupportedExecutorActionError``."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class JobExecutorTable:
|
|
22
|
+
"""The job executors adapter bundles contribute, keyed by offering mode and action.
|
|
23
|
+
|
|
24
|
+
Service composition fills the table once and freezes it before the service
|
|
25
|
+
accepts traffic; a job service holds the table from construction and resolves
|
|
26
|
+
through it at execution time. A key registered twice is a composition error,
|
|
27
|
+
and nothing resolves until the table is frozen, so a job can never run against
|
|
28
|
+
a partially composed set of executors.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self) -> None:
|
|
32
|
+
self._executors: dict[tuple[str, str], JobExecutor] = {}
|
|
33
|
+
self._frozen = False
|
|
34
|
+
|
|
35
|
+
def register(self, offering_mode: str, action: str, executor: JobExecutor) -> None:
|
|
36
|
+
if self._frozen:
|
|
37
|
+
raise RuntimeError("job executor table is frozen")
|
|
38
|
+
key = (offering_mode, action)
|
|
39
|
+
if key in self._executors:
|
|
40
|
+
raise ValueError(
|
|
41
|
+
f"duplicate job executor for {offering_mode!r}/{action!r}"
|
|
42
|
+
)
|
|
43
|
+
self._executors[key] = executor
|
|
44
|
+
|
|
45
|
+
def freeze(self) -> None:
|
|
46
|
+
self._frozen = True
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def frozen(self) -> bool:
|
|
50
|
+
return self._frozen
|
|
51
|
+
|
|
52
|
+
def resolve(self, offering_mode: str, action: str) -> JobExecutor:
|
|
53
|
+
if not self._frozen:
|
|
54
|
+
raise RuntimeError("job executor table has not been composed")
|
|
55
|
+
try:
|
|
56
|
+
return self._executors[(offering_mode, action)]
|
|
57
|
+
except KeyError as exc:
|
|
58
|
+
raise UnsupportedExecutorActionError(
|
|
59
|
+
f"no job executor for offering mode {offering_mode!r} "
|
|
60
|
+
f"and action {action!r}"
|
|
61
|
+
) from exc
|
|
62
|
+
|
|
63
|
+
def mocked_by_offering_mode(self) -> dict[str, bool]:
|
|
64
|
+
"""Whether each offering mode's executors are the mock.
|
|
65
|
+
|
|
66
|
+
A mode counts as mocked only when every executor registered for it
|
|
67
|
+
carries the compute mock mechanism's rules (``executor_is_mocked``).
|
|
68
|
+
"""
|
|
69
|
+
mocked: dict[str, bool] = {}
|
|
70
|
+
for (offering_mode, _action), executor in self._executors.items():
|
|
71
|
+
mocked[offering_mode] = mocked.get(offering_mode, True) and executor_is_mocked(
|
|
72
|
+
executor
|
|
73
|
+
)
|
|
74
|
+
return mocked
|
|
75
|
+
|
|
76
|
+
def executors_by_offering_mode(self) -> dict[str, tuple[JobExecutor, ...]]:
|
|
77
|
+
"""Each offering mode's distinct executors, in registration order.
|
|
78
|
+
|
|
79
|
+
An implementation reads this to report on the executors it built,
|
|
80
|
+
whichever domain contributed them.
|
|
81
|
+
"""
|
|
82
|
+
grouped: dict[str, list[JobExecutor]] = {}
|
|
83
|
+
for (offering_mode, _action), executor in self._executors.items():
|
|
84
|
+
known = grouped.setdefault(offering_mode, [])
|
|
85
|
+
if not any(executor is seen for seen in known):
|
|
86
|
+
known.append(executor)
|
|
87
|
+
return {mode: tuple(executors) for mode, executors in grouped.items()}
|
|
88
|
+
|
|
89
|
+
def executors(self) -> tuple[JobExecutor, ...]:
|
|
90
|
+
"""Each distinct executor once, in registration order."""
|
|
91
|
+
|
|
92
|
+
seen: list[JobExecutor] = []
|
|
93
|
+
for executor in self._executors.values():
|
|
94
|
+
if not any(executor is known for known in seen):
|
|
95
|
+
seen.append(executor)
|
|
96
|
+
return tuple(seen)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Reusable FastAPI app shell composition for compute provisioners."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class ComputeProvisioningAppConfig:
|
|
12
|
+
"""Configuration for a compute provisioning FastAPI app shell."""
|
|
13
|
+
|
|
14
|
+
title: str
|
|
15
|
+
description: str
|
|
16
|
+
version: str
|
|
17
|
+
openapi_tags: list[dict[str, Any]] = field(default_factory=list)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class ComputeProvisioningMiddlewareMount:
|
|
22
|
+
"""Middleware class plus keyword arguments to install on the app."""
|
|
23
|
+
|
|
24
|
+
middleware_class: Any
|
|
25
|
+
kwargs: dict[str, Any] = field(default_factory=dict)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True)
|
|
29
|
+
class ComputeProvisioningRouterMount:
|
|
30
|
+
"""Router plus optional prefix to register on the app."""
|
|
31
|
+
|
|
32
|
+
router: Any
|
|
33
|
+
prefix: str = ""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
DEFAULT_COMPUTE_PROVISIONING_DESCRIPTION = (
|
|
37
|
+
"Asynchronous provisioning for a multi-agent compute marketplace."
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def build_compute_provisioning_app(
|
|
42
|
+
*,
|
|
43
|
+
config: ComputeProvisioningAppConfig,
|
|
44
|
+
lifespan: Any | None = None,
|
|
45
|
+
middlewares: Iterable[ComputeProvisioningMiddlewareMount] = (),
|
|
46
|
+
routers: Iterable[ComputeProvisioningRouterMount] = (),
|
|
47
|
+
) -> Any:
|
|
48
|
+
"""Build a FastAPI compute provisioning app and register mounts.
|
|
49
|
+
|
|
50
|
+
FastAPI remains a lazy import so callers can import the package without
|
|
51
|
+
also importing FastAPI unless they call the builder.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
from fastapi import FastAPI
|
|
55
|
+
|
|
56
|
+
app = FastAPI(
|
|
57
|
+
title=config.title,
|
|
58
|
+
version=config.version,
|
|
59
|
+
description=config.description,
|
|
60
|
+
openapi_tags=config.openapi_tags,
|
|
61
|
+
lifespan=lifespan,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
for middleware in middlewares:
|
|
65
|
+
app.add_middleware(middleware.middleware_class, **middleware.kwargs)
|
|
66
|
+
|
|
67
|
+
for mount in routers:
|
|
68
|
+
if mount.prefix:
|
|
69
|
+
app.include_router(mount.router, prefix=mount.prefix)
|
|
70
|
+
else:
|
|
71
|
+
app.include_router(mount.router)
|
|
72
|
+
|
|
73
|
+
return app
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"""Domain adapter contributions and startup-time composition validation.
|
|
2
|
+
|
|
3
|
+
Each compute domain describes what it contributes as an ``ExecutorAdapterBundle``;
|
|
4
|
+
the provisioning service's composition root passes every installed bundle to
|
|
5
|
+
``compose_adapter_bundles``, which refuses an ambiguous or incomplete
|
|
6
|
+
registration before anything starts. The contract types live in the family kit
|
|
7
|
+
so a domain adapter can build its bundle without depending on the deployed
|
|
8
|
+
service.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from collections.abc import Mapping
|
|
14
|
+
from dataclasses import dataclass, field
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from .adapters import JobExecutorTable
|
|
18
|
+
from .definition_documents import DefinitionDocumentContribution
|
|
19
|
+
from .release_effects import ReleaseEffect, ReleaseEffects
|
|
20
|
+
from .inventory_views import InventoryViewProjection, InventoryViews, compose_inventory_views
|
|
21
|
+
from .jobs.executor import JobExecutor
|
|
22
|
+
from .startup import ComputeProvisioningBackgroundTask
|
|
23
|
+
from market_fulfillment import FulfillmentProvider, ProviderRegistry, provider_needs_host
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True)
|
|
27
|
+
class ExecutorAdapterContribution:
|
|
28
|
+
"""What one offering mode contributes: its job executors.
|
|
29
|
+
|
|
30
|
+
``job_executors`` maps each job action of the mode to what runs it. Work
|
|
31
|
+
reaches these executors only through fulfillment and the domain's own
|
|
32
|
+
operations; nothing submits an action to them from outside. A mode
|
|
33
|
+
contributes nothing to release: every mode's lease is released through its
|
|
34
|
+
fulfillment aggregate, whose provider the pool already names.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
offering_mode: str
|
|
38
|
+
job_executors: Mapping[str, JobExecutor]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(frozen=True)
|
|
42
|
+
class ExecutorAdapterBundle:
|
|
43
|
+
"""Everything one compute domain contributes to service composition.
|
|
44
|
+
|
|
45
|
+
The family's relays contribute one too, with no executor or provider: the
|
|
46
|
+
release effect, definitions document, and worker every domain a relay
|
|
47
|
+
carries shares, registered once. A domain's routes are not part of it: the service mounts them when it
|
|
48
|
+
builds the app, before any bundle exists, through the router factories the
|
|
49
|
+
adapter exports. Execution readiness is not either: the composition root
|
|
50
|
+
reports it from the executors it composed.
|
|
51
|
+
|
|
52
|
+
``release_effects`` run whenever the site releases a reservation's
|
|
53
|
+
capacity, in that transaction; ``definition_documents`` are imported at
|
|
54
|
+
startup before the service's own documents; ``background_tasks`` start
|
|
55
|
+
with the service's own workers.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
name: str
|
|
59
|
+
executors: tuple[ExecutorAdapterContribution, ...]
|
|
60
|
+
fulfillment_providers: Mapping[str, FulfillmentProvider] = field(default_factory=dict)
|
|
61
|
+
pool_config_handlers: Mapping[str, Any] = field(default_factory=dict)
|
|
62
|
+
inventory_views: tuple[InventoryViewProjection, ...] = ()
|
|
63
|
+
release_effects: tuple[ReleaseEffect, ...] = ()
|
|
64
|
+
definition_documents: tuple[DefinitionDocumentContribution, ...] = ()
|
|
65
|
+
background_tasks: tuple[ComputeProvisioningBackgroundTask, ...] = ()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@dataclass(frozen=True)
|
|
69
|
+
class ComposedComputeAdapters:
|
|
70
|
+
provider_registry: ProviderRegistry
|
|
71
|
+
pool_config_handlers: Mapping[str, Any]
|
|
72
|
+
inventory_views: InventoryViews
|
|
73
|
+
job_executors: JobExecutorTable
|
|
74
|
+
definition_documents: tuple[DefinitionDocumentContribution, ...] = ()
|
|
75
|
+
background_tasks: tuple[ComputeProvisioningBackgroundTask, ...] = ()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
#: Document kinds the service imports itself; a contribution may not claim one.
|
|
79
|
+
SERVICE_DEFINITION_DOCUMENT_KINDS = frozenset({"pools", "capacity"})
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _validate_executor(bundle_name: str, contribution: ExecutorAdapterContribution) -> str:
|
|
83
|
+
offering_mode = str(contribution.offering_mode or "").strip()
|
|
84
|
+
if not offering_mode:
|
|
85
|
+
raise ValueError(f"adapter bundle {bundle_name!r} has an executor without offering_mode")
|
|
86
|
+
if offering_mode != contribution.offering_mode:
|
|
87
|
+
raise ValueError(
|
|
88
|
+
f"adapter bundle {bundle_name!r} offering mode "
|
|
89
|
+
f"{contribution.offering_mode!r} is not canonical"
|
|
90
|
+
)
|
|
91
|
+
if not contribution.job_executors:
|
|
92
|
+
raise ValueError(
|
|
93
|
+
f"adapter bundle {bundle_name!r} executor {offering_mode!r} "
|
|
94
|
+
"contributes no job executors"
|
|
95
|
+
)
|
|
96
|
+
return offering_mode
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _validate_provider_pairing(bundle: ExecutorAdapterBundle) -> None:
|
|
100
|
+
provider_names = frozenset(bundle.fulfillment_providers)
|
|
101
|
+
handler_names = frozenset(bundle.pool_config_handlers)
|
|
102
|
+
if provider_names == handler_names:
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
detail = []
|
|
106
|
+
missing_handlers = sorted(provider_names - handler_names)
|
|
107
|
+
missing_providers = sorted(handler_names - provider_names)
|
|
108
|
+
if missing_handlers:
|
|
109
|
+
detail.append(
|
|
110
|
+
"missing pool config handler(s) for "
|
|
111
|
+
+ ", ".join(repr(name) for name in missing_handlers)
|
|
112
|
+
)
|
|
113
|
+
if missing_providers:
|
|
114
|
+
detail.append(
|
|
115
|
+
"missing fulfillment provider(s) for "
|
|
116
|
+
+ ", ".join(repr(name) for name in missing_providers)
|
|
117
|
+
)
|
|
118
|
+
raise ValueError(
|
|
119
|
+
f"adapter bundle {bundle.name!r} has incomplete provider contributions: "
|
|
120
|
+
+ "; ".join(detail)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _validate_pool_config_handler(
|
|
125
|
+
*, bundle_name: str, provider_name: str, handler: Any
|
|
126
|
+
) -> str:
|
|
127
|
+
name = provider_name.strip()
|
|
128
|
+
if not name:
|
|
129
|
+
raise ValueError(
|
|
130
|
+
f"adapter bundle {bundle_name!r} declares an empty pool config handler"
|
|
131
|
+
)
|
|
132
|
+
if name != provider_name:
|
|
133
|
+
raise ValueError(
|
|
134
|
+
f"pool config handler key {provider_name!r} in bundle "
|
|
135
|
+
f"{bundle_name!r} is not canonical"
|
|
136
|
+
)
|
|
137
|
+
handler_provider = getattr(handler, "provider", None)
|
|
138
|
+
if handler_provider != name:
|
|
139
|
+
raise ValueError(
|
|
140
|
+
f"pool config handler {name!r} in bundle {bundle_name!r} "
|
|
141
|
+
f"declares provider {handler_provider!r}"
|
|
142
|
+
)
|
|
143
|
+
required_hooks = (
|
|
144
|
+
"validate_config",
|
|
145
|
+
"validate_config_problems",
|
|
146
|
+
"read_config",
|
|
147
|
+
"replace_config",
|
|
148
|
+
)
|
|
149
|
+
missing_hooks = [
|
|
150
|
+
hook for hook in required_hooks if not callable(getattr(handler, hook, None))
|
|
151
|
+
]
|
|
152
|
+
if missing_hooks:
|
|
153
|
+
raise ValueError(
|
|
154
|
+
f"pool config handler {name!r} in bundle {bundle_name!r} "
|
|
155
|
+
f"is missing callable hooks: {', '.join(missing_hooks)}"
|
|
156
|
+
)
|
|
157
|
+
return name
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _validate_host_requirement(
|
|
161
|
+
providers: Mapping[str, FulfillmentProvider],
|
|
162
|
+
host_requirement: Mapping[str, bool],
|
|
163
|
+
) -> None:
|
|
164
|
+
"""Refuse a host requirement that disagrees with the registered providers.
|
|
165
|
+
|
|
166
|
+
The site ledger and the settlement scheduler are built before any provider
|
|
167
|
+
instance exists, so they receive this requirement as data rather than
|
|
168
|
+
reading it from the providers. Checking it against the providers actually
|
|
169
|
+
registered here is what keeps that data from drifting: a provider absent
|
|
170
|
+
from it would be treated as needing a host, and an entry for an
|
|
171
|
+
unregistered provider would govern pools nothing can execute.
|
|
172
|
+
"""
|
|
173
|
+
declared: dict[str, bool] = {}
|
|
174
|
+
for name, provider in providers.items():
|
|
175
|
+
try:
|
|
176
|
+
declared[name] = provider_needs_host(provider)
|
|
177
|
+
except TypeError as exc:
|
|
178
|
+
raise ValueError(str(exc)) from exc
|
|
179
|
+
missing = sorted(set(declared) - set(host_requirement))
|
|
180
|
+
unregistered = sorted(set(host_requirement) - set(declared))
|
|
181
|
+
disagreeing = sorted(
|
|
182
|
+
name
|
|
183
|
+
for name in set(declared) & set(host_requirement)
|
|
184
|
+
if host_requirement[name] is not declared[name]
|
|
185
|
+
)
|
|
186
|
+
problems = []
|
|
187
|
+
if missing:
|
|
188
|
+
problems.append("omits registered provider(s) " + ", ".join(map(repr, missing)))
|
|
189
|
+
if unregistered:
|
|
190
|
+
problems.append("names unregistered provider(s) " + ", ".join(map(repr, unregistered)))
|
|
191
|
+
if disagreeing:
|
|
192
|
+
problems.append(
|
|
193
|
+
"disagrees with the declaration of provider(s) "
|
|
194
|
+
+ ", ".join(map(repr, disagreeing))
|
|
195
|
+
)
|
|
196
|
+
if problems:
|
|
197
|
+
raise ValueError("host requirement " + "; ".join(problems))
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def compose_adapter_bundles(
|
|
201
|
+
bundles: tuple[ExecutorAdapterBundle, ...] | list[ExecutorAdapterBundle],
|
|
202
|
+
*,
|
|
203
|
+
host_requirement: Mapping[str, bool],
|
|
204
|
+
job_executors: JobExecutorTable,
|
|
205
|
+
release_effects: ReleaseEffects | None = None,
|
|
206
|
+
) -> ComposedComputeAdapters:
|
|
207
|
+
"""Compose bundles and reject ambiguous registrations before startup.
|
|
208
|
+
|
|
209
|
+
``host_requirement`` is the per-provider host need already handed to the
|
|
210
|
+
site ledger and scheduler; it must match the registered providers exactly.
|
|
211
|
+
``job_executors`` is the table the job service was built with; every
|
|
212
|
+
bundle's job executors are registered into it, refusing a key registered
|
|
213
|
+
twice, and it is frozen before composition returns. ``release_effects`` is
|
|
214
|
+
the registry the site ledger runs when it releases capacity; every
|
|
215
|
+
contributed effect is registered into it, and it is frozen with the table.
|
|
216
|
+
A contributed effect with no registry to receive it is refused rather than
|
|
217
|
+
dropped.
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
executor_owners: dict[str, str] = {}
|
|
221
|
+
provider_owners: dict[str, str] = {}
|
|
222
|
+
handler_owners: dict[str, str] = {}
|
|
223
|
+
providers: dict[str, FulfillmentProvider] = {}
|
|
224
|
+
pool_config_handlers: dict[str, Any] = {}
|
|
225
|
+
inventory_views: list[tuple[str, InventoryViewProjection]] = []
|
|
226
|
+
effects_contributed: list[tuple[str, ReleaseEffect]] = []
|
|
227
|
+
document_owners: dict[str, str] = {}
|
|
228
|
+
definition_documents: list[DefinitionDocumentContribution] = []
|
|
229
|
+
task_owners: dict[str, str] = {}
|
|
230
|
+
background_tasks: list[ComputeProvisioningBackgroundTask] = []
|
|
231
|
+
|
|
232
|
+
bundle_names: set[str] = set()
|
|
233
|
+
for bundle in bundles:
|
|
234
|
+
bundle_name = bundle.name.strip()
|
|
235
|
+
if not bundle_name:
|
|
236
|
+
raise ValueError("adapter bundle name must not be empty")
|
|
237
|
+
if bundle_name in bundle_names:
|
|
238
|
+
raise ValueError(f"duplicate adapter bundle: {bundle_name!r}")
|
|
239
|
+
bundle_names.add(bundle_name)
|
|
240
|
+
_validate_provider_pairing(bundle)
|
|
241
|
+
|
|
242
|
+
for contribution in bundle.executors:
|
|
243
|
+
offering_mode = _validate_executor(bundle_name, contribution)
|
|
244
|
+
previous = executor_owners.get(offering_mode)
|
|
245
|
+
if previous is not None:
|
|
246
|
+
raise ValueError(
|
|
247
|
+
f"duplicate offering mode {offering_mode!r}: "
|
|
248
|
+
f"bundles {previous!r} and {bundle_name!r}"
|
|
249
|
+
)
|
|
250
|
+
executor_owners[offering_mode] = bundle_name
|
|
251
|
+
for action, executor in contribution.job_executors.items():
|
|
252
|
+
try:
|
|
253
|
+
job_executors.register(offering_mode, action, executor)
|
|
254
|
+
except ValueError as exc:
|
|
255
|
+
raise ValueError(f"adapter bundle {bundle_name!r}: {exc}") from exc
|
|
256
|
+
|
|
257
|
+
for provider_name, provider in bundle.fulfillment_providers.items():
|
|
258
|
+
name = provider_name.strip()
|
|
259
|
+
if not name:
|
|
260
|
+
raise ValueError(
|
|
261
|
+
f"adapter bundle {bundle_name!r} has an empty provider identity"
|
|
262
|
+
)
|
|
263
|
+
if name != provider_name:
|
|
264
|
+
raise ValueError(
|
|
265
|
+
f"fulfillment provider key {provider_name!r} in bundle "
|
|
266
|
+
f"{bundle_name!r} is not canonical"
|
|
267
|
+
)
|
|
268
|
+
previous = provider_owners.get(name)
|
|
269
|
+
if previous is not None:
|
|
270
|
+
raise ValueError(
|
|
271
|
+
f"duplicate fulfillment provider {name!r} and pool config handler: "
|
|
272
|
+
f"bundles {previous!r} and {bundle_name!r}"
|
|
273
|
+
)
|
|
274
|
+
provider_owners[name] = bundle_name
|
|
275
|
+
providers[name] = provider
|
|
276
|
+
|
|
277
|
+
for provider_name, handler in bundle.pool_config_handlers.items():
|
|
278
|
+
name = _validate_pool_config_handler(
|
|
279
|
+
bundle_name=bundle_name,
|
|
280
|
+
provider_name=provider_name,
|
|
281
|
+
handler=handler,
|
|
282
|
+
)
|
|
283
|
+
previous = handler_owners.get(name)
|
|
284
|
+
if previous is not None:
|
|
285
|
+
raise ValueError(
|
|
286
|
+
f"duplicate pool config handler {name!r}: "
|
|
287
|
+
f"bundles {previous!r} and {bundle_name!r}"
|
|
288
|
+
)
|
|
289
|
+
handler_owners[name] = bundle_name
|
|
290
|
+
pool_config_handlers[name] = handler
|
|
291
|
+
|
|
292
|
+
inventory_views.extend(
|
|
293
|
+
(bundle_name, projection) for projection in bundle.inventory_views
|
|
294
|
+
)
|
|
295
|
+
effects_contributed.extend(
|
|
296
|
+
(bundle_name, effect) for effect in bundle.release_effects
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
for document in bundle.definition_documents:
|
|
300
|
+
if document.kind in SERVICE_DEFINITION_DOCUMENT_KINDS:
|
|
301
|
+
raise ValueError(
|
|
302
|
+
f"adapter bundle {bundle_name!r} claims the service's own "
|
|
303
|
+
f"definition document kind {document.kind!r}"
|
|
304
|
+
)
|
|
305
|
+
previous = document_owners.get(document.kind)
|
|
306
|
+
if previous is not None:
|
|
307
|
+
raise ValueError(
|
|
308
|
+
f"duplicate definition document kind {document.kind!r}: "
|
|
309
|
+
f"bundles {previous!r} and {bundle_name!r}"
|
|
310
|
+
)
|
|
311
|
+
document_owners[document.kind] = bundle_name
|
|
312
|
+
definition_documents.append(document)
|
|
313
|
+
|
|
314
|
+
for task in bundle.background_tasks:
|
|
315
|
+
previous = task_owners.get(task.name)
|
|
316
|
+
if previous is not None:
|
|
317
|
+
raise ValueError(
|
|
318
|
+
f"duplicate background task {task.name!r}: "
|
|
319
|
+
f"bundles {previous!r} and {bundle_name!r}"
|
|
320
|
+
)
|
|
321
|
+
task_owners[task.name] = bundle_name
|
|
322
|
+
background_tasks.append(task)
|
|
323
|
+
|
|
324
|
+
_validate_host_requirement(providers, host_requirement)
|
|
325
|
+
composed_views = compose_inventory_views(inventory_views)
|
|
326
|
+
if effects_contributed and release_effects is None:
|
|
327
|
+
owners = sorted({owner for owner, _ in effects_contributed})
|
|
328
|
+
raise ValueError(
|
|
329
|
+
"release effects contributed by "
|
|
330
|
+
+ ", ".join(repr(owner) for owner in owners)
|
|
331
|
+
+ " but no registry was given to run them"
|
|
332
|
+
)
|
|
333
|
+
if release_effects is not None:
|
|
334
|
+
for _owner, effect in effects_contributed:
|
|
335
|
+
release_effects.register(effect)
|
|
336
|
+
release_effects.freeze()
|
|
337
|
+
job_executors.freeze()
|
|
338
|
+
|
|
339
|
+
return ComposedComputeAdapters(
|
|
340
|
+
provider_registry=ProviderRegistry(providers),
|
|
341
|
+
pool_config_handlers=pool_config_handlers,
|
|
342
|
+
inventory_views=composed_views,
|
|
343
|
+
job_executors=job_executors,
|
|
344
|
+
definition_documents=tuple(definition_documents),
|
|
345
|
+
background_tasks=tuple(background_tasks),
|
|
346
|
+
)
|