fix: 避免dbinstance_sku.get 异常

This commit is contained in:
Qu Xuan
2020-03-17 17:04:13 +08:00
parent 4dbbb2b1b5
commit 6367d20757
8 changed files with 49 additions and 17 deletions
+23
View File
@@ -0,0 +1,23 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package compute
import "yunion.io/x/onecloud/pkg/apis"
type DBInstanceSkuDetails struct {
apis.StandaloneResourceDetails
CloudregionInfo
}
+2 -3
View File
@@ -57,11 +57,10 @@ func call(obj interface{}, fName string, inputs ...interface{}) ([]reflect.Value
func callObject(modelVal reflect.Value, fName string, inputs ...interface{}) ([]reflect.Value, error) {
funcVal := modelVal.MethodByName(fName)
return callFunc(funcVal, inputs...)
return callFunc(funcVal, fName, inputs...)
}
func callFunc(funcVal reflect.Value, inputs ...interface{}) ([]reflect.Value, error) {
fName := funcVal.String()
func callFunc(funcVal reflect.Value, fName string, inputs ...interface{}) ([]reflect.Value, error) {
if !funcVal.IsValid() || funcVal.IsNil() {
return nil, httperrors.NewActionNotFoundError(fmt.Sprintf("%s method not found", fName))
}
+12 -10
View File
@@ -792,12 +792,11 @@ func (dispatcher *DBModelDispatcher) tryGetModelProperty(ctx context.Context, pr
return nil, nil
}
userCred := fetchUserCredential(ctx)
params := []reflect.Value{
reflect.ValueOf(ctx),
reflect.ValueOf(userCred),
reflect.ValueOf(query),
params := []interface{}{ctx, userCred, query}
outs, err := callFunc(funcValue, allowFuncName, params...)
if err != nil {
return nil, httperrors.NewInternalServerError("reflect call %s fail %s", allowFuncName, err)
}
outs := funcValue.Call(params)
if len(outs) != 1 {
return nil, httperrors.NewInternalServerError("Invald %s return value", funcName)
}
@@ -806,7 +805,10 @@ func (dispatcher *DBModelDispatcher) tryGetModelProperty(ctx context.Context, pr
}
funcValue = modelValue.MethodByName(funcName)
outs = funcValue.Call(params)
outs, err = callFunc(funcValue, funcName, params...)
if err != nil {
return nil, httperrors.NewInternalServerError("reflect call %s fail %s", funcName, err)
}
if len(outs) != 2 {
return nil, httperrors.NewInternalServerError("Invald %s return value", funcName)
}
@@ -887,7 +889,7 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri
return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec)
}
outs, err := callFunc(funcValue, params...)
outs, err := callFunc(funcValue, funcName, params...)
if err != nil {
return nil, err
}
@@ -905,7 +907,7 @@ func (dispatcher *DBModelDispatcher) GetSpecific(ctx context.Context, idStr stri
return nil, httperrors.NewSpecNotFoundError("%s %s %s not found", dispatcher.Keyword(), idStr, spec)
}
outs, err := callFunc(funcValue, params...)
outs, err := callFunc(funcValue, funcName, params...)
if err != nil {
return nil, err
}
@@ -1470,7 +1472,7 @@ func reflectDispatcherInternal(
return nil, httperrors.NewActionNotFoundError(msg)
}
outs, err := callFunc(allowFuncValue, params...)
outs, err := callFunc(allowFuncValue, allowFuncName, params...)
if err != nil {
return nil, err
}
@@ -1483,7 +1485,7 @@ func reflectDispatcherInternal(
}
}
outs, err := callFunc(funcValue, params...)
outs, err := callFunc(funcValue, funcName, params...)
if err != nil {
return nil, err
}
+1 -1
View File
@@ -37,7 +37,7 @@ func (self *SCloudregionResourceBase) GetRegion() *SCloudregion {
return region.(*SCloudregion)
}
func (self *SCloudregionResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) api.CloudregionInfo {
func (self *SCloudregionResourceBase) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) api.CloudregionInfo {
out := api.CloudregionInfo{}
region := self.GetRegion()
if region == nil {
+8
View File
@@ -136,6 +136,14 @@ func (manager *SDBInstanceSkuManager) ListItemFilter(ctx context.Context, q *sql
return q, nil
}
func (self *SDBInstanceSku) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, isList bool) (api.DBInstanceSkuDetails, error) {
var err error
out := api.DBInstanceSkuDetails{}
out.StandaloneResourceDetails, err = self.SEnabledStatusStandaloneResourceBase.GetExtraDetails(ctx, userCred, query, isList)
out.CloudregionInfo = self.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query, isList)
return out, err
}
func (manager *SDBInstanceSkuManager) GetDBStringArray(q *sqlchemy.SQuery) ([]string, error) {
array := []string{}
rows, err := q.Rows()
@@ -400,7 +400,7 @@ func (lbbg *SLoadbalancerBackendGroup) GetExtraDetails(ctx context.Context, user
return out, err
}
out.Loadbalancer = lb.GetName()
out.CloudregionInfo = lbbg.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query)
out.CloudregionInfo = lbbg.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query, isList)
return out, nil
}
@@ -505,7 +505,7 @@ func (lbr *SLoadbalancerListenerRule) GetExtraDetails(ctx context.Context, userC
if err != nil {
return out, err
}
out.CloudregionInfo = lbr.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query)
out.CloudregionInfo = lbr.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query, isList)
if lbr.BackendGroupId == "" {
log.Errorf("loadbalancer listener rule %s(%s): empty backend group field", lbr.Name, lbr.Id)
return out, nil
+1 -1
View File
@@ -445,7 +445,7 @@ func (lblis *SLoadbalancerListener) GetExtraDetails(ctx context.Context, userCre
out.OriginCertificateId = cert.CertificateId
}
}
out.CloudregionInfo = lblis.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query)
out.CloudregionInfo = lblis.SCloudregionResourceBase.GetExtraDetails(ctx, userCred, query, isList)
return out, nil
}