binding appID when creating service

This commit is contained in:
yangk 2020-09-18 14:59:49 +08:00
parent 985c9be20a
commit 7c6f9303bd

View File

@ -39,11 +39,11 @@ import (
mqclient "github.com/goodrain/rainbond/mq/client" mqclient "github.com/goodrain/rainbond/mq/client"
validation "github.com/goodrain/rainbond/util/endpoint" validation "github.com/goodrain/rainbond/util/endpoint"
"github.com/goodrain/rainbond/util/fuzzy" "github.com/goodrain/rainbond/util/fuzzy"
validator "github.com/goodrain/rainbond/util/govalidator"
httputil "github.com/goodrain/rainbond/util/http" httputil "github.com/goodrain/rainbond/util/http"
"github.com/goodrain/rainbond/worker/client" "github.com/goodrain/rainbond/worker/client"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
validator "github.com/goodrain/rainbond/util/govalidator"
) )
//V2Routes v2Routes //V2Routes v2Routes
@ -649,6 +649,17 @@ func (t *TenantStruct) CreateService(w http.ResponseWriter, r *http.Request) {
return return
} }
// Check if the application ID exists
_, err := handler.GetTenantApplicationHandler().GetAppByID(ss.AppID)
if err != nil || ss.AppID == "" {
if err.Error() == gorm.ErrRecordNotFound.Error() {
httputil.ReturnError(r, w, 404, "can't find application")
return
}
httputil.ReturnError(r, w, 500, "get assign tenant application failed")
return
}
// clean etcd data(source check) // clean etcd data(source check)
handler.GetEtcdHandler().CleanServiceCheckData(ss.EtcdKey) handler.GetEtcdHandler().CleanServiceCheckData(ss.EtcdKey)