Skip to content

Commit

Permalink
Merge pull request #201 from ICRAR/LIU-285
Browse files Browse the repository at this point in the history
Liu 285 - Rebuilt lg_web with FastAPI
  • Loading branch information
pritchardn committed Sep 30, 2022
2 parents 92cfff7 + fbb50fb commit 25fab6e
Show file tree
Hide file tree
Showing 13 changed files with 1,213 additions and 83 deletions.
1 change: 1 addition & 0 deletions daliuge-translator/dlg/dropmake/web/graph_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function graphInit(graphType){
success: function(data) {
// get node count
var nodeCount = 0;
data = JSON.parse(data);
data.nodeDataArray.forEach(element => {
nodeCount++
});
Expand Down
55 changes: 2 additions & 53 deletions daliuge-translator/dlg/dropmake/web/lg_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,14 @@
from dlg.dropmake.pgt import GPGTException
from dlg.dropmake.scheduler import SchedulerException
from jsonschema import validate, ValidationError
from translator_utils import lg_path, lg_exists, pgt_path, pgt_exists, lg_repo_contents, \
pgt_repo_contents, file_as_string, prepare_lgt

logger = logging.getLogger(__name__)

# Patched to be larger to accomodate large config drops
bottle.BaseRequest.MEMFILE_MAX = 1024 * 512


def file_as_string(fname, package=__name__, enc="utf8"):
b = pkg_resources.resource_string(package, fname) # @UndefinedVariable
return common.b2s(b, enc)


# lg_dir = None
post_sem = threading.Semaphore(1)
gen_pgt_sem = threading.Semaphore(1)
Expand All @@ -99,49 +95,6 @@ def file_as_string(fname, package=__name__, enc="utf8"):
LG_SCHEMA = json.loads(file_as_string("lg.graph.schema", package="dlg.dropmake"))


def lg_path(lg_name):
return "{0}/{1}".format(lg_dir, lg_name)


def lg_exists(lg_name):
return os.path.exists(lg_path(lg_name))


def pgt_path(pgt_name):
return "{0}/{1}".format(pgt_dir, pgt_name)


def pgt_exists(pgt_name):
return os.path.exists(pgt_path(pgt_name))


def lg_repo_contents():
return _repo_contents(lg_dir)


def pgt_repo_contents():
return _repo_contents(pgt_dir)


def _repo_contents(root_dir):
# We currently allow only one depth level
b = os.path.basename
contents = {}
for dirpath, dirnames, fnames in os.walk(root_dir):
if ".git" in dirnames:
dirnames.remove(".git")
if dirpath == root_dir:
continue

# Not great yet -- we should do a full second step pruning branches
# of the tree that are empty
files = [f for f in fnames if f.endswith(".graph")]
if files:
contents[b(dirpath)] = files

return contents


@route("/static/<filepath:path>")
def server_static(filepath):
staticRoot = pkg_resources.resource_filename(
Expand Down Expand Up @@ -504,10 +457,6 @@ def gen_pg_spec():
return "Fail to generate pg_spec: {0}".format(ex)


def prepare_lgt(filename, rmode: str):
return init_lg_repro_data(init_lgt_repro_data(load_lg(filename), rmode))


@get("/gen_pgt")
def gen_pgt():
"""
Expand Down
4 changes: 2 additions & 2 deletions daliuge-translator/dlg/dropmake/web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,15 @@ async function restDeploy() {
// fetch the PGT from this server
console.log("sending request to ", pgt_url);
console.log("graph name:", pgtName);
const pgt = await fetch(pgt_url, {
let pgt = await fetch(pgt_url, {
method: 'GET',
})
.then(handleFetchErrors)
.then(response => response.json())
.catch(function (error) {
showMessageModal('Error', error + "\nGetting PGT unsuccessful: Unable to continue!");
});

pgt = JSON.parse(pgt);
// This is for a deferred start of daliuge, e.g. on SLURM
console.log("sending request to ", create_slurm_url);
var body = [pgtName, pgt]; // we send the name in the body with the pgt
Expand Down
3 changes: 0 additions & 3 deletions daliuge-translator/dlg/dropmake/web/matrix_vis.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,3 @@
<body onload="init()">

</body>


</script>
3 changes: 2 additions & 1 deletion daliuge-translator/dlg/dropmake/web/pg_viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarExportDropdown">
<a href="javascript:void(0)" class="dropdown-item" onclick="$('#aboutModal').modal('toggle')">About</a>
<a href="https://daliuge.readthedocs.io/en/latest/basics.html#translator-service%22%3EDALiuGE" target="_blank" class="dropdown-item">Online Docs</a>
<a href="/docs" target="_blank" class="dropdown-item">Live Translator Docs</a>
<a href="https://daliuge.readthedocs.io/en/latest/basics.html#translator-service%22%3EDALiuGE" target="_blank" class="dropdown-item">Online DALiuGE Docs</a>
<a href="javascript:void(0)" class="dropdown-item" onclick="$('#shortcutsModal').modal('toggle')">Keyboard Shortcuts [K]</a>
</div>
</li>
Expand Down

0 comments on commit 25fab6e

Please sign in to comment.