HEAD /agents doesn't work because app has /agents link. Use GET /ping instead.

This commit is contained in:
Daniel Nichter
2013-09-18 20:37:09 -07:00
parent d6a46cfd33
commit 488b5de0b7
2 changed files with 22 additions and 48 deletions

View File

@@ -965,23 +965,6 @@ sub get {
return $resource_objects; 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 { sub post {
my $self = shift; my $self = shift;
$self->_set( $self->_set(
@@ -5798,13 +5781,9 @@ sub init_agent {
if ( $EVAL_ERROR ) { if ( $EVAL_ERROR ) {
my $code = $client->response->code; my $code = $client->response->code;
if ( $code && $code == 404 ) { if ( $code && $code == 404 ) {
my $agents_link = $client->entry_link . '/agents'; my $api_ok = ping_api(
$agents_link =~ s!/{2,}!/!g; # //agents doesn't work client => $client,
my $api_ok = eval { );
$client->head(
link => $agents_link,
);
};
if ( $api_ok ) { if ( $api_ok ) {
$logger->fatal("API reports agent not found: the agent has been " $logger->fatal("API reports agent not found: the agent has been "
. "deleted, or its UUID (" . ($agent->uuid || '?') . ") " . "deleted, or its UUID (" . ($agent->uuid || '?') . ") "
@@ -6267,13 +6246,9 @@ sub get_config {
if (blessed($e)) { if (blessed($e)) {
if ($e->isa('Percona::WebAPI::Exception::Request')) { if ($e->isa('Percona::WebAPI::Exception::Request')) {
if ( $e->status == 404 ) { if ( $e->status == 404 ) {
my $agents_link = $client->entry_link . '/agents'; my $api_ok = ping_api(
$agents_link =~ s!/{2,}!/!g; # //agents doesn't work client => $client,
my $api_ok = eval { );
$client->head(
link => $agents_link,
);
};
if ( $api_ok ) { if ( $api_ok ) {
stop_all_services( stop_all_services(
lib_dir => $lib_dir, lib_dir => $lib_dir,
@@ -9117,6 +9092,22 @@ sub too_many_agents {
return scalar @pids > 10 ? 1 : 0; 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 { sub _logger {
my $_logger = shift; my $_logger = shift;
$logger = $_logger if $_logger; $logger = $_logger if $_logger;

View File

@@ -159,23 +159,6 @@ sub get {
return $resource_objects; 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 # For a successful POST, the server sets the Location header with
# the URI of the newly created resource. # the URI of the newly created resource.
sub post { sub post {