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 67d531c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 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 exists and is implicit
// - the subscription is attached to the specified operational intent
// - the subscription is not attached to any other operational intent
//
// This is to be used in contexts where an implicit subscription may need to be cleaned up: if true is returned,
// the subscription can be safely removed after the operational intent is deleted or attached to another subscription.
//
// 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 67d531c

Please sign in to comment.