Skip to content

Commit

Permalink
stop using readAllConfigs in spectre
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Jul 5, 2011
1 parent caf9efc commit 287c26a
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions lib/Spectre/Admin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use Spectre::Cron;
use Spectre::Workflow;
use WebGUI::Paths;
use WebGUI::Config;
use File::Spec;


#-------------------------------------------------------------------
Expand Down Expand Up @@ -137,38 +138,40 @@ Fetches the site from each defined site, and loads it into the Workflow and Cron
=cut

sub loadSiteData {
my ( $kernel, $self) = @_[ KERNEL, OBJECT ];
my $configs = WebGUI::Config->readAllConfigs;
my ( $kernel, $self) = @_[ KERNEL, OBJECT ];
$self->debug("Reading site configs.");
foreach my $key (keys %{$configs}) {
next if $key =~ m/^demo/;
$self->debug("Fetching site data for $key");
my $userAgent = new LWP::UserAgent;
my @configs = WebGUI::Paths->siteConfigs;
foreach my $configFile (@configs) {
my $shortName = (File::Spec->splitpath($configFile))[2];
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')) {
$userAgent->env_proxy;
}
$userAgent->agent("Spectre");
$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 $response = $userAgent->request($request);
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 {
my $siteData = {};
eval { $siteData = JSON::decode_json($response->content); };
if ($@) {
$self->error("Couldn't fetch Spectre configuration data for $key : $@");
$self->error("Couldn't fetch Spectre configuration data for $shortName : $@");
}
else {
$self->debug("Loading workflow data for $key");
$self->debug("Loading workflow data for $shortName");
foreach my $instance (@{$siteData->{workflow}}) {
$kernel->post("workflow" ,"addInstance", $instance);
}
$self->debug("Loading scheduler data for $key");
$self->debug("Loading scheduler data for $shortName");
foreach my $task (@{$siteData->{cron}}) {
$task->{config} = $key;
$task->{config} = $shortName;
$kernel->post("cron", "addJob", $task);
}
}
Expand Down Expand Up @@ -246,29 +249,31 @@ sub runTests {
my $class = shift;
my $config = shift;
print "Running connectivity tests.\n";
my $configs = WebGUI::Config->readAllConfigs;
foreach my $key (keys %{$configs}) {
next if $key =~ m/^demo/;
print "Testing $key\n";
my @configs = WebGUI::Paths->siteConfigs;
foreach my $configFile (@configs) {
my $shortName = (File::Spec->splitpath($configFile))[2];
next if $shortName =~ m/\bdemo/;
my $siteConfig = WebGUI::Config->new($configFile);
print "Testing $shortName\n";
my $userAgent = new LWP::UserAgent;
if (!$config->get('ignoreEnvProxy')) {
$userAgent->env_proxy;
}
$userAgent->agent("Spectre");
$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 $response = $userAgent->request($request);
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 {
my $response = $response->content;
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") {
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") {
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";
}
}
}
Expand Down

0 comments on commit 287c26a

Please sign in to comment.