Skip to content

Commit 6c2ac67

Browse files
committed
add strategy method: FILLGLOBAL
1 parent cf31615 commit 6c2ac67

File tree

4 files changed

+49
-20
lines changed

4 files changed

+49
-20
lines changed

rpc/gen/core.pb.go

+23-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/gen/core.proto

+1
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ message DeployOptions {
408408
FILL = 1;
409409
EACH = 2;
410410
GLOBAL = 3;
411+
FILLGLOBAL = 4;
411412
DUMMY = 99;
412413
}
413414
string name = 1;

strategy/fill_global.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package strategy
2+
3+
import (
4+
"github.com/projecteru2/core/log"
5+
"github.com/projecteru2/core/types"
6+
)
7+
8+
func FillGlobalPlan(strategyInfo []Info, need, total, limit int, resourceType types.ResourceType) (map[string]int, error) {
9+
originStrategyInfo := make([]Info, len(strategyInfo))
10+
copy(originStrategyInfo, strategyInfo)
11+
12+
deployMap, err := FillPlan(strategyInfo, need, total, limit, resourceType)
13+
if err == nil {
14+
return deployMap, nil
15+
}
16+
log.Info("[FillGlobalPlan] fill plan failed, try global fill: %+v", err)
17+
return GlobalPlan(originStrategyInfo, need, total, limit, resourceType)
18+
}

strategy/strategy.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ const (
1818
Each = "EACH"
1919
// Global .
2020
Global = "GLOBAL"
21+
// Fill + Global
22+
FillGlobal = "FILLGLOBAL"
2123
// Dummy for calculate capacity
2224
Dummy = "DUMMY"
2325
)
2426

2527
var Plans = map[string]startegyFunc{
26-
Auto: CommunismPlan,
27-
Fill: FillPlan,
28-
Each: AveragePlan,
29-
Global: GlobalPlan,
28+
Auto: CommunismPlan,
29+
Fill: FillPlan,
30+
Each: AveragePlan,
31+
Global: GlobalPlan,
32+
FillGlobal: FillGlobalPlan,
3033
}
3134

3235
type startegyFunc = func(_ []Info, need, total, limit int, _ types.ResourceType) (map[string]int, error)

0 commit comments

Comments
 (0)