mirror of
https://github.com/openziti/zrok.git
synced 2024-11-25 17:43:53 +01:00
formalize class selection to facilitate highest cascade when running limit actions (#606)
This commit is contained in:
parent
0f32c5e8a3
commit
e2a55393a5
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user