[#xx] cli: Add policy-playground command #416

Merged
fyrchik merged 1 commit from ale64bit/frostfs-node:feature/policy-playground into master 2023-06-02 09:23:42 +00:00
Member

Not sure if we actually want this, but just in case.
A very simple playground to experiment with placement policies and dry run their effect before actually creating containers.

It can be used as a standalone tool without any deployment:

$ frostfs-cli container policy-playground
> ls
> add 01 Loc:RU Storage:SSD City:Omsk
> add 02 Loc:EU City:Milan Storage:SSD
> add 03 Storage:SomePieceOfPaper Loc:US
> add 04 Storage:SSD Loc:RU City:SPb
> add 05 Storage:SSD Loc:RU City:SPb Foo:Bar
> ls
	 1: id=05 attrs={Storage:SSD Loc:RU City:SPb Foo:Bar}
	 2: id=01 attrs={Loc:RU Storage:SSD City:Omsk}
	 3: id=02 attrs={Loc:EU City:Milan Storage:SSD}
	 4: id=03 attrs={Storage:SomePieceOfPaper Loc:US}
	 5: id=04 attrs={Storage:SSD Loc:RU City:SPb}
> eval REP 1
	 1: [05 02 03]
> eval REP 1 REP 1
	 1: [05 02 03]
	 2: [05 02 03]
> eval REP 1 REP 1 CBF 1
	 1: [05]
	 2: [05]
> eval REP 2 IN X CBF 2 SELECT 2 FROM * AS X
	 1: [05 03 02 01]
> eval REP 1 IN SPB SELECT 1 IN City FROM SPBSSD AS SPB FILTER City EQ SPb AND Storage EQ SSD AS SPBSSD
	 1: [04 05]
> 

or pulling the initial netmap data from an existing deployment (e.g. dev-env):

$ frostfs-cli container policy-playground --wallet /path/to/frostfs-dev-env/wallets/wallet.json --rpc-endpoint s01.frostfs.devenv:8080
Enter password > 
> ls
	 1: id=022bb4041c50d607ff871dec7e4cd7778388e0ea6849d84ccbd9aa8f32e16a8131 attrs={Continent:Europe Country:Russia CountryCode:RU Location:Moskva Price:22 SubDiv:Moskva SubDivCode:MOW UN-LOCODE:RU MOW User-Agent:FrostFS/0.34}
	 2: id=02ac920cd7df0b61b289072e6b946e2da4e1a31b9ab1c621bb475e30fa4ab102c3 attrs={Continent:Europe Country:Sweden CountryCode:SE Location:Stockholm Price:11 SubDiv:Stockholms l�n SubDivCode:AB UN-LOCODE:SE STO User-Agent:FrostFS/0.34}
	 3: id=038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35 attrs={Continent:Europe Country:Finland CountryCode:FI Location:Helsinki (Helsingfors) Price:44 SubDiv:Uusimaa SubDivCode:18 UN-LOCODE:FI HEL User-Agent:FrostFS/0.34}
	 4: id=03ff65b6ae79134a4dce9d0d39d3851e9bab4ee97abf86e81e1c5bbc50cd2826ae attrs={Continent:Europe Country:Russia CountryCode:RU Location:Saint Petersburg (ex Leningrad) Price:33 SubDiv:Sankt-Peterburg SubDivCode:SPE UN-LOCODE:RU LED User-Agent:FrostFS/0.34}
> remove 022bb4041c50d607ff871dec7e4cd7778388e0ea6849d84ccbd9aa8f32e16a8131
> ls
	 1: id=03ff65b6ae79134a4dce9d0d39d3851e9bab4ee97abf86e81e1c5bbc50cd2826ae attrs={Continent:Europe Country:Russia CountryCode:RU Location:Saint Petersburg (ex Leningrad) Price:33 SubDiv:Sankt-Peterburg SubDivCode:SPE UN-LOCODE:RU LED User-Agent:FrostFS/0.34}
	 2: id=02ac920cd7df0b61b289072e6b946e2da4e1a31b9ab1c621bb475e30fa4ab102c3 attrs={Continent:Europe Country:Sweden CountryCode:SE Location:Stockholm Price:11 SubDiv:Stockholms l�n SubDivCode:AB UN-LOCODE:SE STO User-Agent:FrostFS/0.34}
	 3: id=038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35 attrs={Continent:Europe Country:Finland CountryCode:FI Location:Helsinki (Helsingfors) Price:44 SubDiv:Uusimaa SubDivCode:18 UN-LOCODE:FI HEL User-Agent:FrostFS/0.34}
> eval REP 1 
	 1: [03ff65b6ae79134a4dce9d0d39d3851e9bab4ee97abf86e81e1c5bbc50cd2826ae 02ac920cd7df0b61b289072e6b946e2da4e1a31b9ab1c621bb475e30fa4ab102c3 038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35]

Related to #227
Signed-off-by: Alejandro Lopez a.lopez@yadro.com

Not sure if we actually want this, but just in case. A very simple playground to experiment with placement policies and dry run their effect before actually creating containers. It can be used as a standalone tool without any deployment: ```shell $ frostfs-cli container policy-playground > ls > add 01 Loc:RU Storage:SSD City:Omsk > add 02 Loc:EU City:Milan Storage:SSD > add 03 Storage:SomePieceOfPaper Loc:US > add 04 Storage:SSD Loc:RU City:SPb > add 05 Storage:SSD Loc:RU City:SPb Foo:Bar > ls 1: id=05 attrs={Storage:SSD Loc:RU City:SPb Foo:Bar} 2: id=01 attrs={Loc:RU Storage:SSD City:Omsk} 3: id=02 attrs={Loc:EU City:Milan Storage:SSD} 4: id=03 attrs={Storage:SomePieceOfPaper Loc:US} 5: id=04 attrs={Storage:SSD Loc:RU City:SPb} > eval REP 1 1: [05 02 03] > eval REP 1 REP 1 1: [05 02 03] 2: [05 02 03] > eval REP 1 REP 1 CBF 1 1: [05] 2: [05] > eval REP 2 IN X CBF 2 SELECT 2 FROM * AS X 1: [05 03 02 01] > eval REP 1 IN SPB SELECT 1 IN City FROM SPBSSD AS SPB FILTER City EQ SPb AND Storage EQ SSD AS SPBSSD 1: [04 05] > ``` or pulling the initial netmap data from an existing deployment (e.g. dev-env): ```shell $ frostfs-cli container policy-playground --wallet /path/to/frostfs-dev-env/wallets/wallet.json --rpc-endpoint s01.frostfs.devenv:8080 Enter password > > ls 1: id=022bb4041c50d607ff871dec7e4cd7778388e0ea6849d84ccbd9aa8f32e16a8131 attrs={Continent:Europe Country:Russia CountryCode:RU Location:Moskva Price:22 SubDiv:Moskva SubDivCode:MOW UN-LOCODE:RU MOW User-Agent:FrostFS/0.34} 2: id=02ac920cd7df0b61b289072e6b946e2da4e1a31b9ab1c621bb475e30fa4ab102c3 attrs={Continent:Europe Country:Sweden CountryCode:SE Location:Stockholm Price:11 SubDiv:Stockholms l�n SubDivCode:AB UN-LOCODE:SE STO User-Agent:FrostFS/0.34} 3: id=038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35 attrs={Continent:Europe Country:Finland CountryCode:FI Location:Helsinki (Helsingfors) Price:44 SubDiv:Uusimaa SubDivCode:18 UN-LOCODE:FI HEL User-Agent:FrostFS/0.34} 4: id=03ff65b6ae79134a4dce9d0d39d3851e9bab4ee97abf86e81e1c5bbc50cd2826ae attrs={Continent:Europe Country:Russia CountryCode:RU Location:Saint Petersburg (ex Leningrad) Price:33 SubDiv:Sankt-Peterburg SubDivCode:SPE UN-LOCODE:RU LED User-Agent:FrostFS/0.34} > remove 022bb4041c50d607ff871dec7e4cd7778388e0ea6849d84ccbd9aa8f32e16a8131 > ls 1: id=03ff65b6ae79134a4dce9d0d39d3851e9bab4ee97abf86e81e1c5bbc50cd2826ae attrs={Continent:Europe Country:Russia CountryCode:RU Location:Saint Petersburg (ex Leningrad) Price:33 SubDiv:Sankt-Peterburg SubDivCode:SPE UN-LOCODE:RU LED User-Agent:FrostFS/0.34} 2: id=02ac920cd7df0b61b289072e6b946e2da4e1a31b9ab1c621bb475e30fa4ab102c3 attrs={Continent:Europe Country:Sweden CountryCode:SE Location:Stockholm Price:11 SubDiv:Stockholms l�n SubDivCode:AB UN-LOCODE:SE STO User-Agent:FrostFS/0.34} 3: id=038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35 attrs={Continent:Europe Country:Finland CountryCode:FI Location:Helsinki (Helsingfors) Price:44 SubDiv:Uusimaa SubDivCode:18 UN-LOCODE:FI HEL User-Agent:FrostFS/0.34} > eval REP 1 1: [03ff65b6ae79134a4dce9d0d39d3851e9bab4ee97abf86e81e1c5bbc50cd2826ae 02ac920cd7df0b61b289072e6b946e2da4e1a31b9ab1c621bb475e30fa4ab102c3 038c862959e56b43e20f79187c4fe9e0bc7c8c66c1603e6cf0ec7f87ab6b08dc35] ``` Related to #227 Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
ale64bit added the
discussion
label 2023-06-01 10:03:35 +00:00
aarifullin reviewed 2023-06-01 10:58:15 +00:00
@ -0,0 +131,4 @@
}
cmdHandlers := map[string]func([]string) error{
"ls": repl.handleLs,
Member

Probably, someone won't find the necessity of this, but I suggest you to consider Cobra approach to create subcommands for ls, add, remove, eval

I believe your implementation works finely but for me: this isn't my approach to process args within the handlers :) Cobra can handle better

Probably, someone won't find the necessity of this, but I suggest you to consider `Cobra` approach to create subcommands for `ls`, `add`, `remove`, `eval` I believe your implementation works finely but for me: this isn't my approach to process args within the handlers :) `Cobra` can handle better
Author
Member

I don't mind using cobra or even flag for it, although it feels a bit of an overkill. The idea was to circulate the feature first, in the simplest implementation I came up with. In case it's something we want to add, I can polish it a bit, including better command handling if needed. If it's not something we want, I'll keep it to myself without any fancy command handling.

I don't mind using `cobra` or even `flag` for it, although it feels a bit of an overkill. The idea was to circulate the feature first, in the simplest implementation I came up with. In case it's something we want to add, I can polish it a bit, including better command handling if needed. If it's not something we want, I'll keep it to myself without any fancy command handling.
Member

OK

OK
aarifullin approved these changes 2023-06-01 11:07:33 +00:00
acid-ant approved these changes 2023-06-01 11:25:44 +00:00
fyrchik reviewed 2023-06-01 13:20:11 +00:00
@ -0,0 +114,4 @@
}
func (repl *policyPlaygroundREPL) run() error {
if len(viper.GetString(commonflags.WalletPath)) > 0 {
Owner

Can we use key.GetOrGenerate and branch based on the --rpc-endpoint? https://git.frostfs.info/TrueCloudLab/frostfs-node/src/branch/master/cmd/frostfs-cli/internal/key/raw.go#L47

Netmap snapshot does not need any specific key.

Can we use `key.GetOrGenerate` and branch based on the `--rpc-endpoint`? https://git.frostfs.info/TrueCloudLab/frostfs-node/src/branch/master/cmd/frostfs-cli/internal/key/raw.go#L47 Netmap snapshot does not need any specific key.
Author
Member

done 👍

done 👍
fyrchik marked this conversation as resolved
ale64bit force-pushed feature/policy-playground from 024a93b1f4 to 2fdde0861d 2023-06-01 13:30:06 +00:00 Compare
aarifullin approved these changes 2023-06-01 14:10:32 +00:00
fyrchik requested review from anikeev-yadro 2023-06-02 09:08:46 +00:00
fyrchik approved these changes 2023-06-02 09:19:06 +00:00
fyrchik merged commit 2dd3fc8b7e into master 2023-06-02 09:23:42 +00:00
anikeev-yadro approved these changes 2023-06-02 10:57:24 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
5 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#416
No description provided.