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

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Yuji Oshima <[email protected]>
  • Loading branch information
YujiOshima committed Apr 11, 2017
1 parent e47c5e5 commit 07c03f4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions cmd/cli/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 11 additions & 10 deletions examples/application/event-repeater/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -71,6 +72,7 @@ type eventRepeater struct {
eventListMt *sync.Mutex
}

// RepeatRule for each event
type RepeatRule struct {
SourceTopic string
SinkTopic string
Expand All @@ -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 {
Expand All @@ -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.")
}
Expand Down Expand Up @@ -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.")
}
Expand Down Expand Up @@ -167,7 +169,6 @@ func (e eventRepeater) publishToSink(rr *RepeatRule) error {
}
}
}
return nil
}

func (e eventRepeater) Update(message *application.Message) error {
Expand All @@ -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
}
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/rpc/application/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/spi/application/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions pkg/spi/event/spi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 07c03f4

Please sign in to comment.