Skip to content

Commit

Permalink
LIU-375: Move named input port mapping to data_base.py
Browse files Browse the repository at this point in the history
Based on @awicenec feedback in CR to expand what drops can access this feature.
  • Loading branch information
myxie committed Jun 14, 2024
1 parent 353a974 commit 80b8bc5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 64 deletions.
65 changes: 65 additions & 0 deletions daliuge-engine/dlg/data/drops/data_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,71 @@ def checksumType(self, value):
)
self._checksumType = value

def _map_input_ports_to_params(self):
"""
Map the input ports that are on this FileDrop to the Drop parameters
This method performs the following steps:
- Iterate through each producer, finding the portname and value of the
port associated with that producers
- Iterate through the input port names of _this_ drop, and match the UID
and name to the producer map, and then getting the value.
- Finally, match the value of the named input drop with a DROP parameter (
if it exists).
"""

try:
dropInputPorts = self.parameters['producers']
except KeyError:
logging.debug("No producers available for drop: %s", self.uid)
return

producerPortValueMap = {} # Map Producer UIDs to a portname
finalDropPortMap = {} # Final mapping of named port to value stored in producer

for p in self.producers:
params = p.parameters['outputs']
for param in params:
try:
key = list(param.keys())[0]
except AttributeError:
logging.debug("Producer %s does not have named ports", p.uid)
continue
portName = param[key]
portValue = ""
producerUid = p.uid
if portName in p.parameters:
portValue = p.parameters[param[key]]
# TODO This currently only allows 1 UID -> Portname/Value
# Investigate UID -> [Portname1:Value1, Portnam2:value2,..,]
producerPortValueMap[producerUid] = {"portname": portName,
"value": portValue}

for port in dropInputPorts:
try:
port.items()
except AttributeError:
logging.debug("Producer %s does not have named ports", p.uid)
continue
for uid, portname in port.items():
try:
print(uid, portname)
tmp = producerPortValueMap[uid]
if tmp['portname'] == portname:
finalDropPortMap[portname] = tmp['value']
except KeyError:
print("Not available")

for portname in finalDropPortMap:
if portname in self.parameters:
self.parameters[portname] = finalDropPortMap[portname]

self._updatedPorts = True


@abstractmethod
def getIO(self) -> DataIO:
"""
Expand Down
64 changes: 0 additions & 64 deletions daliuge-engine/dlg/data/drops/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,70 +172,6 @@ def getIO(self):

return FileIO(self._path)

def _map_input_ports_to_params(self):
"""
Map the input ports that are on this FileDrop to the Drop parameters
This method performs the following steps:
- Iterate through each producer, finding the portname and value of the
port associated with that producers
- Iterate through the input port names of _this_ drop, and match the UID
and name to the producer map, and then getting the value.
- Finally, match the value of the named input drop with a DROP parameter (
if it exists).
"""

try:
dropInputPorts = self.parameters['producers']
except KeyError:
logging.debug("No producers available for drop: %s", self.uid)
return

producerPortValueMap = {} # Map Producer UIDs to a portname
finalDropPortMap = {} # Final mapping of named port to value stored in producer

for p in self.producers:
params = p.parameters['outputs']
for param in params:
try:
key = list(param.keys())[0]
except AttributeError:
logging.debug("Producer %s does not have named ports", p.uid)
continue
portName = param[key]
portValue = ""
producerUid = p.uid
if portName in p.parameters:
portValue = p.parameters[param[key]]
# TODO This currently only allows 1 UID -> Portname/Value
# Investigate UID -> [Portname1:Value1, Portnam2:value2,..,]
producerPortValueMap[producerUid] = {"portname": portName,
"value": portValue}

for port in dropInputPorts:
try:
port.items()
except AttributeError:
logging.debug("Producer %s does not have named ports", p.uid)
continue
for uid, portname in port.items():
try:
print(uid, portname)
tmp = producerPortValueMap[uid]
if tmp['portname'] == portname:
finalDropPortMap[portname] = tmp['value']
except KeyError:
print("Not available")

for portname in finalDropPortMap:
if portname in self.parameters:
self.parameters[portname] = finalDropPortMap[portname]

self._updatedPorts = True

def delete(self):
super().delete()
if self.delete_parent_directory:
Expand Down

0 comments on commit 80b8bc5

Please sign in to comment.