Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 9057644

Browse files
author
David Chung
authored
spi and implementation cleanup to use a single implementation for Path (#484)
* spi and implementation cleanup to use a single implementation for Path Signed-off-by: David Chung <[email protected]> * remove deployment section for pr Signed-off-by: David Chung <[email protected]>
1 parent 190e269 commit 9057644

File tree

23 files changed

+166
-735
lines changed

23 files changed

+166
-735
lines changed

circle.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ test:
4747
- cd $WORKDIR && bash <(curl -s https://codecov.io/bash)
4848

4949
deployment:
50-
pr:
51-
branch: /pull\/.*/
52-
commands:
53-
- # DISABLED TO SPEED UP PR Process: DOCKER_BUILD_FLAGS="--rm=false" make build-docker
54-
5550
release:
5651
branch: /release-.*/
5752
commands:

cmd/cli/metadata/metadata.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"github.com/docker/infrakit/cmd/cli/base"
99
"github.com/docker/infrakit/pkg/discovery"
1010
logutil "github.com/docker/infrakit/pkg/log"
11-
metadata_plugin "github.com/docker/infrakit/pkg/plugin/metadata"
1211
"github.com/docker/infrakit/pkg/rpc/client"
1312
metadata_rpc "github.com/docker/infrakit/pkg/rpc/metadata"
1413
"github.com/docker/infrakit/pkg/spi/metadata"
14+
"github.com/docker/infrakit/pkg/types"
1515
"github.com/spf13/cobra"
1616
)
1717

@@ -48,17 +48,17 @@ func forPlugin(plugins func() discovery.Plugins, do func(string, metadata.Plugin
4848
return nil
4949
}
5050

51-
func listAll(m metadata.Plugin, path metadata.Path) ([]metadata.Path, error) {
51+
func listAll(m metadata.Plugin, path types.Path) ([]types.Path, error) {
5252
if m == nil {
5353
return nil, fmt.Errorf("no plugin")
5454
}
55-
result := []metadata.Path{}
55+
result := []types.Path{}
5656
nodes, err := m.List(path)
5757
if err != nil {
5858
return nil, err
5959
}
6060
for _, n := range nodes {
61-
c := path.Join(n)
61+
c := path.JoinString(n)
6262
more, err := listAll(m, c)
6363
if err != nil {
6464
return nil, err
@@ -110,7 +110,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
110110
return fmt.Errorf("No absolute path")
111111
}
112112

113-
path := metadata_plugin.Path(p)
113+
path := types.PathFromString(p)
114114
first := path.Index(0)
115115

116116
targets := []string{} // target plugins to query
@@ -128,7 +128,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
128128

129129
for j, target := range targets {
130130

131-
nodes := []metadata.Path{} // the result set to print
131+
nodes := []types.Path{} // the result set to print
132132

133133
match, err := getPlugin(plugins, target)
134134
if err != nil {
@@ -142,11 +142,11 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
142142
log.Warn("Cannot metadata ls on plugin", "target", target, "err", err)
143143
}
144144
for _, c := range allPaths {
145-
nodes = append(nodes, metadata_plugin.Path(target).Sub(c))
145+
nodes = append(nodes, types.PathFromString(target).Join(c))
146146
}
147147
} else {
148148
for _, t := range targets {
149-
nodes = append(nodes, metadata_plugin.Path(t))
149+
nodes = append(nodes, types.PathFromString(t))
150150
}
151151
}
152152

@@ -157,15 +157,15 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
157157
log.Warn("Cannot metadata ls on plugin", "target", target, "err", err)
158158
}
159159
for _, c := range allPaths {
160-
nodes = append(nodes, metadata_plugin.Path(target).Sub(c))
160+
nodes = append(nodes, types.PathFromString(target).Join(c))
161161
}
162162
} else {
163163
children, err := match.List(path.Shift(1))
164164
if err != nil {
165165
log.Warn("Cannot metadata ls on plugin", "target", target, "err", err)
166166
}
167167
for _, c := range children {
168-
nodes = append(nodes, path.Join(c))
168+
nodes = append(nodes, path.JoinString(c))
169169
}
170170
}
171171
}
@@ -177,9 +177,9 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
177177
}
178178
for _, l := range nodes {
179179
if *long {
180-
fmt.Println(metadata_plugin.String(l))
180+
fmt.Println(l)
181181
} else {
182-
fmt.Println(metadata_plugin.String(l.Rel(path)))
182+
fmt.Println(l.Rel(path))
183183
}
184184
}
185185
break
@@ -196,9 +196,9 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
196196
}
197197
for _, l := range nodes {
198198
if *long {
199-
fmt.Println(metadata_plugin.String(l))
199+
fmt.Println(l)
200200
} else {
201-
fmt.Println(metadata_plugin.String(l.Rel(path)))
201+
fmt.Println(l.Rel(path))
202202
}
203203
}
204204
}
@@ -215,7 +215,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
215215

216216
for _, p := range args {
217217

218-
path := metadata_plugin.Path(p)
218+
path := types.PathFromString(p)
219219
first := path.Index(0)
220220
if first != nil {
221221
match, err := getPlugin(plugins, *first)

cmd/group/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
metadata_rpc "github.com/docker/infrakit/pkg/rpc/metadata"
1717
"github.com/docker/infrakit/pkg/spi/flavor"
1818
"github.com/docker/infrakit/pkg/spi/instance"
19+
"github.com/docker/infrakit/pkg/types"
1920
"github.com/spf13/cobra"
2021
)
2122

@@ -76,7 +77,7 @@ func main() {
7677
}
7778

7879
updateSnapshot <- func(view map[string]interface{}) {
79-
metadata_plugin.Put([]string{"specs"}, snapshot, view)
80+
types.Put([]string{"specs"}, snapshot, view)
8081
}
8182

8283
case <-tick30:
@@ -95,7 +96,7 @@ func main() {
9596
}
9697

9798
updateSnapshot <- func(view map[string]interface{}) {
98-
metadata_plugin.Put([]string{"groups"}, snapshot, view)
99+
types.Put([]string{"groups"}, snapshot, view)
99100
}
100101

101102
case <-stopSnapshot:

cmd/manager/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
manager_rpc "github.com/docker/infrakit/pkg/rpc/manager"
1818
metadata_rpc "github.com/docker/infrakit/pkg/rpc/metadata"
1919
"github.com/docker/infrakit/pkg/store"
20+
"github.com/docker/infrakit/pkg/types"
2021
"github.com/docker/infrakit/pkg/util/docker"
2122
"github.com/spf13/cobra"
2223
)
@@ -106,7 +107,7 @@ func runMain(cfg config) error {
106107
// update leadership
107108
if isLeader, err := mgr.IsLeader(); err == nil {
108109
updateSnapshot <- func(view map[string]interface{}) {
109-
metadata_plugin.Put([]string{"leader"}, isLeader, view)
110+
types.Put([]string{"leader"}, isLeader, view)
110111
}
111112
} else {
112113
logrus.Warningln("Cannot check leader for metadata:", err)
@@ -115,7 +116,7 @@ func runMain(cfg config) error {
115116
// update config
116117
if err := cfg.snapshot.Load(&snapshot); err == nil {
117118
updateSnapshot <- func(view map[string]interface{}) {
118-
metadata_plugin.Put([]string{"configs"}, snapshot, view)
119+
types.Put([]string{"configs"}, snapshot, view)
119120
}
120121
} else {
121122
logrus.Warningln("Cannot load snapshot for metadata:", err)

examples/event/time/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ func main() {
152152

153153
// For metadata -- queries for current time
154154
timeQueries := map[string]interface{}{}
155-
metadata_plugin.Put(metadata_plugin.Path("now/nano"),
155+
types.Put(types.PathFromString("now/nano"),
156156
func() interface{} {
157157
return time.Now().UnixNano()
158158
},
159159
timeQueries)
160-
metadata_plugin.Put(metadata_plugin.Path("now/sec"),
160+
types.Put(types.PathFromString("now/sec"),
161161
func() interface{} {
162162
return time.Now().Unix()
163163
},

examples/flavor/swarm/flavor.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/docker/go-connections/tlsconfig"
1212
"github.com/docker/infrakit/pkg/discovery"
1313
group_types "github.com/docker/infrakit/pkg/plugin/group/types"
14-
metadata_plugin "github.com/docker/infrakit/pkg/plugin/metadata"
1514
metadata_template "github.com/docker/infrakit/pkg/plugin/metadata/template"
1615
"github.com/docker/infrakit/pkg/spi/flavor"
1716
"github.com/docker/infrakit/pkg/spi/instance"
@@ -103,7 +102,7 @@ func (s *baseFlavor) runMetadataSnapshot(stopSnapshot <-chan struct{}) chan func
103102
}
104103

105104
updateSnapshot <- func(view map[string]interface{}) {
106-
metadata_plugin.Put([]string{"groups"}, snapshot, view)
105+
types.Put([]string{"groups"}, snapshot, view)
107106
}
108107

109108
case <-stopSnapshot:
@@ -116,15 +115,15 @@ func (s *baseFlavor) runMetadataSnapshot(stopSnapshot <-chan struct{}) chan func
116115
}
117116

118117
// List implements the metadata.Plugin SPI's List method
119-
func (s *baseFlavor) List(path metadata.Path) ([]string, error) {
118+
func (s *baseFlavor) List(path types.Path) ([]string, error) {
120119
if s.metadataPlugin != nil {
121120
return s.metadataPlugin.List(path)
122121
}
123122
return nil, nil
124123
}
125124

126125
// Get implements the metadata.Plugin SPI's List method
127-
func (s *baseFlavor) Get(path metadata.Path) (*types.Any, error) {
126+
func (s *baseFlavor) Get(path types.Path) (*types.Any, error) {
128127
if s.metadataPlugin != nil {
129128
return s.metadataPlugin.Get(path)
130129
}

examples/instance/docker/instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,15 @@ func (p dockerInstancePlugin) DescribeInstances(tags map[string]string, properti
398398
}
399399

400400
// List implements the metadata.Plugin SPI's List method
401-
func (p dockerInstancePlugin) List(path metadata.Path) ([]string, error) {
401+
func (p dockerInstancePlugin) List(path types.Path) ([]string, error) {
402402
if p.metadataPlugin != nil {
403403
return p.metadataPlugin.List(path)
404404
}
405405
return nil, nil
406406
}
407407

408408
// Get implements the metadata.Plugin SPI's List method
409-
func (p dockerInstancePlugin) Get(path metadata.Path) (*types.Any, error) {
409+
func (p dockerInstancePlugin) Get(path types.Path) (*types.Any, error) {
410410
if p.metadataPlugin != nil {
411411
return p.metadataPlugin.Get(path)
412412
}

examples/instance/docker/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/docker/docker/api/types/filters"
1111
"github.com/docker/infrakit/pkg/cli"
1212
"github.com/docker/infrakit/pkg/plugin/metadata"
13-
metadata_plugin "github.com/docker/infrakit/pkg/plugin/metadata"
1413
instance_plugin "github.com/docker/infrakit/pkg/rpc/instance"
1514
metadata_rpc "github.com/docker/infrakit/pkg/rpc/metadata"
15+
"github.com/docker/infrakit/pkg/types"
1616
"github.com/spf13/cobra"
1717
"golang.org/x/net/context"
1818
)
@@ -78,7 +78,7 @@ func main() {
7878
}
7979
}
8080
updateSnapshot <- func(view map[string]interface{}) {
81-
metadata_plugin.Put([]string{"containers"}, snapshot, view)
81+
types.Put([]string{"containers"}, snapshot, view)
8282
}
8383

8484
case <-stopSnapshot:

pkg/plugin/metadata/path.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

pkg/plugin/metadata/plugin.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,32 @@ type plugin struct {
5555

5656
// List returns a list of *child nodes* given a path, which is specified as a slice
5757
// where for i > j path[i] is the parent of path[j]
58-
func (p *plugin) List(path metadata.Path) ([]string, error) {
58+
func (p *plugin) List(path types.Path) ([]string, error) {
5959
if p.reads == nil && p.data != nil {
60-
return List(path, p.data), nil
60+
return types.List(path, p.data), nil
6161
}
6262

6363
children := make(chan []string)
6464

6565
p.reads <- func(data map[string]interface{}) {
66-
children <- List(path, data)
66+
children <- types.List(path, data)
6767
return
6868
}
6969

7070
return <-children, nil
7171
}
7272

7373
// Get retrieves the value at path given.
74-
func (p *plugin) Get(path metadata.Path) (*types.Any, error) {
74+
func (p *plugin) Get(path types.Path) (*types.Any, error) {
7575
if p.reads == nil && p.data != nil {
76-
return types.AnyValue(Get(path, p.data))
76+
return types.AnyValue(types.Get(path, p.data))
7777
}
7878

7979
value := make(chan *types.Any)
8080
err := make(chan error)
8181

8282
p.reads <- func(data map[string]interface{}) {
83-
v, e := types.AnyValue(Get(path, data))
83+
v, e := types.AnyValue(types.Get(path, data))
8484
value <- v
8585
err <- e
8686
return

0 commit comments

Comments
 (0)