github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/worker/apiaddressupdater/manifold.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package apiaddressupdater 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/names" 9 10 "github.com/juju/juju/api/base" 11 "github.com/juju/juju/api/uniter" 12 "github.com/juju/juju/worker" 13 "github.com/juju/juju/worker/agent" 14 "github.com/juju/juju/worker/dependency" 15 "github.com/juju/juju/worker/util" 16 ) 17 18 // ManifoldConfig defines the names of the manifolds on which a Manifold will depend. 19 type ManifoldConfig util.AgentApiManifoldConfig 20 21 // Manifold returns a dependency manifold that runs an API address updater worker, 22 // using the resource names defined in the supplied config. 23 func Manifold(config ManifoldConfig) dependency.Manifold { 24 return util.AgentApiManifold(util.AgentApiManifoldConfig(config), newWorker) 25 } 26 27 // newWorker trivially wraps NewAPIAddressUpdater for use in a util.AgentApiManifold. 28 // It's not tested at the moment, because the scaffolding necessary to test these 5 29 // lines outweighs them by several times for very little confirmatory power; in the 30 // long term, all APIAddressUpdaters should be constructed via a manifold, and the 31 // tests can be updated to reflect that. 32 var newWorker = func(agent agent.Agent, apiCaller base.APICaller) (worker.Worker, error) { 33 // TODO(fwereade): why on *earth* do we use the *uniter* facade for this 34 // worker? This code really ought to work anywhere... 35 unitTag, ok := agent.Tag().(names.UnitTag) 36 if !ok { 37 return nil, errors.Errorf("expected a unit tag; got %q", agent.Tag()) 38 } 39 return NewAPIAddressUpdater(uniter.NewState(apiCaller, unitTag), agent), nil 40 }