| 1 | # -*- perl -*- | ||
| 2 | |||
| 3 | # Copyright (c) 2010 AdCopy | ||
| 4 | # Author: Jeff Weisberg | ||
| 5 | # Created: 2010-Jan-14 17:04 (EST) | ||
| 6 | # Function: get list of files to map | ||
| 7 | # | ||
| 8 | # $Id: FileList.pm,v 1.3 2010/11/10 16:24:38 jaw Exp $ | ||
| 9 | |||
| 10 | package AC::MrGamoo::AC::FileList; | ||
| 11 | use AC::MrGamoo::Debug 'files'; | ||
| 12 | use AC::ISOTime; | ||
| 13 | use AC::Yenta::Direct; | ||
| 14 | use JSON; | ||
| 15 | use strict; | ||
| 16 | |||
| 17 | my $YDBFILE = "/home/acdata/logfile.ydb"; | ||
| 18 | |||
| 19 | # return an array of: | ||
| 20 | # { | ||
| 21 | # filename => www/2010/01/17/23/5943_prod_5x2N5qyerdeddsNi | ||
| 22 | # location => [ scrib@a2be021bd31c, scrib@a2be021ad31c ] | ||
| 23 | # size => 10863 | ||
| 24 | # [anything else] | ||
| 25 | # } | ||
| 26 | |||
| 27 | # convert legacy scriblr ids | ||
| 28 | my %CONVERT = ( | ||
| 29 | 'scrib@a2be021ad31c' => 'mrm@gefiltefish1-r3.ccsphl', | ||
| 30 | 'scrib@a2be021bd31c' => 'mrm@gefiltefish1-r4.ccsphl', | ||
| 31 | 'scrib@a2be021cd31c' => 'mrm@gefiltefish2-r3.ccsphl', | ||
| 32 | 'scrib@a2be021dd31c' => 'mrm@gefiltefish2-r4.ccsphl', | ||
| 33 | 'scrib@a2be021ed31c' => 'mrm@gefiltefish3-r3.ccsphl', | ||
| 34 | 'scrib@a2be021fd31c' => 'mrm@gefiltefish3-r4.ccsphl', | ||
| 35 | 'scrib@a2be0220d31c' => 'mrm@gefiltefish4-r3.ccsphl', | ||
| 36 | 'scrib@a2be0221d31c' => 'mrm@gefiltefish4-r4.ccsphl', | ||
| 37 | ); | ||
| 38 | |||
| 39 | sub get_file_list { | ||
| 40 | my $config = shift; | ||
| 41 | |||
| 42 | my $yenta = AC::Yenta::Direct->new( 'logfile', $YDBFILE ); | ||
| 43 | |||
| 44 | my $mode = $config->{datamode}; | ||
| 45 | my $syst = $config->{system}; | ||
| 46 | my $tmax = $config->{end}; | ||
| 47 | my $tmin = $config->{start}; | ||
| 48 | my $start = isotime($tmin); | ||
| 49 | $start =~ s/^(\d+)T(\d+).*/$1$2/; # 20091109T123456... => 20091109123456 | ||
| 50 | |||
| 51 | # NB: keys in the yenta logfile map are of the form: 20100126150139_eqaB5uSerdeddsOw | ||
| 52 | |||
| 53 | $syst = undef if $syst eq '*'; | ||
| 54 | $mode = undef if $mode eq '*'; | ||
| 55 | $syst =~ s/[ ,]/\|/g; | ||
| 56 | if( $syst ){ | ||
| 57 | $syst = qr/^($syst)$/; | ||
| 58 | } | ||
| 59 | |||
| 60 | debug("mode=$mode, syst=$syst, tmin=$tmin, tmax=$tmax, start=$start"); | ||
| 61 | my @files = grep { | ||
| 62 | (!$mode || ($_->{environment} eq $mode)) && | ||
| 63 | (!$syst || ($_->{subsystem} =~ $syst)) && | ||
| 64 | ($_->{end_time} >= $tmin) && | ||
| 65 | ($_->{start_time} <= $tmax) | ||
| 66 | } map { | ||
| 67 | #debug("file: $_"); | ||
| 68 | my $d = $yenta->get($_); | ||
| 69 | $d = $d ? decode_json($d) : {}; | ||
| 70 | $d->{location} = [ map { $CONVERT{$_} || $_ } (split /\s+/, $d->{location}) ]; | ||
| 71 | $d; | ||
| 72 | } $yenta->getrange($start, undef); | ||
| 73 | |||
| 74 | debug("found " .scalar(@files)." files"); | ||
| 75 | return \@files; | ||
| 76 | } | ||
| 77 | |||
| 78 | |||
| 79 | 1; |