From dc6fd37e02e1bf50deeb72f134d8607a6eabad3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20He=C3=9F?= Date: Wed, 16 Jul 2025 17:05:45 +0200 Subject: [PATCH] Show queue runner v2 status This is guarded behind a setting and will overwrite everything that was learned from the machines file. Also drops `sshKeys` since that wasn't used anyway. --- src/lib/Hydra/Controller/Root.pm | 6 ++- src/lib/Hydra/Helper/Nix.pm | 77 +++++++++++++++++++++----------- t/Hydra/Helper/Nix.t | 4 -- 3 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 0a5d05e5..d78e1b6d 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -189,8 +189,10 @@ sub machines :Local Args(0) { my ($self, $c) = @_; my $machines = getMachines; - # Add entry for localhost. - $machines->{''} //= {}; + # Add entry for localhost. The implicit addition is not needed with queue runner v2 + if (not $c->config->{'queue_runner_endpoint'}) { + $machines->{''} //= {}; + } delete $machines->{'localhost'}; my $status = $c->model('DB::SystemStatus')->find("queue-runner"); diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 134b8b7e..5150ec47 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -12,6 +12,8 @@ use Nix::Store; use Encode; use Sys::Hostname::Long; use IPC::Run; +use LWP::UserAgent; +use JSON::MaybeXS; use UUID4::Tiny qw(is_uuid4_string); our @ISA = qw(Exporter); @@ -340,37 +342,60 @@ sub getEvals { sub getMachines { my %machines = (); + my $config = getHydraConfig(); - my @machinesFiles = split /:/, ($ENV{"NIX_REMOTE_SYSTEMS"} || "/etc/nix/machines"); + if ($config->{'queue_runner_endpoint'}) { + my $ua = LWP::UserAgent->new(); + my $resp = $ua->get($config->{'queue_runner_endpoint'} . "/status/machines"); + if (not $resp->is_success) { + print STDERR "Unable to ask queue runner for machines\n"; + return \%machines; + } - for my $machinesFile (@machinesFiles) { - next unless -e $machinesFile; - open(my $conf, "<", $machinesFile) or die; - while (my $line = <$conf>) { - chomp($line); - $line =~ s/\#.*$//g; - next if $line =~ /^\s*$/; - my @tokens = split /\s+/, $line; + my $data = decode_json($resp->decoded_content) or return \%machines; + my $machinesData = $data->{machines}; - if (!defined($tokens[5]) || $tokens[5] eq "-") { - $tokens[5] = ""; - } - my @supportedFeatures = split(/,/, $tokens[5] || ""); - - if (!defined($tokens[6]) || $tokens[6] eq "-") { - $tokens[6] = ""; - } - my @mandatoryFeatures = split(/,/, $tokens[6] || ""); - $machines{$tokens[0]} = - { systemTypes => [ split(/,/, $tokens[1]) ] - , sshKeys => $tokens[2] - , maxJobs => int($tokens[3]) - , speedFactor => 1.0 * (defined $tokens[4] ? int($tokens[4]) : 1) - , supportedFeatures => [ @supportedFeatures, @mandatoryFeatures ] - , mandatoryFeatures => [ @mandatoryFeatures ] + foreach my $machineName (keys %$machinesData) { + my $machine = %$machinesData{$machineName}; + $machines{$machineName} = + { systemTypes => $machine->{systems} + , maxJobs => $machine->{maxJobs} + , speedFactor => $machine->{speedFactor} + , supportedFeatures => [ @{$machine->{supportedFeatures}}, @{$machine->{mandatoryFeatures}} ] + , mandatoryFeatures => [ @{$machine->{mandatoryFeatures}} ] }; } - close $conf; + } else { + my @machinesFiles = split /:/, ($ENV{"NIX_REMOTE_SYSTEMS"} || "/etc/nix/machines"); + + for my $machinesFile (@machinesFiles) { + next unless -e $machinesFile; + open(my $conf, "<", $machinesFile) or die; + while (my $line = <$conf>) { + chomp($line); + $line =~ s/\#.*$//g; + next if $line =~ /^\s*$/; + my @tokens = split /\s+/, $line; + + if (!defined($tokens[5]) || $tokens[5] eq "-") { + $tokens[5] = ""; + } + my @supportedFeatures = split(/,/, $tokens[5] || ""); + + if (!defined($tokens[6]) || $tokens[6] eq "-") { + $tokens[6] = ""; + } + my @mandatoryFeatures = split(/,/, $tokens[6] || ""); + $machines{$tokens[0]} = + { systemTypes => [ split(/,/, $tokens[1]) ] + , maxJobs => int($tokens[3]) + , speedFactor => 1.0 * (defined $tokens[4] ? int($tokens[4]) : 1) + , supportedFeatures => [ @supportedFeatures, @mandatoryFeatures ] + , mandatoryFeatures => [ @mandatoryFeatures ] + }; + } + close $conf; + } } return \%machines; diff --git a/t/Hydra/Helper/Nix.t b/t/Hydra/Helper/Nix.t index a34cfe02..98c1f8c0 100644 --- a/t/Hydra/Helper/Nix.t +++ b/t/Hydra/Helper/Nix.t @@ -33,7 +33,6 @@ close $fh; is(Hydra::Helper::Nix::getMachines(), { 'root@ip' => { 'systemTypes' => ["x86_64-darwin"], - 'sshKeys' => '/sshkey', 'maxJobs' => 15, 'speedFactor' => 15, 'supportedFeatures' => ["big-parallel", "kvm", "nixos-test" ], @@ -41,7 +40,6 @@ is(Hydra::Helper::Nix::getMachines(), { }, 'root@baz' => { 'systemTypes' => [ "aarch64-darwin" ], - 'sshKeys' => '/sshkey', 'maxJobs' => 4, 'speedFactor' => 1, 'supportedFeatures' => ["big-parallel"], @@ -49,7 +47,6 @@ is(Hydra::Helper::Nix::getMachines(), { }, 'root@bux' => { 'systemTypes' => [ "i686-linux", "x86_64-linux" ], - 'sshKeys' => '/var/sshkey', 'maxJobs' => 1, 'speedFactor' => 1, 'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ], @@ -57,7 +54,6 @@ is(Hydra::Helper::Nix::getMachines(), { }, 'root@lotsofspace' => { 'systemTypes' => [ "i686-linux", "x86_64-linux" ], - 'sshKeys' => '/var/sshkey', 'maxJobs' => 1, 'speedFactor' => 1, 'supportedFeatures' => [ "kvm", "nixos-test", "benchmark" ],