This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
quality_of_service_provider.go
60 lines (51 loc) · 2.17 KB
/
quality_of_service_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package runtime
import (
"fmt"
"github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flytestdlib/config"
"github.com/golang/protobuf/ptypes"
)
const qualityOfServiceKey = "qualityOfService"
var qualityOfServiceConfig = config.MustRegisterSection(qualityOfServiceKey, &interfaces.QualityOfServiceConfig{})
// Implementation of an interfaces.QualityOfServiceConfiguration
type QualityOfServiceConfigProvider struct {
}
func (p *QualityOfServiceConfigProvider) GetTierExecutionValues() map[core.QualityOfService_Tier]core.QualityOfServiceSpec {
tierExecutionValues := make(map[core.QualityOfService_Tier]core.QualityOfServiceSpec)
if qualityOfServiceConfig != nil {
values := qualityOfServiceConfig.GetConfig().(*interfaces.QualityOfServiceConfig).TierExecutionValues
for tierName, spec := range values {
tierExecutionValues[core.QualityOfService_Tier(core.QualityOfService_Tier_value[tierName])] =
core.QualityOfServiceSpec{
QueueingBudget: ptypes.DurationProto(spec.QueueingBudget.Duration),
}
}
}
return tierExecutionValues
}
func (p *QualityOfServiceConfigProvider) GetDefaultTiers() map[interfaces.DomainName]core.QualityOfService_Tier {
defaultTiers := make(map[interfaces.DomainName]core.QualityOfService_Tier)
if qualityOfServiceConfig != nil {
tiers := qualityOfServiceConfig.GetConfig().(*interfaces.QualityOfServiceConfig).DefaultTiers
for domainName, tierName := range tiers {
defaultTiers[domainName] = core.QualityOfService_Tier(core.QualityOfService_Tier_value[tierName])
}
}
return defaultTiers
}
func validateConfigValues() {
if qualityOfServiceConfig != nil {
values := qualityOfServiceConfig.GetConfig().(*interfaces.QualityOfServiceConfig).TierExecutionValues
for tierName, spec := range values {
_, err := ptypes.Duration(ptypes.DurationProto(spec.QueueingBudget.Duration))
if err != nil {
panic(fmt.Sprintf("Invalid duration [%+v] specified for %s", spec.QueueingBudget.Duration, tierName))
}
}
}
}
func NewQualityOfServiceConfigProvider() interfaces.QualityOfServiceConfiguration {
validateConfigValues()
return &QualityOfServiceConfigProvider{}
}