示例#1
0
func (p *FakeProvisioner) AddUnits(app provision.App, n uint) ([]provision.Unit, error) {
	if err := p.getError("AddUnits"); err != nil {
		return nil, err
	}
	if n == 0 {
		return nil, errors.New("Cannot add 0 units.")
	}
	index := p.FindApp(app)
	if index < 0 {
		return nil, errors.New("App is not provisioned.")
	}
	name := app.GetName()
	framework := app.GetFramework()
	p.unitMut.Lock()
	defer p.unitMut.Unlock()
	length := uint(len(p.units[name]))
	for i := uint(0); i < n; i++ {
		unit := provision.Unit{
			Name:    fmt.Sprintf("%s/%d", name, length+i),
			AppName: name,
			Type:    framework,
			Status:  provision.StatusStarted,
			Ip:      fmt.Sprintf("10.10.10.%d", length+i),
			Machine: int(length + i),
		}
		p.units[name] = append(p.units[name], unit)
	}
	return p.units[name][length:], nil
}
示例#2
0
func (p *FakeProvisioner) Provision(app provision.App) error {
	if err := p.getError("Provision"); err != nil {
		return err
	}
	index := p.FindApp(app)
	if index > -1 {
		return &provision.Error{Reason: "App already provisioned."}
	}
	p.apps = append(p.apps, app)
	p.unitMut.Lock()
	p.units[app.GetName()] = []provision.Unit{
		{
			Name:       app.GetName() + "/0",
			AppName:    app.GetName(),
			Type:       app.GetFramework(),
			Status:     provision.StatusStarted,
			InstanceId: "i-080",
			Ip:         "10.10.10.1",
			Machine:    1,
		},
	}
	p.unitLen++
	p.unitMut.Unlock()
	return nil
}
示例#3
0
func (p *JujuProvisioner) Provision(app provision.App) error {
	var buf bytes.Buffer
	args := []string{
		"deploy", "--repository", "/home/charms",
		"local:" + app.GetFramework(), app.GetName(),
	}
	err := runCmd(true, &buf, &buf, args...)
	out := buf.String()
	if err != nil {
		app.Log("Failed to create machine: "+out, "tsuru")
		return &provision.Error{Reason: out, Err: err}
	}
	return nil
}
示例#4
0
func (p *JujuProvisioner) Provision(app provision.App) error {
	var buf bytes.Buffer
	charms, err := config.GetString("juju:charms-path")
	if err != nil {
		return errors.New(`Setting "juju:charms-path" is not defined.`)
	}
	args := []string{
		"deploy", "--repository", charms,
		"local:" + app.GetFramework(), app.GetName(),
	}
	err = runCmd(false, &buf, &buf, args...)
	out := buf.String()
	if err != nil {
		app.Log("Failed to create machine: "+out, "tsuru")
		return cmdError(out, err, args)
	}
	setOption := []string{
		"set", app.GetName(), "app-repo=" + repository.GetReadOnlyUrl(app.GetName()),
	}
	runCmd(true, &buf, &buf, setOption...)
	if p.elbSupport() {
		if err = p.LoadBalancer().Create(app); err != nil {
			return err
		}
		p.enqueueUnits(app.GetName())
	}
	return nil
}
示例#5
0
func (p *LocalProvisioner) Provision(app provision.App) error {
	go func(p *LocalProvisioner, app provision.App) {
		c := container{name: app.GetName()}
		log.Printf("creating container %s", c.name)
		u := provision.Unit{
			Name:       app.GetName(),
			AppName:    app.GetName(),
			Type:       app.GetFramework(),
			Machine:    0,
			InstanceId: app.GetName(),
			Status:     provision.StatusCreating,
			Ip:         "",
		}
		log.Printf("inserting container unit %s in the database", app.GetName())
		err := p.collection().Insert(u)
		if err != nil {
			log.Print(err)
		}
		err = c.create()
		if err != nil {
			log.Printf("error on create container %s", app.GetName())
			log.Print(err)
		}
		err = c.start()
		if err != nil {
			log.Printf("error on start container %s", app.GetName())
			log.Print(err)
		}
		ip := c.ip()
		u.Ip = ip
		u.Status = provision.StatusInstalling
		err = p.collection().Update(bson.M{"name": u.Name}, u)
		if err != nil {
			log.Print(err)
		}
		err = p.setup(ip, app.GetFramework())
		if err != nil {
			log.Printf("error on setup container %s", app.GetName())
			log.Print(err)
		}
		err = p.install(ip)
		if err != nil {
			log.Printf("error on install container %s", app.GetName())
			log.Print(err)
		}
		err = p.start(ip)
		if err != nil {
			log.Printf("error on start app for container %s", app.GetName())
			log.Print(err)
		}
		err = AddRoute(app.GetName(), ip)
		if err != nil {
			log.Printf("error on add route for %s with ip %s", app.GetName(), ip)
			log.Print(err)
		}
		err = RestartRouter()
		if err != nil {
			log.Printf("error on restart router")
			log.Print(err)
		}
		u.Status = provision.StatusStarted
		err = p.collection().Update(bson.M{"name": u.Name}, u)
		if err != nil {
			log.Print(err)
		}
	}(p, app)
	return nil
}