Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
fixed lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Rammer <[email protected]>
  • Loading branch information
hamersaw committed Aug 25, 2021
1 parent 6d5530e commit 8e3778c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
14 changes: 7 additions & 7 deletions pkg/manager/impl/reservation_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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),
}

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/manager/impl/reservation_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/repositories/gormimpl/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/repositories/transformers/reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions pkg/repositories/transformers/reservation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8e3778c

Please sign in to comment.