mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #8031 from wanyaoqi/feature/wyq/support-mutli-params
apigateway: support mutli params
This commit is contained in:
@@ -488,7 +488,17 @@ func (f *ResourceHandlers) batchUpdateHandler(ctx context.Context, w http.Respon
|
||||
return
|
||||
}
|
||||
|
||||
ret := module.BatchUpdate(req.Session(), idlist, body)
|
||||
var ret []modulebase.SubmitResult
|
||||
if jsonutils.QueryBoolean(query, "batch_params", false) {
|
||||
bodys, err := body.GetArray()
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
return
|
||||
}
|
||||
ret = module.BatchParamsUpdate(req.Session(), idlist, bodys)
|
||||
} else {
|
||||
ret = module.BatchUpdate(req.Session(), idlist, body)
|
||||
}
|
||||
w.WriteHeader(207)
|
||||
appsrv.SendJSON(w, modulebase.SubmitResults2JSON(ret))
|
||||
}
|
||||
|
||||
@@ -304,6 +304,20 @@ func BatchDo(ids []string, do func(id string) (jsonutils.JSONObject, error)) []S
|
||||
return waitResults(results, len(ids))
|
||||
}
|
||||
|
||||
func BatchParamsDo(
|
||||
ids []string, params []jsonutils.JSONObject,
|
||||
do func(id string, param jsonutils.JSONObject) (jsonutils.JSONObject, error),
|
||||
) []SubmitResult {
|
||||
results := make(chan SubmitResult, len(ids))
|
||||
for i := 0; i < len(ids); i++ {
|
||||
go func(id string, param jsonutils.JSONObject) {
|
||||
r, e := do(id, param)
|
||||
addResult(results, id, r, e)
|
||||
}(ids[i], params[i])
|
||||
}
|
||||
return waitResults(results, len(ids))
|
||||
}
|
||||
|
||||
func BatchDoClassAction(
|
||||
batchParams []jsonutils.JSONObject, do func(jsonutils.JSONObject) (jsonutils.JSONObject, error),
|
||||
) []SubmitResult {
|
||||
|
||||
@@ -113,6 +113,7 @@ type Manager interface {
|
||||
PutInContext(session *mcclient.ClientSession, id string, params jsonutils.JSONObject, ctx Manager, ctxid string) (jsonutils.JSONObject, error)
|
||||
PutInContexts(session *mcclient.ClientSession, id string, params jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error)
|
||||
BatchUpdate(session *mcclient.ClientSession, idlist []string, params jsonutils.JSONObject) []SubmitResult
|
||||
BatchParamsUpdate(session *mcclient.ClientSession, idlist []string, params []jsonutils.JSONObject) []SubmitResult
|
||||
BatchPut(session *mcclient.ClientSession, idlist []string, params jsonutils.JSONObject) []SubmitResult
|
||||
BatchPutInContext(session *mcclient.ClientSession, idlist []string, params jsonutils.JSONObject, ctx Manager, ctxid string) []SubmitResult
|
||||
BatchPutInContexts(session *mcclient.ClientSession, idlist []string, params jsonutils.JSONObject, ctxs []ManagerContext) []SubmitResult
|
||||
|
||||
@@ -453,6 +453,16 @@ func (this *ResourceManager) BatchPutInContexts(session *mcclient.ClientSession,
|
||||
})
|
||||
}
|
||||
|
||||
func (this *ResourceManager) BatchParamsUpdate(session *mcclient.ClientSession, idlist []string, params []jsonutils.JSONObject) []SubmitResult {
|
||||
return this.BatchParamsPutInContexts(session, idlist, params, nil)
|
||||
}
|
||||
|
||||
func (this *ResourceManager) BatchParamsPutInContexts(session *mcclient.ClientSession, idlist []string, params []jsonutils.JSONObject, ctxs []ManagerContext) []SubmitResult {
|
||||
return BatchParamsDo(idlist, params, func(id string, param jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return this.PutInContexts(session, id, param, ctxs)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *ResourceManager) Patch(session *mcclient.ClientSession, id string, params jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return this.PatchInContexts(session, id, params, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user