diff --git a/lib/MetaCPAN/Script/Snapshot.pm b/lib/MetaCPAN/Script/Snapshot.pm index 976cb11e7..42ca98b96 100644 --- a/lib/MetaCPAN/Script/Snapshot.pm +++ b/lib/MetaCPAN/Script/Snapshot.pm @@ -82,8 +82,10 @@ has snap_name => ( has host => ( is => 'ro', isa => Str, - default => - sub { MetaCPAN::Server::Config::config()->{elasticsearch_servers} }, + default => sub { + my $self = shift; + return $self->es->transport->cxn_pool->cxns->[0]->uri; + }, documentation => 'ES host, defaults to: http://localhost:9200', ); diff --git a/metacpan_server.yaml b/metacpan_server.yaml index c7f8a9c76..63fd7bed8 100644 --- a/metacpan_server.yaml +++ b/metacpan_server.yaml @@ -4,7 +4,9 @@ git: /usr/bin/git cpan: /CPAN secret: "the stone roses" level: info -elasticsearch_servers: http://elasticsearch:9200 +elasticsearch_servers: + client: '2_0::Direct' + nodes: http://elasticsearch:9200 minion_dsn: "postgresql://metacpan:t00lchain@pghost:5432/minion_queue" port: 5000 diff --git a/metacpan_server_testing.yaml b/metacpan_server_testing.yaml index 3616d5509..77c91a046 100644 --- a/metacpan_server_testing.yaml +++ b/metacpan_server_testing.yaml @@ -4,7 +4,9 @@ level: warn port: 5000 source_base: var/t/tmp/source -elasticsearch_servers: http://elasticsearch_test:9200 +elasticsearch_servers: + client: '2_0::Direct' + nodes: http://elasticsearch_test:9200 logger: class: Log::Log4perl::Appender::Screen diff --git a/t/lib/MetaCPAN/Server/Test.pm b/t/lib/MetaCPAN/Server/Test.pm index 870d170ba..98ef26885 100644 --- a/t/lib/MetaCPAN/Server/Test.pm +++ b/t/lib/MetaCPAN/Server/Test.pm @@ -40,8 +40,7 @@ sub app { sub model { my $c = MetaCPAN::Server::Config::config(); - MetaCPAN::Model->new( - es => { nodes => [ $c->{elasticsearch_servers} ] } ); + MetaCPAN::Model->new( es => $c->{elasticsearch_servers} ); } 1; diff --git a/t/lib/MetaCPAN/TestServer.pm b/t/lib/MetaCPAN/TestServer.pm index de285bcdc..69328084b 100644 --- a/t/lib/MetaCPAN/TestServer.pm +++ b/t/lib/MetaCPAN/TestServer.pm @@ -18,12 +18,14 @@ use MetaCPAN::Server (); use MetaCPAN::Server::Config (); use MetaCPAN::TestHelpers qw( fakecpan_dir ); use MetaCPAN::Types::TypeTiny qw( HashRef Path ); +use MooseX::Types::ElasticSearch qw( ES ); use Search::Elasticsearch (); use Test::More; has es_client => ( is => 'ro', - does => 'Search::Elasticsearch::Role::Client', + isa => ES, + coerce => 1, lazy => 1, builder => '_build_es_client', ); @@ -64,14 +66,13 @@ sub _build_config { sub _build_es_client { my $self = shift; - my $es = Search::Elasticsearch->new( - nodes => MetaCPAN::Server::Config::config()->{elasticsearch_servers}, - ( $ENV{ES_TRACE} ? ( trace_to => [ 'File', 'es.log' ] ) : () ) - ); + my $es = ES->coerce( + MetaCPAN::Server::Config::config()->{elasticsearch_servers}, ); - ok( $es, 'got ElasticSearch object' ); + ok( $es, 'got Search::Elasticsearch object' ); note( Test::More::explain( { 'Elasticsearch info' => $es->info } ) ); + return $es; }