github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/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  	coreagent "github.com/juju/juju/agent"
     8  	"github.com/juju/juju/api/base"
     9  	"github.com/juju/juju/api/rsyslog"
    10  	"github.com/juju/juju/worker"
    11  	"github.com/juju/juju/worker/agent"
    12  	"github.com/juju/juju/worker/dependency"
    13  	"github.com/juju/juju/worker/util"
    14  )
    15  
    16  // ManifoldConfig defines the names of the manifolds on which a
    17  // Manifold will depend.
    18  type ManifoldConfig util.AgentApiManifoldConfig
    19  
    20  // Manifold returns a dependency manifold that runs an rsyslog
    21  // worker, using the resource names defined in the supplied config.
    22  func Manifold(config ManifoldConfig) dependency.Manifold {
    23  	return util.AgentApiManifold(util.AgentApiManifoldConfig(config), newWorker)
    24  }
    25  
    26  // newWorker exists to wrap NewRsyslogConfigWorker in a format convenient for an
    27  // AgentApiManifold.
    28  // TODO(fwereade) 2015-05-11 Eventually, the method should be the sole accessible
    29  // package factory function -- as part of the manifold -- and all tests should
    30  // thus be routed through it.
    31  var newWorker = func(agent agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
    32  	agentConfig := agent.CurrentConfig()
    33  	tag := agentConfig.Tag()
    34  	namespace := agentConfig.Value(coreagent.Namespace)
    35  	addrs, err := agentConfig.APIAddresses()
    36  	if err != nil {
    37  		return nil, err
    38  	}
    39  	return NewRsyslogConfigWorker(
    40  		rsyslog.NewState(apiCaller),
    41  		RsyslogModeForwarding,
    42  		tag,
    43  		namespace,
    44  		addrs,
    45  	)
    46  }