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

Commit 07c03f4

Browse files
committed
fix
Signed-off-by: Yuji Oshima <[email protected]>
1 parent e47c5e5 commit 07c03f4

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

cmd/cli/application/application.go

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
var log = logutil.New("module", "cli/event")
1818

19+
//OPERATIONS code of update command
1920
var OPERATIONS = map[int]string{1: "Add", 2: "Delete", 3: "Update", 4: "Read"}
2021

2122
func init() {

examples/application/event-repeater/application.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sync"
1414
)
1515

16+
// NewEventRepeater creates an event repeater application.
1617
func NewEventRepeater(eSource string, eSink string, protocol string, allowall bool) application.Plugin {
1718
sub, err := event_rpc.NewClient(eSource)
1819
if err != nil {
@@ -71,6 +72,7 @@ type eventRepeater struct {
7172
eventListMt *sync.Mutex
7273
}
7374

75+
// RepeatRule for each event
7476
type RepeatRule struct {
7577
SourceTopic string
7678
SinkTopic string
@@ -80,8 +82,8 @@ type RepeatRule struct {
8082
}
8183

8284
type messageData struct {
83-
SourceTopic string `json:"sourcetopic",omitempty"`
84-
SinkTopic string `json:"sinktopic",omitempty"`
85+
SourceTopic string `json:"sourcetopic, omitempty"`
86+
SinkTopic string `json:"sinktopic, omitempty"`
8587
}
8688

8789
func (e eventRepeater) Validate(applicationProperties *types.Any) error {
@@ -92,7 +94,7 @@ func (e eventRepeater) Healthy(applicationProperties *types.Any) (application.He
9294
return application.Healthy, nil
9395
}
9496

95-
func (e eventRepeater) AddEvent(sourcesTopic string, sinkTopic string) error {
97+
func (e eventRepeater) addEvent(sourcesTopic string, sinkTopic string) error {
9698
if sourcesTopic == "" {
9799
return fmt.Errorf("Error: %s", "You must have a topic of source for add repeat event.")
98100
}
@@ -120,7 +122,7 @@ func (e eventRepeater) AddEvent(sourcesTopic string, sinkTopic string) error {
120122
return nil
121123
}
122124

123-
func (e eventRepeater) DelEvent(sourcesTopic string) error {
125+
func (e eventRepeater) delEvent(sourcesTopic string) error {
124126
if sourcesTopic == "" {
125127
return fmt.Errorf("Error: %s", "You must have a topic of source for delete repeat event.")
126128
}
@@ -167,7 +169,6 @@ func (e eventRepeater) publishToSink(rr *RepeatRule) error {
167169
}
168170
}
169171
}
170-
return nil
171172
}
172173

173174
func (e eventRepeater) Update(message *application.Message) error {
@@ -183,25 +184,25 @@ func (e eventRepeater) Update(message *application.Message) error {
183184
case application.ADD:
184185
for _, d := range dataStruct {
185186
log.Debugf("Add message %v \n", d)
186-
err := e.AddEvent(d.SourceTopic, d.SinkTopic)
187+
err := e.addEvent(d.SourceTopic, d.SinkTopic)
187188
if err != nil {
188189
return err
189190
}
190191
}
191192
case application.DELETE:
192193
for _, d := range dataStruct {
193-
err := e.DelEvent(d.SourceTopic)
194+
err := e.delEvent(d.SourceTopic)
194195
if err != nil {
195196
return err
196197
}
197198
}
198199
case application.UPDATE:
199200
for _, d := range dataStruct {
200-
err := e.DelEvent(d.SourceTopic)
201+
err := e.delEvent(d.SourceTopic)
201202
if err != nil {
202203
return err
203204
}
204-
err = e.AddEvent(d.SourceTopic, d.SinkTopic)
205+
err = e.addEvent(d.SourceTopic, d.SinkTopic)
205206
if err != nil {
206207
return err
207208
}
@@ -218,7 +219,7 @@ func (e eventRepeater) Update(message *application.Message) error {
218219

219220
func (e eventRepeater) serve() error {
220221
if e.allowAll {
221-
e.AddEvent(".", "")
222+
e.addEvent(".", "")
222223
}
223224
for {
224225
select {

pkg/rpc/application/service.go

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func (p *Application) Healthy(_ *http.Request, req *HealthyRequest, resp *Health
151151
return nil
152152
}
153153

154+
// Update specify resource information
154155
func (p *Application) Update(_ *http.Request, req *UpdateRequest, resp *UpdateResponse) error {
155156
resp.Type = req.Type
156157
c := p.getPlugin(req.Type)

pkg/spi/application/types.go

+9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@ import (
44
"github.com/docker/infrakit/pkg/types"
55
)
66

7+
// Type is the type of an application. This gives hint about what struct types to map to, etc.
8+
// It also marks one instance of an application as of different nature from another.
79
type Type string
10+
11+
//Operation : update operation code
812
type Operation int
913

1014
const (
1115
// TypeError is the type to use for sending errors in the transport of the events.
1216
TypeError = Type("error")
1317

18+
// ADD new resources
1419
ADD Operation = iota
20+
// DELETE resources
1521
DELETE
22+
// UPDATE resources
1623
UPDATE
24+
// GET resources
1725
GET
1826
)
1927

28+
// Message :update message struct
2029
type Message struct {
2130
Op Operation
2231
Resource string

pkg/spi/event/spi.go

-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,3 @@ type Subscriber interface {
4040
// SubscribeOn returns the channel for the topic
4141
SubscribeOn(topic types.Path) (<-chan *Event, chan<- struct{}, error)
4242
}
43-
44-
type Application interface {
45-
List(topic types.Path) ([]string, error)
46-
}

0 commit comments

Comments
 (0)