Skip to content

Commit

Permalink
rename and make subscriptionCanBeRemoved more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick committed Aug 13, 2024
1 parent a32df4a commit ddf25c7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/scd/operational_intents_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import (
"github.com/interuss/stacktrace"
)

// subscriptionCanBeRemoved will check if:
// - a previous subscription was attached,
// - if so, if it was an implicit subscription
// - if so, if we can remove it after creating the new implicit subscription
// subscriptionIsOnlyAttachedToOIR will check if:
// - the subscription is attached to the specified operational intent,
// - if so, if it is an implicit subscription
// - if so, if it is the only one (it isn't attached to other operational intents)
//
// If true is returned, the passed OIR ID is the only one attached to the subscription, and the subscription is implicit.
//
// This is to be used in contexts where an implicit subscription may need to be cleaned up.
// NOTE: this should eventually be pushed down to CRDB as part of the queries being executed in the callers of this method.
//
// See https://github.com/interuss/dss/issues/1059 for more details
func subscriptionCanBeRemoved(ctx context.Context, r repos.Repository, subscriptionID *dssmodels.ID) (bool, error) {
func subscriptionIsOnlyAttachedToOIR(ctx context.Context, r repos.Repository, oirID, subscriptionID *dssmodels.ID) (bool, error) {
// Get the Subscription supporting the OperationalIntent, if one is defined
if subscriptionID != nil {
sub, err := r.GetSubscription(ctx, *subscriptionID)
Expand All @@ -44,7 +46,7 @@ func subscriptionCanBeRemoved(ctx context.Context, r repos.Repository, subscript
}
if len(dependentOps) == 0 {
return false, stacktrace.NewError("An implicit Subscription had no dependent OperationalIntents")
} else if len(dependentOps) == 1 {
} else if len(dependentOps) == 1 && dependentOps[0] == *oirID {
return true, nil
}
}
Expand Down Expand Up @@ -92,7 +94,7 @@ func (a *Server) DeleteOperationalIntentReference(ctx context.Context, req *rest
"OperationalIntent owned by %s, but %s attempted to delete", old.Manager, *req.Auth.ClientID)
}

removeImplicitSubscription, err := subscriptionCanBeRemoved(ctx, r, old.SubscriptionID)
removeImplicitSubscription, err := subscriptionIsOnlyAttachedToOIR(ctx, r, &id, old.SubscriptionID)
if err != nil {
return stacktrace.Propagate(err, "Could not determine if Subscription can be removed")
}
Expand Down Expand Up @@ -509,7 +511,7 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize
}
}

removePreviousImplicitSubscription, err = subscriptionCanBeRemoved(ctx, r, previousSubscriptionID)
removePreviousImplicitSubscription, err = subscriptionIsOnlyAttachedToOIR(ctx, r, &id, previousSubscriptionID)
if err != nil {
return stacktrace.Propagate(err, "Could not determine if previous Subscription can be removed")
}
Expand Down

0 comments on commit ddf25c7

Please sign in to comment.