1 |
|
## ------------------------------------------------------------------------- |
2 |
|
## |
3 |
## $Id$ |
## $Id$ |
4 |
## |
## |
5 |
## Copyright (c) 2002 Andreas Motl <andreas.motl@ilo.de> |
## Copyright (c) 2002 Andreas Motl <andreas.motl@ilo.de> |
6 |
## |
## |
7 |
## See COPYRIGHT section in pod text below for usage and distribution rights. |
## See COPYRIGHT section in associated pod text |
8 |
|
## or below for usage and distribution rights. |
9 |
## |
## |
10 |
## ---------------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------- |
11 |
## $Log$ |
## $Log$ |
12 |
|
## Revision 1.9 2003/05/13 08:16:44 joko |
13 |
|
## minor update: modified header |
14 |
|
## |
15 |
|
## Revision 1.8 2003/03/27 15:31:15 joko |
16 |
|
## fixes to modules regarding new namespace(s) below Data::Mungle::* |
17 |
|
## |
18 |
|
## Revision 1.7 2003/02/21 08:00:24 joko |
19 |
|
## debugging |
20 |
|
## |
21 |
|
## Revision 1.6 2003/02/14 12:58:47 joko |
22 |
|
## + re-enabled the erase-mechanism |
23 |
|
## |
24 |
|
## Revision 1.5 2003/02/11 05:26:04 joko |
25 |
|
## + sub _tellWhatIWillDo |
26 |
|
## + re-enabled "branch to execution path for special targets" mechanism |
27 |
|
## |
28 |
|
## Revision 1.4 2003/02/09 05:03:02 joko |
29 |
|
## + minor fix regarding namespace of api versioning extension module |
30 |
|
## |
31 |
## Revision 1.3 2003/02/09 04:59:27 joko |
## Revision 1.3 2003/02/09 04:59:27 joko |
32 |
## + api versioning mechanism |
## + api versioning mechanism |
33 |
## + major structure changes |
## + major structure changes |
57 |
use Data::Dumper; |
use Data::Dumper; |
58 |
use Hash::Merge qw( merge ); |
use Hash::Merge qw( merge ); |
59 |
|
|
60 |
use Data::Compare::Struct qw( isEmpty ); |
use Data::Mungle::Compare::Struct qw( isEmpty ); |
61 |
|
|
62 |
# get logger instance |
# get logger instance |
63 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
77 |
$logger->debug( __PACKAGE__ . "->loadVersionExtensions( version='$syncVersion' )"); |
$logger->debug( __PACKAGE__ . "->loadVersionExtensions( version='$syncVersion' )"); |
78 |
#print Dumper($self); |
#print Dumper($self); |
79 |
#exit; |
#exit; |
80 |
my $module = "Version::$syncVersion"; |
my $module = "API::$syncVersion"; |
81 |
$self->load($module); |
$self->load($module); |
82 |
} |
} |
83 |
|
|
85 |
sub configure { |
sub configure { |
86 |
my $self = shift; |
my $self = shift; |
87 |
|
|
|
#print "YAI\n"; |
|
|
#print Dumper(@_); |
|
|
#exit; |
|
|
|
|
88 |
$logger->debug( __PACKAGE__ . "->configure"); |
$logger->debug( __PACKAGE__ . "->configure"); |
89 |
|
|
90 |
my @args = @_; |
my @args = @_; |
91 |
|
|
|
#print Dumper(@args); |
|
|
|
|
92 |
if (!isEmpty(\@args)) { |
if (!isEmpty(\@args)) { |
93 |
my %properties = @_; |
my %properties = @_; |
94 |
# merge args to properties |
# merge args to properties |
163 |
my $self = shift; |
my $self = shift; |
164 |
my $args = shift; |
my $args = shift; |
165 |
|
|
166 |
|
#$logger->notice( "========================== " . __PACKAGE__ . "->syncNodes =============="); |
167 |
$logger->debug( __PACKAGE__ . "->syncNodes: starting" ); |
$logger->debug( __PACKAGE__ . "->syncNodes: starting" ); |
168 |
|
|
169 |
#print Dumper($self); |
#print Dumper($self); |
172 |
#print Dumper($self->{options}); |
#print Dumper($self->{options}); |
173 |
$self->_prepareOptions(); |
$self->_prepareOptions(); |
174 |
|
|
175 |
#print Dumper($self->{options}); |
# trace |
176 |
|
#print Dumper($self->{options}); |
177 |
|
#exit; |
178 |
|
|
179 |
if (!$self->checkOptions()) { |
if (!$self->checkOptions()) { |
180 |
$logger->critical( __PACKAGE__ . "->syncNodes: 'Data::Transfer::Sync::checkOptions' failed."); |
$logger->critical( __PACKAGE__ . "->syncNodes: 'Data::Transfer::Sync::checkOptions' failed."); |
186 |
return; |
return; |
187 |
} |
} |
188 |
|
|
189 |
|
#print Dumper($args); |
190 |
|
|
191 |
# remember arguments through the whole processing |
# remember arguments through the whole processing |
192 |
$self->{args} = $args; |
$self->{args} = $args; |
193 |
|
|
197 |
# hash to sum up results |
# hash to sum up results |
198 |
# TODO: re-implement! (sync-statistics???) |
# TODO: re-implement! (sync-statistics???) |
199 |
|
|
200 |
|
#print Dumper($self->{options}->{process}); |
201 |
|
|
202 |
# detect synchronization method to determine which optical symbol (directed arrow) to use |
# detect synchronization method to determine which optical symbol (directed arrow) to use |
203 |
my $mode = $self->{args}->{mode}; # V1 |
my $mode = $self->{args}->{mode}; # V1 |
204 |
$mode ||= $self->{options}->{process}->{mode}; # V2 |
$mode ||= $self->{options}->{process}->{mode}; # V2 |
219 |
$self->options2metadata(); |
$self->options2metadata(); |
220 |
$self->options2metadata_accessor(); |
$self->options2metadata_accessor(); |
221 |
|
|
222 |
|
# branch to execution path for special targets |
223 |
|
# detect for option 'handler' which could be a CODEref |
224 |
|
if ($self->{options}->{handler} && ref $self->{options}->{handler} eq 'CODE') { |
225 |
|
$logger->info( __PACKAGE__ . "->syncNodes: Running (special handler code - no generic sync!) on '$self->{options}->{target}->{dbKey}' with MODE $self->{options}->{process}->{mode}, NODE $self->{options}->{target}->{address}"); |
226 |
|
#print Dumper($self); |
227 |
|
#exit; |
228 |
|
# don't do this any more - it wasn't very nice somehow ... |
229 |
|
#$self->{options}->{handler}->($self->{app}, $self->{options}); |
230 |
|
# .... now: better let the parent application scope handle this via callback |
231 |
|
# not any more required for this: $self->{app} inside here (which isn't the app we mean here) |
232 |
|
# required for this: getting the options out of here: establish some getter method! ($self->getOptions(...)) |
233 |
|
# so.... |
234 |
|
#$self->{__bridge}->{parent_ref}-> |
235 |
|
|
236 |
|
# ahh okay, DesignPattern::Bridge moves closer to some Class::Inner!??? |
237 |
|
# so... |
238 |
|
# similar like above - but it isn't very nice anyway ... (no privateness, but: who cares?) |
239 |
|
#print Dumper($self->{__bridge}); |
240 |
|
# just take the global application instance and |
241 |
|
# throw it into the context of the mapping module - this is heavy! ;-) (but again, who cares...) |
242 |
|
# TODO: handle this more abstract *sometime* |
243 |
|
#$self->{options}->{handler}->($self->{__bridge}->{parent}->{app}, $self->{options}); |
244 |
|
$self->{options}->{handler}->($self->{__bridge}->{parent}->{process}, $self->{options}); |
245 |
|
|
246 |
|
return; |
247 |
|
} |
248 |
|
|
249 |
|
# TODO: execution path branch V2!!! |
250 |
|
# option1: wrap this via callback to parent scope (like current impl. mechanism) |
251 |
|
# option2: branch directly from here (this needs refactoring of the sub handler) |
252 |
|
|
253 |
# tracing |
# tracing |
254 |
#print Dumper($self); |
#print Dumper($self); |
255 |
#exit; |
#exit; |
256 |
|
|
257 |
$logger->info( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbKey}/$self->{meta}->{source}->{nodeName} [$self->{meta}->{source}->{nodeType}] $direction_arrow target=$self->{meta}->{target}->{dbKey}/$self->{meta}->{target}->{nodeName} [$self->{meta}->{target}->{nodeType}]" ); |
# V1: |
258 |
|
$logger->debug( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbKey}/$self->{meta}->{source}->{nodeName} [$self->{meta}->{source}->{nodeType}] $direction_arrow target=$self->{meta}->{target}->{dbKey}/$self->{meta}->{target}->{nodeName} [$self->{meta}->{target}->{nodeType}]" ); |
259 |
|
|
260 |
|
# V2: |
261 |
|
my $what = "$self->{meta}->{source}->{dbKey}/$self->{meta}->{source}->{nodeName} [$self->{meta}->{source}->{nodeType}] $direction_arrow $self->{meta}->{target}->{dbKey}/$self->{meta}->{target}->{nodeName} [$self->{meta}->{target}->{nodeType}]"; |
262 |
|
#my $header = ("~.." x 7) . " " . $what . " " . ("~.." x 4); |
263 |
|
#my $header = ("= " x 7) . " " . $what . " " . ("= " x 4); |
264 |
|
#my $header = ("~=-_-=" x 3) . " " . $what . " " . ("~=-_-=" x 4); |
265 |
|
my $header = ("_-=~=-" x 4) . " " . $what . " " . ("_-=~=-" x 4); |
266 |
|
$logger->notice($header); |
267 |
|
|
268 |
|
|
269 |
return if !$self->buildFieldmapping(); |
return if !$self->buildFieldmapping(); |
270 |
return if !$self->_touchNodeSet(); |
return if !$self->_touchNodeSet(); |
271 |
return if !$self->_prepare_sync(); |
return if !$self->_prepare_sync(); |
272 |
|
$self->_tellWhatIWillDo(); |
273 |
|
|
274 |
# tracing |
# tracing |
275 |
#print Dumper($self); |
#print Dumper($self); |
285 |
} |
} |
286 |
|
|
287 |
|
|
288 |
|
my $c_string_default = ''; |
289 |
|
sub c_string { |
290 |
|
my $value = shift; |
291 |
|
$value ||= "[$c_string_default]"; |
292 |
|
return $value; |
293 |
|
} |
294 |
|
|
295 |
|
sub _tellWhatIWillDo { |
296 |
|
my $self = shift; |
297 |
|
|
298 |
|
|
299 |
|
#return; |
300 |
|
|
301 |
|
# trace |
302 |
|
#print Dumper($self->{meta}); |
303 |
|
#exit; |
304 |
|
|
305 |
|
$c_string_default = 'n/a'; |
306 |
|
my $source = c_string($self->{opt}->{'source'}); |
307 |
|
my $source_node = c_string($self->{opt}->{'source-node'}); |
308 |
|
my $source_type = c_string($self->{opt}->{'source-type'}); |
309 |
|
my $target = c_string($self->{opt}->{'target'}); |
310 |
|
my $target_node = c_string($self->{opt}->{'target-node'}); |
311 |
|
my $target_type = c_string($self->{opt}->{'target-type'}); |
312 |
|
|
313 |
|
my $mapping_module = c_string($self->{opt}->{'mapping-module'}); |
314 |
|
my $mode = uc c_string($self->{opt}->{'mode'}); |
315 |
|
|
316 |
|
#my $ql = "$mode INTO $source NODE $source_node TYPE $source_type SELECT NODE $target_node TYPE $target_type FROM $target USING MODULE $mapping_module;"; |
317 |
|
#$logger->notice( __PACKAGE__ . ": $ql" ); |
318 |
|
my $ql = <<EOT; |
319 |
|
|
320 |
|
FETCH DATA |
321 |
|
FROM STORAGE $self->{meta}->{source}->{dbKey} |
322 |
|
AT NODE $self->{meta}->{source}->{accessorName}.$self->{meta}->{source}->{nodeName} |
323 |
|
USING IDENTIFIER $self->{meta}->{source}->{IdentProvider}->{method}.$self->{meta}->{source}->{IdentProvider}->{arg} |
324 |
|
CONVERT DATA |
325 |
|
CAST FROM $self->{meta}->{source}->{nodeType} TO $self->{meta}->{target}->{nodeType} |
326 |
|
MAP ATTRIBUTES FROM @{$self->{meta}->{source}->{childnodes}} TO @{$self->{meta}->{target}->{childnodes}} |
327 |
|
STORE DATA |
328 |
|
TO STORAGE $self->{meta}->{target}->{dbKey} |
329 |
|
AT NODE $self->{meta}->{target}->{accessorName}.$self->{meta}->{target}->{nodeName} |
330 |
|
USING IDENTIFIER $self->{meta}->{target}->{IdentProvider}->{method}.$self->{meta}->{target}->{IdentProvider}->{arg} |
331 |
|
EOT |
332 |
|
|
333 |
|
|
334 |
|
chomp($ql); |
335 |
|
$logger->info($ql); |
336 |
|
|
337 |
|
#exit; |
338 |
|
return; |
339 |
|
|
340 |
|
my $actioning = ucfirst $self->{opt}->{'action'} . 'ing'; |
341 |
|
|
342 |
|
# FIXME: this is weird! |
343 |
|
my $long = <<EOT; |
344 |
|
|
345 |
|
- $actioning data of type $target_type and |
346 |
|
filtered by $target_node from the storage named $target |
347 |
|
to the storage named $source - filtered by $source_node. |
348 |
|
- Will attempt to convert the data to $source_type. |
349 |
|
EOT |
350 |
|
chomp($long); |
351 |
|
$logger->notice( __PACKAGE__ . ": $long" ); |
352 |
|
|
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
sub _prepareOptions { |
sub _prepareOptions { |
357 |
|
|
358 |
my $self = shift; |
my $self = shift; |
441 |
# merging - V2 |
# merging - V2 |
442 |
|
|
443 |
# merge local map with local opts |
# merge local map with local opts |
444 |
|
|
445 |
|
# delete undef'd items in $map |
446 |
|
|
447 |
# enable cloning |
# enable cloning |
448 |
# FIXME: do we really need cloning here? trade safety/encapsulation for speed? |
# FIXME: do we really need cloning here? trade safety/encapsulation for speed? |
449 |
Hash::Merge::set_clone_behavior(1); |
Hash::Merge::set_clone_behavior(1); |
450 |
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
451 |
|
#Hash::Merge::set_behavior( 'STORAGE_PRECEDENT' ); |
452 |
|
#Hash::Merge::set_behavior( 'RETAINMENT_PRECEDENT' ); |
453 |
|
# TODO: add an option to Hash::Merge not to overwrite set items with undefined/empty/not assigned ones |
454 |
my $locals_merged = merge( $opts, $map ); |
my $locals_merged = merge( $opts, $map ); |
455 |
|
|
456 |
# trace |
# trace |
536 |
# TODO: introduce different mechanism to make more then two partners (descents) possible |
# TODO: introduce different mechanism to make more then two partners (descents) possible |
537 |
($self->{meta}->{source}, $self->{meta}->{target}) = |
($self->{meta}->{source}, $self->{meta}->{target}) = |
538 |
($self->{meta}->{target}, $self->{meta}->{source}); |
($self->{meta}->{target}, $self->{meta}->{source}); |
539 |
|
#($self->{options}->{source}, $self->{options}->{target}) = |
540 |
|
# ($self->{options}->{target}, $self->{options}->{source}); |
541 |
|
|
542 |
} elsif (lc $self->{options}->{process}->{mode} eq 'full') { |
} elsif (lc $self->{options}->{process}->{mode} eq 'full') { |
543 |
# TODO: |
# TODO: |
551 |
|
|
552 |
# import flag means: prepare the source node to be syncable |
# import flag means: prepare the source node to be syncable |
553 |
# this is useful if there are e.g. no "ident" or "checksum" columns yet inside a DBI like (row-based) storage |
# this is useful if there are e.g. no "ident" or "checksum" columns yet inside a DBI like (row-based) storage |
554 |
if ($self->{args}->{prepare}) { |
if ($self->{options}->{process}->{prepare}) { |
555 |
$self->_prepareNode_MetaProperties('source'); |
$self->_prepareNode_MetaProperties('source'); |
556 |
$self->_prepareNode_DummyIdent('source'); |
$self->_prepareNode_DummyIdent('source'); |
557 |
#return; |
#return; |
560 |
|
|
561 |
# erase flag means: erase the target |
# erase flag means: erase the target |
562 |
#if ($opts->{erase}) { |
#if ($opts->{erase}) { |
563 |
if ($self->{args}->{erase}) { |
if ($self->{options}->{process}->{erase}) { |
564 |
# TODO: move this method to the scope of the synchronization core and wrap it around different handlers |
# TODO: move this method to the scope of the synchronization core and wrap it around different handlers |
565 |
#print "ERASE", "\n"; |
#print "ERASE", "\n"; |
566 |
$self->_erase_all('target'); |
$self->_erase_all('target'); |