From 3ba19abba4be9a0eeb9dc1568f9dd04c07fc01f1 Mon Sep 17 00:00:00 2001 From: Jack Ding Date: Mon, 15 Jul 2024 13:08:08 -0400 Subject: [PATCH] Set Event Source according to O-RAN Spec Signed-off-by: Jack Ding --- go.mod | 4 +++- go.sum | 2 -- v2/routes.go | 8 +++----- vendor/github.com/redhat-cne/sdk-go/pkg/event/event_ce.go | 4 ++-- vendor/modules.txt | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 3a87baa..ea58dff 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,14 @@ require ( github.com/google/uuid v1.6.0 github.com/gorilla/mux v1.8.0 github.com/prometheus/client_golang v1.14.0 - github.com/redhat-cne/sdk-go v1.0.1-0.20240715150244-f435c154a612 + github.com/redhat-cne/sdk-go v1.0.1-unpublished github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.8.0 golang.org/x/net v0.7.0 ) +replace github.com/redhat-cne/sdk-go v1.0.1-unpublished => ../sdk-go + require ( github.com/BurntSushi/toml v0.3.1 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/go.sum b/go.sum index 8e618d8..210e666 100644 --- a/go.sum +++ b/go.sum @@ -53,8 +53,6 @@ github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= -github.com/redhat-cne/sdk-go v1.0.1-0.20240715150244-f435c154a612 h1:TnnP33wqdtZ4GCp8WYHVFVywWxrcGonc0ijGCpfqTdU= -github.com/redhat-cne/sdk-go v1.0.1-0.20240715150244-f435c154a612/go.mod h1:q9LxxPbK1tGpDbQm/KIPujqdP0bK1hhuHrIXV3vuUrM= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= diff --git a/v2/routes.go b/v2/routes.go index 89706d8..d2db1ff 100644 --- a/v2/routes.go +++ b/v2/routes.go @@ -400,7 +400,7 @@ func (s *Server) publishEvent(w http.ResponseWriter, r *http.Request) { respondWithError(w, fmt.Sprintf("no publisher data for id %s found to publish event for", cneEvent.ID)) return } - ceEvent, err := cneEvent.NewCloudEventV2(&pub) + ceEvent, err := cneEvent.NewCloudEventV2() if err != nil { localmetrics.UpdateEventPublishedCount(pub.Resource, localmetrics.FAIL, 1) respondWithError(w, err.Error()) @@ -467,7 +467,6 @@ func (s *Server) getCurrentState(w http.ResponseWriter, r *http.Request) { } e, _ := out.CreateCloudEvents(CURRENTSTATE) - e.SetSource(resourceAddress) // statusReceiveOverrideFn must return value for if s.statusReceiveOverrideFn != nil { if statusErr := s.statusReceiveOverrideFn(*e, &out); statusErr != nil { @@ -501,10 +500,9 @@ func (s *Server) pingForSubscribedEventStatus(w http.ResponseWriter, r *http.Req cneEvent.SetTime(types.Timestamp{Time: time.Now().UTC()}.Time) cneEvent.SetDataContentType(cloudevents.ApplicationJSON) cneEvent.SetData(cne.Data{ - - Version: "v1", + Version: cne.APISchemaVersion, }) - ceEvent, err := cneEvent.NewCloudEventV2(&sub) + ceEvent, err := cneEvent.NewCloudEventV2() if err != nil { respondWithError(w, err.Error()) diff --git a/vendor/github.com/redhat-cne/sdk-go/pkg/event/event_ce.go b/vendor/github.com/redhat-cne/sdk-go/pkg/event/event_ce.go index 228b5a2..a5dd91a 100644 --- a/vendor/github.com/redhat-cne/sdk-go/pkg/event/event_ce.go +++ b/vendor/github.com/redhat-cne/sdk-go/pkg/event/event_ce.go @@ -40,11 +40,11 @@ func (e *Event) NewCloudEvent(ps *pubsub.PubSub) (*cloudevent.Event, error) { } // NewCloudEvent create new cloud event from cloud native events and pubsub -func (e *Event) NewCloudEventV2(ps *pubsub.PubSub) (*cloudevent.Event, error) { +func (e *Event) NewCloudEventV2() (*cloudevent.Event, error) { ce := cloudevent.NewEvent(cloudevent.VersionV1) ce.SetTime(e.GetTime()) ce.SetType(e.Type) - ce.SetSource(ps.Resource) // bus address + ce.SetSource(e.Source) ce.SetSpecVersion(cloudevent.VersionV1) ce.SetID(uuid.New().String()) if err := ce.SetData("", e.GetData()); err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index e9a7b74..6090f78 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -71,7 +71,7 @@ github.com/prometheus/common/model github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util -# github.com/redhat-cne/sdk-go v1.0.1-0.20240715150244-f435c154a612 +# github.com/redhat-cne/sdk-go v1.0.1-unpublished => ../sdk-go ## explicit; go 1.22 github.com/redhat-cne/sdk-go/pkg/channel github.com/redhat-cne/sdk-go/pkg/common