Beispiel #1
0
func (p *JujuProvisioner) removeUnit(app provision.App, unit provision.AppUnit) error {
	var (
		buf bytes.Buffer
		err error
	)
	cmd := []string{"remove-unit", unit.GetName()}
	// Sometimes juju gives the "no node" error. This is one of Zookeeper bad
	// behaviors. Let's try it multiple times before raising the error to the
	// user, and hope that someday we run away from Zookeeper.
	for i := 0; i < destroyTries; i++ {
		buf.Reset()
		err = runCmd(false, &buf, &buf, cmd...)
		if err != nil && unitNotFound(unit.GetName(), buf.Bytes()) {
			err = nil
		}
		if err == nil {
			break
		}
	}
	if err != nil {
		return cmdError(buf.String(), err, cmd)
	}
	if p.elbSupport() {
		router, err := Router()
		if err != nil {
			return err
		}
		err = router.RemoveRoute(app.GetName(), unit.GetInstanceId())
	}
	collection := p.unitsCollection()
	defer collection.Close()
	collection.RemoveId(unit.GetName())
	go p.terminateMachines(app, unit)
	return err
}
Beispiel #2
0
func fixContainer(container *container, ip, port string) error {
	router, err := getRouter()
	if err != nil {
		return err
	}
	router.RemoveRoute(container.AppName, container.getAddress())
	runCmd("ssh-keygen", "-R", container.Ip)
	container.Ip = ip
	container.HostPort = port
	router.AddRoute(container.AppName, container.getAddress())
	return collection().UpdateId(container.Id, container)
}
func fixContainer(container *container, ip, port string) error {
	router, err := getRouter()
	if err != nil {
		return err
	}
	router.RemoveRoute(container.AppName, container.getAddress())
	container.removeHost()
	container.IP = ip
	container.HostPort = port
	router.AddRoute(container.AppName, container.getAddress())
	coll := collection()
	defer coll.Database.Session.Close()
	return coll.UpdateId(container.ID, container)
}
Beispiel #4
0
func Example() {
	router, err := router.Get("hipache")
	if err != nil {
		panic(err)
	}
	err = router.AddRoute("myapp", "http://10.10.10.10:8080")
	if err != nil {
		panic(err)
	}
	addr, _ := router.Addr("myapp")
	fmt.Println("Please access:", addr)
	err = router.RemoveRoute("myapp")
	if err != nil {
		panic(err)
	}
}
Beispiel #5
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)
		}
	}
}