Skip to content

Commit

Permalink
Merge dde0028 into 8f146c1
Browse files Browse the repository at this point in the history
  • Loading branch information
james-strauss-uwa committed Oct 5, 2020
2 parents 8f146c1 + dde0028 commit 855f380
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 18 deletions.
10 changes: 10 additions & 0 deletions daliuge-translator/dlg/dropmake/cwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import cwlgen

from dlg import common
from dlg.common import Categories

# the following node categories are not supported by the CWL translator
UNSUPPORTED_CATEGORIES = [Categories.COMPONENT, Categories.MPI, Categories.DYNLIB_APP, Categories.DYNLIB_PROC_APP, Categories.DOCKER]

#from ..common import dropdict, get_roots
logger = logging.getLogger(__name__)
Expand All @@ -47,6 +50,13 @@ def create_workflow(drops, cwl_filename, buffer):
Non-BashShellApp nodes are unable to be implemented in CWL
"""

# search the drops for non-BashShellApp drops,
# if found, the graph cannot be translated into CWL
for index, node in enumerate(drops):
dataType = node.get('dt', '')
if dataType in UNSUPPORTED_CATEGORIES:
raise Exception('Node {0} has an unsupported category: {1}'.format(index, dataType))

# create list for command line tool description files
step_files = []

Expand Down
6 changes: 5 additions & 1 deletion daliuge-translator/dlg/dropmake/web/lg_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ def pgtcwl_get():
# create the workflow
import io
buffer = io.BytesIO()
create_workflow(pgtp.drops, cwl_filename, buffer)
try:
create_workflow(pgtp.drops, cwl_filename, buffer)
except Exception as e:
response.status = 400 # HTTP 400 Bad Request
return e

# respond with download of ZIP file
response.content_type = 'application/zip'
Expand Down
49 changes: 34 additions & 15 deletions daliuge-translator/dlg/dropmake/web/pg_viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -481,22 +481,41 @@
}
}

function getCWLZipFilenameFromResponseURL(url){
const FILE_NAME_PREFIX = "pgt_name=";
return url.substring(url.lastIndexOf(FILE_NAME_PREFIX) + FILE_NAME_PREFIX.length, url.lastIndexOf('.graph')) + ".zip";
}

function makeCWL() {
//given a logical graph name, get its CWL from the server
$.ajax({
url: "/pgt_cwl?pgt_name={{pgt_view_json_name}}",
type: 'get',
error: function(XMLHttpRequest, textStatus, errorThrown) {
if (404 == XMLHttpRequest.status) {
console.error('Server cannot locate physical graph file {{pgt_view_json_name}}');
} else {
console.error('status:' + XMLHttpRequest.status + ', status text: ' + XMLHttpRequest.statusText);
}
},
success: function(data){
console.log("success", data);
var fileName = "";
var error = "";

fetch('/pgt_cwl?pgt_name={{pgt_view_json_name}}')
.then(async resp => {

// if fetch was not successful, await the error message in the body of the response
if (resp.status !== 200){
error = await resp.text();
return;
}
});

// otherwise, re-generate a filename for the download
filename = getCWLZipFilenameFromResponseURL(resp.url);

return resp.blob();
})
.then(blob => {
// build an object URL from the response and 'download' it
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch(() => alert(error)); // present error, if it occurred
}

function zoomToFit() {
Expand Down Expand Up @@ -570,7 +589,7 @@
<button id="gantt_button" class="button" onclick="genGanttChart()">Produce Gantt Chart</button>
<button id="schedule_button" class="button" onclick="genScheduleChart()">Produce Schedule Matrix</button>
<button id="png_button" class="button" onclick="makePNG()">Export to PNG</button>
<button id="cwl_button" class="button" onclick="window.location.href='/pgt_cwl?pgt_name={{pgt_view_json_name}}'">Export to CWL</button>
<button id="cwl_button" class="button" onclick="makeCWL()">Export to CWL</button>
<button id="zoom_button" class="button" onclick="zoomToFit()">Zoom to Fit</button>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions daliuge-translator/dlg/translator/tool_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,11 @@ def cwl(parser, args):
from ..dropmake.cwl import create_workflow

# write to file
with _open_o(opts.output, "wb") as f:
create_workflow(pgt, "workflow.cwl", f)
try:
with _open_o(opts.output, "wb") as f:
create_workflow(pgt, "workflow.cwl", f)
except Exception as e:
logger.error(e)

def register_commands():
tool.cmdwrap('lgweb', 'A Web server for the Logical Graph Editor', 'dlg.dropmake.web.lg_web:run')
Expand Down

0 comments on commit 855f380

Please sign in to comment.