/[cvs]/nfo/perl/libs/Data/Transfer/Sync/Core.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Transfer/Sync/Core.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by joko, Sun Feb 9 05:01:10 2003 UTC revision 1.10 by joko, Wed Jun 25 23:03:57 2003 UTC
# Line 1  Line 1 
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 pod text below for usage and distribution rights.
8  ##  ##
9  ##    ----------------------------------------------------------------------------------------  ## -------------------------------------------------------------------------
10  ##    $Log$  ##    $Log$
11    ##    Revision 1.10  2003/06/25 23:03:57  joko
12    ##    no debugging
13    ##
14    ##    Revision 1.9  2003/05/13 08:17:52  joko
15    ##    buildAttributeMap now propagates error
16    ##
17    ##    Revision 1.8  2003/03/27 15:31:15  joko
18    ##    fixes to modules regarding new namespace(s) below Data::Mungle::*
19    ##
20    ##    Revision 1.7  2003/02/21 08:01:11  joko
21    ##    debugging, logging
22    ##    renamed module
23    ##
24    ##    Revision 1.6  2003/02/14 14:03:49  joko
25    ##    + logging, debugging
26    ##    - refactored code to sister module
27    ##
28    ##    Revision 1.5  2003/02/11 05:30:47  joko
29    ##    + minor fixes and some debugging mud
30    ##
31  ##    Revision 1.4  2003/02/09 05:01:10  joko  ##    Revision 1.4  2003/02/09 05:01:10  joko
32  ##    + major structure changes  ##    + major structure changes
33  ##    - refactored code to sister modules  ##    - refactored code to sister modules
# Line 52  Line 74 
74  ##    + minor cosmetics for logging  ##    + minor cosmetics for logging
75  ##  ##
76  ##    Revision 1.2  2002/12/01 04:43:25  joko  ##    Revision 1.2  2002/12/01 04:43:25  joko
77  ##    + mapping deatil entries may now be either an ARRAY or a HASH  ##    + mapping detail entries may now be either an ARRAY or a HASH
78  ##    + erase flag is used now (for export-operations)  ##    + erase flag is used now (for export-operations)
79  ##    + expressions to refer to values inside deep nested structures  ##    + expressions to refer to values inside deep nested structures
80  ##    - removed old mappingV2-code  ##    - removed old mappingV2-code
# Line 64  Line 86 
86  ##  ##
87  ##    Revision 1.1  2002/10/10 03:44:21  cvsjoko  ##    Revision 1.1  2002/10/10 03:44:21  cvsjoko
88  ##    + new  ##    + new
89  ##    ----------------------------------------------------------------------------------------  ## -------------------------------------------------------------------------
90    
91    
92  package Data::Transfer::Sync::Core;  package Data::Transfer::Sync::Core;
# Line 79  use mixin::with qw( Data::Transfer::Sync Line 101  use mixin::with qw( Data::Transfer::Sync
101    
102  use Data::Dumper;  use Data::Dumper;
103    
104  use misc::HashExt;  #use misc::HashExt;
105  use Data::Compare::Struct qw( getDifference isEmpty );  use Hash::Serializer;
106    use Data::Mungle::Compare::Struct qw( getDifference isEmpty );
107  use Data::Storage::Container;  use Data::Storage::Container;
108  use DesignPattern::Object;  use DesignPattern::Object;
109    use shortcuts::database qw( quotesql );
110    
111  # get logger instance  # get logger instance
112  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 113  sub _init { Line 137  sub _init {
137      $self->{container}->addStorage($_, $self->{storages}->{$_});      $self->{container}->addStorage($_, $self->{storages}->{$_});
138    }    }
139        
140      # trace
141        #print Dumper($self);
142        #exit;
143    
144    return 1;    return 1;
145        
146  }  }
# Line 140  sub _run { Line 168  sub _run {
168    $logger->debug( __PACKAGE__ . "->_run" );    $logger->debug( __PACKAGE__ . "->_run" );
169    
170    # for statistics    # for statistics
171    my $tc = OneLineDumpHash->new( {} );    my $tc = Hash::Serializer->new( {} );
172    my $results;    my $results;
173        
174    # set of objects is already in $self->{args}    # set of objects is already in $self->{args}
# Line 157  sub _run { Line 185  sub _run {
185    # get reference to node list from convenient method provided by CORE-HANDLE    # get reference to node list from convenient method provided by CORE-HANDLE
186    $results ||= $self->_getNodeList('source');    $results ||= $self->_getNodeList('source');
187    
188      #print Dumper($results);
189    
190    # checkpoint: do we actually have a list to iterate through?    # checkpoint: do we actually have a list to iterate through?
191    if (!$results || !@{$results}) {    if (!$results || !@{$results}) {
192      $logger->notice( __PACKAGE__ . "->_run: No nodes to synchronize." );      $logger->notice( __PACKAGE__ . "->_run: No nodes to synchronize." );
# Line 178  sub _run { Line 208  sub _run {
208    # iterate through set    # iterate through set
209    foreach my $source_node_real (@results) {    foreach my $source_node_real (@results) {
210    
211        print ":" if $self->{verbose};
212    
213      $tc->{total}++;      $tc->{total}++;
214    
215  #print "========================  iter", "\n";  #print "========================  iter", "\n";
# Line 187  sub _run { Line 219  sub _run {
219      #   - is a "deep_copy" needed here if occouring modifications take place?      #   - is a "deep_copy" needed here if occouring modifications take place?
220      #   - puuhhhh, i guess a deep_copy would destroy tangram mechanisms?      #   - puuhhhh, i guess a deep_copy would destroy tangram mechanisms?
221      #   - after all, just take care for now that this object doesn't get updated!      #   - after all, just take care for now that this object doesn't get updated!
222        #   - so, just use its reference for now - if some cloning is needed in future, do this here!
223      my $source_node = $source_node_real;      my $source_node = $source_node_real;
224    
225      # modify entry - handle new style callbacks (the readers)      # modify entry - handle new style callbacks (the readers)
226  #print Dumper($source_node);  
227  #exit;      # trace
228          #print Dumper($source_node);
229          #exit;
230    
231      my $descent = 'source';      my $descent = 'source';
232    
# Line 199  sub _run { Line 234  sub _run {
234      my $map_callbacks = {};      my $map_callbacks = {};
235      if (my $callbacks = $self->{meta}->{$descent}->{Callback}) {      if (my $callbacks = $self->{meta}->{$descent}->{Callback}) {
236    
237          # trace
238            #print Dumper($callbacks);
239            #exit;
240    
241        my $error = 0;        my $error = 0;
242    
243        foreach my $node (keys %{$callbacks->{read}}) {        foreach my $node (keys %{$callbacks->{read}}) {
# Line 206  sub _run { Line 245  sub _run {
245          my $object = $source_node;          my $object = $source_node;
246          my $value; # = $source_node->{$node};          my $value; # = $source_node->{$node};
247    
248          # trace
249            #print Dumper($self->{options});
250    
251          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)
252          #my $perl_callback = $self->{meta}->{$descent}->{node} . '::' . $node . '_read';          #my $perl_callback = $self->{meta}->{$descent}->{node} . '::' . $node . '_read';
253          my $perl_callback = $self->{meta}->{$descent}->{nodeType} . '::' . $node . '_read';          my $perl_callback = $self->{meta}->{$descent}->{nodeType} . '::' . $node . '_read';
# Line 213  sub _run { Line 255  sub _run {
255          #print $evalstring, "\n"; exit;          #print $evalstring, "\n"; exit;
256          my $cb_result = eval($evalstring);          my $cb_result = eval($evalstring);
257          if ($@) {          if ($@) {
           die $@;  
258            $error = 1;            $error = 1;
259            print $@, "\n";            $logger->error( __PACKAGE__ . "->_run: $@" );
260              next;
261          }          }
262          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)
263                    
# Line 225  sub _run { Line 267  sub _run {
267    
268      }      }
269    
270  #print Dumper($source_node);      # trace
271          #print Dumper($source_node);
272    
273      # exclude defined fields  (simply delete from object)      # exclude defined fields  (simply delete from object)
274      map { delete $source_node->{$_} } @{$self->{meta}->{source}->{subnodes_exclude}};      map { delete $source_node->{$_} } @{$self->{meta}->{source}->{subnodes_exclude}};
# Line 234  sub _run { Line 277  sub _run {
277      $self->{node} = {};      $self->{node} = {};
278      $self->{node}->{source}->{payload} = $source_node;      $self->{node}->{source}->{payload} = $source_node;
279    
280  #print "res - ident", "\n";      # trace
281          #print Dumper($self->{node});
282          #exit;
283    
284      # determine ident of entry      # determine ident of entry
285      my $identOK = $self->_resolveNodeIdent('source');      my $identOK = $self->_resolveNodeIdent('source');
# Line 256  sub _run { Line 301  sub _run {
301    
302  #print "checksum", "\n";  #print "checksum", "\n";
303            
     print ":" if $self->{verbose};  
   
304      #print Dumper($self);      #print Dumper($self);
305            
306      # determine status of entry by synchronization method      # determine status of entry by synchronization method
# Line 290  sub _run { Line 333  sub _run {
333        # determine if entry is "new" or "dirty"        # determine if entry is "new" or "dirty"
334        # after all, this seems to be the point where the hammer falls.....        # after all, this seems to be the point where the hammer falls.....
335        print "c" if $self->{verbose};        print "c" if $self->{verbose};
336  #print Dumper($self->{node});  
337  #exit;        # trace
338            #print Dumper($self->{node});
339            #exit;
340    
341        $self->{node}->{status}->{new} = !$self->{node}->{target}->{checksum};        $self->{node}->{status}->{new} = !$self->{node}->{target}->{checksum};
342        if (!$self->{node}->{status}->{new}) {        if (!$self->{node}->{status}->{new}) {
343          $self->{node}->{status}->{dirty} =          $self->{node}->{status}->{dirty} =
# Line 306  sub _run { Line 352  sub _run {
352        $tc->{skip}++;        $tc->{skip}++;
353        print "s" if $self->{verbose};        print "s" if $self->{verbose};
354        next;        next;
         
355      }      }
356    
357      # first reaction on entry-status: continue with next entry if the current is already "in sync"      # first reaction on entry-status: continue with next entry if the current is already "in sync"
# Line 316  sub _run { Line 361  sub _run {
361      }      }
362    
363      # build map to actually transfer the data from source to target      # build map to actually transfer the data from source to target
364      $self->buildAttributeMap();      if (!$self->buildAttributeMap()) {
365          #$logger->warning( __PACKAGE__ . "->_run: Attribute Map could not be created. Will not insert or modify node.");
366          $tc->{skip}++;
367  #print Dumper($self->{node}); exit;        print "e" if $self->{verbose};
368          next;
369        }
370    
371  #print "attempt", "\n";      # trace
372          #print Dumper($self->{node}); exit;
373          #print "attempt", "\n";
374    
375      # additional (new) checks for feature "write-protection"      # additional (new) checks for feature "write-protection"
376      if ($self->{meta}->{target}->{storage}->{isWriteProtected}) {      if ($self->{meta}->{target}->{storage}->{isWriteProtected}) {
# Line 334  sub _run { Line 383  sub _run {
383        next;        next;
384      }      }
385    
386  #print Dumper($self);      # trace
387  #exit;        #print Dumper($self);
388          #exit;
389    
390      # transfer contents of map to target      # transfer contents of map to target
391      if ($self->{node}->{status}->{new}) {      if ($self->{node}->{status}->{new}) {
# Line 371  sub _run { Line 421  sub _run {
421            
422      # change ident in source (take from target), if transfer was ok and target is an IdentAuthority      # change ident in source (take from target), if transfer was ok and target is an IdentAuthority
423      # this is (for now) called a "retransmit" indicated by a "r"-character when verbosing      # this is (for now) called a "retransmit" indicated by a "r"-character when verbosing
424      if ($self->{node}->{status}->{ok} && $self->{options}->{target}->{storage}->{idAuthority}) {      #if ($self->{node}->{status}->{ok} && $self->{options}->{target}->{storage}->{idAuthority}) {
425        if ($self->{node}->{status}->{ok} && $self->{meta}->{target}->{isIdentAuthority}) {
426        print "r" if $self->{verbose};        print "r" if $self->{verbose};
427        #print Dumper($self->{meta});        #print Dumper($self->{meta});
428        #print Dumper($self->{node});        #print Dumper($self->{node});
# Line 394  sub _run { Line 445  sub _run {
445            
446      # todo!!!      # todo!!!
447      #sysevent( { usermsg => $msg, level => $level }, $taskEvent );      #sysevent( { usermsg => $msg, level => $level }, $taskEvent );
448      $logger->info( __PACKAGE__ . "->_run: $msg" );      #$logger->info( __PACKAGE__ . "->_run: $msg" );
449        $logger->info($msg . "\n");
450    
451    return $tc;    return $tc;
452    
# Line 449  sub _dumpCompact { Line 501  sub _dumpCompact {
501  sub _doTransferToTarget {  sub _doTransferToTarget {
502    my $self = shift;    my $self = shift;
503    my $action = shift;    my $action = shift;
504    #print Dumper($self->{node});      
505    #exit;    # trace
506        #print Dumper($self->{meta});
507        #print Dumper($self->{node});
508        #exit;
509        
510    $self->_modifyNode('target', $action, $self->{node}->{map});    $self->_modifyNode('target', $action, $self->{node}->{map});
511  }  }
512    
# Line 551  sub _prepareNode_DummyIdent { Line 607  sub _prepareNode_DummyIdent {
607      $i++;      $i++;
608    }    }
609    
610    print "\n" if $self->{verbose};    #print "\n" if $self->{verbose};
611        
612    if (!$i) {    if (!$i) {
613      $logger->warning( __PACKAGE__ . "->_prepareNode_DummyIdent: no nodes touched" );      $logger->warning( __PACKAGE__ . "->_prepareNode_DummyIdent: no nodes touched" );
# Line 568  sub _otherSide { Line 624  sub _otherSide {
624    return '';    return '';
625  }  }
626    
 sub _erase_all {  
   my $self = shift;  
   my $descent = shift;  
   #my $node = shift;  
   my $node = $self->{meta}->{$descent}->{node};  
   $self->{meta}->{$descent}->{storage}->eraseAll($node);  
 }  
627    
628  1;  1;
629    __END__

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.10

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed