88// the Business Source License, use of this software will be governed
99// by the Apache License, Version 2.0.
1010
11- use super :: error:: * ;
12- use crate :: generate_meta_api_error;
13- use crate :: rest_api:: create_envelope_header;
14- use crate :: state:: AdminServiceState ;
1511use axum:: Json ;
1612use axum:: extract:: { Path , Query , State } ;
1713use axum:: http:: StatusCode ;
1814use okapi_operation:: * ;
15+ use serde:: Deserialize ;
16+
1917use restate_admin_rest_model:: invocations:: RestartAsNewInvocationResponse ;
20- use restate_types:: identifiers:: {
21- DeploymentId , InvocationId , PartitionProcessorRpcRequestId , WithPartitionKey ,
22- } ;
18+ use restate_types:: identifiers:: { DeploymentId , InvocationId , PartitionProcessorRpcRequestId } ;
2319use restate_types:: invocation:: client:: {
2420 self , CancelInvocationResponse , InvocationClient , KillInvocationResponse ,
2521 PauseInvocationResponse , PurgeInvocationResponse , ResumeInvocationResponse ,
2622} ;
27- use restate_types:: invocation:: { InvocationTermination , PurgeInvocationRequest , TerminationFlavor } ;
2823use restate_types:: journal_v2:: EntryIndex ;
29- use restate_wal_protocol:: { Command , Envelope } ;
30- use serde:: Deserialize ;
31- use std:: sync:: Arc ;
32- use tracing:: warn;
3324
34- #[ derive( Debug , Default , Deserialize , JsonSchema ) ]
35- pub enum DeletionMode {
36- #[ default]
37- #[ serde( alias = "cancel" ) ]
38- Cancel ,
39- #[ serde( alias = "kill" ) ]
40- Kill ,
41- #[ serde( alias = "purge" ) ]
42- Purge ,
43- }
44- #[ derive( Debug , Default , Deserialize , JsonSchema ) ]
45- pub struct DeleteInvocationParams {
46- pub mode : Option < DeletionMode > ,
47- }
48-
49- /// Terminate an invocation
50- #[ openapi(
51- summary = "Delete an invocation" ,
52- deprecated = true ,
53- description = "Use kill_invocation/cancel_invocation/purge_invocation instead." ,
54- operation_id = "delete_invocation" ,
55- tags = "invocation" ,
56- parameters(
57- path(
58- name = "invocation_id" ,
59- description = "Invocation identifier." ,
60- schema = "std::string::String"
61- ) ,
62- query(
63- name = "mode" ,
64- description = "If cancel, it will gracefully terminate the invocation. \
65- If kill, it will terminate the invocation with a hard stop. \
66- If purge, it will only cleanup the response for completed invocations, and leave unaffected an in-flight invocation.",
67- required = false ,
68- style = "simple" ,
69- allow_empty_value = false ,
70- schema = "DeletionMode" ,
71- )
72- ) ,
73- responses(
74- ignore_return_type = true ,
75- response(
76- status = "202" ,
77- description = "Accepted" ,
78- content = "okapi_operation::Empty" ,
79- ) ,
80- from_type = "MetaApiError" ,
81- )
82- ) ]
83- pub async fn delete_invocation < Metadata , Discovery , Telemetry , Invocations > (
84- State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations > > ,
85- Path ( invocation_id) : Path < String > ,
86- Query ( DeleteInvocationParams { mode } ) : Query < DeleteInvocationParams > ,
87- ) -> Result < StatusCode , MetaApiError > {
88- let invocation_id = invocation_id
89- . parse :: < InvocationId > ( )
90- . map_err ( |e| MetaApiError :: InvalidField ( "invocation_id" , e. to_string ( ) ) ) ?;
91-
92- let cmd = match mode. unwrap_or_default ( ) {
93- DeletionMode :: Cancel => Command :: TerminateInvocation ( InvocationTermination {
94- invocation_id,
95- flavor : TerminationFlavor :: Cancel ,
96- response_sink : None ,
97- } ) ,
98- DeletionMode :: Kill => Command :: TerminateInvocation ( InvocationTermination {
99- invocation_id,
100- flavor : TerminationFlavor :: Kill ,
101- response_sink : None ,
102- } ) ,
103- DeletionMode :: Purge => Command :: PurgeInvocation ( PurgeInvocationRequest {
104- invocation_id,
105- response_sink : None ,
106- } ) ,
107- } ;
108-
109- let partition_key = invocation_id. partition_key ( ) ;
110-
111- let result = restate_bifrost:: append_to_bifrost (
112- & state. bifrost ,
113- Arc :: new ( Envelope :: new ( create_envelope_header ( partition_key) , cmd) ) ,
114- )
115- . await ;
116-
117- if let Err ( err) = result {
118- warn ! ( "Could not append invocation termination command to Bifrost: {err}" ) ;
119- Err ( MetaApiError :: Internal (
120- "Failed sending invocation termination to the cluster." . to_owned ( ) ,
121- ) )
122- } else {
123- Ok ( StatusCode :: ACCEPTED )
124- }
125- }
25+ use super :: error:: * ;
26+ use crate :: generate_meta_api_error;
27+ use crate :: state:: AdminServiceState ;
12628
12729generate_meta_api_error ! ( KillInvocationError : [ InvocationNotFoundError , InvocationClientError , InvalidFieldError , InvocationWasAlreadyCompletedError ] ) ;
12830
@@ -139,8 +41,8 @@ generate_meta_api_error!(KillInvocationError: [InvocationNotFoundError, Invocati
13941 schema = "std::string::String"
14042 ) )
14143) ]
142- pub async fn kill_invocation < Metadata , Discovery , Telemetry , Invocations > (
143- State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations > > ,
44+ pub async fn kill_invocation < Metadata , Discovery , Telemetry , Invocations , Transport > (
45+ State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations , Transport > > ,
14446 Path ( invocation_id) : Path < String > ,
14547) -> Result < ( ) , KillInvocationError >
14648where
@@ -199,8 +101,8 @@ generate_meta_api_error!(CancelInvocationError: [InvocationNotFoundError, Invoca
199101 from_type = "CancelInvocationError" ,
200102 )
201103) ]
202- pub async fn cancel_invocation < Metadata , Discovery , Telemetry , Invocations > (
203- State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations > > ,
104+ pub async fn cancel_invocation < Metadata , Discovery , Telemetry , Invocations , Transport > (
105+ State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations , Transport > > ,
204106 Path ( invocation_id) : Path < String > ,
205107) -> Result < StatusCode , CancelInvocationError >
206108where
@@ -241,8 +143,8 @@ generate_meta_api_error!(PurgeInvocationError: [InvocationNotFoundError, Invocat
241143 schema = "std::string::String"
242144 ) )
243145) ]
244- pub async fn purge_invocation < Metadata , Discovery , Telemetry , Invocations > (
245- State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations > > ,
146+ pub async fn purge_invocation < Metadata , Discovery , Telemetry , Invocations , Transport > (
147+ State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations , Transport > > ,
246148 Path ( invocation_id) : Path < String > ,
247149) -> Result < ( ) , PurgeInvocationError >
248150where
@@ -284,8 +186,8 @@ generate_meta_api_error!(PurgeJournalError: [InvocationNotFoundError, Invocation
284186 schema = "std::string::String"
285187 ) )
286188) ]
287- pub async fn purge_journal < Metadata , Discovery , Telemetry , Invocations > (
288- State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations > > ,
189+ pub async fn purge_journal < Metadata , Discovery , Telemetry , Invocations , Transport > (
190+ State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations , Transport > > ,
289191 Path ( invocation_id) : Path < String > ,
290192) -> Result < ( ) , PurgeJournalError >
291193where
@@ -398,8 +300,8 @@ generate_meta_api_error!(RestartInvocationError: [
398300 ) ,
399301 )
400302) ]
401- pub async fn restart_as_new_invocation < Metadata , Discovery , Telemetry , Invocations > (
402- State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations > > ,
303+ pub async fn restart_as_new_invocation < Metadata , Discovery , Telemetry , Invocations , Transport > (
304+ State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations , Transport > > ,
403305 Path ( invocation_id) : Path < String > ,
404306 Query ( RestartAsNewInvocationQueryParams { from, deployment } ) : Query <
405307 RestartAsNewInvocationQueryParams ,
@@ -510,8 +412,8 @@ generate_meta_api_error!(ResumeInvocationError: [
510412 )
511413 )
512414) ]
513- pub async fn resume_invocation < Metadata , Discovery , Telemetry , Invocations > (
514- State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations > > ,
415+ pub async fn resume_invocation < Metadata , Discovery , Telemetry , Invocations , Transport > (
416+ State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations , Transport > > ,
515417 Path ( invocation_id) : Path < String > ,
516418 Query ( ResumeInvocationQueryParams { deployment } ) : Query < ResumeInvocationQueryParams > ,
517419) -> Result < ( ) , ResumeInvocationError >
@@ -596,8 +498,8 @@ generate_meta_api_error!(PauseInvocationError: [
596498 from_type = "PauseInvocationError" ,
597499 )
598500) ]
599- pub async fn pause_invocation < Metadata , Discovery , Telemetry , Invocations > (
600- State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations > > ,
501+ pub async fn pause_invocation < Metadata , Discovery , Telemetry , Invocations , Transport > (
502+ State ( state) : State < AdminServiceState < Metadata , Discovery , Telemetry , Invocations , Transport > > ,
601503 Path ( invocation_id) : Path < String > ,
602504) -> Result < StatusCode , PauseInvocationError >
603505where
0 commit comments