2121# SOFTWARE.
2222"""Module containing the admin service implementation for v1."""
2323
24+ import warnings
25+
2426import grpc
27+ import semver
2528
2629from ansys .geometry .core .errors import protect_grpc
2730
2831from ..base .admin import GRPCAdminService
32+ from .conversions import from_grpc_backend_type_to_backend_type
2933
3034
3135class GRPCAdminServiceV1 (GRPCAdminService ): # pragma: no cover
@@ -43,18 +47,83 @@ class GRPCAdminServiceV1(GRPCAdminService): # pragma: no cover
4347
4448 @protect_grpc
4549 def __init__ (self , channel : grpc .Channel ): # noqa: D102
46- from ansys .api .dbu .v1 .admin_pb2_grpc import AdminStub
50+ from ansys .api .discovery .v1 .commands .application_pb2_grpc import ApplicationStub
51+ from ansys .api .discovery .v1 .commands .communication_pb2_grpc import CommunicationStub
4752
48- self .stub = AdminStub (channel )
53+ self .admin_stub = ApplicationStub (channel )
54+ self .communication_stub = CommunicationStub (channel )
4955
5056 @protect_grpc
5157 def get_backend (self , ** kwargs ) -> dict : # noqa: D102
52- raise NotImplementedError
58+ # TODO: Remove this context and filter once the protobuf UserWarning is downgraded to INFO
59+ # https://github.com/grpc/grpc/issues/37609
60+ with warnings .catch_warnings ():
61+ warnings .filterwarnings (
62+ "ignore" , "Protobuf gencode version" , UserWarning , "google.protobuf.runtime_version"
63+ )
64+ from ansys .api .discovery .v1 .commands .application_pb2 import GetBackendRequest
65+
66+ # Create the request - assumes all inputs are valid and of the proper type
67+ request = GetBackendRequest ()
68+
69+ # Call the gRPC service
70+ response = self .admin_stub .GetBackend (request = request )
71+
72+ # COMPATIBILITY HACK: retrieve the backend version -- for versions after 24R1
73+ ver = response .version
74+ backend_version = semver .Version (ver .major_release , ver .minor_release , ver .service_pack )
75+ api_server_build_info = f"{ ver .build_number } " if ver .build_number != 0 else "N/A"
76+ product_build_info = (
77+ response .backend_version_info .strip () if response .backend_version_info else "N/A"
78+ )
79+
80+ # Convert the response to a dictionary
81+ return {
82+ "backend" : from_grpc_backend_type_to_backend_type (response .type ),
83+ "version" : backend_version ,
84+ "api_server_build_info" : api_server_build_info ,
85+ "product_build_info" : product_build_info ,
86+ "additional_info" : {k : v for k , v in response .additional_build_info .items ()},
87+ }
5388
5489 @protect_grpc
5590 def get_logs (self , ** kwargs ) -> dict : # noqa: D102
56- raise NotImplementedError
91+ from ansys .api .discovery .v1 .commands .communication_pb2 import LogsRequest
92+ from ansys .api .discovery .v1 .commonenums_pb2 import LogsPeriodType , LogsTarget
93+
94+ # Create the request - assumes all inputs are valid and of the proper type
95+ request = LogsRequest (
96+ target = LogsTarget .LOGSTARGET_CLIENT ,
97+ period_type = (
98+ LogsPeriodType .LOGSPERIODTIME_CURRENT
99+ if not kwargs ["all_logs" ]
100+ else LogsPeriodType .LOGSPERIODTIME_ALL
101+ ),
102+ null_path = None ,
103+ null_period = None ,
104+ )
105+
106+ # Call the gRPC service
107+ logs_generator = self .communication_stub .GetLogs (request )
108+ logs : dict [str , str ] = {}
109+
110+ # Convert the response to a dictionary
111+ for chunk in logs_generator :
112+ if chunk .log_name not in logs :
113+ logs [chunk .log_name ] = ""
114+ logs [chunk .log_name ] += chunk .log_chunk .decode ()
115+
116+ return {"logs" : logs }
57117
58118 @protect_grpc
59119 def get_service_status (self , ** kwargs ) -> dict : # noqa: D102
60- raise NotImplementedError
120+ from ansys .api .discovery .v1 .commands .communication_pb2 import HealthRequest
121+
122+ # Create the request - assumes all inputs are valid and of the proper type
123+ request = HealthRequest ()
124+
125+ # Call the gRPC service
126+ response = self .communication_stub .Health (request = request )
127+
128+ # Convert the response to a dictionary
129+ return {"healthy" : True if response .message == "I am healthy!" else False }
0 commit comments