github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/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/juju/agent" 8 "github.com/juju/juju/api/base" 9 "github.com/juju/juju/api/rsyslog" 10 "github.com/juju/juju/feature" 11 "github.com/juju/juju/worker" 12 "github.com/juju/juju/worker/dependency" 13 "github.com/juju/juju/worker/util" 14 "github.com/juju/utils/featureflag" 15 ) 16 17 // ManifoldConfig defines the names of the manifolds on which a 18 // Manifold will depend. 19 type ManifoldConfig util.AgentApiManifoldConfig 20 21 // Manifold returns a dependency manifold that runs an rsyslog 22 // worker, 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 exists to wrap NewRsyslogConfigWorker in a format convenient for an 28 // AgentApiManifold. 29 // TODO(fwereade) 2015-05-11 Eventually, the method should be the sole accessible 30 // package factory function -- as part of the manifold -- and all tests should 31 // thus be routed through it. 32 var newWorker = func(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) { 33 if featureflag.Enabled(feature.DisableRsyslog) { 34 logger.Warningf("rsyslog manifold disabled by feature flag") 35 return nil, dependency.ErrMissing 36 } 37 38 agentConfig := a.CurrentConfig() 39 tag := agentConfig.Tag() 40 namespace := agentConfig.Value(agent.Namespace) 41 addrs, err := agentConfig.APIAddresses() 42 if err != nil { 43 return nil, err 44 } 45 return NewRsyslogConfigWorker( 46 rsyslog.NewState(apiCaller), 47 RsyslogModeForwarding, 48 tag, 49 namespace, 50 addrs, 51 agentConfig.DataDir(), 52 ) 53 }