our %equivs;
foreach my $ident (@ARGV) {
- my $hid= { Conds => { host => [] } };
+ my $hid= { Conds => { host => [] }, Diverse => [] };
my $override_use;
if ($ident =~ m/\=/) {
$hid->{OverrideUse}= $'; #'
my $equiv= $hid->{Equiv}= $equivs{$formalclass};
print DEBUG "HID $ident FLAG $flag EQUIV $equiv->{Wanted}\n";
next;
+ } elsif ($flag =~ m/^diverse-/) {
+ my $dclass= $'; #'
+ push @{ $hid->{Diverse} }, $dclass;
+ print DEBUG "HID $ident FLAG $flag DIVERSE $dclass\n";
+ next;
} elsif ($flag =~ m/^\w+:/) {
my (@c) = split /:/, $flag;
my $o;
LIMIT 1;
END
+ # we are looking for other jobs where the runvar diversehosts_CLASS
+ # (a space-separated list of hostnames) has been set
+ my $diverseq = $dbh_tests->prepare(<<END);
+ SELECT r.job, r.val
+ FROM runvars r
+ WHERE r.flight = ?
+ AND r.name = ?
+END
+
my @candidates;
my $any=0;
+ my %diverse_excluded;
+ # $diverse_excluded{CLASS}{HOST} = 1
+ foreach my $dclass (@{ $hid->{Diverse} }) {
+ print DEBUG "HID $hid->{Ident} DIVERSE $dclass:";
+ # look for allocated
+ $diverseq->execute($flight, "diversehosts_$dclass");
+ my ($djob, $dhosts) = $diverseq->fetchrow_array();
+ my $excl = sub {
+ my ($dh,$why) = @_;
+ print DEBUG " $dh ($why)";
+ $diverse_excluded{$dclass}{$dh} = $why;
+ };
+ if (defined $dhosts) {
+ $excl->($_, "alloc'd job $job") foreach split / /, $dhosts;
+ }
+ # look for booked
+ my $notekey = "hostalloc-diverse-$flight-$dclass";
+ my $booked = $plan->{ClientNotes}{$notekey};
+ $excl->($_, "boooked ".$booked->{$_}) foreach sort keys %$booked;
+ print DEBUG ".\n";
+ }
+
CANDIDATE:
while (my $candrow= $findhostsq->fetchrow_hashref()) {
$candrow->{Warnings}= [ ];
"specified host lacks flags @missingflags";
}
+ foreach my $dclass (@{ $hid->{Diverse} }) {
+ my $excl = $diverse_excluded{$dclass}{ $candrow->{resname} };
+ next unless defined $excl;
+ print DEBUG "$dbg excluded by diverse-$dclass ($excl)\n";
+ next CANDIDATE unless defined $use;
+ }
+
foreach my $c (@{ $hid->{Conds}{$candrow->{restype}} }) {
if (!$c->check($candrow->{restype}, $candrow->{resname})) {
print DEBUG "$dbg failed $c condition\n";
my $use= $r{ $hid->{Ident} };
next if defined $use;
store_runvar($hid->{Ident}, $sel->{resname});
+ foreach my $dclass (@{ $hid->{Diverse} }) {
+ my $drk = "diversehosts_$dclass";
+ my %dused;
+ $dused{$_} = 1 foreach split / /, ($r{$drk} // '');
+ $dused{$sel->{resname}} = 1;
+ store_runvar($drk, join ' ', sort keys %dused);
+ }
}
logm("host allocation: all successful and recorded.");
sub compute_booking_list () {
my @bookings;
+ my %cnotes;
foreach my $hid (@hids) {
my $sel= $hid->{Selected};
my $alloc= $hid->{Allocated};
$book->{Start}= $best->{Start};
$book->{End}= $best->{Start} + $best->{Duration};
push @bookings, $book;
+ foreach my $dclass (@{ $hid->{Diverse} }) {
+ my $notekey = "hostalloc-diverse-$flight-$dclass";
+ $cnotes{$notekey}{$sel->{resname}} = "$job $hid->{Ident}";
+ }
}
- return { Bookings => \@bookings };
+ return { Bookings => \@bookings, ClientNotes => \%cnotes };
}
#---------- actually allocate things ----------