Skip to content

Commit

Permalink
refactor: drop application from the lease manager getter
Browse files Browse the repository at this point in the history
Application is the implementation detail of the model lease manager
getter. We could have another implementation that is for singular
controllers. The interface shouldn't care. It's just offering out
a given type.
  • Loading branch information
SimonRichardson committed Nov 8, 2024
1 parent a5590a8 commit 6a67cfe
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 98 deletions.
11 changes: 6 additions & 5 deletions core/lease/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ type LeaseCheckerWaiter interface {
Checker
}

// ApplicationLeaseManagerGetter is an interface that provides a method to get a
// lease manager for a given application using its UUID.
type ApplicationLeaseManagerGetter interface {
// LeaseManagerGetter is an interface that provides a method to get a lease
// manager for a given lease using its UUID. The lease namespace could be a
// model or an application.
type LeaseManagerGetter interface {
// GetLeaseManager returns a lease manager for the given model UUID.
GetLeaseManager(model.UUID) (LeaseCheckerWaiter, error)
}

// ModelApplicationLeaseManagerGetter is an interface that provides a method to
// ModelLeaseManagerGetter is an interface that provides a method to
// get a lease manager in the scope of a model.
type ModelApplicationLeaseManagerGetter interface {
type ModelLeaseManagerGetter interface {
// GetLeaseManager returns a lease manager for the given model UUID.
GetLeaseManager() (LeaseCheckerWaiter, error)
}
44 changes: 22 additions & 22 deletions domain/lease_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions domain/leaseservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

// LeaseService creates a base service that offers lease capabilities.
type LeaseService struct {
leaseChecker lease.ModelApplicationLeaseManagerGetter
leaseChecker lease.ModelLeaseManagerGetter
}

// NewLeaseService creates a new LeaseService.
func NewLeaseService(leaseChecker lease.ModelApplicationLeaseManagerGetter) *LeaseService {
func NewLeaseService(leaseChecker lease.ModelLeaseManagerGetter) *LeaseService {
return &LeaseService{
leaseChecker: leaseChecker,
}
Expand All @@ -31,7 +31,7 @@ func (s *LeaseService) WithLease(ctx context.Context, leaseName, holderName stri
// Holding the lease is quite a complex operation, so we need to ensure that
// the context is not cancelled before we start the operation.
if err := ctx.Err(); err != nil {
return internalerrors.Errorf("lease prechecking").Add(ctx.Err())
return internalerrors.Errorf("lease pre-checking").Add(ctx.Err())
}

leaseChecker, err := s.leaseChecker.GetLeaseManager()
Expand Down
4 changes: 2 additions & 2 deletions domain/leaseservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type leaseServiceSuite struct {
testing.IsolationSuite

modelLeaseManager *MockModelApplicationLeaseManagerGetter
modelLeaseManager *MockModelLeaseManagerGetter
leaseCheckerWaiter *MockLeaseCheckerWaiter
token *MockToken
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func (s *leaseServiceSuite) TestWithLeaseFailsOnWaitCheck(c *gc.C) {
func (s *leaseServiceSuite) setupMocks(c *gc.C) *gomock.Controller {
ctrl := gomock.NewController(c)

s.modelLeaseManager = NewMockModelApplicationLeaseManagerGetter(ctrl)
s.modelLeaseManager = NewMockModelLeaseManagerGetter(ctrl)
s.leaseCheckerWaiter = NewMockLeaseCheckerWaiter(ctrl)
s.token = NewMockToken(ctrl)

Expand Down
2 changes: 1 addition & 1 deletion domain/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

//go:generate go run go.uber.org/mock/mockgen -typed -package domain -destination changestream_mock_test.go github.com/juju/juju/core/changestream Subscription,EventSource
//go:generate go run go.uber.org/mock/mockgen -typed -package domain -destination lease_mock_test.go github.com/juju/juju/core/lease Token,LeaseCheckerWaiter,ModelApplicationLeaseManagerGetter
//go:generate go run go.uber.org/mock/mockgen -typed -package domain -destination lease_mock_test.go github.com/juju/juju/core/lease Token,LeaseCheckerWaiter,ModelLeaseManagerGetter

func TestPackage(t *testing.T) {
defer goleak.VerifyNone(t)
Expand Down
4 changes: 2 additions & 2 deletions domain/services/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type ModelFactory struct {
objectstore objectstore.ModelObjectStoreGetter
storageRegistry corestorage.ModelStorageRegistryGetter
publicKeyImporter PublicKeyImporter
leaseManager lease.ModelApplicationLeaseManagerGetter
leaseManager lease.ModelLeaseManagerGetter
}

// NewModelFactory returns a new registry which uses the provided modelDB
Expand All @@ -100,7 +100,7 @@ func NewModelFactory(
objectStore objectstore.ModelObjectStoreGetter,
storageRegistry corestorage.ModelStorageRegistryGetter,
publicKeyImporter PublicKeyImporter,
leaseManager lease.ModelApplicationLeaseManagerGetter,
leaseManager lease.ModelLeaseManagerGetter,
clock clock.Clock,
logger logger.Logger,
) *ModelFactory {
Expand Down
2 changes: 1 addition & 1 deletion domain/services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewDomainServices(
objectStore objectstore.ModelObjectStoreGetter,
storageRegistry storage.ModelStorageRegistryGetter,
publicKeyImporter PublicKeyImporter,
leaseManager lease.ModelApplicationLeaseManagerGetter,
leaseManager lease.ModelLeaseManagerGetter,
clock clock.Clock,
logger logger.Logger,
) *DomainServices {
Expand Down
84 changes: 42 additions & 42 deletions internal/worker/domainservices/lease_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6a67cfe

Please sign in to comment.