-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rollout tracking for iso and repo projects (#451)
- Loading branch information
1 parent
83cdac5
commit ed41764
Showing
12 changed files
with
321 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package Directory::Scanner::OBSReleaseInfo; | ||
|
||
use Mojo::Base -base, -signatures; | ||
|
||
has ['type', 'version', 'versionfilename', 'versionmtime']; | ||
|
||
sub new($class, $type, $mtime) { | ||
my $self = Mojo::Base::new($class); | ||
$mtime = 0 unless $mtime; | ||
$self->type($type); | ||
$self->versionmtime($mtime); | ||
$self->versionfilename(''); | ||
} | ||
|
||
sub next_file($self, $filename, $mtime) { | ||
return 0 unless $mtime; | ||
return 0 if $self->versionmtime > $mtime; | ||
if ($self->type eq 'iso') { | ||
if ($filename =~ /.*(Build|Snapshot)((\d)+\.?(\d*))-Media\.iso$/) { | ||
$self->version($2); | ||
$self->versionfilename($filename); | ||
$self->versionmtime($mtime); | ||
return 1; | ||
} | ||
} elsif ($self->type eq 'repo') { | ||
if ($filename =~ /.*primary.xml(\.(gz|zst))$/) { | ||
my $version = $mtime; | ||
$self->version($version); | ||
$self->versionfilename($filename); | ||
$self->versionmtime($mtime); | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use utf8; | ||
package MirrorCache::Schema::Result::ProjectRollout; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use base 'DBIx::Class::Core'; | ||
use DBIx::Class::Timestamps; | ||
|
||
__PACKAGE__->table("project_rollout"); | ||
|
||
|
||
__PACKAGE__->load_components(qw(InflateColumn::DateTime DynamicDefault)); | ||
__PACKAGE__->add_columns( | ||
"project_id", | ||
{ data_type => "integer"}, | ||
"epc", | ||
{ data_type => "integer"}, | ||
"dt", | ||
{ | ||
data_type => 'timestamp', | ||
is_nullable => 1 | ||
}, | ||
version => { | ||
data_type => 'varchar', | ||
size => 32 | ||
}, | ||
); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use utf8; | ||
package MirrorCache::Schema::ResultSet::ProjectRollout; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use base 'DBIx::Class::ResultSet'; | ||
use Mojo::File qw(path); | ||
|
||
|
||
sub project_for_folder { | ||
my ($self, $path) = @_; | ||
my $dbh = $self->result_source->schema->storage->dbh; | ||
|
||
my $sql = <<"END_SQL"; | ||
select id, name, path, max(epc) as prev_epc, | ||
case | ||
when upper(name) like '%ISO%' then 'iso' | ||
when upper(name) like '%REPO%' and ?::text = concat(path,'/repodata') then 'repo' | ||
else '' | ||
end as type | ||
from project | ||
left join project_rollout on id = project_id | ||
where ? like concat(path, '/%') | ||
group by id, name, path | ||
END_SQL | ||
$sql =~ s/::text//g unless ($dbh->{Driver}->{Name} eq 'Pg'); | ||
|
||
my $prep = $dbh->prepare($sql); | ||
$prep->execute($path, $path); | ||
return $dbh->selectrow_hashref($prep); | ||
} | ||
|
||
# the same as project_for_folder, but also profides filename to track | ||
sub rollout_file_for_folder { | ||
my ($self, $path) = @_; | ||
my $dbh = $self->result_source->schema->storage->dbh; | ||
|
||
my $sql = <<"END_SQL"; | ||
select id, name, path, epc, filename | ||
from ( | ||
select id, name, path, max(epc) as prev_epc, | ||
case | ||
when upper(name) like '%ISO%' then 'iso' | ||
when upper(name) like '%REPO%' and ?::text = concat(path,'/repodata') then 'repo' | ||
else '' | ||
end as type | ||
from project | ||
join project_rollout on id = project_id | ||
where ? like concat(path, '/%') | ||
group by id, name, path | ||
) rollout | ||
join project_rollout on (id, prev_epc) = (project_id, epc) and type != '' | ||
END_SQL | ||
$sql =~ s/::text//g unless ($dbh->{Driver}->{Name} eq 'Pg'); | ||
|
||
my $prep = $dbh->prepare($sql); | ||
$prep->execute($path, $path); | ||
return $dbh->selectrow_hashref($prep); | ||
} | ||
|
||
sub add_rollout_server { | ||
my ($self, $server_id, $proj_id, $epc) = @_; | ||
my $dbh = $self->result_source->schema->storage->dbh; | ||
|
||
my $sql = 'insert into project_rollout_server(server_id, project_id, epc, dt) select ?, ?, ?, now()'; | ||
$dbh->prepare($sql)->execute($server_id, $proj_id, $epc); | ||
return 1; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!lib/test-in-container-environ.sh | ||
set -ex | ||
|
||
mc=$(environ mc $(pwd)) | ||
|
||
$mc/start | ||
|
||
ap8=$(environ ap8) | ||
ap7=$(environ ap7) | ||
ap6=$(environ ap6) | ||
ap5=$(environ ap5) | ||
ap4=$(environ ap4) | ||
|
||
for x in $mc $ap7 $ap8 $ap6 $ap5 $ap4; do | ||
mkdir -p $x/dt/{folder1,folder2,folder3} | ||
mkdir -p $x/dt/project1/iso | ||
mkdir -p $x/dt/project2/iso | ||
echo $x/dt/project1/iso/proj1-Build1.1-Media.iso{,sha256} | xargs -n 1 touch | ||
echo $x/dt/project2/iso/proj1-Snapshot240131-Media.iso{,.sha256} | xargs -n 1 touch | ||
done | ||
|
||
$ap4/start | ||
$ap5/start | ||
$ap6/start | ||
$ap7/start | ||
$ap8/start | ||
|
||
$mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap6/print_address)','','t','us','na'" | ||
$mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap7/print_address)','','t','us','na'" | ||
$mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap8/print_address)','','t','de','eu'" | ||
$mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap5/print_address)','','t','cn','as'" | ||
$mc/sql "insert into server(hostname,urldir,enabled,country,region) select '$($ap4/print_address)','','t','jp','as'" | ||
|
||
$mc/sql "insert into project(name,path,etalon) select 'proj1 ISO','/project1', 3" | ||
$mc/sql "insert into project(name,path,etalon) select 'proj 2 ISO','/project2', 3" | ||
|
||
$mc/backstage/job -e folder_sync -a '["/project1/iso"]' | ||
$mc/backstage/job -e mirror_scan -a '["/project1/iso"]' | ||
$mc/backstage/shoot | ||
|
||
$mc/sql_test 1 == 'select count(*) from project_rollout' | ||
$mc/sql_test 1.1 == 'select version from project_rollout' | ||
$mc/sql_test proj1-Build1.1-Media.iso == 'select filename from project_rollout' | ||
|
||
$mc/sql_test 5 == 'select count(*) from project_rollout_server' | ||
|
||
$mc/backstage/job -e folder_sync -a '["/project2/iso"]' | ||
$mc/backstage/job -e mirror_scan -a '["/project2/iso"]' | ||
$mc/backstage/shoot | ||
|
||
$mc/sql_test 2 == 'select count(*) from project_rollout' | ||
$mc/sql_test 240131 == 'select version from project_rollout where project_id = 2' | ||
|
||
echo success |
Oops, something went wrong.