From 488b5de0b77c7b7adda844b69b80f6c93e8c7a51 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 18 Sep 2013 20:37:09 -0700 Subject: [PATCH] HEAD /agents doesn't work because app has /agents link. Use GET /ping instead. --- bin/pt-agent | 53 +++++++++++++++--------------------- lib/Percona/WebAPI/Client.pm | 17 ------------ 2 files changed, 22 insertions(+), 48 deletions(-) diff --git a/bin/pt-agent b/bin/pt-agent index 696ef502..18240eec 100755 --- a/bin/pt-agent +++ b/bin/pt-agent @@ -965,23 +965,6 @@ sub get { return $resource_objects; } -sub head { - my ($self, %args) = @_; - - have_required_args(\%args, qw( - link - )) or die; - my ($link) = $args{link}; - - eval { - $self->_request( - method => 'HEAD', - link => $link, - ); - }; - return $EVAL_ERROR; -} - sub post { my $self = shift; $self->_set( @@ -5798,13 +5781,9 @@ sub init_agent { if ( $EVAL_ERROR ) { my $code = $client->response->code; if ( $code && $code == 404 ) { - my $agents_link = $client->entry_link . '/agents'; - $agents_link =~ s!/{2,}!/!g; # //agents doesn't work - my $api_ok = eval { - $client->head( - link => $agents_link, - ); - }; + my $api_ok = ping_api( + client => $client, + ); if ( $api_ok ) { $logger->fatal("API reports agent not found: the agent has been " . "deleted, or its UUID (" . ($agent->uuid || '?') . ") " @@ -6267,13 +6246,9 @@ sub get_config { if (blessed($e)) { if ($e->isa('Percona::WebAPI::Exception::Request')) { if ( $e->status == 404 ) { - my $agents_link = $client->entry_link . '/agents'; - $agents_link =~ s!/{2,}!/!g; # //agents doesn't work - my $api_ok = eval { - $client->head( - link => $agents_link, - ); - }; + my $api_ok = ping_api( + client => $client, + ); if ( $api_ok ) { stop_all_services( lib_dir => $lib_dir, @@ -9117,6 +9092,22 @@ sub too_many_agents { return scalar @pids > 10 ? 1 : 0; } +sub ping_api { + my (%args) = @_; + have_required_args(\%args, qw( + client + )) or die; + my $client = $args{client}; + my $ping_link = $client->entry_link . '/ping'; + $ping_link =~ s!/{2,}!/!g; # //agents doesn't work + eval { + $client->get( + link => $ping_link, + ); + }; + return $EVAL_ERROR ? 0 : 1; +} + sub _logger { my $_logger = shift; $logger = $_logger if $_logger; diff --git a/lib/Percona/WebAPI/Client.pm b/lib/Percona/WebAPI/Client.pm index 0fdd89f3..286b19b3 100644 --- a/lib/Percona/WebAPI/Client.pm +++ b/lib/Percona/WebAPI/Client.pm @@ -159,23 +159,6 @@ sub get { return $resource_objects; } -sub head { - my ($self, %args) = @_; - - have_required_args(\%args, qw( - link - )) or die; - my ($link) = $args{link}; - - eval { - $self->_request( - method => 'HEAD', - link => $link, - ); - }; - return $EVAL_ERROR; -} - # For a successful POST, the server sets the Location header with # the URI of the newly created resource. sub post {