all the bug fixes and a working plugin!!!!!!!!! :-D
This commit is contained in:
@@ -34,7 +34,7 @@ sub _load_web_plugins {
|
|||||||
if $plugin !~ m/^\+/;
|
if $plugin !~ m/^\+/;
|
||||||
$plugin =~ s/^\+//;
|
$plugin =~ s/^\+//;
|
||||||
|
|
||||||
debug "loading Netdisco plugin $plugin";
|
$ENV{PLUGIN_LOAD_DEBUG} && debug "loading Netdisco plugin $plugin";
|
||||||
Module::Load::load $plugin;
|
Module::Load::load $plugin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ sub load_worker_plugins {
|
|||||||
if $plugin !~ m/^\+/;
|
if $plugin !~ m/^\+/;
|
||||||
$plugin =~ s/^\+//;
|
$plugin =~ s/^\+//;
|
||||||
|
|
||||||
debug "loading Netdisco plugin $plugin";
|
$ENV{PLUGIN_LOAD_DEBUG} && debug "loading Netdisco plugin $plugin";
|
||||||
eval { Module::Load::load $plugin };
|
eval { Module::Load::load $plugin };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ use App::Netdisco::Util::Permission qw/check_acl_no check_acl_only/;
|
|||||||
set( '_nd2worker_hooks' => [] );
|
set( '_nd2worker_hooks' => [] );
|
||||||
|
|
||||||
register 'register_worker' => sub {
|
register 'register_worker' => sub {
|
||||||
my ($self, $workerconf, $code) = @_;
|
my ($self, $workerconf, $code) = plugin_args(@_);
|
||||||
return error "bad param to register_worker"
|
return error "bad param to register_worker"
|
||||||
unless ((ref sub {} eq ref $code) and (ref {} eq ref $workerconf));
|
unless ((ref sub {} eq ref $code) and (ref {} eq ref $workerconf));
|
||||||
|
|
||||||
# needs to be here for caller() context
|
# needs to be here for caller() context
|
||||||
my ($package, $action, $phase) = ((caller)[0], undef, undef);
|
my ($package, $action, $phase) = ((caller)[0], undef, undef);
|
||||||
if ($package =~ m/Plugin::(\w+)$/) {
|
if ($package =~ m/::Plugin::(\w+)$/) {
|
||||||
$action = lc $1;
|
$action = lc $1;
|
||||||
}
|
}
|
||||||
if ($package =~ m/Plugin::(\w+)::(\w+)/) {
|
elsif ($package =~ m/::Plugin::(\w+)::(\w+)/) {
|
||||||
$action = lc $1; $phase = lc $2;
|
$action = lc $1; $phase = lc $2;
|
||||||
}
|
}
|
||||||
else { return error "worker Package does not match standard naming" }
|
else { return error "worker Package does not match standard naming" }
|
||||||
@@ -63,17 +63,18 @@ register 'register_worker' => sub {
|
|||||||
};
|
};
|
||||||
|
|
||||||
my $primary = ($workerconf->{primary} ? '_primary' : '');
|
my $primary = ($workerconf->{primary} ? '_primary' : '');
|
||||||
my $hook = 'nd2worker_'. $action .'_'. $phase . $primary;
|
my $hook = 'nd2worker_'. $action .'_'. $workerconf->{phase} . $primary;
|
||||||
my $store = Dancer::Factory::Hook->instance();
|
my $store = Dancer::Factory::Hook->instance();
|
||||||
|
|
||||||
if (not $store->hook_is_registered($hook)) {
|
if (not $store->hook_is_registered($hook)) {
|
||||||
$store->install_hooks($hook);
|
$store->install_hooks($hook);
|
||||||
# track just the basic phase names which are used
|
# track just the basic phase names which are used
|
||||||
push @{ setting('_nd2worker_hooks') }, $hook
|
push @{ setting('_nd2worker_hooks') }, $hook
|
||||||
if $phase ne '00init' and 0 == length($primary);
|
if $workerconf->{phase} ne '00init' and 0 == length($primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
$store->register_hook($hook, $worker);
|
# D::Factory::Hook::register_hook() does not work?!
|
||||||
|
hook $hook => $worker;
|
||||||
};
|
};
|
||||||
|
|
||||||
register_plugin;
|
register_plugin;
|
||||||
|
|||||||
40
lib/App/Netdisco/Worker/Plugin/Psql.pm
Normal file
40
lib/App/Netdisco/Worker/Plugin/Psql.pm
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package App::Netdisco::Worker::Plugin::Psql;
|
||||||
|
|
||||||
|
use Dancer ':syntax';
|
||||||
|
use App::Netdisco::Worker::Plugin;
|
||||||
|
|
||||||
|
use aliased 'App::Netdisco::Worker::Status';
|
||||||
|
|
||||||
|
register_worker({} => sub {
|
||||||
|
my ($job, $workerconf) = @_;
|
||||||
|
my ($device, $port, $extra) = map {$job->$_} qw/device port extra/;
|
||||||
|
|
||||||
|
my $name = ($ENV{NETDISCO_DBNAME} || setting('database')->{name} || 'netdisco');
|
||||||
|
my $host = setting('database')->{host};
|
||||||
|
my $user = setting('database')->{user};
|
||||||
|
my $pass = setting('database')->{pass};
|
||||||
|
|
||||||
|
my $portnum = undef;
|
||||||
|
if ($host and $host =~ m/([^;]+);port=(\d+)/) {
|
||||||
|
$host = $1;
|
||||||
|
$portnum = $2;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ENV{PGHOST} = $host if $host;
|
||||||
|
$ENV{PGPORT} = $portnum if defined $portnum;
|
||||||
|
$ENV{PGDATABASE} = $name;
|
||||||
|
$ENV{PGUSER} = $user;
|
||||||
|
$ENV{PGPASSWORD} = $pass;
|
||||||
|
$ENV{PGCLIENTENCODING} = 'UTF8';
|
||||||
|
|
||||||
|
if ($extra) {
|
||||||
|
system('psql', '-c', $extra);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
system('psql');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status->done('psql session closed.');
|
||||||
|
});
|
||||||
|
|
||||||
|
true;
|
||||||
@@ -62,8 +62,12 @@ sub run {
|
|||||||
@{ (setting('_nd2worker_hooks') || []) };
|
@{ (setting('_nd2worker_hooks') || []) };
|
||||||
|
|
||||||
# run 00init primary
|
# run 00init primary
|
||||||
$self->run_workers("nd2worker_${action}_00init_primary");
|
my $store = Dancer::Factory::Hook->instance();
|
||||||
return if $self->jobstat->not_ok;
|
my $initprimary = "nd2worker_${action}_00init_primary";
|
||||||
|
if (scalar @{ $store->get_hooks_for($initprimary) }) {
|
||||||
|
$self->run_workers($initprimary);
|
||||||
|
return if $self->jobstat->not_ok;
|
||||||
|
}
|
||||||
|
|
||||||
# run each 00init worker
|
# run each 00init worker
|
||||||
$self->run_workers("nd2worker_${action}_00init");
|
$self->run_workers("nd2worker_${action}_00init");
|
||||||
@@ -80,6 +84,7 @@ sub run_workers {
|
|||||||
my $hook = shift or return $self->jobstat->error('missing hook param');
|
my $hook = shift or return $self->jobstat->error('missing hook param');
|
||||||
my $primary = ($hook =~ m/_primary$/);
|
my $primary = ($hook =~ m/_primary$/);
|
||||||
my $store = Dancer::Factory::Hook->instance();
|
my $store = Dancer::Factory::Hook->instance();
|
||||||
|
# debug "entering hook $hook";
|
||||||
|
|
||||||
foreach my $worker (@{ $store->get_hooks_for($hook) }) {
|
foreach my $worker (@{ $store->get_hooks_for($hook) }) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user