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 maxEnvironments := a.cfg.Environments
var lcId *int var lcId *int
for _, alc := range alcs { 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 maxEnvironments = alc.Environments
lcId = &alc.Id lcId = &alc.Id
} }
@ -570,9 +570,6 @@ func (a *Agent) bandwidthClassPoints(bwc store.BandwidthClass) int {
if bwc.GetLimitAction() == store.LimitLimitAction { if bwc.GetLimitAction() == store.LimitLimitAction {
points += 2 points += 2
} }
if bwc.GetShareMode() != "" {
points += 5
}
if bwc.GetBackendMode() != "" { if bwc.GetBackendMode() != "" {
points += 10 points += 10
} }

View File

@ -3,8 +3,15 @@ package limits
import ( import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/openziti/zrok/controller/store" "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 { type AccountAction interface {
HandleAccount(a *store.Account, rxBytes, txBytes int64, limit store.BandwidthClass, trx *sqlx.Tx) error 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" "github.com/pkg/errors"
) )
type ResourceCountClass interface {
IsGlobal() bool
GetLimitClassId() int
GetEnvironments() int
GetShares() int
GetReservedShares() int
GetUniqueNames() int
String()
}
type BandwidthClass interface { type BandwidthClass interface {
IsGlobal() bool IsGlobal() bool
GetLimitClassId() int GetLimitClassId() int
GetShareMode() sdk.ShareMode
GetBackendMode() sdk.BackendMode GetBackendMode() sdk.BackendMode
GetPeriodMinutes() int GetPeriodMinutes() int
GetRxBytes() int64 GetRxBytes() int64
@ -22,8 +31,8 @@ type BandwidthClass interface {
type LimitClass struct { type LimitClass struct {
Model Model
ShareMode sdk.ShareMode ShareMode *sdk.ShareMode
BackendMode sdk.BackendMode BackendMode *sdk.BackendMode
Environments int Environments int
Shares int Shares int
ReservedShares int ReservedShares int
@ -44,11 +53,17 @@ func (lc LimitClass) GetLimitClassId() int {
} }
func (lc LimitClass) GetShareMode() sdk.ShareMode { func (lc LimitClass) GetShareMode() sdk.ShareMode {
return lc.ShareMode if lc.ShareMode == nil {
return ""
}
return *lc.ShareMode
} }
func (lc LimitClass) GetBackendMode() sdk.BackendMode { func (lc LimitClass) GetBackendMode() sdk.BackendMode {
return lc.BackendMode if lc.BackendMode == nil {
return ""
}
return *lc.BackendMode
} }
func (lc LimitClass) GetPeriodMinutes() int { func (lc LimitClass) GetPeriodMinutes() int {