added service change app_id method

This commit is contained in:
yangk 2020-09-18 15:54:21 +08:00
parent 7c6f9303bd
commit 3a5d622a5e
2 changed files with 19 additions and 1 deletions

View File

@ -717,6 +717,7 @@ func (t *TenantStruct) UpdateService(w http.ResponseWriter, r *http.Request) {
"container_memory": []string{},
"service_name": []string{},
"extend_method": []string{},
"app_id": []string{},
}
data, ok := httputil.ValidatorRequestMapAndErrorResponse(r, w, rules, nil)
if !ok {
@ -724,6 +725,22 @@ func (t *TenantStruct) UpdateService(w http.ResponseWriter, r *http.Request) {
}
serviceID := r.Context().Value(middleware.ContextKey("service_id")).(string)
data["service_id"] = serviceID
// Check if the application ID exists
var appID string
if data["app_id"] != nil {
appID = data["app_id"].(string)
}
_, err := handler.GetTenantApplicationHandler().GetAppByID(appID)
if err != nil || 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
}
logrus.Debugf("begin to update service")
if err := handler.GetServiceManager().ServiceUpdate(data); err != nil {
httputil.ReturnError(r, w, 500, fmt.Sprintf("update service error, %v", err))

View File

@ -28,10 +28,10 @@ import (
"strings"
"time"
"github.com/sirupsen/logrus"
"github.com/coreos/etcd/clientv3"
"github.com/jinzhu/gorm"
"github.com/pquerna/ffjson/ffjson"
"github.com/sirupsen/logrus"
"github.com/twinj/uuid"
"github.com/goodrain/rainbond/api/proxy"
@ -744,6 +744,7 @@ func (s *ServiceAction) ServiceUpdate(sc map[string]interface{}) error {
if err != nil {
return err
}
ts.AppID = sc["app_id"].(string)
version, err := db.GetManager().VersionInfoDao().GetVersionByDeployVersion(ts.DeployVersion, ts.ServiceID)
if sc["container_memory"] != nil {
ts.ContainerMemory = sc["container_memory"].(int)