Skip to content

Commit 07ac152

Browse files
committed
Management part for internal shovels. Experimenting with owner linking
1 parent 7a34bf8 commit 07ac152

File tree

5 files changed

+104
-45
lines changed

5 files changed

+104
-45
lines changed

deps/rabbit/src/rabbit_runtime_parameters.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ parse_set(VHost, Component, Name, String, User) ->
8989
set(_, <<"policy">>, _, _, _) ->
9090
{error_string, "policies may not be set using this method"};
9191
set(VHost, Component, Name, Term, User) ->
92+
io:format("qweqwe ~p", [{VHost, Component, Name, Term, User}]),
9293
set_any(VHost, Component, Name, Term, User).
9394

9495
parse_set_global(Name, String, ActingUser) ->

deps/rabbitmq_management/priv/www/js/formatters.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,3 +1094,15 @@ function fmt_deprecation_phase(phase, deprecation_phases){
10941094
}
10951095
}
10961096
}
1097+
1098+
function fmt_resource(res) {
1099+
return `${res.kind} '${res.name}' in vhost '${res.virtual_host}'`;
1100+
}
1101+
1102+
function fmt_resource_link(res) {
1103+
if (res.kind == "queue") {
1104+
return `${res.kind} '${link_queue(res.virtual_host, res.name, {})}' in vhost '${link_vhost(res.virtual_host)}'`;
1105+
} else if (res.kind == "exchange") {
1106+
return `${res.kind} '${link_exchange(res.virtual_host, res.name, {})}' in vhost '${link_vhost(res.virtual_host)}'`;
1107+
}
1108+
}

deps/rabbitmq_shovel_management/priv/www/js/shovel.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,27 @@ function fmt_shovel_endpoint(prefix, shovel) {
206206
return txt;
207207
}
208208

209+
function is_internal_shovel(shovel) {
210+
if (!shovel.hasOwnProperty('internal')) {
211+
return false;
212+
} else {
213+
return shovel['internal'];
214+
}
215+
}
216+
217+
function shovel_has_internal_owner(shovel) {
218+
if (!shovel.hasOwnProperty('internal_owner')) {
219+
return false;
220+
} else {
221+
return true;
222+
}
223+
}
224+
225+
function shovel_internal_owner(shovel) {
226+
return shovel.internal_owner;
227+
}
228+
229+
209230
function fallback_value(shovel, key1, key2) {
210231
var v = shovel.value[key1];
211232
return (v !== undefined ? v : shovel.value[key2]);

deps/rabbitmq_shovel_management/priv/www/js/tmpl/dynamic-shovel.ejs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,23 @@
4444
</div>
4545
</div>
4646

47-
<div class="section-hidden">
47+
48+
<div class="section-hidden">
4849
<h2>Delete this shovel</h2>
4950
<div class="hider">
50-
<form action="#/shovel-parameters" method="delete" class="confirm">
51-
<input type="hidden" name="component" value="shovel"/>
52-
<input type="hidden" name="vhost" value="<%= fmt_string(shovel.vhost) %>"/>
53-
<input type="hidden" name="name" value="<%= fmt_string(shovel.name) %>"/>
54-
<input type="submit" value="Delete this shovel"/>
55-
</form>
51+
<% if (!is_internal_shovel(shovel.value)) { %>
52+
<form action="#/shovel-parameters" method="delete" class="confirm">
53+
<input type="hidden" name="component" value="shovel"/>
54+
<input type="hidden" name="vhost" value="<%= fmt_string(shovel.vhost) %>"/>
55+
<input type="hidden" name="name" value="<%= fmt_string(shovel.name) %>"/>
56+
<input type="submit" value="Delete this shovel"/>
57+
</form>
58+
<% } else { %>
59+
<% if (shovel_has_internal_owner(shovel.value)) { %>
60+
<span>This shovel is internal and owned by <%= fmt_resource_link(shovel_internal_owner(shovel.value)) %>. Could be deleted only via CLI command with --force.</span>
61+
<% } else { %>
62+
<span>This shovel is internal. Could be deleted only via CLI command with '--force'.</span>
63+
<% } %>
64+
<% } %>
65+
</div>
5666
</div>
57-
</div>

deps/rabbitmq_shovel_management/src/rabbit_shovel_mgmt_shovel.erl

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,45 +79,56 @@ is_authorized(ReqData, Context) ->
7979

8080
delete_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

Comments
 (0)