Skip to content

Commit c9da731

Browse files
committed
refactor: move realm definitions to deployment directory
1 parent cd797fc commit c9da731

4 files changed

Lines changed: 97 additions & 16 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This file defines the deployments for various beamlines at PSI.
2+
# The structure is as follows:
3+
#
4+
# Realm:
5+
# xname: <xname> # Optional: xname if available e.g. X12SA
6+
# managers: # defining the manager groups
7+
# - <access_group>
8+
# deployments:
9+
# bec-vm-host-00x.psi.ch:
10+
# name: <name>
11+
# description: <description>
12+
# deployment_access: # defining permissions to change the DeploymentAccess and thus the ACLs
13+
# - <access_group>
14+
# experiment_access: # defining additional groups to retrieve the Experiment info
15+
# - <access_group>
16+
17+
BL_wakonig:
18+
managers:
19+
- wakonig_k
20+
deployments:
21+
localhost:
22+
name: production
23+
description: Primary deployment for BL_wakonig
24+
deployment_access:
25+
- wakonig_k
26+
experiment_access:
27+
- wakonig_k
28+
29+
BL_appel:
30+
managers:
31+
- appel_c
32+
deployments:
33+
localhost:
34+
name: production
35+
description: Primary deployment for BL_appel
36+
deployment_access:
37+
- appel_c
38+
experiment_access:
39+
- appel_c
40+
41+
BL_wyzula:
42+
managers:
43+
- wyzula_j
44+
deployments:
45+
localhost:
46+
name: production
47+
description: Primary deployment for BL_wyzula
48+
deployment_access:
49+
- wyzula_j
50+
experiment_access:
51+
- wyzula_j
52+
53+
BL_perl:
54+
managers:
55+
- perl_d
56+
deployments:
57+
localhost:
58+
name: production
59+
description: Primary deployment for BL_perl
60+
deployment_access:
61+
- perl_d
62+
experiment_access:
63+
- perl_d

backend/utils/sls_deployments.yaml renamed to backend/bec_atlas/deployment/realms/sls_deployments.yaml

File renamed without changes.

backend/bec_atlas/ingestor/deployment_ingestor.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,15 @@ def _load_deployments(self):
5353
)
5454

5555
# Check if the deployment already exists in the database and insert if not
56-
existing_deployment = self.db["deployments"].find_one({"name": deployment.name})
56+
existing_deployment = self.db["deployments"].find_one(
57+
{"name": deployment.name, "realm_id": deployment.realm_id}
58+
)
5759
if existing_deployment is None:
5860
print(f"Inserting deployment: {deployment.name}")
5961
self.db["deployments"].insert_one(deployment.__dict__)
60-
existing_deployment = self.db["deployments"].find_one({"name": deployment.name})
62+
existing_deployment = self.db["deployments"].find_one(
63+
{"name": deployment.name, "realm_id": deployment.realm_id}
64+
)
6165
else:
6266
# Update the access groups if necessary
6367
if existing_deployment["access_groups"] != deployment.access_groups:
@@ -141,9 +145,12 @@ def _load_deployments(self):
141145

142146

143147
if __name__ == "__main__":
148+
import glob
144149

145-
default_path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname((__file__)))))
150+
default_path = os.path.abspath(os.path.dirname(os.path.dirname((__file__))))
146151
loader = DeploymentIngestor({"host": "localhost", "port": 27017})
147-
with open(os.path.join(default_path, "utils/sls_deployments.yaml"), "r") as file:
148-
data = yaml.safe_load(file)
149-
loader.load(data)
152+
realm_files = glob.glob(os.path.join(default_path, "deployment/realms/*.yaml"))
153+
for realm_file in realm_files:
154+
with open(realm_file, "r") as file:
155+
data = yaml.safe_load(file)
156+
loader.load(data)

backend/bec_atlas/utils/bec_atlas_update.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import glob
12
import os
23

34
import typer
@@ -10,19 +11,29 @@
1011

1112

1213
@app.command("deployments")
13-
def update_deployments(file_path: str):
14+
def update_deployments(file_path: str = typer.Argument(None, help="Path to the YAML file")):
1415
"""
1516
Update the available realms and deployments using the provided YAML file.
17+
If no path is specified, the deployment realms are used (deployment/realms/*.yaml)
1618
"""
17-
if not os.path.exists(file_path):
18-
typer.echo(f"File not found: {file_path}")
19-
raise typer.Exit(code=1)
20-
21-
with open(file_path, "r") as f:
22-
data = yaml.safe_load(f)
23-
# Process the YAML data
24-
typer.echo(f"Updating deployments with data from {file_path}")
25-
DeploymentIngestor({"host": "localhost", "port": 27017}).load(data)
19+
if file_path is not None:
20+
if not os.path.exists(file_path):
21+
typer.echo(f"File not found: {file_path}")
22+
raise typer.Exit(code=1)
23+
files = [file_path]
24+
25+
else:
26+
base_path = os.path.abspath(os.path.dirname(os.path.dirname((__file__))))
27+
realm_path = os.path.join(base_path, "deployment/realms/*.yaml")
28+
29+
files = glob.glob(realm_path)
30+
31+
for file in files:
32+
with open(file, "r") as f:
33+
data = yaml.safe_load(f)
34+
# Process the YAML data
35+
typer.echo(f"Updating deployments with data from {file}")
36+
DeploymentIngestor({"host": "localhost", "port": 27017}).load(data)
2637

2738

2839
@app.command("experiments")

0 commit comments

Comments
 (0)