github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/worker/upgrader/manifold.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package upgrader
     5  
     6  import (
     7  	"github.com/juju/juju/agent"
     8  	"github.com/juju/juju/api/base"
     9  	"github.com/juju/juju/api/upgrader"
    10  	"github.com/juju/juju/worker"
    11  	"github.com/juju/juju/worker/dependency"
    12  	"github.com/juju/juju/worker/util"
    13  )
    14  
    15  // ManifoldConfig defines the names of the manifolds on which a
    16  // Manifold will depend.
    17  type ManifoldConfig util.AgentApiManifoldConfig
    18  
    19  // Manifold returns a dependency manifold that runs an upgrader
    20  // worker, using the resource names defined in the supplied config.
    21  func Manifold(config ManifoldConfig) dependency.Manifold {
    22  	return util.AgentApiManifold(util.AgentApiManifoldConfig(config), newWorker)
    23  }
    24  
    25  // newWorker wraps NewUpgrader for the convenience of AgentApiManifold. It should
    26  // eventually replace NewUpgrader.
    27  var newWorker = func(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
    28  	currentConfig := a.CurrentConfig()
    29  	upgraderFacade := upgrader.NewState(apiCaller)
    30  	return NewAgentUpgrader(
    31  		upgraderFacade,
    32  		currentConfig,
    33  		// TODO(fwereade): surely we shouldn't need both currentConfig
    34  		// *and* currentConfig.UpgradedToVersion?
    35  		currentConfig.UpgradedToVersion(),
    36  		// TODO(fwereade): these are unit-agent-specific, and very much
    37  		// unsuitable for use in a machine agent.
    38  		func() bool { return false },
    39  		make(chan struct{}),
    40  	), nil
    41  }