diff --git a/core/lease/lease.go b/core/lease/lease.go index 77d7c21ce14..a41b0850650 100644 --- a/core/lease/lease.go +++ b/core/lease/lease.go @@ -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) } diff --git a/domain/lease_mock_test.go b/domain/lease_mock_test.go index 3e1958bbf70..ec966225c65 100644 --- a/domain/lease_mock_test.go +++ b/domain/lease_mock_test.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/juju/juju/core/lease (interfaces: Token,LeaseCheckerWaiter,ModelApplicationLeaseManagerGetter) +// Source: github.com/juju/juju/core/lease (interfaces: Token,LeaseCheckerWaiter,ModelLeaseManagerGetter) // // Generated by this command: // -// mockgen -typed -package domain -destination lease_mock_test.go github.com/juju/juju/core/lease Token,LeaseCheckerWaiter,ModelApplicationLeaseManagerGetter +// mockgen -typed -package domain -destination lease_mock_test.go github.com/juju/juju/core/lease Token,LeaseCheckerWaiter,ModelLeaseManagerGetter // // Package domain is a generated GoMock package. @@ -177,31 +177,31 @@ func (c *MockLeaseCheckerWaiterWaitUntilExpiredCall) DoAndReturn(f func(context. return c } -// MockModelApplicationLeaseManagerGetter is a mock of ModelApplicationLeaseManagerGetter interface. -type MockModelApplicationLeaseManagerGetter struct { +// MockModelLeaseManagerGetter is a mock of ModelLeaseManagerGetter interface. +type MockModelLeaseManagerGetter struct { ctrl *gomock.Controller - recorder *MockModelApplicationLeaseManagerGetterMockRecorder + recorder *MockModelLeaseManagerGetterMockRecorder } -// MockModelApplicationLeaseManagerGetterMockRecorder is the mock recorder for MockModelApplicationLeaseManagerGetter. -type MockModelApplicationLeaseManagerGetterMockRecorder struct { - mock *MockModelApplicationLeaseManagerGetter +// MockModelLeaseManagerGetterMockRecorder is the mock recorder for MockModelLeaseManagerGetter. +type MockModelLeaseManagerGetterMockRecorder struct { + mock *MockModelLeaseManagerGetter } -// NewMockModelApplicationLeaseManagerGetter creates a new mock instance. -func NewMockModelApplicationLeaseManagerGetter(ctrl *gomock.Controller) *MockModelApplicationLeaseManagerGetter { - mock := &MockModelApplicationLeaseManagerGetter{ctrl: ctrl} - mock.recorder = &MockModelApplicationLeaseManagerGetterMockRecorder{mock} +// NewMockModelLeaseManagerGetter creates a new mock instance. +func NewMockModelLeaseManagerGetter(ctrl *gomock.Controller) *MockModelLeaseManagerGetter { + mock := &MockModelLeaseManagerGetter{ctrl: ctrl} + mock.recorder = &MockModelLeaseManagerGetterMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockModelApplicationLeaseManagerGetter) EXPECT() *MockModelApplicationLeaseManagerGetterMockRecorder { +func (m *MockModelLeaseManagerGetter) EXPECT() *MockModelLeaseManagerGetterMockRecorder { return m.recorder } // GetLeaseManager mocks base method. -func (m *MockModelApplicationLeaseManagerGetter) GetLeaseManager() (lease.LeaseCheckerWaiter, error) { +func (m *MockModelLeaseManagerGetter) GetLeaseManager() (lease.LeaseCheckerWaiter, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetLeaseManager") ret0, _ := ret[0].(lease.LeaseCheckerWaiter) @@ -210,31 +210,31 @@ func (m *MockModelApplicationLeaseManagerGetter) GetLeaseManager() (lease.LeaseC } // GetLeaseManager indicates an expected call of GetLeaseManager. -func (mr *MockModelApplicationLeaseManagerGetterMockRecorder) GetLeaseManager() *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall { +func (mr *MockModelLeaseManagerGetterMockRecorder) GetLeaseManager() *MockModelLeaseManagerGetterGetLeaseManagerCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLeaseManager", reflect.TypeOf((*MockModelApplicationLeaseManagerGetter)(nil).GetLeaseManager)) - return &MockModelApplicationLeaseManagerGetterGetLeaseManagerCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLeaseManager", reflect.TypeOf((*MockModelLeaseManagerGetter)(nil).GetLeaseManager)) + return &MockModelLeaseManagerGetterGetLeaseManagerCall{Call: call} } -// MockModelApplicationLeaseManagerGetterGetLeaseManagerCall wrap *gomock.Call -type MockModelApplicationLeaseManagerGetterGetLeaseManagerCall struct { +// MockModelLeaseManagerGetterGetLeaseManagerCall wrap *gomock.Call +type MockModelLeaseManagerGetterGetLeaseManagerCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall) Return(arg0 lease.LeaseCheckerWaiter, arg1 error) *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall { +func (c *MockModelLeaseManagerGetterGetLeaseManagerCall) Return(arg0 lease.LeaseCheckerWaiter, arg1 error) *MockModelLeaseManagerGetterGetLeaseManagerCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall) Do(f func() (lease.LeaseCheckerWaiter, error)) *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall { +func (c *MockModelLeaseManagerGetterGetLeaseManagerCall) Do(f func() (lease.LeaseCheckerWaiter, error)) *MockModelLeaseManagerGetterGetLeaseManagerCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall) DoAndReturn(f func() (lease.LeaseCheckerWaiter, error)) *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall { +func (c *MockModelLeaseManagerGetterGetLeaseManagerCall) DoAndReturn(f func() (lease.LeaseCheckerWaiter, error)) *MockModelLeaseManagerGetterGetLeaseManagerCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/domain/leaseservice.go b/domain/leaseservice.go index 8b8e8985aea..a930476aafa 100644 --- a/domain/leaseservice.go +++ b/domain/leaseservice.go @@ -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, } @@ -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() diff --git a/domain/leaseservice_test.go b/domain/leaseservice_test.go index aca3be77608..e2a2c0bb3d7 100644 --- a/domain/leaseservice_test.go +++ b/domain/leaseservice_test.go @@ -19,7 +19,7 @@ import ( type leaseServiceSuite struct { testing.IsolationSuite - modelLeaseManager *MockModelApplicationLeaseManagerGetter + modelLeaseManager *MockModelLeaseManagerGetter leaseCheckerWaiter *MockLeaseCheckerWaiter token *MockToken } @@ -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) diff --git a/domain/package_test.go b/domain/package_test.go index f55c26a1ecc..b16fc88c364 100644 --- a/domain/package_test.go +++ b/domain/package_test.go @@ -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) diff --git a/domain/services/model.go b/domain/services/model.go index e2d8c30f1cb..57759af5d83 100644 --- a/domain/services/model.go +++ b/domain/services/model.go @@ -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 @@ -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 { diff --git a/domain/services/service.go b/domain/services/service.go index 20e007cc696..5f5b185c353 100644 --- a/domain/services/service.go +++ b/domain/services/service.go @@ -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 { diff --git a/internal/worker/domainservices/lease_mock_test.go b/internal/worker/domainservices/lease_mock_test.go index 9b54323ea1d..14de949af90 100644 --- a/internal/worker/domainservices/lease_mock_test.go +++ b/internal/worker/domainservices/lease_mock_test.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/juju/juju/core/lease (interfaces: LeaseCheckerWaiter,Manager,ApplicationLeaseManagerGetter,ModelApplicationLeaseManagerGetter) +// Source: github.com/juju/juju/core/lease (interfaces: LeaseCheckerWaiter,Manager,LeaseManagerGetter,ModelLeaseManagerGetter) // // Generated by this command: // -// mockgen -typed -package domainservices -destination lease_mock_test.go github.com/juju/juju/core/lease LeaseCheckerWaiter,Manager,ApplicationLeaseManagerGetter,ModelApplicationLeaseManagerGetter +// mockgen -typed -package domainservices -destination lease_mock_test.go github.com/juju/juju/core/lease LeaseCheckerWaiter,Manager,LeaseManagerGetter,ModelLeaseManagerGetter // // Package domainservices is a generated GoMock package. @@ -335,31 +335,31 @@ func (c *MockManagerRevokerCall) DoAndReturn(f func(string, string) (lease.Revok return c } -// MockApplicationLeaseManagerGetter is a mock of ApplicationLeaseManagerGetter interface. -type MockApplicationLeaseManagerGetter struct { +// MockLeaseManagerGetter is a mock of LeaseManagerGetter interface. +type MockLeaseManagerGetter struct { ctrl *gomock.Controller - recorder *MockApplicationLeaseManagerGetterMockRecorder + recorder *MockLeaseManagerGetterMockRecorder } -// MockApplicationLeaseManagerGetterMockRecorder is the mock recorder for MockApplicationLeaseManagerGetter. -type MockApplicationLeaseManagerGetterMockRecorder struct { - mock *MockApplicationLeaseManagerGetter +// MockLeaseManagerGetterMockRecorder is the mock recorder for MockLeaseManagerGetter. +type MockLeaseManagerGetterMockRecorder struct { + mock *MockLeaseManagerGetter } -// NewMockApplicationLeaseManagerGetter creates a new mock instance. -func NewMockApplicationLeaseManagerGetter(ctrl *gomock.Controller) *MockApplicationLeaseManagerGetter { - mock := &MockApplicationLeaseManagerGetter{ctrl: ctrl} - mock.recorder = &MockApplicationLeaseManagerGetterMockRecorder{mock} +// NewMockLeaseManagerGetter creates a new mock instance. +func NewMockLeaseManagerGetter(ctrl *gomock.Controller) *MockLeaseManagerGetter { + mock := &MockLeaseManagerGetter{ctrl: ctrl} + mock.recorder = &MockLeaseManagerGetterMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockApplicationLeaseManagerGetter) EXPECT() *MockApplicationLeaseManagerGetterMockRecorder { +func (m *MockLeaseManagerGetter) EXPECT() *MockLeaseManagerGetterMockRecorder { return m.recorder } // GetLeaseManager mocks base method. -func (m *MockApplicationLeaseManagerGetter) GetLeaseManager(arg0 model.UUID) (lease.LeaseCheckerWaiter, error) { +func (m *MockLeaseManagerGetter) GetLeaseManager(arg0 model.UUID) (lease.LeaseCheckerWaiter, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetLeaseManager", arg0) ret0, _ := ret[0].(lease.LeaseCheckerWaiter) @@ -368,60 +368,60 @@ func (m *MockApplicationLeaseManagerGetter) GetLeaseManager(arg0 model.UUID) (le } // GetLeaseManager indicates an expected call of GetLeaseManager. -func (mr *MockApplicationLeaseManagerGetterMockRecorder) GetLeaseManager(arg0 any) *MockApplicationLeaseManagerGetterGetLeaseManagerCall { +func (mr *MockLeaseManagerGetterMockRecorder) GetLeaseManager(arg0 any) *MockLeaseManagerGetterGetLeaseManagerCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLeaseManager", reflect.TypeOf((*MockApplicationLeaseManagerGetter)(nil).GetLeaseManager), arg0) - return &MockApplicationLeaseManagerGetterGetLeaseManagerCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLeaseManager", reflect.TypeOf((*MockLeaseManagerGetter)(nil).GetLeaseManager), arg0) + return &MockLeaseManagerGetterGetLeaseManagerCall{Call: call} } -// MockApplicationLeaseManagerGetterGetLeaseManagerCall wrap *gomock.Call -type MockApplicationLeaseManagerGetterGetLeaseManagerCall struct { +// MockLeaseManagerGetterGetLeaseManagerCall wrap *gomock.Call +type MockLeaseManagerGetterGetLeaseManagerCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockApplicationLeaseManagerGetterGetLeaseManagerCall) Return(arg0 lease.LeaseCheckerWaiter, arg1 error) *MockApplicationLeaseManagerGetterGetLeaseManagerCall { +func (c *MockLeaseManagerGetterGetLeaseManagerCall) Return(arg0 lease.LeaseCheckerWaiter, arg1 error) *MockLeaseManagerGetterGetLeaseManagerCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *MockApplicationLeaseManagerGetterGetLeaseManagerCall) Do(f func(model.UUID) (lease.LeaseCheckerWaiter, error)) *MockApplicationLeaseManagerGetterGetLeaseManagerCall { +func (c *MockLeaseManagerGetterGetLeaseManagerCall) Do(f func(model.UUID) (lease.LeaseCheckerWaiter, error)) *MockLeaseManagerGetterGetLeaseManagerCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockApplicationLeaseManagerGetterGetLeaseManagerCall) DoAndReturn(f func(model.UUID) (lease.LeaseCheckerWaiter, error)) *MockApplicationLeaseManagerGetterGetLeaseManagerCall { +func (c *MockLeaseManagerGetterGetLeaseManagerCall) DoAndReturn(f func(model.UUID) (lease.LeaseCheckerWaiter, error)) *MockLeaseManagerGetterGetLeaseManagerCall { c.Call = c.Call.DoAndReturn(f) return c } -// MockModelApplicationLeaseManagerGetter is a mock of ModelApplicationLeaseManagerGetter interface. -type MockModelApplicationLeaseManagerGetter struct { +// MockModelLeaseManagerGetter is a mock of ModelLeaseManagerGetter interface. +type MockModelLeaseManagerGetter struct { ctrl *gomock.Controller - recorder *MockModelApplicationLeaseManagerGetterMockRecorder + recorder *MockModelLeaseManagerGetterMockRecorder } -// MockModelApplicationLeaseManagerGetterMockRecorder is the mock recorder for MockModelApplicationLeaseManagerGetter. -type MockModelApplicationLeaseManagerGetterMockRecorder struct { - mock *MockModelApplicationLeaseManagerGetter +// MockModelLeaseManagerGetterMockRecorder is the mock recorder for MockModelLeaseManagerGetter. +type MockModelLeaseManagerGetterMockRecorder struct { + mock *MockModelLeaseManagerGetter } -// NewMockModelApplicationLeaseManagerGetter creates a new mock instance. -func NewMockModelApplicationLeaseManagerGetter(ctrl *gomock.Controller) *MockModelApplicationLeaseManagerGetter { - mock := &MockModelApplicationLeaseManagerGetter{ctrl: ctrl} - mock.recorder = &MockModelApplicationLeaseManagerGetterMockRecorder{mock} +// NewMockModelLeaseManagerGetter creates a new mock instance. +func NewMockModelLeaseManagerGetter(ctrl *gomock.Controller) *MockModelLeaseManagerGetter { + mock := &MockModelLeaseManagerGetter{ctrl: ctrl} + mock.recorder = &MockModelLeaseManagerGetterMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockModelApplicationLeaseManagerGetter) EXPECT() *MockModelApplicationLeaseManagerGetterMockRecorder { +func (m *MockModelLeaseManagerGetter) EXPECT() *MockModelLeaseManagerGetterMockRecorder { return m.recorder } // GetLeaseManager mocks base method. -func (m *MockModelApplicationLeaseManagerGetter) GetLeaseManager() (lease.LeaseCheckerWaiter, error) { +func (m *MockModelLeaseManagerGetter) GetLeaseManager() (lease.LeaseCheckerWaiter, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetLeaseManager") ret0, _ := ret[0].(lease.LeaseCheckerWaiter) @@ -430,31 +430,31 @@ func (m *MockModelApplicationLeaseManagerGetter) GetLeaseManager() (lease.LeaseC } // GetLeaseManager indicates an expected call of GetLeaseManager. -func (mr *MockModelApplicationLeaseManagerGetterMockRecorder) GetLeaseManager() *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall { +func (mr *MockModelLeaseManagerGetterMockRecorder) GetLeaseManager() *MockModelLeaseManagerGetterGetLeaseManagerCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLeaseManager", reflect.TypeOf((*MockModelApplicationLeaseManagerGetter)(nil).GetLeaseManager)) - return &MockModelApplicationLeaseManagerGetterGetLeaseManagerCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLeaseManager", reflect.TypeOf((*MockModelLeaseManagerGetter)(nil).GetLeaseManager)) + return &MockModelLeaseManagerGetterGetLeaseManagerCall{Call: call} } -// MockModelApplicationLeaseManagerGetterGetLeaseManagerCall wrap *gomock.Call -type MockModelApplicationLeaseManagerGetterGetLeaseManagerCall struct { +// MockModelLeaseManagerGetterGetLeaseManagerCall wrap *gomock.Call +type MockModelLeaseManagerGetterGetLeaseManagerCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall) Return(arg0 lease.LeaseCheckerWaiter, arg1 error) *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall { +func (c *MockModelLeaseManagerGetterGetLeaseManagerCall) Return(arg0 lease.LeaseCheckerWaiter, arg1 error) *MockModelLeaseManagerGetterGetLeaseManagerCall { c.Call = c.Call.Return(arg0, arg1) return c } // Do rewrite *gomock.Call.Do -func (c *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall) Do(f func() (lease.LeaseCheckerWaiter, error)) *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall { +func (c *MockModelLeaseManagerGetterGetLeaseManagerCall) Do(f func() (lease.LeaseCheckerWaiter, error)) *MockModelLeaseManagerGetterGetLeaseManagerCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall) DoAndReturn(f func() (lease.LeaseCheckerWaiter, error)) *MockModelApplicationLeaseManagerGetterGetLeaseManagerCall { +func (c *MockModelLeaseManagerGetterGetLeaseManagerCall) DoAndReturn(f func() (lease.LeaseCheckerWaiter, error)) *MockModelLeaseManagerGetterGetLeaseManagerCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/internal/worker/domainservices/manifold.go b/internal/worker/domainservices/manifold.go index 625e66a956f..b8e6b35bad0 100644 --- a/internal/worker/domainservices/manifold.go +++ b/internal/worker/domainservices/manifold.go @@ -75,7 +75,7 @@ type ModelDomainServicesFn func( objectstore.ModelObjectStoreGetter, storage.ModelStorageRegistryGetter, domainservices.PublicKeyImporter, - lease.ModelApplicationLeaseManagerGetter, + lease.ModelLeaseManagerGetter, clock.Clock, logger.Logger, ) services.ModelDomainServices @@ -250,7 +250,7 @@ func NewProviderTrackerModelDomainServices( objectStore objectstore.ModelObjectStoreGetter, storageRegistry storage.ModelStorageRegistryGetter, publicKeyImporter domainservices.PublicKeyImporter, - leaseManager lease.ModelApplicationLeaseManagerGetter, + leaseManager lease.ModelLeaseManagerGetter, clock clock.Clock, logger logger.Logger, ) services.ModelDomainServices { diff --git a/internal/worker/domainservices/manifold_test.go b/internal/worker/domainservices/manifold_test.go index 35aa8328dcb..560b76179e2 100644 --- a/internal/worker/domainservices/manifold_test.go +++ b/internal/worker/domainservices/manifold_test.go @@ -223,7 +223,7 @@ func (s *manifoldSuite) TestNewModelDomainServices(c *gc.C) { s.modelObjectStoreGetter, s.modelStorageRegistryGetter, s.publicKeyImporter, - s.modelApplicationLeaseManagerGetter, + s.modelLeaseManagerGetter, s.clock, s.logger, ) @@ -301,7 +301,7 @@ func noopModelDomainServices( objectstore.ModelObjectStoreGetter, storage.ModelStorageRegistryGetter, domainservices.PublicKeyImporter, - lease.ModelApplicationLeaseManagerGetter, + lease.ModelLeaseManagerGetter, clock.Clock, logger.Logger, ) services.ModelDomainServices { diff --git a/internal/worker/domainservices/package_test.go b/internal/worker/domainservices/package_test.go index 283eb263bb1..d564cad7566 100644 --- a/internal/worker/domainservices/package_test.go +++ b/internal/worker/domainservices/package_test.go @@ -32,7 +32,7 @@ import ( //go:generate go run go.uber.org/mock/mockgen -typed -package domainservices -destination objectstore_mock_test.go github.com/juju/juju/core/objectstore ObjectStore,ObjectStoreGetter,ModelObjectStoreGetter //go:generate go run go.uber.org/mock/mockgen -typed -package domainservices -destination storage_mock_test.go github.com/juju/juju/core/storage StorageRegistryGetter,ModelStorageRegistryGetter //go:generate go run go.uber.org/mock/mockgen -typed -package domainservices -destination http_mock_test.go github.com/juju/juju/core/http HTTPClientGetter,HTTPClient -//go:generate go run go.uber.org/mock/mockgen -typed -package domainservices -destination lease_mock_test.go github.com/juju/juju/core/lease LeaseCheckerWaiter,Manager,ApplicationLeaseManagerGetter,ModelApplicationLeaseManagerGetter +//go:generate go run go.uber.org/mock/mockgen -typed -package domainservices -destination lease_mock_test.go github.com/juju/juju/core/lease LeaseCheckerWaiter,Manager,LeaseManagerGetter,ModelLeaseManagerGetter func TestPackage(t *testing.T) { gc.TestingT(t) @@ -63,9 +63,9 @@ type baseSuite struct { httpClientGetter *MockHTTPClientGetter httpClient *MockHTTPClient - leaseManager *MockManager - applicationLeaseManagerGetter *MockApplicationLeaseManagerGetter - modelApplicationLeaseManagerGetter *MockModelApplicationLeaseManagerGetter + leaseManager *MockManager + leaseManagerGetter *MockLeaseManagerGetter + modelLeaseManagerGetter *MockModelLeaseManagerGetter publicKeyImporter *sshimporter.Importer } @@ -96,8 +96,8 @@ func (s *baseSuite) setupMocks(c *gc.C) *gomock.Controller { s.httpClient = NewMockHTTPClient(ctrl) s.leaseManager = NewMockManager(ctrl) - s.applicationLeaseManagerGetter = NewMockApplicationLeaseManagerGetter(ctrl) - s.modelApplicationLeaseManagerGetter = NewMockModelApplicationLeaseManagerGetter(ctrl) + s.leaseManagerGetter = NewMockLeaseManagerGetter(ctrl) + s.modelLeaseManagerGetter = NewMockModelLeaseManagerGetter(ctrl) s.publicKeyImporter = sshimporter.NewImporter(&http.Client{}) @@ -113,7 +113,7 @@ func NewModelDomainServices( objectStore objectstore.ModelObjectStoreGetter, storageRegistry storage.ModelStorageRegistryGetter, publicKeyImporter domainservices.PublicKeyImporter, - leaseManager lease.ModelApplicationLeaseManagerGetter, + leaseManager lease.ModelLeaseManagerGetter, clock clock.Clock, logger logger.Logger, ) services.ModelDomainServices { diff --git a/internal/worker/domainservices/worker.go b/internal/worker/domainservices/worker.go index f1e20024d4d..82f9d9f9a27 100644 --- a/internal/worker/domainservices/worker.go +++ b/internal/worker/domainservices/worker.go @@ -82,12 +82,6 @@ func (config Config) Validate() error { if config.LeaseManager == nil { return errors.NotValidf("nil LeaseManager") } - if config.Logger == nil { - return errors.NotValidf("nil Logger") - } - if config.Clock == nil { - return errors.NotValidf("nil Clock") - } if config.NewDomainServicesGetter == nil { return errors.NotValidf("nil NewDomainServicesGetter") } @@ -97,6 +91,12 @@ func (config Config) Validate() error { if config.NewModelDomainServices == nil { return errors.NotValidf("nil NewModelDomainServices") } + if config.Logger == nil { + return errors.NotValidf("nil Logger") + } + if config.Clock == nil { + return errors.NotValidf("nil Clock") + } return nil } @@ -240,6 +240,8 @@ func (s modelStorageRegistryGetter) GetStorageRegistry(ctx context.Context) (int return s.storageRegistryGetter.GetStorageRegistry(ctx, s.modelUUID.String()) } +// modelApplicationLeaseManager is a lease manager that is specific to +// an application scope. type modelApplicationLeaseManager struct { modelUUID coremodel.UUID manager lease.Manager @@ -252,12 +254,12 @@ func (s modelApplicationLeaseManager) GetLeaseManager() (lease.LeaseCheckerWaite // be happy with a sync.Pool at minimum though. claimer, err := s.manager.Claimer(lease.ApplicationLeadershipNamespace, s.modelUUID.String()) if err != nil { - return nil, errors.Trace(err) + return nil, errors.Errorf("getting claim lease manager: %w", err) } checker, err := s.manager.Checker(lease.ApplicationLeadershipNamespace, s.modelUUID.String()) if err != nil { - return nil, errors.Trace(err) + return nil, errors.Errorf("getting checker lease manager: %w", err) } return &leaseManager{ diff --git a/internal/worker/domainservices/worker_test.go b/internal/worker/domainservices/worker_test.go index e124a894976..715fbce104c 100644 --- a/internal/worker/domainservices/worker_test.go +++ b/internal/worker/domainservices/worker_test.go @@ -124,7 +124,7 @@ func (s *workerSuite) getConfig() Config { objectstore.ModelObjectStoreGetter, storage.ModelStorageRegistryGetter, domainservices.PublicKeyImporter, - lease.ModelApplicationLeaseManagerGetter, + lease.ModelLeaseManagerGetter, clock.Clock, logger.Logger, ) services.ModelDomainServices {