use PVE::Exception qw(raise_param_exc);
use PVE::VZDump;
use PVE::VZDump::Common;
+use PVE::VZDump::JobBase;
use PVE::Jobs; # for VZDump Jobs
use Proxmox::RS::CalendarEvent;
if $data->{ids}->{$id};
PVE::VZDump::verify_vzdump_parameters($param, 1);
- my $plugin = PVE::Jobs::Plugin->lookup('vzdump');
- my $opts = $plugin->check_config($id, $param, 1, 1);
+ my $opts = PVE::VZDump::JobBase->check_config($id, $param, 1, 1);
$data->{ids}->{$id} = $opts;
die "no options specified\n" if !scalar(keys %$param);
PVE::VZDump::verify_vzdump_parameters($param);
- my $plugin = PVE::Jobs::Plugin->lookup('vzdump');
- my $opts = $plugin->check_config($id, $param, 0, 1);
+ my $opts = PVE::VZDump::JobBase->check_config($id, $param, 0, 1);
# try to find it in old vzdump.cron and convert it to a job
my ($idx) = grep { $jobs->[$_]->{id} eq $id } (0 .. scalar(@$jobs) - 1);
use warnings;
use JSON;
-use PVE::Cluster qw(cfs_read_file cfs_lock_file);
-use PVE::Jobs::Plugin;
+use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_register_file);
+use PVE::Job::Registry;
use PVE::Jobs::VZDump;
use PVE::Tools;
PVE::Jobs::VZDump->register();
-PVE::Jobs::Plugin->init();
+PVE::Job::Registry->init();
+
+cfs_register_file(
+ 'jobs.cfg',
+ sub { PVE::Job::Registry->parse_config(@_); },
+ sub { PVE::Job::Registry->write_config(@_); },
+);
my $state_dir = "/var/lib/pve-manager/jobs";
my $lock_dir = "/var/lock/pve-manager";
next if !defined($next_sync) || time() < $next_sync; # not yet its (next) turn
- my $plugin = PVE::Jobs::Plugin->lookup($type);
+ my $plugin = PVE::Job::Registry->lookup($type);
if (starting_job($id, $type)) {
my $upid = eval { $plugin->run($cfg, $id, $schedule) };
if (my $err = $@) {
include ../../defines.mk
PERLSOURCE = \
- Plugin.pm\
- VZDump.pm
+ VZDump.pm \
all:
+++ /dev/null
-package PVE::Jobs::Plugin;
-
-use strict;
-use warnings;
-
-use PVE::Cluster qw(cfs_register_file);
-
-use base qw(PVE::SectionConfig);
-
-cfs_register_file(
- 'jobs.cfg',
- sub { __PACKAGE__->parse_config(@_); },
- sub { __PACKAGE__->write_config(@_); }
-);
-
-my $defaultData = {
- propertyList => {
- type => { description => "Section type." },
- id => {
- description => "The ID of the job.",
- type => 'string',
- format => 'pve-configid',
- maxLength => 64,
- },
- enabled => {
- description => "Determines if the job is enabled.",
- type => 'boolean',
- default => 1,
- optional => 1,
- },
- schedule => {
- description => "Backup schedule. The format is a subset of `systemd` calendar events.",
- type => 'string', format => 'pve-calendar-event',
- maxLength => 128,
- },
- comment => {
- optional => 1,
- type => 'string',
- description => "Description for the Job.",
- maxLength => 512,
- },
- 'repeat-missed' => {
- optional => 1,
- type => 'boolean',
- description => "If true, the job will be run as soon as possible if it was missed".
- " while the scheduler was not running.",
- default => 0,
- },
- },
-};
-
-sub private {
- return $defaultData;
-}
-
-sub parse_config {
- my ($class, $filename, $raw) = @_;
-
- my $cfg = $class->SUPER::parse_config($filename, $raw);
-
- foreach my $id (sort keys %{$cfg->{ids}}) {
- my $data = $cfg->{ids}->{$id};
-
- $data->{id} = $id;
- $data->{enabled} //= 1;
-
- if (defined($data->{comment})) {
- $data->{comment} = PVE::Tools::decode_text($data->{comment});
- }
- }
-
- return $cfg;
-}
-
-# call the plugin specific decode/encode code
-sub decode_value {
- my ($class, $type, $key, $value) = @_;
-
- my $plugin = __PACKAGE__->lookup($type);
- return $plugin->decode_value($type, $key, $value);
-}
-
-sub encode_value {
- my ($class, $type, $key, $value) = @_;
-
- my $plugin = __PACKAGE__->lookup($type);
- return $plugin->encode_value($type, $key, $value);
-}
-
-sub write_config {
- my ($class, $filename, $cfg) = @_;
-
- for my $job (values $cfg->{ids}->%*) {
- if (defined($job->{comment})) {
- $job->{comment} = PVE::Tools::encode_text($job->{comment});
- }
- }
-
- $class->SUPER::write_config($filename, $cfg);
-}
-
-sub run {
- my ($class, $cfg) = @_;
- # implement in subclass
- die "not implemented";
-}
-
-1;
use strict;
use warnings;
-use PVE::INotify;
-use PVE::VZDump::Common;
-use PVE::API2::VZDump;
use PVE::Cluster;
use PVE::JSONSchema;
-use base qw(PVE::Jobs::Plugin);
-
-sub type {
- return 'vzdump';
-}
-
-my $props = PVE::VZDump::Common::json_config_properties();
-
-sub properties {
- return $props;
-}
-
-sub options {
- my $options = {
- enabled => { optional => 1 },
- schedule => {},
- comment => { optional => 1 },
- 'repeat-missed' => { optional => 1 },
- };
- foreach my $opt (keys %$props) {
- if ($props->{$opt}->{optional}) {
- $options->{$opt} = { optional => 1 };
- } else {
- $options->{$opt} = {};
- }
- }
-
- return $options;
-}
-
-sub decode_value {
- my ($class, $type, $key, $value) = @_;
-
- if ((my $format = $PVE::VZDump::Common::PROPERTY_STRINGS->{$key}) && !ref($value)) {
- $value = PVE::JSONSchema::parse_property_string($format, $value);
- }
-
- return $value;
-}
-
-sub encode_value {
- my ($class, $type, $key, $value) = @_;
+use PVE::VZDump::Common;
- if ((my $format = $PVE::VZDump::Common::PROPERTY_STRINGS->{$key}) && ref($value) eq 'HASH') {
- $value = PVE::JSONSchema::print_property_string($value, $format);
- }
+use PVE::API2::VZDump;
- return $value;
-}
+use base qw(PVE::VZDump::JobBase);
sub run {
my ($class, $conf) = @_;
+ my $props = $class->properties();
# remove all non vzdump related options
foreach my $opt (keys %$conf) {
delete $conf->{$opt} if !defined($props->{$opt});
}
- # Required as string parameters
+ # Required as string parameters # FIXME why?! we could just check ref()
for my $key (keys $PVE::VZDump::Common::PROPERTY_STRINGS->%*) {
if ($conf->{$key} && ref($conf->{$key}) eq 'HASH') {
my $format = $PVE::VZDump::Common::PROPERTY_STRINGS->{$key};
$conf->{quiet} = 1; # do not write to stdout/stderr
- PVE::Cluster::cfs_update(); # refresh vmlist
+ PVE::Cluster::cfs_update(); # refresh vmlist; FIXME: move this to the job run loop
return PVE::API2::VZDump->vzdump($conf);
}