* The job progress display in Striker while in maintenance mode is coming along and mostly working now.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent eaca4c885f
commit eecef192b3
  1. 54
      cgi-bin/striker
  2. 2
      html/jquery-latest.js
  3. 26
      html/skins/alteeve/jobs.js
  4. 8
      html/skins/alteeve/main.css
  5. 4
      html/skins/alteeve/main.html
  6. 26
      html/skins/alteeve/striker.html
  7. 2
      rpm/SPECS/anvil.spec
  8. 1
      share/words.xml
  9. 71
      tools/anvil-daemon
  10. 14
      tools/anvil-update-system

@ -792,7 +792,61 @@ sub check_availability
$available = 0; $available = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { available => $available }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { available => $available }});
# If we have any running or recently finished jobs, we'll desplay them below.
my $jobs_list = "#!string!striker_0097!#"; my $jobs_list = "#!string!striker_0097!#";
my $return = $anvil->Database->get_jobs({debug => 2, ended_within => 300});
my $count = @{$return};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
if ($count)
{
$jobs_list = "";
foreach my $hash_ref (@{$return})
{
my $job_uuid = $hash_ref->{job_uuid};
my $job_command = $hash_ref->{job_command};
my $job_data = $hash_ref->{job_data};
my $job_picked_up_by = $hash_ref->{job_picked_up_by};
my $job_picked_up_at = $hash_ref->{job_picked_up_at};
my $job_updated = $hash_ref->{job_updated};
my $job_name = $hash_ref->{job_name};
my $job_progress = $hash_ref->{job_progress};
my $job_title = $hash_ref->{job_title};
my $job_description = $hash_ref->{job_description};
my $job_status = $hash_ref->{job_status};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_uuid => $job_uuid,
job_command => $job_command,
job_data => $job_data,
job_picked_up_by => $job_picked_up_by,
job_picked_up_at => $job_picked_up_at,
job_updated => $job_updated,
job_name => $job_name,
job_progress => $job_progress,
job_title => $job_title,
}});
# Convert the double-banged strings into a proper message.
my $say_title = $job_title ? $anvil->Words->parse_banged_string({key_string => $job_title}) : "";
my $say_description = $job_description ? $anvil->Words->parse_banged_string({key_string => $job_description}) : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_title => $job_title,
say_description => $say_description,
}});
### TODO: left off here
my $job_template = $anvil->Template->get({file => "striker.html", name => "job-details", variables => {
div_id => "job_".$job_uuid,
title => $say_title,
description => $say_description,
progress_bar => "job_progress_".$job_uuid,
status => "job_status_".$job_uuid,
}});
$jobs_list .= $job_template."\n";
}
}
#
$anvil->data->{say}{maintenance} = $anvil->Template->get({file => "striker.html", name => "striker-offline", variables => { $anvil->data->{say}{maintenance} = $anvil->Template->get({file => "striker.html", name => "striker-offline", variables => {
title_id => "", title_id => "",
message_id => "", message_id => "",

@ -1 +1 @@
jquery-3.2.1.js jquery-3.3.1.js

@ -0,0 +1,26 @@
$.ajaxSetup({
cache: false
});
$(function() {
if($("#running_jobs").length) {
console.log('Looking for running jobs.');
setInterval(function() {
$.getJSON('/status/jobs.json', { get_param: 'value' }, function(data) {
$.each(data.jobs, function(index, element) {
var progress = element.job_progress
console.log('entry: ['+index+'], uuid: ['+element.job_uuid+'], progress: ['+progress+']');
//console.log('status: ['+element.job_status+']');
// Initialize
$("#job_progress_"+element.job_uuid).progressbar({value: parseInt(element.job_progress)});
$("#job_status_"+element.job_uuid).html(element.job_status);
});
});
}, 1000);
}
else
{
alert('Jobs status not loaded.');
}
});

@ -301,3 +301,11 @@ td {
padding-left: 10px; padding-left: 10px;
padding-right: 10px; padding-right: 10px;
} }
/* This is used by HTML::FromText when converting a text string to HTML */
.hft-lines {
text-align: left;
font-family: 'Dejavu Sans Mono', Courier;
padding: 0.2em;
font-size: 0.9em;
}

@ -101,6 +101,10 @@
<link rel="stylesheet" href="#!data!skin::url!#/main.css" media="screen" /> <link rel="stylesheet" href="#!data!skin::url!#/main.css" media="screen" />
<script type="text/javascript" src="/jquery-latest.js"></script> <script type="text/javascript" src="/jquery-latest.js"></script>
<script type="text/javascript" src="#!data!skin::url!#/main.js"></script> <script type="text/javascript" src="#!data!skin::url!#/main.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head> </head>
<!-- end header --> <!-- end header -->

@ -208,7 +208,8 @@
&nbsp; &nbsp;
</td> </td>
</tr> </tr>
<div id="running-jobs"> <div id="running_jobs">
<script type="text/javascript" src="/skins/alteeve/jobs.js"></script>
<tr> <tr>
<td> <td>
<span name="jobs-title" id="jobs-title" class="config_header2">#!string!header_0011!#</span><br /> <span name="jobs-title" id="jobs-title" class="config_header2">#!string!header_0011!#</span><br />
@ -223,6 +224,29 @@
<!-- end striker-offline --> <!-- end striker-offline -->
<!-- start job-details --> <!-- start job-details -->
<div id="#!variable!div_id!#">
<br />
<table style="border: 1px solid white">
<tr>
<td width="50%">
<span class="column_header">#!variable!title!#</span>
</td>
<td width="50%">
<div id="#!variable!progress_bar!#"></div>
</td>
</tr>
<tr>
<td colspan="2">
<span class="column_row_name">#!variable!description!#</span>
</td>
</tr>
<tr>
<td colspan="2">
<div id="#!variable!status!#"></div>
</td>
</tr>
</table>
</div>
<!-- end job-details --> <!-- end job-details -->
<!-- start striker-setup --> <!-- start striker-setup -->

@ -35,6 +35,8 @@ Requires: perl-Data-Dumper
Requires: perl-DBD-Pg Requires: perl-DBD-Pg
Requires: perl-DBI Requires: perl-DBI
Requires: perl-Digest-SHA Requires: perl-Digest-SHA
Requires: perl-HTML-FromText
Requires: perl-HTML-Strip
Requires: perl-JSON Requires: perl-JSON
Requires: perl-Log-Journald Requires: perl-Log-Journald
Requires: perl-Net-SSH2 Requires: perl-Net-SSH2

@ -89,6 +89,7 @@ Report if a reboot is needed: #!variable!program!#
<key name="message_0053">This system needs to be rebooted.</key> <key name="message_0053">This system needs to be rebooted.</key>
<key name="message_0054">This system does NOT need to be rebooted.</key> <key name="message_0054">This system does NOT need to be rebooted.</key>
<key name="message_0055">Exiting to '--run-once' switch.</key> <key name="message_0055">Exiting to '--run-once' switch.</key>
<key name="message_0056">Previous run exited early. Restarting momentarily.</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>

@ -17,6 +17,8 @@ use warnings;
use Anvil::Tools; use Anvil::Tools;
use Proc::Simple; use Proc::Simple;
use JSON; use JSON;
use HTML::Strip;
use HTML::FromText;
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
@ -274,20 +276,66 @@ sub run_jobs
job_name => $job_name, job_name => $job_name,
job_progress => $job_progress, job_progress => $job_progress,
job_title => $job_title, job_title => $job_title,
job_description => $job_description,
job_status => $job_status,
started_seconds_ago => $started_seconds_ago, started_seconds_ago => $started_seconds_ago,
updated_seconds_ago => $updated_seconds_ago, updated_seconds_ago => $updated_seconds_ago,
}}); }});
# See if the job was picked up by a now-dead instance.
if ($job_picked_up_by)
{
# Check if the PID is still active.
$anvil->System->pids({ignore_me => 1});
### TODO: Add a check to verify the job isn't hung.
# Skip if this job is in progress.
if (not exists $anvil->data->{pids}{$job_picked_up_by})
{
# The previous job is gone, but the job isn't finished. Start it again.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "striker_warning_0007", variables => {
command => $job_command,
pid => $job_picked_up_by,
percent => $job_progress,
}});
clear_job($anvil, $job_uuid);
# Clear some variables.
$job_picked_up_by = 0;
$job_progress = 0;
$job_status = "message_0056";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_picked_up_by => $job_picked_up_by,
job_progress => $job_progress,
job_status => $job_status,
}});
}
}
# Convert the double-banged strings into a proper message. # Convert the double-banged strings into a proper message.
my $say_title = $job_title ? $anvil->Words->parse_banged_string({key_string => $job_title}) : ""; my $say_title = $job_title ? $anvil->Words->parse_banged_string({key_string => $job_title}) : "";
my $say_description = $job_description ? $anvil->Words->parse_banged_string({key_string => $job_description}) : ""; my $say_description = $job_description ? $anvil->Words->parse_banged_string({key_string => $job_description}) : "";
my $say_status = $job_progress ? $anvil->Words->parse_banged_string({key_string => $job_status}) : ""; my $say_status = $job_progress ? $anvil->Words->parse_banged_string({key_string => $job_status}) : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
job_title => $job_title, job_title => $job_title,
say_description => $say_description, say_description => $say_description,
say_status => $say_status, say_status => $say_status,
}}); }});
# Make the status HTML friendly. Strip any embedded HTML then encode the text string.
my $html_strip = HTML::Strip->new();
$say_status = $html_strip->parse($say_status);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }});
# Now make the resulting text string HTML friendly
my $text_to_html = HTML::FromText->new({
urls => 1,
email => 1,
lines => 1,
});
$say_status = $text_to_html->parse($say_status);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }});
# Add this to the jobs.json file # Add this to the jobs.json file
my $json_string = to_json ({ my $json_string = to_json ({
job_uuid => $job_uuid, job_uuid => $job_uuid,
@ -309,25 +357,8 @@ sub run_jobs
# If the job is done, move on. # If the job is done, move on.
next if $job_progress eq "100"; next if $job_progress eq "100";
# See if the job was picked up by another running instance. # If the job is not running, start it.
if ($job_picked_up_by) if (not $job_picked_up_by)
{
# Check if the PID is still active.
$anvil->System->pids({ignore_me => 1});
### TODO: Add a check to verify the job isn't hung.
# Skip if this job is in progress.
next if exists $anvil->data->{pids}{$job_picked_up_by};
# The previous job is gone, but the job isn't finished. Start it again.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "striker_warning_0007", variables => {
command => $job_command,
pid => $job_picked_up_by,
percent => $job_progress,
}});
clear_job($anvil, $job_uuid);
}
else
{ {
# Start the job, appending '--job-uuid' to the command. # Start the job, appending '--job-uuid' to the command.
$anvil->data->{jobs}{handles}{$job_uuid} = $anvil->System->call({ $anvil->data->{jobs}{handles}{$job_uuid} = $anvil->System->call({

@ -144,14 +144,9 @@ WHERE
update_progress($anvil, 0, "clear"); update_progress($anvil, 0, "clear");
# Mark that we're starting # Mark that we're starting
print $THIS_FILE."; time: [".time."], running with PID: [".$$."]\n";
update_progress($anvil, 1, "message_0033"); update_progress($anvil, 1, "message_0033");
sleep 10;
print $THIS_FILE."; time: [".time."], exiting\n";
update_progress($anvil, 2, "message_0035,!!size!42M!!");
update_progress($anvil, 3, "message_0017,!!hostname!neutron!!,!!bad_hostname!mermaid!!");
exit;
# Run the update
run_os_update($anvil); run_os_update($anvil);
# We're done updating # We're done updating
@ -226,7 +221,7 @@ WHERE
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { message => $message }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { message => $message }});
if ($job_status) if (($message) && ($job_status))
{ {
$job_status .= "\n"; $job_status .= "\n";
} }
@ -263,6 +258,7 @@ sub run_os_update
my ($anvil) = @_; my ($anvil) = @_;
# NOTE: We run this directly to better monitor progress and update the progress. # NOTE: We run this directly to better monitor progress and update the progress.
my $transaction_shown = 0;
my $success = 0; my $success = 0;
my $to_update = 0; my $to_update = 0;
my $percent_step = 0; my $percent_step = 0;
@ -301,7 +297,11 @@ sub run_os_update
if ($line =~ /Running transaction/i) if ($line =~ /Running transaction/i)
{ {
# Done downloading # Done downloading
if (not $transaction_shown)
{
update_progress($anvil, $progress, "message_0037"); update_progress($anvil, $progress, "message_0037");
$transaction_shown = 1;
}
} }
if ($line =~ /return_code:(\d+)$/) if ($line =~ /return_code:(\d+)$/)

Loading…
Cancel
Save