* Added the 'job_status' column to the 'jobs' table where progress to be shown to users is stored.

* Updated anvil-configure-network to use Database->insert_or_update_jobs().

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent d86750ba01
commit d6846841a2
  1. 38
      Anvil/Tools/Database.pm
  2. 3
      share/words.xml
  3. 61
      tools/anvil-configure-network
  4. 2
      tools/anvil-daemon
  5. 6
      tools/anvil.sql

@ -1588,6 +1588,12 @@ When C<< anvil-jobs >> picks up a job, it will record it's PID here.
This is a numeric value between C<< 0 >> and C<< 100 >>. The job will update this as it runs, with C<< 100 >> indicating that the job is complete. A value of C<< 0 >> will indicate that the job needs to be started. When the daemon picks up the job, it will set this to C<< 1 >>. Any value in between is set by the job itself. This is a numeric value between C<< 0 >> and C<< 100 >>. The job will update this as it runs, with C<< 100 >> indicating that the job is complete. A value of C<< 0 >> will indicate that the job needs to be started. When the daemon picks up the job, it will set this to C<< 1 >>. Any value in between is set by the job itself.
=head3 job_status (optional)
This is used to tell the user the current status of the job. It can be included when C<< update_progress_only >> is set.
The expected format is C<< <key>,!!var1!foo!!,...,!!varN!bar!!\n >>, one key/variable set per line. The new lines will be converted to C<< <br />\n >> automatically in Striker.
=head3 job_title (required*) =head3 job_title (required*)
This is a string key to display in the title of the box showing that the job is running. This is a string key to display in the title of the box showing that the job is running.
@ -1602,6 +1608,10 @@ This is the C<< job_uuid >> to update. If it is not specified but the C<< job_na
* This or C<< job_name >> must be passed * This or C<< job_name >> must be passed
=head3 update_progress_only (optional)
When set, the progress percentage and, optionally, the C<< job_data >>, will be updated only.
=cut =cut
sub insert_or_update_jobs sub insert_or_update_jobs
{ {
@ -1625,6 +1635,7 @@ sub insert_or_update_jobs
my $job_progress = defined $parameter->{job_progress} ? $parameter->{job_progress} : 0; my $job_progress = defined $parameter->{job_progress} ? $parameter->{job_progress} : 0;
my $job_title = defined $parameter->{job_title} ? $parameter->{job_title} : ""; my $job_title = defined $parameter->{job_title} ? $parameter->{job_title} : "";
my $job_description = defined $parameter->{job_description} ? $parameter->{job_description} : ""; my $job_description = defined $parameter->{job_description} ? $parameter->{job_description} : "";
my $job_status = defined $parameter->{job_status} ? $parameter->{job_status} : "";
my $update_progress_only = defined $parameter->{update_progress_only} ? $parameter->{update_progress_only} : 0; my $update_progress_only = defined $parameter->{update_progress_only} ? $parameter->{update_progress_only} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
id => $id, id => $id,
@ -1641,6 +1652,7 @@ sub insert_or_update_jobs
job_progress => $job_progress, job_progress => $job_progress,
job_title => $job_title, job_title => $job_title,
job_description => $job_description, job_description => $job_description,
job_status => $job_status,
update_progress_only => $update_progress_only, update_progress_only => $update_progress_only,
}}); }});
@ -1774,6 +1786,7 @@ INSERT INTO
job_progress, job_progress,
job_title, job_title,
job_description, job_description,
job_status,
modified_date modified_date
) VALUES ( ) VALUES (
".$anvil->data->{sys}{use_db_fh}->quote($job_uuid).", ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid).",
@ -1787,7 +1800,8 @@ INSERT INTO
".$anvil->data->{sys}{use_db_fh}->quote($job_progress).", ".$anvil->data->{sys}{use_db_fh}->quote($job_progress).",
".$anvil->data->{sys}{use_db_fh}->quote($job_title).", ".$anvil->data->{sys}{use_db_fh}->quote($job_title).",
".$anvil->data->{sys}{use_db_fh}->quote($job_description).", ".$anvil->data->{sys}{use_db_fh}->quote($job_description).",
".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})." ".$anvil->data->{sys}{use_db_fh}->quote($job_status).",
".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
); );
"; ";
$query =~ s/'NULL'/NULL/g; $query =~ s/'NULL'/NULL/g;
@ -1808,7 +1822,8 @@ SELECT
job_name, job_name,
job_progress, job_progress,
job_title, job_title,
job_description job_description,
job_status
FROM FROM
jobs jobs
WHERE WHERE
@ -1834,6 +1849,7 @@ WHERE
my $old_job_progress = $row->[7]; my $old_job_progress = $row->[7];
my $old_job_title = $row->[8]; my $old_job_title = $row->[8];
my $old_job_description = $row->[9]; my $old_job_description = $row->[9];
my $old_job_status = $row->[10];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_job_host_uuid => $old_job_host_uuid, old_job_host_uuid => $old_job_host_uuid,
old_job_command => $old_job_command, old_job_command => $old_job_command,
@ -1845,6 +1861,7 @@ WHERE
old_job_progress => $old_job_progress, old_job_progress => $old_job_progress,
old_job_title => $old_job_title, old_job_title => $old_job_title,
old_job_description => $old_job_description, old_job_description => $old_job_description,
old_job_status => $old_job_status,
}}); }});
# Anything change? # Anything change?
@ -1862,6 +1879,19 @@ SET
WHERE WHERE
job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)." job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)."
"; ";
if ($job_status)
{
$query = "
UPDATE
jobs
SET
job_progress = ".$anvil->data->{sys}{use_db_fh}->quote($job_progress).",
job_status = ".$anvil->data->{sys}{use_db_fh}->quote($job_status).",
modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
WHERE
job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)."
";
}
$query =~ s/'NULL'/NULL/g; $query =~ s/'NULL'/NULL/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__}); $anvil->Database->write({query => $query, source => $file ? $file : $THIS_FILE, line => $line ? $line : __LINE__});
@ -1878,7 +1908,8 @@ WHERE
($old_job_name ne $job_name) or ($old_job_name ne $job_name) or
($old_job_progress ne $job_progress) or ($old_job_progress ne $job_progress) or
($old_job_title ne $job_title) or ($old_job_title ne $job_title) or
($old_job_description ne $job_description)) ($old_job_description ne $job_description) or
($old_job_status ne $job_status))
{ {
# Something changed, save. # Something changed, save.
my $query = " my $query = "
@ -1895,6 +1926,7 @@ SET
job_progress = ".$anvil->data->{sys}{use_db_fh}->quote($job_progress).", job_progress = ".$anvil->data->{sys}{use_db_fh}->quote($job_progress).",
job_title = ".$anvil->data->{sys}{use_db_fh}->quote($job_title).", job_title = ".$anvil->data->{sys}{use_db_fh}->quote($job_title).",
job_description = ".$anvil->data->{sys}{use_db_fh}->quote($job_description).", job_description = ".$anvil->data->{sys}{use_db_fh}->quote($job_description).",
job_status = ".$anvil->data->{sys}{use_db_fh}->quote($job_status).",
modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})." modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})."
WHERE WHERE
job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)." job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)."

@ -36,6 +36,9 @@ Author: Madison Kelly <mkelly@alteeve.ca>
<key name="message_0012">Wrote the journald config file: [#!variable!file!#] to disable rate limiting to ensure high log levels are not lost.</key> <key name="message_0012">Wrote the journald config file: [#!variable!file!#] to disable rate limiting to ensure high log levels are not lost.</key>
<key name="message_0013">The md5sum of: [#!variable!file!#] has changed since the daemon started.</key> <key name="message_0013">The md5sum of: [#!variable!file!#] has changed since the daemon started.</key>
<key name="message_0014">Exiting to reload.</key> <key name="message_0014">Exiting to reload.</key>
<key name="message_0015">The reconfigure of the network has begun.</key>
<key name="message_0016">The hostname: [#!variable!hostname!#] has been set.</key>
<key name="message_0017">Failed to set the hostname: [#!variable!hostname!#]! The hostname is currently [#!variable!bad_hostname!#]. This is probably a program error.</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>

@ -4,6 +4,8 @@
# #
# Exit codes; # Exit codes;
# 0 = Normal exit. # 0 = Normal exit.
# 1 = Job was already picked up by another running instance.
# 2 = The host name did not update properly.
# #
use strict; use strict;
@ -81,15 +83,59 @@ sub reconfigure_network
}}); }});
# Set the hostname # Set the hostname
my $hostnam = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 2}); my $hostname = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 2});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { hostname => $hostname }});
if ($hostname eq $new_hostname) if ($hostname eq $new_hostname)
{ {
# Success # Success
$anvil->Database->insert_or_update_jobs({
job_uuid => $anvil->{job}{uuid},
update_progress_only => 1,
job_progress => 10,
job_status => "message_0016,!!hostname!$new_hostname!!\n",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0016", variables => { hostname => $new_hostname }});
} }
else else
{ {
# Failed # Failed
$anvil->Database->insert_or_update_jobs({
job_uuid => $anvil->{job}{uuid},
update_progress_only => 1,
job_progress => 100,
job_status => "message_0017,!!hostname!$new_hostname!!,!!bad_hostname!$hostname!!\nfailed\n",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "message_0017", variables => {
hostname => $new_hostname,
bad_hostname => $hostname,
}});
$anvil->nice_exit({code => 2});
}
# Now configure the network.
foreach my $network (1..$bcn_count)
{
my $link1_key = "bcn".$network."_iface1_mac";
my $link2_key = "bcn".$network."_iface2_mac";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
link1_key => $link1_key,
link2_key => $link2_key,
}});
my $create_bond = 0;
if ((exists $anvil->data->{variables}{form}{config_step2}{$link2_key}{value}) && ($anvil->Validate->is_mac({mac => $anvil->data->{variables}{form}{config_step2}{$link2_key}{value}})))
{
# Bonded
}
elsif ((exists $anvil->data->{variables}{form}{config_step2}{$link1_key}{value}) && ($anvil->Validate->is_mac({mac => $anvil->data->{variables}{form}{config_step2}{$link1_key}{value}})))
{
# Single
}
else
{
# Doesn't exist, skip.
}
} }
=cut =cut
print Dumper $anvil->data->{variables}; print Dumper $anvil->data->{variables};
@ -196,6 +242,9 @@ LIMIT 1;";
job_progress => $job_progress, job_progress => $job_progress,
}}); }});
# This will be used when updating the job
$anvil->{job}{uuid} = $job_uuid;
# See if the job was picked up by another running instance. # See if the job was picked up by another running instance.
if ($job_picked_up_by) if ($job_picked_up_by)
{ {
@ -261,10 +310,12 @@ AND
} }
# Record that we've picked up this job. # Record that we've picked up this job.
$query = "UPDATE jobs SET job_picked_up_by = ".$$.", job_progress = 1, job_picked_up_at = ".time." WHERE job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid).";"; $anvil->Database->insert_or_update_jobs({
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); job_uuid => $anvil->{job}{uuid},
update_progress_only => 1,
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); job_progress => 1,
job_status => "message_0015\n",
});
return(0); return(0);
} }

@ -89,6 +89,8 @@ sub keep_running
# Run any pending jobs by calling 'anvil-jobs' with the 'job_uuid' as a background process. # Run any pending jobs by calling 'anvil-jobs' with the 'job_uuid' as a background process.
# Check the local network and running services and tune the firewall as things change.
return(0); return(0);
} }

@ -283,9 +283,10 @@ CREATE TABLE jobs (
job_picked_up_at numeric not null default 0, -- This is unix timestamp of when the job was picked up. job_picked_up_at numeric not null default 0, -- This is unix timestamp of when the job was picked up.
job_updated numeric not null default 0, -- This is unix timestamp that is perdiodically updated for jobs that take a long time. It is used to help determine when a job is hung. job_updated numeric not null default 0, -- This is unix timestamp that is perdiodically updated for jobs that take a long time. It is used to help determine when a job is hung.
job_name text not null, -- This is the 'x::y::z' style job name. job_name text not null, -- This is the 'x::y::z' style job name.
job_progress numeric not null, -- An approximate percentage completed. Useful for jobs that that a while and are able to provide data for progress bars. When set to '100', the job is considered completed. job_progress numeric not null default 0, -- An approximate percentage completed. Useful for jobs that that a while and are able to provide data for progress bars. When set to '100', the job is considered completed.
job_title text not null, -- This is a word key for the title of this job job_title text not null, -- This is a word key for the title of this job
job_description text not null, -- This is a word key that describes this job. job_description text not null, -- This is a word key that describes this job.
job_status text, -- This is a field used to report the status of the job. It is expected to be 'key,!!var1!foo!!,...,!!varN!bar!!' format, one per line. If the last line is 'failed', the job will be understood to have failed.
modified_date timestamp with time zone not null, modified_date timestamp with time zone not null,
FOREIGN KEY(job_host_uuid) REFERENCES hosts(host_uuid) FOREIGN KEY(job_host_uuid) REFERENCES hosts(host_uuid)
@ -305,6 +306,7 @@ CREATE TABLE history.jobs (
job_progress numeric, job_progress numeric,
job_title text, job_title text,
job_description text, job_description text,
job_status text,
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
ALTER TABLE history.jobs OWNER TO #!variable!user!#; ALTER TABLE history.jobs OWNER TO #!variable!user!#;
@ -327,6 +329,7 @@ BEGIN
job_progress, job_progress,
job_title, job_title,
job_description, job_description,
job_status,
modified_date) modified_date)
VALUES VALUES
(history_jobs.job_uuid, (history_jobs.job_uuid,
@ -340,6 +343,7 @@ BEGIN
history_jobs.job_progress, history_jobs.job_progress,
history_jobs.job_title, history_jobs.job_title,
history_jobs.job_description, history_jobs.job_description,
history_jobs.job_status,
history_jobs.modified_date); history_jobs.modified_date);
RETURN NULL; RETURN NULL;
END; END;

Loading…
Cancel
Save