Skip to content

Commit

Permalink
Merge pull request #100 from tbs60/dev_tming
Browse files Browse the repository at this point in the history
buf fix of server crash,issue: #99
  • Loading branch information
tming authored Jul 28, 2023
2 parents 69d87d5 + e27e1ce commit 69a5675
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions src/backend/booster/server/pkg/resource/crm/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit 69a5675

Please sign in to comment.