From 4680087711f4fd8a42669a8e8e7eef53b5b8323d Mon Sep 17 00:00:00 2001 From: Alejandro Lopez Date: Mon, 17 Jul 2023 13:59:37 +0300 Subject: [PATCH] [#527] Add support for select-filter expressions in policy playground Signed-off-by: Alejandro Lopez --- .../modules/container/policy_playground.go | 33 +++++++++++++----- go.mod | 2 +- go.sum | Bin 99007 -> 99007 bytes 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/cmd/frostfs-cli/modules/container/policy_playground.go b/cmd/frostfs-cli/modules/container/policy_playground.go index 65255f9c2..97e30a3cd 100644 --- a/cmd/frostfs-cli/modules/container/policy_playground.go +++ b/cmd/frostfs-cli/modules/container/policy_playground.go @@ -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 diff --git a/go.mod b/go.mod index e2735b223..7378621c4 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ddbc776336c5b9c02464f6cba41387ea84b1f6d2..2ea573e1e11904d54c28c67a2c07ce1d0b5ffb23 100644 GIT binary patch delta 115 zcmdnr%C^6iZG)wtv$>&xk)?@+Zjz;8nq`Vbvbm+9fkK9%RcLOAPnoy5zPp8YlE1%G zk#?!6xp|tuxwD~{pNp%1p1XmwlWBI4Q;2co29d18{Wp+bhCRY0&uSV^Ueaap;MUr16) zxKn7AL3m+~VYr8hQC_fffVN4NSwOC5dXz=v