@@ -2,25 +2,11 @@ package MetaCPAN::Script::Mapping;
2
2
3
3
use Moose;
4
4
5
- use Cpanel::JSON::XS qw( decode_json ) ;
6
- use DateTime ();
7
- use Log::Contextual qw( :log ) ;
8
- use MetaCPAN::Script::Mapping::Contributor ();
9
- use MetaCPAN::Script::Mapping::Cover ();
10
- use MetaCPAN::Script::Mapping::CPAN::Author ();
11
- use MetaCPAN::Script::Mapping::CPAN::Distribution ();
12
- use MetaCPAN::Script::Mapping::CPAN::Favorite ();
13
- use MetaCPAN::Script::Mapping::CPAN::File ();
14
- use MetaCPAN::Script::Mapping::CPAN::Mirror ();
15
- use MetaCPAN::Script::Mapping::CPAN::Package ();
16
- use MetaCPAN::Script::Mapping::CPAN::Permission ();
17
- use MetaCPAN::Script::Mapping::CPAN::Release ();
18
- use MetaCPAN::Script::Mapping::CVE ();
19
- use MetaCPAN::Script::Mapping::DeployStatement ();
20
- use MetaCPAN::Script::Mapping::User::Account ();
21
- use MetaCPAN::Script::Mapping::User::Identity ();
22
- use MetaCPAN::Script::Mapping::User::Session ();
23
- use MetaCPAN::Types::TypeTiny qw( Bool Str ) ;
5
+ use Cpanel::JSON::XS qw( decode_json ) ;
6
+ use DateTime ();
7
+ use Log::Contextual qw( :log ) ;
8
+ use MetaCPAN::ESConfig qw( es_config ) ;
9
+ use MetaCPAN::Types::TypeTiny qw( Bool Str ) ;
24
10
25
11
use constant {
26
12
EXPECTED => 1,
@@ -29,13 +15,6 @@ use constant {
29
15
30
16
with ' MetaCPAN::Role::Script' , ' MooseX::Getopt' ;
31
17
32
- has cpan_index => (
33
- is => ' ro' ,
34
- isa => Str,
35
- default => ' cpan_v1_01' ,
36
- documentation => ' real name for the cpan index' ,
37
- );
38
-
39
18
has arg_deploy_mapping => (
40
19
init_arg => ' delete' ,
41
20
is => ' ro' ,
@@ -285,11 +264,9 @@ sub update_index {
285
264
die " update_index requires patch_mapping\n "
286
265
unless $self -> patch_mapping;
287
266
288
- my $patch_mapping = decode_json $self -> patch_mapping;
289
- my @patch_types = sort keys %{$patch_mapping };
290
- my $dep = $self -> index -> deployment_statement;
291
- my $existing_mapping = delete $dep -> {mappings };
292
- my $mapping = +{ map { $_ => $patch_mapping -> {$_ } } @patch_types };
267
+ my $patch_mapping = decode_json $self -> patch_mapping;
268
+ my @patch_types = sort keys %{$patch_mapping };
269
+ my $mapping = +{ map { $_ => $patch_mapping -> {$_ } } @patch_types };
293
270
294
271
log_info {" Updating mapping for index: $name " };
295
272
@@ -311,15 +288,14 @@ sub create_index {
311
288
my $dst_idx = $self -> arg_create_index;
312
289
$self -> _check_index_exists( $dst_idx , NOT_EXPECTED );
313
290
314
- my $patch_mapping = decode_json $self -> patch_mapping;
315
- my @patch_types = sort keys %{$patch_mapping };
316
- my $dep = $self -> index -> deployment_statement;
317
- delete $dep -> {mappings };
318
- my $mapping = +{};
291
+ my $patch_mapping = decode_json $self -> patch_mapping;
292
+ my @patch_types = sort keys %{$patch_mapping };
293
+ my $index_settings = es_config-> index_settings($dst_idx );
294
+ my $mapping = +{};
319
295
320
296
# create the new index with the copied settings
321
297
log_info {" Creating index: $dst_idx " };
322
- $self -> es-> indices-> create( index => $dst_idx , body => $dep );
298
+ $self -> es-> indices-> create( index => $dst_idx , body => $index_settings );
323
299
324
300
# override with new type mapping
325
301
if ( $self -> patch_mapping ) {
@@ -489,51 +465,25 @@ sub show_info {
489
465
}
490
466
491
467
sub _build_mapping {
492
- my $self = $_ [0];
493
- return {
494
- $self -> cpan_index => {
495
- author =>
496
- decode_json(MetaCPAN::Script::Mapping::CPAN::Author::mapping),
497
- distribution => decode_json(
498
- MetaCPAN::Script::Mapping::CPAN::Distribution::mapping),
499
- favorite => decode_json(
500
- MetaCPAN::Script::Mapping::CPAN::Favorite::mapping),
501
- file =>
502
- decode_json(MetaCPAN::Script::Mapping::CPAN::File::mapping),
503
- mirror =>
504
- decode_json(MetaCPAN::Script::Mapping::CPAN::Mirror::mapping),
505
- permission => decode_json(
506
- MetaCPAN::Script::Mapping::CPAN::Permission::mapping),
507
- package => decode_json(
508
- MetaCPAN::Script::Mapping::CPAN::Package::mapping),
509
- release => decode_json(
510
- MetaCPAN::Script::Mapping::CPAN::Release::mapping),
511
- },
468
+ my $self = $_ [0];
469
+ my $docs = es_config-> documents;
470
+ my $mappings = {};
471
+ for my $name ( sort keys %$docs ) {
472
+ my $doc = $docs -> {$name };
473
+ my $index = $doc -> {index }
474
+ or die " no index defined for $name documents" ;
475
+ my $type = $doc -> {type }
476
+ or die " no type defined for $name documents" ;
477
+ my $mapping = es_config-> mapping($name );
478
+ $mappings -> {$index }{$type } = $mapping ;
479
+ }
512
480
513
- user => {
514
- account => decode_json(
515
- MetaCPAN::Script::Mapping::User::Account::mapping),
516
- identity => decode_json(
517
- MetaCPAN::Script::Mapping::User::Identity::mapping),
518
- session => decode_json(
519
- MetaCPAN::Script::Mapping::User::Session::mapping),
520
- },
521
- contributor => {
522
- contributor =>
523
- decode_json(MetaCPAN::Script::Mapping::Contributor::mapping),
524
- },
525
- cover => {
526
- cover => decode_json(MetaCPAN::Script::Mapping::Cover::mapping),
527
- },
528
- cve => {
529
- cve => decode_json(MetaCPAN::Script::Mapping::CVE::mapping),
530
- },
531
- };
481
+ return $mappings ;
532
482
}
533
483
534
484
sub _build_aliases {
535
485
my $self = $_ [0];
536
- return { ' cpan ' => $self -> cpan_index } ;
486
+ es_config -> aliases ;
537
487
}
538
488
539
489
sub deploy_mapping {
@@ -546,18 +496,16 @@ sub deploy_mapping {
546
496
# Deserialize the Index Mapping Structure
547
497
my $rmappings = $self -> _build_mapping;
548
498
549
- my $deploy_statement
550
- = decode_json(MetaCPAN::Script::Mapping::DeployStatement::mapping);
551
-
552
499
my $es = $self -> es;
553
500
554
501
# recreate the indices and apply the mapping
555
502
556
503
for my $idx ( sort keys %$rmappings ) {
557
504
$self -> _delete_index($idx ) if $es -> indices-> exists ( index => $idx );
505
+ my $index_settings = es_config-> index_settings($idx );
558
506
559
507
log_info {" Creating index: $idx " };
560
- $es -> indices-> create( index => $idx , body => $deploy_statement );
508
+ $es -> indices-> create( index => $idx , body => $index_settings );
561
509
562
510
for my $type ( sort keys %{ $rmappings -> {$idx } } ) {
563
511
log_info {" Adding mapping: $idx /$type " };
0 commit comments