Exemplo n.º 1
0
// rebindWhenNeed rebinds a unit to the app's services when it finds
// that the unit being removed has the same host that any
// of the units that still being used
func rebindWhenNeed(appName string, container *container) error {
	containers, err := listContainersByApp(appName)
	if err != nil {
		return err
	}
	for _, c := range containers {
		if c.HostAddr == container.HostAddr && c.ID != container.ID {
			msg := queue.Message{Action: app.BindService, Args: []string{appName, c.ID}}
			go app.Enqueue(msg)
			break
		}
	}
	return nil
}
Exemplo n.º 2
0
func (p *JujuProvisioner) heal(units []provision.Unit) {
	var inst instance
	coll := p.unitsCollection()
	defer coll.Close()
	for _, unit := range units {
		err := coll.FindId(unit.Name).One(&inst)
		if err != nil {
			coll.Insert(instance{UnitName: unit.Name, InstanceID: unit.InstanceId})
		} else if unit.InstanceId == inst.InstanceID {
			continue
		} else {
			format := "[juju] instance-id of unit %q changed from %q to %q. Healing."
			log.Debugf(format, unit.Name, inst.InstanceID, unit.InstanceId)
			if p.elbSupport() {
				router, err := Router()
				if err != nil {
					continue
				}
				router.RemoveRoute(unit.AppName, inst.InstanceID)
				err = router.AddRoute(unit.AppName, unit.InstanceId)
				if err != nil {
					format := "[juju] Could not register instance %q in the load balancer: %s."
					log.Errorf(format, unit.InstanceId, err)
					continue
				}
			}
			if inst.InstanceID != "pending" {
				msg := queue.Message{
					Action: app.RegenerateApprcAndStart,
					Args:   []string{unit.AppName, unit.Name},
				}
				app.Enqueue(msg)
			}
			inst.InstanceID = unit.InstanceId
			coll.UpdateId(unit.Name, inst)
		}
	}
}
Exemplo n.º 3
0
	},
}

var bindService = action.Action{
	Name: "bind-service",
	Forward: func(ctx action.FWContext) (action.Result, error) {
		opts, ok := ctx.Params[0].(app.DeployOptions)
		if !ok {
			return nil, errors.New("First parameter must be DeployOptions")
		}
		for _, u := range opts.App.Units() {
			msg := queue.Message{
				Action: app.BindService,
				Args:   []string{opts.App.GetName(), u.Name},
			}
			go app.Enqueue(msg)
		}
		return nil, nil
	},
	Backward: func(ctx action.BWContext) {
	},
}

var provisionAddUnitToHost = action.Action{
	Name: "provision-add-unit-to-host",
	Forward: func(ctx action.FWContext) (action.Result, error) {
		a := ctx.Params[0].(provision.App)
		destinationHost := ctx.Params[1].(string)
		units, err := addUnitsWithHost(a, 1, destinationHost)
		if err != nil {
			return nil, err