pgraph: Replace CompareMatch with VertexMatchFn

This removes a reference to the resources package in pgraph.
This commit is contained in:
James Shubin
2017-05-13 13:55:42 -04:00
parent d74c2115fd
commit e67d97d9da
3 changed files with 49 additions and 13 deletions

View File

@@ -136,7 +136,13 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World,
// XXX: should we export based on a @@ prefix, or a metaparam
// like exported => true || exported => (host pattern)||(other pattern?)
if !strings.HasPrefix(res.GetName(), "@@") { // not exported resource
v := graph.CompareMatch(res)
fn := func(v *pgraph.Vertex) (bool, error) {
return v.Res.Compare(res), nil
}
v, err := graph.VertexMatchFn(fn)
if err != nil {
return nil, errwrap.Wrapf(err, "could not VertexMatchFn() resource")
}
if v == nil { // no match found
v = pgraph.NewVertex(res)
graph.AddVertex(v) // call standalone in case not part of an edge
@@ -207,7 +213,14 @@ func (c *GraphConfig) NewGraphFromConfig(hostname string, world resources.World,
if _, exists := lookup[kind]; !exists {
lookup[kind] = make(map[string]*pgraph.Vertex)
}
v := graph.CompareMatch(res)
fn := func(v *pgraph.Vertex) (bool, error) {
return v.Res.Compare(res), nil
}
v, err := graph.VertexMatchFn(fn)
if err != nil {
return nil, errwrap.Wrapf(err, "could not VertexMatchFn() resource")
}
if v == nil { // no match found
v = pgraph.NewVertex(res)
graph.AddVertex(v) // call standalone in case not part of an edge