mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
automatically save pendingUsage in context
This commit is contained in:
@@ -39,7 +39,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
@@ -1242,14 +1241,9 @@ func (dispatcher *DBModelDispatcher) BatchCreate(ctx context.Context, query json
|
||||
for i, res := range createResults {
|
||||
result := modulebase.SubmitResult{}
|
||||
if res.err != nil {
|
||||
jsonErr, ok := res.err.(*httputils.JSONClientError)
|
||||
if ok {
|
||||
result.Status = jsonErr.Code
|
||||
result.Data = jsonutils.Marshal(jsonErr)
|
||||
} else {
|
||||
result.Status = 500
|
||||
result.Data = jsonutils.NewString(res.err.Error())
|
||||
}
|
||||
jsonErr := httperrors.NewGeneralError(res.err)
|
||||
result.Status = jsonErr.Code
|
||||
result.Data = jsonutils.Marshal(jsonErr)
|
||||
} else {
|
||||
lockman.LockObject(ctx, res.model)
|
||||
defer lockman.ReleaseObject(ctx, res.model)
|
||||
|
||||
@@ -57,7 +57,7 @@ func clearPendingUsagesInContext(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func SavePendingUsagesInContext(ctx context.Context, quotas ...IQuota) {
|
||||
func savePendingUsagesInContext(ctx context.Context, quotas ...IQuota) {
|
||||
val := ctx.Value(APP_CONTEXT_KEY_PENDINGUSAGES)
|
||||
if val != nil {
|
||||
quotaList := val.(*list.List)
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
@@ -61,7 +62,12 @@ func CancelPendingUsage(ctx context.Context, userCred mcclient.TokenCredential,
|
||||
|
||||
func CheckSetPendingQuota(ctx context.Context, userCred mcclient.TokenCredential, quota IQuota) error {
|
||||
manager := getQuotaManager(quota)
|
||||
return manager.checkSetPendingQuota(ctx, userCred, quota)
|
||||
err := manager.checkSetPendingQuota(ctx, userCred, quota)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "manager.checkSetPendingQuota")
|
||||
}
|
||||
savePendingUsagesInContext(ctx, quota)
|
||||
return nil
|
||||
}
|
||||
|
||||
func CancelUsages(ctx context.Context, userCred mcclient.TokenCredential, usages []db.IUsage) {
|
||||
|
||||
@@ -1393,7 +1393,6 @@ func (manager *SGuestManager) checkCreateQuota(
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "quotas.CheckSetPendingQuota")
|
||||
}
|
||||
quotas.SavePendingUsagesInContext(ctx, &req, ®ionReq)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user