Skip to content

Commit

Permalink
v2 clean up subscriptions
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Ding <jackding@gmail.com>
  • Loading branch information
jzding committed Aug 15, 2024
1 parent 44062f4 commit ba67c5b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 37 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.20240809152305-d59009827df0
github.com/redhat-cne/sdk-go v1.0.0-new
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.0-new => ../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.20240809152305-d59009827df0 h1:1dHxOlK41SQ4OCpMk+D0vM141zLVNplLooCTLk4F/wc=
github.com/redhat-cne/sdk-go v1.0.1-0.20240809152305-d59009827df0/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
49 changes: 26 additions & 23 deletions v2/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,6 @@ func (s *Server) sendOut(eType channel.Type, sub *pubsub.PubSub) {
}
}

func (s *Server) sendOutToDelete(eType channel.Type, sub *pubsub.PubSub) {
// go ahead and create QDR to this address
s.dataOut <- &channel.DataChan{
ID: sub.GetID(),
Address: sub.GetResource(),
Data: &ce.Event{},
Type: eType,
Status: channel.DELETE,
}
}

func (s *Server) getSubscriptionByID(w http.ResponseWriter, r *http.Request) {
queries := mux.Vars(r)
subscriptionID, ok := queries["subscriptionid"]
Expand Down Expand Up @@ -340,9 +329,10 @@ func (s *Server) deleteSubscription(w http.ResponseWriter, r *http.Request) {
for _, subs := range s.subscriberAPI.SubscriberStore.Store {
cevent, _ := subs.CreateCloudEvents()
out := channel.DataChan{
Data: cevent,
Status: channel.SUCCESS,
Type: channel.SUBSCRIBER,
ClientID: subs.GetClientID(),
Data: cevent,
Status: channel.SUCCESS,
Type: channel.SUBSCRIBER,
}
s.dataOut <- &out
}
Expand All @@ -352,18 +342,31 @@ func (s *Server) deleteSubscription(w http.ResponseWriter, r *http.Request) {
}

func (s *Server) deleteAllSubscriptions(w http.ResponseWriter, _ *http.Request) {
size := len(s.pubSubAPI.GetSubscriptions())
if err := s.pubSubAPI.DeleteAllSubscriptions(); err != nil {
// update configMap
for _, subs := range s.subscriberAPI.SubscriberStore.Store {
cevent, _ := subs.CreateCloudEvents()
out := channel.DataChan{
ClientID: subs.GetClientID(),
Data: cevent,
Status: channel.DELETE,
Type: channel.SUBSCRIBER,
}
s.dataOut <- &out
}

numSubDeleted, err := s.subscriberAPI.DeleteAllSubscriptions()

// Subscriptions could be partially deleted when there were errors
if numSubDeleted > 0 {
localmetrics.UpdateSubscriptionCount(localmetrics.ACTIVE, -(numSubDeleted))
}

if err != nil {
respondWithError(w, err.Error())
return
}
//update metrics
if size > 0 {
localmetrics.UpdateSubscriptionCount(localmetrics.ACTIVE, -(size))
}
// go ahead and create QDR to this address
s.sendOutToDelete(channel.SUBSCRIBER, &pubsub.PubSub{ID: "", Resource: "delete-all-subscriptions"})
respondWithMessage(w, http.StatusOK, "deleted all subscriptions")

respondWithStatusCode(w, http.StatusNoContent, "")
}

func (s *Server) deleteAllPublishers(w http.ResponseWriter, _ *http.Request) {
Expand Down

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.20240809152305-d59009827df0
# github.com/redhat-cne/sdk-go v1.0.0-new => ../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 ba67c5b

Please sign in to comment.