Compare commits

...

1 commit

Author SHA1 Message Date
8eddc99868 [#527] Add support for select-filter expressions in policy playground
All checks were successful
Build / Build Components (1.20) (pull_request) Successful in 3m53s
Build / Build Components (1.19) (pull_request) Successful in 4m1s
ci/woodpecker/pr/pre-commit Pipeline was successful
Tests and linters / Tests (1.20) (pull_request) Successful in 3m37s
Tests and linters / Lint (pull_request) Successful in 14m46s
Tests and linters / Staticcheck (pull_request) Successful in 2m58s
Tests and linters / Tests with -race (pull_request) Successful in 8m19s
Tests and linters / Tests (1.19) (pull_request) Successful in 23m31s
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
2023-07-18 15:01:37 +03:00
3 changed files with 28 additions and 11 deletions

View file

@ -82,15 +82,32 @@ func (repl *policyPlaygroundREPL) handleRemove(args []string) error {
}
func (repl *policyPlaygroundREPL) handleEval(args []string) error {
policyStr := strings.Join(args, " ")
placementPolicy, err := parseContainerPolicy(repl.cmd, policyStr)
if err != nil {
return fmt.Errorf("parsing placement policy: %v", err)
}
policyStr := strings.TrimSpace(strings.Join(args, " "))
var nodes [][]netmap.NodeInfo
nm := repl.netMap()
nodes, err := nm.ContainerNodes(*placementPolicy, nil)
if err != nil {
return fmt.Errorf("building container nodes: %v", err)
if strings.HasPrefix(policyStr, "CBF") || strings.HasPrefix(policyStr, "SELECT") || strings.HasPrefix(policyStr, "FILTER") {
// Assume that the input is a partial SELECT-FILTER expression.
// Full inline policies always start with UNIQUE or REP keywords,
// or different prefixes when it's the case of an external file.
sfExpr, err := netmap.DecodeSelectFilterString(policyStr)
if err != nil {
return fmt.Errorf("parsing select-filter expression: %v", err)
}
nodes, err = nm.SelectFilterNodes(sfExpr)
if err != nil {
return fmt.Errorf("building select-filter nodes: %v", err)
}
} else {
// Assume that the input is a full policy or input file otherwise.
placementPolicy, err := parseContainerPolicy(repl.cmd, policyStr)
if err != nil {
return fmt.Errorf("parsing placement policy: %v", err)
}
nodes, err = nm.ContainerNodes(*placementPolicy, nil)
if err != nil {
return fmt.Errorf("building container nodes: %v", err)
}
}
for i, ns := range nodes {
var ids []string

2
go.mod
View file

@ -6,7 +6,7 @@ require (
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.15.1-0.20230704092742-285516a94ebe
git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230627134746-36f3d39c406a
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230711142135-998fe1a7ab31
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230717102948-b91f9d8c7910
git.frostfs.info/TrueCloudLab/hrw v1.2.1
git.frostfs.info/TrueCloudLab/tzhash v1.8.0
github.com/cheggaaa/pb v1.0.29

4
go.sum
View file

@ -44,8 +44,8 @@ git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSV
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0/go.mod h1:RUIKZATQLJ+TaYQa60X2fTDwfuhMfm8Ar60bQ5fr+vU=
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6 h1:aGQ6QaAnTerQ5Dq5b2/f9DUQtSqPkZZ/bkMx/HKuLCo=
git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6/go.mod h1:W8Nn08/l6aQ7UlIbpF7FsQou7TVpcRD1ZT1KG4TrFhE=
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230711142135-998fe1a7ab31 h1:PSHVtyD3vw2NTbdWBUz0Wql1WH42nSCP+4j6PmIgZ8Y=
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230711142135-998fe1a7ab31/go.mod h1:MlLlhZb4qbLhUScDngfujUZKhs0/2YKW9D8LTY3BApY=
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230717102948-b91f9d8c7910 h1:UmTLvK7/G8KbOOBr+u577fO7C1JNDEOnG0CB5kRBT3Y=
git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20230717102948-b91f9d8c7910/go.mod h1:MlLlhZb4qbLhUScDngfujUZKhs0/2YKW9D8LTY3BApY=
git.frostfs.info/TrueCloudLab/hrw v1.2.1 h1:ccBRK21rFvY5R1WotI6LNoPlizk7qSvdfD8lNIRudVc=
git.frostfs.info/TrueCloudLab/hrw v1.2.1/go.mod h1:C1Ygde2n843yTZEQ0FP69jYiuaYV0kriLvP4zm8JuvM=
git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 h1:M2KR3iBj7WpY3hP10IevfIB9MURr4O9mwVfJ+SjT3HA=