- Timestamp:
- 11/11/08 11:50:09 (8 weeks ago)
- Location:
- branches/pop-proxy-branch/ebox/src/EBox
- Files:
-
- 3 modified
-
Logs.pm (modified) (5 diffs)
-
Logs/Consolidate.pm (modified) (5 diffs)
-
Logs/Consolidate/Test.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pop-proxy-branch/ebox/src/EBox/Logs.pm
r11612 r11622 276 276 277 277 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) }; 288 279 289 280 foreach my $comp (@tableInfos) { … … 313 304 my $tables = $self->getAllTables(); 314 305 return $tables->{$index}; 306 } 307 308 309 310 sub 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; 315 332 } 316 333 … … 766 783 my $thresholdDate = $self->_thresholdDate($lifetime); 767 784 768 foreach my $tableInfo ( values %{ $self->getAllTables } ) { 785 my @tables = map { 786 @{ $self->getModTableInfos($_) } 787 } @{ $self->getLogsModules }; 788 789 foreach my $tableInfo ( @tables ) { 769 790 my $table = $tableInfo->{tablename}; 770 791 my $timeCol = $tableInfo->{timecol}; … … 790 811 my ($self) = @_; 791 812 792 my %thresholdBy Domain= ();813 my %thresholdByModule = (); 793 814 794 815 # get the threshold date for each domain … … 801 822 802 823 my $threshold = $self->_thresholdDate($lifeTime); 803 $thresholdBy Domain{$row_r->valueByName('domain')} = $threshold;824 $thresholdByModule{$row_r->valueByName('domain')} = $threshold; 804 825 } 805 826 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 812 842 } 813 843 } 844 845 846 847 814 848 815 849 # Transform an hour into a localtime -
branches/pop-proxy-branch/ebox/src/EBox/Logs/Consolidate.pm
r11487 r11622 47 47 return; 48 48 } 49 50 49 @modNames = ( $modName ); 51 50 } 52 51 53 52 54 53 55 54 56 55 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( 77 80 destinationTable => $destTable, 78 81 configuration => $configuration, … … 81 84 sourceTimePeriod => $prevTimePeriod, 82 85 83 ); 84 85 $prevTimePeriod = $timePeriod; 86 ); 87 88 $prevTimePeriod = $timePeriod; 89 } 90 86 91 } 87 88 } 89 90 } 91 92 93 } 94 } 92 95 93 96 … … 121 124 my $global = EBox::Global->getInstance(); 122 125 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 130 146 131 147 return \@modNames; … … 387 403 } 388 404 389 sub _tableInfoFromMod 390 { 391 my ($self, $modName) = @_; 405 sub _tableInfosFromMod 406 { 407 my ($self, $modName, $noThrowsException) = @_; 408 defined $noThrowsException or 409 $noThrowsException = 0; 392 410 393 411 my $mod = EBox::Global->modInstance($modName); … … 396 414 } 397 415 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; 405 437 } 406 438 -
branches/pop-proxy-branch/ebox/src/EBox/Logs/Consolidate/Test.pm
r11487 r11622 21 21 use EBox::TestStubs; 22 22 23 sub weeklyDateTest : Test(6)23 sub weeklyDateTest #: Test(6) 24 24 { 25 25 my %cases = ( … … 234 234 name => $modName, 235 235 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 }, 237 244 ], 245 isa => ['EBox::LogObserver'], 238 246 ); 239 247 }
