added grpc get/set session metadata
This commit is contained in:
parent
c0516255f2
commit
fe95f246d4
4 changed files with 109 additions and 0 deletions
|
@ -270,6 +270,33 @@ class CoreGrpcClient:
|
||||||
)
|
)
|
||||||
return self.stub.SetSessionOptions(request)
|
return self.stub.SetSessionOptions(request)
|
||||||
|
|
||||||
|
def get_session_metadata(self, session_id):
|
||||||
|
"""
|
||||||
|
Retrieve session metadata as a dict with id mapping.
|
||||||
|
|
||||||
|
:param int session_id: id of session
|
||||||
|
:return: response with metadata dict
|
||||||
|
:rtype: core_pb2.GetSessionMetadataResponse
|
||||||
|
: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(self, session_id, config):
|
||||||
|
"""
|
||||||
|
Set metadata for a session.
|
||||||
|
|
||||||
|
:param int session_id: id of session
|
||||||
|
:param dict[str, str] config: configuration values to set
|
||||||
|
:return: response with result of success or failure
|
||||||
|
:rtype: core_pb2.SetSessionMetadataResponse
|
||||||
|
:raises grpc.RpcError: when session doesn't exist
|
||||||
|
"""
|
||||||
|
request = core_pb2.SetSessionMetadataRequest(
|
||||||
|
session_id=session_id, config=config
|
||||||
|
)
|
||||||
|
return self.stub.SetSessionMetadata(request)
|
||||||
|
|
||||||
def get_session_location(self, session_id):
|
def get_session_location(self, session_id):
|
||||||
"""
|
"""
|
||||||
Get session location.
|
Get session location.
|
||||||
|
|
|
@ -331,6 +331,35 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
config.update(request.config)
|
config.update(request.config)
|
||||||
return core_pb2.SetSessionOptionsResponse(result=True)
|
return core_pb2.SetSessionOptionsResponse(result=True)
|
||||||
|
|
||||||
|
def GetSessionMetadata(self, request, context):
|
||||||
|
"""
|
||||||
|
Retrieve session metadata.
|
||||||
|
|
||||||
|
:param core.api.grpc.core_pb2.GetSessionMetadata request: get session metadata
|
||||||
|
request
|
||||||
|
:param grpc.ServicerContext context: context object
|
||||||
|
:return: get session metadata response
|
||||||
|
:rtype: core.api.grpc.core_pb2.GetSessionMetadata
|
||||||
|
"""
|
||||||
|
logging.debug("get session metadata: %s", request)
|
||||||
|
session = self.get_session(request.session_id, context)
|
||||||
|
config = session.metadata.get_configs()
|
||||||
|
return core_pb2.GetSessionMetadataResponse(config=config)
|
||||||
|
|
||||||
|
def SetSessionMetadata(self, request, context):
|
||||||
|
"""
|
||||||
|
Update a session's metadata.
|
||||||
|
|
||||||
|
:param core.api.grpc.core_pb2.SetSessionMetadata request: set metadata request
|
||||||
|
:param grpc.ServicerContext context: context object
|
||||||
|
:return: set metadata response
|
||||||
|
:rtype: core.api.grpc.core_pb2.SetSessionMetadataResponse
|
||||||
|
"""
|
||||||
|
logging.debug("set session metadata: %s", request)
|
||||||
|
session = self.get_session(request.session_id, context)
|
||||||
|
session.metadata.set_configs(request.config)
|
||||||
|
return core_pb2.SetSessionMetadataResponse(result=True)
|
||||||
|
|
||||||
def GetSession(self, request, context):
|
def GetSession(self, request, context):
|
||||||
"""
|
"""
|
||||||
Retrieve requested session
|
Retrieve requested session
|
||||||
|
|
|
@ -23,6 +23,10 @@ service CoreApi {
|
||||||
}
|
}
|
||||||
rpc SetSessionOptions (SetSessionOptionsRequest) returns (SetSessionOptionsResponse) {
|
rpc SetSessionOptions (SetSessionOptionsRequest) returns (SetSessionOptionsResponse) {
|
||||||
}
|
}
|
||||||
|
rpc SetSessionMetadata (SetSessionMetadataRequest) returns (SetSessionMetadataResponse) {
|
||||||
|
}
|
||||||
|
rpc GetSessionMetadata (GetSessionMetadataRequest) returns (GetSessionMetadataResponse) {
|
||||||
|
}
|
||||||
rpc GetSessionLocation (GetSessionLocationRequest) returns (GetSessionLocationResponse) {
|
rpc GetSessionLocation (GetSessionLocationRequest) returns (GetSessionLocationResponse) {
|
||||||
}
|
}
|
||||||
rpc SetSessionLocation (SetSessionLocationRequest) returns (SetSessionLocationResponse) {
|
rpc SetSessionLocation (SetSessionLocationRequest) returns (SetSessionLocationResponse) {
|
||||||
|
@ -203,6 +207,23 @@ message SetSessionOptionsResponse {
|
||||||
bool result = 1;
|
bool result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message SetSessionMetadataRequest {
|
||||||
|
int32 session_id = 1;
|
||||||
|
map<string, string> config = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SetSessionMetadataResponse {
|
||||||
|
bool result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetSessionMetadataRequest {
|
||||||
|
int32 session_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetSessionMetadataResponse {
|
||||||
|
map<string, string> config = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message GetSessionLocationRequest {
|
message GetSessionLocationRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,6 +283,38 @@ class TestGrpc:
|
||||||
config = session.options.get_configs()
|
config = session.options.get_configs()
|
||||||
assert len(config) > 0
|
assert len(config) > 0
|
||||||
|
|
||||||
|
def test_set_session_metadata(self, grpc_server):
|
||||||
|
# given
|
||||||
|
client = CoreGrpcClient()
|
||||||
|
session = grpc_server.coreemu.create_session()
|
||||||
|
|
||||||
|
# then
|
||||||
|
key = "meta1"
|
||||||
|
value = "value1"
|
||||||
|
with client.context_connect():
|
||||||
|
response = client.set_session_metadata(session.id, {key: value})
|
||||||
|
|
||||||
|
# then
|
||||||
|
assert response.result is True
|
||||||
|
assert session.metadata.get_config(key) == value
|
||||||
|
config = session.metadata.get_configs()
|
||||||
|
assert len(config) > 0
|
||||||
|
|
||||||
|
def test_get_session_metadata(self, grpc_server):
|
||||||
|
# given
|
||||||
|
client = CoreGrpcClient()
|
||||||
|
session = grpc_server.coreemu.create_session()
|
||||||
|
key = "meta1"
|
||||||
|
value = "value1"
|
||||||
|
session.metadata.set_config(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):
|
def test_set_session_state(self, grpc_server):
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
|
|
Loading…
Reference in a new issue