Beispiel #1
0
// UnbindApp makes the unbind between the service instance and an app.
func (si *ServiceInstance) UnbindApp(app bind.App, writer io.Writer) error {
	err := si.RemoveApp(app.GetName())
	if err != nil {
		return &errors.HTTP{Code: http.StatusPreconditionFailed, Message: "This app is not bound to this service instance."}
	}
	err = si.update(nil)
	if err != nil {
		return err
	}
	var wg sync.WaitGroup
	for _, unit := range app.GetUnits() {
		wg.Add(1)
		go func(unit bind.Unit) {
			si.UnbindUnit(app, unit)
			wg.Done()
		}(unit)
	}
	instance := bind.ServiceInstance{Name: si.Name, Envs: make(map[string]string)}
	for k, envVar := range app.InstanceEnv(si.Name) {
		instance.Envs[k] = envVar.Value
	}
	wg.Wait()
	if endpoint, err := si.Service().getClient("production"); err == nil {
		endpoint.UnbindApp(si, app)
	}
	return app.RemoveInstance(si.ServiceName, instance, writer)
}
// UnbindApp makes the unbind between the service instance and an app.
func (si *ServiceInstance) UnbindApp(app bind.App) error {
	err := si.RemoveApp(app.GetName())
	if err != nil {
		return &errors.HTTP{Code: http.StatusPreconditionFailed, Message: "This app is not bound to this service instance."}
	}
	err = si.update()
	if err != nil {
		return err
	}
	for _, unit := range app.GetUnits() {
		go func(unit bind.Unit) {
			si.UnbindUnit(unit)
		}(unit)
	}
	var envVars []string
	for k := range app.InstanceEnv(si.Name) {
		envVars = append(envVars, k)
	}
	return app.UnsetEnvs(envVars, false)
}