mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 13:40:07 +00:00
Add Agent.user attribute.
This commit is contained in:
39
bin/pt-agent
39
bin/pt-agent
@@ -1256,6 +1256,12 @@ has 'alias' => (
|
||||
required => 0,
|
||||
);
|
||||
|
||||
has 'user' => (
|
||||
is => 'ro',
|
||||
isa => 'Str',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
has 'versions' => (
|
||||
is => 'ro',
|
||||
isa => 'Maybe[HashRef]',
|
||||
@@ -5005,15 +5011,7 @@ sub load_local_agent {
|
||||
|
||||
my $agent;
|
||||
my $agent_file = $lib_dir . "/agent";
|
||||
if ( $agent_uuid ) {
|
||||
_info("Re-creating Agent with UUID $agent_uuid");
|
||||
chomp(my $hostname = `hostname`);
|
||||
$agent = Percona::WebAPI::Resource::Agent->new(
|
||||
uuid => $agent_uuid,
|
||||
hostname => $hostname,
|
||||
);
|
||||
}
|
||||
elsif ( -f $agent_file ) {
|
||||
if ( -f $agent_file ) {
|
||||
_info("Reading saved Agent from $agent_file");
|
||||
my $agent_hashref = decode_json(slurp($agent_file));
|
||||
$agent = Percona::WebAPI::Resource::Agent->new(%$agent_hashref);
|
||||
@@ -5050,6 +5048,12 @@ sub init_agent {
|
||||
# Optional args
|
||||
my $_oktorun = $args{oktorun} || sub { return $oktorun };
|
||||
|
||||
# Update these attribs every time the agent is initialized.
|
||||
# Other optional attribs, like versions, are left to the caller.
|
||||
chomp(my $hostname = `hostname`);
|
||||
$agent->{hostname} = $hostname;
|
||||
$agent->{user} = $ENV{USER} || $ENV{LOGNAME};
|
||||
|
||||
# Try forever to create/update the Agent. The tool can't
|
||||
# do anything without an Agent, so we must succeed to proceed.
|
||||
while ( $_oktorun->() ) {
|
||||
@@ -5188,27 +5192,34 @@ sub run_agent {
|
||||
# Load and update the local (i.e. existing) agent, or create a new one.
|
||||
my ($action, $link);
|
||||
if ( !$agent ) {
|
||||
$agent = load_local_agent (
|
||||
if ( $agent_uuid ) {
|
||||
_info("Re-creating Agent with UUID $agent_uuid");
|
||||
$agent = Percona::WebAPI::Resource::Agent->new(
|
||||
uuid => $agent_uuid,
|
||||
versions => $versions,
|
||||
);
|
||||
}
|
||||
else {
|
||||
# First try to load the local agent.
|
||||
$agent = load_local_agent(
|
||||
lib_dir => $lib_dir,
|
||||
agent_uuid => $agent_uuid,
|
||||
);
|
||||
if ( $agent ) {
|
||||
# Loaded (or re-created) local agent.
|
||||
# Loaded local agent.
|
||||
$action = 'put'; # update
|
||||
$link = $entry_links->{agents} . '/' . $agent->uuid;
|
||||
$agent->{versions} = $versions;
|
||||
}
|
||||
else {
|
||||
# No local agent and --agent-uuid wasn't give.
|
||||
chomp(my $hostname = `hostname`);
|
||||
$agent = Percona::WebAPI::Resource::Agent->new(
|
||||
hostname => $hostname,
|
||||
versions => $versions,
|
||||
);
|
||||
$action = 'post'; # create
|
||||
$link = $entry_links->{agents};
|
||||
}
|
||||
}
|
||||
}
|
||||
$agent = init_agent(
|
||||
agent => $agent,
|
||||
action => $action,
|
||||
|
@@ -40,6 +40,12 @@ has 'alias' => (
|
||||
required => 0,
|
||||
);
|
||||
|
||||
has 'user' => (
|
||||
is => 'ro',
|
||||
isa => 'Str',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
has 'versions' => (
|
||||
is => 'ro',
|
||||
isa => 'Maybe[HashRef]',
|
||||
|
Reference in New Issue
Block a user