summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorAndrew Gaffney <agaffney@gentoo.org>2007-12-24 18:30:59 +0000
committerAndrew Gaffney <agaffney@gentoo.org>2007-12-24 18:30:59 +0000
commitbb59574e35600f77f989458ceb68bba2a1c9fca3 (patch)
treea9c401c56db80121ea48f49ca8aaca0e9db232bf /client
parentimplement IDENTIFY command with random response in server (diff)
downloadscire-bb59574e35600f77f989458ceb68bba2a1c9fca3.tar.gz
scire-bb59574e35600f77f989458ceb68bba2a1c9fca3.tar.bz2
scire-bb59574e35600f77f989458ceb68bba2a1c9fca3.zip
move connection string building into its own function
move most of global stuff inside run_main react properly to responses from IDENTIFY command move the job_dir check into its own function svn path=/branches/new-fu/; revision=263
Diffstat (limited to 'client')
-rwxr-xr-xclient/scireclient.pl90
1 files changed, 52 insertions, 38 deletions
diff --git a/client/scireclient.pl b/client/scireclient.pl
index a1708f0..fc02c54 100755
--- a/client/scireclient.pl
+++ b/client/scireclient.pl
@@ -14,42 +14,29 @@ my $SCIRE_CONFIG_FILE = '../etc/scire.conf'; #will be /etc/scire.conf when relea
my %conf;
my ($SERVER_STDOUT, $SERVER_STDIN);
-parse_command_line();
-my $conf_file = (defined($conf{config})) ? $conf{config} : $SCIRE_CONFIG_FILE;
-read_config($conf_file);
-
-# Build the connection command.
-# This will eventually be something like "ssh scire@${scireserver} /usr/bin/scireserver.pl"
-my $connection_command = "ssh ";
-if(defined($conf{port})) {
- $connection_command .= "-o Port=$conf{port} ";
-}
-$connection_command .= "$conf{user}\@$conf{host} $conf{server_script}";
+run_main();
-if (-d ".svn") {
- # Overwrite $connection_command in the case of a dev environment for now
- $connection_command = "../server/scireserver.pl";
-}
+sub run_main {
+ parse_command_line();
+ my $conf_file = (defined($conf{config})) ? $conf{config} : $SCIRE_CONFIG_FILE;
+ read_config_file($conf_file);
-if (! -d $conf{job_dir}) {
- print "WARNING! $conf{job_dir} does not exist...creating\n";
- mkpath( $conf{job_dir}, {verbose => 1, mode => 0660})
- or die("Couldn't make $conf{job_dir} w/ perms 0660: $!");
-}
+ check_job_dir();
-run_main();
+ my $connection_command = build_connection_command();
-sub run_main {
#ok folks so here's how this thang goes down.
#1. Connect.
- create_connection();
+ create_connection($connection_command);
#2. Register with the DB. (only it knows if you're allowed to be active)
- if(-f "../etc/client_key") {
- identify_client();
- } else {
+# if(-f "../etc/client_key") {
+ if(!identify_client()) {
+ exit(1);
+ }
+# } else {
# register_client();
- }
+# }
#3. Scan the jobs directory. If there are done/failed jobs, report them. Note jobs in running or queue.
#4. Fetch the jobs list
@@ -61,13 +48,12 @@ sub run_test {
for(('PING', 'FOO', 'QUIT')) {
send_command($_);
my $response = get_response();
- print "Got: ${response}";
}
}
sub parse_command_line {
GetOptions(
- 'debug|D' => \$conf{debug},
+ 'debug|d' => \$conf{debug},
'dry-run' => \$conf{dry_run},
'help|h' => \$conf{help},
'config|c=s' => \$conf{config},
@@ -81,7 +67,7 @@ sub parse_command_line {
'job_dir' => \$conf{job_dir},
);
if ($conf{help}) {
- print "\nusage: scireclient.pl [--debug or -D]\n\t [--dry-run]"
+ print "\nusage: scireclient.pl [--debug or -d]\n\t [--dry-run]"
."\t [--config=CONF or -c] \n\t [--threads=# or -t] \t [--help or -h] \n"
."\t [[--host=HOST] \t [--port=PORT] \t [--user=USER or -u] \n\t"
." [--server_script=foo.pl] \t [--job_dir=/tmp/jobs] \n";
@@ -110,6 +96,7 @@ sub send_command {
sub get_response {
# XXX: Add some logic for multi-line responses here
my $response = <SERVER_STDOUT>;
+ print "Got: ${response}" if($conf{debug});
return $response;
}
@@ -120,10 +107,35 @@ sub create_connection {
# doesn't fail in the main process. When it fails, it outputs an error
# to STDERR:
# open2: exec of ../server/scireserver.pl failed at ./scireclient.pl line 116
+ my $connection_command = shift;
my $pid = open2(*SERVER_STDOUT, *SERVER_STDIN, $connection_command);
}
-sub read_config {
+sub build_connection_command {
+ # This will eventually be something like "ssh scire@${scireserver} /usr/bin/scireserver.pl"
+ my $connection_command = "ssh ";
+ if(defined($conf{port})) {
+ $connection_command .= "-o Port=$conf{port} ";
+ }
+ $connection_command .= "$conf{user}\@$conf{host} $conf{server_script}";
+
+ if (-d ".svn") {
+ # Overwrite $connection_command in the case of a dev environment for now
+ $connection_command = "../server/scireserver.pl";
+ }
+
+ return $connection_command;
+}
+
+sub check_job_dir {
+ if (! -d $conf{job_dir}) {
+ print "WARNING! $conf{job_dir} does not exist...creating\n";
+ mkpath( $conf{job_dir}, {verbose => 1, mode => 0660})
+ or die("Couldn't make $conf{job_dir} w/ perms 0660: $!");
+ }
+}
+
+sub read_config_file {
my $conf_file = shift;
open(FH, "< ${conf_file}") or die("Couldn't open the config file ${conf_file}: $!");
while (<FH>) {
@@ -143,15 +155,17 @@ sub register_client {
}
sub identify_client {
- open FILE, "< ../etc/client_key" or die "Couldn't open client_key: $!";
- my $client_key = join("", <FILE>);
- close FILE;
- my $cmd = "IDENTIFY ${client_key}";
- send_command($cmd);
+# open FILE, "< ../etc/client_key" or die "Couldn't open client_key: $!";
+# my $client_key = join("", <FILE>);
+# close FILE;
+ my $client_key = "124567890";
+ send_command("IDENTIFY", $client_key);
my $response = get_response();
- $response =~ /^(OK|ERROR (.+))$/;
+ $response =~ /^(OK|ERROR)(?: (.+))?$/;
if($1 eq "ERROR") {
print "Could not identify to server: $2\n";
+ return 0;
}
- print "Registered client $conf{client_id}\n" if $conf{debug};
+# print "Registered client $conf{client_id}\n" if $conf{debug};
+ return 1;
}