From 07c03f4b9c71aa5d674d4b0273304a5944890854 Mon Sep 17 00:00:00 2001 From: Yuji Oshima Date: Tue, 11 Apr 2017 11:00:23 +0900 Subject: [PATCH] fix Signed-off-by: Yuji Oshima --- cmd/cli/application/application.go | 1 + .../application/event-repeater/application.go | 21 ++++++++++--------- pkg/rpc/application/service.go | 1 + pkg/spi/application/types.go | 9 ++++++++ pkg/spi/event/spi.go | 4 ---- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cmd/cli/application/application.go b/cmd/cli/application/application.go index a254c3e09..1ae569f0e 100644 --- a/cmd/cli/application/application.go +++ b/cmd/cli/application/application.go @@ -16,6 +16,7 @@ import ( var log = logutil.New("module", "cli/event") +//OPERATIONS code of update command var OPERATIONS = map[int]string{1: "Add", 2: "Delete", 3: "Update", 4: "Read"} func init() { diff --git a/examples/application/event-repeater/application.go b/examples/application/event-repeater/application.go index 1ec50988e..41cfdf7a1 100644 --- a/examples/application/event-repeater/application.go +++ b/examples/application/event-repeater/application.go @@ -13,6 +13,7 @@ import ( "sync" ) +// NewEventRepeater creates an event repeater application. func NewEventRepeater(eSource string, eSink string, protocol string, allowall bool) application.Plugin { sub, err := event_rpc.NewClient(eSource) if err != nil { @@ -71,6 +72,7 @@ type eventRepeater struct { eventListMt *sync.Mutex } +// RepeatRule for each event type RepeatRule struct { SourceTopic string SinkTopic string @@ -80,8 +82,8 @@ type RepeatRule struct { } type messageData struct { - SourceTopic string `json:"sourcetopic",omitempty"` - SinkTopic string `json:"sinktopic",omitempty"` + SourceTopic string `json:"sourcetopic, omitempty"` + SinkTopic string `json:"sinktopic, omitempty"` } func (e eventRepeater) Validate(applicationProperties *types.Any) error { @@ -92,7 +94,7 @@ func (e eventRepeater) Healthy(applicationProperties *types.Any) (application.He return application.Healthy, nil } -func (e eventRepeater) AddEvent(sourcesTopic string, sinkTopic string) error { +func (e eventRepeater) addEvent(sourcesTopic string, sinkTopic string) error { if sourcesTopic == "" { return fmt.Errorf("Error: %s", "You must have a topic of source for add repeat event.") } @@ -120,7 +122,7 @@ func (e eventRepeater) AddEvent(sourcesTopic string, sinkTopic string) error { return nil } -func (e eventRepeater) DelEvent(sourcesTopic string) error { +func (e eventRepeater) delEvent(sourcesTopic string) error { if sourcesTopic == "" { return fmt.Errorf("Error: %s", "You must have a topic of source for delete repeat event.") } @@ -167,7 +169,6 @@ func (e eventRepeater) publishToSink(rr *RepeatRule) error { } } } - return nil } func (e eventRepeater) Update(message *application.Message) error { @@ -183,25 +184,25 @@ func (e eventRepeater) Update(message *application.Message) error { case application.ADD: for _, d := range dataStruct { log.Debugf("Add message %v \n", d) - err := e.AddEvent(d.SourceTopic, d.SinkTopic) + err := e.addEvent(d.SourceTopic, d.SinkTopic) if err != nil { return err } } case application.DELETE: for _, d := range dataStruct { - err := e.DelEvent(d.SourceTopic) + err := e.delEvent(d.SourceTopic) if err != nil { return err } } case application.UPDATE: for _, d := range dataStruct { - err := e.DelEvent(d.SourceTopic) + err := e.delEvent(d.SourceTopic) if err != nil { return err } - err = e.AddEvent(d.SourceTopic, d.SinkTopic) + err = e.addEvent(d.SourceTopic, d.SinkTopic) if err != nil { return err } @@ -218,7 +219,7 @@ func (e eventRepeater) Update(message *application.Message) error { func (e eventRepeater) serve() error { if e.allowAll { - e.AddEvent(".", "") + e.addEvent(".", "") } for { select { diff --git a/pkg/rpc/application/service.go b/pkg/rpc/application/service.go index 722a27d9a..36dc90dd3 100644 --- a/pkg/rpc/application/service.go +++ b/pkg/rpc/application/service.go @@ -151,6 +151,7 @@ func (p *Application) Healthy(_ *http.Request, req *HealthyRequest, resp *Health return nil } +// Update specify resource information func (p *Application) Update(_ *http.Request, req *UpdateRequest, resp *UpdateResponse) error { resp.Type = req.Type c := p.getPlugin(req.Type) diff --git a/pkg/spi/application/types.go b/pkg/spi/application/types.go index 0ae939e57..a0a83a53a 100644 --- a/pkg/spi/application/types.go +++ b/pkg/spi/application/types.go @@ -4,19 +4,28 @@ import ( "github.com/docker/infrakit/pkg/types" ) +// Type is the type of an application. This gives hint about what struct types to map to, etc. +// It also marks one instance of an application as of different nature from another. type Type string + +//Operation : update operation code type Operation int const ( // TypeError is the type to use for sending errors in the transport of the events. TypeError = Type("error") + // ADD new resources ADD Operation = iota + // DELETE resources DELETE + // UPDATE resources UPDATE + // GET resources GET ) +// Message :update message struct type Message struct { Op Operation Resource string diff --git a/pkg/spi/event/spi.go b/pkg/spi/event/spi.go index 2a46a5aaf..219481ab9 100644 --- a/pkg/spi/event/spi.go +++ b/pkg/spi/event/spi.go @@ -40,7 +40,3 @@ type Subscriber interface { // SubscribeOn returns the channel for the topic SubscribeOn(topic types.Path) (<-chan *Event, chan<- struct{}, error) } - -type Application interface { - List(topic types.Path) ([]string, error) -}