Skip to content

Commit

Permalink
Updated to verify status before cancel
Browse files Browse the repository at this point in the history
Now verifies status before trying to cancel and will give an error if
it is attempted. Moved most code into dm.js in preparation for adding
similar code to dm.html.
  • Loading branch information
markaboulton committed Feb 1, 2019
1 parent 499eaa2 commit ec107cf
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 23 deletions.
28 changes: 6 additions & 22 deletions dlg/manager/web/session.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<title>Session '{{sessionId}}'</title>
<script src="/static/js/d3/d3.v3.min.js"></script>
<script src="/static/js/d3/dagre-d3.min.js"></script>
<script src="/static/js/jquery-1.11.3.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/bootbox.min.js"></script>
<script src="/static/js/dm.js"></script>
<link href="/static/css/session.css" rel="stylesheet" type="text/css"/>
<link href="/static/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
Expand Down Expand Up @@ -58,8 +61,6 @@ <h4>Status: <span id="session-status"></span></h4>
<script>


var cancelSessionBtn = d3.select('#cancelBtn');


function view_as_graph(sessionId, selectedNode, serverUrl) {

Expand Down Expand Up @@ -142,39 +143,22 @@ <h4>Status: <span id="session-status"></span></h4>
}
startStatusQuery(serverUrl, sessionId, selectedNode, f, 1000);
}
var cancelSessionBtn = d3.select('#cancelBtn');

function cancel_session(serverUrl, sessionId) {

console.log("test")
var url = serverUrl + '/api';
url += '/sessions/' + sessionId + '/cancel';
cancelSessionBtn.attr('disabled', null);

d3.json(url).post(function (error, response){
if( error ) {
console.error(error)
return
}

cancelSessionBtn.attr('disabled', null);
});
}


(function(){

/* URL parameters: sessionId, selected node and view mode */
var sessionId = '{{sessionId}}';
var selectedNode = '{{selectedNode}}';
var viewMode = '{{viewMode}}';
var cancelSessionBtn = d3.select('#cancelBtn');

if( sessionId == '' ) { sessionId = null; }
if( selectedNode == '' ) { selectedNode = null; }
if( viewMode == '' ) { viewMode = null; }
if( !viewMode || (viewMode != 'list' && viewMode != 'graph') ) { viewMode = 'graph'; }

// Listeners for the cancelSession button
cancelSessionBtn.on('click', function(){ cancel_session(serverUrl, sessionId); } );
cancelSessionBtn.on('click', function(){ cancel_session(serverUrl, sessionId, cancelSessionBtn); } );

/* Nothing to do, sorry */
if( sessionId == null ) {
Expand Down
60 changes: 59 additions & 1 deletion dlg/manager/web/static/js/dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,62 @@ function startGraphStatusUpdates(serverUrl, sessionId, selectedNode, delay) {
return true;
}
d3.timer(updateStates);
}
}

/**
* Determine, based on the numerical status, if the associated session can be cancelled.
*
* @param status the numerical status of the associated session.
* @returns {boolean} true if it can be cancelled and false otherwise.
*/
function does_status_allow_cancel(status) {
// During RUNNING we can cancel
if (status == 3) {
return true;
} else {
return false;
}
}

/**
* Cancel the given sessionId using the provided information.
*
* @param serverUrl to use for the REST API
* @param sessionId to cancel
* @param cancelSessionBtn that initiated the cancel
*/
function cancel_session(serverUrl, sessionId, cancelSessionBtn) {

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

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

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

if (does_status_allow_cancel(sessionInfo['status'])) {
bootbox.alert("Cdoes_state_all_cancel was true");
url += '/cancel';
cancelSessionBtn.attr('disabled', null);

d3.json(url).post(function (error, response) {
// We don't expect a response so ignoring it.

if( error ) {
console.error(error)
return
}

cancelSessionBtn.attr('disabled', null);
});

} else {
// display an error
bootbox.alert("Can't cancel " + sessionId + " unless it is RUNNING.");
}
})
}

0 comments on commit ec107cf

Please sign in to comment.