exec: Add autoEdges between ExecRes and PkgRes
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
21
examples/autoedges5.yaml
Normal file
21
examples/autoedges5.yaml
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
graph: mygraph
|
||||
resources:
|
||||
pkg:
|
||||
- name: httpd
|
||||
meta:
|
||||
autoedge: true
|
||||
noop: true
|
||||
state: installed
|
||||
exec:
|
||||
- name: pkg10
|
||||
cmd: /usr/bin/apachectl status
|
||||
shell: ''
|
||||
timeout: 0
|
||||
watchcmd: ''
|
||||
watchshell: ''
|
||||
ifcmd: ''
|
||||
ifshell: ''
|
||||
pollint: 0
|
||||
state: present
|
||||
edges: []
|
||||
@@ -331,11 +331,39 @@ type ExecUID struct {
|
||||
// TODO: add more elements here
|
||||
}
|
||||
|
||||
// AutoEdges returns the AutoEdge interface. In this case no autoedges are used.
|
||||
// ExecResAutoEdges holds the state of the auto edge generator.
|
||||
type ExecResAutoEdges struct {
|
||||
edges []ResUID
|
||||
}
|
||||
|
||||
// Next returns the next automatic edge.
|
||||
func (obj *ExecResAutoEdges) Next() []ResUID {
|
||||
return obj.edges
|
||||
}
|
||||
|
||||
// Test gets results of the earlier Next() call, & returns if we should continue!
|
||||
func (obj *ExecResAutoEdges) Test(input []bool) bool {
|
||||
return false // Never keep going
|
||||
// TODO: We could return false if we find as many edges as the number of different path in cmdFiles()
|
||||
}
|
||||
|
||||
// AutoEdges returns the AutoEdge interface. In this case the systemd units.
|
||||
func (obj *ExecRes) AutoEdges() (AutoEdge, error) {
|
||||
// TODO: parse as many exec params to look for auto edges, for example
|
||||
// the path of the binary in the Cmd variable might be from in a pkg
|
||||
return nil, nil
|
||||
var data []ResUID
|
||||
for _, x := range obj.cmdFiles() {
|
||||
var reversed = true
|
||||
data = append(data, &PkgFileUID{
|
||||
BaseUID: BaseUID{
|
||||
Name: obj.GetName(),
|
||||
Kind: obj.GetKind(),
|
||||
Reversed: &reversed,
|
||||
},
|
||||
path: x, // what matters
|
||||
})
|
||||
}
|
||||
return &ExecResAutoEdges{
|
||||
edges: data,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// UIDs includes all params to make a unique identification of this object.
|
||||
@@ -485,3 +513,24 @@ func (w *wrapWriter) Write(p []byte) (int, error) {
|
||||
func (w *wrapWriter) String() string {
|
||||
return w.Buffer.String()
|
||||
}
|
||||
|
||||
// cmdFiles returns all the potential files/commands this command might need.
|
||||
func (obj *ExecRes) cmdFiles() []string {
|
||||
var paths []string
|
||||
if obj.Shell != "" {
|
||||
paths = append(paths, obj.Shell)
|
||||
} else if cmdSplit := strings.Fields(obj.Cmd); len(cmdSplit) > 0 {
|
||||
paths = append(paths, cmdSplit[0])
|
||||
}
|
||||
if obj.WatchShell != "" {
|
||||
paths = append(paths, obj.WatchShell)
|
||||
} else if watchSplit := strings.Fields(obj.WatchCmd); len(watchSplit) > 0 {
|
||||
paths = append(paths, watchSplit[0])
|
||||
}
|
||||
if obj.IfShell != "" {
|
||||
paths = append(paths, obj.IfShell)
|
||||
} else if ifSplit := strings.Fields(obj.IfCmd); len(ifSplit) > 0 {
|
||||
paths = append(paths, ifSplit[0])
|
||||
}
|
||||
return paths
|
||||
}
|
||||
|
||||
@@ -323,13 +323,19 @@ func (obj *PkgRes) CheckApply(apply bool) (checkOK bool, err error) {
|
||||
return false, nil // success
|
||||
}
|
||||
|
||||
// PkgUID is the UID struct for PkgRes.
|
||||
// PkgUID is the main UID struct for PkgRes.
|
||||
type PkgUID struct {
|
||||
BaseUID
|
||||
name string // pkg name
|
||||
state string // pkg state or "version"
|
||||
}
|
||||
|
||||
// PkgFileUID is the UID struct for PkgRes files.
|
||||
type PkgFileUID struct {
|
||||
BaseUID
|
||||
path string // path of the file
|
||||
}
|
||||
|
||||
// IFF aka if and only if they are equivalent, return true. If not, false.
|
||||
func (obj *PkgUID) IFF(uid ResUID) bool {
|
||||
res, ok := uid.(*PkgUID)
|
||||
@@ -473,6 +479,14 @@ func (obj *PkgRes) UIDs() []ResUID {
|
||||
state: obj.State,
|
||||
}
|
||||
result := []ResUID{x}
|
||||
|
||||
for _, y := range obj.fileList {
|
||||
y := &PkgFileUID{
|
||||
BaseUID: BaseUID{Name: obj.GetName(), Kind: obj.GetKind()},
|
||||
path: y,
|
||||
}
|
||||
result = append(result, y)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user