diff --git a/pkg/manager/impl/reservation_manager.go b/pkg/manager/impl/reservation_manager.go index f6f94543..8c234393 100644 --- a/pkg/manager/impl/reservation_manager.go +++ b/pkg/manager/impl/reservation_manager.go @@ -88,14 +88,14 @@ func NewReservationManager( } func (r *reservationManager) GetOrReserveArtifact(ctx context.Context, request *datacatalog.GetOrReserveArtifactRequest) (*datacatalog.GetOrReserveArtifactResponse, error) { - reservationId := request.ReservationId - tagKey := transformers.ToTagKey(reservationId.DatasetId, reservationId.TagName) + reservationID := request.ReservationId + tagKey := transformers.ToTagKey(reservationID.DatasetId, reservationID.TagName) tag, err := r.repo.TagRepo().Get(ctx, tagKey) if err != nil { if errors.IsDoesNotExistError(err) { // Tag does not exist yet, let's acquire the reservation to work on // generating the artifact. - status, err := r.tryAcquireReservation(ctx, reservationId, request.OwnerId) + status, err := r.tryAcquireReservation(ctx, reservationID, request.OwnerId) if err != nil { r.systemMetrics.acquireReservationFailure.Inc(ctx) return nil, err @@ -130,9 +130,9 @@ func (r *reservationManager) GetOrReserveArtifact(ctx context.Context, request * // to do a GET here because we want to know who owns the reservation // and show it to users on the UI. However, the reservation is held by a single // task most of the times and there is no need to do a write. -func (r *reservationManager) tryAcquireReservation(ctx context.Context, reservationId *datacatalog.ReservationID, ownerId string) (datacatalog.ReservationStatus, error) { +func (r *reservationManager) tryAcquireReservation(ctx context.Context, reservationID *datacatalog.ReservationID, ownerID string) (datacatalog.ReservationStatus, error) { repo := r.repo.ReservationRepo() - reservationKey := transformers.FromReservationID(reservationId) + reservationKey := transformers.FromReservationID(reservationID) reservation, err := repo.Get(ctx, reservationKey) reservationExists := true @@ -148,7 +148,7 @@ func (r *reservationManager) tryAcquireReservation(ctx context.Context, reservat now := r.now() newReservation := models.Reservation{ ReservationKey: reservationKey, - OwnerID: ownerId, + OwnerID: ownerID, ExpiresAt: now.Add(r.heartbeatInterval * r.heartbeatGracePeriodMultiplier), } @@ -157,7 +157,7 @@ func (r *reservationManager) tryAcquireReservation(ctx context.Context, reservat var repoErr error if !reservationExists { repoErr = repo.Create(ctx, newReservation, now) - } else if reservation.ExpiresAt.Before(now) || reservation.OwnerID == ownerId { + } else if reservation.ExpiresAt.Before(now) || reservation.OwnerID == ownerID { repoErr = repo.Update(ctx, newReservation, now) } else { logger.Debugf(ctx, "Reservation: %+v is held by %s", reservationKey, reservation.OwnerID) diff --git a/pkg/manager/impl/reservation_manager_test.go b/pkg/manager/impl/reservation_manager_test.go index d14181fc..7a8f958d 100644 --- a/pkg/manager/impl/reservation_manager_test.go +++ b/pkg/manager/impl/reservation_manager_test.go @@ -68,7 +68,7 @@ func TestGetOrReserveArtifact_ArtifactExists(t *testing.T) { req := datacatalog.GetOrReserveArtifactRequest{ ReservationId: &reservationID, - OwnerId: currentOwner, + OwnerId: currentOwner, } resp, err := reservationManager.GetOrReserveArtifact(context.Background(), &req) @@ -237,7 +237,7 @@ func TestGetOrReserveArtifact_ExtendReservation(t *testing.T) { req := datacatalog.GetOrReserveArtifactRequest{ ReservationId: &reservationID, - OwnerId: prevOwner, + OwnerId: prevOwner, } resp, err := reservationManager.GetOrReserveArtifact(context.Background(), &req) diff --git a/pkg/repositories/gormimpl/reservation.go b/pkg/repositories/gormimpl/reservation.go index 53bae84f..31f9f516 100644 --- a/pkg/repositories/gormimpl/reservation.go +++ b/pkg/repositories/gormimpl/reservation.go @@ -67,14 +67,14 @@ func (r *reservationRepo) Delete(ctx context.Context, reservationKey models.Rese if result.RowsAffected == 0 { return errors2.GetMissingEntityError("Reservation", - &datacatalog.ReservationID { + &datacatalog.ReservationID{ DatasetId: &datacatalog.DatasetID{ Project: reservationKey.DatasetProject, Domain: reservationKey.DatasetDomain, Name: reservationKey.DatasetName, Version: reservationKey.DatasetVersion, }, - TagName: reservationKey.TagName, + TagName: reservationKey.TagName, }) } diff --git a/pkg/repositories/transformers/reservation.go b/pkg/repositories/transformers/reservation.go index 71a471a8..770d5754 100644 --- a/pkg/repositories/transformers/reservation.go +++ b/pkg/repositories/transformers/reservation.go @@ -32,8 +32,8 @@ func CreateReservationStatus(reservation *models.Reservation, heartbeatInterval heartbeatIntervalPb := ptypes.DurationProto(heartbeatInterval) return datacatalog.ReservationStatus{ - ReservationId: &datacatalog.ReservationID { - DatasetId: &datacatalog.DatasetID { + ReservationId: &datacatalog.ReservationID{ + DatasetId: &datacatalog.DatasetID{ Project: reservation.DatasetProject, Domain: reservation.DatasetDomain, Name: reservation.DatasetName, diff --git a/pkg/repositories/transformers/reservation_test.go b/pkg/repositories/transformers/reservation_test.go index 496a1487..87ff6bc2 100644 --- a/pkg/repositories/transformers/reservation_test.go +++ b/pkg/repositories/transformers/reservation_test.go @@ -30,24 +30,25 @@ func TestFromReservationID(t *testing.T) { func TestCreateReservationStatus(t *testing.T) { now := time.Now() - heartbeatInterval := time.Duration(time.Second * 5) - reservation := models.Reservation { - ReservationKey: models.ReservationKey { + heartbeatInterval := time.Second * 5 + reservation := models.Reservation{ + ReservationKey: models.ReservationKey{ DatasetProject: "p", DatasetName: "n", DatasetDomain: "d", DatasetVersion: "v", TagName: "t", }, - OwnerID: "o", + OwnerID: "o", ExpiresAt: now, } reservationStatus, err := CreateReservationStatus(&reservation, heartbeatInterval, datacatalog.ReservationStatus_ACQUIRED) assert.Equal(t, err, nil) - assert.Equal(t, reservationStatus.OwnerId, reservation.OwnerID) assert.Equal(t, reservationStatus.ExpiresAt.AsTime(), reservation.ExpiresAt.UTC()) + assert.Equal(t, reservationStatus.HeartbeatInterval.AsDuration(), heartbeatInterval) + assert.Equal(t, reservationStatus.OwnerId, reservation.OwnerID) reservationID := reservationStatus.ReservationId assert.Equal(t, reservationID.TagName, reservation.TagName)