/[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.9 by joko, Tue May 13 08:17:52 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.9  2003/05/13 08:17:52  joko
12    ##    buildAttributeMap now propagates error
13    ##
14    ##    Revision 1.8  2003/03/27 15:31:15  joko
15    ##    fixes to modules regarding new namespace(s) below Data::Mungle::*
16    ##
17    ##    Revision 1.7  2003/02/21 08:01:11  joko
18    ##    debugging, logging
19    ##    renamed module
20    ##
21    ##    Revision 1.6  2003/02/14 14:03:49  joko
22    ##    + logging, debugging
23    ##    - refactored code to sister module
24    ##
25    ##    Revision 1.5  2003/02/11 05:30:47  joko
26    ##    + minor fixes and some debugging mud
27    ##
28  ##    Revision 1.4  2003/02/09 05:01:10  joko  ##    Revision 1.4  2003/02/09 05:01:10  joko
29  ##    + major structure changes  ##    + major structure changes
30  ##    - refactored code to sister modules  ##    - refactored code to sister modules
# Line 52  Line 71 
71  ##    + minor cosmetics for logging  ##    + minor cosmetics for logging
72  ##  ##
73  ##    Revision 1.2  2002/12/01 04:43:25  joko  ##    Revision 1.2  2002/12/01 04:43:25  joko
74  ##    + mapping deatil entries may now be either an ARRAY or a HASH  ##    + mapping detail entries may now be either an ARRAY or a HASH
75  ##    + erase flag is used now (for export-operations)  ##    + erase flag is used now (for export-operations)
76  ##    + expressions to refer to values inside deep nested structures  ##    + expressions to refer to values inside deep nested structures
77  ##    - removed old mappingV2-code  ##    - removed old mappingV2-code
# Line 64  Line 83 
83  ##  ##
84  ##    Revision 1.1  2002/10/10 03:44:21  cvsjoko  ##    Revision 1.1  2002/10/10 03:44:21  cvsjoko
85  ##    + new  ##    + new
86  ##    ----------------------------------------------------------------------------------------  ## -------------------------------------------------------------------------
87    
88    
89  package Data::Transfer::Sync::Core;  package Data::Transfer::Sync::Core;
# Line 79  use mixin::with qw( Data::Transfer::Sync Line 98  use mixin::with qw( Data::Transfer::Sync
98    
99  use Data::Dumper;  use Data::Dumper;
100    
101  use misc::HashExt;  #use misc::HashExt;
102  use Data::Compare::Struct qw( getDifference isEmpty );  use Hash::Serializer;
103    use Data::Mungle::Compare::Struct qw( getDifference isEmpty );
104  use Data::Storage::Container;  use Data::Storage::Container;
105  use DesignPattern::Object;  use DesignPattern::Object;
106    use shortcuts::database qw( quotesql );
107    
108  # get logger instance  # get logger instance
109  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 113  sub _init { Line 134  sub _init {
134      $self->{container}->addStorage($_, $self->{storages}->{$_});      $self->{container}->addStorage($_, $self->{storages}->{$_});
135    }    }
136        
137      # trace
138        #print Dumper($self);
139        #exit;
140    
141    return 1;    return 1;
142        
143  }  }
# Line 140  sub _run { Line 165  sub _run {
165    $logger->debug( __PACKAGE__ . "->_run" );    $logger->debug( __PACKAGE__ . "->_run" );
166    
167    # for statistics    # for statistics
168    my $tc = OneLineDumpHash->new( {} );    my $tc = Hash::Serializer->new( {} );
169    my $results;    my $results;
170        
171    # set of objects is already in $self->{args}    # set of objects is already in $self->{args}
# Line 178  sub _run { Line 203  sub _run {
203    # iterate through set    # iterate through set
204    foreach my $source_node_real (@results) {    foreach my $source_node_real (@results) {
205    
206        print ":" if $self->{verbose};
207    
208      $tc->{total}++;      $tc->{total}++;
209    
210  #print "========================  iter", "\n";  #print "========================  iter", "\n";
# Line 187  sub _run { Line 214  sub _run {
214      #   - is a "deep_copy" needed here if occouring modifications take place?      #   - is a "deep_copy" needed here if occouring modifications take place?
215      #   - puuhhhh, i guess a deep_copy would destroy tangram mechanisms?      #   - puuhhhh, i guess a deep_copy would destroy tangram mechanisms?
216      #   - 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!
217        #   - so, just use its reference for now - if some cloning is needed in future, do this here!
218      my $source_node = $source_node_real;      my $source_node = $source_node_real;
219    
220      # modify entry - handle new style callbacks (the readers)      # modify entry - handle new style callbacks (the readers)
221  #print Dumper($source_node);  
222  #exit;      # trace
223          #print Dumper($source_node);
224          #exit;
225    
226      my $descent = 'source';      my $descent = 'source';
227    
# Line 199  sub _run { Line 229  sub _run {
229      my $map_callbacks = {};      my $map_callbacks = {};
230      if (my $callbacks = $self->{meta}->{$descent}->{Callback}) {      if (my $callbacks = $self->{meta}->{$descent}->{Callback}) {
231    
232          # trace
233            #print Dumper($callbacks);
234            #exit;
235    
236        my $error = 0;        my $error = 0;
237    
238        foreach my $node (keys %{$callbacks->{read}}) {        foreach my $node (keys %{$callbacks->{read}}) {
# Line 206  sub _run { Line 240  sub _run {
240          my $object = $source_node;          my $object = $source_node;
241          my $value; # = $source_node->{$node};          my $value; # = $source_node->{$node};
242    
243          # trace
244            #print Dumper($self->{options});
245    
246          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)
247          #my $perl_callback = $self->{meta}->{$descent}->{node} . '::' . $node . '_read';          #my $perl_callback = $self->{meta}->{$descent}->{node} . '::' . $node . '_read';
248          my $perl_callback = $self->{meta}->{$descent}->{nodeType} . '::' . $node . '_read';          my $perl_callback = $self->{meta}->{$descent}->{nodeType} . '::' . $node . '_read';
# Line 213  sub _run { Line 250  sub _run {
250          #print $evalstring, "\n"; exit;          #print $evalstring, "\n"; exit;
251          my $cb_result = eval($evalstring);          my $cb_result = eval($evalstring);
252          if ($@) {          if ($@) {
           die $@;  
253            $error = 1;            $error = 1;
254            print $@, "\n";            $logger->error( __PACKAGE__ . "->_run: $@" );
255              next;
256          }          }
257          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)
258                    
# Line 225  sub _run { Line 262  sub _run {
262    
263      }      }
264    
265  #print Dumper($source_node);      # trace
266          #print Dumper($source_node);
267    
268      # exclude defined fields  (simply delete from object)      # exclude defined fields  (simply delete from object)
269      map { delete $source_node->{$_} } @{$self->{meta}->{source}->{subnodes_exclude}};      map { delete $source_node->{$_} } @{$self->{meta}->{source}->{subnodes_exclude}};
# Line 234  sub _run { Line 272  sub _run {
272      $self->{node} = {};      $self->{node} = {};
273      $self->{node}->{source}->{payload} = $source_node;      $self->{node}->{source}->{payload} = $source_node;
274    
275  #print "res - ident", "\n";      # trace
276          #print Dumper($self->{node});
277          #exit;
278    
279      # determine ident of entry      # determine ident of entry
280      my $identOK = $self->_resolveNodeIdent('source');      my $identOK = $self->_resolveNodeIdent('source');
# Line 256  sub _run { Line 296  sub _run {
296    
297  #print "checksum", "\n";  #print "checksum", "\n";
298            
     print ":" if $self->{verbose};  
   
299      #print Dumper($self);      #print Dumper($self);
300            
301      # determine status of entry by synchronization method      # determine status of entry by synchronization method
# Line 290  sub _run { Line 328  sub _run {
328        # determine if entry is "new" or "dirty"        # determine if entry is "new" or "dirty"
329        # after all, this seems to be the point where the hammer falls.....        # after all, this seems to be the point where the hammer falls.....
330        print "c" if $self->{verbose};        print "c" if $self->{verbose};
331  #print Dumper($self->{node});  
332  #exit;        # trace
333            #print Dumper($self->{node});
334            #exit;
335    
336        $self->{node}->{status}->{new} = !$self->{node}->{target}->{checksum};        $self->{node}->{status}->{new} = !$self->{node}->{target}->{checksum};
337        if (!$self->{node}->{status}->{new}) {        if (!$self->{node}->{status}->{new}) {
338          $self->{node}->{status}->{dirty} =          $self->{node}->{status}->{dirty} =
# Line 306  sub _run { Line 347  sub _run {
347        $tc->{skip}++;        $tc->{skip}++;
348        print "s" if $self->{verbose};        print "s" if $self->{verbose};
349        next;        next;
         
350      }      }
351    
352      # 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 356  sub _run {
356      }      }
357    
358      # build map to actually transfer the data from source to target      # build map to actually transfer the data from source to target
359      $self->buildAttributeMap();      if (!$self->buildAttributeMap()) {
360          #$logger->warning( __PACKAGE__ . "->_run: Attribute Map could not be created. Will not insert or modify node.");
361          $tc->{skip}++;
362  #print Dumper($self->{node}); exit;        print "e" if $self->{verbose};
363          next;
364        }
365    
366  #print "attempt", "\n";      # trace
367          #print Dumper($self->{node}); exit;
368          #print "attempt", "\n";
369    
370      # additional (new) checks for feature "write-protection"      # additional (new) checks for feature "write-protection"
371      if ($self->{meta}->{target}->{storage}->{isWriteProtected}) {      if ($self->{meta}->{target}->{storage}->{isWriteProtected}) {
# Line 334  sub _run { Line 378  sub _run {
378        next;        next;
379      }      }
380    
381  #print Dumper($self);      # trace
382  #exit;        #print Dumper($self);
383          #exit;
384    
385      # transfer contents of map to target      # transfer contents of map to target
386      if ($self->{node}->{status}->{new}) {      if ($self->{node}->{status}->{new}) {
# Line 371  sub _run { Line 416  sub _run {
416            
417      # 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
418      # 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
419      if ($self->{node}->{status}->{ok} && $self->{options}->{target}->{storage}->{idAuthority}) {      #if ($self->{node}->{status}->{ok} && $self->{options}->{target}->{storage}->{idAuthority}) {
420        if ($self->{node}->{status}->{ok} && $self->{meta}->{target}->{isIdentAuthority}) {
421        print "r" if $self->{verbose};        print "r" if $self->{verbose};
422        #print Dumper($self->{meta});        #print Dumper($self->{meta});
423        #print Dumper($self->{node});        #print Dumper($self->{node});
# Line 394  sub _run { Line 440  sub _run {
440            
441      # todo!!!      # todo!!!
442      #sysevent( { usermsg => $msg, level => $level }, $taskEvent );      #sysevent( { usermsg => $msg, level => $level }, $taskEvent );
443      $logger->info( __PACKAGE__ . "->_run: $msg" );      #$logger->info( __PACKAGE__ . "->_run: $msg" );
444        $logger->info($msg . "\n");
445    
446    return $tc;    return $tc;
447    
# Line 449  sub _dumpCompact { Line 496  sub _dumpCompact {
496  sub _doTransferToTarget {  sub _doTransferToTarget {
497    my $self = shift;    my $self = shift;
498    my $action = shift;    my $action = shift;
499    #print Dumper($self->{node});      
500    #exit;    # trace
501        #print Dumper($self->{meta});
502        #print Dumper($self->{node});
503        #exit;
504        
505    $self->_modifyNode('target', $action, $self->{node}->{map});    $self->_modifyNode('target', $action, $self->{node}->{map});
506  }  }
507    
# Line 551  sub _prepareNode_DummyIdent { Line 602  sub _prepareNode_DummyIdent {
602      $i++;      $i++;
603    }    }
604    
605    print "\n" if $self->{verbose};    #print "\n" if $self->{verbose};
606        
607    if (!$i) {    if (!$i) {
608      $logger->warning( __PACKAGE__ . "->_prepareNode_DummyIdent: no nodes touched" );      $logger->warning( __PACKAGE__ . "->_prepareNode_DummyIdent: no nodes touched" );
# Line 568  sub _otherSide { Line 619  sub _otherSide {
619    return '';    return '';
620  }  }
621    
 sub _erase_all {  
   my $self = shift;  
   my $descent = shift;  
   #my $node = shift;  
   my $node = $self->{meta}->{$descent}->{node};  
   $self->{meta}->{$descent}->{storage}->eraseAll($node);  
 }  
622    
623  1;  1;
624    __END__

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

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