Skip to content

Commit 9da8033

Browse files
feat: DIRAC can associate a pilot with a job
1 parent 77a59b0 commit 9da8033

File tree

17 files changed

+1479
-143
lines changed

17 files changed

+1479
-143
lines changed

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

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
build_jobs_summary_request,
5656
build_jobs_unassign_bulk_jobs_sandboxes_request,
5757
build_jobs_unassign_job_sandboxes_request,
58+
build_pilots_associate_pilot_with_jobs_request,
5859
build_pilots_associate_pilots_with_secrets_request,
5960
build_pilots_create_pilot_secrets_request,
6061
build_pilots_patch_pilot_data_request,
@@ -3202,3 +3203,110 @@ async def update_pilot_fields(
32023203

32033204
if cls:
32043205
return cls(pipeline_response, None, {}) # type: ignore
3206+
3207+
@overload
3208+
async def associate_pilot_with_jobs(
3209+
self,
3210+
body: _models.BodyPilotsAssociatePilotWithJobs,
3211+
*,
3212+
content_type: str = "application/json",
3213+
**kwargs: Any,
3214+
) -> None:
3215+
"""Associate Pilot With Jobs.
3216+
3217+
Associate Pilot With Jobs.
3218+
3219+
:param body: Required.
3220+
:type body: ~_generated.models.BodyPilotsAssociatePilotWithJobs
3221+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
3222+
Default value is "application/json".
3223+
:paramtype content_type: str
3224+
:return: None
3225+
:rtype: None
3226+
:raises ~azure.core.exceptions.HttpResponseError:
3227+
"""
3228+
3229+
@overload
3230+
async def associate_pilot_with_jobs(
3231+
self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
3232+
) -> None:
3233+
"""Associate Pilot With Jobs.
3234+
3235+
Associate Pilot With Jobs.
3236+
3237+
:param body: Required.
3238+
:type body: IO[bytes]
3239+
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
3240+
Default value is "application/json".
3241+
:paramtype content_type: str
3242+
:return: None
3243+
:rtype: None
3244+
:raises ~azure.core.exceptions.HttpResponseError:
3245+
"""
3246+
3247+
@distributed_trace_async
3248+
async def associate_pilot_with_jobs(
3249+
self,
3250+
body: Union[_models.BodyPilotsAssociatePilotWithJobs, IO[bytes]],
3251+
**kwargs: Any,
3252+
) -> None:
3253+
"""Associate Pilot With Jobs.
3254+
3255+
Associate Pilot With Jobs.
3256+
3257+
:param body: Is either a BodyPilotsAssociatePilotWithJobs type or a IO[bytes] type. Required.
3258+
:type body: ~_generated.models.BodyPilotsAssociatePilotWithJobs or IO[bytes]
3259+
:return: None
3260+
:rtype: None
3261+
:raises ~azure.core.exceptions.HttpResponseError:
3262+
"""
3263+
error_map: MutableMapping = {
3264+
401: ClientAuthenticationError,
3265+
404: ResourceNotFoundError,
3266+
409: ResourceExistsError,
3267+
304: ResourceNotModifiedError,
3268+
}
3269+
error_map.update(kwargs.pop("error_map", {}) or {})
3270+
3271+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
3272+
_params = kwargs.pop("params", {}) or {}
3273+
3274+
content_type: Optional[str] = kwargs.pop(
3275+
"content_type", _headers.pop("Content-Type", None)
3276+
)
3277+
cls: ClsType[None] = kwargs.pop("cls", None)
3278+
3279+
content_type = content_type or "application/json"
3280+
_json = None
3281+
_content = None
3282+
if isinstance(body, (IOBase, bytes)):
3283+
_content = body
3284+
else:
3285+
_json = self._serialize.body(body, "BodyPilotsAssociatePilotWithJobs")
3286+
3287+
_request = build_pilots_associate_pilot_with_jobs_request(
3288+
content_type=content_type,
3289+
json=_json,
3290+
content=_content,
3291+
headers=_headers,
3292+
params=_params,
3293+
)
3294+
_request.url = self._client.format_url(_request.url)
3295+
3296+
_stream = False
3297+
pipeline_response: PipelineResponse = (
3298+
await self._client._pipeline.run( # pylint: disable=protected-access
3299+
_request, stream=_stream, **kwargs
3300+
)
3301+
)
3302+
3303+
response = pipeline_response.http_response
3304+
3305+
if response.status_code not in [204]:
3306+
map_error(
3307+
status_code=response.status_code, response=response, error_map=error_map
3308+
)
3309+
raise HttpResponseError(response=response)
3310+
3311+
if cls:
3312+
return cls(pipeline_response, None, {}) # type: ignore

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
BodyAuthGetOidcTokenGrantType,
1717
BodyAuthPilotLogin,
1818
BodyAuthRefreshPilotTokens,
19+
BodyPilotsAssociatePilotWithJobs,
1920
BodyPilotsAssociatePilotsWithSecrets,
2021
BodyPilotsCreatePilotSecrets,
2122
BodyPilotsRegisterNewPilotsToDb,
@@ -74,6 +75,7 @@
7475
"BodyAuthGetOidcTokenGrantType",
7576
"BodyAuthPilotLogin",
7677
"BodyAuthRefreshPilotTokens",
78+
"BodyPilotsAssociatePilotWithJobs",
7779
"BodyPilotsAssociatePilotsWithSecrets",
7880
"BodyPilotsCreatePilotSecrets",
7981
"BodyPilotsRegisterNewPilotsToDb",

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,41 @@ def __init__(
190190
self.pilot_secrets = pilot_secrets
191191

192192

193+
class BodyPilotsAssociatePilotWithJobs(_serialization.Model):
194+
"""Body_pilots_associate_pilot_with_jobs.
195+
196+
All required parameters must be populated in order to send to server.
197+
198+
:ivar pilot_stamp: The stamp of the pilot. Required.
199+
:vartype pilot_stamp: str
200+
:ivar pilot_jobs_ids: The jobs we want to add to the pilot. Required.
201+
:vartype pilot_jobs_ids: list[int]
202+
"""
203+
204+
_validation = {
205+
"pilot_stamp": {"required": True},
206+
"pilot_jobs_ids": {"required": True},
207+
}
208+
209+
_attribute_map = {
210+
"pilot_stamp": {"key": "pilot_stamp", "type": "str"},
211+
"pilot_jobs_ids": {"key": "pilot_jobs_ids", "type": "[int]"},
212+
}
213+
214+
def __init__(
215+
self, *, pilot_stamp: str, pilot_jobs_ids: List[int], **kwargs: Any
216+
) -> None:
217+
"""
218+
:keyword pilot_stamp: The stamp of the pilot. Required.
219+
:paramtype pilot_stamp: str
220+
:keyword pilot_jobs_ids: The jobs we want to add to the pilot. Required.
221+
:paramtype pilot_jobs_ids: list[int]
222+
"""
223+
super().__init__(**kwargs)
224+
self.pilot_stamp = pilot_stamp
225+
self.pilot_jobs_ids = pilot_jobs_ids
226+
227+
193228
class BodyPilotsCreatePilotSecrets(_serialization.Model):
194229
"""Body_pilots_create_pilot_secrets.
195230

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

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,26 @@ def build_pilots_update_pilot_fields_request(**kwargs: Any) -> HttpRequest:
824824
return HttpRequest(method="PATCH", url=_url, headers=_headers, **kwargs)
825825

826826

827+
def build_pilots_associate_pilot_with_jobs_request(
828+
**kwargs: Any,
829+
) -> HttpRequest: # pylint: disable=name-too-long
830+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
831+
832+
content_type: Optional[str] = kwargs.pop(
833+
"content_type", _headers.pop("Content-Type", None)
834+
)
835+
# Construct URL
836+
_url = "/api/pilots/fields/jobs"
837+
838+
# Construct headers
839+
if content_type is not None:
840+
_headers["Content-Type"] = _SERIALIZER.header(
841+
"content_type", content_type, "str"
842+
)
843+
844+
return HttpRequest(method="PATCH", url=_url, headers=_headers, **kwargs)
845+
846+
827847
class WellKnownOperations:
828848
"""
829849
.. warning::
@@ -3385,7 +3405,7 @@ class PilotsOperations:
33853405

33863406
models = _models
33873407

3388-
def __init__(self, *args, **kwargs):
3408+
def __init__(self, *args, **kwargs) -> None:
33893409
input_args = list(args)
33903410
self._client: PipelineClient = (
33913411
input_args.pop(0) if input_args else kwargs.pop("client")
@@ -3950,3 +3970,110 @@ def update_pilot_fields( # pylint: disable=inconsistent-return-statements
39503970

39513971
if cls:
39523972
return cls(pipeline_response, None, {}) # type: ignore
3973+
3974+
@overload
3975+
def associate_pilot_with_jobs(
3976+
self,
3977+
body: _models.BodyPilotsAssociatePilotWithJobs,
3978+
*,
3979+
content_type: str = "application/json",
3980+
**kwargs: Any,
3981+
) -> None:
3982+
"""Associate Pilot With Jobs.
3983+
3984+
Associate Pilot With Jobs.
3985+
3986+
:param body: Required.
3987+
:type body: ~_generated.models.BodyPilotsAssociatePilotWithJobs
3988+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
3989+
Default value is "application/json".
3990+
:paramtype content_type: str
3991+
:return: None
3992+
:rtype: None
3993+
:raises ~azure.core.exceptions.HttpResponseError:
3994+
"""
3995+
3996+
@overload
3997+
def associate_pilot_with_jobs(
3998+
self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any
3999+
) -> None:
4000+
"""Associate Pilot With Jobs.
4001+
4002+
Associate Pilot With Jobs.
4003+
4004+
:param body: Required.
4005+
:type body: IO[bytes]
4006+
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
4007+
Default value is "application/json".
4008+
:paramtype content_type: str
4009+
:return: None
4010+
:rtype: None
4011+
:raises ~azure.core.exceptions.HttpResponseError:
4012+
"""
4013+
4014+
@distributed_trace
4015+
def associate_pilot_with_jobs( # pylint: disable=inconsistent-return-statements
4016+
self,
4017+
body: Union[_models.BodyPilotsAssociatePilotWithJobs, IO[bytes]],
4018+
**kwargs: Any,
4019+
) -> None:
4020+
"""Associate Pilot With Jobs.
4021+
4022+
Associate Pilot With Jobs.
4023+
4024+
:param body: Is either a BodyPilotsAssociatePilotWithJobs type or a IO[bytes] type. Required.
4025+
:type body: ~_generated.models.BodyPilotsAssociatePilotWithJobs or IO[bytes]
4026+
:return: None
4027+
:rtype: None
4028+
:raises ~azure.core.exceptions.HttpResponseError:
4029+
"""
4030+
error_map: MutableMapping = {
4031+
401: ClientAuthenticationError,
4032+
404: ResourceNotFoundError,
4033+
409: ResourceExistsError,
4034+
304: ResourceNotModifiedError,
4035+
}
4036+
error_map.update(kwargs.pop("error_map", {}) or {})
4037+
4038+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
4039+
_params = kwargs.pop("params", {}) or {}
4040+
4041+
content_type: Optional[str] = kwargs.pop(
4042+
"content_type", _headers.pop("Content-Type", None)
4043+
)
4044+
cls: ClsType[None] = kwargs.pop("cls", None)
4045+
4046+
content_type = content_type or "application/json"
4047+
_json = None
4048+
_content = None
4049+
if isinstance(body, (IOBase, bytes)):
4050+
_content = body
4051+
else:
4052+
_json = self._serialize.body(body, "BodyPilotsAssociatePilotWithJobs")
4053+
4054+
_request = build_pilots_associate_pilot_with_jobs_request(
4055+
content_type=content_type,
4056+
json=_json,
4057+
content=_content,
4058+
headers=_headers,
4059+
params=_params,
4060+
)
4061+
_request.url = self._client.format_url(_request.url)
4062+
4063+
_stream = False
4064+
pipeline_response: PipelineResponse = (
4065+
self._client._pipeline.run( # pylint: disable=protected-access
4066+
_request, stream=_stream, **kwargs
4067+
)
4068+
)
4069+
4070+
response = pipeline_response.http_response
4071+
4072+
if response.status_code not in [204]:
4073+
map_error(
4074+
status_code=response.status_code, response=response, error_map=error_map
4075+
)
4076+
raise HttpResponseError(response=response)
4077+
4078+
if cls:
4079+
return cls(pipeline_response, None, {}) # type: ignore

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,13 @@ class SecretHasExpiredError(GenericError):
165165
class SecretAlreadyExistsError(GenericError):
166166
head = "Secret"
167167
tail = "already exists"
168+
169+
170+
class PilotJobsNotFoundError(GenericError):
171+
head = "Pilots or Jobs"
172+
tail = "not found"
173+
174+
175+
class PilotAlreadyAssociatedWithJobError(GenericError):
176+
head = "Pilot is already associated with a job"
177+
tail = ""

0 commit comments

Comments
 (0)