Skip to content

Commit 697fe01

Browse files
committed
Always use type coercion to construct Search::Elasticsearch object
Make all uses of elasticsearch_servers consistent, passing the value directly to the MooseX::Types::ElasticSearch::ES type coercion. This ensures we can use any value that the type will accept. This allows adding additional parameters that will be passed to the constructor. With that allowed, explicitly set the client version we want to use. Since we are currently pinned to Search::Elasticsearch 2.03, this won't have any direct impact. But it will assist in upgrading the Search::Elasticsearch version.
1 parent 07643e3 commit 697fe01

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

lib/MetaCPAN/Script/Snapshot.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ has snap_name => (
8282
has host => (
8383
is => 'ro',
8484
isa => Str,
85-
default =>
86-
sub { MetaCPAN::Server::Config::config()->{elasticsearch_servers} },
85+
default => sub {
86+
my $self = shift;
87+
return $self->es->transport->cxn_pool->cxns->[0]->uri;
88+
},
8789
documentation => 'ES host, defaults to: http://localhost:9200',
8890
);
8991

metacpan_server.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ git: /usr/bin/git
44
cpan: /CPAN
55
secret: "the stone roses"
66
level: info
7-
elasticsearch_servers: http://elasticsearch:9200
7+
elasticsearch_servers:
8+
client: '2_0::Direct'
9+
nodes: http://elasticsearch:9200
810
minion_dsn: "postgresql://metacpan:t00lchain@pghost:5432/minion_queue"
911
port: 5000
1012

metacpan_server_testing.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ level: warn
44
port: 5000
55
source_base: var/t/tmp/source
66

7-
elasticsearch_servers: http://elasticsearch_test:9200
7+
elasticsearch_servers:
8+
client: '2_0::Direct'
9+
nodes: http://elasticsearch_test:9200
810

911
logger:
1012
class: Log::Log4perl::Appender::Screen

t/lib/MetaCPAN/Server/Test.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ sub app {
4040

4141
sub model {
4242
my $c = MetaCPAN::Server::Config::config();
43-
MetaCPAN::Model->new(
44-
es => { nodes => [ $c->{elasticsearch_servers} ] } );
43+
MetaCPAN::Model->new( es => $c->{elasticsearch_servers} );
4544
}
4645

4746
1;

t/lib/MetaCPAN/TestServer.pm

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ use MetaCPAN::Server ();
1818
use MetaCPAN::Server::Config ();
1919
use MetaCPAN::TestHelpers qw( fakecpan_dir );
2020
use MetaCPAN::Types::TypeTiny qw( HashRef Path );
21+
use MooseX::Types::ElasticSearch qw( ES );
2122
use Search::Elasticsearch ();
2223
use Test::More;
2324

2425
has es_client => (
2526
is => 'ro',
26-
does => 'Search::Elasticsearch::Role::Client',
27+
isa => ES,
28+
coerce => 1,
2729
lazy => 1,
2830
builder => '_build_es_client',
2931
);
@@ -64,14 +66,13 @@ sub _build_config {
6466
sub _build_es_client {
6567
my $self = shift;
6668

67-
my $es = Search::Elasticsearch->new(
68-
nodes => MetaCPAN::Server::Config::config()->{elasticsearch_servers},
69-
( $ENV{ES_TRACE} ? ( trace_to => [ 'File', 'es.log' ] ) : () )
70-
);
69+
my $es = ES->coerce(
70+
MetaCPAN::Server::Config::config()->{elasticsearch_servers}, );
7171

72-
ok( $es, 'got ElasticSearch object' );
72+
ok( $es, 'got Search::Elasticsearch object' );
7373

7474
note( Test::More::explain( { 'Elasticsearch info' => $es->info } ) );
75+
7576
return $es;
7677
}
7778

0 commit comments

Comments
 (0)