Skip to content

Draft: Added setup test #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7df5cd8
Test data - added test data
mickeyn May 3, 2025
9256cd9
author - fix script
mickeyn May 6, 2025
3f1e1fa
backpan - fix script
mickeyn May 6, 2025
7364503
backup - fix script
mickeyn May 6, 2025
d335e49
check - fix script
mickeyn May 6, 2025
2024cb7
checksum - fix script
mickeyn May 6, 2025
8bfc512
contributor - fix script
mickeyn May 6, 2025
176b28e
cover - fix script
mickeyn May 6, 2025
a76473e
cpan_testers - fix script
mickeyn May 6, 2025
8f04dcd
cpan_testers_api - fix script
mickeyn May 6, 2025
47ba547
cve - fix script
mickeyn May 6, 2025
89e23f7
external - fix script
mickeyn May 6, 2025
78e2ccc
favorite - fix script
mickeyn May 6, 2025
9d95b5f
first - fix script
mickeyn May 6, 2025
9ec9923
latest - fix script
mickeyn May 6, 2025
e0fa317
mirrors - fix script
mickeyn May 6, 2025
f48435d
package - fix script
mickeyn May 6, 2025
fbfd09e
permission - fix script
mickeyn May 6, 2025
46c4630
purge - fix script
mickeyn May 6, 2025
b374eaf
release - fix script
mickeyn May 6, 2025
e95fba6
river - fix script
mickeyn May 6, 2025
87b40ee
session - fix script
mickeyn May 6, 2025
a011f78
snapshot - fix script
mickeyn May 6, 2025
406ef2b
suggest - fix script
mickeyn May 6, 2025
8733aa3
tickets - fix script
mickeyn May 6, 2025
280d49d
watcher - fix script
mickeyn May 6, 2025
5594c0b
Added mapper logic - create full index + mapping
mickeyn May 6, 2025
5cb6cbe
ES - support dev mode
mickeyn May 6, 2025
dceb9eb
a few more type removals and wrong node setting
mickeyn May 7, 2025
abb96cb
setup test - draft
mickeyn May 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ COPY lib lib
COPY conf conf
COPY *.conf .

# move the following to test only
COPY t t
COPY test_data test_data

ENV PERL5LIB="/app/local/lib/perl5:/app/lib" PATH="/app/local/bin:${PATH}"

USER metacpan
Expand Down
5 changes: 2 additions & 3 deletions bin/author.pl
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@
};

# args
my ( $mode, $pauseid, $whois_file );
my ( $pauseid, $whois_file );
GetOptions(
"mode=s" => \$mode,
"pauseid=s" => \$pauseid,
"whois_file=s" => \$whois_file,
);

# setup
my $es = MetaCPAN::ES->new( index => "author", ( $mode ? ( mode => $mode ) : () ) );
my $es = MetaCPAN::ES->new( index => "author" );

log_info {'Reading 00whois'};
my $authors_data = read_00whois( $whois_file );
Expand Down
6 changes: 3 additions & 3 deletions bin/backpan.pl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

# setup
my $cpan_file_map = cpan_file_map();
my $es_release = MetaCPAN::ES->new( type => "release" );
my $es_file = MetaCPAN::ES->new( type => "file" );
my $es_release = MetaCPAN::ES->new( index => "release" );
my $es_file = MetaCPAN::ES->new( index => "file" );

my %bulk;
my %release_status;
Expand Down Expand Up @@ -169,6 +169,6 @@ =head1 DESCRIPTION
Sets "backpan" status on all BackPAN releases.

--undo will set distributions' status back as 'cpan'
--file_only will only fix the 'file' type
--file_only will only fix the 'file' index

=cut
10 changes: 3 additions & 7 deletions bin/backup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@
my $size = 1000;
my $index = "cpan";

my ( $dry_run, $mode, $purge, $restore );
my ( $dry_run, $purge, $restore );
GetOptions(
"batch_size=i" => \$batch_size,
"dry_run" => \$dry_run,
"index=s" => \$index,
"mode=s" => \$mode,
"purge" => \$purge,
"restore=s" => \$restore,
"size=i" => \$size,
);
# TODO: find a better way
my @es_mode = ( $mode ? mode => $mode : () );
$mode eq 'test' and Log::Log4perl::init('log4perl_test.conf');

# setup
my $home = home();
Expand Down Expand Up @@ -76,7 +72,7 @@ ()
# create a new bulk helper for each
my $key = $raw->{_index};

$es_store{$key} ||= MetaCPAN::ES->new( index => $key, @es_mode );
$es_store{$key} ||= MetaCPAN::ES->new( index => $key );
my $es = $es_store{$key};

$bulk_store{$key} ||= $es->bulk( max_count => $batch_size );
Expand Down Expand Up @@ -164,7 +160,7 @@ sub run_backup {
$file->parent->mkpath unless ( -e $file->parent );
my $fh = IO::Zlib->new( "$file", 'wb4' );

my $es = MetaCPAN::ES->new( index => $index, @es_mode );
my $es = MetaCPAN::ES->new( index => $index );
my $scroll = $es->scroll(
scroll => '1m',
body => {
Expand Down
11 changes: 5 additions & 6 deletions bin/check.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
use MetaCPAN::Ingest qw< read_02packages_fh >;

# args
my ( $module, $max_errors, $errors_only );

my ( $errors_only, $max_errors, $module );
GetOptions(
"module=s" => \$module,
"max_errors" => \$max_errors,
"errors_only" => \$errors_only,
"max_errors" => \$max_errors,
"module=s" => \$module,
);

# setup
my $error_count = 0;
my $packages_fh = read_02packages_fh();
my $es_file = MetaCPAN::ES->new( type => "file" );
my $es_release = MetaCPAN::ES->new( type => "release" );
my $es_file = MetaCPAN::ES->new( index => "file" );
my $es_release = MetaCPAN::ES->new( index => "release" );

my $modules_start = 0;
while ( my $line = <$packages_fh> ) {
Expand Down
6 changes: 3 additions & 3 deletions bin/checksum.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

# args
my $limit = 1000;
my $dry_run;
my ( $dry_run );
GetOptions(
"limit=i" => \$limit,
"dry_run" => \$dry_run,
"limit=i" => \$limit,
);

# setup
my $es = MetaCPAN::ES->new( type => "release" );
my $es = MetaCPAN::ES->new( index => "release" );
my $bulk;
$bulk = $es->bulk() unless $dry_run;

Expand Down
9 changes: 4 additions & 5 deletions bin/contributor.pl
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
"all" => \$all,
"distribution=s" => \$distribution,
"release=s" => \$release,

);

# setup
my $author_mapping = {};
my $email_mapping = {};

my $es_author = MetaCPAN::ES->new( type => 'author' );
my $es_release = MetaCPAN::ES->new( type => "release" );
my $es_contributor = MetaCPAN::ES->new( type => "contributor" );
my $es_author = MetaCPAN::ES->new( index => 'author' );
my $es_release = MetaCPAN::ES->new( index => "release" );
my $es_contributor = MetaCPAN::ES->new( index => "contributor" );

run();

Expand Down Expand Up @@ -296,6 +295,6 @@ =head1 SYNOPSIS
=head1 DESCRIPTION

Update the list of contributors (CPAN authors only) of all/matching
releases in the 'contributor' type (index).
releases in the 'contributor' index.

=cut
15 changes: 7 additions & 8 deletions bin/cover.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
my ( $json_file, $test );
GetOptions(
"json=s" => \$json_file,
"test" => \$test
"test" => \$test,
);
my $cover_url //= 'http://cpancover.com/latest/cpancover.json';
my $cover_dev_url //= 'http://cpancover.com/latest/cpancover_dev.json';
Expand All @@ -24,8 +24,9 @@
my %valid_keys
= map { $_ => 1 } qw< branch condition statement subroutine total >;

my $es = MetaCPAN::ES->new( index => "cover", type => "cover" );
my $bulk = $es->bulk();
my $es_release = MetaCPAN::ES->new( index => "release" );
my $es_cover = MetaCPAN::ES->new( index => "cover" );
my $bulk_cover = $es_cover->bulk();

my $data = retrieve_cover_data();

Expand All @@ -34,9 +35,7 @@
for my $dist ( sort keys %{$data} ) {
for my $version ( keys %{ $data->{$dist} } ) {
my $release = $dist . '-' . $version;
my $rel_check = $es->search(
index => 'cpan',
type => 'release',
my $rel_check = $es_release->search(
size => 0,
body => {
query => { term => { name => $release } },
Expand All @@ -56,7 +55,7 @@
delete $doc_data{$k} unless exists $valid_keys{$k};
}

$bulk->update( {
$bulk_cover->update( {
id => $release,
doc => {
distribution => $dist,
Expand All @@ -69,7 +68,7 @@
}
}

$bulk->flush;
$bulk_cover->flush;

###

Expand Down
2 changes: 1 addition & 1 deletion bin/cpan_testers.pl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

my $ua = ua();

my $es = MetaCPAN::ES->new( type => "release" );
my $es = MetaCPAN::ES->new( index => "release" );
my $bulk = $es->bulk();

log_info { 'Mirroring ' . $db };
Expand Down
7 changes: 1 addition & 6 deletions bin/cpan_testers_api.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use v5.36;

use Cpanel::JSON::XS qw< decode_json >;
use Getopt::Long;

use MetaCPAN::Logger qw< :log :dlog >;

Expand All @@ -13,10 +12,6 @@
ua
>;

# args
my ();
GetOptions();

# setup
my $home = home();

Expand All @@ -27,7 +22,7 @@

my $ua = ua();

my $es = MetaCPAN::ES->new( type => "release" );
my $es = MetaCPAN::ES->new( index => "release" );
my $bulk = $es->bulk();

log_info { 'Fetching ' . $url };
Expand Down
16 changes: 8 additions & 8 deletions bin/cve.pl
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
"json_file=s" => \$json_file,
"test" => \$test,
);

# setup
$cve_url //= 'https://hackeriet.github.io/cpansa-feed/cpansa.json';
$cve_dev_url //= 'https://hackeriet.github.io/cpansa-feed/cpansa_dev.json';

# setup
my $es = MetaCPAN::ES->new( index => "cve", type => "cve" );
my $bulk = $es->bulk();
my $es_release = MetaCPAN::ES->new( index => "release" );
my $es_cve = MetaCPAN::ES->new( index => "cve" );
my $bulk_cve = $es_cve->bulk();

my $data = retrieve_cve_data();

Expand Down Expand Up @@ -140,9 +142,7 @@
}
};

my $releases = $es->search(
index => 'cpan',
type => 'release',
my $releases = $es_release->search(
body => {
query => $query,
_source => [qw< version name author >],
Expand Down Expand Up @@ -183,15 +183,15 @@
delete $doc_data->{$k} unless exists $valid_keys{$k};
}

$bulk->update( {
$bulk_cve->update( {
id => $cpansa->{cpansa_id},
doc => $doc_data,
doc_as_upsert => 1,
} );
}
}

$bulk->flush;
$bulk_cve->flush;

sub retrieve_cve_data {
return decode_json( path($json_file)->slurp ) if $json_file;
Expand Down
30 changes: 12 additions & 18 deletions bin/external.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
use MetaCPAN::External::Cygwin qw< run_cygwin >;
use MetaCPAN::External::Debian qw< run_debian >;

# with(
# 'MetaCPAN::Script::Role::External::Cygwin',
# 'MetaCPAN::Script::Role::External::Debian',
# );

# args
my ( $email_to, $external_source );
GetOptions(
Expand All @@ -28,7 +23,18 @@
and grep { $_ eq $external_source } qw< cygwin debian >;

# setup
my $es = MetaCPAN::ES->new( type => "author" );
my $es = MetaCPAN::ES->new( index => "distribution" );
my $bulk = $es->bulk();
my $scroll = $es->scroll(
scroll => '10m',
body => {
query => {
exists => { field => "external_package." . $external_source }
}
},
);



my $ret;

Expand All @@ -54,16 +60,6 @@
log_debug {$email_body};
}

my $scroll = $es->scroll(
type => 'distribution',
scroll => '10m',
body => {
query => {
exists => { field => "external_package." . $external_source }
}
},
);

my @to_remove;

while ( my $s = $scroll->next ) {
Expand All @@ -80,8 +76,6 @@
}
}

my $bulk = $es->bulk( type => 'distribution' );

for my $d ( keys %{$dist} ) {
log_debug {"[$external_source] adding $d"};
$bulk->update( {
Expand Down
8 changes: 4 additions & 4 deletions bin/favorite.pl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ()
$query = { term => { distribution => $distribution } };
}
elsif ($age) {
my $es = MetaCPAN::ES->new( type => "favorite" );
my $es = MetaCPAN::ES->new( index => "favorite" );
my $favs = $es->scroll(
scroll => '5m',
body => {
Expand Down Expand Up @@ -84,7 +84,7 @@ ()
$dist_fav_count{$distribution} = $count;
}
else {
my $es = MetaCPAN::ES->new( type => "favorite" );
my $es = MetaCPAN::ES->new( index => "favorite" );
my $favs = $es->scroll(
scroll => '30s',
body => {
Expand Down Expand Up @@ -113,7 +113,7 @@ ()
@age_filter = ( must => [$age_filter] );
}

my $es = MetaCPAN::ES->new( type => "file" );
my $es = MetaCPAN::ES->new( index => "file" );
my $files = $es->scroll(
scroll => '15m',
body => {
Expand Down Expand Up @@ -184,7 +184,7 @@ ()
);
}
else {
my $es = MetaCPAN::ES->new( type => "file" );
my $es = MetaCPAN::ES->new( index => "file" );
my $bulk = $es->bulk( timeout => '120m' );
my $files = $es->scroll(
scroll => '15s',
Expand Down
Loading
Loading