~ubuntu-branches/ubuntu/saucy/juju-core/saucy

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/worker/minunitsworker/minunitsworker.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 16:02:16 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20130820160216-5yu1llasa2e2youn
Tags: 1.13.1-0ubuntu1
* New upstream release.
  - Build and install juju metadata plugin.
  - d/NEWS: Add some guidance on upgrading environments from 1.11.x
    to 1.13.x.
* d/NEWS: Add details about lack of upgrade path from juju < 1.11
  and how to interact with older juju environments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012, 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package minunitsworker
 
5
 
 
6
import (
 
7
        "launchpad.net/loggo"
 
8
 
 
9
        "launchpad.net/juju-core/state"
 
10
        "launchpad.net/juju-core/state/api"
 
11
        "launchpad.net/juju-core/worker"
 
12
)
 
13
 
 
14
var logger = loggo.GetLogger("juju.worker.minunitsworker")
 
15
 
 
16
// MinUnitsWorker ensures the minimum number of units for services is respected.
 
17
type MinUnitsWorker struct {
 
18
        st *state.State
 
19
}
 
20
 
 
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)
 
27
}
 
28
 
 
29
func (mu *MinUnitsWorker) SetUp() (api.StringsWatcher, error) {
 
30
        return mu.st.WatchMinUnits(), nil
 
31
}
 
32
 
 
33
func (mu *MinUnitsWorker) handleOneService(serviceName string) error {
 
34
        service, err := mu.st.Service(serviceName)
 
35
        if err != nil {
 
36
                return err
 
37
        }
 
38
        return service.EnsureMinUnits()
 
39
}
 
40
 
 
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)
 
46
                        return err
 
47
                }
 
48
        }
 
49
        return nil
 
50
}
 
51
 
 
52
func (mu *MinUnitsWorker) TearDown() error {
 
53
        // Nothing to do here.
 
54
        return nil
 
55
}