[#xx] Add support for select-filter expressions in policy playground #527

Merged
fyrchik merged 1 commit from ale64bit/frostfs-node:feature/eval-select-filter-expr into master 2023-07-18 13:16:00 +00:00
3 changed files with 26 additions and 9 deletions

View file

@ -82,16 +82,33 @@ func (repl *policyPlaygroundREPL) handleRemove(args []string) error {
}
func (repl *policyPlaygroundREPL) handleEval(args []string) error {
policyStr := strings.Join(args, " ")
policyStr := strings.TrimSpace(strings.Join(args, " "))
var nodes [][]netmap.NodeInfo
nm := repl.netMap()
if strings.HasPrefix(policyStr, "CBF") || strings.HasPrefix(policyStr, "SELECT") || strings.HasPrefix(policyStr, "FILTER") {
fyrchik marked this conversation as resolved Outdated

Could you mention why it is valid in comments? (any policy starts with REP)

Could you mention why it is valid in comments? (any policy starts with `REP`)

done

done
// 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)
}
nm := repl.netMap()
nodes, err := nm.ContainerNodes(*placementPolicy, nil)
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
for _, node := range ns {

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

BIN
go.sum

Binary file not shown.