Get MySQL version if needed. Remove Agent.actions.

This commit is contained in:
Daniel Nichter
2013-06-14 19:54:30 -07:00
parent 4e97201e34
commit 31157e368f
2 changed files with 42 additions and 45 deletions

View File

@@ -1274,12 +1274,6 @@ has 'versions' => (
required => 0, required => 0,
); );
has 'actions' => (
is => 'ro',
isa => 'Maybe[ArrayRef]',
requierd => 0,
);
has 'links' => ( has 'links' => (
is => 'rw', is => 'rw',
isa => 'Maybe[HashRef]', isa => 'Maybe[HashRef]',
@@ -5630,18 +5624,11 @@ sub init_agent {
# Update these attribs every time the agent is initialized. # Update these attribs every time the agent is initialized.
# Other optional attribs, like versions, are left to the caller. # Other optional attribs, like versions, are left to the caller.
chomp(my $hostname = `hostname`); chomp(my $hostname = `hostname`);
$agent->{hostname} = $hostname; $agent->hostname($hostname);
$agent->{username} = $ENV{USER} || $ENV{LOGNAME}; $agent->username($ENV{USER} || $ENV{LOGNAME});
# Add agent actions, if any. Used by instal() to report the # Try to create/update the Agent.
# MySQL user and pass created by pt-agent so PWS will add them my $success = 0;
# to the agent's default config.
if ( $actions ) {
$agent->{actions} = $actions;
}
# Try forever to create/update the Agent. The tool can't
# do anything without an Agent, so we must succeed to proceed.
while ( $_oktorun->() && (!defined $tries || $tries--) ) { while ( $_oktorun->() && (!defined $tries || $tries--) ) {
$logger->info($action eq 'put' ? "Updating agent " . $agent->name $logger->info($action eq 'put' ? "Updating agent " . $agent->name
: "Creating new agent"); : "Creating new agent");
@@ -5670,6 +5657,7 @@ sub init_agent {
$logger->warning($EVAL_ERROR); $logger->warning($EVAL_ERROR);
} }
else { else {
$success = 1;
last; # success last; # success
} }
} }
@@ -5679,7 +5667,7 @@ sub init_agent {
} }
$logger->info("Agent " . $agent->name . " (" . $agent->uuid . ") is ready"); $logger->info("Agent " . $agent->name . " (" . $agent->uuid . ") is ready");
return $agent; return $agent, $success;
} }
# Check and init the --lib dir. This dir is used to save the Agent resource # Check and init the --lib dir. This dir is used to save the Agent resource
@@ -5757,7 +5745,6 @@ sub start_agent {
my $_oktorun = $args{oktorun} || sub { return $oktorun }; my $_oktorun = $args{oktorun} || sub { return $oktorun };
my $tries = $args{tries}; my $tries = $args{tries};
my $interval = $args{interval} || sub { sleep 60; }; my $interval = $args{interval} || sub { sleep 60; };
my $actions = $args{actions};
my $versions = $args{versions}; # for testing my $versions = $args{versions}; # for testing
my $client = $args{client}; # for testing my $client = $args{client}; # for testing
my $entry_links = $args{entry_links}; # for testing my $entry_links = $args{entry_links}; # for testing
@@ -5828,7 +5815,6 @@ These values can change if a different configuration is received.
if ( !$versions ) { if ( !$versions ) {
$versions = get_versions( $versions = get_versions(
Cxn => $cxn, Cxn => $cxn,
tries => 1,
); );
} }
return unless $_oktorun->(); return unless $_oktorun->();
@@ -5867,16 +5853,14 @@ These values can change if a different configuration is received.
} }
} }
$agent = init_agent( ($agent) = init_agent(
agent => $agent, agent => $agent,
action => $action, # put or post action => $action, # put or post
link => $link, link => $link,
client => $client, client => $client,
tries => $tries,
interval => sub { sleep 60 }, interval => sub { sleep 60 },
lib_dir => $lib_dir, tries => $tries, # optional
oktorun => $_oktorun, oktorun => $_oktorun, # optional
actions => $actions, # Agent.actions
); );
# Give the logger its client so that it will also POST every log entry # Give the logger its client so that it will also POST every log entry
@@ -5947,6 +5931,34 @@ sub run_agent {
Cxn => $cxn, Cxn => $cxn,
); );
if ( $state->{need_mysql_version} ) {
my $versions = get_versions(
Cxn => $cxn,
);
if ( $versions->{MySQL} ) {
$agent->versions($versions);
my $updated_agent;
($agent, $updated_agent) = init_agent(
agent => $agent,
action => 'put',
link => $agent->links->{self},
client => $client,
interval => sub { return; },
tries => 1, # optional
);
if ( $updated_agent ) {
$logger->info("Got MySQL versions");
save_agent(
agent => $agent,
lib_dir => $lib_dir,
);
}
else {
$state->{need_mysql_version} = 1;
}
}
}
($config, $lib_dir, $new_daemon, $success) = get_config( ($config, $lib_dir, $new_daemon, $success) = get_config(
link => $agent->links->{config}, link => $agent->links->{config},
agent => $agent, agent => $agent,
@@ -8115,7 +8127,6 @@ sub install {
# ######################################################################## # ########################################################################
# Do the install # Do the install
# ######################################################################## # ########################################################################
my @actions;
# 4. Create/update the pt_agent MySQL user. pt-agent does not and should # 4. Create/update the pt_agent MySQL user. pt-agent does not and should
# not run as a privileged MySQL user. # not run as a privileged MySQL user.
@@ -8131,7 +8142,6 @@ sub install {
. $EVAL_ERROR; . $EVAL_ERROR;
} }
$cxn->dbh->disconnect(); $cxn->dbh->disconnect();
push @actions, "create-mysql-user: pt_agent,$random_pass";
# 5. Save the pt_agent MySQL user info in /etc/percona/agent/my.cnf. # 5. Save the pt_agent MySQL user info in /etc/percona/agent/my.cnf.
# We could set user= and pass= in ~/.pt-agent.conf, but each new agent # We could set user= and pass= in ~/.pt-agent.conf, but each new agent
@@ -8171,7 +8181,6 @@ pass=$random_pass
die "Sorry, an error occured while initializing $agent_my_cnf: " die "Sorry, an error occured while initializing $agent_my_cnf: "
. $EVAL_ERROR; . $EVAL_ERROR;
} }
push @actions, "init-agent-my-cnf: $agent_my_cnf";
# 6. Save the API key and defaults file in ~/.pt-agent.conf. # 6. Save the API key and defaults file in ~/.pt-agent.conf.
$next_step->(); $next_step->();
@@ -8188,7 +8197,6 @@ defaults-file=$agent_my_cnf
die "Sorry, an error occured while initializing $config_file: " die "Sorry, an error occured while initializing $config_file: "
. $EVAL_ERROR; . $EVAL_ERROR;
} }
push @actions, "init-config-file: $config_file";
# 7. Init --lib and --spool. pt-agent would do this itself, but we'll # 7. Init --lib and --spool. pt-agent would do this itself, but we'll
# do it now in case there are problems. # do it now in case there are problems.
@@ -8196,11 +8204,9 @@ defaults-file=$agent_my_cnf
init_lib_dir( init_lib_dir(
lib_dir => $o->get('lib'), lib_dir => $o->get('lib'),
); );
push @actions, "init-lib-dir: " . $o->get('lib');
init_spool_dir( init_spool_dir(
spool_dir => $o->get('spool'), spool_dir => $o->get('spool'),
); );
push @actions, "init-spool-dir: " . $o->get('spool');
# 8. Start the agent, don't run it yet. Normally this forks in # 8. Start the agent, don't run it yet. Normally this forks in
# anticipation of run_agent() being called next, but we don't do # anticipation of run_agent() being called next, but we don't do
@@ -8219,7 +8225,6 @@ defaults-file=$agent_my_cnf
log_file => undef, log_file => undef,
interval => sub { sleep 2; }, interval => sub { sleep 2; },
tries => 2, tries => 2,
#actions => \@actions,
); );
}; };
if ( $EVAL_ERROR ) { if ( $EVAL_ERROR ) {
@@ -8335,8 +8340,8 @@ sub _set_logger {
sub get_versions { sub get_versions {
my (%args) = @_; my (%args) = @_;
my $cxn = $args{Cxn}; my $cxn = $args{Cxn};
my $tries = $args{tries} || 3; my $tries = $args{tries} || 1;
my $interval = $args{interval} || sub { sleep 5 }; my $interval = $args{interval} || sub { sleep 3; };
my $have_mysql = 0; my $have_mysql = 0;
if ( $cxn ) { if ( $cxn ) {
@@ -8354,13 +8359,11 @@ sub get_versions {
last; # success last; # success
} }
if ( $tryno < $tries ) { if ( $tryno < $tries ) {
sleep 3; # failure, try again sleep $interval; # failure, try again
} }
else { else {
$state->{need_mysql_version} = 1; $state->{need_mysql_version} = 1;
$logger->info("Configure MySQL connection options for the agent " $logger->warning("Cannot get MySQL version, will try again later");
. "at https://pws.percona.com. Some services may not "
. "work until a MySQL connection can be established.");
last; # failure last; # failure
} }
} }

View File

@@ -57,12 +57,6 @@ has 'versions' => (
required => 0, required => 0,
); );
has 'actions' => (
is => 'ro',
isa => 'Maybe[ArrayRef]',
requierd => 0,
);
has 'links' => ( has 'links' => (
is => 'rw', is => 'rw',
isa => 'Maybe[HashRef]', isa => 'Maybe[HashRef]',