From 96ed444bbbc9362cfe7941a8c5daae51b8fc245b Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 22 May 2017 22:52:51 +0100 Subject: [PATCH] set up list of jobs the backend instance should skip --- lib/App/Netdisco/Backend/Worker/Manager.pm | 6 ++- lib/App/Netdisco/JobQueue.pm | 7 ++++ lib/App/Netdisco/JobQueue/PostgreSQL.pm | 47 ++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/App/Netdisco/Backend/Worker/Manager.pm b/lib/App/Netdisco/Backend/Worker/Manager.pm index 58b5bb76..f6763f1e 100644 --- a/lib/App/Netdisco/Backend/Worker/Manager.pm +++ b/lib/App/Netdisco/Backend/Worker/Manager.pm @@ -8,7 +8,8 @@ use App::Netdisco::Util::Backend; use Role::Tiny; use namespace::clean; -use App::Netdisco::JobQueue qw/jq_locked jq_getsome jq_getsomep jq_lock/; +use App::Netdisco::JobQueue + qw/jq_locked jq_getsome jq_getsomep jq_lock jq_prime_skiplist/; sub worker_begin { my $self = shift; @@ -19,6 +20,9 @@ sub worker_begin { debug "entering Manager ($wid) worker_begin()"; + # rebuild device skip hints + jq_prime_skiplist; + # requeue jobs locally debug "mgr ($wid): searching for jobs booked to this processing node"; my @jobs = jq_locked; diff --git a/lib/App/Netdisco/JobQueue.pm b/lib/App/Netdisco/JobQueue.pm index fd93e726..1c5a059e 100644 --- a/lib/App/Netdisco/JobQueue.pm +++ b/lib/App/Netdisco/JobQueue.pm @@ -13,6 +13,7 @@ our @EXPORT_OK = qw/ jq_getsomep jq_locked jq_queued + jq_prime_skiplist jq_log jq_userlog jq_lock @@ -57,6 +58,12 @@ Netdisco job instance interface (see below). Returns a list of IP addresses of devices which currently have a job of the given C<$job_type> queued (e.g. C, C, etc). +=head2 jq_prime_skiplist() + +Sets up a table of hints for the backend daemon manager to help avoid picking +jobs from the queue that it cannot process due to C<*_no> configuration +settings. + =head2 jq_log() Returns a list of the most recent 50 jobs in the queue. Jobs are returned as diff --git a/lib/App/Netdisco/JobQueue/PostgreSQL.pm b/lib/App/Netdisco/JobQueue/PostgreSQL.pm index d2026e6f..6dcafbd6 100644 --- a/lib/App/Netdisco/JobQueue/PostgreSQL.pm +++ b/lib/App/Netdisco/JobQueue/PostgreSQL.pm @@ -3,7 +3,11 @@ package App::Netdisco::JobQueue::PostgreSQL; use Dancer qw/:moose :syntax :script/; use Dancer::Plugin::DBIC 'schema'; +use App::Netdisco::Util::Device + qw/is_discoverable is_macsuckable is_arpnipable/; use App::Netdisco::Backend::Job; + + use Net::Domain 'hostfqdn'; use Module::Load (); use Try::Tiny; @@ -15,6 +19,7 @@ our @EXPORT_OK = qw/ jq_getsomep jq_locked jq_queued + jq_prime_skiplist jq_log jq_userlog jq_lock @@ -89,6 +94,48 @@ sub jq_queued { })->get_column('device')->all; } +sub jq_prime_skiplist { + my $fqdn = hostfqdn || 'localhost'; + my $rs = schema('netdisco')->resultset('DeviceSkip'); + my @d_actions = ('discover', @{ setting('job_prio')->{high} }); + + schema('netdisco')->txn_do(sub { + my @devices = schema('netdisco')->resultset('Device')->all; + $rs->search({ backend => $fqdn })->delete; + + foreach my $action (@d_actions) { + $rs->populate([ + map {{ + backend => $fqdn, + device => $_->ip, + action => $action, + skipover => \'true', + }} grep { not is_discoverable($_) } @devices + ]); + } + + foreach my $action (qw/macsuck nbtstat/) { + $rs->populate([ + map {{ + backend => $fqdn, + device => $_->ip, + action => $action, + skipover => \'true', + }} grep { not is_macsuckable($_) } @devices + ]); + } + + $rs->populate([ + map {{ + backend => $fqdn, + device => $_->ip, + action => 'arpnip', + skipover => \'true', + }} grep { not is_arpnipable($_) } @devices + ]); + }); +} + sub jq_log { return schema('netdisco')->resultset('Admin')->search({}, { order_by => { -desc => [qw/entered device action/] },