Skip to content

Commit

Permalink
cover delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick committed Sep 2, 2024
1 parent 47e45c3 commit 8228781
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions pkg/scd/operational_intents_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ func (a *Server) DeleteOperationalIntentReference(ctx context.Context, req *rest
}
}

// Find Subscriptions that may overlap the OperationalIntent's Volume4D
allsubs, err := r.SearchSubscriptions(ctx, &dssmodels.Volume4D{
notifyVolume := &dssmodels.Volume4D{
StartTime: old.StartTime,
EndTime: old.EndTime,
SpatialVolume: &dssmodels.Volume3D{
Expand All @@ -104,23 +103,9 @@ func (a *Server) DeleteOperationalIntentReference(ctx context.Context, req *rest
Footprint: dssmodels.GeometryFunc(func() (s2.CellUnion, error) {
return old.Cells, nil
}),
}})
if err != nil {
return stacktrace.Propagate(err, "Unable to search Subscriptions in repo")
}

// Limit Subscription notifications to only those interested in OperationalIntents
subs := repos.Subscriptions{}
for _, s := range allsubs {
if s.NotifyForOperationalIntents {
subs = append(subs, s)
}
}
}}

// Increment notification indices for Subscriptions to be notified
if err := subs.IncrementNotificationIndices(ctx, r); err != nil {
return stacktrace.Propagate(err, "Unable to increment notification indices")
}
subsToNotify, err := getRelevantSubscriptionsAndIncrementIndices(ctx, r, notifyVolume)

// Delete OperationalIntent from repo
if err := r.DeleteOperationalIntent(ctx, id); err != nil {
Expand All @@ -139,7 +124,7 @@ func (a *Server) DeleteOperationalIntentReference(ctx context.Context, req *rest
// Return response to client
response = &restapi.ChangeOperationalIntentReferenceResponse{
OperationalIntentReference: *old.ToRest(),
Subscribers: makeSubscribersToNotify(subs),
Subscribers: makeSubscribersToNotify(subsToNotify),
}

return nil
Expand Down Expand Up @@ -517,12 +502,13 @@ func validateUpsertRequestAgainstPreviousOIR(
return nil
}

func getRelevantSubscriptionsAndIncrementIndices(
ctx context.Context,
r repos.Repository,
// upsertOperationalIntentReference computes the volume that neeeds to be queried for subscriptions
// given the requested extend and the (possibly nil) previous operational intent.
// The returned volume is either the union of the requested extent and the previous extent, or just the requested extent
// if the previous OIR is nil.
func computeNotificationVolume(
previousOIR *scdmodels.OperationalIntent,
requestedExtent *dssmodels.Volume4D,
) (repos.Subscriptions, error) {
requestedExtent *dssmodels.Volume4D) (*dssmodels.Volume4D, error) {

// Compute total affected Volume4D for notification purposes
notifyVol4 := requestedExtent
Expand All @@ -545,6 +531,15 @@ func getRelevantSubscriptionsAndIncrementIndices(
}
}

return notifyVol4, nil
}

func getRelevantSubscriptionsAndIncrementIndices(
ctx context.Context,
r repos.Repository,
notifyVol4 *dssmodels.Volume4D,
) (repos.Subscriptions, error) {

// Find Subscriptions that may need to be notified
allsubs, err := r.SearchSubscriptions(ctx, notifyVol4)
if err != nil {
Expand Down Expand Up @@ -814,8 +809,13 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize
return stacktrace.Propagate(err, "Failed to upsert OperationalIntent in repo")
}

notifyVolume, err := computeNotificationVolume(old, validParams.uExtent)
if err != nil {
return stacktrace.Propagate(err, "Failed to compute notification volume")
}

// Notify relevant Subscriptions
subsToNotify, err := getRelevantSubscriptionsAndIncrementIndices(ctx, r, old, validParams.uExtent)
subsToNotify, err := getRelevantSubscriptionsAndIncrementIndices(ctx, r, notifyVolume)
if err != nil {
return stacktrace.Propagate(err, "Failed to notify relevant Subscriptions")
}
Expand Down

0 comments on commit 8228781

Please sign in to comment.