コード例 #1
0
ファイル: router.go プロジェクト: rochacon/tsuru
func (r elbRouter) RemoveBackend(name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	_, err = r.elb().DeleteLoadBalancer(backendName)
	if err != nil {
		return err
	}
	return router.Remove(backendName)
}
コード例 #2
0
ファイル: router.go プロジェクト: RichardKnop/tsuru
func (r *fakeRouter) RemoveBackend(name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if !r.HasBackend(backendName) {
		return router.ErrBackendNotFound
	}
	r.mutex.Lock()
	defer r.mutex.Unlock()
	delete(r.backends, backendName)
	return router.Remove(backendName)
}
コード例 #3
0
ファイル: router.go プロジェクト: RichardKnop/tsuru
func (r *vulcandRouter) RemoveBackend(name string) error {
	frontendKey := engine.FrontendKey{Id: r.frontendName(r.frontendHostname(name))}
	err := r.client.DeleteFrontend(frontendKey)
	if err != nil {
		if _, ok := err.(*engine.NotFoundError); ok {
			return router.ErrBackendNotFound
		}
		return err
	}
	backendKey := engine.BackendKey{Id: r.backendName(name)}
	err = r.client.DeleteBackend(backendKey)
	if err != nil {
		return err
	}
	return router.Remove(name)
}
コード例 #4
0
ファイル: router.go プロジェクト: nicolas2bonfils/tsuru
func (r *vulcandRouter) RemoveBackend(name string) error {
	usedName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if usedName != name {
		return router.ErrBackendSwapped
	}
	backendKey := engine.BackendKey{Id: r.backendName(usedName)}
	frontends, err := r.client.GetFrontends()
	if err != nil {
		return &router.RouterError{Err: err, Op: "remove-backend"}
	}
	toRemove := []engine.FrontendKey{}
	for _, f := range frontends {
		if f.BackendId == backendKey.Id {
			toRemove = append(toRemove, engine.FrontendKey{Id: f.GetId()})
		}
	}
	for _, fk := range toRemove {
		err := r.client.DeleteFrontend(fk)
		if err != nil {
			if _, ok := err.(*engine.NotFoundError); ok {
				return router.ErrBackendNotFound
			}
			return &router.RouterError{Err: err, Op: "remove-backend"}
		}
	}
	routes, err := r.Routes(name)
	if err != nil {
		return err
	}
	for _, route := range routes {
		err = r.RemoveRoute(name, route)
		if err != nil {
			return err
		}
	}
	err = r.client.DeleteBackend(backendKey)
	if err != nil {
		if _, ok := err.(*engine.NotFoundError); ok {
			return router.ErrBackendNotFound
		}
		return &router.RouterError{Err: err, Op: "remove-backend"}
	}
	return router.Remove(usedName)
}
コード例 #5
0
ファイル: router.go プロジェクト: nicolas2bonfils/tsuru
func (r *galebRouter) RemoveBackend(name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if backendName != name {
		return router.ErrBackendSwapped
	}
	data, err := getGalebData(backendName)
	if err != nil {
		return err
	}
	client, err := r.getClient()
	if err != nil {
		return err
	}
	err = client.RemoveResource(data.VirtualHostId)
	if err != nil {
		return err
	}
	for _, cnameData := range data.CNames {
		err = client.RemoveResource(cnameData.VirtualHostId)
		if err != nil {
			return err
		}
	}
	err = client.RemoveResource(data.RootRuleId)
	if err != nil {
		return err
	}
	for _, route := range data.Reals {
		err = client.RemoveResource(route.BackendId)
		if err != nil {
			return err
		}
	}
	err = client.RemoveResource(data.BackendPoolId)
	if err != nil {
		return err
	}
	err = data.remove()
	if err != nil {
		return err
	}
	return router.Remove(backendName)
}
コード例 #6
0
ファイル: router.go プロジェクト: pedrosnk/tsuru
func (r *hipacheRouter) RemoveBackend(name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if backendName != name {
		return router.ErrBackendSwapped
	}
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return &router.RouterError{Op: "remove", Err: err}
	}
	frontend := "frontend:" + backendName + "." + domain
	conn, err := r.connect()
	if err != nil {
		return &router.RouterError{Op: "remove", Err: err}
	}
	err = conn.Del(frontend).Err()
	if err != nil {
		return &router.RouterError{Op: "remove", Err: err}
	}
	err = router.Remove(backendName)
	if err != nil {
		return &router.RouterError{Op: "remove", Err: err}
	}
	cnames, err := r.getCNames(backendName)
	if err != nil {
		return err
	}
	if cnames == nil {
		return nil
	}
	for _, cname := range cnames {
		err = conn.Del("frontend:" + cname).Err()
		if err != nil {
			return &router.RouterError{Op: "remove", Err: err}
		}
	}
	err = conn.Del("cname:" + backendName).Err()
	if err != nil {
		return &router.RouterError{Op: "remove", Err: err}
	}
	return nil
}
コード例 #7
0
ファイル: router.go プロジェクト: zhenruyan/tsuru
func (r *fakeRouter) RemoveBackend(name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if backendName != name {
		return router.ErrBackendSwapped
	}
	if !r.HasBackend(backendName) {
		return router.ErrBackendNotFound
	}
	r.mutex.Lock()
	defer r.mutex.Unlock()
	for cname, backend := range r.cnames {
		if backend == backendName {
			delete(r.cnames, cname)
		}
	}
	delete(r.backends, backendName)
	return router.Remove(backendName)
}
コード例 #8
0
ファイル: router.go プロジェクト: nicolas2bonfils/tsuru
func (r *galebRouter) RemoveBackend(name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	if backendName != name {
		return router.ErrBackendSwapped
	}
	rule := ruleName(backendName)
	virtualhosts, err := r.client.FindVirtualHostsByRule(rule)
	if err != nil {
		return err
	}
	for _, virtualhost := range virtualhosts {
		err = r.client.RemoveRuleVirtualHost(rule, virtualhost.Name)
		if err != nil {
			return err
		}
		err = r.client.RemoveVirtualHostByID(virtualhost.FullId())
		if err != nil {
			return err
		}
	}
	err = r.client.RemoveRule(ruleName(backendName))
	if err != nil {
		return err
	}
	targets, err := r.client.FindTargetsByParent(poolName(backendName))
	if err != nil {
		return err
	}
	for _, target := range targets {
		r.client.RemoveBackendByID(target.FullId())
	}
	err = r.client.RemoveBackendPool(poolName(backendName))
	if err != nil {
		return err
	}
	return router.Remove(backendName)
}
コード例 #9
0
ファイル: router.go プロジェクト: RichardKnop/tsuru
func (r *hipacheRouter) RemoveBackend(name string) error {
	backendName, err := router.Retrieve(name)
	if err != nil {
		return err
	}
	domain, err := config.GetString(r.prefix + ":domain")
	if err != nil {
		return &routeError{"remove", err}
	}
	frontend := "frontend:" + backendName + "." + domain
	conn := r.connect()
	defer conn.Close()
	_, err = conn.Do("DEL", frontend)
	if err != nil {
		return &routeError{"remove", err}
	}
	err = router.Remove(backendName)
	if err != nil {
		return &routeError{"remove", err}
	}
	cnames, err := r.getCNames(backendName)
	if err != nil {
		return err
	}
	if cnames == nil {
		return nil
	}
	for _, cname := range cnames {
		_, err = conn.Do("DEL", "frontend:"+cname)
		if err != nil {
			return &routeError{"remove", err}
		}
	}
	_, err = conn.Do("DEL", "cname:"+backendName)
	if err != nil {
		return &routeError{"remove", err}
	}
	return nil
}
コード例 #10
0
ファイル: app.go プロジェクト: tsuru/tsuru
// Delete deletes an app.
func Delete(app *App, w io.Writer) error {
	isSwapped, swappedWith, err := router.IsSwapped(app.GetName())
	if err != nil {
		return errors.Wrap(err, "unable to check if app is swapped")
	}
	if isSwapped {
		return errors.Errorf("application is swapped with %q, cannot remove it", swappedWith)
	}
	appName := app.Name
	if w == nil {
		w = ioutil.Discard
	}
	fmt.Fprintf(w, "---- Removing application %q...\n", appName)
	var hasErrors bool
	defer func() {
		var problems string
		if hasErrors {
			problems = " Some errors occurred during removal."
		}
		fmt.Fprintf(w, "---- Done removing application.%s\n", problems)
	}()
	logErr := func(msg string, err error) {
		msg = fmt.Sprintf("%s: %s", msg, err)
		fmt.Fprintf(w, "%s\n", msg)
		log.Errorf("[delete-app: %s] %s", appName, msg)
		hasErrors = true
	}
	prov, err := app.getProvisioner()
	if err != nil {
		return err
	}
	err = prov.Destroy(app)
	if err != nil {
		logErr("Unable to destroy app in provisioner", err)
	}
	r, err := app.Router()
	if err == nil {
		err = r.RemoveBackend(app.Name)
	}
	if err != nil {
		logErr("Failed to remove router backend", err)
	}
	err = router.Remove(app.Name)
	if err != nil {
		logErr("Failed to remove router backend from database", err)
	}
	err = app.unbind()
	if err != nil {
		logErr("Unable to unbind app", err)
	}
	err = repository.Manager().RemoveRepository(appName)
	if err != nil {
		logErr("Unable to remove app from repository manager", err)
	}
	token := app.Env["TSURU_APP_TOKEN"].Value
	err = AuthScheme.AppLogout(token)
	if err != nil {
		logErr("Unable to remove app token in destroy", err)
	}
	owner, err := auth.GetUserByEmail(app.Owner)
	if err == nil {
		err = auth.ReleaseApp(owner)
	}
	if err != nil {
		logErr("Unable to release app quota", err)
	}
	logConn, err := db.LogConn()
	if err == nil {
		defer logConn.Close()
		err = logConn.Logs(appName).DropCollection()
	}
	if err != nil {
		logErr("Unable to remove logs collection", err)
	}
	conn, err := db.Conn()
	if err == nil {
		defer conn.Close()
		err = conn.Apps().Remove(bson.M{"name": appName})
	}
	if err != nil {
		logErr("Unable to remove app from db", err)
	}
	err = event.MarkAsRemoved(event.Target{Type: event.TargetTypeApp, Value: appName})
	if err != nil {
		logErr("Unable to mark old events as removed", err)
	}
	return nil
}