github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/api/multiobj.go (about) 1 // Package api provides native Go-based API/SDK over HTTP(S). 2 /* 3 * Copyright (c) 2018-2024, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package api 6 7 import ( 8 "net/http" 9 "net/url" 10 "strconv" 11 12 "github.com/NVIDIA/aistore/api/apc" 13 "github.com/NVIDIA/aistore/cmn" 14 "github.com/NVIDIA/aistore/cmn/cos" 15 ) 16 17 // 18 // In this file: APIs to start multi-object xactions 19 // See also: xaction.go (generic part) 20 // 21 22 // Archive multiple objects from the specified source bucket. 23 // The option to append multiple objects to an existing archive is also supported. 24 // The source and the destination buckets are defined as `bckFrom` and `bckTo`, respectively 25 // (not necessarily distinct) 26 // For supported archiving formats, see `archive.FileExtensions`. 27 // See also: api.PutApndArch 28 func ArchiveMultiObj(bp BaseParams, bckFrom cmn.Bck, msg *cmn.ArchiveBckMsg) (string, error) { 29 bp.Method = http.MethodPut 30 q := bckFrom.NewQuery() 31 return dolr(bp, bckFrom, apc.ActArchive, msg, q) 32 } 33 34 // `fltPresence` applies exclusively to remote `bckFrom` (is ignored if the source is ais://) 35 // and is one of: { apc.FltExists, apc.FltPresent, ... } - for complete enum, see api/apc/query.go 36 37 func CopyMultiObj(bp BaseParams, bckFrom cmn.Bck, msg *cmn.TCObjsMsg, fltPresence ...int) (xid string, err error) { 38 bp.Method = http.MethodPost 39 q := bckFrom.NewQuery() 40 if len(fltPresence) > 0 { 41 q.Set(apc.QparamFltPresence, strconv.Itoa(fltPresence[0])) 42 } 43 return dolr(bp, bckFrom, apc.ActCopyObjects, msg, q) 44 } 45 46 func ETLMultiObj(bp BaseParams, bckFrom cmn.Bck, msg *cmn.TCObjsMsg, fltPresence ...int) (xid string, err error) { 47 bp.Method = http.MethodPost 48 q := bckFrom.NewQuery() 49 if len(fltPresence) > 0 { 50 q.Set(apc.QparamFltPresence, strconv.Itoa(fltPresence[0])) 51 } 52 return dolr(bp, bckFrom, apc.ActETLObjects, msg, q) 53 } 54 55 func DeleteMultiObj(bp BaseParams, bck cmn.Bck, objNames []string, template string) (string, error) { 56 bp.Method = http.MethodDelete 57 q := bck.NewQuery() 58 msg := apc.ListRange{ObjNames: objNames, Template: template} 59 return dolr(bp, bck, apc.ActDeleteObjects, msg, q) 60 } 61 62 func EvictMultiObj(bp BaseParams, bck cmn.Bck, objNames []string, template string) (string, error) { 63 bp.Method = http.MethodDelete 64 q := bck.NewQuery() 65 msg := apc.ListRange{ObjNames: objNames, Template: template} 66 return dolr(bp, bck, apc.ActEvictObjects, msg, q) 67 } 68 69 func Prefetch(bp BaseParams, bck cmn.Bck, msg apc.PrefetchMsg) (string, error) { 70 bp.Method = http.MethodPost 71 q := bck.NewQuery() 72 return dolr(bp, bck, apc.ActPrefetchObjects, msg, q) 73 } 74 75 // multi-object list-range (delete, prefetch, evict, archive, copy, and etl) 76 func dolr(bp BaseParams, bck cmn.Bck, action string, msg any, q url.Values) (xid string, err error) { 77 reqParams := AllocRp() 78 { 79 reqParams.BaseParams = bp 80 reqParams.Path = apc.URLPathBuckets.Join(bck.Name) 81 reqParams.Body = cos.MustMarshal(apc.ActMsg{Action: action, Value: msg}) 82 reqParams.Header = http.Header{cos.HdrContentType: []string{cos.ContentJSON}} 83 reqParams.Query = q 84 } 85 _, err = reqParams.doReqStr(&xid) 86 FreeRp(reqParams) 87 return xid, err 88 }