mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Test and implement more run_agent(). Fix as_json() for lists of resources. Add alias attrib to Service for its friendly name; make name its code-friendly name. Fix ts in log messages.
This commit is contained in:
@@ -44,14 +44,27 @@ sub as_hashref {
|
||||
}
|
||||
|
||||
sub as_json {
|
||||
return encode_json(as_hashref(@_));
|
||||
my $resource = shift;
|
||||
|
||||
my $json = JSON->new;
|
||||
$json->allow_blessed([]);
|
||||
$json->convert_blessed([]);
|
||||
|
||||
return $json->encode(
|
||||
ref $resource eq 'ARRAY' ? $resource : as_hashref($resource)
|
||||
);
|
||||
}
|
||||
|
||||
sub as_config {
|
||||
my $as_hashref = as_hashref(@_);
|
||||
my $resource = shift;
|
||||
if ( !$resource->isa('Percona::WebAPI::Resource::Config') ) {
|
||||
die "Only Config resources can be represented as config.\n";
|
||||
}
|
||||
my $as_hashref = as_hashref($resource);
|
||||
my $options = $as_hashref->{options};
|
||||
my $config = join("\n",
|
||||
map { defined $as_hashref->{$_} ? "$_=$as_hashref->{$_}" : "$_" }
|
||||
sort keys %$as_hashref
|
||||
map { defined $options->{$_} ? "$_=$options->{$_}" : "$_" }
|
||||
sort keys %$options
|
||||
) . "\n";
|
||||
return $config;
|
||||
}
|
||||
|
@@ -28,6 +28,12 @@ has 'name' => (
|
||||
required => 1,
|
||||
);
|
||||
|
||||
has 'alias' => (
|
||||
is => 'ro',
|
||||
isa => 'Str',
|
||||
required => 1,
|
||||
);
|
||||
|
||||
has 'schedule' => (
|
||||
is => 'ro',
|
||||
isa => 'Str',
|
||||
|
@@ -33,7 +33,7 @@ sub resource_diff {
|
||||
return 0 if !$x && !$y;
|
||||
return 1 if ($x && !$y) || (!$x && $y);
|
||||
return md5_hex(Percona::WebAPI::Representation::as_json($x))
|
||||
cmp md5_hex(Percona::WebAPI::Representation::as_json($y));
|
||||
ne md5_hex(Percona::WebAPI::Representation::as_json($y));
|
||||
}
|
||||
|
||||
1;
|
||||
|
Reference in New Issue
Block a user