Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event source was lost when converting cloud native events to events. #39

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/event/event_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (e *Event) NewCloudEvent(ps *pubsub.PubSub) (*cloudevent.Event, error) {
ce.SetTime(e.GetTime())
ce.SetType(e.Type)
ce.SetDataContentType(cloudevent.ApplicationJSON)
ce.SetSubject(e.Source) // subject is set to source of the event object
ce.SetSource(ps.Resource) // bus address
ce.SetSpecVersion(cloudevent.VersionV03)
ce.SetID(uuid.New().String())
Expand All @@ -50,7 +51,9 @@ func (e *Event) GetCloudNativeEvents(ce *cloudevent.Event) (err error) {
e.SetDataContentType(ApplicationJSON)
e.SetTime(ce.Time())
e.SetType(ce.Type())
e.SetSource(ce.Source())
e.SetSource(ce.Subject())
e.SetData(data)
e.SetID(ce.ID())

return
}
6 changes: 5 additions & 1 deletion pkg/event/event_ce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestEvent_NewCloudEvent(t *testing.T) {
e.SetType(_type)
e.SetSource(_source)
e.SetData(data)
e.SetID(id)
return &e
}(),
cnePubsub: &pubsub,
Expand All @@ -89,6 +90,7 @@ func TestEvent_NewCloudEvent(t *testing.T) {
_ = e.SetData(ce.ApplicationJSON, data)
e.SetTime(now.Time)
e.SetSource(pubsub.GetResource())
e.SetSubject(_source)
e.SetID(id)
return &e
}(),
Expand Down Expand Up @@ -124,6 +126,7 @@ func TestEvent_GetCloudNativeEvents(t *testing.T) {
_ = e.SetData(ce.ApplicationJSON, data)
e.SetTime(now.Time)
e.SetSource(pubsub.GetResource())
e.SetSubject(_source)
e.SetID(id)
return &e
}(),
Expand All @@ -132,8 +135,9 @@ func TestEvent_GetCloudNativeEvents(t *testing.T) {
e.SetDataContentType(cneevent.ApplicationJSON)
e.SetTime(now.Time)
e.SetType(_type)
e.SetSource(pubsub.GetResource())
e.SetSource(_source)
e.SetData(data)
e.SetID(id)
return &e
}(),
},
Expand Down
9 changes: 7 additions & 2 deletions pkg/event/redfish/event_ce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
uriLocation = "http://localhost:8089/api/cloudNotifications/v1/subscriptions/da42fb86-819e-47c5-84a3-5512d5a3c732"
endPointURI = "http://localhost:9089/event"
resource = "/cluster/node/nodename/redfish/event"
_source = "/cluster/node/nodename/redfish/event/fan"
_type = string(redfish.Alert)
version = "v1"
id = uuid.New().String()
Expand Down Expand Up @@ -98,8 +99,9 @@ func TestEvent_NewCloudEvent(t *testing.T) {
e.SetDataContentType(cneevent.ApplicationJSON)
e.SetTime(now.Time)
e.SetType(_type)
e.SetSource(pubsub.GetResource())
e.SetSource(_source)
e.SetData(data)
e.SetID(id)
return &e
}(),
cnePubsub: &pubsub,
Expand All @@ -110,6 +112,7 @@ func TestEvent_NewCloudEvent(t *testing.T) {
_ = e.SetData(ce.ApplicationJSON, data)
e.SetTime(now.Time)
e.SetSource(pubsub.GetResource())
e.SetSubject(_source)
e.SetID(id)
return &e
}(),
Expand Down Expand Up @@ -145,6 +148,7 @@ func TestEvent_GetCloudNativeEvents(t *testing.T) {
_ = e.SetData(ce.ApplicationJSON, data)
e.SetTime(now.Time)
e.SetSource(pubsub.GetResource())
e.SetSubject(_source)
e.SetID(id)
return &e
}(),
Expand All @@ -153,8 +157,9 @@ func TestEvent_GetCloudNativeEvents(t *testing.T) {
e.SetDataContentType(cneevent.ApplicationJSON)
e.SetTime(now.Time)
e.SetType(_type)
e.SetSource(pubsub.GetResource())
e.SetSource(_source)
e.SetData(data)
e.SetID(id)
return &e
}(),
},
Expand Down
1 change: 1 addition & 0 deletions v1/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func GetCloudNativeEvents(ce cloudevents.Event) (e event.Event, err error) {
e.SetTime(ce.Time())
e.SetType(ce.Type())
e.SetSource(ce.Source())
e.SetID(ce.ID())
e.SetData(data)
return
}