1 |
joko |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
## -------------------------------------------------------------------------------- |
4 |
joko |
1.2 |
## $Id: AbstractFeeder.pm,v 1.1 2003/02/09 16:27:06 joko Exp $ |
5 |
joko |
1.1 |
## -------------------------------------------------------------------------------- |
6 |
joko |
1.2 |
## $Log: AbstractFeeder.pm,v $ |
7 |
|
|
## Revision 1.1 2003/02/09 16:27:06 joko |
8 |
|
|
## + initial commit |
9 |
|
|
## |
10 |
joko |
1.1 |
## -------------------------------------------------------------------------------- |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
package OEF::Script::AbstractFeeder; |
14 |
|
|
|
15 |
|
|
use strict; |
16 |
|
|
use warnings; |
17 |
|
|
|
18 |
|
|
#use base 'OEF::Component::Task'; |
19 |
|
|
use base qw( |
20 |
|
|
DesignPattern::Object |
21 |
|
|
DesignPattern::Object::Logger |
22 |
|
|
); |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
use Data::Dumper; |
26 |
|
|
use Getopt::Long; |
27 |
|
|
|
28 |
|
|
|
29 |
|
|
# get logger instance |
30 |
|
|
my $logger = Log::Dispatch::Config->instance; |
31 |
|
|
|
32 |
|
|
sub usage { |
33 |
|
|
my $self = shift; |
34 |
|
|
print "\n"; |
35 |
|
|
print <<EOU; |
36 |
|
|
usage: |
37 |
|
|
feed.pl --source=<dbkey> --node=<node> --target=<dbkey> --action=<action> [--mapping=] |
38 |
|
|
|
39 |
|
|
source: dbkey links to a configuration resource representing a storage (~= database) |
40 |
|
|
node: the name of a node on the first level below the source storage |
41 |
|
|
target: dbkey links to a configuration resource representing a storage |
42 |
|
|
action: <action> is issued on given dbkey as source node |
43 |
|
|
sync FULL sync (PULL & PUSH) |
44 |
|
|
load|save PULL or PUSH syncs |
45 |
|
|
import|export IMPORT and EXPORT syncs |
46 |
|
|
mapping: future use: specify name of a perl module / xml file which describes/outlines the mapping |
47 |
|
|
EOU |
48 |
|
|
exit; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
sub getoptions { |
52 |
|
|
my $self = shift; |
53 |
|
|
|
54 |
|
|
GetOptions( |
55 |
|
|
'source=s' => \$self->{opt}->{source}, |
56 |
|
|
'source-type=s' => \$self->{opt}->{'source-type'}, |
57 |
|
|
'source-node=s' => \$self->{opt}->{'source-node'}, |
58 |
|
|
'target=s' => \$self->{opt}->{target}, |
59 |
|
|
'target-node=s' => \$self->{opt}->{'target-node'}, |
60 |
|
|
'action=s' => \$self->{opt}->{action}, |
61 |
|
|
'mapping-module=s' => \$self->{opt}->{'mapping-module'}, |
62 |
|
|
'prepare' => \$self->{opt}->{prepare}, |
63 |
|
|
'fresh' => \$self->{opt}->{fresh}, |
64 |
|
|
'help' => \&usage, |
65 |
|
|
# v1-API-spec backward compatibility |
66 |
|
|
'node=s' => \$self->{opt}->{'node'}, |
67 |
|
|
); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
sub getoptions_old { |
71 |
|
|
my $self = shift; |
72 |
|
|
GetOptions( |
73 |
|
|
'source=s' => \$self->{opt}->{source}, |
74 |
|
|
'node=s' => \$self->{opt}->{node}, |
75 |
|
|
'target=s' => \$self->{opt}->{target}, |
76 |
|
|
'action=s' => \$self->{opt}->{action}, |
77 |
|
|
'mapping=s' => \$self->{opt}->{mapping}, |
78 |
|
|
'prepare' => \$self->{opt}->{prepare}, |
79 |
|
|
'fresh' => \$self->{opt}->{fresh}, |
80 |
|
|
); |
81 |
|
|
|
82 |
|
|
# TODO: use some core function/method (e.g. 'init_hash($hashref, $value, $force = 0)') |
83 |
|
|
$self->{opt}->{source} ||= ''; |
84 |
|
|
$self->{opt}->{node} ||= ''; |
85 |
|
|
$self->{opt}->{target} ||= ''; |
86 |
|
|
$self->{opt}->{action} ||= ''; |
87 |
|
|
$self->{opt}->{mapping} ||= ''; |
88 |
|
|
$self->{opt}->{prepare} ||= ''; |
89 |
|
|
$self->{opt}->{fresh} ||= ''; |
90 |
|
|
|
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
|
94 |
|
|
sub set { |
95 |
|
|
my $self = shift; |
96 |
|
|
my $data = { @_ }; |
97 |
|
|
#return bless $self, $class; |
98 |
|
|
foreach (keys %$data) { |
99 |
|
|
#print $_, "\n"; |
100 |
|
|
$self->{$_} = $data->{$_}; |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
sub run { |
105 |
|
|
my $self = shift; |
106 |
|
|
$self->_before_run(); |
107 |
|
|
$self->prepare(); |
108 |
joko |
1.2 |
#$self->tellWhatIAmDoing(); |
109 |
joko |
1.1 |
$self->sync(); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
sub prepare { |
113 |
|
|
my $self = shift; |
114 |
|
|
|
115 |
|
|
# TODO: |
116 |
|
|
# - move this to Data::Transfer::Sync::checkOptions!!! |
117 |
|
|
# - use 'syncable'??? |
118 |
|
|
|
119 |
|
|
#if ($self->{app}->{config}->{databases}->{$self->{opt}->{target}}->{syncable}) { |
120 |
|
|
|
121 |
|
|
my $mode = ''; |
122 |
|
|
my $erase = 0; |
123 |
|
|
my $import = 0; |
124 |
|
|
$mode = 'PUSH' if $self->{opt}->{action} eq 'save'; |
125 |
|
|
$mode = 'PULL' if $self->{opt}->{action} eq 'load'; |
126 |
|
|
if ($self->{opt}->{action} eq 'import') { |
127 |
|
|
$mode = 'PULL'; |
128 |
|
|
$erase = 1; |
129 |
|
|
$import = 1; |
130 |
|
|
} |
131 |
|
|
if ($self->{opt}->{action} eq 'export') { |
132 |
|
|
$mode = 'PUSH'; |
133 |
|
|
$erase = 1; |
134 |
|
|
#$import = 1; |
135 |
|
|
} |
136 |
|
|
$self->{opt}->{mode} = $mode; |
137 |
|
|
$self->{opt}->{erase} = $erase; |
138 |
|
|
$self->{opt}->{import} = $import; |
139 |
|
|
|
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
sub sync { |
143 |
|
|
my $self = shift; |
144 |
|
|
|
145 |
|
|
# trace |
146 |
|
|
#print Dumper($self); |
147 |
|
|
#print Dumper($self->{opt}); |
148 |
|
|
#exit; |
149 |
|
|
|
150 |
|
|
# proposal to introduce full backward-compatibility mechanism |
151 |
|
|
# "just" have many APIs with different versions accessing the very same core ... |
152 |
|
|
# is api-version specified? |
153 |
|
|
my $sync_version = $self->{opt}->{sv}; |
154 |
|
|
$sync_version ||= 'V1'; |
155 |
|
|
|
156 |
|
|
# create a new synchronization object |
157 |
joko |
1.2 |
my $sync = Data::Transfer::Sync->new( 'sync_version' => $sync_version, __parent => $self ); |
158 |
joko |
1.1 |
|
159 |
|
|
# trace |
160 |
|
|
#print Dumper($self); |
161 |
joko |
1.2 |
#print Dumper($self); |
162 |
|
|
#exit; |
163 |
|
|
|
164 |
joko |
1.1 |
|
165 |
|
|
# configure the synchronization-object |
166 |
|
|
$sync->configure( |
167 |
|
|
source => { |
168 |
|
|
storage => { |
169 |
|
|
#handle => $mapiStorage, |
170 |
|
|
handle => $self->{app}->{$self->{opt}->{source}}, |
171 |
joko |
1.2 |
#isIdentAuthority => $self->{app}->{config}->{{$self->{opt}->{source}}, |
172 |
|
|
#isChecksumAuthority => 1, |
173 |
|
|
#writeProtected => 1, |
174 |
joko |
1.1 |
}, |
175 |
|
|
}, |
176 |
|
|
target => { |
177 |
|
|
storage => { |
178 |
|
|
#handle => $ldapStorage, |
179 |
|
|
handle => $self->{app}->{$self->{opt}->{target}}, |
180 |
joko |
1.2 |
#idAuthority => 1, |
181 |
|
|
#isChecksumAuthority => 1, |
182 |
|
|
#isWriteProtected => 0, |
183 |
joko |
1.1 |
}, |
184 |
|
|
}, |
185 |
|
|
verbose => 1, |
186 |
|
|
); |
187 |
joko |
1.2 |
|
188 |
|
|
# TODO: |
189 |
|
|
=pod |
190 |
|
|
$sync->configure( |
191 |
|
|
'source.storage.handle' => ..., |
192 |
|
|
'target.storage.handle' => ..., |
193 |
|
|
); |
194 |
|
|
=cut |
195 |
joko |
1.1 |
|
196 |
|
|
# trace |
197 |
|
|
#print Dumper($sync); |
198 |
|
|
#exit; |
199 |
|
|
|
200 |
|
|
# read, mungle & check the options |
201 |
|
|
$sync->setArguments($self->{opt}); |
202 |
|
|
$sync->readArguments(); |
203 |
|
|
|
204 |
|
|
# trace |
205 |
|
|
#print Dumper($sync); |
206 |
|
|
|
207 |
|
|
# finally, run the sync ... |
208 |
|
|
$sync->syncNodes(); |
209 |
|
|
|
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
|
213 |
|
|
1; |