summaryrefslogtreecommitdiff
path: root/deps/rabbitmq_shovel_management/priv/www/js/shovel.js
blob: a4f85cb98876c48ef8a95f4a37429df3c23c6b8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
dispatcher_add(function(sammy) {
    sammy.get('#/shovels', function() {
            render({'shovels': {path:    '/shovels',
                                options: {vhost:true}}},
                    'shovels', '#/shovels');
        });
    sammy.get('#/dynamic-shovels', function() {
            render({'shovels': {path:   '/parameters/shovel',
                            options:{vhost:true}},
                    'vhosts': '/vhosts'},
                   'dynamic-shovels', '#/dynamic-shovels');
        });
    sammy.get('#/dynamic-shovels/:vhost/:id', function() {
            render({'shovel': '/parameters/shovel/' + esc(this.params['vhost']) + '/' + esc(this.params['id'])},
                   'dynamic-shovel', '#/dynamic-shovels');
        });
    sammy.put('#/shovel-parameters-move-messages', function() {
            var num_keys = ['src-prefetch-count', 'reconnect-delay'];
            var bool_keys = ['dest-add-forward-headers'];
            var arrayable_keys = ['src-uri', 'dest-uri'];
            var redirect = this.params['redirect'];
            if (redirect !== undefined) {
                delete this.params['redirect'];
            }
            put_parameter(this, [], num_keys, bool_keys, arrayable_keys);
            if (redirect !== undefined) {
                go_to(redirect);
            }
            return false;
        });
    sammy.put('#/shovel-parameters', function() {
            // patch up the protocol selectors
            var src_proto = this.params['src-protocol-selector'];
            this.params['src-protocol'] = src_proto.substr(0, src_proto.indexOf('-'));
            var dest_proto = this.params['dest-protocol-selector'];
            this.params['dest-protocol'] = dest_proto.substr(0, dest_proto.indexOf('-'));

            //remove fields not required by the selected protocol
            if (this.params['src-protocol'] == 'amqp10') {
                remove_params_with(this, 'amqp091-src');
            } else {
                remove_params_with(this, 'amqp10-src');
            }
            if (this.params['dest-protocol'] == 'amqp10') {
                remove_params_with(this, 'amqp091-dest');
            } else {
                remove_params_with(this, 'amqp10-dest');
            }

            var trimProtoPrefix = function (x) {
                if(x.startsWith('amqp10-') || x.startsWith('amqp091-')) {
                    return x.substr(x.indexOf('-') + 1, x.length);
                }
                return x;
            };

            rekey_params(this, trimProtoPrefix);

            var num_keys = ['src-prefetch-count', 'reconnect-delay'];

            //copy the correct delete-after value
            if (this.params['src-delete-after-selector'] == 'never') {
                this.params['src-delete-after'] = 'never';
            } else if (this.params['src-delete-after-selector'] == 'number') {
                num_keys.push('src-delete-after');
            }

            delete this.params['src-delete-after-selector'];

            var bool_keys = ['dest-add-forward-headers'];
            var arrayable_keys = ['src-uri', 'dest-uri'];
            var redirect = this.params['redirect'];
            if (redirect !== undefined) {
                delete this.params['redirect'];
            }
            put_parameter(this, [], num_keys, bool_keys, arrayable_keys);
            if (redirect !== undefined) {
                go_to(redirect);
            }
            return false;
        });
    sammy.del('#/shovel-parameters', function() {
            if (sync_delete(this, '/shovels/vhost/:vhost/:name')) {
                go_to('#/dynamic-shovels');
            } else {
                show_popup('warn', 'Shovel not deleted because it is not running on this node.');
                return false;
            }
        });
    sammy.del("#/shovel-restart-link", function(){
            if (sync_delete(this, '/shovels/vhost/:vhost/:name/restart')) {
                update();
            } else {
                show_popup('warn', 'Shovel not restarted because it is not running on this node.');
                return false;
            }
        });
});


NAVIGATION['Admin'][0]['Shovel Status'] = ['#/shovels', "monitoring"];
NAVIGATION['Admin'][0]['Shovel Management'] = ['#/dynamic-shovels', "policymaker"];

HELP['shovel-uri'] =
    'Both source and destination can be either a local or remote broker. See the "URI examples" pane for examples of how to construct URIs. If connecting to a cluster, you can enter several URIs here separated by spaces.';

HELP['shovel-amqp10-address'] =
    'The AMQP 1.0 address representing the source or target node.'

HELP['shovel-queue-exchange'] =
    'You can set both source and destination as either a queue or an exchange. If you choose "queue", it will be declared beforehand; if you choose "exchange" it will not, but an appropriate binding and queue will be created when the source is an exchange.';

HELP['shovel-prefetch'] =
    'Maximum number of unacknowledged messages that may be in flight over a shovel at one time. Defaults to 1000 if not set.';

HELP['shovel-reconnect'] =
    'Time in seconds to wait after a shovel goes down before attempting reconnection. Defaults to 1 if not set.';

HELP['shovel-forward-headers'] =
    'Whether to add headers to the shovelled messages indicating where they have been shovelled from and to. Defaults to false if not set.';

HELP['shovel-ack-mode'] =
    '<dl>\
       <dt><code>on-confirm</code></dt>\
       <dd>Messages are acknowledged at the source after they have been confirmed at the destination. Handles network errors and broker failures without losing messages. The slowest option, and the default.</dd>\
       <dt><code>on-publish</code></dt>\
       <dd>Messages are acknowledged at the source after they have been published at the destination. Handles network errors without losing messages, but may lose messages in the event of broker failures.</dd>\
       <dt><code>no-ack</code></dt>\
       <dd>Message acknowledgements are not used. The fastest option, but may lose messages in the event of network or broker failures.</dd>\
</dl>';

HELP['shovel-amqp091-auto-delete'] =
    '<dl>\
       <dt><code>Never</code></dt>\
       <dd>The shovel never deletes itself; it will persist until it is explicitly removed.</dd>\
       <dt><code>After initial length transferred</code></dt>\
       <dd>The shovel will check the length of the queue when it starts up. It will transfer that many messages, and then delete itself.</dd>\
</dl>';

HELP['shovel-amqp10-auto-delete'] =
    '<dl>\
       <dt><code>Never</code></dt>\
       <dd>The shovel never deletes itself; it will persist until it is explicitly removed.</dd>\
       <dt><code>After num messages</code></dt>\
       <dd>The shovel will delete itself after the given number of messages have been transferred.</dd>\
</dl>';
function remove_params_with(sammy, prefix) {
    for (var i in sammy.params) {
        if(i.startsWith(prefix)) {
            delete sammy.params[i];
        }
    }
}

function rekey_params(sammy, func) {
    for (var i in sammy.params) {
        var k = func(i);
        if(i != k) {
            var v = sammy.params[i];
            delete sammy.params[i];
            sammy.params[k] = v;
        }
    }
}
function link_shovel(vhost, name) {
    return _link_to(name, '#/dynamic-shovels/' + esc(vhost) + '/' + esc(name));
}

function fmt_shovel_endpoint(prefix, shovel) {
    var txt = '';
    if(shovel[prefix + "protocol"] == 'amqp10') {
        txt += fmt_string(shovel[prefix + 'address']);
    } else {
        if (shovel[prefix + 'queue']) {
            txt += fmt_string(shovel[prefix + 'queue']) + '<sub>queue</sub>';
        } else {
            if (shovel[prefix + 'exchange']) {
                txt += fmt_string(shovel[prefix + 'exchange']);
            } else {
                txt += '<i>as published</i>';
            }
            if (shovel[prefix + 'exchange_key']) {
                txt += ' : ' + fmt_string(shovel[prefix + 'exchange_key']);
            }
            txt += '<sub>exchange</sub>';
        }
    }

    return txt;
}

function fallback_value(shovel, key1, key2) {
    var v = shovel.value[key1];
    return (v !== undefined ? v : shovel.value[key2]);
}