Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to declare bad files in the WebUI : Closes #2173 #2214

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rucio/core/permission/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Authors:
# - Vincent Garonne <vgaronne@gmail.com>, 2016
# - Martin Barisits <martin.barisits@cern.ch>, 2016-2018
# - Cedric Serfon <cedric.serfon@cern.ch>, 2016-2018
# - Cedric Serfon <cedric.serfon@cern.ch>, 2016-2019
# - Mario Lassnig <mario.lassnig@cern.ch>, 2018
# - Hannes Hansen <hannes.jakob.hansen@cern.ch>, 2018-2019
#
Expand Down Expand Up @@ -1031,9 +1031,9 @@ def perm_add_bad_pfns(issuer, kwargs):
:param kwargs: List of arguments for the action.
:returns: True if account is allowed, otherwise False
"""
if kwargs['state'] in [BadPFNStatus.BAD, BadPFNStatus.TEMPORARY_UNAVAILABLE]:
if kwargs['state'] in [str(BadPFNStatus.BAD), str(BadPFNStatus.TEMPORARY_UNAVAILABLE)]:
is_cloud_admin = bool([acc_attr for acc_attr in list_account_attributes(account=issuer) if (acc_attr['key'].startswith('cloud-')) and (acc_attr['value'] == 'admin')])
return issuer == 'root' or has_account_attribute(account=issuer, key='admin') or is_cloud_admin
elif kwargs['state'] == BadPFNStatus.SUSPICIOUS:
elif kwargs['state'] == str(BadPFNStatus.SUSPICIOUS):
return True
return issuer == 'root'
72 changes: 71 additions & 1 deletion lib/rucio/web/ui/static/rucio.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* - Mario Lassnig, <mario.lassnig@cern.ch>, 2014-2015
* - Thomas Beermann, <thomas.beermann@cern.ch>, 2014-2017
* - Martin Barisits, <martin.barisits@cern.ch>, 2014
* - Cedric Serfon, <cedric.serfon@cern.ch>, 2015-2017
* - Cedric Serfon, <cedric.serfon@cern.ch>, 2015-2019
* - Stefan Prenner, <stefan.prenner@cern.ch>, 2018
*/

Expand Down Expand Up @@ -1235,6 +1235,76 @@ RucioClient.prototype.get_bad_replicas_summary = function(options) {
});
};

/* get the suspicious files summary */
RucioClient.prototype.get_suspicious_files = function(options) {
//check_token();
var url = this.url + '/replicas/suspicious/';
if (options.rse_expression != "" || options.younger_than != "" || options.nattempts != "") {
url += "?";
}
if (options.rse_expression != "" && options.rse_expression != undefined) {
url += 'rse_expression=' + options.rse_expression +'&';
}
if (options.younger_than != "" && options.younger_than != undefined) {
url += 'younger_than=' + options.younger_than + '&';
}
if (options.nattempts != "" && options.nattempts != undefined) {
url += 'nattempts=' + options.nattempts + '&';
}
if (options.rse_expression != "" || options.from_date != "" || options.to_date != "") {
url = url.slice(0, -1);
}
console.log(url);
console.log(this.headers);
jQuery.ajax({url: url,
crossDomain: true,
headers: this.headers,
dataType: 'json',
type: 'GET',
success: function(data)
{
options.success(data);
},
error: function(jqXHR, textStatus, errorThrown)
{
options.error(jqXHR, textStatus, errorThrown);
}
});
};

/* Declare bad PFNs */
RucioClient.prototype.declare_bad_pfns = function(options) {
//check_token();
var url = this.url + '/replicas/bad/pfns/';
if (options.pfns == '') { options.pfns = []; };
if (options.reason == '') { options.reason = 'LOST'; };
if (options.state == '') { options.state = null; };
if (options.expires_at == '') { options.expires_at = null; };
console.log(url);
console.log(this.headers);
console.log(options);
jQuery.ajax({url: url,
crossDomain: true,
headers: this.headers,
type: 'POST',
dataType: 'text',
data: JSON.stringify({
'pfns' : options.pfns,
'reason': options.reason,
'state': options.state,
'expires_at': options.expires_at
}),
success: function(data)
{
options.success(data);
},
error: function(jqXHR, textStatus, errorThrown)
{
options.error(jqXHR, textStatus, errorThrown);
}
});
};

/* list all heartbeats */
RucioClient.prototype.list_heartbeats = function(options) {
check_token();
Expand Down
81 changes: 78 additions & 3 deletions lib/rucio/web/ui/static/suspicious_replicas.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,55 @@ $(document).ready(function(){
younger_than: from_date,
success: function(data) {
$('#loader').html('');
var bad_replicas = Array();
var bad_pfns = Object();
$.each(data, function(index, value) {
var html_checkbox = '<input type="checkbox" class="inline" name="' + value.scope + ',' + value.name + ',' + value.rse + '">';
value['selected'] = html_checkbox;
});

var tbl_head = '<thead><tr><th>Scope</th><th>Name</th><th>RSE</th><th>Created_at</th><th>Count</th></tr></thead>';
var tbl_foot = '<tfoot><tr><th>Scope</th><th>Name</th><th>RSE</th><th>Created_at</th><th>Count</th></tr></foot>';
var tbl_head = '<thead><tr><th>Declare bad</th><th>Scope</th><th>Name</th><th>RSE</th><th>Created_at</th><th>Count</th></tr></thead>';
var tbl_foot = '<tfoot><tr><th>Declare bad</th><th>Scope</th><th>Name</th><th>RSE</th><th>Created_at</th><th>Count</th></tr></foot>';
$("#suspiciousreplicas").remove();
$("#suspiciousreplicas2").append('<table id="suspiciousreplicas" style="word-wrap: break-word;">'+tbl_head+tbl_foot+'</table>');

var download = '<a href="data:application/octet-stream;base64,' + btoa(JSON.stringify(data)) + '" download="dump.json">download as JSON</a>';
$('#downloader').html(download);
dt = $('#suspiciousreplicas').DataTable({
data: data,
columns: [{'data': 'scope'},
columns: [{
'className': 'bad_replicas',
'orderable': false,
'data': 'selected',
'defaultContent': ''
},
{'data': 'scope'},
{'data': 'name'},
{'data': 'rse'},
{'data': 'created_at'},
{'data': 'cnt'}]
});
$('#suspiciousreplicas tbody').on('change', 'td.bad_replicas', function () {
var tr = $(this).closest('tr');
var checkbox = tr.children()[0].firstChild;
if (checkbox.checked == true){
bad_replicas.push(checkbox.name);
var scope = checkbox.name.split(',')[0];
var name = checkbox.name.split(',')[1];
var rse = checkbox.name.split(',')[2];
r.list_replicas({
'scope': scope,
'name': name,
success: function(replicas) {
bad_pfns[checkbox.name] = replicas[0].rses[rse][0];
}
});
}
else{
bad_replicas.pop(checkbox.name);
}
});
$('#declare_bad').html('<input id="submit_button2" type="button" value="Declare bad replicas">');
var suspicious_replicas = {};
var series = [];
$.each( data, function(index, value ) {
Expand Down Expand Up @@ -142,6 +175,48 @@ $(document).ready(function(){
title: { text: 'Creation date of the replicas' },
series: series
});

$("#submit_button2").click(function(){
list_pfns = Array();
$.each(bad_replicas, function(index, value) {
if (value in bad_pfns){
list_pfns.push(bad_pfns[value]);
}
});
console.log(list_pfns);
$("#dialogform").html('Will declare ' + list_pfns.length + ' files lost. <br>Please provide a reason for the loss<br><form><label for="reason">Reason</label><input type="text" name="Reason" id="reason" value="Lost" class="text ui-widget-content ui-corner-all"></form>');
dialog = $("#dialogform").dialog({
autoOpen: false,
height: 400,
width: 350,
modal: true,
title: "Bad replicas declaration",
buttons: {
Yes: function(){
process_request = true;
r.declare_bad_pfns({
"pfns": list_pfns,
"reason": $("#dialogform").find("form")[0][0].value,
"state": "BAD",
success: function(data) {
console.log('Bad files declared');
dialog.dialog( "close");
$("#alert_box").html('<div data-alert class="alert-box success radius">The files have been successfully declared bad.</div>');
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Could not declare bad files: ' + textStatus);
console.log(errorThrown);
dialog.dialog( "close");
}
});
},
Cancel: function() {
dialog.dialog( "close" );
}
}
});
dialog.dialog( "open" );
});
}
});
});
Expand Down
14 changes: 12 additions & 2 deletions lib/rucio/web/ui/templates/suspicious_replicas.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
$var script: <script src="/static/suspicious_replicas.js"></script>


<div id="alert_box">
<div id="result" class="row" data-equalizer>
<div id="State" class="columns panel">
<h4>Suspicious Replicas</h4>
<div id="loader"></div>
<div id="dialogform" title="Declare bad replica">
</div>

<div class="row">
<div class="large-6 columns">
<table id="datepicker" style="table-layout:fixed; width:auto;">
Expand Down Expand Up @@ -52,8 +56,14 @@ <h4>Suspicious Replicas</h4>
</div>
<br>
</div>

<input id="submit_button" type="button" value="Retrieve results">
<div class="row">
<div class="large-3 column">
<input id="submit_button" type="button" value="Retrieve results">
</div>
<div class="large-3 column">
<div id="declare_bad"></div>
</div>
</div>

</div>
<div class="large-6 columns">
Expand Down