Skip to content

Commit bb16569

Browse files
author
Robin VAN DE MERGHEL
committed
feat: POC to have legacy pilots sending logs
1 parent b6360e2 commit bb16569

File tree

25 files changed

+1834
-14
lines changed

25 files changed

+1834
-14
lines changed

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

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
build_pilots_add_pilot_stamps_request,
5757
build_pilots_delete_pilots_request,
5858
build_pilots_get_pilot_jobs_request,
59+
build_pilots_search_logs_request,
5960
build_pilots_search_request,
61+
build_pilots_send_message_request,
6062
build_pilots_summary_request,
6163
build_pilots_update_pilot_fields_request,
6264
build_well_known_get_installation_metadata_request,
@@ -2705,6 +2707,143 @@ async def search(
27052707

27062708
return deserialized # type: ignore
27072709

2710+
@overload
2711+
async def search_logs(
2712+
self,
2713+
body: Optional[_models.SearchParams] = None,
2714+
*,
2715+
page: int = 1,
2716+
per_page: int = 100,
2717+
content_type: str = "application/json",
2718+
**kwargs: Any
2719+
) -> List[Dict[str, Any]]:
2720+
"""Search Logs.
2721+
2722+
Search Logs.
2723+
2724+
:param body: Default value is None.
2725+
:type body: ~_generated.models.SearchParams
2726+
:keyword page: Default value is 1.
2727+
:paramtype page: int
2728+
:keyword per_page: Default value is 100.
2729+
:paramtype per_page: int
2730+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
2731+
Default value is "application/json".
2732+
:paramtype content_type: str
2733+
:return: list of dict mapping str to any
2734+
:rtype: list[dict[str, any]]
2735+
:raises ~azure.core.exceptions.HttpResponseError:
2736+
"""
2737+
2738+
@overload
2739+
async def search_logs(
2740+
self,
2741+
body: Optional[IO[bytes]] = None,
2742+
*,
2743+
page: int = 1,
2744+
per_page: int = 100,
2745+
content_type: str = "application/json",
2746+
**kwargs: Any
2747+
) -> List[Dict[str, Any]]:
2748+
"""Search Logs.
2749+
2750+
Search Logs.
2751+
2752+
:param body: Default value is None.
2753+
:type body: IO[bytes]
2754+
:keyword page: Default value is 1.
2755+
:paramtype page: int
2756+
:keyword per_page: Default value is 100.
2757+
:paramtype per_page: int
2758+
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
2759+
Default value is "application/json".
2760+
:paramtype content_type: str
2761+
:return: list of dict mapping str to any
2762+
:rtype: list[dict[str, any]]
2763+
:raises ~azure.core.exceptions.HttpResponseError:
2764+
"""
2765+
2766+
@distributed_trace_async
2767+
async def search_logs(
2768+
self,
2769+
body: Optional[Union[_models.SearchParams, IO[bytes]]] = None,
2770+
*,
2771+
page: int = 1,
2772+
per_page: int = 100,
2773+
**kwargs: Any
2774+
) -> List[Dict[str, Any]]:
2775+
"""Search Logs.
2776+
2777+
Search Logs.
2778+
2779+
:param body: Is either a SearchParams type or a IO[bytes] type. Default value is None.
2780+
:type body: ~_generated.models.SearchParams or IO[bytes]
2781+
:keyword page: Default value is 1.
2782+
:paramtype page: int
2783+
:keyword per_page: Default value is 100.
2784+
:paramtype per_page: int
2785+
:return: list of dict mapping str to any
2786+
:rtype: list[dict[str, any]]
2787+
:raises ~azure.core.exceptions.HttpResponseError:
2788+
"""
2789+
error_map: MutableMapping = {
2790+
401: ClientAuthenticationError,
2791+
404: ResourceNotFoundError,
2792+
409: ResourceExistsError,
2793+
304: ResourceNotModifiedError,
2794+
}
2795+
error_map.update(kwargs.pop("error_map", {}) or {})
2796+
2797+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
2798+
_params = kwargs.pop("params", {}) or {}
2799+
2800+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
2801+
cls: ClsType[List[Dict[str, Any]]] = kwargs.pop("cls", None)
2802+
2803+
content_type = content_type or "application/json"
2804+
_json = None
2805+
_content = None
2806+
if isinstance(body, (IOBase, bytes)):
2807+
_content = body
2808+
else:
2809+
if body is not None:
2810+
_json = self._serialize.body(body, "SearchParams")
2811+
else:
2812+
_json = None
2813+
2814+
_request = build_pilots_search_logs_request(
2815+
page=page,
2816+
per_page=per_page,
2817+
content_type=content_type,
2818+
json=_json,
2819+
content=_content,
2820+
headers=_headers,
2821+
params=_params,
2822+
)
2823+
_request.url = self._client.format_url(_request.url)
2824+
2825+
_stream = False
2826+
pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
2827+
_request, stream=_stream, **kwargs
2828+
)
2829+
2830+
response = pipeline_response.http_response
2831+
2832+
if response.status_code not in [200, 206]:
2833+
map_error(status_code=response.status_code, response=response, error_map=error_map)
2834+
raise HttpResponseError(response=response)
2835+
2836+
response_headers = {}
2837+
if response.status_code == 206:
2838+
response_headers["Content-Range"] = self._deserialize("str", response.headers.get("Content-Range"))
2839+
2840+
deserialized = self._deserialize("[{object}]", pipeline_response.http_response)
2841+
2842+
if cls:
2843+
return cls(pipeline_response, deserialized, response_headers) # type: ignore
2844+
2845+
return deserialized # type: ignore
2846+
27082847
@overload
27092848
async def summary(
27102849
self, body: _models.SummaryParams, *, content_type: str = "application/json", **kwargs: Any
@@ -2799,3 +2938,94 @@ async def summary(self, body: Union[_models.SummaryParams, IO[bytes]], **kwargs:
27992938
return cls(pipeline_response, deserialized, {}) # type: ignore
28002939

28012940
return deserialized # type: ignore
2941+
2942+
@overload
2943+
async def send_message(
2944+
self, body: _models.BodyPilotsSendMessage, *, content_type: str = "application/json", **kwargs: Any
2945+
) -> None:
2946+
"""Send Message.
2947+
2948+
Send logs with legacy pilot.
2949+
2950+
:param body: Required.
2951+
:type body: ~_generated.models.BodyPilotsSendMessage
2952+
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
2953+
Default value is "application/json".
2954+
:paramtype content_type: str
2955+
:return: None
2956+
:rtype: None
2957+
:raises ~azure.core.exceptions.HttpResponseError:
2958+
"""
2959+
2960+
@overload
2961+
async def send_message(self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any) -> None:
2962+
"""Send Message.
2963+
2964+
Send logs with legacy pilot.
2965+
2966+
:param body: Required.
2967+
:type body: IO[bytes]
2968+
:keyword content_type: Body Parameter content-type. Content type parameter for binary body.
2969+
Default value is "application/json".
2970+
:paramtype content_type: str
2971+
:return: None
2972+
:rtype: None
2973+
:raises ~azure.core.exceptions.HttpResponseError:
2974+
"""
2975+
2976+
@distributed_trace_async
2977+
async def send_message(self, body: Union[_models.BodyPilotsSendMessage, IO[bytes]], **kwargs: Any) -> None:
2978+
"""Send Message.
2979+
2980+
Send logs with legacy pilot.
2981+
2982+
:param body: Is either a BodyPilotsSendMessage type or a IO[bytes] type. Required.
2983+
:type body: ~_generated.models.BodyPilotsSendMessage or IO[bytes]
2984+
:return: None
2985+
:rtype: None
2986+
:raises ~azure.core.exceptions.HttpResponseError:
2987+
"""
2988+
error_map: MutableMapping = {
2989+
401: ClientAuthenticationError,
2990+
404: ResourceNotFoundError,
2991+
409: ResourceExistsError,
2992+
304: ResourceNotModifiedError,
2993+
}
2994+
error_map.update(kwargs.pop("error_map", {}) or {})
2995+
2996+
_headers = case_insensitive_dict(kwargs.pop("headers", {}) or {})
2997+
_params = kwargs.pop("params", {}) or {}
2998+
2999+
content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None))
3000+
cls: ClsType[None] = kwargs.pop("cls", None)
3001+
3002+
content_type = content_type or "application/json"
3003+
_json = None
3004+
_content = None
3005+
if isinstance(body, (IOBase, bytes)):
3006+
_content = body
3007+
else:
3008+
_json = self._serialize.body(body, "BodyPilotsSendMessage")
3009+
3010+
_request = build_pilots_send_message_request(
3011+
content_type=content_type,
3012+
json=_json,
3013+
content=_content,
3014+
headers=_headers,
3015+
params=_params,
3016+
)
3017+
_request.url = self._client.format_url(_request.url)
3018+
3019+
_stream = False
3020+
pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
3021+
_request, stream=_stream, **kwargs
3022+
)
3023+
3024+
response = pipeline_response.http_response
3025+
3026+
if response.status_code not in [204]:
3027+
map_error(status_code=response.status_code, response=response, error_map=error_map)
3028+
raise HttpResponseError(response=response)
3029+
3030+
if cls:
3031+
return cls(pipeline_response, None, {}) # type: ignore

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
BodyAuthGetOidcToken,
1616
BodyAuthGetOidcTokenGrantType,
1717
BodyPilotsAddPilotStamps,
18+
BodyPilotsSendMessage,
1819
BodyPilotsUpdatePilotFields,
1920
GroupInfo,
2021
HTTPValidationError,
@@ -23,6 +24,7 @@
2324
InsertedJob,
2425
JobCommand,
2526
JobStatusUpdate,
27+
LogLine,
2628
Metadata,
2729
OpenIDConfiguration,
2830
PilotFieldsMapping,
@@ -66,6 +68,7 @@
6668
"BodyAuthGetOidcToken",
6769
"BodyAuthGetOidcTokenGrantType",
6870
"BodyPilotsAddPilotStamps",
71+
"BodyPilotsSendMessage",
6972
"BodyPilotsUpdatePilotFields",
7073
"GroupInfo",
7174
"HTTPValidationError",
@@ -74,6 +77,7 @@
7477
"InsertedJob",
7578
"JobCommand",
7679
"JobStatusUpdate",
80+
"LogLine",
7781
"Metadata",
7882
"OpenIDConfiguration",
7983
"PilotFieldsMapping",

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,41 @@ def __init__(
162162
self.pilot_status = pilot_status
163163

164164

165+
class BodyPilotsSendMessage(_serialization.Model):
166+
"""Body_pilots_send_message.
167+
168+
All required parameters must be populated in order to send to server.
169+
170+
:ivar lines: Message from the pilot to the logging system. Required.
171+
:vartype lines: list[~_generated.models.LogLine]
172+
:ivar pilot_stamp: PilotStamp, required as legacy pilots do not have a token with stamp in it.
173+
Required.
174+
:vartype pilot_stamp: str
175+
"""
176+
177+
_validation = {
178+
"lines": {"required": True},
179+
"pilot_stamp": {"required": True},
180+
}
181+
182+
_attribute_map = {
183+
"lines": {"key": "lines", "type": "[LogLine]"},
184+
"pilot_stamp": {"key": "pilot_stamp", "type": "str"},
185+
}
186+
187+
def __init__(self, *, lines: List["_models.LogLine"], pilot_stamp: str, **kwargs: Any) -> None:
188+
"""
189+
:keyword lines: Message from the pilot to the logging system. Required.
190+
:paramtype lines: list[~_generated.models.LogLine]
191+
:keyword pilot_stamp: PilotStamp, required as legacy pilots do not have a token with stamp in
192+
it. Required.
193+
:paramtype pilot_stamp: str
194+
"""
195+
super().__init__(**kwargs)
196+
self.lines = lines
197+
self.pilot_stamp = pilot_stamp
198+
199+
165200
class BodyPilotsUpdatePilotFields(_serialization.Model):
166201
"""Body_pilots_update_pilot_fields.
167202
@@ -503,6 +538,53 @@ def __init__(
503538
self.source = source
504539

505540

541+
class LogLine(_serialization.Model):
542+
"""LogLine.
543+
544+
All required parameters must be populated in order to send to server.
545+
546+
:ivar timestamp: Timestamp. Required.
547+
:vartype timestamp: str
548+
:ivar severity: Severity. Required.
549+
:vartype severity: str
550+
:ivar message: Message. Required.
551+
:vartype message: str
552+
:ivar scope: Scope. Required.
553+
:vartype scope: str
554+
"""
555+
556+
_validation = {
557+
"timestamp": {"required": True},
558+
"severity": {"required": True},
559+
"message": {"required": True},
560+
"scope": {"required": True},
561+
}
562+
563+
_attribute_map = {
564+
"timestamp": {"key": "timestamp", "type": "str"},
565+
"severity": {"key": "severity", "type": "str"},
566+
"message": {"key": "message", "type": "str"},
567+
"scope": {"key": "scope", "type": "str"},
568+
}
569+
570+
def __init__(self, *, timestamp: str, severity: str, message: str, scope: str, **kwargs: Any) -> None:
571+
"""
572+
:keyword timestamp: Timestamp. Required.
573+
:paramtype timestamp: str
574+
:keyword severity: Severity. Required.
575+
:paramtype severity: str
576+
:keyword message: Message. Required.
577+
:paramtype message: str
578+
:keyword scope: Scope. Required.
579+
:paramtype scope: str
580+
"""
581+
super().__init__(**kwargs)
582+
self.timestamp = timestamp
583+
self.severity = severity
584+
self.message = message
585+
self.scope = scope
586+
587+
506588
class Metadata(_serialization.Model):
507589
"""Metadata.
508590

0 commit comments

Comments
 (0)