Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced dependency resolution #244

Open
WilliamMcCumstie opened this issue Jul 15, 2019 · 1 comment
Open

Advanced dependency resolution #244

WilliamMcCumstie opened this issue Jul 15, 2019 · 1 comment

Comments

@WilliamMcCumstie
Copy link
Contributor

WilliamMcCumstie commented Jul 15, 2019

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants