Exemplo n.º 1
0
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")
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
0
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)
}
Exemplo n.º 4
0
func init() {
	common.RegisterStandardFacade(
		FacadeName,
		2,
		NewLeadershipServiceFacade,
	)
}
Exemplo n.º 5
0
func (c payloads) registerPublicFacade() {
	common.RegisterStandardFacade(
		payload.ComponentName,
		0,
		c.newPublicFacade,
	)
}
Exemplo n.º 6
0
Arquivo: shim.go Projeto: bac/juju
func init() {
	common.RegisterStandardFacade(
		"LifeFlag", 1,
		func(st *state.State, resources facade.Resources, authorizer facade.Authorizer) (*Facade, error) {
			return NewFacade(st, resources, authorizer)
		},
	)
}
Exemplo n.º 7
0
Arquivo: singular.go Projeto: bac/juju
func init() {
	common.RegisterStandardFacade(
		"Singular", 1,
		func(st *state.State, _ facade.Resources, auth facade.Authorizer) (*Facade, error) {
			return NewFacade(st, auth)
		},
	)
}
Exemplo n.º 8
0
func init() {

	common.RegisterStandardFacade(
		FacadeName,
		1,
		NewLeadershipServiceFn(leaderMgr),
	)
}
Exemplo n.º 9
0
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)
}
Exemplo n.º 10
0
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`)
}
Exemplo n.º 11
0
// 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)
}
Exemplo n.º 12
0
Arquivo: payload.go Projeto: bac/juju
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,
	)
}
Exemplo n.º 13
0
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)
}
Exemplo n.º 14
0
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)
}
Exemplo n.º 15
0
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"`)
}
Exemplo n.º 16
0
// 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,
	})
}
Exemplo n.º 17
0
func init() {
	common.RegisterStandardFacade("ModelManager", 2, newFacade)
}
Exemplo n.º 18
0
func init() {
	common.RegisterStandardFacade("MetricsDebug", 1, NewMetricsDebugAPI)
}
Exemplo n.º 19
0
func init() {
	common.RegisterStandardFacade("Controller", 1, NewControllerAPI)
}
Exemplo n.º 20
0
func init() {
	common.RegisterStandardFacade("Service", 3, NewAPI)
}
Exemplo n.º 21
0
func init() {
	common.RegisterStandardFacade("Resumer", 2, NewResumerAPI)
}
Exemplo n.º 22
0
func init() {
	common.RegisterStandardFacade("DiscoverSpaces", 2, NewDiscoverSpacesAPI)
}
Exemplo n.º 23
0
func init() {
	common.RegisterStandardFacade("Cleaner", 2, NewCleanerAPI)
}
Exemplo n.º 24
0
func init() {
	common.RegisterStandardFacade("Client", 0, NewClient)
}
Exemplo n.º 25
0
func init() {
	common.RegisterStandardFacade("DiskManager", 2, NewDiskManagerAPI)
}
Exemplo n.º 26
0
Arquivo: upgrader.go Projeto: bac/juju
func init() {
	common.RegisterStandardFacade("Upgrader", 1, upgraderFacade)
}
Exemplo n.º 27
0
func init() {
	common.RegisterStandardFacade("Addresser", 1, NewAddresserAPI)
}
Exemplo n.º 28
0
func init() {
	common.RegisterStandardFacade("Reboot", 2, NewRebootAPI)
}
Exemplo n.º 29
0
func init() {
	common.RegisterStandardFacade("HighAvailability", 2, NewHighAvailabilityAPI)
}
Exemplo n.º 30
0
func init() {
	common.RegisterStandardFacade("ImageManager", 1, NewImageManagerAPI)
}