Changeset 42


Ignore:
Timestamp:
11/28/10 14:59:48 (13 years ago)
Author:
nanardon
Message:
  • add dump/load distrib config using Yaml
  • separate DB connection for session
Location:
server/trunk/web
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/bin/sophie_scan

    r18 r42  
    109109                foreach my $pathkey (@{ $job }) { 
    110110                    my @delta = Sophie::Base::RpmsPath->new($pathkey) 
    111                     ->find_delta; 
     111                        ->find_delta; 
    112112                    while (my @d = splice(@delta, 0, 25)) { 
    113113                        my $path = Sophie::Base::RpmsPath->new($pathkey); 
  • server/trunk/web/lib/Sophie.pm

    r35 r42  
    7474__PACKAGE__->config->{session} = { 
    7575    expires   => 3600, 
    76     dbi_dbh   => 'Base', 
     76    dbi_dbh   => 'Session', 
    7777    dbi_table => 'sessions', 
     78#    dbi_dsn => 'dbi:Pg:' . $config->{dbconnect}, 
     79#    dbi_user => $config->{dbuser}, 
     80#    dbi_pass => $config->{dbpassword}, 
    7881}; 
    7982 
  • server/trunk/web/lib/Sophie/Base.pm

    r26 r42  
    1010__PACKAGE__->load_namespaces(); 
    1111 
    12 sub connection { 
    13     my ($class) = @_; 
    14     $class->SUPER::connection( 
    15         sub { __PACKAGE__->db }, 
    16    ) 
    17 } 
    18  
    19 sub db { 
    20    my ($self) = @_; 
     12sub default_config { 
    2113   my $config; 
    2214   foreach my $file ('sophie.conf', "$Bin/../sophie.conf", 
     
    2719    } 
    2820    $config or die "No config found"; 
     21    return $config; 
     22} 
    2923 
    30    DBI->connect_cached( 
    31        'dbi:Pg:' . $config->{dbconnect}, 
    32        $config->{dbuser}, 
    33        $config->{dbpassword}, 
    34        { 
    35            AutoCommit => 0, 
    36            PrintError => 1, 
    37        } 
    38    );  
     24sub connection { 
     25    my ($class, $connect_info) = @_; 
     26    if (! $connect_info->{dsn}) { 
     27        my $config = default_config(); 
     28        $connect_info->{dsn} = 'dbi:Pg:' . $config->{dbconnect}; 
     29        $connect_info->{user} = $config->{dbuser}; 
     30        $connect_info->{password} = $config->{dbpassword}; 
     31    } 
     32    exists($connect_info->{AutoCommit}) or $connect_info->{AutoCommit} = 0; 
     33    $class->SUPER::connection( 
     34        $connect_info, 
     35   ) 
     36} 
     37 
     38sub db { 
     39   my ($self) = @_; 
     40 
     41   $self->connect->storage->dbh; 
    3942} 
    4043 
  • server/trunk/web/lib/Sophie/Base/Header.pm

    r18 r42  
    1313    my ($class, $pkgid) = @_; 
    1414 
    15     bless(\$pkgid, $class); 
     15    bless({ key => $pkgid }, $class); 
    1616} 
     17 
     18sub key { $_[0]->{key} } 
    1719 
    1820sub rpm_path { 
     
    2628        } 
    2729    ); 
    28     $listrpm->execute($$self); 
     30    $listrpm->execute($self->key); 
    2931 
    3032    return $listrpm->fetchall_hashref({}); 
     
    5153        select (rpmqueryfiles(header)).* from rpms where pkgid = ? 
    5254    }); 
    53     $list_file->execute($$self); 
     55    $list_file->execute($self->key); 
    5456 
    5557    my $files = $list_file->fetchall_hashref([ 'dirname', 'basename' ]); 
     
    9294                    $add_content->execute( 
    9395                        $enc && ref $enc ? encode('utf8', $enc->decode($content)) : $content, 
    94                         $$self, 
     96                        $self->key, 
    9597                        $entry->{count}) or do { 
    9698                        $self->db->pg_rollback_to('FILECONTENT'); 
  • server/trunk/web/lib/Sophie/Base/RpmsPath.pm

    r39 r42  
    1515    my ($class, $pathkey) = @_; 
    1616 
    17     bless(\$pathkey, $class); 
    18 } 
     17    bless({ key => $pathkey }, $class); 
     18} 
     19 
     20sub key { $_[0]->{key} } 
    1921 
    2022sub path { 
     
    2426        q{select path from d_path where d_path_key = ?} 
    2527    ); 
    26     $sth->execute($$self); 
     28    $sth->execute($self->key); 
    2729    my $res = $sth->fetchrow_hashref; 
    2830    $sth->finish; 
     
    3638        q{select * from rpmfiles where d_path = ?} 
    3739    ); 
    38     $sth->execute($$self); 
     40    $sth->execute($self->key); 
    3941    $sth->fetchall_hashref([ 'filename' ]); 
    4042} 
     
    101103    $self->db->prepare_cached(q{ 
    102104        update d_path set updated = now() where d_path_key = ? 
    103         })->execute($$self); 
     105        })->execute($self->key); 
    104106    $self->db->commit; 
    105107} 
     
    114116    ); 
    115117    for (1 .. 3) { 
    116         if ($remove->execute($$self, $rpm)) {  
     118        if ($remove->execute($self->key, $rpm)) {  
    117119            warn "deleting $rpm"; 
    118120            $self->db->commit; 
     
    135137                } 
    136138            ); 
    137             if ($register->execute($$self, $rpm, $pkgid)) { 
     139            if ($register->execute($self->key, $rpm, $pkgid)) { 
    138140                warn "adding $rpm"; 
    139141                $self->db->commit; 
  • server/trunk/web/lib/Sophie/Controller/Admin.pm

    r41 r42  
    22use Moose; 
    33use namespace::autoclean; 
     4use YAML qw/freeze thaw/; 
    45 
    56BEGIN {extends 'Catalyst::Controller'; } 
     
    8990    } 
    9091 
    91     @{ $c->stash->{xmlrpc} } = 
     92    $c->stash->{xmlrpc}  = [ 
    9293    $c->model('Base')->resultset('Distribution') 
    9394        ->search($distribution ? (name => $distribution) : ()) 
     
    9798        ->search_related('MediasPaths') 
    9899        ->search_related('Paths')->get_column('path') 
    99         ->all; 
     100        ->all ]; 
    100101} 
    101102 
     
    156157        ->search_related('Release', version => $version) 
    157158        ->search_related('Arch', arch => $arch) 
    158         ->search_related('Medias', label => $label)->next or return; 
     159        ->search_related('Medias', label => $label)->find or return; 
    159160 
    160161    my $rspath = $c->model('Base')->resultset('Paths') 
     
    162163            return; 
    163164    }; 
    164     my $new = $c->model('Base')->resultset('MediasPaths')->new({ 
    165             Medias => $med, 
    166             Paths =>  $rspath, 
    167         }); 
    168     $new->delete; 
     165    my $new = $c->model('Base')->resultset('MediasPaths')->search({ 
     166            d_media => $med->d_media_key, 
     167            d_path =>  $rspath->d_path_key, 
     168        })->next->delete; 
    169169 
    170170    $c->model('Base')->storage->dbh->commit; 
     
    177177} 
    178178 
     179sub dump_distrib : XMLRPC { 
     180    my ($self, $c, $distribution, $version, $arch) = @_; 
     181     
     182    if (!ref $distribution) { 
     183        $distribution = { 
     184            distribution => $distribution, 
     185            release => $version, 
     186            arch => $arch, 
     187        }; 
     188    } 
     189 
     190    my $ref = { 
     191        distrib => $distribution, 
     192    }; 
     193 
     194    $ref->{media} = $c->forward('/distrib/struct', [ $distribution ]); 
     195 
     196    foreach (@{ $ref->{media} || []}) { 
     197        warn $_->{label}; 
     198        $ref->{path}{$_->{label}} = $c->forward('list_path', [ $distribution, 
     199                $_->{label} ]); 
     200    } 
     201 
     202    $c->stash->{xmlrpc} = freeze($ref); 
     203} 
     204 
     205sub clean_distrib : XMLRPC { 
     206    my ($self, $c, $distribution, $version, $arch) = @_; 
     207     
     208    if (!ref $distribution) { 
     209        $distribution = { 
     210            distribution => $distribution, 
     211            release => $version, 
     212            arch => $arch, 
     213        }; 
     214    } 
     215 
     216    my $rsdist = $c->model('Base')->resultset('Distribution') 
     217        ->search(name => $distribution->{distribution}) 
     218        ->search_related('Release', version => $distribution->{release}) 
     219        ->search_related('Arch', arch => $distribution->{arch}) 
     220        ->search_related('Medias'); 
     221 
     222    my $new = $c->model('Base')->resultset('MediasPaths')->search({ 
     223            d_media => { IN => $rsdist->get_column('d_media_key')->as_query }, 
     224        })->delete; 
     225 
     226    # $c->model('Base')->storage->dbh->rollback; 
     227     
     228} 
     229 
     230sub load_distrib : XMLRPC { 
     231    my ( $self, $c, $dump ) = @_; 
     232 
     233    my $ref = thaw($dump); 
     234 
     235    warn keys %{$ref->{path}}; 
     236 
     237    $c->forward('clean_distrib', [ $ref->{distrib} ]); 
     238 
     239    $c->forward('create', [  
     240            $ref->{distrib}{distribution}, 
     241            $ref->{distrib}{release}, 
     242            $ref->{distrib}{arch}, 
     243        ]); 
     244 
     245    foreach my $media (@{ $ref->{media} || []}) { 
     246        $c->forward('add_media', [ $ref->{distrib}, $media ]); 
     247    } 
     248    foreach my $media (keys %{ $ref->{path} || [] }) { 
     249        foreach my $path (@{ $ref->{path}{$media} || [] }) { 
     250            $c->forward('media_path', [ $ref->{distrib}, $media, $path ]); 
     251        } 
     252    } 
     253 
     254    #$c->model('Base')->storage->dbh->rollback; 
     255} 
     256 
    179257=head1 AUTHOR 
    180258 
  • server/trunk/web/lib/Sophie/Controller/Distrib.pm

    r41 r42  
    7474            label => $_->label, 
    7575            group_label => $_->group_label, 
    76             key => $_->d_media_key, 
    7776        }  
    7877    } $rs->all ]; 
  • server/trunk/web/lib/Sophie/Controller/Root.pm

    r41 r42  
    8888    } 
    8989    $c->stash->{data} = $c->stash->{xmlrpc}; 
    90     $c->model('Base')->storage->dbh->commit; 
     90    $c->model('Base')->storage->dbh->rollback; 
    9191} 
    9292 
  • server/trunk/web/lib/Sophie/Model/Base.pm

    r41 r42  
    77    schema_class => 'Sophie::Base', 
    88    connect_info => { 
    9         dsn => 'toto', 
     9        dsn => '', 
     10        private_cache_key => __PACKAGE__, 
     11        AutoCommit => 0, 
    1012    },     
    1113); 
Note: See TracChangeset for help on using the changeset viewer.