Skip to content

Commit

Permalink
O-RAN V3 Rest Api: Status Notification
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Ding <jackding@gmail.com>
  • Loading branch information
jzding committed Jul 9, 2024
1 parent da39815 commit 3db84e4
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 43 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240702163442-605f629084b9
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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240702163442-605f629084b9 h1:qDOGSHOtHRszd8FnM0GZVUvbIvHhZrw5GeccXYPwT04=
github.com/redhat-cne/sdk-go v1.0.1-0.20240702163442-605f629084b9/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=
Expand Down
34 changes: 14 additions & 20 deletions v2/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,19 @@ func (s *Server) createSubscription(w http.ResponseWriter, r *http.Request) {
localmetrics.UpdateSubscriptionCount(localmetrics.FAILCREATE, 1)
return
}
if subExists, ok := s.pubSubAPI.HasSubscription(sub.GetResource()); ok {
clientIDs := s.subscriberAPI.GetClientIDByResource(sub.GetResource())
if len(clientIDs) != 0 {
respondWithStatusCode(w, http.StatusConflict,
fmt.Sprintf("subscription (id: %s) with same resource already exists, skipping creation",
subExists.GetID()))
fmt.Sprintf("subscription (clientID: %s) with same resource already exists, skipping creation",
clientIDs[0]))
return
}

id := uuid.New().String()
sub.SetID(id)
sub.SetVersion(API_VERSION)
sub.SetURILocation(fmt.Sprintf("http://localhost:%d%s%s/%s", s.port, s.apiPath, "subscriptions", sub.ID)) //nolint:errcheck

// TODO: cleanup: local pubsub is no longer needed since we are using configMap
newSub, err := s.pubSubAPI.CreateSubscription(sub)
if err != nil {
respondWithStatusCode(w, http.StatusNotFound, fmt.Sprintf("error creating subscription %v", err))
localmetrics.UpdateSubscriptionCount(localmetrics.FAILCREATE, 1)
return
}
addr := newSub.GetResource()
addr := sub.GetResource()

// this is placeholder not sending back to report
out := channel.DataChan{
Expand Down Expand Up @@ -119,7 +112,8 @@ func (s *Server) createSubscription(w http.ResponseWriter, r *http.Request) {
}

restClient := restclient.New()
out.Data.SetID(newSub.ID) // set ID to the subscriptionID
// make sure event ID is unique
out.Data.SetID(uuid.New().String())
status, err := restClient.PostCloudEvent(sub.EndPointURI, *out.Data)
if err != nil {
respondWithStatusCode(w, http.StatusBadRequest,
Expand All @@ -139,7 +133,7 @@ func (s *Server) createSubscription(w http.ResponseWriter, r *http.Request) {
subs := subscriber.New(s.getClientIDFromURI(endPointURI))
_ = subs.SetEndPointURI(endPointURI)

subs.AddSubscription(newSub)
subs.AddSubscription(sub)
subs.Action = channel.NEW
cevent, _ := subs.CreateCloudEvents()
cevent.SetSource(addr)
Expand All @@ -165,7 +159,7 @@ func (s *Server) createSubscription(w http.ResponseWriter, r *http.Request) {
_ = out.Data.SetData(cloudevents.ApplicationJSON, updatedObj)
log.Infof("subscription created successfully.")
localmetrics.UpdateSubscriptionCount(localmetrics.ACTIVE, 1)
respondWithJSON(w, http.StatusCreated, newSub)
respondWithJSON(w, http.StatusCreated, sub)
}

s.dataOut <- &out
Expand Down Expand Up @@ -441,12 +435,12 @@ func (s *Server) getCurrentState(w http.ResponseWriter, r *http.Request) {
}
}
} else {
respondWithError(w, "subscription not found")
respondWithStatusCode(w, http.StatusNotFound, "subscription not found")
return
}

if sub == nil {
respondWithError(w, "subscription not found")
respondWithStatusCode(w, http.StatusNotFound, "subscription not found")
return
}

Expand All @@ -471,14 +465,14 @@ func (s *Server) getCurrentState(w http.ResponseWriter, r *http.Request) {
// statusReceiveOverrideFn must return value for
if s.statusReceiveOverrideFn != nil {
if statusErr := s.statusReceiveOverrideFn(*e, &out); statusErr != nil {
respondWithError(w, statusErr.Error())
respondWithStatusCode(w, http.StatusNotFound, statusErr.Error())
} else if out.Data != nil {
respondWithJSON(w, http.StatusOK, *out.Data)
} else {
respondWithError(w, "event not found")
respondWithStatusCode(w, http.StatusNotFound, "event not found")
}
} else {
respondWithError(w, "onReceive function not defined")
respondWithStatusCode(w, http.StatusNotFound, "onReceive function not defined")
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.20240702163442-605f629084b9
# 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
Expand Down

0 comments on commit 3db84e4

Please sign in to comment.