Changeset 11622 for branches

Show
Ignore:
Timestamp:
11/11/08 11:50:09 (8 weeks ago)
Author:
javier.amor.garcia@…
Message:

fixed consolidate and purge for modules with multiples tableInfo closes #1152

Location:
branches/pop-proxy-branch/ebox/src/EBox
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/pop-proxy-branch/ebox/src/EBox/Logs.pm

    r11612 r11622  
    276276         
    277277    foreach my $mod (@{getLogsModules()}) { 
    278         my @tableInfos; 
    279         my $ti = $mod->tableInfo(); 
    280         if (ref $ti eq 'HASH') { 
    281             EBox::warn('tableInfo() in ' . $mod->name .   
    282              'must return a reference to a list of hashes not the hash itself'); 
    283             @tableInfos = ( $ti ); 
    284         } 
    285         else { 
    286             @tableInfos = @{ $ti }; 
    287         } 
     278        my @tableInfos = @{ $self->getModTableInfos($mod) }; 
    288279         
    289280        foreach my $comp (@tableInfos) { 
     
    313304    my $tables = $self->getAllTables(); 
    314305    return $tables->{$index}; 
     306} 
     307 
     308 
     309 
     310sub getModTableInfos 
     311{ 
     312    my ($self, $mod) = @_; 
     313    my @tableInfos; 
     314 
     315    my $ti = $mod->tableInfo(); 
     316    if (ref $ti eq 'ARRAY') { 
     317        @tableInfos = @{ $ti }; 
     318    } 
     319    elsif (ref $ti eq 'HASH') { 
     320        EBox::warn('tableInfo() in ' . $mod->name .   
     321                   'must return a reference to a list of hashes not the hash itself'); 
     322        @tableInfos = ( $ti ); 
     323    } 
     324    else { 
     325        throw EBox::Exceptions::Internal( 
     326                                         $mod->name .  
     327                                         "'s tableInfo returned invalid module" 
     328                                        ); 
     329    } 
     330 
     331    return \@tableInfos; 
    315332} 
    316333 
     
    766783  my $thresholdDate = $self->_thresholdDate($lifetime); 
    767784 
    768   foreach my $tableInfo ( values %{ $self->getAllTables } ) { 
     785  my @tables = map { 
     786      @{  $self->getModTableInfos($_) } 
     787  } @{ $self->getLogsModules }; 
     788 
     789  foreach my $tableInfo ( @tables ) { 
    769790    my $table = $tableInfo->{tablename}; 
    770791    my $timeCol = $tableInfo->{timecol}; 
     
    790811  my ($self) = @_; 
    791812 
    792   my %thresholdByDomain = (); 
     813  my %thresholdByModule = (); 
    793814 
    794815  # get the threshold date for each domain 
     
    801822 
    802823    my $threshold = $self->_thresholdDate($lifeTime); 
    803     $thresholdByDomain{$row_r->valueByName('domain')} = $threshold; 
     824    $thresholdByModule{$row_r->valueByName('domain')} = $threshold; 
    804825  } 
    805826 
    806   # purge each domain 
    807   my $tables = $self->getAllTables(); 
    808   while (my ($domain, $threshold) = each %thresholdByDomain) { 
    809     my $table = $tables->{$domain}->{tablename}; 
    810     my $timeCol = $tables->{$domain}->{timecol}; 
    811     $self->_purgeTable($table, $timeCol, $threshold); 
     827  # purge each module 
     828 
     829 
     830  while (my ($modName, $threshold) = each %thresholdByModule) { 
     831      my $mod = EBox::Global->modInstance($modName); 
     832      my @logTables = @{ $self->getModTableInfos($mod) }; 
     833 
     834      foreach my $table (@logTables) { 
     835          my $dbTable = $table->{tablename}; 
     836          my $timeCol = $table->{timecol}; 
     837 
     838          $self->_purgeTable($dbTable, $timeCol, $threshold); 
     839      } 
     840 
     841 
    812842  } 
    813843} 
     844 
     845 
     846 
     847 
    814848 
    815849# Transform an hour into a localtime 
  • branches/pop-proxy-branch/ebox/src/EBox/Logs/Consolidate.pm

    r11487 r11622  
    4747            return; 
    4848        } 
    49  
    5049        @modNames = ( $modName ); 
    5150    } 
    5251 
    5352     
    54  
     53     
    5554 
    5655    foreach my $name (@modNames) { 
    57         my $tableInfo = $self->_tableInfoFromMod($name); 
    58         while (my ($destTable, $configuration) = each %{ $tableInfo->{consolidate} }) { 
    59             my @timePeriods = TIME_PERIODS; 
    60  
    61             my $firstTimePeriod = shift @timePeriods; 
    62  
    63              
    64             $self->_consolidateTable( 
    65                                      destinationTable => $destTable, 
    66                                      configuration    => $configuration, 
    67                                       
    68                                      tableInfo        => $tableInfo, 
    69                                       
    70                                      timePeriod       => $firstTimePeriod, 
    71                                     ); 
    72  
    73  
    74             my $prevTimePeriod = $firstTimePeriod; 
    75             foreach my $timePeriod (@timePeriods) { 
    76                 $self->_reconsolidateTable( 
     56        EBox::debug("BEF TABLE INOFS FROM"); 
     57        my @tableInfos = @{ $self->_tableInfosFromMod($name) }; 
     58        EBox::debug("tableInfos @tableInfos"); 
     59        foreach my $tableInfo (@tableInfos) { 
     60 
     61            while (my ($destTable, $configuration) = each %{ $tableInfo->{consolidate} }) { 
     62                my @timePeriods = TIME_PERIODS; 
     63                 
     64                my $firstTimePeriod = shift @timePeriods; 
     65                 
     66                 
     67                $self->_consolidateTable( 
     68                                         destinationTable => $destTable, 
     69                                         configuration    => $configuration, 
     70                                          
     71                                         tableInfo        => $tableInfo, 
     72                                          
     73                                         timePeriod       => $firstTimePeriod, 
     74                                        ); 
     75                 
     76 
     77                my $prevTimePeriod = $firstTimePeriod; 
     78                foreach my $timePeriod (@timePeriods) { 
     79                    $self->_reconsolidateTable( 
    7780                                     destinationTable => $destTable, 
    7881                                     configuration    => $configuration, 
     
    8184                                     sourceTimePeriod => $prevTimePeriod, 
    8285 
    83                                           ); 
    84  
    85                 $prevTimePeriod = $timePeriod; 
     86                                              ); 
     87                     
     88                    $prevTimePeriod = $timePeriod; 
     89                } 
     90 
    8691            } 
    87  
    88         } 
    89  
    90     } 
    91  
     92             
     93        } 
     94    } 
    9295 
    9396 
     
    121124    my $global = EBox::Global->getInstance(); 
    122125 
    123     my @mods = grep { 
    124         my $tableInfo = $_->tableInfo(); 
    125         $_->isEnabled() and 
    126             (exists  $tableInfo->{consolidate}) and ($tableInfo->{consolidate}) 
    127     } @{  $global->modInstancesOfType('EBox::LogObserver')  }; 
    128          
    129     my @modNames = map { $_->name()  } @mods; 
     126 
     127    my @modNames; 
     128    my @mods =  @{  $global->modInstancesOfType('EBox::LogObserver')  }; 
     129 
     130    foreach my $mod (@mods) { 
     131        if (not $mod->isEnabled()) { 
     132            next; 
     133        } 
     134 
     135        my $name = $mod->name(); 
     136 
     137        my $consolidate = @{  $self->_tableInfosFromMod($name, 1) }; 
     138        if (not $consolidate) { 
     139            next; 
     140        } 
     141 
     142        push @modNames, $name; 
     143    } 
     144 
     145 
    130146 
    131147    return \@modNames; 
     
    387403} 
    388404 
    389 sub _tableInfoFromMod 
    390 { 
    391     my ($self, $modName) = @_; 
     405sub _tableInfosFromMod 
     406{ 
     407    my ($self, $modName, $noThrowsException) = @_; 
     408    defined $noThrowsException or 
     409        $noThrowsException = 0; 
    392410 
    393411    my $mod = EBox::Global->modInstance($modName); 
     
    396414    } 
    397415 
    398  
    399     my $tableInfo = $mod->tableInfo(); 
    400     if (not exists $tableInfo->{consolidate}) { 
    401         throw EBox::Exceptions::Internal("Module $modName has not consolidate conofguration"); 
    402     } 
    403  
    404     return $tableInfo; 
     416    EBox::debug("BEF tableInfo())"); 
     417    my @tableInfos; 
     418    my $ti = $mod->tableInfo(); 
     419    EBox::debug("AFT tableInfo())"); 
     420    if (ref $ti eq 'HASH') { 
     421        EBox::warn('tableInfo() in ' . $mod->name .   
     422                   'must return a reference to a list of hashes not the hash itself'); 
     423        @tableInfos = ( $ti ); 
     424    } 
     425    else { 
     426        @tableInfos = @{ $ti }; 
     427    } 
     428 
     429     
     430    @tableInfos = grep { exists $_->{consolidate} } @tableInfos; 
     431 
     432    if (not @tableInfos and (not $noThrowsException)) { 
     433        throw EBox::Exceptions::Internal("Module $modName has not any table with consolidate configuration"); 
     434    } 
     435 
     436    return \@tableInfos; 
    405437} 
    406438 
  • branches/pop-proxy-branch/ebox/src/EBox/Logs/Consolidate/Test.pm

    r11487 r11622  
    2121use EBox::TestStubs; 
    2222 
    23 sub weeklyDateTest : Test(6) 
     23sub weeklyDateTest #: Test(6) 
    2424{ 
    2525    my %cases = ( 
     
    234234                                       name => $modName, 
    235235                                       subs => [ 
    236                                                 isEnabled => sub { return 1  } 
     236                                                isEnabled => sub { return 1  }, 
     237                                                tableInfo => sub { 
     238                                                    my ($mock) = @_; 
     239                                                    return 
     240                                                      $self->fakeTableInfoFromMod($mock->name); 
     241 
     242                                                } 
     243#                                                name => sub {  return $modName }, 
    237244                                               ], 
     245                                        isa => ['EBox::LogObserver'], 
    238246                                      ); 
    239247    }