Skip to content

Commit f5f434b

Browse files
doc: Add doc to present what are pilots and their endpoints
1 parent a70b4b4 commit f5f434b

File tree

5 files changed

+31
-42
lines changed

5 files changed

+31
-42
lines changed

diracx-core/src/diracx/core/exceptions.py

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -102,42 +102,11 @@ def __init__(self, job_id, detail: str = ""):
102102
class NotReadyError(DiracError):
103103
"""Tried to access a value which is asynchronously loaded but not yet available."""
104104

105+
class PilotNotFoundError(DiracError):
106+
"""At least one pilot is not found"""
105107

106-
class DiracFormattedError(DiracError):
107-
# TODO: Refactor?
108-
pattern = "Error %s"
108+
class PilotAlreadyExistsError(DiracError):
109+
"""At least one pilot already exists, we avoid collitions."""
109110

110-
def __init__(self, data: dict[str, str], detail: str = ""):
111-
self.data = data
112-
113-
parts = [f"({key}: {value})" for key, value in data.items()]
114-
message = type(self).pattern % (" ".join(parts))
115-
if detail:
116-
message += f": {detail}"
117-
118-
super().__init__(message)
119-
120-
121-
class PilotNotFoundError(DiracFormattedError):
122-
pattern = "Pilot %s not found"
123-
124-
def __init__(
125-
self,
126-
data: dict[str, str],
127-
detail: str = "",
128-
non_existing_pilots: set = set(),
129-
):
130-
super().__init__(data, detail)
131-
self.non_existing_pilots = non_existing_pilots
132-
133-
134-
class PilotAlreadyExistsError(DiracFormattedError):
135-
pattern = "Pilot %s already exists"
136-
137-
138-
class PilotJobsNotFoundError(DiracFormattedError):
139-
pattern = "Pilots or Jobs %s not found"
140-
141-
142-
class PilotAlreadyAssociatedWithJobError(DiracFormattedError):
143-
pattern = "Pilot is already associated with a job %s "
111+
class PilotAlreadyAssociatedWithJobError(DiracError):
112+
"""We can't associate a pilot with the same job twice."""

diracx-db/src/diracx/db/sql/pilots/db.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ async def add_jobs_to_pilot(self, job_to_pilot_mapping: list[dict[str, Any]]):
102102
except IntegrityError as e:
103103
if "foreign key" in str(e.orig).lower():
104104
raise PilotNotFoundError(
105-
data={"pilot_stamps": str(job_to_pilot_mapping)},
106105
detail="at least one of these pilots do not exist",
107106
) from e
108107

@@ -111,7 +110,7 @@ async def add_jobs_to_pilot(self, job_to_pilot_mapping: list[dict[str, Any]]):
111110
or "unique constraint" in str(e.orig).lower()
112111
):
113112
raise PilotAlreadyAssociatedWithJobError(
114-
data={"job_to_pilot_mapping": str(job_to_pilot_mapping)}
113+
detail="at least one of these pilots is already associated with a given job."
115114
) from e
116115

117116
# Other errors to catch
@@ -194,7 +193,7 @@ async def update_pilot_fields(
194193

195194
if res.rowcount != len(pilot_stamps_to_fields_mapping):
196195
raise PilotNotFoundError(
197-
data={"mapping": str(pilot_stamps_to_fields_mapping)}
196+
"at least one of the given pilot does not exist."
198197
)
199198

200199
# ----------------------------- Search Functions -----------------------------

diracx-logic/src/diracx/logic/pilots/management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def register_new_pilots(
3434
if len(existing_pilots) > 0:
3535
found_keys = {pilot["PilotStamp"] for pilot in existing_pilots}
3636

37-
raise PilotAlreadyExistsError(data={"pilot_stamps": str(found_keys)})
37+
raise PilotAlreadyExistsError(f"The following pilots already exist: {found_keys}")
3838

3939
await pilot_db.add_pilots(
4040
pilot_stamps=pilot_stamps,

diracx-routers/tests/pilots/test_pilot_creation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def test_create_pilots(normal_test_client):
6868
assert r.status_code == 409
6969
assert (
7070
r.json()["detail"]
71-
== f"Pilot (pilot_stamps: {{'{pilot_stamps[0]}'}}) already exists"
71+
== f"The following pilots already exist: {{'{pilot_stamps[0]}'}}"
7272
)
7373

7474
# -------------- Register a pilot that does not exists **but** was called before in an error --------------

docs/dev/explanations/pilots.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Presentation
2+
3+
Pilots are a piece of software that is running on *worker nodes*. There are two types of pilots: "DIRAC pilots", and "DiracX pilots". The first type corresponds to pilots with proxies, sent by DIRAC; and the second type corresponds to pilots with secrets. Both kinds will eventually interact with DiracX using tokens (DIRAC pilots by exchanging their proxies for tokens, DiracX by exchanging their secrets for tokens).
4+
5+
## Management
6+
7+
Their management is adapted in DiracX, and each feature has its own route in DiracX. We will split the `/pilots` route into two parts:
8+
9+
1. `/api/pilots/*` to allow administrators and users to access and modify pilots
10+
2. `/api/pilots/internal/*` is allocated for pilots resources: only DiracX pilots will have access to these resources
11+
12+
Each part has its own security policy: we want to prevent pilots to access users resources and vice-versa. To differenciate DIRAC pilots from users, we can get their token and compare their properties: `GENERIC_PILOT` is the property that defines a pilot. For DiracX pilots, we can differenciate them by looking at the token structure: they don't have properties, but a "stamp" (their identifier).
13+
14+
## Endpoints
15+
16+
We ordered our endpoints like so:
17+
18+
1. Creation: `POST /api/pilots/`
19+
2. Deletion: `DELETE /api/pilots/`
20+
3. Modification: `PATCH /api/pilots/metadata`
21+

0 commit comments

Comments
 (0)