stop using readAllConfigs in spectre

This commit is contained in:
Graham Knop 2011-07-05 08:10:39 -05:00
parent caf9efc784
commit 287c26adaa

View file

@ -26,6 +26,7 @@ use Spectre::Cron;
use Spectre::Workflow; use Spectre::Workflow;
use WebGUI::Paths; use WebGUI::Paths;
use WebGUI::Config; use WebGUI::Config;
use File::Spec;
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -137,38 +138,40 @@ Fetches the site from each defined site, and loads it into the Workflow and Cron
=cut =cut
sub loadSiteData { sub loadSiteData {
my ( $kernel, $self) = @_[ KERNEL, OBJECT ]; my ( $kernel, $self) = @_[ KERNEL, OBJECT ];
my $configs = WebGUI::Config->readAllConfigs;
$self->debug("Reading site configs."); $self->debug("Reading site configs.");
foreach my $key (keys %{$configs}) { my @configs = WebGUI::Paths->siteConfigs;
next if $key =~ m/^demo/; foreach my $configFile (@configs) {
$self->debug("Fetching site data for $key"); my $shortName = (File::Spec->splitpath($configFile))[2];
my $userAgent = new LWP::UserAgent; next if $shortName =~ m/\bdemo/;
my $siteConfig = WebGUI::Config->new($configFile);
$self->debug("Fetching site data for $shortName");
my $userAgent = new LWP::UserAgent;
if (!$self->config->get('ignoreEnvProxy')) { if (!$self->config->get('ignoreEnvProxy')) {
$userAgent->env_proxy; $userAgent->env_proxy;
} }
$userAgent->agent("Spectre"); $userAgent->agent("Spectre");
$userAgent->timeout(30); $userAgent->timeout(30);
my $url = "http://".$configs->{$key}->get("sitename")->[0].":".$self->{_config}->get("webguiPort").$configs->{$key}->get("gateway")."?op=spectreGetSiteData"; my $url = "http://".$siteConfig->get("sitename")->[0].":".$self->{_config}->get("webguiPort").$siteConfig->get("gateway")."?op=spectreGetSiteData";
my $request = new HTTP::Request (GET => $url); my $request = new HTTP::Request (GET => $url);
my $response = $userAgent->request($request); my $response = $userAgent->request($request);
if ($response->is_error) { if ($response->is_error) {
$self->error( "Couldn't connect to WebGUI site $key at $url. Response: " . $response->status_line ); $self->error( "Couldn't connect to WebGUI site $shortName at $url. Response: " . $response->status_line );
} }
else { else {
my $siteData = {}; my $siteData = {};
eval { $siteData = JSON::decode_json($response->content); }; eval { $siteData = JSON::decode_json($response->content); };
if ($@) { if ($@) {
$self->error("Couldn't fetch Spectre configuration data for $key : $@"); $self->error("Couldn't fetch Spectre configuration data for $shortName : $@");
} }
else { else {
$self->debug("Loading workflow data for $key"); $self->debug("Loading workflow data for $shortName");
foreach my $instance (@{$siteData->{workflow}}) { foreach my $instance (@{$siteData->{workflow}}) {
$kernel->post("workflow" ,"addInstance", $instance); $kernel->post("workflow" ,"addInstance", $instance);
} }
$self->debug("Loading scheduler data for $key"); $self->debug("Loading scheduler data for $shortName");
foreach my $task (@{$siteData->{cron}}) { foreach my $task (@{$siteData->{cron}}) {
$task->{config} = $key; $task->{config} = $shortName;
$kernel->post("cron", "addJob", $task); $kernel->post("cron", "addJob", $task);
} }
} }
@ -246,29 +249,31 @@ sub runTests {
my $class = shift; my $class = shift;
my $config = shift; my $config = shift;
print "Running connectivity tests.\n"; print "Running connectivity tests.\n";
my $configs = WebGUI::Config->readAllConfigs; my @configs = WebGUI::Paths->siteConfigs;
foreach my $key (keys %{$configs}) { foreach my $configFile (@configs) {
next if $key =~ m/^demo/; my $shortName = (File::Spec->splitpath($configFile))[2];
print "Testing $key\n"; next if $shortName =~ m/\bdemo/;
my $siteConfig = WebGUI::Config->new($configFile);
print "Testing $shortName\n";
my $userAgent = new LWP::UserAgent; my $userAgent = new LWP::UserAgent;
if (!$config->get('ignoreEnvProxy')) { if (!$config->get('ignoreEnvProxy')) {
$userAgent->env_proxy; $userAgent->env_proxy;
} }
$userAgent->agent("Spectre"); $userAgent->agent("Spectre");
$userAgent->timeout(30); $userAgent->timeout(30);
my $url = "http://".$configs->{$key}->get("sitename")->[0].":".$config->get("webguiPort").$configs->{$key}->get("gateway")."?op=spectreTest"; my $url = "http://".$siteConfig->get("sitename")->[0].":".$config->get("webguiPort").$siteConfig->get("gateway")."?op=spectreTest";
my $request = new HTTP::Request (GET => $url); my $request = new HTTP::Request (GET => $url);
my $response = $userAgent->request($request); my $response = $userAgent->request($request);
if ($response->is_error) { if ($response->is_error) {
print "ERROR: Couldn't connect to WebGUI site $key\n"; print "ERROR: Couldn't connect to WebGUI site $shortName\n";
} else { } else {
my $response = $response->content; my $response = $response->content;
if ($response eq "subnet") { if ($response eq "subnet") {
print "ERROR: Spectre cannot communicate with WebGUI. Perhaps you need to adjust the spectreSubnets setting in this config file: $key.\n"; print "ERROR: Spectre cannot communicate with WebGUI. Perhaps you need to adjust the spectreSubnets setting in this config file: $shortName.\n";
} elsif ($response eq "spectre") { } elsif ($response eq "spectre") {
print "ERROR: WebGUI cannot communicate with Spectre. Perhaps you need to adjust the spectreIp or spectrePort setting the this config file: $key."; print "ERROR: WebGUI cannot communicate with Spectre. Perhaps you need to adjust the spectreIp or spectrePort setting the this config file: $shortName.";
} elsif ($response ne "success") { } elsif ($response ne "success") {
print "ERROR: Spectre received an invalid response ($response) from WebGUI while testing $key\n"; print "ERROR: Spectre received an invalid response ($response) from WebGUI while testing $shortName\n";
} }
} }
} }