formalize class selection to facilitate highest cascade when running limit actions (#606)

This commit is contained in:
Michael Quigley 2024-06-05 12:56:27 -04:00
parent 0f32c5e8a3
commit e2a55393a5
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 28 additions and 9 deletions

View File

@ -64,7 +64,7 @@ func (a *Agent) CanCreateEnvironment(acctId int, trx *sqlx.Tx) (bool, error) {
maxEnvironments := a.cfg.Environments
var lcId *int
for _, alc := range alcs {
if alc.ShareMode == "" && alc.BackendMode == "" && alc.Environments > maxEnvironments {
if alc.ShareMode == nil && alc.BackendMode == nil && alc.Environments > maxEnvironments {
maxEnvironments = alc.Environments
lcId = &alc.Id
}
@ -570,9 +570,6 @@ func (a *Agent) bandwidthClassPoints(bwc store.BandwidthClass) int {
if bwc.GetLimitAction() == store.LimitLimitAction {
points += 2
}
if bwc.GetShareMode() != "" {
points += 5
}
if bwc.GetBackendMode() != "" {
points += 10
}

View File

@ -3,8 +3,15 @@ package limits
import (
"github.com/jmoiron/sqlx"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/sdk/golang/sdk"
)
type UserLimits struct {
resource store.ResourceCountClass
bandwidth store.BandwidthClass
scopes map[sdk.BackendMode]store.BandwidthClass
}
type AccountAction interface {
HandleAccount(a *store.Account, rxBytes, txBytes int64, limit store.BandwidthClass, trx *sqlx.Tx) error
}

View File

@ -7,10 +7,19 @@ import (
"github.com/pkg/errors"
)
type ResourceCountClass interface {
IsGlobal() bool
GetLimitClassId() int
GetEnvironments() int
GetShares() int
GetReservedShares() int
GetUniqueNames() int
String()
}
type BandwidthClass interface {
IsGlobal() bool
GetLimitClassId() int
GetShareMode() sdk.ShareMode
GetBackendMode() sdk.BackendMode
GetPeriodMinutes() int
GetRxBytes() int64
@ -22,8 +31,8 @@ type BandwidthClass interface {
type LimitClass struct {
Model
ShareMode sdk.ShareMode
BackendMode sdk.BackendMode
ShareMode *sdk.ShareMode
BackendMode *sdk.BackendMode
Environments int
Shares int
ReservedShares int
@ -44,11 +53,17 @@ func (lc LimitClass) GetLimitClassId() int {
}
func (lc LimitClass) GetShareMode() sdk.ShareMode {
return lc.ShareMode
if lc.ShareMode == nil {
return ""
}
return *lc.ShareMode
}
func (lc LimitClass) GetBackendMode() sdk.BackendMode {
return lc.BackendMode
if lc.BackendMode == nil {
return ""
}
return *lc.BackendMode
}
func (lc LimitClass) GetPeriodMinutes() int {