Skip to content

Commit c4ee603

Browse files
committed
feat: bucket inventory (part one); refactor 'api' package
* add ActCreateInventory control action (stub) * create system's ais://.sys-inventory on very first (inventory) request ------------- * refactor api/(bucket, multiobj) to reduce code - consolidate bucket-scoped requests via doBckAct() Signed-off-by: Alex Aizman <alex.aizman@gmail.com>
1 parent 33eff79 commit c4ee603

7 files changed

Lines changed: 147 additions & 164 deletions

File tree

‎ais/proxy.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,18 @@ func (p *proxy) _bckpost(w http.ResponseWriter, r *http.Request, msg *apc.ActMsg
16141614
p.writeErr(w, r, err)
16151615
return
16161616
}
1617+
case apc.ActCreateInventory:
1618+
if err := p._sysInvBck(w, r, msg); err != nil {
1619+
return
1620+
}
1621+
cimsg := &apc.CreateInvMsg{}
1622+
if err := cos.MorphMarshal(msg.Value, cimsg); err != nil {
1623+
p.writeErrf(w, r, cmn.FmtErrMorphUnmarshal, p.si, msg.Action, msg.Value, err)
1624+
return
1625+
}
1626+
nlog.Errorf("%s: %+v", p, cimsg) // DEBUG
1627+
p.writeErr(w, r, cmn.NewErrNotImpl("create", "bucket inventory"), http.StatusNotImplemented)
1628+
return
16171629
default:
16181630
p.writeErrAct(w, r, msg.Action)
16191631
return
@@ -1623,6 +1635,20 @@ func (p *proxy) _bckpost(w http.ResponseWriter, r *http.Request, msg *apc.ActMsg
16231635
writeXid(w, xid)
16241636
}
16251637

1638+
func (p *proxy) _sysInvBck(w http.ResponseWriter, r *http.Request, msg *apc.ActMsg) error {
1639+
sys := &meta.Bck{Provider: apc.AIS, Name: cmn.SysInventoryName}
1640+
1641+
bctx := allocBctx()
1642+
bctx.p, bctx.w, bctx.r = p, w, r
1643+
bctx.bck = sys
1644+
bctx.msg = msg
1645+
bctx.createAIS = true
1646+
bctx.perms = apc.AceAdmin // (readability; will check admin access for reserved name)
1647+
_, err := bctx.initAndTry()
1648+
freeBctx(bctx)
1649+
return err
1650+
}
1651+
16261652
// init existing or create remote
16271653
// not calling `initAndTry` - delegating ais:from// props cloning to the separate method
16281654
func (p *proxy) initBckTo(w http.ResponseWriter, r *http.Request, query url.Values, bckTo *meta.Bck) (*meta.Bck, int, error) {

‎ais/prxauth.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func (p *proxy) access(ctx context.Context, hdr http.Header, bck *meta.Bck, ace
401401

402402
// If auth is NOT enabled, only check bucket properties
403403
if !cmn.Rom.AuthEnabled() {
404-
if bck == nil {
404+
if bck == nil || bck.Props == nil {
405405
return nil
406406
}
407407
// With Auth disabled, always allow read-only access, PATCH, and ACL

‎api/apc/actmsg.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Package apc: API constant and control messages
22
/*
3-
* Copyright (c) 2018-2025, NVIDIA CORPORATION. All rights reserved.
3+
* Copyright (c) 2018-2026, NVIDIA CORPORATION. All rights reserved.
44
*/
55
package apc
66

@@ -90,7 +90,7 @@ const (
9090
ActEnableBackend = "enable-bend"
9191
ActDisableBackend = "disable-bend"
9292

93-
// Node maintenance & cluster membership (see also ActRmNodeUnsafe below)
93+
// node maintenance & cluster membership (see also ActRmNodeUnsafe below)
9494
ActStartMaintenance = "start-maintenance" // put into maintenance state
9595
ActStopMaintenance = "stop-maintenance" // cancel maintenance state
9696
ActShutdownNode = "shutdown-node" // shutdown node
@@ -112,8 +112,11 @@ const (
112112
// advanced usage
113113
ActCheckLock = "check-lock"
114114

115-
// Moss
115+
// api/ml.go; x-moss
116116
ActGetBatch = "get-batch"
117+
118+
// bucket inventory
119+
ActCreateInventory = "create-inventory"
117120
)
118121

119122
// internal use

‎api/apc/lsmsg.go‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,26 @@ var (
162162
GetPropsVersion, GetPropsCached, GetPropsStatus, GetPropsCopies, GetPropsEC, GetPropsCustom, GetPropsLocation}
163163
)
164164

165-
// swagger:model
166-
type LsoMsg struct {
167-
Header http.Header `json:"hdr,omitempty"` // (for pointers, see `ListArgs` in api/ls.go)
168-
UUID string `json:"uuid"` // ID to identify a single multi-page request
169-
Props string `json:"props"` // comma-delimited, e.g. "checksum,size,custom" (see GetProps* enum)
170-
TimeFormat string `json:"time_format,omitempty"` // RFC822 is the default
171-
Prefix string `json:"prefix"` // return obj names starting with prefix (TODO: e.g. "A.tar/tutorials/")
172-
StartAfter string `json:"start_after,omitempty"` // start listing after (AIS buckets only)
173-
ContinuationToken string `json:"continuation_token"` // => LsoResult.ContinuationToken => LsoMsg.ContinuationToken
174-
SID string `json:"target"` // selected target to solely execute backend.list-objects
175-
Flags uint64 `json:"flags,string"` // enum {LsCached, ...} - "LsoMsg flags" above
176-
PageSize int64 `json:"pagesize"` // max entries returned by list objects call
177-
}
165+
type (
166+
// swagger:model
167+
LsoMsg struct {
168+
Header http.Header `json:"hdr,omitempty"` // (for pointers, see `ListArgs` in api/ls.go)
169+
UUID string `json:"uuid"` // ID to identify a single multi-page request
170+
Props string `json:"props"` // comma-delimited, e.g. "checksum,size,custom" (see GetProps* enum)
171+
TimeFormat string `json:"time_format,omitempty"` // RFC822 is the default
172+
Prefix string `json:"prefix"` // return names starting with prefix (including arch. files (e.g. "A.tar/tutorials/"))
173+
StartAfter string `json:"start_after,omitempty"` // start listing after (AIS buckets only)
174+
ContinuationToken string `json:"continuation_token"` // => LsoResult.ContinuationToken => LsoMsg.ContinuationToken
175+
SID string `json:"target"` // selected target to solely execute backend.list-objects
176+
Flags uint64 `json:"flags,string"` // enum {LsCached, ...} - "LsoMsg flags" above
177+
PageSize int64 `json:"pagesize"` // max entries returned by list objects call
178+
}
179+
180+
CreateInvMsg struct {
181+
Name string `json:"name,omitempty"` // inventory name (optional; must be unique for a given bucket)
182+
LsoMsg
183+
}
184+
)
178185

179186
////////////
180187
// LsoMsg //

0 commit comments

Comments
 (0)