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:
Daniel Nichter
2012-12-26 17:44:19 -07:00
parent 66fb54e793
commit 0495f9aa8a
7 changed files with 318 additions and 47 deletions

View File

@@ -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;
}

View File

@@ -28,6 +28,12 @@ has 'name' => (
required => 1,
);
has 'alias' => (
is => 'ro',
isa => 'Str',
required => 1,
);
has 'schedule' => (
is => 'ro',
isa => 'Str',

View File

@@ -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;