Commit 9a605506 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component:

- Fix Topological Sort of sub_devices
parent 6884fff3
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -296,15 +296,21 @@ def populate_endpoints(

    # Topologically sort new_sub_devices so that controllers (those referenced by other
    # devices via their controller_id) come before the devices that depend on them.

    LOGGER.info('new_sub_devices.keys={:s}'.format(str(new_sub_devices.keys())))
    graph : Dict[str, Set[str]] = dict()
    for dev_uuid, sub_device in new_sub_devices.items():
        if dev_uuid == device_uuid: continue # current device has no dependencies
        predecesors = graph.setdefault(dev_uuid, set())
        ctrl_uuid = get_device_controller_uuid(sub_device)
        LOGGER.info('dev_uuid={:s}, ctrl_uuid={:s}'.format(str(dev_uuid), str(ctrl_uuid)))

        if dev_uuid == device_uuid: continue # current device has no dependencies
        if ctrl_uuid is None: continue # sub_device has no controller
        if ctrl_uuid == device_uuid: continue # current device has no dependencies
        predecesors = graph.setdefault(dev_uuid, set())
        predecesors.add(ctrl_uuid)

    LOGGER.info('graph={:s}'.format(str(graph)))

    try:
        ts = TopologicalSorter(graph)
        sorted_sub_device_uuids.extend(list(ts.static_order()))
@@ -314,6 +320,8 @@ def populate_endpoints(
        LOGGER.exception(msg)
        errors.append(msg)

    LOGGER.info('sorted_sub_device_uuids={:s}'.format(str(sorted_sub_device_uuids)))

    return errors

def populate_endpoint_monitoring_resources(device_with_uuids : Device, monitoring_loops : MonitoringLoops) -> None: