38
38
type ApplicationDeployer interface {
39
Model() (*state.Model, error)
40
39
AddApplication(state.AddApplicationArgs) (*state.Application, error)
42
type UnitAssigner interface {
43
AssignUnit(*state.Unit, state.AssignmentPolicy) error
44
AssignUnitWithPlacement(*state.Unit, *instance.Placement) error
47
type UnitAdder interface {
48
AddUnit() (*state.Unit, error)
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)
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) {
116
unitAssigner UnitAssigner,
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()
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)
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)
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())