forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_release_mode.go
More file actions
47 lines (40 loc) · 1.6 KB
/
config_release_mode.go
File metadata and controls
47 lines (40 loc) · 1.6 KB
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
package evergreen
import (
"context"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson"
)
// ReleaseModeConfig holds settings for release mode.
type ReleaseModeConfig struct {
DistroMaxHostsFactor float64 `bson:"distro_max_hosts_factor" json:"distro_max_hosts_factor" yaml:"distro_max_hosts_factor"`
TargetTimeSecondsOverride int `bson:"target_time_seconds_override" json:"target_time_seconds_override" yaml:"target_time_seconds_override"`
IdleTimeSecondsOverride int `bson:"idle_time_seconds_override" json:"idle_time_seconds_override" yaml:"idle_time_seconds_override"`
}
func (c *ReleaseModeConfig) SectionId() string { return "release_mode" }
func (c *ReleaseModeConfig) Get(ctx context.Context) error {
return getConfigSection(ctx, c)
}
func (c *ReleaseModeConfig) Set(ctx context.Context) error {
return errors.Wrapf(setConfigSection(ctx, c.SectionId(), bson.M{
"$set": bson.M{
"distro_max_hosts_factor": c.DistroMaxHostsFactor,
"target_time_seconds_override": c.TargetTimeSecondsOverride,
"idle_time_seconds_override": c.IdleTimeSecondsOverride,
}}), "updating config section '%s'", c.SectionId(),
)
}
func (c *ReleaseModeConfig) ValidateAndDefault() error {
if c.TargetTimeSecondsOverride < 0 {
return errors.Errorf("target time seconds override cannot be negative")
}
if c.IdleTimeSecondsOverride < 0 {
return errors.Errorf("idle time seconds override cannot be negative")
}
if c.DistroMaxHostsFactor < 0 {
return errors.Errorf("distro max hosts factor cannot be negative")
}
if c.DistroMaxHostsFactor == 0 {
c.DistroMaxHostsFactor = 1
}
return nil
}