/usr/lib/obs/server/BSSched/EventSource/Directory.pm is in obs-server 2.7.1-10.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | # Copyright (c) 2015 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 BSSched::EventSource::Directory;
use strict;
use warnings;
use POSIX;
use Digest::MD5 ();
use Data::Dumper;
use BSUtil;
use BSXML;
=head1 NAME
BSSched::EventSource::Directory
=head1 DESCRIPTION
This class/module is reponsible for the scheduler`s event management,
e.g. creating, sending and reading events.
=head1 FUNCTIONS
=cut
###
### Event reader code
###
=head2 readevents - read events from a directory
we special case the "built" event type as it is so common
=cut
sub readevents {
my ($gctx, $eventdir) = @_;
my @events;
for my $evfilename (sort(ls($eventdir))) {
next if $evfilename =~ /^\./;
my $ev;
if ($evfilename =~ /^finished:(.*)/) {
$ev = {'type' => 'built', 'job' => $1, 'evfilename' => "$eventdir/$evfilename"};
} else {
$ev = readxml("$eventdir/$evfilename", $BSXML::event, 1);
if (!$ev) {
print "$evfilename: bad event xml\n";
unlink("$eventdir/$evfilename");
next;
}
$ev->{'type'} ||= 'unknown';
$ev->{'evfilename'} = "$eventdir/$evfilename";
}
push @events, $ev;
}
return @events;
}
###
### Event writer code
###
=head2 sendevent - send an event to a different scheduler / publisher / signer
TODO: add description
=cut
sub sendevent {
my ($gctx, $ev, $arch, $evname) = @_;
my $eventdir = $gctx->{'eventdir'};
mkdir_p("$eventdir/$arch");
$evname = "$ev->{'type'}:::".Digest::MD5::md5_hex($evname) if length($evname) > 200;
writexml("$eventdir/$arch/.$evname$$", "$eventdir/$arch/$evname", $ev, $BSXML::event);
BSUtil::ping("$eventdir/$arch/.ping");
}
=head2 sendrepochangeevent - send a repository/repoinfo event
we don't directly send it to the src server, as this would
slow down the scheduler too much. Instead, we write it on
disk and the dispatcher will pick it up and send it for us.
=cut
sub sendrepochangeevent {
my ($gctx, $prp, $type) = @_;
my $myarch = $gctx->{'arch'};
my ($projid, $repoid) = split('/', $prp, 2);
my $ev = {
'type' => ($type || 'repository'),
'project' => $projid,
'repository' => $repoid,
'arch' => $myarch,
};
sendevent($gctx, $ev, 'repository', "${projid}::${repoid}::${myarch}");
}
=head2 sendunblockedevent - send an unblocked event to another scheduler
input: $prp - prp that is unblocked
$arch - target scheduler architecture
=cut
sub sendunblockedevent {
my ($gctx, $prp, $arch) = @_;
my ($projid, $repoid) = split('/', $prp, 2);
my $ev = {
'type' => 'unblocked',
'project' => $projid,
'repository' => $repoid,
};
sendevent($gctx, $ev, $arch, "unblocked::${projid}::${repoid}");
}
=head2 sendpublishevent - send a publish event to the publisher
input: $prp - prp to be published
=cut
sub sendpublishevent {
my ($gctx, $prp) = @_;
my ($projid, $repoid) = split('/', $prp, 2);
my $ev = {
'type' => 'publish',
'project' => $projid,
'repository' => $repoid,
};
sendevent($gctx, $ev, 'publish', "${projid}::$repoid");
}
=head2 sendimportevent - send an import event to another scheduler
input: $job - import job name
$arch - target scheduler architecture
=cut
sub sendimportevent {
my ($gctx, $job, $arch) = @_;
my $ev = {
'type' => 'import',
'job' => $job,
};
# prefix with "import." so that there's no name conflict
sendevent($gctx, $ev, $arch, "import.$job");
}
1;
|