provium-cloud 0.1.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.
- provium_cloud/__init__.py +25 -0
- provium_cloud/artifacts/__init__.py +33 -0
- provium_cloud/artifacts/backends/__init__.py +1 -0
- provium_cloud/artifacts/backends/file_s3.py +83 -0
- provium_cloud/artifacts/interface.py +25 -0
- provium_cloud/cli/__init__.py +12 -0
- provium_cloud/cli/aws/__init__.py +5 -0
- provium_cloud/cli/aws/arguments.py +131 -0
- provium_cloud/cli/aws/commands/__init__.py +1 -0
- provium_cloud/cli/aws/commands/artifacts.py +43 -0
- provium_cloud/cli/aws/commands/aws.py +47 -0
- provium_cloud/cli/aws/commands/base.py +32 -0
- provium_cloud/cli/aws/commands/execution.py +69 -0
- provium_cloud/cli/aws/commands/invocations.py +42 -0
- provium_cloud/cli/aws/commands/runs.py +99 -0
- provium_cloud/cli/aws/commands/validate.py +29 -0
- provium_cloud/cli/commands/__init__.py +1 -0
- provium_cloud/cli/commands/cloud.py +15 -0
- provium_cloud/client.py +169 -0
- provium_cloud/deployment/__init__.py +19 -0
- provium_cloud/deployment/config.py +98 -0
- provium_cloud/deployment/loader.py +36 -0
- provium_cloud/execution/__init__.py +1 -0
- provium_cloud/execution/aws/__init__.py +1 -0
- provium_cloud/execution/aws/batch.py +126 -0
- provium_cloud/execution/controller.py +172 -0
- provium_cloud/execution/interface.py +15 -0
- provium_cloud/execution/worker.py +133 -0
- provium_cloud/invocations/__init__.py +1 -0
- provium_cloud/invocations/inputs.py +52 -0
- provium_cloud/invocations/models.py +41 -0
- provium_cloud/invocations/planning.py +176 -0
- provium_cloud/py.typed +0 -0
- provium_cloud/state/__init__.py +41 -0
- provium_cloud/state/backends/__init__.py +1 -0
- provium_cloud/state/backends/postgres.py +44 -0
- provium_cloud/state/backends/sql.py +141 -0
- provium_cloud/state/backends/sqlite.py +44 -0
- provium_cloud/state/coordination.py +207 -0
- provium_cloud/state/interface.py +40 -0
- provium_cloud/state/jobs.py +109 -0
- provium_cloud/state/models.py +108 -0
- provium_cloud/state/runs.py +179 -0
- provium_cloud-0.1.0.dist-info/METADATA +111 -0
- provium_cloud-0.1.0.dist-info/RECORD +49 -0
- provium_cloud-0.1.0.dist-info/WHEEL +5 -0
- provium_cloud-0.1.0.dist-info/entry_points.txt +2 -0
- provium_cloud-0.1.0.dist-info/licenses/LICENSE +21 -0
- provium_cloud-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Cloud execution orchestration for Provium."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import version
|
|
4
|
+
|
|
5
|
+
from provium_cloud.client import CloudClient
|
|
6
|
+
from provium_cloud.deployment import (
|
|
7
|
+
BackendConfiguration,
|
|
8
|
+
CloudDeployment,
|
|
9
|
+
JobSettings,
|
|
10
|
+
SchedulingOptions,
|
|
11
|
+
SchedulingRule,
|
|
12
|
+
load_deployment,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__version__ = version("provium-cloud")
|
|
16
|
+
__all__ = [
|
|
17
|
+
"CloudClient",
|
|
18
|
+
"BackendConfiguration",
|
|
19
|
+
"CloudDeployment",
|
|
20
|
+
"JobSettings",
|
|
21
|
+
"SchedulingOptions",
|
|
22
|
+
"SchedulingRule",
|
|
23
|
+
"load_deployment",
|
|
24
|
+
"__version__",
|
|
25
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Artifact backend selection and extension discovery."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import entry_points
|
|
4
|
+
from typing import cast
|
|
5
|
+
from urllib.parse import urlparse
|
|
6
|
+
|
|
7
|
+
from provium_cloud.artifacts.interface import ArtifactBackend, ArtifactReference
|
|
8
|
+
from provium_cloud.deployment import BackendConfiguration
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def open_artifacts(config: BackendConfiguration) -> ArtifactBackend:
|
|
12
|
+
if config.backend in {"file", "s3"}:
|
|
13
|
+
from provium_cloud.artifacts.backends.file_s3 import (
|
|
14
|
+
FileStoreBackend,
|
|
15
|
+
FileStoreOptions,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
options = FileStoreOptions.model_validate(config.options)
|
|
19
|
+
scheme = urlparse(options.location).scheme
|
|
20
|
+
if (config.backend == "s3" and scheme != "s3") or (
|
|
21
|
+
config.backend == "file" and scheme not in {"", "file"}
|
|
22
|
+
):
|
|
23
|
+
raise ValueError("artifact location does not match its backend")
|
|
24
|
+
return FileStoreBackend(options)
|
|
25
|
+
factories = list(
|
|
26
|
+
entry_points(group="provium.cloud.artifact_backends", name=config.backend)
|
|
27
|
+
)
|
|
28
|
+
if len(factories) != 1:
|
|
29
|
+
raise ValueError(f"unknown or ambiguous artifact backend: {config.backend}")
|
|
30
|
+
return cast(ArtifactBackend, factories[0].load()(dict(config.options)))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
__all__ = ["ArtifactBackend", "ArtifactReference", "open_artifacts"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Built-in artifact storage adapters."""
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Local/S3 storage using Provium's artifact verifier and atomic file publisher."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Self
|
|
4
|
+
|
|
5
|
+
from provium.semantic import canonical_hash
|
|
6
|
+
from provium_pipeline.publication import FilePublisher
|
|
7
|
+
from provium_pipeline.store import Artifact, ArtifactStore
|
|
8
|
+
from pydantic import BaseModel, ConfigDict
|
|
9
|
+
|
|
10
|
+
from provium_cloud.artifacts.interface import ArtifactReference
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FileStoreOptions(BaseModel):
|
|
14
|
+
model_config = ConfigDict(extra="forbid")
|
|
15
|
+
location: str
|
|
16
|
+
scratch_directory: str | None = None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class FileStoreBackend:
|
|
20
|
+
def __init__(self, options: FileStoreOptions) -> None:
|
|
21
|
+
self.store = ArtifactStore(options.location, scratch=options.scratch_directory)
|
|
22
|
+
self.namespace = self.store.namespace
|
|
23
|
+
|
|
24
|
+
def inspect(self, location: str) -> ArtifactReference:
|
|
25
|
+
artifact = self.store.inspect(location)
|
|
26
|
+
return {
|
|
27
|
+
"location": artifact.location,
|
|
28
|
+
"identity": artifact.identity,
|
|
29
|
+
"fingerprint": artifact.fingerprint,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def put(self, location: str) -> ArtifactReference:
|
|
33
|
+
reference = self.inspect(location)
|
|
34
|
+
return self.stage(
|
|
35
|
+
canonical_hash(reference["fingerprint"]),
|
|
36
|
+
{"input": location},
|
|
37
|
+
{"input": reference["fingerprint"]["provenance"]},
|
|
38
|
+
)["input"]
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def _artifact(reference: ArtifactReference) -> Artifact:
|
|
42
|
+
return Artifact(
|
|
43
|
+
reference["location"], None, reference["identity"], reference["fingerprint"]
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def materialize(self, reference: ArtifactReference) -> str:
|
|
47
|
+
artifact = self.store.materialize(self._artifact(reference))
|
|
48
|
+
assert artifact.path is not None
|
|
49
|
+
return artifact.path
|
|
50
|
+
|
|
51
|
+
def stage(
|
|
52
|
+
self, computation: str, paths: dict[str, str], expected: dict[str, str]
|
|
53
|
+
) -> dict[str, ArtifactReference]:
|
|
54
|
+
return self.store.stage(computation, paths, expected)
|
|
55
|
+
|
|
56
|
+
def verify(
|
|
57
|
+
self, outputs: dict[str, ArtifactReference], expected: dict[str, str]
|
|
58
|
+
) -> None:
|
|
59
|
+
try:
|
|
60
|
+
self.store.verify(outputs, expected)
|
|
61
|
+
except Exception as error:
|
|
62
|
+
response: Any = getattr(error, "response", {})
|
|
63
|
+
if response.get("Error", {}).get("Code") in ("404", "NoSuchKey"):
|
|
64
|
+
raise FileNotFoundError(
|
|
65
|
+
"committed artifact no longer exists"
|
|
66
|
+
) from error
|
|
67
|
+
raise
|
|
68
|
+
|
|
69
|
+
def fetch(
|
|
70
|
+
self, reference: ArtifactReference, destination: str, *, overwrite: bool = False
|
|
71
|
+
) -> None:
|
|
72
|
+
FilePublisher(self.store).publish(
|
|
73
|
+
self._artifact(reference), destination, overwrite=overwrite
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
def close(self) -> None:
|
|
77
|
+
self.store.close()
|
|
78
|
+
|
|
79
|
+
def __enter__(self) -> Self:
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def __exit__(self, *args: Any) -> None:
|
|
83
|
+
self.close()
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Artifact bytes and verification, independent of execution-state storage."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Protocol, Self
|
|
4
|
+
|
|
5
|
+
type ArtifactReference = dict[str, Any]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ArtifactBackend(Protocol):
|
|
9
|
+
namespace: str
|
|
10
|
+
|
|
11
|
+
def put(self, location: str) -> ArtifactReference: ...
|
|
12
|
+
def inspect(self, location: str) -> ArtifactReference: ...
|
|
13
|
+
def materialize(self, reference: ArtifactReference) -> str: ...
|
|
14
|
+
def stage(
|
|
15
|
+
self, computation: str, paths: dict[str, str], expected: dict[str, str]
|
|
16
|
+
) -> dict[str, ArtifactReference]: ...
|
|
17
|
+
def verify(
|
|
18
|
+
self, outputs: dict[str, ArtifactReference], expected: dict[str, str]
|
|
19
|
+
) -> None: ...
|
|
20
|
+
def fetch(
|
|
21
|
+
self, reference: ArtifactReference, destination: str, *, overwrite: bool = False
|
|
22
|
+
) -> None: ...
|
|
23
|
+
def close(self) -> None: ...
|
|
24
|
+
def __enter__(self) -> Self: ...
|
|
25
|
+
def __exit__(self, *args: Any) -> None: ...
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Register cloud commands with the core Provium CLI."""
|
|
2
|
+
|
|
3
|
+
from provium.cli.catalog import CommandCatalog
|
|
4
|
+
from provium.cli.plugin import CLI_PLUGIN_API_VERSION, CLIPlugin
|
|
5
|
+
|
|
6
|
+
from provium_cloud.cli.commands.cloud import CloudCommand
|
|
7
|
+
|
|
8
|
+
catalog = CommandCatalog()
|
|
9
|
+
catalog.register(CloudCommand)
|
|
10
|
+
plugin = CLIPlugin(CLI_PLUGIN_API_VERSION, "provium-cloud", catalog)
|
|
11
|
+
|
|
12
|
+
__all__ = ["CloudCommand", "catalog", "plugin"]
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Shared AWS deployment and invocation arguments."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from provium.configuration import parse_override
|
|
8
|
+
from provium.procedure.config import compose_configuration
|
|
9
|
+
|
|
10
|
+
from provium_cloud.deployment import CloudDeployment, load_deployment
|
|
11
|
+
from provium_cloud.invocations.models import InvocationPlan
|
|
12
|
+
from provium_cloud.invocations.planning import prepare_pipeline, prepare_procedure
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def configure_deployment(
|
|
16
|
+
parser: argparse.ArgumentParser, *, worker: bool = False
|
|
17
|
+
) -> None:
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"--deployment", "-d", required=not worker, help="Deployment YAML file"
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--deployment-set",
|
|
23
|
+
action="append",
|
|
24
|
+
default=[],
|
|
25
|
+
metavar="KEY.PATH=VALUE",
|
|
26
|
+
help="Override any deployment setting (repeatable)",
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument("--region")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def deployment(arguments: argparse.Namespace) -> CloudDeployment:
|
|
32
|
+
config = (
|
|
33
|
+
load_deployment(arguments.deployment)
|
|
34
|
+
if arguments.deployment
|
|
35
|
+
else CloudDeployment.model_validate_json(os.environ["PROVIUM_CLOUD_DEPLOYMENT"])
|
|
36
|
+
)
|
|
37
|
+
layers = [
|
|
38
|
+
config.model_dump(mode="json"),
|
|
39
|
+
*(parse_override(value) for value in arguments.deployment_set),
|
|
40
|
+
]
|
|
41
|
+
if arguments.region:
|
|
42
|
+
layers.append({"region": arguments.region})
|
|
43
|
+
return CloudDeployment.model_validate(compose_configuration(layers))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def configure_invocation(parser: argparse.ArgumentParser) -> None:
|
|
47
|
+
configure_deployment(parser)
|
|
48
|
+
selector = parser.add_mutually_exclusive_group(required=True)
|
|
49
|
+
selector.add_argument("--file", "-f", help="Unnamed pipeline graph YAML")
|
|
50
|
+
selector.add_argument("--procedure", help="Procedure identifier")
|
|
51
|
+
parser.add_argument("--input", action="append", default=[], metavar="NAME=VALUE")
|
|
52
|
+
parser.add_argument(
|
|
53
|
+
"--parameter",
|
|
54
|
+
action="append",
|
|
55
|
+
default=[],
|
|
56
|
+
metavar="KEY.PATH=VALUE",
|
|
57
|
+
help="Standalone procedure configuration",
|
|
58
|
+
)
|
|
59
|
+
parser.add_argument(
|
|
60
|
+
"--tag", action="append", default=[], help="Standalone procedure scheduling tag"
|
|
61
|
+
)
|
|
62
|
+
parser.add_argument(
|
|
63
|
+
"--target", action="append", help="Pipeline target alias or nodes.NAME.OUTPUT"
|
|
64
|
+
)
|
|
65
|
+
force = parser.add_mutually_exclusive_group()
|
|
66
|
+
force.add_argument("--force", action="store_true")
|
|
67
|
+
force.add_argument(
|
|
68
|
+
"--force-selector",
|
|
69
|
+
action="append",
|
|
70
|
+
help="nodes.NAME, procedures.ID, or tags.TAG",
|
|
71
|
+
)
|
|
72
|
+
parser.add_argument("--job-queue")
|
|
73
|
+
parser.add_argument("--job-definition")
|
|
74
|
+
parser.add_argument(
|
|
75
|
+
"--timeout", help="Job timeout: seconds, or duration such as 15m"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def assignments(values: list[str]) -> dict[str, str]:
|
|
80
|
+
result: dict[str, str] = {}
|
|
81
|
+
for assignment in values:
|
|
82
|
+
key, separator, value = assignment.partition("=")
|
|
83
|
+
if not separator or not key or key in result:
|
|
84
|
+
raise ValueError("inputs require unique NAME=VALUE assignments")
|
|
85
|
+
result[key] = value
|
|
86
|
+
return result
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def invocation(
|
|
90
|
+
arguments: argparse.Namespace, config: CloudDeployment
|
|
91
|
+
) -> InvocationPlan:
|
|
92
|
+
overrides = {
|
|
93
|
+
key: getattr(arguments, key)
|
|
94
|
+
for key in ("job_queue", "job_definition", "timeout")
|
|
95
|
+
if getattr(arguments, key) is not None
|
|
96
|
+
}
|
|
97
|
+
if arguments.procedure:
|
|
98
|
+
if arguments.target or arguments.force_selector:
|
|
99
|
+
raise ValueError("targets and force selectors require a pipeline")
|
|
100
|
+
return prepare_procedure(
|
|
101
|
+
arguments.procedure,
|
|
102
|
+
config,
|
|
103
|
+
configuration=compose_configuration(
|
|
104
|
+
[parse_override(value) for value in arguments.parameter]
|
|
105
|
+
),
|
|
106
|
+
tags=arguments.tag,
|
|
107
|
+
force=arguments.force,
|
|
108
|
+
overrides=overrides,
|
|
109
|
+
)
|
|
110
|
+
if arguments.parameter or arguments.tag:
|
|
111
|
+
raise ValueError("parameters and tags require a standalone procedure")
|
|
112
|
+
return prepare_pipeline(
|
|
113
|
+
arguments.file,
|
|
114
|
+
config,
|
|
115
|
+
targets=arguments.target,
|
|
116
|
+
force=arguments.force_selector or arguments.force,
|
|
117
|
+
overrides=overrides,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def json_result(value: Any) -> Any:
|
|
122
|
+
from provium_cloud.state.models import Run, RunPage
|
|
123
|
+
|
|
124
|
+
if isinstance(value, Run):
|
|
125
|
+
return {**value.model_dump(mode="json"), "progress": value.progress}
|
|
126
|
+
if isinstance(value, RunPage):
|
|
127
|
+
return {
|
|
128
|
+
"items": [json_result(run) for run in value.items],
|
|
129
|
+
"next_cursor": value.next_cursor,
|
|
130
|
+
}
|
|
131
|
+
return value.model_dump(mode="json") if hasattr(value, "model_dump") else value
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""AWS cloud configuration and execution commands."""
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Look up committed computation outputs and retrieve run artifacts."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from provium_cloud.cli.aws.arguments import configure_deployment, deployment
|
|
7
|
+
from provium_cloud.cli.aws.commands.base import AWSAction
|
|
8
|
+
from provium_cloud.client import CloudClient
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class LookupCommand(AWSAction):
|
|
12
|
+
name = "lookup"
|
|
13
|
+
help = "Look up verified outputs by computation key"
|
|
14
|
+
|
|
15
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
16
|
+
configure_deployment(parser)
|
|
17
|
+
parser.add_argument("computation")
|
|
18
|
+
|
|
19
|
+
def action(self, arguments: argparse.Namespace) -> Any:
|
|
20
|
+
with CloudClient(deployment(arguments)) as client:
|
|
21
|
+
return {"outputs": client.lookup(arguments.computation)}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class FetchCommand(AWSAction):
|
|
25
|
+
name = "fetch"
|
|
26
|
+
help = "Download a committed run output to a local artifact file"
|
|
27
|
+
|
|
28
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
29
|
+
configure_deployment(parser)
|
|
30
|
+
parser.add_argument("run_id")
|
|
31
|
+
parser.add_argument("output")
|
|
32
|
+
parser.add_argument("destination")
|
|
33
|
+
parser.add_argument("--overwrite", action="store_true")
|
|
34
|
+
|
|
35
|
+
def action(self, arguments: argparse.Namespace) -> dict[str, str]:
|
|
36
|
+
with CloudClient(deployment(arguments)) as client:
|
|
37
|
+
client.fetch(
|
|
38
|
+
arguments.run_id,
|
|
39
|
+
arguments.output,
|
|
40
|
+
arguments.destination,
|
|
41
|
+
overwrite=arguments.overwrite,
|
|
42
|
+
)
|
|
43
|
+
return {"destination": arguments.destination}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""AWS actions registered as native Provium commands."""
|
|
2
|
+
|
|
3
|
+
from provium.cli.catalog import CommandCatalog
|
|
4
|
+
from provium.cli.group import CommandGroup
|
|
5
|
+
|
|
6
|
+
from provium_cloud.cli.aws.commands.artifacts import FetchCommand, LookupCommand
|
|
7
|
+
from provium_cloud.cli.aws.commands.execution import (
|
|
8
|
+
ControllerCommand,
|
|
9
|
+
LogsCommand,
|
|
10
|
+
WorkerCommand,
|
|
11
|
+
)
|
|
12
|
+
from provium_cloud.cli.aws.commands.invocations import EnqueueCommand, PlanCommand
|
|
13
|
+
from provium_cloud.cli.aws.commands.runs import (
|
|
14
|
+
CancelCommand,
|
|
15
|
+
InspectCommand,
|
|
16
|
+
ListCommand,
|
|
17
|
+
RetryCommand,
|
|
18
|
+
StatusCommand,
|
|
19
|
+
WaitCommand,
|
|
20
|
+
)
|
|
21
|
+
from provium_cloud.cli.aws.commands.validate import ValidateCommand
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class AWSCommand(CommandGroup):
|
|
25
|
+
name = "aws"
|
|
26
|
+
help = "Schedule and manage execution on AWS Batch"
|
|
27
|
+
catalog = CommandCatalog()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
AWSCommand.catalog.register(ValidateCommand)
|
|
31
|
+
|
|
32
|
+
for command in (
|
|
33
|
+
PlanCommand,
|
|
34
|
+
EnqueueCommand,
|
|
35
|
+
ListCommand,
|
|
36
|
+
StatusCommand,
|
|
37
|
+
InspectCommand,
|
|
38
|
+
CancelCommand,
|
|
39
|
+
RetryCommand,
|
|
40
|
+
WaitCommand,
|
|
41
|
+
LookupCommand,
|
|
42
|
+
FetchCommand,
|
|
43
|
+
LogsCommand,
|
|
44
|
+
ControllerCommand,
|
|
45
|
+
WorkerCommand,
|
|
46
|
+
):
|
|
47
|
+
AWSCommand.catalog.register(command)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Consistent JSON results and error reporting for AWS actions."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
from abc import abstractmethod
|
|
6
|
+
from typing import Any, ClassVar
|
|
7
|
+
|
|
8
|
+
from provium.cli.command import Command
|
|
9
|
+
from provium.cli.errors import print_cli_error
|
|
10
|
+
|
|
11
|
+
from provium_cloud.cli.aws.arguments import json_result
|
|
12
|
+
from provium_cloud.state.models import Run
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AWSAction(Command):
|
|
16
|
+
fail_on_run_error: ClassVar[bool] = False
|
|
17
|
+
|
|
18
|
+
def execute(self, arguments: argparse.Namespace) -> int:
|
|
19
|
+
try:
|
|
20
|
+
result = self.action(arguments)
|
|
21
|
+
if result is not None:
|
|
22
|
+
print(json.dumps(json_result(result)))
|
|
23
|
+
return int(
|
|
24
|
+
self.fail_on_run_error
|
|
25
|
+
and isinstance(result, Run)
|
|
26
|
+
and result.status != "succeeded"
|
|
27
|
+
)
|
|
28
|
+
except Exception as error:
|
|
29
|
+
return print_cli_error(f"cloud AWS {self.name}", error)
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def action(self, arguments: argparse.Namespace) -> Any: ...
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Controller, worker, and provider log commands."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from provium_cloud.cli.aws.arguments import configure_deployment, deployment
|
|
8
|
+
from provium_cloud.cli.aws.commands.base import AWSAction
|
|
9
|
+
from provium_cloud.client import CloudClient
|
|
10
|
+
from provium_cloud.execution.aws.batch import BatchExecutor
|
|
11
|
+
from provium_cloud.execution.controller import Controller
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ControllerCommand(AWSAction):
|
|
15
|
+
name = "controller"
|
|
16
|
+
help = "Advance queued runs and reconcile AWS Batch jobs"
|
|
17
|
+
|
|
18
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
19
|
+
configure_deployment(parser)
|
|
20
|
+
parser.add_argument("--once", action="store_true")
|
|
21
|
+
parser.add_argument("--interval", type=float, default=2)
|
|
22
|
+
|
|
23
|
+
def action(self, arguments: argparse.Namespace) -> None:
|
|
24
|
+
with CloudClient(deployment(arguments)) as client:
|
|
25
|
+
controller = Controller(client)
|
|
26
|
+
if arguments.once:
|
|
27
|
+
controller.tick()
|
|
28
|
+
else:
|
|
29
|
+
controller.serve(interval=arguments.interval)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class WorkerCommand(AWSAction):
|
|
33
|
+
name = "worker"
|
|
34
|
+
help = "Execute an admitted computation inside a configured Batch job"
|
|
35
|
+
|
|
36
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
37
|
+
configure_deployment(parser, worker=True)
|
|
38
|
+
parser.add_argument("--computation", required=True)
|
|
39
|
+
parser.add_argument("--generation", required=True, type=int)
|
|
40
|
+
parser.add_argument("--attempt", required=True)
|
|
41
|
+
|
|
42
|
+
def action(self, arguments: argparse.Namespace) -> dict[str, bool]:
|
|
43
|
+
from provium_cloud.execution.worker import execute_job
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
"executed": execute_job(
|
|
47
|
+
deployment(arguments),
|
|
48
|
+
arguments.computation,
|
|
49
|
+
arguments.generation,
|
|
50
|
+
arguments.attempt,
|
|
51
|
+
job_id=os.environ.get("AWS_BATCH_JOB_ID"),
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class LogsCommand(AWSAction):
|
|
57
|
+
name = "logs"
|
|
58
|
+
help = "Read an AWS Batch job’s CloudWatch log page"
|
|
59
|
+
|
|
60
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
61
|
+
configure_deployment(parser)
|
|
62
|
+
parser.add_argument("job_id")
|
|
63
|
+
parser.add_argument("--cursor")
|
|
64
|
+
parser.add_argument("--limit", type=int, default=100)
|
|
65
|
+
|
|
66
|
+
def action(self, arguments: argparse.Namespace) -> dict[str, Any]:
|
|
67
|
+
return BatchExecutor(deployment(arguments).region).logs(
|
|
68
|
+
arguments.job_id, cursor=arguments.cursor, limit=arguments.limit
|
|
69
|
+
)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Plan and enqueue unnamed pipeline or standalone procedure invocations."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
from provium_cloud.cli.aws.arguments import (
|
|
6
|
+
assignments,
|
|
7
|
+
configure_invocation,
|
|
8
|
+
deployment,
|
|
9
|
+
invocation,
|
|
10
|
+
)
|
|
11
|
+
from provium_cloud.cli.aws.commands.base import AWSAction
|
|
12
|
+
from provium_cloud.client import CloudClient
|
|
13
|
+
from provium_cloud.invocations.models import InvocationPlan
|
|
14
|
+
from provium_cloud.state.models import Run
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PlanCommand(AWSAction):
|
|
18
|
+
name = "plan"
|
|
19
|
+
help = "Validate and resolve a graph and scheduling routes without submitting work"
|
|
20
|
+
|
|
21
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
22
|
+
configure_invocation(parser)
|
|
23
|
+
|
|
24
|
+
def action(self, arguments: argparse.Namespace) -> InvocationPlan:
|
|
25
|
+
return invocation(arguments, deployment(arguments))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class EnqueueCommand(AWSAction):
|
|
29
|
+
name = "enqueue"
|
|
30
|
+
help = "Durably enqueue a procedure or pipeline input set"
|
|
31
|
+
|
|
32
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
33
|
+
configure_invocation(parser)
|
|
34
|
+
parser.add_argument("--request-id", help="Idempotency key for this submission")
|
|
35
|
+
|
|
36
|
+
def action(self, arguments: argparse.Namespace) -> Run:
|
|
37
|
+
config = deployment(arguments)
|
|
38
|
+
plan = invocation(arguments, config)
|
|
39
|
+
with CloudClient(config) as client:
|
|
40
|
+
return client.enqueue(
|
|
41
|
+
plan, assignments(arguments.input), request_id=arguments.request_id
|
|
42
|
+
)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Query and manage durable run history."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from provium_cloud.cli.aws.arguments import configure_deployment, deployment
|
|
7
|
+
from provium_cloud.cli.aws.commands.base import AWSAction
|
|
8
|
+
from provium_cloud.client import CloudClient
|
|
9
|
+
from provium_cloud.state.models import Run, RunPage
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ListCommand(AWSAction):
|
|
13
|
+
name = "list"
|
|
14
|
+
help = "List input sets and run progress"
|
|
15
|
+
|
|
16
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
17
|
+
configure_deployment(parser)
|
|
18
|
+
parser.add_argument(
|
|
19
|
+
"--status",
|
|
20
|
+
action="append",
|
|
21
|
+
choices=["queued", "running", "succeeded", "failed", "canceled"],
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument("--input-set-id")
|
|
24
|
+
parser.add_argument("--cursor")
|
|
25
|
+
parser.add_argument("--limit", type=int, default=100)
|
|
26
|
+
|
|
27
|
+
def action(self, arguments: argparse.Namespace) -> RunPage:
|
|
28
|
+
with CloudClient(deployment(arguments)) as client:
|
|
29
|
+
return client.list_runs(
|
|
30
|
+
statuses=arguments.status,
|
|
31
|
+
input_set_id=arguments.input_set_id,
|
|
32
|
+
cursor=arguments.cursor,
|
|
33
|
+
limit=arguments.limit,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class StatusCommand(AWSAction):
|
|
38
|
+
name = "status"
|
|
39
|
+
help = "Show run inputs, tasks, progress, status, and outputs"
|
|
40
|
+
|
|
41
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
42
|
+
configure_deployment(parser)
|
|
43
|
+
parser.add_argument("run_id")
|
|
44
|
+
|
|
45
|
+
def action(self, arguments: argparse.Namespace) -> Run:
|
|
46
|
+
with CloudClient(deployment(arguments)) as client:
|
|
47
|
+
return client.get_run(arguments.run_id)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class InspectCommand(StatusCommand):
|
|
51
|
+
name = "inspect"
|
|
52
|
+
help = "Inspect a run or a task’s shared computation attempts"
|
|
53
|
+
|
|
54
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
55
|
+
super().configure(parser)
|
|
56
|
+
parser.add_argument("--node")
|
|
57
|
+
|
|
58
|
+
def action(self, arguments: argparse.Namespace) -> Any:
|
|
59
|
+
with CloudClient(deployment(arguments)) as client:
|
|
60
|
+
return (
|
|
61
|
+
client.attempts(arguments.run_id, arguments.node)
|
|
62
|
+
if arguments.node
|
|
63
|
+
else client.get_run(arguments.run_id)
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class CancelCommand(StatusCommand):
|
|
68
|
+
name = "cancel"
|
|
69
|
+
help = "Cancel a run; preserve work still needed by other runs"
|
|
70
|
+
|
|
71
|
+
def action(self, arguments: argparse.Namespace) -> Run:
|
|
72
|
+
with CloudClient(deployment(arguments)) as client:
|
|
73
|
+
return client.cancel(arguments.run_id)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class RetryCommand(StatusCommand):
|
|
77
|
+
name = "retry"
|
|
78
|
+
help = "Retry unfinished tasks of a failed or canceled run"
|
|
79
|
+
|
|
80
|
+
def action(self, arguments: argparse.Namespace) -> Run:
|
|
81
|
+
with CloudClient(deployment(arguments)) as client:
|
|
82
|
+
return client.retry(arguments.run_id)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class WaitCommand(StatusCommand):
|
|
86
|
+
name = "wait"
|
|
87
|
+
help = "Wait for a run to finish; exit nonzero if it fails or is canceled"
|
|
88
|
+
fail_on_run_error = True
|
|
89
|
+
|
|
90
|
+
def configure(self, parser: argparse.ArgumentParser) -> None:
|
|
91
|
+
super().configure(parser)
|
|
92
|
+
parser.add_argument("--timeout", type=float)
|
|
93
|
+
parser.add_argument("--interval", type=float, default=2)
|
|
94
|
+
|
|
95
|
+
def action(self, arguments: argparse.Namespace) -> Run:
|
|
96
|
+
with CloudClient(deployment(arguments)) as client:
|
|
97
|
+
return client.wait(
|
|
98
|
+
arguments.run_id, timeout=arguments.timeout, interval=arguments.interval
|
|
99
|
+
)
|