From 25e154e261694a42f40a4535e1222dc5a2024557 Mon Sep 17 00:00:00 2001 From: Andrii Nikitin Date: Fri, 13 Oct 2023 15:58:57 +0200 Subject: [PATCH] ui: improve geo avareness of Mirror details form Improve Mirror details form: * When mirrors are imported using MIRROR_PROVIDER option - refer the provider in "Private notes". * When mirrors are maintaned by subsidiary - refer corresponding subsidiary for "Last incidents" table. --- .../WebAPI/Controller/App/Server.pm | 14 ++ t/environ/14-project-hq-regions.sh | 169 ++++++++++++++++++ t/environ/14-project-hq.sh | 3 - templates/app/server/show.html.ep | 24 ++- 4 files changed, 204 insertions(+), 6 deletions(-) create mode 100755 t/environ/14-project-hq-regions.sh diff --git a/lib/MirrorCache/WebAPI/Controller/App/Server.pm b/lib/MirrorCache/WebAPI/Controller/App/Server.pm index 8a722d29..3729d23a 100644 --- a/lib/MirrorCache/WebAPI/Controller/App/Server.pm +++ b/lib/MirrorCache/WebAPI/Controller/App/Server.pm @@ -59,12 +59,26 @@ sub show { if ($self->is_operator) { $admin_email = $self->schema->storage->dbh->selectrow_array("SELECT msg FROM server_note WHERE hostname = ? AND kind = 'Email' ORDER BY dt DESC LIMIT 1", undef, $hostname); } + my $subsidiary; + if (my $regions = $self->mcconfig->regions) { + if ($f->region && -1 == CORE::index($regions, $f->region)) { + $subsidiary = $self->subsidiary->url($f->region); + } + } + my $provider; + if ($provider = $self->mcconfig->mirror_provider) { + $provider =~ s!^https?://(?:www\.)?!!i; + $provider =~ s!/.*!!; + $provider =~ s/[\?\#\:].*//; + } my $server = { id => $f->id, hostname => $f->hostname, public_notes => $f->public_notes, admin_email => $admin_email, + subsidiary => $subsidiary, + provider => $provider, }; return $self->render('app/server/show', server => $server); diff --git a/t/environ/14-project-hq-regions.sh b/t/environ/14-project-hq-regions.sh new file mode 100755 index 00000000..4d315007 --- /dev/null +++ b/t/environ/14-project-hq-regions.sh @@ -0,0 +1,169 @@ +#!lib/test-in-container-environ.sh +set -ex + +# environ by number: +# 9 - headquarter with REGIONS=eu,sa,af +# 6 - NA subsidiary +# 7 - EU subsidiary (same DB as hq) +# 8 - ASIA subsidiary + +# all mirrors are centralized in hq and imported by subsidiaries with MIRROR_PROVIDER +# hq mirrors: ap1 ap2 +# na mirrors: ap3 ap4 +# eu mirrors: ap5 ap6 +# as mirrors: ap7 ap8 + +for i in 6 7 8 9; do + x=$(environ mc$i $(pwd)) + mkdir -p $x/dt/{project1,project2}/{folder1,folder2,folder3} + echo $x/dt/{project1,project2}/{folder1,folder2,folder3}/{file1.1,file2.1}.dat | xargs -n 1 touch + eval mc$i=$x +done + +for i in 1 2 3 4 5 6 7 8; do + x=$(environ ap$i) + mkdir -p $x/dt/{project1,project2}/{folder1,folder2,folder3} + echo $x/dt/{project1,project2}/{folder1,folder2,folder3}/{file1.1,file2.1}.dat | xargs -n 1 touch + $x/start + eval ap$i=$x +done + +hq_address=$($mc9/print_address) +na_address=$($mc6/print_address) +na_interface=127.0.0.2 +eu_address=$($mc7/print_address) +eu_interface=127.0.0.3 +as_address=$($mc8/print_address) +as_interface=127.0.0.4 + +# deploy db +$mc9/gen_env MIRRORCACHE_REGIONS=eu,sa,af +$mc9/backstage/shoot + +$mc9/sql "insert into subsidiary(hostname,region) select '$na_address','na'" +$mc9/sql "insert into subsidiary(hostname,region,local) select '$eu_address','eu','t'" +$mc9/sql "insert into subsidiary(hostname,region) select '$as_address','as'" +$mc9/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap1/print_address)','','t','br','sa'" +$mc9/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap2/print_address)','','t','br','sa'" +$mc9/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap5/print_address)','','t','de','eu'" +$mc9/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap6/print_address)','','t','dk','eu'" +$mc9/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap3/print_address)','','t','us','na'" +$mc9/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap4/print_address)','','t','ca','na'" +$mc9/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap7/print_address)','','t','jp','as'" +$mc9/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap8/print_address)','','t','jp','as'" + +$mc9/start + +$mc6/gen_env MIRRORCACHE_MIRROR_PROVIDER=$($mc9/print_address)/rest/server_location?region=na +$mc6/start +$mc6/backstage/shoot +echo test mirrors imported to mc6 +$mc6/sql_test 2 == "select count(*) from server" + +$mc7/gen_env +rm -r $mc7/db +ln -s $mc9/db $mc7/db +$mc7/start + +$mc8/gen_env MIRRORCACHE_MIRROR_PROVIDER=$($mc9/print_address)/rest/server_location?region=as +$mc8/start +$mc8/backstage/shoot +echo test mirrors imported to mc8 +$mc8/sql_test 2 == "select count(*) from server" + + + +for i in 6 8 9; do + mc$i/sql "insert into project(name,path,etalon) select 'proj1','/project1', min(id) from server" + mc$i/sql "insert into project(name,path,etalon) select 'proj 2','/project2', min(id) from server" + mc$i/backstage/job -e folder_sync -a '["/project1/folder1"]' + mc$i/backstage/job -e mirror_scan -a '["/project1/folder1"]' + mc$i/backstage/job -e folder_sync -a '["/project1/folder2"]' + mc$i/backstage/job -e mirror_scan -a '["/project1/folder2"]' + mc$i/backstage/job -e folder_sync -a '["/project2/folder1"]' + mc$i/backstage/job -e mirror_scan -a '["/project2/folder1"]' + mc$i/backstage/shoot + mc$i/backstage/job -e report -a '["once"]' + mc$i/backstage/shoot +done + +echo project1 to eu if we contacted hq from na +$mc9/sql "update project set redirect = 'na:$eu_address/download' where id = 1" +echo project2 to na even if we contacted hq from as or eu +$mc9/sql "update project set redirect = 'as:$na_address/download;eu:$na_address/download' where id = 2" +echo test project1 redirects +$mc9/curl --interface $na_interface -I /download/project1/folder1/file1.1.dat | grep "$eu_address" +$mc9/curl --interface $eu_interface -I /download/project1/folder1/file1.1.dat | grep "$eu_address" + +echo test project2 redirects +$mc9/curl --interface $eu_interface -I /download/project2/folder1/file1.1.dat | grep "$na_address" +$mc9/curl --interface $as_interface -I /download/project2/folder1/file1.1.dat | grep "$na_address" +$mc9/curl --interface $as_interface -IL /download/project2/folder1/file1.1.dat | grep -E "$($ap3/print_address)|$($ap4/print_address)" +$mc9/curl --interface $na_interface -I /download/project2/folder1/file1.1.dat | grep "$na_address" + +echo "Let's pretend proj 2 has no good mirrors in as and we redirect all requests from it to na subsidiary" +$mc8/sql "update project set redirect = '$na_address/download' where id = 2" + +echo project1 redirects to regular mirror +$mc8/curl -I /download/project1/folder1/file1.1.dat | grep -E "$($ap7/print_address)|$($ap8/print_address)" + +echo project2 redirects to na +$mc8/curl -I /download/project2/folder1/file1.1.dat | grep $na_address/download/project2/folder1/file1.1.dat +$mc8/curl -IL /download/project2/folder1/file1.1.dat | grep -E "$($ap3/print_address)|$($ap4/print_address)" + + +# all countries present in report +$mc9/curl /rest/repmirror \ + | grep '"country":"br"' \ + | grep '"country":"de"' \ + | grep '"country":"dk"' \ + | grep '"country":"ca"' \ + | grep '"country":"us"' \ + | grep '"country":"jp"' \ + | grep -F '"region":"na (http:\/\/127.0.0.1:3160)"' + +allmirrorspattern="$(ap1/print_address)" +for i in {2..8}; do + x=ap$i + allmirrorspattern="$allmirrorspattern|$($x/print_address)" +done + +# all mirrors are mentioned in html report +test 8 == $($mc9/curl -i /report/mirrors | grep -A500 '200 OK' | grep -Eo $allmirrorspattern | sort | uniq | wc -l) + +echo collect report when one of the instances is down +$mc6/stop + +$mc9/backstage/job -e report -a '["once"]' +$mc9/backstage/shoot + +$mc9/curl /rest/repmirror \ + | grep '"country":"br"' \ + | grep '"country":"de"' \ + | grep '"country":"dk"' \ + | grep '"country":"ca"' \ + | grep '"country":"us"' \ + | grep '"country":"jp"' \ + | grep -F '"region":"na (http:\/\/127.0.0.1:3160)"' + +# all mirrors are mentioned in html report +test 8 == $($mc9/curl -i /report/mirrors | grep -A500 '200 OK' | grep -Eo $allmirrorspattern | sort | uniq | wc -l) + +echo also when the main db is down +$mc9/db/stop + +$mc9/curl /rest/repmirror \ + | grep '"country":"br"' \ + | grep '"country":"de"' \ + | grep '"country":"dk"' \ + | grep '"country":"ca"' \ + | grep '"country":"us"' \ + | grep '"country":"jp"' \ + | grep -F '"region":"na (http:\/\/127.0.0.1:3160)"' + +# all mirrors are mentioned in html report +test 8 == $($mc9/curl -i /report/mirrors | grep -A500 '200 OK' | grep -Eo $allmirrorspattern | sort | uniq | wc -l) + +$mc9/db/start + +echo success diff --git a/t/environ/14-project-hq.sh b/t/environ/14-project-hq.sh index 744dd18d..f4d0b29c 100755 --- a/t/environ/14-project-hq.sh +++ b/t/environ/14-project-hq.sh @@ -48,17 +48,14 @@ $mc9/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ $mc9/start -$mc6/gen_env MIRRORCACHE_REGION=na MIRRORCACHE_HEADQUARTER=$hq_address $mc6/start $mc6/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap3/print_address)','','t','us','na'" $mc6/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap4/print_address)','','t','ca','na'" -$mc7/gen_env MIRRORCACHE_REGION=eu MIRRORCACHE_HEADQUARTER=$hq_address rm -r $mc7/db ln -s $mc9/db $mc7/db $mc7/start -$mc8/gen_env MIRRORCACHE_REGION=as MIRRORCACHE_HEADQUARTER=$hq_address $mc8/start $mc8/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap7/print_address)','','t','jp','as'" $mc8/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap8/print_address)','','t','jp','as'" diff --git a/templates/app/server/show.html.ep b/templates/app/server/show.html.ep index 95c5f499..0b3000c2 100644 --- a/templates/app/server/show.html.ep +++ b/templates/app/server/show.html.ep @@ -3,12 +3,18 @@ % content_for 'ready_function' => begin is_operator = <%= (is_operator) ? 'true' : 'false' %>; - server_id = <%= $server->{id} %>; + server_id = <%= $server->{id} %>; + subsidiary = "<%= $server->{subsidiary} %>"; + provider = "<%= $server->{provider} %>"; if (is_operator) { hostname = "<%= $server->{hostname} %>"; - setupServerNote(hostname); + if (!provider) { + setupServerNote(hostname); + } + } + if (!subsidiary) { + setupServerIncident(server_id); } - setupServerIncident(server_id); % end
@@ -33,6 +39,11 @@ % if (is_operator) {

Private notes

+% if ($server->{provider}) { +
+ Can be found at {hostname} %>"><%= $server->{provider} %> +
+% } else { @@ -52,9 +63,15 @@ +% } % }

Checks last two weeks

+% if ($server->{subsidiary}) { +
+ Can be found at {hostname} %>"><%= $server->{subsidiary} %> +
+% } else {
Date
@@ -62,6 +79,7 @@
DateError
+% }