forked from TrueCloudLab/frostfs-node
[#527] Add support for select-filter expressions in policy playground
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
parent
f0355a453e
commit
4680087711
3 changed files with 28 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue