Skip to content

Commit

Permalink
ui: improve geo avareness of Mirror details form
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrii-suse committed Oct 13, 2023
1 parent 84b349e commit 25e154e
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 6 deletions.
14 changes: 14 additions & 0 deletions lib/MirrorCache/WebAPI/Controller/App/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
169 changes: 169 additions & 0 deletions t/environ/14-project-hq-regions.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions t/environ/14-project-hq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
24 changes: 21 additions & 3 deletions templates/app/server/show.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -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

<div class="row">
Expand All @@ -33,6 +39,11 @@

% if (is_operator) {
<h3>Private notes</h3>
% if ($server->{provider}) {
<div>
Can be found at <a href="https://<%= $server->{provider} . "/app/server/" . $server->{hostname} %>"><%= $server->{provider} %></a>
</div>
% } else {
<table id="server_note" class="table table-striped">
<thead>
<th>Date</th>
Expand All @@ -52,16 +63,23 @@
<input type="text" id="new-note-text" name="new-note-text" onkeyup="addServerNoteButtonStatus()">
<input value="add" id="new-note-submit" onclick="addServerNote(hostname, document.getElementById('new-note-select').value, document.getElementById('new-note-text').value);" type="button" class="btn btn-default" disabled/>
</div>
% }
% }

<h3>Checks last two weeks</h3>
% if ($server->{subsidiary}) {
<div>
Can be found at <a href="<%= $server->{subsidiary} . "/app/server/" . $server->{hostname} %>"><%= $server->{subsidiary} %></a>
</div>
% } else {
<table id="server_incident" class="table table-striped">
<thead>
<th>Date</th>
<th>Capability</th>
<th>Error</th>
</thead>
</table>
% }
</div>

</div>

0 comments on commit 25e154e

Please sign in to comment.