github.com/cloud-green/juju@v0.0.0-20151002100041-a00291338d3d/worker/rsyslog/manifold.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package rsyslog 5 6 import ( 7 "github.com/juju/utils/featureflag" 8 9 "github.com/juju/juju/agent" 10 "github.com/juju/juju/api/base" 11 "github.com/juju/juju/api/rsyslog" 12 "github.com/juju/juju/feature" 13 "github.com/juju/juju/worker" 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 19 // Manifold will depend. 20 type ManifoldConfig util.AgentApiManifoldConfig 21 22 // Manifold returns a dependency manifold that runs an rsyslog 23 // worker, using the resource names defined in the supplied config. 24 func Manifold(config ManifoldConfig) dependency.Manifold { 25 return util.AgentApiManifold(util.AgentApiManifoldConfig(config), newWorker) 26 } 27 28 // newWorker exists to wrap NewRsyslogConfigWorker in a format convenient for an 29 // AgentApiManifold. 30 // TODO(fwereade) 2015-05-11 Eventually, the method should be the sole accessible 31 // package factory function -- as part of the manifold -- and all tests should 32 // thus be routed through it. 33 var newWorker = func(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) { 34 if featureflag.Enabled(feature.DisableRsyslog) { 35 logger.Warningf("rsyslog manifold disabled by feature flag") 36 return nil, dependency.ErrMissing 37 } 38 39 agentConfig := a.CurrentConfig() 40 tag := agentConfig.Tag() 41 namespace := agentConfig.Value(agent.Namespace) 42 addrs, err := agentConfig.APIAddresses() 43 if err != nil { 44 return nil, err 45 } 46 return NewRsyslogConfigWorker( 47 rsyslog.NewState(apiCaller), 48 RsyslogModeForwarding, 49 tag, 50 namespace, 51 addrs, 52 agentConfig.DataDir(), 53 ) 54 }