diff --git a/Protos/V1/session_status.proto b/Protos/V1/session_status.proto index 235d5c689..88cfe1ca2 100644 --- a/Protos/V1/session_status.proto +++ b/Protos/V1/session_status.proto @@ -15,6 +15,7 @@ enum SessionStatus { SESSION_STATUS_RUNNING = 1; /** Session is open and accepting tasks for execution. */ SESSION_STATUS_CANCELLED = 2; /** Session is cancelled. No more tasks can be submitted and no more tasks will be executed. */ SESSION_STATUS_PAUSED = 3; /** Session is paused. Tasks can be submitted but no more new tasks will be executed. Already running tasks will continue until they finish. */ - SESSION_STATUS_PURGED = 4; /** Session is purged. No more tasks can be submitted and executed. Results data will be deleted. */ - SESSION_STATUS_DELETED = 5; /** Session is deleted. No more tasks can be submitted and executed. Sessions, tasks and results metadata associated to the session will be deleted. */ + SESSION_STATUS_CLOSED = 4; /** Session is closed. No more tasks can be submitted and executed. */ + SESSION_STATUS_PURGED = 5; /** Session is purged. No more tasks can be submitted and executed. Results data will be deleted. */ + SESSION_STATUS_DELETED = 6; /** Session is deleted. No more tasks can be submitted and executed. Sessions, tasks and results metadata associated to the session will be deleted. */ } diff --git a/Protos/V1/sessions_common.proto b/Protos/V1/sessions_common.proto index a8141e5fb..9df2e57c5 100644 --- a/Protos/V1/sessions_common.proto +++ b/Protos/V1/sessions_common.proto @@ -28,6 +28,7 @@ message SessionRaw { google.protobuf.Timestamp created_at = 5; /** The creation date. */ google.protobuf.Timestamp cancelled_at = 6; /** The cancellation date. Only set when status is 'cancelled'. */ + google.protobuf.Timestamp closed_at = 12; /** The closure date. Only set when status is 'closed'. */ google.protobuf.Timestamp purged_at = 10; /** The purge date. Only set when status is 'purged'. */ google.protobuf.Timestamp deleted_at = 11; /** The deletion date. Only set when status is 'deleted'. */ google.protobuf.Duration duration = 7; /** The duration. Only set when status is 'cancelled' and 'closed'. */ @@ -159,6 +160,22 @@ message ResumeSessionResponse { SessionRaw session = 1; /** The session. */ } +/** + * Request for closing a single session. + */ +message CloseSessionRequest { + string session_id = 1; /** The session ID. */ +} + +/** + * Response for closing a single session. + * + * Return a raw session. + */ +message CloseSessionResponse { + SessionRaw session = 1; /** The session. */ +} + /** * Request for purging a single session. */ diff --git a/Protos/V1/sessions_fields.proto b/Protos/V1/sessions_fields.proto index 96e76b688..e0fab5a48 100644 --- a/Protos/V1/sessions_fields.proto +++ b/Protos/V1/sessions_fields.proto @@ -15,6 +15,9 @@ enum SessionRawEnumField { SESSION_RAW_ENUM_FIELD_OPTIONS = 4; SESSION_RAW_ENUM_FIELD_CREATED_AT = 5; SESSION_RAW_ENUM_FIELD_CANCELLED_AT = 6; + SESSION_RAW_ENUM_FIELD_CLOSED_AT = 8; + SESSION_RAW_ENUM_FIELD_PURGED_AT = 9; + SESSION_RAW_ENUM_FIELD_DELETED_AT = 10; SESSION_RAW_ENUM_FIELD_DURATION = 7; } diff --git a/Protos/V1/sessions_service.proto b/Protos/V1/sessions_service.proto index dcaa977f5..3871ba206 100644 --- a/Protos/V1/sessions_service.proto +++ b/Protos/V1/sessions_service.proto @@ -43,6 +43,11 @@ service Sessions { */ rpc ResumeSession(ResumeSessionRequest) returns (ResumeSessionResponse); + /** + * Close a session by its id.. + */ + rpc CloseSession(CloseSessionRequest) returns (CloseSessionResponse); + /** * Purge a session by its id. Removes Results data. */ diff --git a/packages/csharp/ArmoniK.Api.Mock/Services/Sessions.cs b/packages/csharp/ArmoniK.Api.Mock/Services/Sessions.cs index bf12c8865..7006039d7 100644 --- a/packages/csharp/ArmoniK.Api.Mock/Services/Sessions.cs +++ b/packages/csharp/ArmoniK.Api.Mock/Services/Sessions.cs @@ -97,6 +97,15 @@ public override Task ResumeSession(ResumeSessionRequest r Session = MockSession, }); + /// + [Count] + public override Task CloseSession(CloseSessionRequest request, + ServerCallContext context) + => Task.FromResult(new CloseSessionResponse + { + Session = MockSession, + }); + /// [Count] public override Task PurgeSession(PurgeSessionRequest request, diff --git a/packages/python/src/armonik/client/sessions.py b/packages/python/src/armonik/client/sessions.py index bfff9c66f..748f60f3e 100644 --- a/packages/python/src/armonik/client/sessions.py +++ b/packages/python/src/armonik/client/sessions.py @@ -19,6 +19,8 @@ PauseSessionResponse, PurgeSessionRequest, PurgeSessionResponse, + CloseSessionRequest, + CloseSessionResponse, ResumeSessionRequest, ResumeSessionResponse, StopSubmissionRequest, @@ -195,6 +197,19 @@ def resume_session(self, session_id: str) -> Session: response: ResumeSessionResponse = self._client.ResumeSession(request) return Session.from_message(response.session) + def close_session(self, session_id: str) -> Session: + """Close a session by its id. + + Args: + session_id: Id of the session to be closed. + + Returns: + session metadata + """ + request = CloseSessionRequest(session_id=session_id) + response: CloseSessionResponse = self._client.CloseSession(request) + return Session.from_message(response.session) + def purge_session(self, session_id: str) -> Session: """Purge a session by its id. @@ -234,4 +249,4 @@ def stop_submission_session(self, session_id: str, client: bool, worker:bool) -> """ request = StopSubmissionRequest(session_id=session_id, client=client, worker=worker) response: StopSubmissionResponse = self._client.StopSubmission(request) - return Session.from_message(response.session) \ No newline at end of file + return Session.from_message(response.session) diff --git a/packages/python/src/armonik/common/objects.py b/packages/python/src/armonik/common/objects.py index 7b3fade48..e3948455f 100644 --- a/packages/python/src/armonik/common/objects.py +++ b/packages/python/src/armonik/common/objects.py @@ -193,6 +193,7 @@ class Session: options: Optional[TaskOptions] = None created_at: Optional[datetime] = None cancelled_at: Optional[datetime] = None + closed_at: Optional[datetime] = None purged_at: Optional[datetime] = None deleted_at: Optional[datetime] = None duration: Optional[timedelta] = None @@ -208,6 +209,7 @@ def from_message(cls, session_raw: SessionRaw) -> "Session": options=TaskOptions.from_message(session_raw.options), created_at=timestamp_to_datetime(session_raw.created_at), cancelled_at=timestamp_to_datetime(session_raw.cancelled_at), + closed_at=timestamp_to_datetime(session_raw.closed_at), purged_at=timestamp_to_datetime(session_raw.purged_at), deleted_at=timestamp_to_datetime(session_raw.deleted_at), duration=duration_to_timedelta(session_raw.duration), diff --git a/packages/python/tests/test_sessions.py b/packages/python/tests/test_sessions.py index fde5240e3..116380779 100644 --- a/packages/python/tests/test_sessions.py +++ b/packages/python/tests/test_sessions.py @@ -89,6 +89,12 @@ def test_purge_session(self): assert rpc_called("Sessions", "PurgeSession") + def test_close_session(self): + session_client: ArmoniKSessions = get_client("Sessions") + session_client.close_session("session-id") + + assert rpc_called("Sessions", "CloseSession") + def test_delete_session(self): session_client: ArmoniKSessions = get_client("Sessions") session_client.delete_session("session-id")