Merge pull request #8661 from zexi/hotfix/scheduler-forecast-with-candidates

scheduler: forecast api with candidates result
This commit is contained in:
Zexi Li
2020-11-05 00:39:17 +08:00
committed by GitHub
5 changed files with 22 additions and 10 deletions
+8 -4
View File
@@ -36,23 +36,27 @@ var (
ErrorEmptyDesc = errors.New("Empty description")
)
// ParseSchedtagConfig desc format: <schedtagName>:<strategy>
// ParseSchedtagConfig desc format: <schedtagName>:<strategy>:<resource_type>
func ParseSchedtagConfig(desc string) (*compute.SchedtagConfig, error) {
if len(desc) == 0 {
return nil, ErrorEmptyDesc
}
parts := strings.Split(desc, ":")
if len(parts) != 2 {
if len(parts) < 2 {
return nil, fmt.Errorf("Invalid desc: %s", desc)
}
strategy := parts[1]
if !utils.IsInStringArray(strategy, compute.STRATEGY_LIST) {
return nil, fmt.Errorf("Invalid strategy: %s", strategy)
}
return &compute.SchedtagConfig{
conf := &compute.SchedtagConfig{
Id: parts[0],
Strategy: parts[1],
}, nil
}
if len(parts) == 3 {
conf.ResourceType = parts[2]
}
return conf, nil
}
// ParseResourceSchedtagConfig desc format: <idx>:<schedtagName>:<strategy>
+6
View File
@@ -45,6 +45,12 @@ func TestParseSchedtagConfig(t *testing.T) {
want: &compute.SchedtagConfig{Id: "ssd", Strategy: "require"},
wantErr: false,
},
{
name: "with resource type",
args: args{"ssd:require:zones"},
want: &compute.SchedtagConfig{Id: "ssd", Strategy: "require", ResourceType: "zones"},
wantErr: false,
},
{
name: "invalid strategy",
args: args{"ssd:require2"},