| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# ecaccess-job-get: Download a Job Output/Input/Error File |
| 4 |
# |
| 5 |
# [email protected] - 2010-10-15 |
| 6 |
|
| 7 |
use ECMWF::ECaccess; |
| 8 |
use Getopt::Long; |
| 9 |
use Pod::Usage; |
| 10 |
use MIME::Base64; |
| 11 |
|
| 12 |
my %opt = ( input => 0, error => 0, bufsize => 524288, version => 0, help => 0, manual => 0, retry => 0, debug => 0 ); |
| 13 |
|
| 14 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if !GetOptions( |
| 15 |
\%opt, |
| 16 |
qw( |
| 17 |
input |
| 18 |
error |
| 19 |
bufsize=i |
| 20 |
version |
| 21 |
help|? |
| 22 |
manual |
| 23 |
retry=i |
| 24 |
debug |
| 25 |
) |
| 26 |
); |
| 27 |
|
| 28 |
# Display version if requested |
| 29 |
die ECMWF::ECaccess->VERSION . "\n" if ( $opt{version} ); |
| 30 |
|
| 31 |
my $jobId = $ARGV[0]; |
| 32 |
my $target = $ARGV[1]; |
| 33 |
|
| 34 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if ( $opt{help} ); |
| 35 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 2 ) if ( $opt{manual} ); |
| 36 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No job-id specified!\n" ) if not($jobId); |
| 37 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No target specified!\n" ) if not($target); |
| 38 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Incompatible options!(-input,-error)\n" ) if ( $opt{input} && $opt{error} ); |
| 39 |
|
| 40 |
# Create the ECaccess Controler |
| 41 |
my $ecaccess = ECMWF::ECaccess->new( $opt{retry}, $opt{debug}); |
| 42 |
|
| 43 |
# Get the Token (using the Certificate in $HOME) |
| 44 |
my $token = $ecaccess->getToken(); |
| 45 |
|
| 46 |
# Get the Control Channel |
| 47 |
my $controlChannel = $ecaccess->getControlChannel(); |
| 48 |
|
| 49 |
# Get the file handle (output, input or error) |
| 50 |
$handle = $controlChannel->getJobOutputHandle( $token, $jobId )->result if not ( $opt{input} || $opt{error} ); |
| 51 |
$handle = $controlChannel->getJobInputHandle( $token, $jobId )->result if ( $opt{input} ); |
| 52 |
$handle = $controlChannel->getJobErrorHandle( $token, $jobId )->result if ( $opt{error} ); |
| 53 |
|
| 54 |
# Open the Target File |
| 55 |
open FILE, ">", $target or die "Error creating file: " . $target . "\n"; |
| 56 |
binmode FILE; |
| 57 |
|
| 58 |
# Open the source file |
| 59 |
my $socket = $ecaccess->getFileInputStream($handle); |
| 60 |
|
| 61 |
# Read the file |
| 62 |
while (1) { |
| 63 |
my $readCount = $socket->read_entity_body( $data, $opt{bufsize} ); |
| 64 |
die "Error downloading file\n" unless defined $readCount; |
| 65 |
last unless $readCount; |
| 66 |
print FILE $data; |
| 67 |
} |
| 68 |
|
| 69 |
# close the file handles |
| 70 |
$controlChannel->closeHandle($handle); |
| 71 |
close FILE; |
| 72 |
|
| 73 |
# Logout |
| 74 |
END { |
| 75 |
$ecaccess->releaseToken($token) if ($token); |
| 76 |
} |
| 77 |
|
| 78 |
__END__ |
| 79 |
|
| 80 |
=head1 NAME |
| 81 |
|
| 82 |
ecaccess-job-get - Download a Job Output/Input/Error File |
| 83 |
|
| 84 |
=head1 SYNOPSIS |
| 85 |
|
| 86 |
B<ecaccess-job-get -version|-help|-manual> |
| 87 |
|
| 88 |
B<ecaccess-job-get [-debug] [-input|-error] [-bufsize> I<length>B<]> I<job-id> I<local-target-file> |
| 89 |
|
| 90 |
=head1 DESCRIPTION |
| 91 |
|
| 92 |
Allow downloading the Job Output/Input/Error Files with identifier I<job-id>. |
| 93 |
|
| 94 |
The file is downloaded localy in the I<local-target-file>. |
| 95 |
|
| 96 |
=head1 ARGUMENTS |
| 97 |
|
| 98 |
=over 8 |
| 99 |
|
| 100 |
=item I<job-id> |
| 101 |
|
| 102 |
The identifier of the ECaccess Job to retrieve. |
| 103 |
|
| 104 |
=item I<local-target-file> |
| 105 |
|
| 106 |
The name of the Local Target File. |
| 107 |
|
| 108 |
=back |
| 109 |
|
| 110 |
=head1 OPTIONS |
| 111 |
|
| 112 |
=over 8 |
| 113 |
|
| 114 |
=item B<-input> |
| 115 |
|
| 116 |
By default the Job Output File is downloaded. Using this option allow downloading |
| 117 |
the Job Input File instead. |
| 118 |
|
| 119 |
=item B<-error> |
| 120 |
|
| 121 |
By default the Job Output File is downloaded. Using this option allow downloading |
| 122 |
the Job Error File instead. |
| 123 |
|
| 124 |
=item B<-bufsize> I<length> |
| 125 |
|
| 126 |
Specify the I<length> of the buffer (in bytes) which is used to download the file. |
| 127 |
The larger the buffer the smaller the number of http/s requests. By default a |
| 128 |
buffer of 524288 bytes (512KB) is used. |
| 129 |
|
| 130 |
=item B<-version> |
| 131 |
|
| 132 |
Display version number and exits. |
| 133 |
|
| 134 |
=item B<-help> |
| 135 |
|
| 136 |
Print a brief help message and exits. |
| 137 |
|
| 138 |
=item B<-manual> |
| 139 |
|
| 140 |
Prints the manual page and exits. |
| 141 |
|
| 142 |
=item B<-retry> I<count> |
| 143 |
|
| 144 |
Number of SSL connection retries per 5s to ECMWF. This parameter only apply to the |
| 145 |
initial SSL connection initiated by the command to the ECMWF server. It does not |
| 146 |
apply to all the subsequent requests made afteward as it is mainly targeting errors |
| 147 |
that can happen from time to time during the SSL handshake. Default is no retry. |
| 148 |
|
| 149 |
=item B<-debug> |
| 150 |
|
| 151 |
Display the SOAP and SSL messages exchanged. |
| 152 |
|
| 153 |
=back |
| 154 |
|
| 155 |
=head1 EXAMPLES |
| 156 |
|
| 157 |
B<ecaccess-job-get> I<124356> I<./ecaccess-job-124356.output> |
| 158 |
|
| 159 |
Download the output of the ECaccess Job I<124356> in the local I<ecaccess-job-124356.output> file. |
| 160 |
|
| 161 |
=head1 SEE ALSO |
| 162 |
|
| 163 |
B<ecaccess-job-delete>, B<ecaccess-job-list>, B<ecaccess-job-restart>, B<ecaccess-job-submit> |
| 164 |
and B<ecaccess>. |
| 165 |
|
| 166 |
=cut |