Skip to content

Commit

Permalink
LIU-308: Ensure drop precious flag is still handled
Browse files Browse the repository at this point in the history
To ensure backwards compatibility rename it to persist when constructing
the drop instances. We also could add duplicated logic to do this during
translation from LG->PG, however we still need to handle this here as
old PGs might still have the flag. Additionally there don't seem to be
any obvious locations in the translator to add this logic as it is
exclusively dealing with graph traversal and just passes through any
properties is doesn't deal with straight through to the PG.
  • Loading branch information
juliancarrivick committed Oct 24, 2022
1 parent 897d79f commit 9f2a0b6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
4 changes: 2 additions & 2 deletions daliuge-engine/dlg/droputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def copyDropContents(source: DataDROP, target: DataDROP, bufsize=65536):
return


def getUpstreamObjects(drop):
def getUpstreamObjects(drop: AbstractDROP):
"""
Returns a list of all direct "upstream" DROPs for the given+
DROP. An DROP A is "upstream" with respect to DROP B if
Expand All @@ -179,7 +179,7 @@ def getUpstreamObjects(drop):
In practice if A is an upstream DROP of B means that it must be moved
to the COMPLETED state before B can do so.
"""
upObjs = []
upObjs: list[AbstractDROP] = []
if isinstance(drop, AppDROP):
upObjs += drop.inputs
upObjs += drop.streamingInputs
Expand Down
18 changes: 15 additions & 3 deletions daliuge-engine/dlg/graph_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .common import Categories
from .ddap_protocol import DROPRel, DROPLinkType
from .drop import (
AbstractDROP,
ContainerDROP,
LINKTYPE_NTO1_PROPERTY,
LINKTYPE_1TON_APPEND_METHOD,
Expand Down Expand Up @@ -326,7 +327,7 @@ def createGraphFromDropSpecList(dropSpecList, session=None):

# We're done! Return the roots of the graph to the caller
logger.info("Calculating graph roots")
roots = []
roots: list[AbstractDROP] = []
for drop in drops.values():
if not droputils.getUpstreamObjects(drop):
roots.append(drop)
Expand All @@ -345,7 +346,7 @@ def _createData(dropSpec, dryRun=False, session=None):
module = importlib.import_module(".".join(parts[:-1]))
storageType = getattr(module, parts[-1])
else:
# Fall back to old behaviour or to FileDROP
# Fall back to old behaviour or to FileDROP
# if nothing else is specified
if "storage" in dropSpec:
storageType = STORAGE_TYPES[dropSpec["storage"]]
Expand Down Expand Up @@ -424,18 +425,29 @@ def _getIds(dropSpec):


def _getKwargs(dropSpec):
kwargs = dict(dropSpec)

REMOVE = [
"oid",
"uid",
"app",
"appclass",
]
kwargs = dict(dropSpec)
for kw in REMOVE:
if kw in kwargs:
del kwargs[kw]

RENAME = {
"precious": "persist",
}
for find, replace in RENAME.items():
if find in kwargs:
kwargs[replace] = kwargs[find]
del kwargs[find]

for name, spec in dropSpec.get("applicationArgs", dict()).items():
kwargs[name] = spec["value"]

return kwargs


Expand Down
23 changes: 23 additions & 0 deletions daliuge-engine/test/test_graph_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,26 @@ def test_applicationArgs(self):
self.assertEqual(app.integer, True)
self.assertEqual(app.low, 34)
self.assertEqual(app.high, 3456)

def test_backwardsCompatibilityWithPreciousFlag(self):
"""
Ensure that precious is detected and exposed as the persist flag
"""
testCases = [
("precious", True),
("precious", False),
("persist", True),
("persist", False),
(None, False), # Default of False is specific to MemoryDrops
]
for key, value in testCases:
with self.subTest(key=key, value=value):
dropSpec = {"oid": "A", "type": "data", "storage": Categories.MEMORY}
if key is not None:
dropSpec[key] = value

graph = graph_loader.createGraphFromDropSpecList([dropSpec])
data = graph[0]
self.assertIsInstance(data, InMemoryDROP)
self.assertEqual(value, data.persist)
self.assertFalse(hasattr(data, 'precious'))
7 changes: 7 additions & 0 deletions daliuge-translator/dlg/dropmake/lg.graph.schema
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@
"expanded": {
"type": "boolean"
},
"precious": {
"type": "boolean",
"deprecated": true
},
"persist": {
"type": "boolean"
},
"inputApplicationName": {
"type": "string"
},
Expand Down

0 comments on commit 9f2a0b6

Please sign in to comment.