From e27e1ce043d3c6cc0534a46e0702f0e525465fe5 Mon Sep 17 00:00:00 2001 From: tbs60 Date: Fri, 28 Jul 2023 12:03:46 +0800 Subject: [PATCH] buf fix of server crash,issue: #99 --- .../server/pkg/resource/crm/manager.go | 55 +++++++++++++++++-- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/backend/booster/server/pkg/resource/crm/manager.go b/src/backend/booster/server/pkg/resource/crm/manager.go index b44991e2..781092b9 100644 --- a/src/backend/booster/server/pkg/resource/crm/manager.go +++ b/src/backend/booster/server/pkg/resource/crm/manager.go @@ -140,6 +140,32 @@ type ResourceParam struct { BrokerName string `json:"broker_name"` } +func (rp *ResourceParam) copy() ResourceParam { + newrp := ResourceParam{ + City: rp.City, + Platform: rp.Platform, + Image: rp.Image, + BrokerName: rp.BrokerName, + Env: make(map[string]string), + Ports: make(map[string]string), + Volumes: make(map[string]op.BcsVolume), + } + + for k, v := range rp.Env { + newrp.Env[k] = v + } + + for k, v := range rp.Ports { + newrp.Ports[k] = v + } + + for k, v := range rp.Volumes { + newrp.Volumes[k] = v + } + + return newrp +} + const ( ServiceStatusStaging = op.ServiceStatusStaging ServiceStatusRunning = op.ServiceStatusRunning @@ -660,7 +686,8 @@ func (rm *resourceManager) getResources(resourceID string) (*resource, error) { return nil, ErrorResourceNoExist } - return copyResource(r), nil + // return copyResource(r), nil + return r.copy(), nil } func (rm *resourceManager) getServiceInfo(resourceID, user string) (*op.ServiceInfo, error) { @@ -1264,8 +1291,26 @@ func resource2Table(r *resource) *TableResource { } } -func copyResource(res *resource) *resource { - r := new(resource) - *r = *res - return r +// func copyResource(res *resource) *resource { +// r := new(resource) +// *r = *res +// return r +// } + +func (r *resource) copy() *resource { + newr := resource{ + resourceID: r.resourceID, + user: r.user, + param: r.param.copy(), + resourceBlockKey: r.resourceBlockKey, + noReadyInstance: r.noReadyInstance, + requestInstance: r.requestInstance, + status: r.status, + brokerResourceID: r.brokerResourceID, + brokerName: r.brokerName, + brokerSold: r.brokerSold, + initTime: r.initTime, + } + + return &newr }