Skip to content

Commit

Permalink
[backend] refactor partition and remote handling in src server
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Jul 27, 2016
1 parent 9623d53 commit 00f302e
Show file tree
Hide file tree
Showing 4 changed files with 937 additions and 830 deletions.
1 change: 1 addition & 0 deletions dist/obs-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ chown %{apache_user}:%{apache_group} /srv/www/obs/api/log/production.log
/usr/lib/obs/server/plugins
/usr/lib/obs/server/BSRepServer
/usr/lib/obs/server/BSSched
/usr/lib/obs/server/BSSrcServer
/usr/lib/obs/server/XML
/usr/lib/obs/server/*.pm
/usr/lib/obs/server/BSConfig.pm.template
Expand Down
105 changes: 105 additions & 0 deletions src/backend/BSSrcServer/Partition.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Copyright (c) 2016 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
package BSSrcServer::Partition;

use strict;
use warnings;

use BSConfiguration;
use BSRevision;
use BSUtil;

sub projid2reposerver {
my ($projid) = @_;
return $BSConfig::reposerver unless $BSConfig::partitionservers;
my @p = @{$BSConfig::partitioning || []};
my $par;
while (@p) {
if ($projid =~ /^$p[0]/) {
$par = $p[1];
last;
}
splice(@p, 0, 2);
}
$par = $BSConfig::partition unless defined $par;
die("cannot determine partition for $projid\n") unless defined $par;
die("partition '$par' from partitioning does not exist\n") unless $BSConfig::partitionservers->{$par};
return $BSConfig::partitionservers->{$par};
}

sub allreposervers {
return ($BSConfig::reposerver) unless $BSConfig::partitionservers;
return sort(BSUtil::unify(values(%$BSConfig::partitionservers)));
}

sub projid2partition {
my ($projid) = @_;
return undef unless $BSConfig::partitioning;
my @p = @{$BSConfig::partitioning || []};
my $par;
while (@p) {
if ($projid =~ /^$p[0]/) {
$par = $p[1];
last;
}
splice(@p, 0, 2);
}
$par = $BSConfig::partition unless defined $par;
die("cannot determine partition for $projid\n") unless defined $par;
die("partition '$par' from partitioning does not exist\n") unless $BSConfig::partitionservers->{$par};
return $par;
}

sub checkpartition {
my ($remotemap, $projid, $proj) = @_;
$remotemap->{':partitions'}->{$projid} = 1;
return if $remotemap->{$projid};
my @p = @{$BSConfig::partitioning || []};
my $par;
while (@p) {
if ($projid =~ /^$p[0]/) {
$par = $p[1];
last;
}
splice(@p, 0, 2);
}
$par = $BSConfig::partition unless defined $par;
die("cannot determine partition for $projid\n") unless defined $par;
return if $par eq $remotemap->{':partition'};
my $reposerver = $BSConfig::reposerver;
if ($BSConfig::partitionservers) {
$reposerver = $BSConfig::partitionservers->{$par};
die("partition '$par' from partitioning does not exist\n") unless $reposerver;
}
$remotemap->{$projid} = {
'name' => $projid, 'remoteurl' => $reposerver, 'remoteproject' => $projid, 'partition' => $par,
};
$proj ||= BSRevision::readproj_loacal($projid, 1);
if (!$proj) {
$remotemap->{$projid} = { 'name' => $projid }; # gone!
return;
}
$remotemap->{$projid}->{'repository'} = $proj->{'repository'} if $proj->{'repository'};
$remotemap->{$projid}->{'kind'} = $proj->{'kind'} if $proj->{'kind'};
if ($proj->{'access'}) {
for ('access', 'publish', 'person', 'group') {
$remotemap->{$projid}->{$_} = $proj->{$_} if exists $proj->{$_};
}
}
}

1;
Loading

0 comments on commit 00f302e

Please sign in to comment.