/usr/share/perl5/Prophet/ReplicaExporter.pm is in libprophet-perl 0.750-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | package Prophet::ReplicaExporter;
use Any::Moose;
use Params::Validate qw(:all);
use File::Spec;
use Prophet::Record;
use Prophet::Collection;
has source_replica => (
is => 'rw',
isa => 'Prophet::Replica',
);
has target_path => (
is => 'rw',
isa => 'Str',
predicate => 'has_target_path',
);
has target_replica => (
is => 'rw',
isa => 'Prophet::Replica',
lazy => 1,
default => sub {
my $self = shift;
confess "No target_path specified" unless $self->has_target_path;
my $replica = Prophet::Replica->get_handle(url => "prophet:file://" . $self->target_path, app_handle => $self->app_handle);
my $src = $self->source_replica;
my %init_args = (
db_uuid => $src->db_uuid,
);
$init_args{resdb_uuid} = $src->resolution_db_handle->db_uuid
if !$src->is_resdb;
$replica->initialize(%init_args);
return $replica;
},
);
has app_handle => (
is => 'ro',
isa => 'Prophet::App',
weak_ref => 1,
predicate => 'has_app_handle',
);
=head1 NAME
Prophet::ReplicaExporter
=head1 DESCRIPTION
A utility class which exports a replica to a serialized on-disk format
=cut
=head1 METHODS
=head2 new
Instantiates a new replica exporter object
=cut
=head2 export
This routine will export a copy of this prophet database replica to a
flat file on disk suitable for publishing via HTTP or over a local
filesystem for other Prophet replicas to clone or incorporate changes
from.
=cut
sub export {
my $self = shift;
$self->init_export_metadata();
print " Exporting records...\n";
$self->export_all_records();
print " Exporting changesets...\n";
$self->export_changesets();
unless ($self->source_replica->is_resdb) {
my $resolutions = Prophet::ReplicaExporter->new(
target_path => File::Spec->catdir($self->target_path, 'resolutions' ),
source_replica => $self->source_replica->resolution_db_handle,
app_handle => $self->app_handle
);
print "Exporting resolution database\n";
$resolutions->export();
}
}
sub init_export_metadata {
my $self = shift;
$self->target_replica->set_latest_sequence_no(
$self->source_replica->latest_sequence_no );
$self->target_replica->set_replica_uuid( $self->source_replica->uuid );
}
sub export_all_records {
my $self = shift;
$self->export_records( type => $_ ) for ( @{ $self->source_replica->list_types } );
}
sub export_records {
my $self = shift;
my %args = validate( @_, { type => 1 } );
my $collection = Prophet::Collection->new(
app_handle => $self->app_handle,
handle => $self->source_replica,
type => $args{type}
);
$collection->matching( sub {1} );
$self->target_replica->_write_record( record => $_ ) for @$collection;
}
sub export_changesets {
my $self = shift;
for my $changeset (
@{ $self->source_replica->fetch_changesets( after => 0 ) } )
{
$self->target_replica->_write_changeset(
changeset => $changeset
);
}
}
__PACKAGE__->meta->make_immutable;
no Any::Moose;
1;
|