grpc: removed set/get sessopm options, removed get session metadata/location, can be done with get/start session
This commit is contained in:
parent
d4c008e564
commit
d8a3f9e78c
6 changed files with 2 additions and 265 deletions
|
@ -298,48 +298,6 @@ class CoreGrpcClient:
|
||||||
request = core_pb2.GetSessionRequest(session_id=session_id)
|
request = core_pb2.GetSessionRequest(session_id=session_id)
|
||||||
return self.stub.GetSession(request)
|
return self.stub.GetSession(request)
|
||||||
|
|
||||||
def get_session_options(
|
|
||||||
self, session_id: int
|
|
||||||
) -> core_pb2.GetSessionOptionsResponse:
|
|
||||||
"""
|
|
||||||
Retrieve session options as a dict with id mapping.
|
|
||||||
|
|
||||||
:param session_id: id of session
|
|
||||||
:return: response with a list of configuration groups
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
request = core_pb2.GetSessionOptionsRequest(session_id=session_id)
|
|
||||||
return self.stub.GetSessionOptions(request)
|
|
||||||
|
|
||||||
def set_session_options(
|
|
||||||
self, session_id: int, config: Dict[str, str]
|
|
||||||
) -> core_pb2.SetSessionOptionsResponse:
|
|
||||||
"""
|
|
||||||
Set options for a session.
|
|
||||||
|
|
||||||
:param session_id: id of session
|
|
||||||
:param config: configuration values to set
|
|
||||||
:return: response with result of success or failure
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
request = core_pb2.SetSessionOptionsRequest(
|
|
||||||
session_id=session_id, config=config
|
|
||||||
)
|
|
||||||
return self.stub.SetSessionOptions(request)
|
|
||||||
|
|
||||||
def get_session_metadata(
|
|
||||||
self, session_id: int
|
|
||||||
) -> core_pb2.GetSessionMetadataResponse:
|
|
||||||
"""
|
|
||||||
Retrieve session metadata as a dict with id mapping.
|
|
||||||
|
|
||||||
:param session_id: id of session
|
|
||||||
:return: response with metadata dict
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
request = core_pb2.GetSessionMetadataRequest(session_id=session_id)
|
|
||||||
return self.stub.GetSessionMetadata(request)
|
|
||||||
|
|
||||||
def set_session_metadata(
|
def set_session_metadata(
|
||||||
self, session_id: int, config: Dict[str, str]
|
self, session_id: int, config: Dict[str, str]
|
||||||
) -> core_pb2.SetSessionMetadataResponse:
|
) -> core_pb2.SetSessionMetadataResponse:
|
||||||
|
@ -356,19 +314,6 @@ class CoreGrpcClient:
|
||||||
)
|
)
|
||||||
return self.stub.SetSessionMetadata(request)
|
return self.stub.SetSessionMetadata(request)
|
||||||
|
|
||||||
def get_session_location(
|
|
||||||
self, session_id: int
|
|
||||||
) -> core_pb2.GetSessionLocationResponse:
|
|
||||||
"""
|
|
||||||
Get session location.
|
|
||||||
|
|
||||||
:param session_id: id of session
|
|
||||||
:return: response with session position reference and scale
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
request = core_pb2.GetSessionLocationRequest(session_id=session_id)
|
|
||||||
return self.stub.GetSessionLocation(request)
|
|
||||||
|
|
||||||
def set_session_location(
|
def set_session_location(
|
||||||
self,
|
self,
|
||||||
session_id: int,
|
session_id: int,
|
||||||
|
|
|
@ -407,18 +407,6 @@ class CoreGrpcClient:
|
||||||
response = self.stub.GetSession(request)
|
response = self.stub.GetSession(request)
|
||||||
return wrappers.Session.from_proto(response.session)
|
return wrappers.Session.from_proto(response.session)
|
||||||
|
|
||||||
def get_session_metadata(self, session_id: int) -> Dict[str, str]:
|
|
||||||
"""
|
|
||||||
Retrieve session metadata as a dict with id mapping.
|
|
||||||
|
|
||||||
:param session_id: id of session
|
|
||||||
:return: response with metadata dict
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
request = core_pb2.GetSessionMetadataRequest(session_id=session_id)
|
|
||||||
response = self.stub.GetSessionMetadata(request)
|
|
||||||
return dict(response.config)
|
|
||||||
|
|
||||||
def set_session_metadata(self, session_id: int, config: Dict[str, str]) -> bool:
|
def set_session_metadata(self, session_id: int, config: Dict[str, str]) -> bool:
|
||||||
"""
|
"""
|
||||||
Set metadata for a session.
|
Set metadata for a session.
|
||||||
|
@ -434,18 +422,6 @@ class CoreGrpcClient:
|
||||||
response = self.stub.SetSessionMetadata(request)
|
response = self.stub.SetSessionMetadata(request)
|
||||||
return response.result
|
return response.result
|
||||||
|
|
||||||
def get_session_location(self, session_id: int) -> wrappers.SessionLocation:
|
|
||||||
"""
|
|
||||||
Get session location.
|
|
||||||
|
|
||||||
:param session_id: id of session
|
|
||||||
:return: response with session position reference and scale
|
|
||||||
:raises grpc.RpcError: when session doesn't exist
|
|
||||||
"""
|
|
||||||
request = core_pb2.GetSessionLocationRequest(session_id=session_id)
|
|
||||||
response = self.stub.GetSessionLocation(request)
|
|
||||||
return wrappers.SessionLocation.from_proto(response.location)
|
|
||||||
|
|
||||||
def set_session_location(
|
def set_session_location(
|
||||||
self, session_id: int, location: wrappers.SessionLocation
|
self, session_id: int, location: wrappers.SessionLocation
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
|
@ -383,26 +383,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
sessions.append(session_summary)
|
sessions.append(session_summary)
|
||||||
return core_pb2.GetSessionsResponse(sessions=sessions)
|
return core_pb2.GetSessionsResponse(sessions=sessions)
|
||||||
|
|
||||||
def GetSessionLocation(
|
|
||||||
self, request: core_pb2.GetSessionLocationRequest, context: ServicerContext
|
|
||||||
) -> core_pb2.GetSessionLocationResponse:
|
|
||||||
"""
|
|
||||||
Retrieve a requested session location
|
|
||||||
|
|
||||||
:param request: get-session-location request
|
|
||||||
:param context: context object
|
|
||||||
:return: a get-session-location response
|
|
||||||
"""
|
|
||||||
logger.debug("get session location: %s", request)
|
|
||||||
session = self.get_session(request.session_id, context)
|
|
||||||
x, y, z = session.location.refxyz
|
|
||||||
lat, lon, alt = session.location.refgeo
|
|
||||||
scale = session.location.refscale
|
|
||||||
location = core_pb2.SessionLocation(
|
|
||||||
x=x, y=y, z=z, lat=lat, lon=lon, alt=alt, scale=scale
|
|
||||||
)
|
|
||||||
return core_pb2.GetSessionLocationResponse(location=location)
|
|
||||||
|
|
||||||
def SetSessionLocation(
|
def SetSessionLocation(
|
||||||
self, request: core_pb2.SetSessionLocationRequest, context: ServicerContext
|
self, request: core_pb2.SetSessionLocationRequest, context: ServicerContext
|
||||||
) -> core_pb2.SetSessionLocationResponse:
|
) -> core_pb2.SetSessionLocationResponse:
|
||||||
|
@ -462,56 +442,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
session.user = request.user
|
session.user = request.user
|
||||||
return core_pb2.SetSessionUserResponse(result=True)
|
return core_pb2.SetSessionUserResponse(result=True)
|
||||||
|
|
||||||
def GetSessionOptions(
|
|
||||||
self, request: core_pb2.GetSessionOptionsRequest, context: ServicerContext
|
|
||||||
) -> core_pb2.GetSessionOptionsResponse:
|
|
||||||
"""
|
|
||||||
Retrieve session options.
|
|
||||||
|
|
||||||
:param request:
|
|
||||||
get-session-options request
|
|
||||||
:param context: context object
|
|
||||||
:return: get-session-options response about all session's options
|
|
||||||
"""
|
|
||||||
logger.debug("get session options: %s", request)
|
|
||||||
session = self.get_session(request.session_id, context)
|
|
||||||
current_config = session.options.get_configs()
|
|
||||||
default_config = session.options.default_values()
|
|
||||||
default_config.update(current_config)
|
|
||||||
config = get_config_options(default_config, session.options)
|
|
||||||
return core_pb2.GetSessionOptionsResponse(config=config)
|
|
||||||
|
|
||||||
def SetSessionOptions(
|
|
||||||
self, request: core_pb2.SetSessionOptionsRequest, context: ServicerContext
|
|
||||||
) -> core_pb2.SetSessionOptionsResponse:
|
|
||||||
"""
|
|
||||||
Update a session's configuration
|
|
||||||
|
|
||||||
:param request: set-session-options request
|
|
||||||
:param context: context object
|
|
||||||
:return: set-session-options response
|
|
||||||
"""
|
|
||||||
logger.debug("set session options: %s", request)
|
|
||||||
session = self.get_session(request.session_id, context)
|
|
||||||
config = session.options.get_configs()
|
|
||||||
config.update(request.config)
|
|
||||||
return core_pb2.SetSessionOptionsResponse(result=True)
|
|
||||||
|
|
||||||
def GetSessionMetadata(
|
|
||||||
self, request: core_pb2.GetSessionMetadataRequest, context: ServicerContext
|
|
||||||
) -> core_pb2.GetSessionMetadataResponse:
|
|
||||||
"""
|
|
||||||
Retrieve session metadata.
|
|
||||||
|
|
||||||
:param request: get session metadata
|
|
||||||
request
|
|
||||||
:param context: context object
|
|
||||||
:return: get session metadata response
|
|
||||||
"""
|
|
||||||
logger.debug("get session metadata: %s", request)
|
|
||||||
session = self.get_session(request.session_id, context)
|
|
||||||
return core_pb2.GetSessionMetadataResponse(config=session.metadata)
|
|
||||||
|
|
||||||
def SetSessionMetadata(
|
def SetSessionMetadata(
|
||||||
self, request: core_pb2.SetSessionMetadataRequest, context: ServicerContext
|
self, request: core_pb2.SetSessionMetadataRequest, context: ServicerContext
|
||||||
) -> core_pb2.SetSessionMetadataResponse:
|
) -> core_pb2.SetSessionMetadataResponse:
|
||||||
|
|
|
@ -27,10 +27,6 @@ service CoreApi {
|
||||||
}
|
}
|
||||||
rpc SetSessionMetadata (SetSessionMetadataRequest) returns (SetSessionMetadataResponse) {
|
rpc SetSessionMetadata (SetSessionMetadataRequest) returns (SetSessionMetadataResponse) {
|
||||||
}
|
}
|
||||||
rpc GetSessionMetadata (GetSessionMetadataRequest) returns (GetSessionMetadataResponse) {
|
|
||||||
}
|
|
||||||
rpc GetSessionLocation (GetSessionLocationRequest) returns (GetSessionLocationResponse) {
|
|
||||||
}
|
|
||||||
rpc SetSessionLocation (SetSessionLocationRequest) returns (SetSessionLocationResponse) {
|
rpc SetSessionLocation (SetSessionLocationRequest) returns (SetSessionLocationResponse) {
|
||||||
}
|
}
|
||||||
rpc SetSessionState (SetSessionStateRequest) returns (SetSessionStateResponse) {
|
rpc SetSessionState (SetSessionStateRequest) returns (SetSessionStateResponse) {
|
||||||
|
@ -249,22 +245,6 @@ message SetSessionMetadataResponse {
|
||||||
bool result = 1;
|
bool result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetSessionMetadataRequest {
|
|
||||||
int32 session_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetSessionMetadataResponse {
|
|
||||||
map<string, string> config = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetSessionLocationRequest {
|
|
||||||
int32 session_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetSessionLocationResponse {
|
|
||||||
SessionLocation location = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message SetSessionLocationRequest {
|
message SetSessionLocationRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
SessionLocation location = 2;
|
SessionLocation location = 2;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import time
|
import time
|
||||||
|
from pathlib import Path
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
@ -235,36 +236,6 @@ class TestGrpc:
|
||||||
assert len(response.sessions) == 1
|
assert len(response.sessions) == 1
|
||||||
assert found_session is not None
|
assert found_session is not None
|
||||||
|
|
||||||
def test_get_session_options(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
|
|
||||||
# then
|
|
||||||
with client.context_connect():
|
|
||||||
response = client.get_session_options(session.id)
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert len(response.config) > 0
|
|
||||||
|
|
||||||
def test_get_session_location(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
|
|
||||||
# then
|
|
||||||
with client.context_connect():
|
|
||||||
response = client.get_session_location(session.id)
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert response.location.scale == 1.0
|
|
||||||
assert response.location.x == 0
|
|
||||||
assert response.location.y == 0
|
|
||||||
assert response.location.z == 0
|
|
||||||
assert response.location.lat == 0
|
|
||||||
assert response.location.lon == 0
|
|
||||||
assert response.location.alt == 0
|
|
||||||
|
|
||||||
def test_set_session_location(self, grpc_server: CoreGrpcServer):
|
def test_set_session_location(self, grpc_server: CoreGrpcServer):
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
|
@ -292,23 +263,6 @@ class TestGrpc:
|
||||||
assert session.location.refscale == scale
|
assert session.location.refscale == scale
|
||||||
assert session.location.refgeo == lat_lon_alt
|
assert session.location.refgeo == lat_lon_alt
|
||||||
|
|
||||||
def test_set_session_options(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
|
|
||||||
# then
|
|
||||||
option = "enablerj45"
|
|
||||||
value = "1"
|
|
||||||
with client.context_connect():
|
|
||||||
response = client.set_session_options(session.id, {option: value})
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert response.result is True
|
|
||||||
assert session.options.get_config(option) == value
|
|
||||||
config = session.options.get_configs()
|
|
||||||
assert len(config) > 0
|
|
||||||
|
|
||||||
def test_set_session_metadata(self, grpc_server: CoreGrpcServer):
|
def test_set_session_metadata(self, grpc_server: CoreGrpcServer):
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
|
@ -324,21 +278,6 @@ class TestGrpc:
|
||||||
assert response.result is True
|
assert response.result is True
|
||||||
assert session.metadata[key] == value
|
assert session.metadata[key] == value
|
||||||
|
|
||||||
def test_get_session_metadata(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
key = "meta1"
|
|
||||||
value = "value1"
|
|
||||||
session.metadata[key] = value
|
|
||||||
|
|
||||||
# then
|
|
||||||
with client.context_connect():
|
|
||||||
response = client.get_session_metadata(session.id)
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert response.config[key] == value
|
|
||||||
|
|
||||||
def test_set_session_state(self, grpc_server: CoreGrpcServer):
|
def test_set_session_state(self, grpc_server: CoreGrpcServer):
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
|
@ -507,7 +446,7 @@ class TestGrpc:
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
session = grpc_server.coreemu.create_session()
|
session = grpc_server.coreemu.create_session()
|
||||||
tmp = tmpdir.join("text.xml")
|
tmp = tmpdir.join("text.xml")
|
||||||
session.save_xml(str(tmp))
|
session.save_xml(Path(str(tmp)))
|
||||||
|
|
||||||
# then
|
# then
|
||||||
with client.context_connect():
|
with client.context_connect():
|
||||||
|
|
|
@ -274,24 +274,6 @@ class TestGrpcw:
|
||||||
assert len(sessions) == 1
|
assert len(sessions) == 1
|
||||||
assert found_session is not None
|
assert found_session is not None
|
||||||
|
|
||||||
def test_get_session_location(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
|
|
||||||
# then
|
|
||||||
with client.context_connect():
|
|
||||||
location = client.get_session_location(session.id)
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert location.scale == 1.0
|
|
||||||
assert location.x == 0
|
|
||||||
assert location.y == 0
|
|
||||||
assert location.z == 0
|
|
||||||
assert location.lat == 0
|
|
||||||
assert location.lon == 0
|
|
||||||
assert location.alt == 0
|
|
||||||
|
|
||||||
def test_set_session_location(self, grpc_server: CoreGrpcServer):
|
def test_set_session_location(self, grpc_server: CoreGrpcServer):
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
|
@ -334,21 +316,6 @@ class TestGrpcw:
|
||||||
assert result is True
|
assert result is True
|
||||||
assert session.metadata[key] == value
|
assert session.metadata[key] == value
|
||||||
|
|
||||||
def test_get_session_metadata(self, grpc_server: CoreGrpcServer):
|
|
||||||
# given
|
|
||||||
client = CoreGrpcClient()
|
|
||||||
session = grpc_server.coreemu.create_session()
|
|
||||||
key = "meta1"
|
|
||||||
value = "value1"
|
|
||||||
session.metadata[key] = value
|
|
||||||
|
|
||||||
# then
|
|
||||||
with client.context_connect():
|
|
||||||
config = client.get_session_metadata(session.id)
|
|
||||||
|
|
||||||
# then
|
|
||||||
assert config[key] == value
|
|
||||||
|
|
||||||
def test_set_session_state(self, grpc_server: CoreGrpcServer):
|
def test_set_session_state(self, grpc_server: CoreGrpcServer):
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
|
|
Loading…
Add table
Reference in a new issue