示例#1
0
func (p *dockerProvisioner) Deploy(a provision.App, w io.Writer) error {
	var deploy = func() error {
		c, err := newContainer(a)
		if err != nil {
			return err
		}
		err = c.deploy(w)
		if err != nil {
			c.remove()
		}
		return err
	}
	if containers, err := listAppContainers(a.GetName()); err == nil && len(containers) > 0 {
		for _, c := range containers {
			err = deploy()
			if err != nil {
				return err
			}
			a.RemoveUnit(c.Id)
		}
	} else if err := deploy(); err != nil {
		return err
	}
	a.Restart(w)
	app.Enqueue(queue.Message{
		Action: app.RegenerateApprcAndStart,
		Args:   []string{a.GetName()},
	})
	return nil
}
示例#2
0
func (p *JujuProvisioner) heal(units []provision.Unit) {
	var inst instance
	coll := p.unitsCollection()
	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.Printf(format, unit.Name, inst.InstanceId, unit.InstanceId)
			if p.elbSupport() {
				a := qApp{unit.AppName}
				manager := p.LoadBalancer()
				manager.Deregister(&a, provision.Unit{InstanceId: inst.InstanceId})
				err := manager.Register(&a, provision.Unit{InstanceId: unit.InstanceId})
				if err != nil {
					format := "[juju] Could not register instance %q in the load balancer: %s."
					log.Printf(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)
		}
	}
}
示例#3
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 := listAppContainers(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
}
示例#4
0
func startInBackground(a provision.App, c container, imageId string, w io.Writer, started chan bool) {
	newContainer, err := start(a, imageId, w)
	if err != nil {
		log.Printf("error on start the app %s - %s", a.GetName(), err)
	}
	msg := queue.Message{Action: app.BindService, Args: []string{a.GetName(), newContainer.ID}}
	go app.Enqueue(msg)
	if c.ID != "" {
		if a.RemoveUnit(c.ID) != nil {
			removeContainer(&c)
		}
	}
	started <- true
}
示例#5
0
文件: provisioner.go 项目: nemx/tsuru
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)
		}
	}
}
示例#6
0
		if err != nil {
			return nil, err
		}
		defer conn.Close()
		conn.Apps().Update(bson.M{"name": a.Name}, a)
		return nil, nil
	},
	Backward: func(ctx action.BWContext) {
	},
}

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