[Bps-public-commit] r15093 - in Pushmi/trunk: . Pushmi-Admin/bin Pushmi-Admin/etc Pushmi-Admin/lib/Pushmi/Admin Pushmi-Admin/lib/Pushmi/Admin/Model Pushmi-Admin/share/web/static/css
alexmv at bestpractical.com
alexmv at bestpractical.com
Tue Aug 12 14:30:51 EDT 2008
Author: alexmv
Date: Tue Aug 12 14:30:51 2008
New Revision: 15093
Added:
Pushmi/trunk/Pushmi-Admin/bin/generate-lights.pl (contents, props changed)
Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/blue.gif (contents, props changed)
Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/green.gif (contents, props changed)
Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/orange.gif (contents, props changed)
Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/red.gif (contents, props changed)
Removed:
Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/blue.png
Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/green.png
Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/orange.png
Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/red.png
Modified:
Pushmi/trunk/ (props changed)
Pushmi/trunk/Pushmi-Admin/etc/config.yml
Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/Replica.pm
Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/View.pm
Pushmi/trunk/Pushmi-Admin/share/web/static/css/app.css
Log:
r35846 at kohr-ah: chmrr | 2008-08-12 14:30:44 -0400
* Log viewing window
* Use new update_on for shorter region update subscriptions
* Pulsing lights!
* More code reuse in determining file paths
Added: Pushmi/trunk/Pushmi-Admin/bin/generate-lights.pl
==============================================================================
--- (empty file)
+++ Pushmi/trunk/Pushmi-Admin/bin/generate-lights.pl Tue Aug 12 14:30:51 2008
@@ -0,0 +1,81 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Math::Polynomial;
+use Image::Magick;
+use Math::Trig;
+
+light( "blue" => -148, 0.4, 0.6, 40, 5 );
+light( "green" => 113, 0.55, 0.6, 20, 15 );
+light( "orange" => 40, 0.4, 0.6, 40, 5 );
+light( "red" => 0, 0.3, 0.6, 15, 5 );
+
+sub light {
+ my ($name, $hue, $min, $max, $steps, $speed) = @_;
+ $hue += 180;
+ $hue /= 180;
+ $hue *= 100;
+
+ my $base = Image::Magick->new;
+ $base->Read("base.psd");
+ $base->[3]->Modulate( hue => $hue );
+
+ my $output = Image::Magick->new;
+ for my $v (sinusoid($min, $max, $steps)) {
+ add_frame($base, $output, $v, $speed);
+ }
+
+ $output->Set(loop => 0);
+ $output->Scale("50x50");
+ $output->Write("share/web/static/images/status/$name.gif");
+}
+
+sub sinusoid {
+ my ($min, $max, $frames) = @_;
+ my $step = 2/$frames;
+ my @vals;
+ my $val = 0;
+ for (1 .. $frames/2) {
+ push @vals, $min + partial($val)*($max-$min);
+ $val += $step;
+ }
+ for (1 .. $frames/2) {
+ push @vals, $min + partial($val)*($max-$min);
+ $val -= $step;
+ }
+ return @vals;
+}
+
+sub partial {
+ my ($val) = @_;
+ return -cos(pi*$val)/2+0.5;
+}
+
+sub add_frame {
+ my ($base, $output, $v, $speed) = @_;
+ my $dup = $base->Clone;
+ $dup->[3] = $dup->[3]->Fx(fit(0,0, 1-$v,$v, 1,1));
+ push @{$output}, $dup->Flatten;
+ $output->[-1]->Set(delay => $speed);
+}
+
+sub fit {
+ my $out = "";
+ my $poly = Math::Polynomial::interpolate(@_);
+ my $seen = 0;
+ for ( my $p = $poly->degree(); $p >= 0; $p-- ) {
+ my $v = sprintf "%.3f", $poly->coeff($p);
+ next if $v eq '0' || $v =~ /^0\.00/ || $v =~ /e-/;
+ $out .= "+" if $seen && substr( $v, 0, 1 ) ne '-';
+ if ( $v ne '1' && $v ne '-1' || $p == 0 ) {
+ $out .= $v;
+ $out .= "*" if $p;
+ }
+ $out .= "u" if $p == 1;
+ $out .= "u^$p" if $p >= 2;
+ $seen = 1;
+ }
+ return $out;
+}
Modified: Pushmi/trunk/Pushmi-Admin/etc/config.yml
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/etc/config.yml (original)
+++ Pushmi/trunk/Pushmi-Admin/etc/config.yml Tue Aug 12 14:30:51 2008
@@ -55,6 +55,7 @@
StaticRoot: share/web/static
TemplateRoot: share/web/templates
application:
+ time_zone: EST
data_root: %var/data%
pushmi_bin: /usr/bin/pushmi
apache:
Modified: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/Replica.pm
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/Replica.pm (original)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/Model/Replica.pm Tue Aug 12 14:30:51 2008
@@ -91,13 +91,17 @@
YAML::DumpFile( $self->config_file, { username => undef, password => undef, authproxy_port => 11211 });
open(LOG, ">", $self->log_config_file ) or die "Can't write log config file @{[$self->log_config_file]}: $!";
print LOG <<EOT;
-log4perl.rootLogger=DEBUG, Logfile
+log4perl.rootLogger=DEBUG, Logfile, Event
log4perl.appender.Logfile=Log::Log4perl::Appender::File
-log4perl.appender.Logfile.filename=@{[$self->file_root]}/pushmi.log
+log4perl.appender.Logfile.filename=@{[$self->log_file]}
log4perl.appender.Logfile.mode=append
log4perl.appender.Logfile.layout=PatternLayout
-log4perl.appender.Logfile.layout.ConversionPattern = [%P][%r] %c - %m%n
+log4perl.appender.Logfile.layout.ConversionPattern = %d - %c - %m%n
+
+log4perl.appender.Event=Jifty::Logger::EventAppender
+log4perl.appender.Event.id=@{[$self->id]}
+log4perl.appender.Event.layout=SimpleLayout
EOT
close LOG;
Pushmi::Admin->update_apache;
@@ -168,26 +172,29 @@
sub file_root {
my $self = shift;
+ my @others = @_;
my @parts = File::Spec->splitpath( Jifty->config->app('data_root') );
- return File::Spec->catfile( @parts, $self->clean_name );
+ return File::Spec->catfile( @parts, $self->clean_name, @others );
}
sub config_file {
my $self = shift;
- my @parts = File::Spec->splitpath( $self->file_root );
- return File::Spec->catfile( @parts, "pushmi.conf" );
+ return $self->file_root( "pushmi.conf" );
}
sub log_config_file {
my $self = shift;
- my @parts = File::Spec->splitpath( $self->file_root );
- return File::Spec->catfile( @parts, "pushmi-log.conf" );
+ return $self->file_root( "pushmi-log.conf" );
+}
+
+sub log_file {
+ my $self = shift;
+ return $self->file_root( "pushmi.log" );
}
sub svn_root {
my $self = shift;
- my @parts = File::Spec->splitpath( $self->file_root );
- return File::Spec->catfile( @parts, "svn" );
+ return $self->file_root( "svn" );
}
sub cache {
Modified: Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/View.pm
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/View.pm (original)
+++ Pushmi/trunk/Pushmi-Admin/lib/Pushmi/Admin/View.pm Tue Aug 12 14:30:51 2008
@@ -8,6 +8,7 @@
use YAML;
use DateTime;
use SVN::Client;
+use Jifty::Event::Log;
template 'index.html' => page { title => "Pushmi Administration" } content {
my $replicas = Pushmi::Admin::Model::ReplicaCollection->new;
@@ -67,7 +68,7 @@
my $data = Pushmi::Admin->svn_info_for( $new->argument_value("url") );
my $changed
= DateTime->from_epoch( epoch => $data->{date} );
- $changed->set_time_zone("EST");
+ $changed->set_time_zone( Jifty->config->app("time_zone") || "UTC" );
div {
{ id is 'new_replica', class is 'roundbox' };
h2 {"Add a new replica"};
@@ -126,14 +127,10 @@
outs_raw( qq{<script>if (jQuery("#progress-$id")) jQuery("#progress-$id").progressBar($progress)</script>} );
}
- # Add a PubSub watcher, if need be
- Jifty->subs->add(
- class => 'ReplicaStatus',
- queries => [{ id => $id }],
- mode => 'Replace',
- region => Jifty->web->qualified_region,
- render_with => '/fragments/summary',
+ Jifty->subs->update_on(
+ class => 'ReplicaStatus',
);
+ # Add a PubSub watcher, if need be
$replica->start_watcher;
};
@@ -178,6 +175,7 @@
}
} elsif ( $replica->status ne "failed" ) {
h2 {"Replica health"};
+ # XXX: Prettify
p {
"Last local commit: r"
. $replica->local_revision . " - "
@@ -202,12 +200,8 @@
} else {
h2 {"Local replica failure"};
}
- Jifty->subs->add(
- class => 'ReplicaStatus',
- queries => [{ id => $id }],
- mode => 'Replace',
- region => Jifty->web->qualified_region,
- render_with => '/fragments/details',
+ Jifty->subs->update_on(
+ class => 'ReplicaStatus',
);
};
@@ -215,25 +209,18 @@
my $id = get('id');
my $replica = Pushmi::Admin::Model::Replica->load($id);
- Jifty->subs->add(
- class => 'ReplicaStatus',
- queries => [{ id => $id, tostatus => "loading" }],
- mode => 'Replace',
- region => Jifty->web->qualified_region,
- render_with => '/fragments/progressbar',
- effect => 'Appear',
- effect_args => 10000,
- remove_effect => 'Hide',
+ Jifty->subs->update_on(
+ class => 'ReplicaStatus',
+ queries => [{ id => $id, tostatus => "loading" }],
+ effect => 'Appear',
+ effect_args => 10000,
+ remove_effect => 'Hide',
remove_effect_args => 0,
);
- Jifty->subs->add(
- class => 'Inactive',
- queries => [{ id => $id }],
- mode => 'Replace',
- region => Jifty->web->qualified_region,
- render_with => '/fragments/progressbar',
- remove_effect => 'Fade',
+ Jifty->subs->update_on(
+ class => 'Inactive',
+ remove_effect => 'Fade',
remove_effect_args => 10000,
);
@@ -245,6 +232,36 @@
span {{ class is "progressbar", id is "progress-$id"}; $progress . "%" };
};
+template 'fragments/logs' => sub {
+ my $id = get('id');
+ my $replica = Pushmi::Admin::Model::Replica->load($id);
+
+ Jifty->subs->update_on(
+ class => 'Jifty::Event::Log',
+ );
+
+ return unless -e $replica->log_file;
+
+ div {
+ { class is 'roundbox' };
+ h2 {"Logs"};
+ div {
+ { class is 'logwindow' };
+ # TODO: Optimize this for long files
+ open(LOG, "<", $replica->log_file ) or die "$!";
+ my @lines = <LOG>;
+ close LOG;
+ splice @lines, 0, -20; # Keep only the last 20
+ my $repos = $replica->svn_root;
+ for my $line (reverse @lines) {
+ $line =~ s/ - \[$repos\]//;
+ $line =~ s/^(\S+)/[$1]/;
+ outs( $line );
+ }
+ }
+ }
+};
+
template 'replica' => page { title => "About " . get("replica")->name } content {
my $replica = get 'replica';
div {
@@ -262,8 +279,7 @@
path => "/fragments/progressbar",
);
};
- };
-
+ }
div {
{ class is 'roundbox' };
@@ -274,6 +290,12 @@
);
};
+ render_region(
+ name => "logs-" . $replica->id,
+ path => "/fragments/logs",
+ arguments => { id => $replica->id },
+ );
+
div {
{ id is 'advanced' }
hyperlink(
Modified: Pushmi/trunk/Pushmi-Admin/share/web/static/css/app.css
==============================================================================
--- Pushmi/trunk/Pushmi-Admin/share/web/static/css/app.css (original)
+++ Pushmi/trunk/Pushmi-Admin/share/web/static/css/app.css Tue Aug 12 14:30:51 2008
@@ -141,12 +141,21 @@
background-position: 0 10px;
}
-.status-light.loading { background-image: url(/static/images/status/blue.png); }
-.status-light.ok { background-image: url(/static/images/status/green.png); }
-.status-light.behind { background-image: url(/static/images/status/orange.png); }
-.status-light.offline { background-image: url(/static/images/status/red.png); }
-.status-light.failed { background-image: url(/static/images/status/red.png); }
-.status-light.locked { background-image: url(/static/images/status/red.png); }
+.status-light.loading { background-image: url(/static/images/status/blue.gif); }
+.status-light.ok { background-image: url(/static/images/status/green.gif); }
+.status-light.behind { background-image: url(/static/images/status/orange.gif); }
+.status-light.offline { background-image: url(/static/images/status/red.gif); }
+.status-light.failed { background-image: url(/static/images/status/red.gif); }
+.status-light.locked { background-image: url(/static/images/status/red.gif); }
+
+/* Log display */
+
+.logwindow {
+ clear: both;
+ overflow: auto;
+ white-space: pre;
+ font-family: monospace;
+}
/* Progressbar */
@@ -196,4 +205,3 @@
.advanced_options .option.last {
border-bottom: none;
}
-/* */
\ No newline at end of file
Added: Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/blue.gif
==============================================================================
Binary file. No diff available.
Added: Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/green.gif
==============================================================================
Binary file. No diff available.
Added: Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/orange.gif
==============================================================================
Binary file. No diff available.
Added: Pushmi/trunk/Pushmi-Admin/share/web/static/images/status/red.gif
==============================================================================
Binary file. No diff available.
More information about the Bps-public-commit
mailing list