1
// Copyright 2012, 2013 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"launchpad.net/juju-core/state"
10
"launchpad.net/juju-core/state/api"
11
"launchpad.net/juju-core/worker"
14
var logger = loggo.GetLogger("juju.worker.minunitsworker")
16
// MinUnitsWorker ensures the minimum number of units for services is respected.
17
type MinUnitsWorker struct {
21
// NewMinUnitsWorker returns a Worker that runs service.EnsureMinUnits()
22
// if the number of alive units belonging to a service decreases, or if the
23
// minimum required number of units for a service is increased.
24
func NewMinUnitsWorker(st *state.State) worker.Worker {
25
mu := &MinUnitsWorker{st: st}
26
return worker.NewStringsWorker(mu)
29
func (mu *MinUnitsWorker) SetUp() (api.StringsWatcher, error) {
30
return mu.st.WatchMinUnits(), nil
33
func (mu *MinUnitsWorker) handleOneService(serviceName string) error {
34
service, err := mu.st.Service(serviceName)
38
return service.EnsureMinUnits()
41
func (mu *MinUnitsWorker) Handle(serviceNames []string) error {
42
for _, name := range serviceNames {
43
logger.Infof("processing service %q", name)
44
if err := mu.handleOneService(name); err != nil {
45
logger.Errorf("failed to process service %q: %v", name, err)
52
func (mu *MinUnitsWorker) TearDown() error {
53
// Nothing to do here.