grpc: removed set session metadata, now accomplished with start session
This commit is contained in:
parent
a217c2445c
commit
634341dd03
8 changed files with 7 additions and 94 deletions
|
@ -298,22 +298,6 @@ class CoreGrpcClient:
|
|||
request = core_pb2.GetSessionRequest(session_id=session_id)
|
||||
return self.stub.GetSession(request)
|
||||
|
||||
def set_session_metadata(
|
||||
self, session_id: int, config: Dict[str, str]
|
||||
) -> core_pb2.SetSessionMetadataResponse:
|
||||
"""
|
||||
Set metadata 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.SetSessionMetadataRequest(
|
||||
session_id=session_id, config=config
|
||||
)
|
||||
return self.stub.SetSessionMetadata(request)
|
||||
|
||||
def set_session_state(
|
||||
self, session_id: int, state: core_pb2.SessionState
|
||||
) -> core_pb2.SetSessionStateResponse:
|
||||
|
|
|
@ -258,6 +258,7 @@ class CoreGrpcClient:
|
|||
|
||||
:param session: session to start
|
||||
:param asymmetric_links: link configuration for asymmetric links
|
||||
:param definition: True to only define session data, False to start session
|
||||
:return: tuple of result and exception strings
|
||||
"""
|
||||
nodes = [x.to_proto() for x in session.nodes.values()]
|
||||
|
@ -335,6 +336,7 @@ class CoreGrpcClient:
|
|||
options=options,
|
||||
user=session.user,
|
||||
definition=definition,
|
||||
metadata=session.metadata,
|
||||
)
|
||||
response = self.stub.StartSession(request)
|
||||
return response.result, list(response.exceptions)
|
||||
|
@ -412,21 +414,6 @@ class CoreGrpcClient:
|
|||
response = self.stub.GetSession(request)
|
||||
return wrappers.Session.from_proto(response.session)
|
||||
|
||||
def set_session_metadata(self, session_id: int, config: Dict[str, str]) -> bool:
|
||||
"""
|
||||
Set metadata for a session.
|
||||
|
||||
:param session_id: id of session
|
||||
:param config: configuration values to set
|
||||
:return: True for success, False otherwise
|
||||
:raises grpc.RpcError: when session doesn't exist
|
||||
"""
|
||||
request = core_pb2.SetSessionMetadataRequest(
|
||||
session_id=session_id, config=config
|
||||
)
|
||||
response = self.stub.SetSessionMetadata(request)
|
||||
return response.result
|
||||
|
||||
def set_session_state(self, session_id: int, state: wrappers.SessionState) -> bool:
|
||||
"""
|
||||
Set session state.
|
||||
|
|
|
@ -235,6 +235,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
session.options.config_reset()
|
||||
for key, value in request.options.items():
|
||||
session.options.set_config(key, value)
|
||||
session.metadata = dict(request.metadata)
|
||||
|
||||
# location
|
||||
if request.HasField("location"):
|
||||
|
@ -419,21 +420,6 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
result = False
|
||||
return core_pb2.SetSessionStateResponse(result=result)
|
||||
|
||||
def SetSessionMetadata(
|
||||
self, request: core_pb2.SetSessionMetadataRequest, context: ServicerContext
|
||||
) -> core_pb2.SetSessionMetadataResponse:
|
||||
"""
|
||||
Update a session's metadata.
|
||||
|
||||
:param request: set metadata request
|
||||
:param context: context object
|
||||
:return: set metadata response
|
||||
"""
|
||||
logger.debug("set session metadata: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
session.metadata = dict(request.config)
|
||||
return core_pb2.SetSessionMetadataResponse(result=True)
|
||||
|
||||
def CheckSession(
|
||||
self, request: core_pb2.GetSessionRequest, context: ServicerContext
|
||||
) -> core_pb2.CheckSessionResponse:
|
||||
|
|
|
@ -456,6 +456,7 @@ class CoreClient:
|
|||
def start_session(self, definition: bool = False) -> Tuple[bool, List[str]]:
|
||||
links, asym_links = self.get_links(definition)
|
||||
self.session.links = links
|
||||
self.session.metadata = self.get_metadata()
|
||||
result = False
|
||||
exceptions = []
|
||||
try:
|
||||
|
@ -469,8 +470,6 @@ class CoreClient:
|
|||
definition,
|
||||
result,
|
||||
)
|
||||
if result:
|
||||
self.set_metadata()
|
||||
except grpc.RpcError as e:
|
||||
self.app.show_grpc_exception("Start Session Error", e)
|
||||
return result, exceptions
|
||||
|
@ -495,7 +494,7 @@ class CoreClient:
|
|||
self.mobility_players[node.id] = mobility_player
|
||||
mobility_player.show()
|
||||
|
||||
def set_metadata(self) -> None:
|
||||
def get_metadata(self) -> Dict[str, str]:
|
||||
# create canvas data
|
||||
canvas_config = self.app.manager.get_metadata()
|
||||
canvas_config = json.dumps(canvas_config)
|
||||
|
@ -521,11 +520,9 @@ class CoreClient:
|
|||
hidden = json.dumps(hidden)
|
||||
|
||||
# save metadata
|
||||
metadata = dict(
|
||||
return dict(
|
||||
canvas=canvas_config, shapes=shapes, edges=edges_config, hidden=hidden
|
||||
)
|
||||
response = self.client.set_session_metadata(self.session.id, metadata)
|
||||
logger.debug("set session metadata %s, result: %s", metadata, response)
|
||||
|
||||
def launch_terminal(self, node_id: int) -> None:
|
||||
try:
|
||||
|
|
|
@ -306,7 +306,6 @@ class Toolbar(ttk.Frame):
|
|||
def start_callback(self, result: bool, exceptions: List[str]) -> None:
|
||||
if result:
|
||||
self.set_runtime()
|
||||
self.app.core.set_metadata()
|
||||
self.app.core.show_mobility_players()
|
||||
else:
|
||||
enable_buttons(self.design_frame, enabled=True)
|
||||
|
|
|
@ -25,8 +25,6 @@ service CoreApi {
|
|||
}
|
||||
rpc CheckSession (CheckSessionRequest) returns (CheckSessionResponse) {
|
||||
}
|
||||
rpc SetSessionMetadata (SetSessionMetadataRequest) returns (SetSessionMetadataResponse) {
|
||||
}
|
||||
rpc SetSessionState (SetSessionStateRequest) returns (SetSessionStateResponse) {
|
||||
}
|
||||
rpc AddSessionServer (AddSessionServerRequest) returns (AddSessionServerResponse) {
|
||||
|
@ -179,6 +177,7 @@ message StartSessionRequest {
|
|||
map<string, string> options = 14;
|
||||
string user = 15;
|
||||
bool definition = 16;
|
||||
map<string, string> metadata = 17;
|
||||
}
|
||||
|
||||
message StartSessionResponse {
|
||||
|
@ -234,15 +233,6 @@ message GetSessionResponse {
|
|||
Session session = 1;
|
||||
}
|
||||
|
||||
message SetSessionMetadataRequest {
|
||||
int32 session_id = 1;
|
||||
map<string, string> config = 2;
|
||||
}
|
||||
|
||||
message SetSessionMetadataResponse {
|
||||
bool result = 1;
|
||||
}
|
||||
|
||||
message SetSessionStateRequest {
|
||||
int32 session_id = 1;
|
||||
SessionState.Enum state = 2;
|
||||
|
|
|
@ -236,21 +236,6 @@ class TestGrpc:
|
|||
assert len(response.sessions) == 1
|
||||
assert found_session is not None
|
||||
|
||||
def test_set_session_metadata(self, grpc_server: CoreGrpcServer):
|
||||
# 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[key] == value
|
||||
|
||||
def test_set_session_state(self, grpc_server: CoreGrpcServer):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
|
|
|
@ -280,21 +280,6 @@ class TestGrpcw:
|
|||
assert len(sessions) == 1
|
||||
assert found_session is not None
|
||||
|
||||
def test_set_session_metadata(self, grpc_server: CoreGrpcServer):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
session = grpc_server.coreemu.create_session()
|
||||
|
||||
# then
|
||||
key = "meta1"
|
||||
value = "value1"
|
||||
with client.context_connect():
|
||||
result = client.set_session_metadata(session.id, {key: value})
|
||||
|
||||
# then
|
||||
assert result is True
|
||||
assert session.metadata[key] == value
|
||||
|
||||
def test_set_session_state(self, grpc_server: CoreGrpcServer):
|
||||
# given
|
||||
client = CoreGrpcClient()
|
||||
|
|
Loading…
Reference in a new issue