openflighthpc / flight-cloud

Cloud orchestration tool
Eclipse Public License 2.0
3 stars 2 forks source link

Advanced dependency resolution #244

Open WilliamMcCumstie opened 5 years ago

WilliamMcCumstie commented 5 years ago

This issue is an enhancement #238 and is not required until nodes start to become dependant on each other. It is not required if nodes are dependent on the Domain alone. However once Nodes start referencing each other, it opens the possibility for cyclic paths creating an infinite dependency loop.

Suppose we have the situation:

node01 => domain,gateway
gateway => domain,bad
bad => domain,gateway

Firstly, all the dependent nodes (and doman) need to be identified without getting stuck in a loop. This can be done by reducing the nodes down to a hash:

node01.method_that_reduces_nodes_to_unsorted_dependencies
step1: { node01: [domain, gateway] } # Add node01 dependencies
step2: { node01: [domain, gateway], domain: [] } # Add node01.domain dependencies
step3: { node01: [domain, gateway], domain: [], gateway: [domain, bad] } # Add node01.gateway dependencies
step4: Skip, node01.domain dependencies as its doesn't have any
step5: Skip node01.gateway.domain as it already been added
step6: {
  node01: [domain, gateway],
  domain: [],
  gateway: [domain, bad],
  bad: [domain,gateway]
} # Add node01.gateway.bad dependencies
step7: Skip node01.gateway.bad.domain as it exists
step8: Skip node01.gateway.bad.gateway as it exists
step9: hash.keys #=> Returns an unsorted list of all the dependencies without getting stuck
WilliamMcCumstie commented 5 years ago

Now that all the dependencies have been identified, they now need to be put into order. This requires preforming a topological sort on the above returned list. The problem with the above example is there is a cyclic loop. This will likely need to be detected before continuing.

The topological sort will then insure that all the nodes sub-dependencies occur before it in the list. Thus creating the node would require creating all the sub-dependencies in topological order. See links for reference: https://en.wikipedia.org/wiki/Topological_sorting https://github.com/brianstorti/ruby-graph-algorithms/tree/master/topological_sort https://github.com/monora/rgl