Skip to content

Commit 60fb4e6

Browse files
refactor: Refactored delete pilot endpoints
1 parent 76381b2 commit 60fb4e6

File tree

7 files changed

+319
-163
lines changed

7 files changed

+319
-163
lines changed

diracx-client/src/diracx/client/_generated/aio/operations/_operations.py

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
build_jobs_unassign_job_sandboxes_request,
5656
build_pilots_add_jobs_to_pilot_request,
5757
build_pilots_add_pilot_stamps_request,
58-
build_pilots_clear_pilots_request,
5958
build_pilots_delete_pilots_request,
59+
build_pilots_get_pilot_jobs_request,
6060
build_pilots_search_request,
6161
build_pilots_update_pilot_fields_request,
6262
build_well_known_get_installation_metadata_request,
@@ -2294,15 +2294,36 @@ async def add_pilot_stamps(self, body: Union[_models.BodyPilotsAddPilotStamps, I
22942294
return deserialized # type: ignore
22952295

22962296
@distributed_trace_async
2297-
async def delete_pilots(self, *, pilot_stamps: List[str], **kwargs: Any) -> None:
2297+
async def delete_pilots(
2298+
self,
2299+
*,
2300+
pilot_stamps: Optional[List[str]] = None,
2301+
age_in_days: Optional[int] = None,
2302+
delete_only_aborted: bool = False,
2303+
**kwargs: Any
2304+
) -> None:
22982305
"""Delete Pilots.
22992306
23002307
Endpoint to delete a pilot.
23012308
2302-
If at least one pilot is not found, it WILL rollback.
2309+
Two features:
2310+
23032311
2304-
:keyword pilot_stamps: Stamps of the pilots we want to delete. Required.
2312+
#. Or you provide pilot_stamps, so you can delete pilots by their stamp
2313+
#. Or you provide age_in_days, so you can delete pilots that lived more than age_in_days days.
2314+
2315+
If deleting by stamps, if at least one pilot is not found, it WILL rollback.
2316+
2317+
:keyword pilot_stamps: Stamps of the pilots we want to delete. Default value is None.
23052318
:paramtype pilot_stamps: list[str]
2319+
:keyword age_in_days: The number of days that define the maximum age of pilots to be
2320+
deleted.Pilots older than this age will be considered for deletion. Default value is None.
2321+
:paramtype age_in_days: int
2322+
:keyword delete_only_aborted: Flag indicating whether to only delete pilots whose status is
2323+
'Aborted'.If set to True, only pilots with the 'Aborted' status will be deleted.It is set by
2324+
default as True to avoid any mistake.This flag is only used for deletion by time. Default value
2325+
is False.
2326+
:paramtype delete_only_aborted: bool
23062327
:return: None
23072328
:rtype: None
23082329
:raises ~azure.core.exceptions.HttpResponseError:
@@ -2322,6 +2343,8 @@ async def delete_pilots(self, *, pilot_stamps: List[str], **kwargs: Any) -> None
23222343

23232344
_request = build_pilots_delete_pilots_request(
23242345
pilot_stamps=pilot_stamps,
2346+
age_in_days=age_in_days,
2347+
delete_only_aborted=delete_only_aborted,
23252348
headers=_headers,
23262349
params=_params,
23272350
)
@@ -2443,20 +2466,15 @@ async def update_pilot_fields(
24432466
return cls(pipeline_response, None, {}) # type: ignore
24442467

24452468
@distributed_trace_async
2446-
async def clear_pilots(self, *, age_in_days: int, delete_only_aborted: bool = False, **kwargs: Any) -> None:
2447-
"""Clear Pilots.
2469+
async def get_pilot_jobs(self, body: str, **kwargs: Any) -> List[int]:
2470+
"""Get Pilot Jobs.
24482471
2449-
Endpoint for DIRAC to delete all pilots that lived more than age_in_days.
2472+
Endpoint only for DIRAC services, to get jobs of a pilot.
24502473
2451-
:keyword age_in_days: The number of days that define the maximum age of pilots to be
2452-
deleted.Pilots older than this age will be considered for deletion. Required.
2453-
:paramtype age_in_days: int
2454-
:keyword delete_only_aborted: Flag indicating whether to only delete pilots whose status is
2455-
'Aborted'.If set to True, only pilots with the 'Aborted' status will be deleted.It is set by
2456-
default as True to avoid any mistake. Default value is False.
2457-
:paramtype delete_only_aborted: bool
2458-
:return: None
2459-
:rtype: None
2474+
:param body: Required.
2475+
:type body: str
2476+
:return: list of int
2477+
:rtype: list[int]
24602478
:raises ~azure.core.exceptions.HttpResponseError:
24612479
"""
24622480
error_map: MutableMapping = {
@@ -2467,14 +2485,17 @@ async def clear_pilots(self, *, age_in_days: int, delete_only_aborted: bool = Fa
24672485
}
24682486
error_map.update(kwargs.pop("error_map", {}) or {})
24692487

2470-
_headers = kwargs.pop("headers", {}) or {}
2488+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
24712489
_params = kwargs.pop("params", {}) or {}
24722490

2473-
cls: ClsType[None] = kwargs.pop("cls", None)
2491+
content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json"))
2492+
cls: ClsType[List[int]] = kwargs.pop("cls", None)
24742493

2475-
_request = build_pilots_clear_pilots_request(
2476-
age_in_days=age_in_days,
2477-
delete_only_aborted=delete_only_aborted,
2494+
_content = self._serialize.body(body, "str")
2495+
2496+
_request = build_pilots_get_pilot_jobs_request(
2497+
content_type=content_type,
2498+
content=_content,
24782499
headers=_headers,
24792500
params=_params,
24802501
)
@@ -2487,12 +2508,16 @@ async def clear_pilots(self, *, age_in_days: int, delete_only_aborted: bool = Fa
24872508

24882509
response = pipeline_response.http_response
24892510

2490-
if response.status_code not in [204]:
2511+
if response.status_code not in [200]:
24912512
map_error(status_code=response.status_code, response=response, error_map=error_map)
24922513
raise HttpResponseError(response=response)
24932514

2515+
deserialized = self._deserialize("[int]", pipeline_response.http_response)
2516+
24942517
if cls:
2495-
return cls(pipeline_response, None, {}) # type: ignore
2518+
return cls(pipeline_response, deserialized, {}) # type: ignore
2519+
2520+
return deserialized # type: ignore
24962521

24972522
@overload
24982523
async def add_jobs_to_pilot(

diracx-client/src/diracx/client/_generated/models/_models.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,14 @@ class BodyPilotsAddPilotStamps(_serialization.Model):
138138
:vartype vo: str
139139
:ivar grid_type: Grid type of the pilots.
140140
:vartype grid_type: str
141+
:ivar grid_site: Pilots grid site.
142+
:vartype grid_site: str
143+
:ivar destination_site: Pilots destination site.
144+
:vartype destination_site: str
141145
:ivar pilot_references: Association of a pilot reference with a pilot stamp.
142146
:vartype pilot_references: dict[str, str]
147+
:ivar status_reason: Status reason of the pilots.
148+
:vartype status_reason: str
143149
"""
144150

145151
_validation = {
@@ -151,7 +157,10 @@ class BodyPilotsAddPilotStamps(_serialization.Model):
151157
"pilot_stamps": {"key": "pilot_stamps", "type": "[str]"},
152158
"vo": {"key": "vo", "type": "str"},
153159
"grid_type": {"key": "grid_type", "type": "str"},
160+
"grid_site": {"key": "grid_site", "type": "str"},
161+
"destination_site": {"key": "destination_site", "type": "str"},
154162
"pilot_references": {"key": "pilot_references", "type": "{str}"},
163+
"status_reason": {"key": "status_reason", "type": "str"},
155164
}
156165

157166
def __init__(
@@ -160,7 +169,10 @@ def __init__(
160169
pilot_stamps: List[str],
161170
vo: str,
162171
grid_type: str = "Dirac",
172+
grid_site: str = "Unknown",
173+
destination_site: str = "NotAssigned",
163174
pilot_references: Optional[Dict[str, str]] = None,
175+
status_reason: str = "Unknown",
164176
**kwargs: Any
165177
) -> None:
166178
"""
@@ -170,14 +182,23 @@ def __init__(
170182
:paramtype vo: str
171183
:keyword grid_type: Grid type of the pilots.
172184
:paramtype grid_type: str
185+
:keyword grid_site: Pilots grid site.
186+
:paramtype grid_site: str
187+
:keyword destination_site: Pilots destination site.
188+
:paramtype destination_site: str
173189
:keyword pilot_references: Association of a pilot reference with a pilot stamp.
174190
:paramtype pilot_references: dict[str, str]
191+
:keyword status_reason: Status reason of the pilots.
192+
:paramtype status_reason: str
175193
"""
176194
super().__init__(**kwargs)
177195
self.pilot_stamps = pilot_stamps
178196
self.vo = vo
179197
self.grid_type = grid_type
198+
self.grid_site = grid_site
199+
self.destination_site = destination_site
180200
self.pilot_references = pilot_references
201+
self.status_reason = status_reason
181202

182203

183204
class BodyPilotsUpdatePilotFields(_serialization.Model):

diracx-client/src/diracx/client/_generated/operations/_operations.py

Lines changed: 73 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def build_pilots_add_pilot_stamps_request(**kwargs: Any) -> HttpRequest:
601601
accept = _headers.pop("Accept", "application/json")
602602

603603
# Construct URL
604-
_url = "/api/pilots/management/pilot"
604+
_url = "/api/pilots/"
605605

606606
# Construct headers
607607
if content_type is not None:
@@ -611,14 +611,25 @@ def build_pilots_add_pilot_stamps_request(**kwargs: Any) -> HttpRequest:
611611
return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs)
612612

613613

614-
def build_pilots_delete_pilots_request(*, pilot_stamps: List[str], **kwargs: Any) -> HttpRequest:
614+
def build_pilots_delete_pilots_request(
615+
*,
616+
pilot_stamps: Optional[List[str]] = None,
617+
age_in_days: Optional[int] = None,
618+
delete_only_aborted: bool = False,
619+
**kwargs: Any
620+
) -> HttpRequest:
615621
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
616622

617623
# Construct URL
618-
_url = "/api/pilots/management/pilot"
624+
_url = "/api/pilots/"
619625

620626
# Construct parameters
621-
_params["pilot_stamps"] = _SERIALIZER.query("pilot_stamps", pilot_stamps, "[str]")
627+
if pilot_stamps is not None:
628+
_params["pilot_stamps"] = _SERIALIZER.query("pilot_stamps", pilot_stamps, "[str]")
629+
if age_in_days is not None:
630+
_params["age_in_days"] = _SERIALIZER.query("age_in_days", age_in_days, "int")
631+
if delete_only_aborted is not None:
632+
_params["delete_only_aborted"] = _SERIALIZER.query("delete_only_aborted", delete_only_aborted, "bool")
622633

623634
return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs)
624635

@@ -628,7 +639,7 @@ def build_pilots_update_pilot_fields_request(**kwargs: Any) -> HttpRequest:
628639

629640
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
630641
# Construct URL
631-
_url = "/api/pilots/management/pilot"
642+
_url = "/api/pilots/metadata"
632643

633644
# Construct headers
634645
if content_type is not None:
@@ -637,28 +648,29 @@ def build_pilots_update_pilot_fields_request(**kwargs: Any) -> HttpRequest:
637648
return HttpRequest(method="PATCH", url=_url, headers=_headers, **kwargs)
638649

639650

640-
def build_pilots_clear_pilots_request(
641-
*, age_in_days: int, delete_only_aborted: bool = False, **kwargs: Any
642-
) -> HttpRequest:
643-
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})
651+
def build_pilots_get_pilot_jobs_request(*, content: str, **kwargs: Any) -> HttpRequest:
652+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
653+
654+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
655+
accept = _headers.pop("Accept", "application/json")
644656

645657
# Construct URL
646-
_url = "/api/pilots/management/pilot/interval"
658+
_url = "/api/pilots/jobs"
647659

648-
# Construct parameters
649-
_params["age_in_days"] = _SERIALIZER.query("age_in_days", age_in_days, "int")
650-
if delete_only_aborted is not None:
651-
_params["delete_only_aborted"] = _SERIALIZER.query("delete_only_aborted", delete_only_aborted, "bool")
660+
# Construct headers
661+
if content_type is not None:
662+
_headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str")
663+
_headers["Accept"] = _SERIALIZER.header("accept", accept, "str")
652664

653-
return HttpRequest(method="DELETE", url=_url, params=_params, **kwargs)
665+
return HttpRequest(method="GET", url=_url, headers=_headers, content=content, **kwargs)
654666

655667

656668
def build_pilots_add_jobs_to_pilot_request(**kwargs: Any) -> HttpRequest:
657669
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
658670

659671
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
660672
# Construct URL
661-
_url = "/api/pilots/management/jobs"
673+
_url = "/api/pilots/jobs"
662674

663675
# Construct headers
664676
if content_type is not None:
@@ -2913,16 +2925,35 @@ def add_pilot_stamps(self, body: Union[_models.BodyPilotsAddPilotStamps, IO[byte
29132925

29142926
@distributed_trace
29152927
def delete_pilots( # pylint: disable=inconsistent-return-statements
2916-
self, *, pilot_stamps: List[str], **kwargs: Any
2928+
self,
2929+
*,
2930+
pilot_stamps: Optional[List[str]] = None,
2931+
age_in_days: Optional[int] = None,
2932+
delete_only_aborted: bool = False,
2933+
**kwargs: Any
29172934
) -> None:
29182935
"""Delete Pilots.
29192936
29202937
Endpoint to delete a pilot.
29212938
2922-
If at least one pilot is not found, it WILL rollback.
2939+
Two features:
2940+
29232941
2924-
:keyword pilot_stamps: Stamps of the pilots we want to delete. Required.
2942+
#. Or you provide pilot_stamps, so you can delete pilots by their stamp
2943+
#. Or you provide age_in_days, so you can delete pilots that lived more than age_in_days days.
2944+
2945+
If deleting by stamps, if at least one pilot is not found, it WILL rollback.
2946+
2947+
:keyword pilot_stamps: Stamps of the pilots we want to delete. Default value is None.
29252948
:paramtype pilot_stamps: list[str]
2949+
:keyword age_in_days: The number of days that define the maximum age of pilots to be
2950+
deleted.Pilots older than this age will be considered for deletion. Default value is None.
2951+
:paramtype age_in_days: int
2952+
:keyword delete_only_aborted: Flag indicating whether to only delete pilots whose status is
2953+
'Aborted'.If set to True, only pilots with the 'Aborted' status will be deleted.It is set by
2954+
default as True to avoid any mistake.This flag is only used for deletion by time. Default value
2955+
is False.
2956+
:paramtype delete_only_aborted: bool
29262957
:return: None
29272958
:rtype: None
29282959
:raises ~azure.core.exceptions.HttpResponseError:
@@ -2942,6 +2973,8 @@ def delete_pilots( # pylint: disable=inconsistent-return-statements
29422973

29432974
_request = build_pilots_delete_pilots_request(
29442975
pilot_stamps=pilot_stamps,
2976+
age_in_days=age_in_days,
2977+
delete_only_aborted=delete_only_aborted,
29452978
headers=_headers,
29462979
params=_params,
29472980
)
@@ -3061,22 +3094,15 @@ def update_pilot_fields( # pylint: disable=inconsistent-return-statements
30613094
return cls(pipeline_response, None, {}) # type: ignore
30623095

30633096
@distributed_trace
3064-
def clear_pilots( # pylint: disable=inconsistent-return-statements
3065-
self, *, age_in_days: int, delete_only_aborted: bool = False, **kwargs: Any
3066-
) -> None:
3067-
"""Clear Pilots.
3097+
def get_pilot_jobs(self, body: str, **kwargs: Any) -> List[int]:
3098+
"""Get Pilot Jobs.
30683099
3069-
Endpoint for DIRAC to delete all pilots that lived more than age_in_days.
3100+
Endpoint only for DIRAC services, to get jobs of a pilot.
30703101
3071-
:keyword age_in_days: The number of days that define the maximum age of pilots to be
3072-
deleted.Pilots older than this age will be considered for deletion. Required.
3073-
:paramtype age_in_days: int
3074-
:keyword delete_only_aborted: Flag indicating whether to only delete pilots whose status is
3075-
'Aborted'.If set to True, only pilots with the 'Aborted' status will be deleted.It is set by
3076-
default as True to avoid any mistake. Default value is False.
3077-
:paramtype delete_only_aborted: bool
3078-
:return: None
3079-
:rtype: None
3102+
:param body: Required.
3103+
:type body: str
3104+
:return: list of int
3105+
:rtype: list[int]
30803106
:raises ~azure.core.exceptions.HttpResponseError:
30813107
"""
30823108
error_map: MutableMapping = {
@@ -3087,14 +3113,17 @@ def clear_pilots( # pylint: disable=inconsistent-return-statements
30873113
}
30883114
error_map.update(kwargs.pop("error_map", {}) or {})
30893115

3090-
_headers = kwargs.pop("headers", {}) or {}
3116+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
30913117
_params = kwargs.pop("params", {}) or {}
30923118

3093-
cls: ClsType[None] = kwargs.pop("cls", None)
3119+
content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json"))
3120+
cls: ClsType[List[int]] = kwargs.pop("cls", None)
30943121

3095-
_request = build_pilots_clear_pilots_request(
3096-
age_in_days=age_in_days,
3097-
delete_only_aborted=delete_only_aborted,
3122+
_content = self._serialize.body(body, "str")
3123+
3124+
_request = build_pilots_get_pilot_jobs_request(
3125+
content_type=content_type,
3126+
content=_content,
30983127
headers=_headers,
30993128
params=_params,
31003129
)
@@ -3107,12 +3136,16 @@ def clear_pilots( # pylint: disable=inconsistent-return-statements
31073136

31083137
response = pipeline_response.http_response
31093138

3110-
if response.status_code not in [204]:
3139+
if response.status_code not in [200]:
31113140
map_error(status_code=response.status_code, response=response, error_map=error_map)
31123141
raise HttpResponseError(response=response)
31133142

3143+
deserialized = self._deserialize("[int]", pipeline_response.http_response)
3144+
31143145
if cls:
3115-
return cls(pipeline_response, None, {}) # type: ignore
3146+
return cls(pipeline_response, deserialized, {}) # type: ignore
3147+
3148+
return deserialized # type: ignore
31163149

31173150
@overload
31183151
def add_jobs_to_pilot(

0 commit comments

Comments
 (0)