func (r *rootSuite) TestFindMethodCachesFacades(c *gc.C) { srvRoot := apiserver.TestingApiRoot(nil) defer common.Facades.Discard("my-counting-facade", 0) defer common.Facades.Discard("my-counting-facade", 1) var count int64 newCounter := func( *state.State, *common.Resources, common.Authorizer, ) ( *countingType, error, ) { count += 1 return &countingType{count: count, id: ""}, nil } common.RegisterStandardFacade("my-counting-facade", 0, newCounter) common.RegisterStandardFacade("my-counting-facade", 1, newCounter) // The first time we call FindMethod, it should lookup a facade, and // request a new object. caller, err := srvRoot.FindMethod("my-counting-facade", 0, "Count") c.Assert(err, jc.ErrorIsNil) assertCallResult(c, caller, "", "1") // The second time we ask for a method on the same facade, it should // reuse that object, rather than creating another instance caller, err = srvRoot.FindMethod("my-counting-facade", 0, "AltCount") c.Assert(err, jc.ErrorIsNil) assertCallResult(c, caller, "", "ALT-1") // But when we ask for a different version, we should get a new // instance caller, err = srvRoot.FindMethod("my-counting-facade", 1, "Count") c.Assert(err, jc.ErrorIsNil) assertCallResult(c, caller, "", "2") // But it, too, should be cached caller, err = srvRoot.FindMethod("my-counting-facade", 1, "AltCount") c.Assert(err, jc.ErrorIsNil) assertCallResult(c, caller, "", "ALT-2") }
func init() { common.RegisterStandardFacade("Application", 1, newAPI) // Facade version 2 adds support for the ConfigSettings // and StorageConstraints fields in SetCharm. common.RegisterStandardFacade("Application", 2, newAPI) }
func init() { common.RegisterStandardFacade("Provisioner", 1, NewProvisionerAPI) // Version 1 has the same set of methods as 0, with the same // signatures, but its ProvisioningInfo returns additional // information. Clients may require version 1 so that they // receive this additional information; otherwise they are // compatible. common.RegisterStandardFacade("Provisioner", 2, NewProvisionerAPI) }
func init() { common.RegisterStandardFacade( FacadeName, 2, NewLeadershipServiceFacade, ) }
func (c payloads) registerPublicFacade() { common.RegisterStandardFacade( payload.ComponentName, 0, c.newPublicFacade, ) }
func init() { common.RegisterStandardFacade( "LifeFlag", 1, func(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*Facade, error) { return NewFacade(st, resources, authorizer) }, ) }
func init() { common.RegisterStandardFacade( "Singular", 1, func(st *state.State, _ facade.Resources, auth facade.Authorizer) (*Facade, error) { return NewFacade(st, auth) }, ) }
func init() { common.RegisterStandardFacade( FacadeName, 1, NewLeadershipServiceFn(leaderMgr), ) }
func (s *facadeRegistrySuite) TestRegisterStandardFacade(c *gc.C) { common.SanitizeFacades(s) common.RegisterStandardFacade("testing", 0, validFactory) wrapped, err := common.Facades.GetFactory("testing", 0) c.Assert(err, gc.IsNil) val, err := wrapped(nil, nil, nil, "") c.Assert(err, gc.IsNil) c.Check(*(val.(*int)), gc.Equals, 100) }
func (s *facadeRegistrySuite) TestRegisterStandardFacadePanic(c *gc.C) { common.SanitizeFacades(s) c.Assert( func() { common.RegisterStandardFacade("badtest", 0, noArgs) }, gc.PanicMatches, `function ".*noArgs" does not take 3 parameters and return 2`) _, err := common.Facades.GetFactory("badtest", 0) c.Assert(err, jc.Satisfies, errors.IsNotFound) c.Assert(err, gc.ErrorMatches, `badtest\(0\) not found`) }
// registerPublicFacade adds the resources public API facade // to the API server. func (r resources) registerPublicFacade() { if !markRegistered(resource.ComponentName, "public-facade") { return } common.RegisterStandardFacade( resource.ComponentName, server.Version, r.newPublicFacade, ) api.RegisterFacadeVersion(resource.ComponentName, server.Version) }
func (c payloads) registerPublicFacade() { if !markRegistered(payload.ComponentName, "public-facade") { return } // NOTE: facade is also defined in api/facadeversions.go. const version = 1 common.RegisterStandardFacade( payload.FacadeName, version, c.newPublicFacade, ) }
func (c payloads) registerPublicFacade() { if !markRegistered(payload.ComponentName, "public-facade") { return } const version = 1 common.RegisterStandardFacade( payload.ComponentName, version, c.newPublicFacade, ) api.RegisterFacadeVersion(payload.ComponentName, version) }
func (r *rootSuite) TestFindMethodHandlesInterfaceTypes(c *gc.C) { srvRoot := apiserver.TestingApiRoot(nil) defer common.Facades.Discard("my-interface-facade", 0) defer common.Facades.Discard("my-interface-facade", 1) common.RegisterStandardFacade("my-interface-facade", 0, func( *state.State, *common.Resources, common.Authorizer, ) ( smallInterface, error, ) { return &firstImpl{}, nil }) common.RegisterStandardFacade("my-interface-facade", 1, func( *state.State, *common.Resources, common.Authorizer, ) ( smallInterface, error, ) { return &secondImpl{}, nil }) caller, err := srvRoot.FindMethod("my-interface-facade", 0, "OneMethod") c.Assert(err, jc.ErrorIsNil) assertCallResult(c, caller, "", "first") caller2, err := srvRoot.FindMethod("my-interface-facade", 1, "OneMethod") c.Assert(err, jc.ErrorIsNil) assertCallResult(c, caller2, "", "second") // We should *not* be able to see AMethod or ZMethod caller, err = srvRoot.FindMethod("my-interface-facade", 1, "AMethod") c.Check(err, gc.FitsTypeOf, (*rpcreflect.CallNotImplementedError)(nil)) c.Check(err, gc.ErrorMatches, `no such request - method my-interface-facade\(1\)\.AMethod is not implemented`) c.Check(caller, gc.IsNil) caller, err = srvRoot.FindMethod("my-interface-facade", 1, "ZMethod") c.Check(err, gc.FitsTypeOf, (*rpcreflect.CallNotImplementedError)(nil)) c.Check(err, gc.ErrorMatches, `no such request - method my-interface-facade\(1\)\.ZMethod is not implemented`) c.Check(caller, gc.IsNil) }
func (r *rootSuite) TestFindMethodUnknownVersion(c *gc.C) { srvRoot := apiserver.TestingApiRoot(nil) defer common.Facades.Discard("my-testing-facade", 0) myGoodFacade := func( *state.State, *common.Resources, common.Authorizer, ) ( *testingType, error, ) { return &testingType{}, nil } common.RegisterStandardFacade("my-testing-facade", 0, myGoodFacade) caller, err := srvRoot.FindMethod("my-testing-facade", 1, "Exposed") c.Check(caller, gc.IsNil) c.Check(err, gc.FitsTypeOf, (*rpcreflect.CallNotImplementedError)(nil)) c.Check(err, gc.ErrorMatches, `unknown version \(1\) of interface "my-testing-facade"`) }
// registerPublicFacade adds the resources public API facade // to the API server. func (r resources) registerPublicFacade() { if !markRegistered(resource.ComponentName, "public-facade") { return } common.RegisterStandardFacade( resource.ComponentName, server.Version, resourceadapters.NewPublicFacade, ) coreapi.RegisterFacadeVersion(resource.ComponentName, server.Version) common.RegisterAPIModelEndpoint(api.HTTPEndpointPattern, apihttp.HandlerSpec{ Constraints: apihttp.HandlerConstraints{ AuthKind: names.UserTagKind, StrictValidation: true, ControllerModelOnly: false, }, NewHandler: resourceadapters.NewUploadHandler, }) }
func init() { common.RegisterStandardFacade("ModelManager", 2, newFacade) }
func init() { common.RegisterStandardFacade("MetricsDebug", 1, NewMetricsDebugAPI) }
func init() { common.RegisterStandardFacade("Controller", 1, NewControllerAPI) }
func init() { common.RegisterStandardFacade("Service", 3, NewAPI) }
func init() { common.RegisterStandardFacade("Resumer", 2, NewResumerAPI) }
func init() { common.RegisterStandardFacade("DiscoverSpaces", 2, NewDiscoverSpacesAPI) }
func init() { common.RegisterStandardFacade("Cleaner", 2, NewCleanerAPI) }
func init() { common.RegisterStandardFacade("Client", 0, NewClient) }
func init() { common.RegisterStandardFacade("DiskManager", 2, NewDiskManagerAPI) }
func init() { common.RegisterStandardFacade("Upgrader", 1, upgraderFacade) }
func init() { common.RegisterStandardFacade("Addresser", 1, NewAddresserAPI) }
func init() { common.RegisterStandardFacade("Reboot", 2, NewRebootAPI) }
func init() { common.RegisterStandardFacade("HighAvailability", 2, NewHighAvailabilityAPI) }
func init() { common.RegisterStandardFacade("ImageManager", 1, NewImageManagerAPI) }