~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/juju/deploy.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
}
37
37
 
38
38
type ApplicationDeployer interface {
39
 
        Model() (*state.Model, error)
40
39
        AddApplication(state.AddApplicationArgs) (*state.Application, error)
41
40
}
42
41
 
 
42
type UnitAssigner interface {
 
43
        AssignUnit(*state.Unit, state.AssignmentPolicy) error
 
44
        AssignUnitWithPlacement(*state.Unit, *instance.Placement) error
 
45
}
 
46
 
 
47
type UnitAdder interface {
 
48
        AddUnit() (*state.Unit, error)
 
49
}
 
50
 
43
51
// DeployApplication takes a charm and various parameters and deploys it.
44
52
func DeployApplication(st ApplicationDeployer, args DeployApplicationParams) (*state.Application, error) {
45
53
        settings, err := args.Charm.Config().ValidateSettings(args.ConfigSettings)
104
112
 
105
113
// AddUnits starts n units of the given application using the specified placement
106
114
// directives to allocate the machines.
107
 
func AddUnits(st *state.State, svc *state.Application, n int, placement []*instance.Placement) ([]*state.Unit, error) {
 
115
func AddUnits(
 
116
        unitAssigner UnitAssigner,
 
117
        unitAdder UnitAdder,
 
118
        appName string,
 
119
        n int,
 
120
        placement []*instance.Placement,
 
121
) ([]*state.Unit, error) {
108
122
        units := make([]*state.Unit, n)
109
123
        // Hard code for now till we implement a different approach.
110
124
        policy := state.AssignCleanEmpty
111
125
        // TODO what do we do if we fail half-way through this process?
112
126
        for i := 0; i < n; i++ {
113
 
                unit, err := svc.AddUnit()
 
127
                unit, err := unitAdder.AddUnit()
114
128
                if err != nil {
115
 
                        return nil, errors.Annotatef(err, "cannot add unit %d/%d to application %q", i+1, n, svc.Name())
 
129
                        return nil, errors.Annotatef(err, "cannot add unit %d/%d to application %q", i+1, n, appName)
116
130
                }
117
131
                // Are there still placement directives to use?
118
132
                if i > len(placement)-1 {
119
 
                        if err := st.AssignUnit(unit, policy); err != nil {
 
133
                        if err := unitAssigner.AssignUnit(unit, policy); err != nil {
120
134
                                return nil, errors.Trace(err)
121
135
                        }
122
136
                        units[i] = unit
123
137
                        continue
124
138
                }
125
 
                if err := st.AssignUnitWithPlacement(unit, placement[i]); err != nil {
 
139
                if err := unitAssigner.AssignUnitWithPlacement(unit, placement[i]); err != nil {
126
140
                        return nil, errors.Annotatef(err, "adding new machine to host unit %q", unit.Name())
127
141
                }
128
142
                units[i] = unit