Permalink
Browse files

Rename type to resource (res) and service to svc

Naming the resources "type" was a stupid mistake, and is a huge source
of confusion when also talking about real types. Fix this before it gets
out of hand.
  • Loading branch information...
1 parent d20b529 commit 3a8538437743d2151c73c108f75a93d6f1fbff17 @purpleidea committed Feb 21, 2016
View
@@ -3,7 +3,7 @@ If you're looking for something to do, look here!
Let us know if you're working on one of the items.
## Package resource
-- [ ] base type [bug](https://github.com/purpleidea/mgmt/issues/11)
+- [ ] base resource [bug](https://github.com/purpleidea/mgmt/issues/11)
- [ ] dnf blocker [bug](https://github.com/hughsie/PackageKit/issues/110)
- [ ] install signal blocker [bug](https://github.com/hughsie/PackageKit/issues/109)
View
@@ -25,13 +25,13 @@ import (
"strings"
)
-type collectorTypeConfig struct {
- Type string `yaml:"type"`
+type collectorResConfig struct {
+ Res string `yaml:"res"`
Pattern string `yaml:"pattern"` // XXX: Not Implemented
}
type vertexConfig struct {
- Type string `yaml:"type"`
+ Res string `yaml:"res"`
Name string `yaml:"name"`
}
@@ -42,16 +42,16 @@ type edgeConfig struct {
}
type GraphConfig struct {
- Graph string `yaml:"graph"`
- Types struct {
- Noop []NoopType `yaml:"noop"`
- File []FileType `yaml:"file"`
- Service []ServiceType `yaml:"service"`
- Exec []ExecType `yaml:"exec"`
- } `yaml:"types"`
- Collector []collectorTypeConfig `yaml:"collect"`
- Edges []edgeConfig `yaml:"edges"`
- Comment string `yaml:"comment"`
+ Graph string `yaml:"graph"`
+ Resources struct {
+ Noop []NoopRes `yaml:"noop"`
+ File []FileRes `yaml:"file"`
+ Svc []SvcRes `yaml:"svc"`
+ Exec []ExecRes `yaml:"exec"`
+ } `yaml:"resources"`
+ Collector []collectorResConfig `yaml:"collect"`
+ Edges []edgeConfig `yaml:"edges"`
+ Comment string `yaml:"comment"`
}
func (c *GraphConfig) Parse(data []byte) error {
@@ -95,13 +95,13 @@ func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO
var NoopMap = make(map[string]*Vertex)
var FileMap = make(map[string]*Vertex)
- var ServiceMap = make(map[string]*Vertex)
+ var SvcMap = make(map[string]*Vertex)
var ExecMap = make(map[string]*Vertex)
var lookup = make(map[string]map[string]*Vertex)
lookup["noop"] = NoopMap
lookup["file"] = FileMap
- lookup["service"] = ServiceMap
+ lookup["svc"] = SvcMap
lookup["exec"] = ExecMap
//log.Printf("%+v", config) // debug
@@ -110,8 +110,8 @@ func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO
var keep []*Vertex // list of vertex which are the same in new graph
- for _, t := range config.Types.Noop {
- obj := NewNoopType(t.Name)
+ for _, t := range config.Resources.Noop {
+ obj := NewNoopRes(t.Name)
v := g.GetVertexMatch(obj)
if v == nil { // no match found
v = NewVertex(obj)
@@ -121,7 +121,7 @@ func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO
keep = append(keep, v) // append
}
- for _, t := range config.Types.File {
+ for _, t := range config.Resources.File {
// XXX: should we export based on a @@ prefix, or a metaparam
// like exported => true || exported => (host pattern)||(other pattern?)
if strings.HasPrefix(t.Name, "@@") { // exported resource
@@ -132,7 +132,7 @@ func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO
continue
}
} else {
- obj := NewFileType(t.Name, t.Path, t.Dirname, t.Basename, t.Content, t.State)
+ obj := NewFileRes(t.Name, t.Path, t.Dirname, t.Basename, t.Content, t.State)
v := g.GetVertexMatch(obj)
if v == nil { // no match found
v = NewVertex(obj)
@@ -143,19 +143,19 @@ func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO
}
}
- for _, t := range config.Types.Service {
- obj := NewServiceType(t.Name, t.State, t.Startup)
+ for _, t := range config.Resources.Svc {
+ obj := NewSvcRes(t.Name, t.State, t.Startup)
v := g.GetVertexMatch(obj)
if v == nil { // no match found
v = NewVertex(obj)
g.AddVertex(v) // call standalone in case not part of an edge
}
- ServiceMap[obj.Name] = v // used for constructing edges
- keep = append(keep, v) // append
+ SvcMap[obj.Name] = v // used for constructing edges
+ keep = append(keep, v) // append
}
- for _, t := range config.Types.Exec {
- obj := NewExecType(t.Name, t.Cmd, t.Shell, t.Timeout, t.WatchCmd, t.WatchShell, t.IfCmd, t.IfShell, t.PollInt, t.State)
+ for _, t := range config.Resources.Exec {
+ obj := NewExecRes(t.Name, t.Cmd, t.Shell, t.Timeout, t.WatchCmd, t.WatchShell, t.IfCmd, t.IfShell, t.PollInt, t.State)
v := g.GetVertexMatch(obj)
if v == nil { // no match found
v = NewVertex(obj)
@@ -171,11 +171,11 @@ func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO
nodes, ok := etcdO.EtcdGet()
if ok {
for _, t := range config.Collector {
- // XXX: use t.Type and optionally t.Pattern to collect from etcd storage
- log.Printf("Collect: %v; Pattern: %v", t.Type, t.Pattern)
+ // XXX: use t.Res and optionally t.Pattern to collect from etcd storage
+ log.Printf("Collect: %v; Pattern: %v", t.Res, t.Pattern)
for _, x := range etcdO.EtcdGetProcess(nodes, "file") {
- var obj *FileType
+ var obj *FileRes
if B64ToObj(x, &obj) != true {
log.Printf("Collect: File: %v not collected!", x)
continue
@@ -205,25 +205,25 @@ func UpdateGraphFromConfig(config *GraphConfig, hostname string, g *Graph, etcdO
for _, v := range g.GetVertices() {
if !HasVertex(v, keep) {
// wait for exit before starting new graph!
- v.Type.SendEvent(eventExit, true, false)
+ v.Res.SendEvent(eventExit, true, false)
g.DeleteVertex(v)
}
}
for _, e := range config.Edges {
- if _, ok := lookup[e.From.Type]; !ok {
+ if _, ok := lookup[e.From.Res]; !ok {
return false
}
- if _, ok := lookup[e.To.Type]; !ok {
+ if _, ok := lookup[e.To.Res]; !ok {
return false
}
- if _, ok := lookup[e.From.Type][e.From.Name]; !ok {
+ if _, ok := lookup[e.From.Res][e.From.Name]; !ok {
return false
}
- if _, ok := lookup[e.To.Type][e.To.Name]; !ok {
+ if _, ok := lookup[e.To.Res][e.To.Name]; !ok {
return false
}
- g.AddEdge(lookup[e.From.Type][e.From.Name], lookup[e.To.Type][e.To.Name], NewEdge(e.Name))
+ g.AddEdge(lookup[e.From.Res][e.From.Name], lookup[e.To.Res][e.To.Name], NewEdge(e.Name))
}
return true
}
View
@@ -27,7 +27,7 @@ import (
"syscall"
)
-// XXX: it would be great if we could reuse code between this and the file type
+// XXX: it would be great if we could reuse code between this and the file resource
// XXX: patch this to submit it as part of go-fsnotify if they're interested...
func ConfigWatch(file string) chan bool {
ch := make(chan bool)
View
@@ -191,8 +191,8 @@ func (etcdO *EtcdWObject) EtcdWatch() chan etcdMsg {
}
}
- // FIXME: we get events on key/type/value changes for
- // each type directory... ignore the non final ones...
+ // FIXME: we get events on key/res/value changes for
+ // each res directory... ignore the non final ones...
// IOW, ignore everything except for the value or some
// field which gets set last... this could be the max count field thing...
@@ -207,19 +207,19 @@ func (etcdO *EtcdWObject) EtcdWatch() chan etcdMsg {
}
// helper function to store our data in etcd
-func (etcdO *EtcdWObject) EtcdPut(hostname, key, typ string, obj interface{}) bool {
+func (etcdO *EtcdWObject) EtcdPut(hostname, key, res string, obj interface{}) bool {
kapi := etcdO.GetKAPI()
output, ok := ObjToB64(obj)
if !ok {
log.Printf("Etcd: Could not encode %v key.", key)
return false
}
- path := fmt.Sprintf("/exported/%s/types/%s/type", hostname, key)
- _, err := kapi.Set(etcd_context.Background(), path, typ, nil)
+ path := fmt.Sprintf("/exported/%s/resources/%s/res", hostname, key)
+ _, err := kapi.Set(etcd_context.Background(), path, res, nil)
// XXX validate...
- path = fmt.Sprintf("/exported/%s/types/%s/value", hostname, key)
+ path = fmt.Sprintf("/exported/%s/resources/%s/value", hostname, key)
resp, err := kapi.Set(etcd_context.Background(), path, output, nil)
if err != nil {
if cerr, ok := err.(*etcd.ClusterError); ok {
@@ -240,16 +240,16 @@ func (etcdO *EtcdWObject) EtcdPut(hostname, key, typ string, obj interface{}) bo
// lookup /exported/ node hierarchy
func (etcdO *EtcdWObject) EtcdGet() (etcd.Nodes, bool) {
kapi := etcdO.GetKAPI()
- // key structure is /exported/<hostname>/types/...
+ // key structure is /exported/<hostname>/resources/...
resp, err := kapi.Get(etcd_context.Background(), "/exported/", &etcd.GetOptions{Recursive: true})
if err != nil {
return nil, false // not found
}
return resp.Node.Nodes, true
}
-func (etcdO *EtcdWObject) EtcdGetProcess(nodes etcd.Nodes, typ string) []string {
- //path := fmt.Sprintf("/exported/%s/types/", h)
+func (etcdO *EtcdWObject) EtcdGetProcess(nodes etcd.Nodes, res string) []string {
+ //path := fmt.Sprintf("/exported/%s/resources/", h)
top := "/exported/"
log.Printf("Etcd: Get: %+v", nodes) // Get().Nodes.Nodes
var output []string
@@ -261,20 +261,20 @@ func (etcdO *EtcdWObject) EtcdGetProcess(nodes etcd.Nodes, typ string) []string
host := x.Key[len(top):]
//log.Printf("Get().Nodes[%v]: %+v ==> %+v", -1, host, x.Nodes)
//log.Printf("Get().Nodes[%v]: %+v ==> %+v", i, x.Key, x.Nodes)
- types, ok := EtcdGetChildNodeByKey(x, "types")
+ resources, ok := EtcdGetChildNodeByKey(x, "resources")
if !ok {
continue
}
- for _, y := range types.Nodes { // loop through types
+ for _, y := range resources.Nodes { // loop through resources
//key := y.Key # UUID?
- //log.Printf("Get(%v): TYPE[%v]", host, y.Key)
- t, ok := EtcdGetChildNodeByKey(y, "type")
+ //log.Printf("Get(%v): RES[%v]", host, y.Key)
+ t, ok := EtcdGetChildNodeByKey(y, "res")
if !ok {
continue
}
- if typ != "" && typ != t.Value {
+ if res != "" && res != t.Value {
continue
- } // filter based on type
+ } // filter based on res
v, ok := EtcdGetChildNodeByKey(y, "value") // B64ToObj this
if !ok {
@@ -1,7 +1,7 @@
---
graph: mygraph
comment: hello world example
-types:
+resources:
noop:
- name: noop1
file:
@@ -13,8 +13,8 @@ types:
edges:
- name: e1
from:
- type: noop
+ res: noop
name: noop1
to:
- type: file
+ res: file
name: file1
View
@@ -1,6 +1,6 @@
---
graph: mygraph
-types:
+resources:
noop:
- name: noop1
file:
@@ -27,15 +27,15 @@ types:
edges:
- name: e1
from:
- type: file
+ res: file
name: file1
to:
- type: file
+ res: file
name: file2
- name: e2
from:
- type: file
+ res: file
name: file2
to:
- type: file
+ res: file
name: file3
View
@@ -1,7 +1,7 @@
---
graph: mygraph
comment: simple exec fan in to fan out example to demonstrate optimization
-types:
+resources:
exec:
- name: exec1
cmd: sleep 10s
@@ -86,43 +86,43 @@ types:
edges:
- name: e1
from:
- type: exec
+ res: exec
name: exec1
to:
- type: exec
+ res: exec
name: exec4
- name: e2
from:
- type: exec
+ res: exec
name: exec2
to:
- type: exec
+ res: exec
name: exec4
- name: e3
from:
- type: exec
+ res: exec
name: exec3
to:
- type: exec
+ res: exec
name: exec4
- name: e4
from:
- type: exec
+ res: exec
name: exec4
to:
- type: exec
+ res: exec
name: exec5
- name: e5
from:
- type: exec
+ res: exec
name: exec4
to:
- type: exec
+ res: exec
name: exec6
- name: e6
from:
- type: exec
+ res: exec
name: exec4
to:
- type: exec
+ res: exec
name: exec7
@@ -1,6 +1,6 @@
---
graph: mygraph
-types:
+resources:
file:
- name: file1
path: "/tmp/mgmt/f1"
@@ -15,8 +15,8 @@ types:
edges:
- name: e1
from:
- type: file
+ res: file
name: file1
to:
- type: file
+ res: file
name: file2
Oops, something went wrong.

0 comments on commit 3a85384

Please sign in to comment.