diff --git a/pkg/scd/operational_intents_handler.go b/pkg/scd/operational_intents_handler.go index cce204de4..6a63f8753 100644 --- a/pkg/scd/operational_intents_handler.go +++ b/pkg/scd/operational_intents_handler.go @@ -354,7 +354,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 @@ -475,7 +475,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) // Check if a subscription is required for this request: // OIRs in an accepted state do not need a subscription. @@ -515,7 +515,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 { @@ -524,7 +524,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) } @@ -731,16 +731,14 @@ 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) + version := scdmodels.VersionNumber(1) if old != nil { - version = int32(old.Version) + version = old.Version + 1 } var sub *scdmodels.Subscription @@ -820,7 +818,7 @@ func (a *Server) upsertOperationalIntentReference(ctx context.Context, authorize op := &scdmodels.OperationalIntent{ ID: validParams.id, Manager: manager, - Version: scdmodels.VersionNumber(version + 1), + Version: version, StartTime: validParams.uExtent.StartTime, EndTime: validParams.uExtent.EndTime,