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 29, 2024
1 parent e2dc466 commit efbb391
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 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 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 @@ -99,12 +101,16 @@ func (a *Server) DeleteOperationalIntentReference(ctx context.Context, req *rest
"OperationalIntent owned by %s, but %s attempted to delete", old.Manager, *req.Auth.ClientID)
}

<<<<<<< HEAD
if old.OVN != ovn {
return stacktrace.NewErrorWithCode(dsserr.VersionMismatch,
"Current version is %s but client specified version %s", old.OVN, ovn)
}

removeImplicitSubscription, err := subscriptionCanBeRemoved(ctx, r, old.SubscriptionID)
=======
removeImplicitSubscription, err := subscriptionIsOnlyAttachedToOIR(ctx, r, &id, old.SubscriptionID)
>>>>>>> fdd5e11 (rename and make subscriptionCanBeRemoved more specific)
if err != nil {
return stacktrace.Propagate(err, "Could not determine if Subscription can be removed")
}
Expand Down Expand Up @@ -523,7 +529,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 efbb391

Please sign in to comment.