Skip to content

Commit

Permalink
Fixed bugs in cancel session and refresh and added delete session button
Browse files Browse the repository at this point in the history
  • Loading branch information
awicenec committed Aug 21, 2021
1 parent 1090328 commit dde980f
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 22 deletions.
5 changes: 4 additions & 1 deletion daliuge-engine/dlg/manager/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ def getSessions(self):

@daliuge_aware
def getSessionInformation(self, sessionId):
graphDict = self.dm.getGraph(sessionId)
status = self.dm.getSessionStatus(sessionId)
if status[list(status.keys())[0]] > 0: # Pristine state sessions don't have a graph, yet.
graphDict = self.dm.getGraph(sessionId)
else:
graphDict = {}
return {'status': status, 'graph': graphDict}

@daliuge_aware
Expand Down
133 changes: 115 additions & 18 deletions daliuge-engine/dlg/manager/web/static/js/dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ function getRender() {

function loadSessions(serverUrl, tbodyEl, refreshBtn, selectedNode, delay) {

// console.log("Inside loadSessions");
refreshBtn.attr('disabled');

// Support for node query forwarding
var url = serverUrl + '/api';
if( selectedNode ) {
Expand Down Expand Up @@ -152,6 +152,11 @@ function loadSessions(serverUrl, tbodyEl, refreshBtn, selectedNode, delay) {
return "cancelBtn" + hashCode(s);
};

var deleteBtnSessionId = function(s) {
// console.log(hashCode(s))
return "deleteBtn" + hashCode(s);
};

var hashCode = function(s){
return s.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);
}
Expand All @@ -173,7 +178,7 @@ function loadSessions(serverUrl, tbodyEl, refreshBtn, selectedNode, delay) {
rows.exit().transition().delay(0).duration(500).style('opacity',0.0).remove();
rows.enter().append('tr').style('opacity', 0.0).transition().delay(0).duration(500).style('opacity',1.0);

fillDmTable(sessions, tbodyEl, sessionLink, DimSessionLink, cancelBtnSessionId, hashCode);
fillDmTable(sessions, tbodyEl, sessionLink, DimSessionLink, cancelBtnSessionId, deleteBtnSessionId, hashCode);
//progressbars in dim

const width = $('#sessionsTable').find('.status').innerWidth();
Expand Down Expand Up @@ -230,6 +235,7 @@ function loadSessions(serverUrl, tbodyEl, refreshBtn, selectedNode, delay) {
if(currentStatus==="Cancelled"){
$(this).css("color","grey");
$(this).parent().find(".actions").find("button").hide();
$(this).parent().find(".d_actions").find("d_button").show();
$(this).parent().removeClass("progressRunning")
}else if(currentStatus==="Deploying"){
$(this).css("color","blue");
Expand All @@ -238,6 +244,7 @@ function loadSessions(serverUrl, tbodyEl, refreshBtn, selectedNode, delay) {
else if (currentStatus==="Running") {
$(this).text("");
$(this).parent().find(".actions").find("button").show();
$(this).parent().find(".d_actions").find("d_button").hide();
$(this).append("<svg>")
if(!$(this).parent().hasClass('progressRunning')){
startStatusQuery(serverUrl, $(this).parent().find(".id").text(), selectedNode, graph_update_handler,
Expand All @@ -247,9 +254,12 @@ function loadSessions(serverUrl, tbodyEl, refreshBtn, selectedNode, delay) {
}else if (currentStatus==="Finished"){
$(this).css("color","#00af28");
$(this).parent().find(".actions").find("button").hide();
$(this).parent().find(".d_actions").find("d_button").show();
$(this).parent().removeClass("progressRunning")
}else{
$(this).css("color","purple");
$(this).parent().find(".actions").find("button").hide();
$(this).parent().find(".d_actions").find("d_button").show();
$(this).parent().removeClass("progressRunning")
}
})
Expand All @@ -266,7 +276,7 @@ function loadSessions(serverUrl, tbodyEl, refreshBtn, selectedNode, delay) {
});
}

function fillDmTable(sessions, tbodyEl, sessionLink, DimSessionLink, cancelBtnSessionId, hashCode){
function fillDmTable(sessions, tbodyEl, sessionLink, DimSessionLink, cancelBtnSessionId, deleteBtnSessionId, hashCode){
var rows = tbodyEl.selectAll('tr').data(sessions);
var idCells = rows.selectAll('td.id').data(function values(s) { return [s.sessionId]; });
idCells.enter().append('td').classed('id', true).text(String)
Expand Down Expand Up @@ -298,22 +308,43 @@ function fillDmTable(sessions, tbodyEl, sessionLink, DimSessionLink, cancelBtnSe
.attr("type", 'button').attr('class', 'btn btn-secondary').attr('onclick', '(cancel_session(serverUrl,"false",this.id))').text('Cancel')
actionCells.select('button')
actionCells.exit().remove()

var d_actionCells = rows.selectAll('td.d_actions').data(function values(s) { return [s.sessionId]; });
d_actionCells.enter().append('td').classed('d_actions', true)
.append("d_button").attr('id', deleteBtnSessionId)
.attr("type", 'button').attr('class', 'btn btn-secondary').attr('onclick', '(delete_session(serverUrl,"false",this.id))').text('Delete')
d_actionCells.select('d_button')
d_actionCells.exit().remove()
}

function handleFetchErrors(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}

function promptNewSession(serverUrl, tbodyEl, refreshBtn) {
bootbox.prompt("Session ID", function(sessionId) {
if( sessionId == null ) {
return;
}
var xhr = d3.xhr(serverUrl + '/api/sessions');
xhr.header("Content-Type", "application/json");
xhr.post(JSON.stringify({sessionId: sessionId}), function(error, data) {
if( error != null ) {
console.error(error)
bootbox.alert('An error occurred while creating session ' + sessionId + ': ' + error.responseText)
return
}
loadSessions(serverUrl, tbodyEl, refreshBtn, null)
});
fetch(serverUrl + '/api/sessions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({sessionId: sessionId})
})
.then(handleFetchErrors)
.then(function(response){
response => response.json()
loadSessions(serverUrl, tbodyEl, refreshBtn, null)
})
.catch(function(error){
console.error(error)
bootbox.alert('An error occurred while creating session ' + sessionId + ': ' + error.responseText)
return});
});
}

Expand Down Expand Up @@ -595,6 +626,16 @@ function does_status_allow_cancel(status) {
}
}

function sessionId_from_buttonId(buttonId) {
//getting session id from sibling in table using js
button = "#"+buttonId
sessionId = $(button).parent().parent().find("td.details").find('a').attr("href")
sessionId = sessionId.split("=")
sessionId = sessionId[1].split("&")
sessionId = sessionId[0]
return sessionId
}

/**
* Cancel the given sessionId using the provided information.
*
Expand All @@ -607,10 +648,7 @@ function cancel_session(serverUrl,sessionId, buttonId) {
if (sessionId === "false"){
//getting session id from sibling in table using js
button = "#"+buttonId
sessionId = $(button).parent().parent().find("td.details").find('a').attr("href")
sessionId = sessionId.split("=")
sessionId = sessionId[1].split("&")
sessionId = sessionId[0]
sessionId = sessionId_from_buttonId(buttonId)
cancelSessionBtn = $(button)
}else{
cancelSessionBtn = buttonId
Expand All @@ -621,7 +659,7 @@ function cancel_session(serverUrl,sessionId, buttonId) {

d3.json(url).then( function(sessionInfo, error) {

if (error) {
if (error) {
//bootbox.alert(error);
console.error(error);
return;
Expand Down Expand Up @@ -658,3 +696,62 @@ function cancel_session(serverUrl,sessionId, buttonId) {
}
})
}

/**
* Delete the given sessionId using the provided information.
*
* @param serverUrl to use for the REST API
* @param sessionId to delete
* @param deleteSessionBtn that initiated the delete
*/
// function delete_session(serverUrl, sessionId, deleteSessionBtn) {
function delete_session(serverUrl,sessionId, buttonId) {
if (sessionId === "false"){
//getting session id from sibling in table using js
button = "#"+buttonId
sessionId = sessionId_from_buttonId(buttonId)
deleteSessionBtn = $(button)
}else{
deleteSessionBtn = buttonId
}

var url = serverUrl + '/api';
url += '/sessions/' + sessionId;

d3.json(url).then( function(sessionInfo, error) {

if (error) {
//bootbox.alert(error);
console.error(error);
return;
}

if (!does_status_allow_cancel(sessionInfo['status'])) {
bootbox.confirm("Do you really want to delete this session?", function(result){
if (result){

deleteSessionBtn.attr('disabled', null);

d3.json(url, {
method: 'DELETE',
headers: {
"Content-type": "application/json; charset=UTF-8"
},
body: JSON.stringify(function (response, error) {
// We don't expect a response so ignoring it.

if( error ) {
console.log(response)
console.error(error)
return
}
})
});
}
});
} else {
// display an error
bootbox.alert("Can't delete " + sessionId + "! It is still RUNNING.");
}
})
}
6 changes: 3 additions & 3 deletions daliuge-translator/dlg/dropmake/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ async function restDeploy(){
// request pg_spec from translator
const pg_spec_response = await fetch(pg_spec_url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
// headers: {
// 'Content-Type': 'application/json',
// },
body: JSON.stringify(pg_spec_request_data)
})
.then(handleFetchErrors)
Expand Down

0 comments on commit dde980f

Please sign in to comment.