grpc: removed set session state, states are a by product of actions done within a session and probably best to automate that instead of relying on clients responsibly setting proper values

This commit is contained in:
Blake Harnden 2021-05-06 11:39:18 -07:00
parent d40435fa68
commit 598cb0f10d
4 changed files with 0 additions and 68 deletions

View file

@ -408,21 +408,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 set_session_state(self, session_id: int, state: wrappers.SessionState) -> bool:
"""
Set session state.
:param session_id: id of session
:param state: session state to transition to
:return: True for success, False otherwise
:raises grpc.RpcError: when session doesn't exist
"""
request = core_pb2.SetSessionStateRequest(
session_id=session_id, state=state.value
)
response = self.stub.SetSessionState(request)
return response.result
def alert( def alert(
self, self,
session_id: int, session_id: int,

View file

@ -402,35 +402,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 SetSessionState(
self, request: core_pb2.SetSessionStateRequest, context: ServicerContext
) -> core_pb2.SetSessionStateResponse:
"""
Set session state
:param request: set-session-state request
:param context:context object
:return: set-session-state response
"""
logger.debug("set session state: %s", request)
session = self.get_session(request.session_id, context)
try:
state = EventTypes(request.state)
session.set_state(state)
if state == EventTypes.INSTANTIATION_STATE:
session.directory.mkdir(exist_ok=True)
session.instantiate()
elif state == EventTypes.SHUTDOWN_STATE:
session.shutdown()
elif state == EventTypes.DATACOLLECT_STATE:
session.data_collect()
elif state == EventTypes.DEFINITION_STATE:
session.clear()
result = True
except KeyError:
result = False
return core_pb2.SetSessionStateResponse(result=result)
def CheckSession( def CheckSession(
self, request: core_pb2.GetSessionRequest, context: ServicerContext self, request: core_pb2.GetSessionRequest, context: ServicerContext
) -> core_pb2.CheckSessionResponse: ) -> core_pb2.CheckSessionResponse:

View file

@ -25,8 +25,6 @@ service CoreApi {
} }
rpc CheckSession (CheckSessionRequest) returns (CheckSessionResponse) { rpc CheckSession (CheckSessionRequest) returns (CheckSessionResponse) {
} }
rpc SetSessionState (SetSessionStateRequest) returns (SetSessionStateResponse) {
}
rpc SessionAlert (SessionAlertRequest) returns (SessionAlertResponse) { rpc SessionAlert (SessionAlertRequest) returns (SessionAlertResponse) {
} }
@ -216,15 +214,6 @@ message GetSessionResponse {
Session session = 1; Session session = 1;
} }
message SetSessionStateRequest {
int32 session_id = 1;
SessionState.Enum state = 2;
}
message SetSessionStateResponse {
bool result = 1;
}
message SessionAlertRequest { message SessionAlertRequest {
int32 session_id = 1; int32 session_id = 1;
ExceptionLevel.Enum level = 2; ExceptionLevel.Enum level = 2;

View file

@ -243,19 +243,6 @@ class TestGrpc:
assert len(sessions) == 1 assert len(sessions) == 1
assert found_session is not None assert found_session is not None
def test_set_session_state(self, grpc_server: CoreGrpcServer):
# given
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
# then
with client.context_connect():
result = client.set_session_state(session.id, SessionState.DEFINITION)
# then
assert result is True
assert session.state == EventTypes.DEFINITION_STATE
def test_add_node(self, grpc_server: CoreGrpcServer): def test_add_node(self, grpc_server: CoreGrpcServer):
# given # given
client = CoreGrpcClient() client = CoreGrpcClient()