@@ -48,9 +48,15 @@ resource_exists(ReqData, Context) ->
4848 % % Deleting or restarting a shovel
4949 case get_shovel_node (VHost , Name , ReqData , Context ) of
5050 undefined ->
51- rabbit_log :error (" Shovel with the name '~ts ' was not found on virtual host '~ts '" ,
51+ rabbit_log :error (" Shovel with the name '~ts ' was not found on virtual host '~ts '. "
52+ " It may be failing to connect and report its status." ,
5253 [Name , VHost ]),
53- false ;
54+ case is_restart (ReqData ) of
55+ true -> false ;
56+ % % this is a deletion attempt, it can continue and idempotently try to
57+ % % delete the shovel
58+ false -> true
59+ end ;
5460 _ ->
5561 true
5662 end
@@ -73,9 +79,17 @@ delete_resource(ReqData, #context{user = #user{username = Username}}=Context) ->
7379 Name ->
7480 case get_shovel_node (VHost , Name , ReqData , Context ) of
7581 undefined -> rabbit_log :error (" Could not find shovel data for shovel '~ts ' in vhost: '~ts '" , [Name , VHost ]),
76- false ;
82+ case is_restart (ReqData ) of
83+ true ->
84+ false ;
85+ % % this is a deletion attempt
86+ false ->
87+ % % if we do not know the node, use the local one
88+ try_delete (node (), VHost , Name , Username ),
89+ true
90+ end ;
7791 Node ->
78- % % We must distinguish between a delete and restart
92+ % % We must distinguish between a delete and a restart
7993 case is_restart (ReqData ) of
8094 true ->
8195 rabbit_log :info (" Asked to restart shovel '~ts ' in vhost '~ts ' on node '~s '" , [Name , VHost , Node ]),
@@ -91,17 +105,8 @@ delete_resource(ReqData, #context{user = #user{username = Username}}=Context) ->
91105 end ;
92106
93107 _ ->
94- rabbit_log :info (" Asked to delete shovel '~ts ' in vhost '~ts ' on node '~s '" , [Name , VHost , Node ]),
95- try erpc :call (Node , rabbit_shovel_util , delete_shovel , [VHost , Name , Username ], ? SHOVEL_CALLS_TIMEOUT_MS ) of
96- ok -> true ;
97- {error , not_found } ->
98- rabbit_log :error (" Could not find shovel data for shovel '~s ' in vhost: '~s '" , [Name , VHost ]),
99- false
100- catch _ :Reason ->
101- rabbit_log :error (" Failed to delete shovel '~s ' on vhost '~s ', reason: ~p " ,
102- [Name , VHost , Reason ]),
103- false
104- end
108+ try_delete (Node , VHost , Name , Username ),
109+ true
105110
106111 end
107112 end
@@ -150,3 +155,18 @@ find_matching_shovel(VHost, Name, Shovels) ->
150155 _ ->
151156 undefined
152157 end .
158+
159+ -spec try_delete (node (), vhost :name (), any (), rabbit_types :username ()) -> boolean ().
160+ try_delete (Node , VHost , Name , Username ) ->
161+ rabbit_log :info (" Asked to delete shovel '~ts ' in vhost '~ts ' on node '~s '" , [Name , VHost , Node ]),
162+ % % this will clear the runtime parameter, the ultimate way of deleting a dynamic Shovel eventually. MK.
163+ try erpc :call (Node , rabbit_shovel_util , delete_shovel , [VHost , Name , Username ], ? SHOVEL_CALLS_TIMEOUT_MS ) of
164+ ok -> true ;
165+ {error , not_found } ->
166+ rabbit_log :error (" Could not find shovel data for shovel '~s ' in vhost: '~s '" , [Name , VHost ]),
167+ false
168+ catch _ :Reason ->
169+ rabbit_log :error (" Failed to delete shovel '~s ' on vhost '~s ', reason: ~p " ,
170+ [Name , VHost , Reason ]),
171+ false
172+ end .
0 commit comments