@@ -79,45 +79,56 @@ is_authorized(ReqData, Context) ->
7979
8080delete_resource (ReqData , # context {user = # user {username = Username }}= Context ) ->
8181 VHost = rabbit_mgmt_util :id (vhost , ReqData ),
82- Reply = case rabbit_mgmt_util :id (name , ReqData ) of
83- none ->
84- false ;
85- Name ->
86- case get_shovel_node (VHost , Name , ReqData , Context ) of
87- undefined -> rabbit_log :error (" Could not find shovel data for shovel '~ts ' in vhost: '~ts '" , [Name , VHost ]),
88- case is_restart (ReqData ) of
89- true ->
90- false ;
91- % % this is a deletion attempt
92- false ->
93- % % if we do not know the node, use the local one
94- try_delete (node (), VHost , Name , Username ),
95- true
82+ case rabbit_mgmt_util :id (name , ReqData ) of
83+ none ->
84+ {false , ReqData , Context };
85+ Name ->
86+ case get_shovel_node (VHost , Name , ReqData , Context ) of
87+ undefined -> rabbit_log :error (" Could not find shovel data for shovel '~ts ' in vhost: '~ts '" , [Name , VHost ]),
88+ case is_restart (ReqData ) of
89+ true ->
90+ {false , ReqData , Context };
91+ % % this is a deletion attempt
92+ false ->
93+ % % if we do not know the node, use the local one
94+ case try_delete (node (), VHost , Name , Username ) of
95+ true -> {true , ReqData , Context };
96+ false -> {false , ReqData , Context };
97+ locked -> Reply = cowboy_req :reply (405 , #{<<" content-type" >> => <<" text/plain" >>},
98+ " Protected" , ReqData ),
99+ {halt , Reply , Context };
100+ error -> {false , ReqData , Context }
101+ end
102+ end ;
103+ Node ->
104+ % % We must distinguish between a delete and a restart
105+ case is_restart (ReqData ) of
106+ true ->
107+ rabbit_log :info (" Asked to restart shovel '~ts ' in vhost '~ts ' on node '~s '" , [Name , VHost , Node ]),
108+ try erpc :call (Node , rabbit_shovel_util , restart_shovel , [VHost , Name ], ? SHOVEL_CALLS_TIMEOUT_MS ) of
109+ ok -> {true , ReqData , Context };
110+ {error , not_found } ->
111+ rabbit_log :error (" Could not find shovel data for shovel '~s ' in vhost: '~s '" , [Name , VHost ]),
112+ {false , ReqData , Context }
113+ catch _ :Reason ->
114+ rabbit_log :error (" Failed to restart shovel '~s ' on vhost '~s ', reason: ~p " ,
115+ [Name , VHost , Reason ]),
116+ {false , ReqData , Context }
96117 end ;
97- Node ->
98- % % We must distinguish between a delete and a restart
99- case is_restart (ReqData ) of
100- true ->
101- rabbit_log :info (" Asked to restart shovel '~ts ' in vhost '~ts ' on node '~s '" , [Name , VHost , Node ]),
102- try erpc :call (Node , rabbit_shovel_util , restart_shovel , [VHost , Name ], ? SHOVEL_CALLS_TIMEOUT_MS ) of
103- ok -> true ;
104- {error , not_found } ->
105- rabbit_log :error (" Could not find shovel data for shovel '~s ' in vhost: '~s '" , [Name , VHost ]),
106- false
107- catch _ :Reason ->
108- rabbit_log :error (" Failed to restart shovel '~s ' on vhost '~s ', reason: ~p " ,
109- [Name , VHost , Reason ]),
110- false
111- end ;
112-
113- _ ->
114- try_delete (Node , VHost , Name , Username ),
115- true
116118
119+ _ ->
120+ case try_delete (Node , VHost , Name , Username ) of
121+ true -> {true , ReqData , Context };
122+ false -> {false , ReqData , Context };
123+ locked -> Reply = cowboy_req :reply (405 , #{<<" content-type" >> => <<" text/plain" >>},
124+ " Protected" , ReqData ),
125+ {halt , Reply , Context };
126+ error -> {false , ReqData , Context }
117127 end
128+
118129 end
119- end ,
120- { Reply , ReqData , Context } .
130+ end
131+ end .
121132
122133% %--------------------------------------------------------------------
123134
@@ -177,8 +188,13 @@ try_delete(Node, VHost, Name, Username) ->
177188 {error , not_found } ->
178189 rabbit_log :error (" Could not find shovel data for shovel '~s ' in vhost: '~s '" , [Name , VHost ]),
179190 false
180- catch _ :Reason ->
191+ catch
192+ _ :{exception , {amqp_error , resource_locked , Reason , _ }} ->
181193 rabbit_log :error (" Failed to delete shovel '~s ' on vhost '~s ', reason: ~p " ,
182194 [Name , VHost , Reason ]),
183- false
195+ locked ;
196+ _ :Reason ->
197+ rabbit_log :error (" Failed to delete shovel '~s ' on vhost '~s ', reason: ~p " ,
198+ [Name , VHost , Reason ]),
199+ error
184200 end .
0 commit comments