[Bps-public-commit] r14912 - in Prophet/trunk: . lib/Prophet/CLI/Command
jesse at bestpractical.com
jesse at bestpractical.com
Fri Aug 8 02:02:44 EDT 2008
Author: jesse
Date: Fri Aug 8 02:02:43 2008
New Revision: 14912
Modified:
Prophet/trunk/Makefile.PL
Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm
Prophet/trunk/lib/Prophet/Server.pm
Log:
* Added support for pulling replicas over Bonjour
* Added support for announcing replicas over bonjour when using the standalone server
Modified: Prophet/trunk/Makefile.PL
==============================================================================
--- Prophet/trunk/Makefile.PL (original)
+++ Prophet/trunk/Makefile.PL Fri Aug 8 02:02:43 2008
@@ -23,12 +23,13 @@
requires('MooseX::AttributeHelpers' => '0.12');
requires('MooseX::ClassAttribute' => '0.04');
requires('XML::Atom::SimpleFeed');
-
+requires('Net::Bonjour');
features(
'Web server' => [
-default => 1,
'HTTP::Server::Simple', # HTTP::Server::Simple::CGI
'Test::WWW::Mechanize' => '1.16',
+ 'HTTP::Server::Simple::Bonjour'
],
'HTML display' => [
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm Fri Aug 8 02:02:43 2008
@@ -3,33 +3,67 @@
extends 'Prophet::CLI::Command::Merge';
override run => sub {
- my $self = shift;
+ my $self = shift;
my @from;
- my $from = $self->arg('from');
- push @from, $from if $from;
+ $self->set_arg( db_uuid => $self->app_handle->handle->db_uuid )
+ unless ($self->arg('db_uuid'));
+
+ push @from, $self->arg('from') if $self->arg('from');
- my %replicas = $self->_read_cached_upstream_replicas;
- push @from, keys %replicas
- if $self->has_arg('all');
-
- die "Please specify a --from, or --all.\n" if @from == 0;
-
- $self->set_arg(to => $self->cli->app_handle->default_replica_type.":file://".$self->cli->app_handle->handle->fs_root);
- $self->set_arg(db_uuid => $self->app_handle->handle->db_uuid);
-
- for my $from (@from) {
- print "Pulling from $from\n" if $self->has_arg('all');
- $self->set_arg(from => $from);
- super();
+ my %previous_sources = $self->_read_cached_upstream_replicas;
+ push @from, keys %previous_sources if $self->has_arg('all');
+
+ my @bonjour_replicas = $self->find_bonjour_replicas;
+
+ die "Please specify a --from, --local or --all.\n"
+ unless ( $self->has_arg('from')
+ || $self->has_arg('local')
+ || $self->has_arg('all') );
+
+ $self->set_arg( to => $self->cli->app_handle->default_replica_type
+ . ":file://"
+ . $self->cli->app_handle->handle->fs_root );
+
+ for my $from ( @from, @bonjour_replicas ) {
+ print "Pulling from $from\n";
+ #if ( $self->has_arg('all') || $self->has_arg('local') );
+ $self->set_arg( from => $from );
+ super();
}
- if ($from && !exists $replicas{$from}) {
- $replicas{$from} = 1;
- $self->_write_cached_upstream_replicas(%replicas);
+ if ( $self->arg('from') && !exists $previous_sources{$self->arg('from')} ) {
+ $previous_sources{$self->arg('from')} = 1;
+ $self->_write_cached_upstream_replicas(%previous_sources);
}
};
+sub find_bonjour_replicas {
+ my $self = shift;
+ my @bonjour_replicas;
+ if ( $self->has_arg('local') ) {
+ Prophet::App->try_to_require('Net::Bonjour');
+ if ( Prophet::App->already_required('Net::Bonjour') ) {
+ print "Probing for local database replicas with Bonjour\n";
+ my $res = Net::Bonjour->new('prophet');
+ $res->discover;
+ foreach my $entry ( $res->entries ) {
+ if ( $entry->name eq $self->arg('db_uuid') ) {
+ print "Found a database replica on " . $entry->hostname."\n";
+ my $uri = URI->new();
+ $uri->scheme( 'http' );
+ $uri->host($entry->hostname);
+ $uri->port( $entry->port );
+ $uri->path('replica/');
+ push @bonjour_replicas, $uri->canonical.""; #scalarize
+ }
+ }
+ }
+
+ }
+ return @bonjour_replicas;
+}
+
sub _read_cached_upstream_replicas {
my $self = shift;
return map { $_ => 1 } $self->cli->app_handle->resdb_handle->_read_cached_upstream_replicas;
Modified: Prophet/trunk/lib/Prophet/Server.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Server.pm (original)
+++ Prophet/trunk/lib/Prophet/Server.pm Fri Aug 8 02:02:43 2008
@@ -1,21 +1,35 @@
package Prophet::Server;
-use Moose;
+use warnings;
+use strict;
Prophet::App->try_to_require('HTTP::Server::Simple::Bonjour');
if (Prophet::App->already_required('HTTP::Server::Simple::Bonjour')){
- extends 'HTTP::Server::Simple::Bonjour';
+ use base qw'HTTP::Server::Simple::Bonjour';
}
-extends 'HTTP::Server::Simple::CGI';
+use base qw'HTTP::Server::Simple::CGI';
+
+
use Prophet::Server::View;
use Params::Validate qw/:all/;
use JSON;
use Path::Class;
-has app_handle => (
- isa => 'Prophet::App',
- is => 'rw'
-);
+# Support for the bonjour replica type
+our $DB_UUID;
+sub service_name { $DB_UUID }
+sub service_type { '_prophet._tcp' }
+
+sub app_handle {
+ my $self = shift;
+ if (@_) {
+ $self->{'app_handle'} = shift;
+ $DB_UUID = $self->{'app_handle'}->handle->db_uuid;
+ }
+ return $self->{'app_handle'};
+}
+# we can't moose until we sort out HTTP::Server::Simple with bonjour
+#has app_handle => ( isa => 'Prophet::App', is => 'rw');
sub new {
my $class = shift;
More information about the Bps-public-commit
mailing list