workflow.core 1.9.4__tar.gz → 1.9.5__tar.gz
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.
- {workflow_core-1.9.4 → workflow_core-1.9.5}/PKG-INFO +1 -1
- {workflow_core-1.9.4 → workflow_core-1.9.5}/pyproject.toml +1 -1
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/definitions/config.py +1 -6
- workflow_core-1.9.5/workflow/lifecycle/archive/__init__.py +158 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/lifecycle/archive/posix.py +8 -4
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/lifecycle/archive/s3.py +35 -19
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/read.py +3 -0
- workflow_core-1.9.5/workflow/workspaces/chimefrb.yml +98 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/workspaces/development.yml +13 -2
- workflow_core-1.9.4/workflow/lifecycle/archive/__init__.py +0 -102
- workflow_core-1.9.4/workflow/workspaces/chimefrb.yml +0 -54
- {workflow_core-1.9.4 → workflow_core-1.9.5}/README.md +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/__init__.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/cli/__init__.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/cli/buckets.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/cli/configs.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/cli/main.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/cli/pipelines.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/cli/results.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/cli/run.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/cli/schedules.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/cli/workspace.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/daemons/__init__.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/daemons/audit.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/daemons/transfer.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/definitions/__init__.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/definitions/jsonschema.md +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/definitions/notify.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/definitions/work.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/definitions/workspace.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/examples/autocomplete.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/examples/function.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/examples/sample.svg +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/examples/sample.workflow.yml +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/exceptions.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/helpers/__init__.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/helpers/date.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/http/__init__.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/http/buckets.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/http/client.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/http/configs.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/http/context.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/http/pipelines.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/http/results.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/http/schedules.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/lifecycle/__init__.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/lifecycle/archive/http.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/lifecycle/attempt.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/lifecycle/configure.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/lifecycle/execute.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/__init__.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/decorators.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/logger.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/prompt.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/renderers.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/tmate.sh +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/validate.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/variables.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/utils/write.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/workspaces/__init__.py +0 -0
- {workflow_core-1.9.4 → workflow_core-1.9.5}/workflow/workspaces/site-dev.yml +0 -0
|
@@ -47,13 +47,8 @@ class Archive(BaseSettings):
|
|
|
47
47
|
description="Archive strategy for the plots.",
|
|
48
48
|
examples=["move"],
|
|
49
49
|
)
|
|
50
|
-
logs: str = Field(
|
|
51
|
-
default="move",
|
|
52
|
-
description="Archive strategy for the logs.",
|
|
53
|
-
examples=["delete"],
|
|
54
|
-
)
|
|
55
50
|
|
|
56
|
-
@field_validator("products", "plots"
|
|
51
|
+
@field_validator("products", "plots")
|
|
57
52
|
def validate_archive(cls, value: str) -> str:
|
|
58
53
|
"""Validate the archive strategy.
|
|
59
54
|
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""Archive lifecycle module."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any, Callable, Dict
|
|
6
|
+
|
|
7
|
+
from workflow.definitions.work import Work
|
|
8
|
+
from workflow.lifecycle.archive import http, posix, s3
|
|
9
|
+
from workflow.utils import logger
|
|
10
|
+
|
|
11
|
+
log = logger.get_logger("workflow.lifecycle.archive")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ArchiveResultsError(Exception):
|
|
15
|
+
"""Exception raised for any error in archiving the results for a Work.
|
|
16
|
+
|
|
17
|
+
Attributes:
|
|
18
|
+
message (str): Explanation for the error.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self, message="Something went wrong when archiving the results."
|
|
23
|
+
) -> None:
|
|
24
|
+
"""Initialize the ArchiveResultsError.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
message (str): Error message to display.
|
|
28
|
+
"""
|
|
29
|
+
self.message = message
|
|
30
|
+
super().__init__(self.message)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _get_basepath(mounts: Dict[str, Any], site: str, storage: str) -> Path:
|
|
34
|
+
"""Get the basepath from the config for the given site and storage.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
mounts: Archive mounts configuration.
|
|
38
|
+
site: Site to get the basepath for.
|
|
39
|
+
storage: Storage type to get the basepath for.
|
|
40
|
+
|
|
41
|
+
Raises:
|
|
42
|
+
ArchiveResultsError: No configuration for the given storage in the workspace.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
Path: The basepath for the given site and storage.
|
|
46
|
+
"""
|
|
47
|
+
if not storage:
|
|
48
|
+
raise ArchiveResultsError("Storage must be given.")
|
|
49
|
+
elif storage == "posix":
|
|
50
|
+
basepath: Path = Path(f"{mounts.get(storage, {}).get(site, {})}")
|
|
51
|
+
elif storage == "s3":
|
|
52
|
+
basepath = Path(f"{mounts.get(storage, {}).get(site, {}).get('subpath', '')}")
|
|
53
|
+
else:
|
|
54
|
+
raise ArchiveResultsError(f"No configuration for {storage} in Workspace.")
|
|
55
|
+
return basepath
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def run(work: Work, workspace: Dict[str, Any]) -> None:
|
|
59
|
+
"""Run the archive lifecycle for a work object.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
work (Work): The work object to run the archive lifecycle for.
|
|
63
|
+
workspace (Dict[str, Any]): The workspace configuration.
|
|
64
|
+
"""
|
|
65
|
+
try:
|
|
66
|
+
mounts: Dict[str, Any] = workspace.get("archive", {})
|
|
67
|
+
archive_config: Dict[str, Any] = workspace.get("config", {}).get("archive", {})
|
|
68
|
+
changes: bool = False
|
|
69
|
+
actions: Dict[str, Dict[str, Callable]] = {
|
|
70
|
+
"s3": {
|
|
71
|
+
"bypass": s3.bypass,
|
|
72
|
+
"copy": s3.copy,
|
|
73
|
+
"delete": s3.delete,
|
|
74
|
+
"move": s3.move,
|
|
75
|
+
},
|
|
76
|
+
"posix": {
|
|
77
|
+
"bypass": posix.bypass,
|
|
78
|
+
"copy": posix.copy,
|
|
79
|
+
"delete": posix.delete,
|
|
80
|
+
"move": posix.move,
|
|
81
|
+
},
|
|
82
|
+
"http": {
|
|
83
|
+
"bypass": http.bypass,
|
|
84
|
+
"copy": http.copy,
|
|
85
|
+
"delete": http.delete,
|
|
86
|
+
"move": http.move,
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
if work.creation:
|
|
90
|
+
date: str = datetime.fromtimestamp(work.creation).strftime("%Y%m%d")
|
|
91
|
+
else:
|
|
92
|
+
raise NameError("Creation date not found in work object.")
|
|
93
|
+
work_subpath: str = f"{date}/{work.pipeline}/{work.id}"
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
if (
|
|
97
|
+
work.config.archive.products
|
|
98
|
+
in archive_config.get("products", {}).get("methods", [])
|
|
99
|
+
and work.products
|
|
100
|
+
):
|
|
101
|
+
storage: str = archive_config.get("products", {}).get("storage", "")
|
|
102
|
+
basepath: Path = _get_basepath(mounts, work.site, storage)
|
|
103
|
+
path: Path = basepath / work_subpath
|
|
104
|
+
if storage in actions.keys():
|
|
105
|
+
actions[storage][work.config.archive.products](
|
|
106
|
+
path,
|
|
107
|
+
work.products,
|
|
108
|
+
work.site,
|
|
109
|
+
)
|
|
110
|
+
changes = True
|
|
111
|
+
else:
|
|
112
|
+
log.warning(
|
|
113
|
+
f"Archive storage {storage} not supported, or storage has not been set for products in workspace." # noqa: E501
|
|
114
|
+
)
|
|
115
|
+
elif work.config.archive.products not in archive_config.get(
|
|
116
|
+
"products", {}
|
|
117
|
+
).get("methods", []):
|
|
118
|
+
log.warning(
|
|
119
|
+
f"Archive method {work.config.archive.products} not allowed for products by workspace." # noqa: E501
|
|
120
|
+
)
|
|
121
|
+
except ArchiveResultsError as error:
|
|
122
|
+
log.warning(error)
|
|
123
|
+
|
|
124
|
+
try:
|
|
125
|
+
if (
|
|
126
|
+
work.config.archive.plots
|
|
127
|
+
in archive_config.get("plots", {}).get("methods", [])
|
|
128
|
+
and work.plots
|
|
129
|
+
):
|
|
130
|
+
storage = archive_config.get("plots", {}).get("storage", "")
|
|
131
|
+
basepath = _get_basepath(mounts, work.site, storage)
|
|
132
|
+
path = basepath / work_subpath
|
|
133
|
+
if storage in actions.keys():
|
|
134
|
+
actions[storage][work.config.archive.plots](
|
|
135
|
+
path,
|
|
136
|
+
work.plots,
|
|
137
|
+
work.site,
|
|
138
|
+
)
|
|
139
|
+
changes = True
|
|
140
|
+
else:
|
|
141
|
+
log.warning(
|
|
142
|
+
f"Archive storage {storage} not supported, or storage has not been set for plots in workspace." # noqa: E501
|
|
143
|
+
)
|
|
144
|
+
elif work.config.archive.plots not in archive_config.get("plots", {}).get(
|
|
145
|
+
"methods", []
|
|
146
|
+
):
|
|
147
|
+
log.warning(
|
|
148
|
+
f"Archive method {work.config.archive.plots} not allowed for plots by workspace." # noqa: E501
|
|
149
|
+
)
|
|
150
|
+
except ArchiveResultsError as error:
|
|
151
|
+
log.warning(error)
|
|
152
|
+
|
|
153
|
+
if changes and "posix" in archive_config.get("permissions", {}):
|
|
154
|
+
posix.permissions(
|
|
155
|
+
path, archive_config.get("permissions", {}).get("posix", {})
|
|
156
|
+
)
|
|
157
|
+
except Exception as error:
|
|
158
|
+
log.warning(error)
|
|
@@ -55,23 +55,25 @@ def check_basepath(path: Path):
|
|
|
55
55
|
return True
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
def bypass(path: Path, payload: Optional[List[str]]) -> bool:
|
|
58
|
+
def bypass(path: Path, payload: Optional[List[str]], site: str) -> bool:
|
|
59
59
|
"""Bypass the archive.
|
|
60
60
|
|
|
61
61
|
Args:
|
|
62
62
|
path (Path): Destination path.
|
|
63
63
|
payload (List[str]): List of files to copy.
|
|
64
|
+
site (str): Site work was performed at.
|
|
64
65
|
"""
|
|
65
66
|
log.info("Bypassing archive.")
|
|
66
67
|
return True
|
|
67
68
|
|
|
68
69
|
|
|
69
|
-
def copy(path: Path, payload: Optional[List[str]]) -> bool:
|
|
70
|
+
def copy(path: Path, payload: Optional[List[str]], site: str) -> bool:
|
|
70
71
|
"""Copy the work products to the archive.
|
|
71
72
|
|
|
72
73
|
Args:
|
|
73
74
|
path (Path): Destination path.
|
|
74
75
|
payload (List[str]): List of files to copy.
|
|
76
|
+
site (str): Site work was performed at.
|
|
75
77
|
"""
|
|
76
78
|
try:
|
|
77
79
|
check_basepath(path)
|
|
@@ -94,12 +96,13 @@ def copy(path: Path, payload: Optional[List[str]]) -> bool:
|
|
|
94
96
|
return False
|
|
95
97
|
|
|
96
98
|
|
|
97
|
-
def move(path: Path, payload: Optional[List[str]]) -> bool:
|
|
99
|
+
def move(path: Path, payload: Optional[List[str]], site: str) -> bool:
|
|
98
100
|
"""Move the work products to the archive.
|
|
99
101
|
|
|
100
102
|
Args:
|
|
101
103
|
path (Path): Destination path.
|
|
102
104
|
payload (List[str]): List of products to move.
|
|
105
|
+
site (str): Site work was performed at.
|
|
103
106
|
"""
|
|
104
107
|
status: bool = False
|
|
105
108
|
try:
|
|
@@ -119,12 +122,13 @@ def move(path: Path, payload: Optional[List[str]]) -> bool:
|
|
|
119
122
|
return status
|
|
120
123
|
|
|
121
124
|
|
|
122
|
-
def delete(path: Path, payload: Optional[List[str]]) -> bool:
|
|
125
|
+
def delete(path: Path, payload: Optional[List[str]], site: str) -> bool:
|
|
123
126
|
"""Delete the work products from the archive.
|
|
124
127
|
|
|
125
128
|
Args:
|
|
126
129
|
path (Path): Destination path.
|
|
127
130
|
payload (List[str]): List of products to delete.
|
|
131
|
+
site (str): Site work was performed at.
|
|
128
132
|
"""
|
|
129
133
|
status: bool = False
|
|
130
134
|
try:
|
|
@@ -6,50 +6,62 @@ from typing import List, Optional
|
|
|
6
6
|
|
|
7
7
|
from minio import Minio
|
|
8
8
|
|
|
9
|
-
from workflow
|
|
9
|
+
from workflow import DEFAULT_WORKSPACE_PATH
|
|
10
|
+
from workflow.utils import logger, read
|
|
10
11
|
|
|
11
12
|
log = logger.get_logger("workflow.lifecycle.archive.s3")
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
workspace = read.workspace(DEFAULT_WORKSPACE_PATH)
|
|
17
|
+
except Exception as error:
|
|
18
|
+
log.debug(f"Failed to import s3 archive configuration, {error}")
|
|
19
|
+
log.debug("Using empty workspace configuration.")
|
|
20
|
+
workspace = {}
|
|
21
|
+
|
|
22
|
+
WORKFLOW_S3_ARCHIVE_CONFIG = workspace.get("archive", {}).get("s3", {})
|
|
14
23
|
WORKFLOW_S3_ACCESS_KEY = os.getenv("WORKFLOW_S3_ACCESS_KEY")
|
|
15
24
|
WORKFLOW_S3_SECRET_KEY = os.getenv("WORKFLOW_S3_SECRET_KEY")
|
|
16
|
-
WORKFLOW_S3_BUCKET = os.getenv("WORKFLOW_S3_BUCKET", "workflow")
|
|
17
25
|
|
|
18
26
|
|
|
19
|
-
def bypass(path: Path, payload: Optional[List[str]]) -> bool:
|
|
27
|
+
def bypass(path: Path, payload: Optional[List[str]], site: str) -> bool:
|
|
20
28
|
"""Bypass the archive.
|
|
21
29
|
|
|
22
30
|
Args:
|
|
23
31
|
path (Path): Destination path.
|
|
24
32
|
payload (List[str]): List of files to copy.
|
|
33
|
+
site (str): Site work was performed at.
|
|
25
34
|
"""
|
|
26
35
|
log.info("Bypassing archive.")
|
|
27
36
|
return True
|
|
28
37
|
|
|
29
38
|
|
|
30
|
-
def copy(path: Path, payload: Optional[List[str]]) -> bool:
|
|
39
|
+
def copy(path: Path, payload: Optional[List[str]], site: str) -> bool:
|
|
31
40
|
"""Copy the work products to the archive.
|
|
32
41
|
|
|
33
42
|
Args:
|
|
34
43
|
path (Path): Destination path.
|
|
35
44
|
payload (List[str]): List of files to copy.
|
|
45
|
+
site (str): Site work was performed at.
|
|
36
46
|
"""
|
|
37
47
|
try:
|
|
48
|
+
workflow_s3_endpoint = WORKFLOW_S3_ARCHIVE_CONFIG.get(site, {}).get("url", "")
|
|
49
|
+
workflow_s3_bucket = WORKFLOW_S3_ARCHIVE_CONFIG.get(site, {}).get("bucket", "")
|
|
38
50
|
# Initialise minio client
|
|
39
51
|
log.info("Connecting to S3 storage to copy files")
|
|
40
|
-
log.debug(f"Endpoint: {
|
|
52
|
+
log.debug(f"Endpoint: {workflow_s3_endpoint}")
|
|
41
53
|
log.debug(f"Access Key: {WORKFLOW_S3_ACCESS_KEY}")
|
|
42
54
|
log.debug(f"Secret Key: {WORKFLOW_S3_SECRET_KEY}")
|
|
43
55
|
client = Minio(
|
|
44
|
-
endpoint=
|
|
56
|
+
endpoint=workflow_s3_endpoint,
|
|
45
57
|
access_key=WORKFLOW_S3_ACCESS_KEY,
|
|
46
58
|
secret_key=WORKFLOW_S3_SECRET_KEY,
|
|
47
59
|
)
|
|
48
60
|
log.info("Connected ✅")
|
|
49
61
|
# Check bucket exists and if not, create it
|
|
50
|
-
if not client.bucket_exists(
|
|
51
|
-
log.info(f"Bucket {
|
|
52
|
-
client.make_bucket(
|
|
62
|
+
if not client.bucket_exists(workflow_s3_bucket):
|
|
63
|
+
log.info(f"Bucket {workflow_s3_bucket} does not exist. Creating it.")
|
|
64
|
+
client.make_bucket(workflow_s3_bucket)
|
|
53
65
|
# Check there are files to copy
|
|
54
66
|
if not payload:
|
|
55
67
|
log.info("No files in payload.")
|
|
@@ -63,7 +75,7 @@ def copy(path: Path, payload: Optional[List[str]]) -> bool:
|
|
|
63
75
|
continue
|
|
64
76
|
# Upload file to S3
|
|
65
77
|
client.fput_object(
|
|
66
|
-
bucket_name=
|
|
78
|
+
bucket_name=workflow_s3_bucket,
|
|
67
79
|
object_name="/".join([object_paths, item.split("/")[-1]]),
|
|
68
80
|
file_path=item,
|
|
69
81
|
)
|
|
@@ -79,29 +91,32 @@ def copy(path: Path, payload: Optional[List[str]]) -> bool:
|
|
|
79
91
|
return False
|
|
80
92
|
|
|
81
93
|
|
|
82
|
-
def move(path: Path, payload: Optional[List[str]]) -> bool:
|
|
94
|
+
def move(path: Path, payload: Optional[List[str]], site: str) -> bool:
|
|
83
95
|
"""Move the work products to the archive.
|
|
84
96
|
|
|
85
97
|
Args:
|
|
86
98
|
path (Path): Destination path.
|
|
87
99
|
payload (List[str]): List of products to move.
|
|
100
|
+
site (str): Site work was performed at.
|
|
88
101
|
"""
|
|
89
102
|
try:
|
|
103
|
+
workflow_s3_endpoint = WORKFLOW_S3_ARCHIVE_CONFIG.get(site, {}).get("url", "")
|
|
104
|
+
workflow_s3_bucket = WORKFLOW_S3_ARCHIVE_CONFIG.get(site, {}).get("bucket", "")
|
|
90
105
|
# Initialise minio client
|
|
91
106
|
log.info("Connecting to S3 storage to move files")
|
|
92
|
-
log.debug(f"Endpoint: {
|
|
107
|
+
log.debug(f"Endpoint: {workflow_s3_endpoint}")
|
|
93
108
|
log.debug(f"Access Key: {WORKFLOW_S3_ACCESS_KEY}")
|
|
94
109
|
log.debug(f"Secret Key: {WORKFLOW_S3_SECRET_KEY}")
|
|
95
110
|
client = Minio(
|
|
96
|
-
endpoint=
|
|
111
|
+
endpoint=workflow_s3_endpoint,
|
|
97
112
|
access_key=WORKFLOW_S3_ACCESS_KEY,
|
|
98
113
|
secret_key=WORKFLOW_S3_SECRET_KEY,
|
|
99
114
|
)
|
|
100
115
|
log.info("Connected ✅")
|
|
101
116
|
# Check bucket exists and if not, create it
|
|
102
|
-
if not client.bucket_exists(
|
|
103
|
-
log.info(f"Bucket {
|
|
104
|
-
client.make_bucket(
|
|
117
|
+
if not client.bucket_exists(workflow_s3_bucket):
|
|
118
|
+
log.info(f"Bucket {workflow_s3_bucket} does not exist. Creating it.")
|
|
119
|
+
client.make_bucket(workflow_s3_bucket)
|
|
105
120
|
# Check there are files to copy
|
|
106
121
|
if not payload:
|
|
107
122
|
log.info("No files in payload.")
|
|
@@ -115,7 +130,7 @@ def move(path: Path, payload: Optional[List[str]]) -> bool:
|
|
|
115
130
|
continue
|
|
116
131
|
# Upload file to S3
|
|
117
132
|
client.fput_object(
|
|
118
|
-
bucket_name=
|
|
133
|
+
bucket_name=workflow_s3_bucket,
|
|
119
134
|
object_name="/".join([object_paths, item.split("/")[-1]]),
|
|
120
135
|
file_path=item,
|
|
121
136
|
)
|
|
@@ -133,12 +148,13 @@ def move(path: Path, payload: Optional[List[str]]) -> bool:
|
|
|
133
148
|
return False
|
|
134
149
|
|
|
135
150
|
|
|
136
|
-
def delete(path: Path, payload: Optional[List[str]]) -> bool:
|
|
151
|
+
def delete(path: Path, payload: Optional[List[str]], site: str) -> bool:
|
|
137
152
|
"""Delete the work products from the archive.
|
|
138
153
|
|
|
139
154
|
Args:
|
|
140
155
|
path (Path): Destination path.
|
|
141
156
|
payload (List[str]): List of products to delete.
|
|
157
|
+
site (str): Site work was performed at.
|
|
142
158
|
"""
|
|
143
159
|
# TODO: Implement delete for S3
|
|
144
160
|
# NOTE: Do we need a specific delete function for S3?
|
|
@@ -32,6 +32,9 @@ def workspace(source: Union[str, Path]) -> Dict[str, Any]:
|
|
|
32
32
|
Returns:
|
|
33
33
|
Dict[str, Any]: Workspace Configuration
|
|
34
34
|
"""
|
|
35
|
+
if isinstance(source, str) and Path(source).exists():
|
|
36
|
+
source = Path(source)
|
|
37
|
+
|
|
35
38
|
if isinstance(source, Path):
|
|
36
39
|
if source.exists():
|
|
37
40
|
if source.suffix in [".yaml", ".yml"]:
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
workspace: chimefrb
|
|
2
|
+
|
|
3
|
+
sites:
|
|
4
|
+
- local
|
|
5
|
+
- chime
|
|
6
|
+
- kko
|
|
7
|
+
- gbo
|
|
8
|
+
- hco
|
|
9
|
+
- aro
|
|
10
|
+
- canfar
|
|
11
|
+
- cedar
|
|
12
|
+
- calcul-quebec
|
|
13
|
+
|
|
14
|
+
http:
|
|
15
|
+
baseurls:
|
|
16
|
+
buckets:
|
|
17
|
+
- http://frb-vsop.chime:8004
|
|
18
|
+
- https://frb.chimenet.ca/buckets
|
|
19
|
+
results:
|
|
20
|
+
- http://frb-vsop.chime:8005
|
|
21
|
+
- https://frb.chimenet.ca/results
|
|
22
|
+
pipelines:
|
|
23
|
+
- http://frb-vsop.chime:8007
|
|
24
|
+
- https://frb.chimenet.ca/pipelines
|
|
25
|
+
configs:
|
|
26
|
+
- http://frb-vsop.chime:8007
|
|
27
|
+
- https://frb.chimenet.ca/pipelines
|
|
28
|
+
schedules:
|
|
29
|
+
- http://frb-vsop.chime:8007
|
|
30
|
+
- https://frb.chimenet.ca/pipelines
|
|
31
|
+
loki: https://frb.chimenet.ca/loki/loki/api/v1/push
|
|
32
|
+
# This is the prefix url to make a output data plot or product accessible to the user
|
|
33
|
+
products: https://frb.chimenet.ca/frb-master/v1/events/query-file?filename=
|
|
34
|
+
|
|
35
|
+
archive:
|
|
36
|
+
posix:
|
|
37
|
+
local: ./workflow
|
|
38
|
+
chime: /data/chime/baseband/processed/workflow
|
|
39
|
+
kko: Null
|
|
40
|
+
gbo: Null
|
|
41
|
+
hco: Null
|
|
42
|
+
aro: Null
|
|
43
|
+
canfar: /arc/projects/chime_frb/data/canfar/processed/workflow
|
|
44
|
+
cedar: Null
|
|
45
|
+
calcul-quebec: Null
|
|
46
|
+
s3:
|
|
47
|
+
local:
|
|
48
|
+
url: Null
|
|
49
|
+
bucket: workflow
|
|
50
|
+
subpath: /workflow
|
|
51
|
+
chime:
|
|
52
|
+
url: Null
|
|
53
|
+
bucket: chime
|
|
54
|
+
subpath: /workflow
|
|
55
|
+
kko:
|
|
56
|
+
url: Null
|
|
57
|
+
bucket: kko
|
|
58
|
+
subpath: /workflow
|
|
59
|
+
gbo:
|
|
60
|
+
url: Null
|
|
61
|
+
bucket: gbo
|
|
62
|
+
subpath: /workflow
|
|
63
|
+
hco:
|
|
64
|
+
url: Null
|
|
65
|
+
bucket: hco
|
|
66
|
+
subpath: /workflow
|
|
67
|
+
aro:
|
|
68
|
+
url: Null
|
|
69
|
+
bucket: aro
|
|
70
|
+
subpath: /workflow
|
|
71
|
+
canfar:
|
|
72
|
+
url: Null
|
|
73
|
+
bucket: canfar
|
|
74
|
+
subpath: /workflow
|
|
75
|
+
cedar:
|
|
76
|
+
url: Null
|
|
77
|
+
bucket: cedar
|
|
78
|
+
subpath: /workflow
|
|
79
|
+
calcul-quebec:
|
|
80
|
+
url: Null
|
|
81
|
+
bucket: calcul-quebec
|
|
82
|
+
subpath: /workflow
|
|
83
|
+
|
|
84
|
+
config:
|
|
85
|
+
archive:
|
|
86
|
+
results: true
|
|
87
|
+
plots:
|
|
88
|
+
methods: ["move", "delete"] # Defines the methods enabled by the workspace admin
|
|
89
|
+
storage: "s3"
|
|
90
|
+
permissions: List[Linux Groups]?
|
|
91
|
+
products:
|
|
92
|
+
methods: ["move", "delete"] # Can also be copy or delete
|
|
93
|
+
storage: "posix"
|
|
94
|
+
permissions:
|
|
95
|
+
posix:
|
|
96
|
+
user: "user"
|
|
97
|
+
group: "chime-frb-ro"
|
|
98
|
+
command: "setfacl -R -m g:{group}:r {path}"
|
|
@@ -3,6 +3,7 @@ workspace: development
|
|
|
3
3
|
# List the valid sites for this workspace
|
|
4
4
|
sites:
|
|
5
5
|
- local
|
|
6
|
+
- testing
|
|
6
7
|
|
|
7
8
|
http:
|
|
8
9
|
baseurls:
|
|
@@ -13,8 +14,18 @@ http:
|
|
|
13
14
|
results: http://localhost:8005
|
|
14
15
|
|
|
15
16
|
archive:
|
|
16
|
-
|
|
17
|
+
posix:
|
|
17
18
|
local: "/"
|
|
19
|
+
testing: "./testing/workflow"
|
|
20
|
+
s3:
|
|
21
|
+
local:
|
|
22
|
+
url: not-real.com
|
|
23
|
+
bucket: local
|
|
24
|
+
subpath: /workflow
|
|
25
|
+
testing:
|
|
26
|
+
url: play.min.io
|
|
27
|
+
bucket: testing
|
|
28
|
+
subpath: /workflow
|
|
18
29
|
|
|
19
30
|
config:
|
|
20
31
|
archive:
|
|
@@ -24,7 +35,7 @@ config:
|
|
|
24
35
|
- "copy"
|
|
25
36
|
- "delete"
|
|
26
37
|
- "move"
|
|
27
|
-
storage: "
|
|
38
|
+
storage: "posix"
|
|
28
39
|
products:
|
|
29
40
|
methods:
|
|
30
41
|
- "bypass"
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"""Archive lifecycle module."""
|
|
2
|
-
|
|
3
|
-
from datetime import datetime
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
from typing import Any, Dict
|
|
6
|
-
|
|
7
|
-
from workflow.definitions.work import Work
|
|
8
|
-
from workflow.lifecycle.archive import http, posix, s3
|
|
9
|
-
from workflow.utils import logger
|
|
10
|
-
|
|
11
|
-
log = logger.get_logger("workflow.lifecycle.archive")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def run(work: Work, workspace: Dict[str, Any]) -> None:
|
|
15
|
-
"""Run the archive lifecycle for a work object.
|
|
16
|
-
|
|
17
|
-
Args:
|
|
18
|
-
work (Work): The work object to run the archive lifecycle for.
|
|
19
|
-
workspace (Dict[str, Any]): The workspace configuration.
|
|
20
|
-
"""
|
|
21
|
-
try:
|
|
22
|
-
mounts: Dict[str, Any] = workspace.get("archive", {}).get("mounts", {})
|
|
23
|
-
archive_config: Dict[str, Any] = workspace.get("config", {}).get("archive", {})
|
|
24
|
-
changes: bool = False
|
|
25
|
-
actions = {
|
|
26
|
-
"s3": {
|
|
27
|
-
"bypass": s3.bypass,
|
|
28
|
-
"copy": s3.copy,
|
|
29
|
-
"delete": s3.delete,
|
|
30
|
-
"move": s3.move,
|
|
31
|
-
},
|
|
32
|
-
"posix": {
|
|
33
|
-
"bypass": posix.bypass,
|
|
34
|
-
"copy": posix.copy,
|
|
35
|
-
"delete": posix.delete,
|
|
36
|
-
"move": posix.move,
|
|
37
|
-
},
|
|
38
|
-
"http": {
|
|
39
|
-
"bypass": http.bypass,
|
|
40
|
-
"copy": http.copy,
|
|
41
|
-
"delete": http.delete,
|
|
42
|
-
"move": http.move,
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
if work.creation:
|
|
46
|
-
date: str = datetime.fromtimestamp(work.creation).strftime("%Y%m%d")
|
|
47
|
-
else:
|
|
48
|
-
raise NameError("Creation date not found in work object.")
|
|
49
|
-
basepath: Path = Path(f"{mounts.get(work.site)}")
|
|
50
|
-
path: Path = basepath / f"/workflow/{date}/{work.pipeline}/{work.id}"
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
work.config.archive.products
|
|
54
|
-
in archive_config.get("products", {}).get("methods", [])
|
|
55
|
-
and work.products
|
|
56
|
-
):
|
|
57
|
-
storage: str = archive_config.get("products", {}).get("storage", "")
|
|
58
|
-
if storage in actions.keys():
|
|
59
|
-
actions[storage][work.config.archive.products](
|
|
60
|
-
path,
|
|
61
|
-
work.products,
|
|
62
|
-
)
|
|
63
|
-
changes = True
|
|
64
|
-
else:
|
|
65
|
-
log.warning(
|
|
66
|
-
f"Archive storage {storage} not supported, or storage has not been set for products in workspace." # noqa: E501
|
|
67
|
-
)
|
|
68
|
-
elif work.config.archive.products not in archive_config.get("products", {}).get(
|
|
69
|
-
"methods", []
|
|
70
|
-
):
|
|
71
|
-
log.warning(
|
|
72
|
-
f"Archive method {work.config.archive.products} not allowed for products by workspace." # noqa: E501
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
work.config.archive.plots
|
|
77
|
-
in archive_config.get("plots", {}).get("methods", [])
|
|
78
|
-
and work.plots
|
|
79
|
-
):
|
|
80
|
-
storage = archive_config.get("plots", {}).get("storage", "")
|
|
81
|
-
if storage in actions.keys():
|
|
82
|
-
actions[storage][work.config.archive.plots](
|
|
83
|
-
path,
|
|
84
|
-
work.plots,
|
|
85
|
-
)
|
|
86
|
-
changes = True
|
|
87
|
-
else:
|
|
88
|
-
log.warning(
|
|
89
|
-
f"Archive storage {storage} not supported, or storage has not been set for plots in workspace." # noqa: E501
|
|
90
|
-
)
|
|
91
|
-
elif work.config.archive.plots not in archive_config.get("plots", {}).get(
|
|
92
|
-
"methods", []
|
|
93
|
-
):
|
|
94
|
-
log.warning(
|
|
95
|
-
f"Archive method {work.config.archive.plots} not allowed for plots by workspace." # noqa: E501
|
|
96
|
-
)
|
|
97
|
-
if changes and "posix" in archive_config.get("permissions", {}):
|
|
98
|
-
posix.permissions(
|
|
99
|
-
path, archive_config.get("permissions", {}).get("posix", {})
|
|
100
|
-
)
|
|
101
|
-
except Exception as error:
|
|
102
|
-
log.warning(error)
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
workspace: chimefrb
|
|
2
|
-
|
|
3
|
-
sites:
|
|
4
|
-
- local
|
|
5
|
-
- chime
|
|
6
|
-
- kko
|
|
7
|
-
- gbo
|
|
8
|
-
- hco
|
|
9
|
-
- aro
|
|
10
|
-
- canfar
|
|
11
|
-
- cedar
|
|
12
|
-
- calcul-quebec
|
|
13
|
-
|
|
14
|
-
http:
|
|
15
|
-
baseurls:
|
|
16
|
-
buckets:
|
|
17
|
-
- http://frb-vsop.chime:8004
|
|
18
|
-
- https://frb.chimenet.ca/buckets
|
|
19
|
-
results:
|
|
20
|
-
- http://frb-vsop.chime:8005
|
|
21
|
-
- https://frb.chimenet.ca/results
|
|
22
|
-
pipelines:
|
|
23
|
-
- http://frb-vsop.chime:8007
|
|
24
|
-
- https://frb.chimenet.ca/pipelines
|
|
25
|
-
loki: https://frb.chimenet.ca/loki/loki/api/v1/push
|
|
26
|
-
# This is the prefix url to make a output data plot or product accessible to the user
|
|
27
|
-
products: https://frb.chimenet.ca/frb-master/v1/events/query-file?filename=
|
|
28
|
-
|
|
29
|
-
archive:
|
|
30
|
-
posix:
|
|
31
|
-
base: "/data/frb-archiver"
|
|
32
|
-
buckets: "/data/frb-archiver/buckets"
|
|
33
|
-
results: "/data/frb-archiver/results"
|
|
34
|
-
pipelines: "/data/frb-archiver/pipelines"
|
|
35
|
-
loki: "/data/frb-archiver/loki"
|
|
36
|
-
products: "/data/frb-archiver/products"
|
|
37
|
-
s3:
|
|
38
|
-
minio:
|
|
39
|
-
url: "https://s3.us-west-2.amazonaws.com/frb-archiver"
|
|
40
|
-
|
|
41
|
-
config:
|
|
42
|
-
archive:
|
|
43
|
-
results: true
|
|
44
|
-
plots:
|
|
45
|
-
methods: ["move", "delete"] # Defines the methods enabled by the workspace admin
|
|
46
|
-
storage: "s3"
|
|
47
|
-
permissions: List[Linux Groups]?
|
|
48
|
-
products:
|
|
49
|
-
methods: ["move", "delete"] # Can also be copy or delete
|
|
50
|
-
storage: "posix"
|
|
51
|
-
logging:
|
|
52
|
-
loki:
|
|
53
|
-
site: "local"
|
|
54
|
-
pipeline: "temp"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|