Skip to content

Commit

Permalink
[scd] Store past OVNs on operational intents upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmis committed Sep 2, 2024
1 parent dfa1062 commit 998a450
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pkg/scd/operational_intents_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (a *Server) UpdateOperationalIntentReference(ctx context.Context, req *rest

type validOIRParams struct {
id dssmodels.ID
ovn restapi.EntityOVN
ovn scdmodels.OVN
state scdmodels.OperationalIntentState
extents []*dssmodels.Volume4D
uExtent *dssmodels.Volume4D
Expand Down Expand Up @@ -446,7 +446,7 @@ func validateAndReturnUpsertParams(
if ovn == "" && params.State != restapi.OperationalIntentState_Accepted {
return nil, stacktrace.NewError("Invalid state for initial version: `%s`", params.State)
}
valid.ovn = ovn
valid.ovn = scdmodels.OVN(ovn)

if params.SubscriptionId != nil {
valid.subscriptionID, err = dssmodels.IDFromOptionalString(string(*params.SubscriptionId))
Expand Down Expand Up @@ -493,7 +493,7 @@ func checkUpsertPermissionsAndReturnManager(authorizedManager *api.Authorization
// - otherwise, it is the version of the previous OIR
func validateUpsertRequestAgainstPreviousOIR(
requestingManager dssmodels.Manager,
providedOVN restapi.EntityOVN,
providedOVN scdmodels.OVN,
previousOIR *scdmodels.OperationalIntent,
) error {

Expand All @@ -502,7 +502,7 @@ func validateUpsertRequestAgainstPreviousOIR(
return stacktrace.NewErrorWithCode(dsserr.PermissionDenied,
"OperationalIntent owned by %s, but %s attempted to modify", previousOIR.Manager, requestingManager)
}
if previousOIR.OVN != scdmodels.OVN(providedOVN) {
if previousOIR.OVN != providedOVN {
return stacktrace.NewErrorWithCode(dsserr.VersionMismatch,
"Current version is %s but client specified version %s", previousOIR.OVN, providedOVN)
}
Expand Down Expand Up @@ -627,16 +627,18 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize
if err != nil {
return stacktrace.Propagate(err, "Could not get OperationalIntent from repo")
}
// Validate the request against the previous OIR and return the current version
// (upon new OIR creation, version is 0)
// Validate the request against the previous OIR
if err := validateUpsertRequestAgainstPreviousOIR(manager, validParams.ovn, old); err != nil {
return stacktrace.PropagateWithCode(err, stacktrace.GetCode(err), "Request validation failed")
}

// For an OIR being created, version starts at 0
version := int32(0)
var (
version = scdmodels.VersionNumber(1)
pastOVNs = []scdmodels.OVN{validParams.ovn}
)
if old != nil {
version = int32(old.Version)
version = old.Version + 1
pastOVNs = append(old.PastOVNs, validParams.ovn)
}

var sub *scdmodels.Subscription
Expand Down Expand Up @@ -739,9 +741,11 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize

// Construct the new OperationalIntent
op := &scdmodels.OperationalIntent{
ID: validParams.id,
Manager: manager,
Version: scdmodels.VersionNumber(version + 1),
ID: validParams.id,
Manager: manager,
Version: version,
OVN: "", // TODO dss#1078: this field must be populated to support USSs setting OVNs in advance
PastOVNs: pastOVNs,

StartTime: validParams.uExtent.StartTime,
EndTime: validParams.uExtent.EndTime,
Expand Down

0 comments on commit 998a450

Please sign in to comment.