Skip to content

Commit

Permalink
Maintenance (#32)
Browse files Browse the repository at this point in the history
* Add support and tests for Maintenance status and defragment.

* Add support and tests for Maintenance class methods version, status and defragment

* Update POD

* Add is_success and content helper methods.

* Update version and change log for pending release.
  • Loading branch information
hexfusion authored Nov 23, 2017
1 parent 02369ae commit 6d34118
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 24 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
Revision history for Net::Etcd
0.016
[ ENHANCEMENTS ]
* Added status, defragment, version and status methods to Maintenance class.
* Added ability to check $etcd->version
* Add is_success and content helper methods to Action role.
* Updated POD.

0.015
[ ENHANCEMENTS ]
* Add ability to retry_auth. This feature is very useful for refreshing stale tokens. Closes GH #26
Expand Down
17 changes: 16 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ SYNOPSIS
$etcd = Net::Etcd->new({ host => $host, port => $port, ssl => 1 });

# put key
$result = $etcd->put({ key =>'foo1', value => 'bar' });
$put_key = $etcd->put({ key =>'foo1', value => 'bar' });

# check for success of a transaction
$put_key->is_success;

# get single key
$key = $etcd->range({ key =>'test0' });
Expand Down Expand Up @@ -50,6 +53,13 @@ SYNOPSIS
# grant role
$etcd->user_role( { user => 'samba', role => 'myrole' } )->grant;

# defrag member's backend database
$defrag = $etcd->maintenance()->defragment;
print "Defrag request complete!" if $defrag->is_success;

# member version
$v = $etcd->version;

DESCRIPTION
Net::Etcd is object oriented interface to the v3 REST API provided by
the etcd grpc-gateway <https://github.com/grpc-ecosystem/grpc-gateway>.
Expand Down Expand Up @@ -82,6 +92,11 @@ ACCESSORS
is changed.

PUBLIC METHODS
version
Returns the etcd member version

$etcd->version()

watch
See Net::Etcd::Watch

Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ Net::Etcd - etcd v3 REST API.
$etcd = Net::Etcd->new({ host => $host, port => $port, ssl => 1 });

# put key
$result = $etcd->put({ key =>'foo1', value => 'bar' });
$put_key = $etcd->put({ key =>'foo1', value => 'bar' });

# check for success of a transaction
$put_key->is_success;

# get single key
$key = $etcd->range({ key =>'test0' });
Expand Down Expand Up @@ -54,6 +57,13 @@ Net::Etcd - etcd v3 REST API.
# grant role
$etcd->user_role( { user => 'samba', role => 'myrole' } )->grant;

# defrag member's backend database
$defrag = $etcd->maintenance()->defragment;
print "Defrag request complete!" if $defrag->is_success;

# member version
$v = $etcd->version;

# DESCRIPTION

[Net::Etcd](https://metacpan.org/pod/Net::Etcd) is object oriented interface to the v3 REST API provided by the etcd [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway).
Expand Down Expand Up @@ -95,6 +105,12 @@ authentication process and stored until no longer valid or username is changed.

# PUBLIC METHODS

## version

Returns the etcd member version

$etcd->version()

## watch

See [Net::Etcd::Watch](https://metacpan.org/pod/Net::Etcd::Watch)
Expand Down
34 changes: 31 additions & 3 deletions lib/Net/Etcd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Net::Etcd - etcd v3 REST API.
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 SYNOPSIS
Expand All @@ -40,7 +40,10 @@ our $VERSION = '0.015';
$etcd = Net::Etcd->new({ host => $host, port => $port, ssl => 1 });
# put key
$result = $etcd->put({ key =>'foo1', value => 'bar' });
$put_key = $etcd->put({ key =>'foo1', value => 'bar' });
# check for success of a transaction
$put_key->is_success;
# get single key
$key = $etcd->range({ key =>'test0' });
Expand Down Expand Up @@ -81,11 +84,17 @@ our $VERSION = '0.015';
# grant role
$etcd->user_role( { user => 'samba', role => 'myrole' } )->grant;
# defrag member's backend database
$defrag = $etcd->maintenance()->defragment;
print "Defrag request complete!" if $defrag->is_success;
# member version
$v = $etcd->version;
=head1 DESCRIPTION
L<Net::Etcd> is object oriented interface to the v3 REST API provided by the etcd L<grpc-gateway|https://github.com/grpc-ecosystem/grpc-gateway>.
=head1 ACCESSORS
=head2 host
Expand Down Expand Up @@ -185,6 +194,25 @@ has auth_token => (

=head1 PUBLIC METHODS
=head2 version
Returns the etcd member version
$etcd->version()
=cut

sub version {
my ( $self, $options ) = @_;
my $cb = pop if ref $_[-1] eq 'CODE';
my $member = Net::Etcd::Maintenance->new(
etcd => $self,
cb => $cb,
( $options ? %$options : () ),
);
return $member->version;
}

=head2 watch
See L<Net::Etcd::Watch>
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Net::Etcd::Auth
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/Auth/Role.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Net::Etcd::Auth::Role
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/Auth/RolePermission.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Net::Etcd::Auth::RolePermission
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Net::Etcd::Config
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 ACCESSORS
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/KV.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Net::Etcd::KV
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/KV/Compare.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Net::Etcd::KV::Compare
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/KV/DeleteRange.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Net::Etcd::DeleteRange
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/KV/Op.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Net::Etcd::KV::Op
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/KV/Put.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Net::Etcd::Put
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
3 changes: 1 addition & 2 deletions lib/Net/Etcd/KV/Range.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use MIME::Base64;
use JSON;

with 'Net::Etcd::Role::Actions';
#extends 'Net::Etcd::KV';

use namespace::clean;

Expand All @@ -20,7 +19,7 @@ Net::Etcd::Range
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/KV/Txn.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Net::Etcd::KV::Txn
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Etcd/Lease.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Net::Etcd::Lease
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
58 changes: 57 additions & 1 deletion lib/Net/Etcd/Maintenance.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ Net::Etcd::Maintenance
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';
=head1 SYNOPSIS
# defrag member's backend database
$defrag = $etcd->maintenance()->defragment;
# check status
$status = $etcd->maintenance()->status;
# member version
$status = $etcd->version;
=head1 DESCRIPTION
Expand Down Expand Up @@ -56,4 +66,50 @@ sub snapshot {
return $self;
}

=head2 status
Status gets the status of the member.
=cut

sub status {
my ( $self, $options ) = @_;
my $cb = pop if ref $_[-1] eq 'CODE';
$self->{endpoint} = '/maintenance/status';
$self->{json_args} = '{}';
$self->request;
return $self;
}

=head2 defragment
Defragment defragments a member's backend database to recover storage space.
=cut

sub defragment {
my ( $self, $options ) = @_;
my $cb = pop if ref $_[-1] eq 'CODE';
$self->{endpoint} = '/maintenance/defragment';
$self->{json_args} = '{}';
$self->request;
return $self;
}

=head2 version
Returns the member version.
=cut

sub version {
my ( $self, $options ) = @_;
my $cb = pop if ref $_[-1] eq 'CODE';
my $status = $self->status;
if ( $status->is_success ) {
return $status->content->{version};
}
return;
}

1;
31 changes: 30 additions & 1 deletion lib/Net/Etcd/Role/Actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Net::Etcd::Role::Actions
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

has etcd => (
is => 'ro',
Expand Down Expand Up @@ -226,4 +226,33 @@ sub all {
return $kvs;
}

=head2 is_success
Success is returned if the response is a 200
=cut

sub is_success {
my ($self) = @_;
my $response = $self->response;
if ( defined $response->{success} ) {
return $response->{success};
}
return;
}

=head2 content
returns JSON decoded content hash
=cut

sub content {
my ($self) = @_;
my $response = $self->response;
my $content = from_json( $response->{content} );
return $content if $content;
return;
}

1;
2 changes: 1 addition & 1 deletion lib/Net/Etcd/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Net::Etcd::User
=cut

our $VERSION = '0.015';
our $VERSION = '0.016';

=head1 DESCRIPTION
Expand Down
Loading

0 comments on commit 6d34118

Please sign in to comment.