| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# ecaccess-job-submit: Submit a new ECaccess Job |
| 4 |
# |
| 5 |
# [email protected] - 2010-10-15 |
| 6 |
|
| 7 |
use ECMWF::ECaccess; |
| 8 |
use Getopt::Long; |
| 9 |
use Pod::Usage; |
| 10 |
use File::Basename; |
| 11 |
|
| 12 |
my %opt = ( |
| 13 |
distant => 0, |
| 14 |
bufsize => 524288, |
| 15 |
scheduledDate => undef, |
| 16 |
noDirectives => 0, |
| 17 |
gateway => undef, |
| 18 |
remote => undef, |
| 19 |
transferOutput => 0, |
| 20 |
transferError => 0, |
| 21 |
transferInput => 0, |
| 22 |
keep => 0, |
| 23 |
eventIds => undef, |
| 24 |
sterr2Stdout => 0, |
| 25 |
noRenew => 0, |
| 26 |
mailTo => undef, |
| 27 |
onStart => 0, |
| 28 |
onSuccess => 0, |
| 29 |
onFailure => 0, |
| 30 |
onRetry => 0, |
| 31 |
queueName => undef, |
| 32 |
jobName => undef, |
| 33 |
manPage => undef, |
| 34 |
lifeTime => 7, |
| 35 |
retryCount => 0, |
| 36 |
retryFrequency => 600, |
| 37 |
version => 0, |
| 38 |
help => 0, |
| 39 |
manual => 0, |
| 40 |
retry => 0, |
| 41 |
debug => 0 |
| 42 |
); |
| 43 |
|
| 44 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if !GetOptions( |
| 45 |
\%opt, |
| 46 |
qw( |
| 47 |
distant |
| 48 |
bufsize=i |
| 49 |
scheduledDate|at=s |
| 50 |
noDirectives|nd |
| 51 |
gateway|tg=s |
| 52 |
remote|tr=s |
| 53 |
transferOutput|to |
| 54 |
transferError|te |
| 55 |
transferInput|ti |
| 56 |
keep|tk |
| 57 |
eventIds|ni=s |
| 58 |
sterr2Stdout|eo |
| 59 |
noRenew|ro |
| 60 |
mailTo|mu=s |
| 61 |
onStart|mb |
| 62 |
onSuccess|me |
| 63 |
onFailure|mf |
| 64 |
onRetry|mr |
| 65 |
queueName=s |
| 66 |
jobName|jn=s |
| 67 |
manPage|mp=s |
| 68 |
lifeTime|lt=i |
| 69 |
retryCount|rc=i |
| 70 |
retryFrequency|rf=i |
| 71 |
version |
| 72 |
help|? |
| 73 |
manual|man |
| 74 |
retry=i |
| 75 |
debug |
| 76 |
) |
| 77 |
); |
| 78 |
|
| 79 |
# Display version if requested |
| 80 |
die ECMWF::ECaccess->VERSION . "\n" if ( $opt{version} ); |
| 81 |
|
| 82 |
my $source = $ARGV[0]; |
| 83 |
|
| 84 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if ( $opt{help} ); |
| 85 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 2 ) if ( $opt{manual} ); |
| 86 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No source specified!\n" ) if not($source); |
| 87 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Source is not a plain text file!\n" ) if not( $opt{distant} ) && not( -f $source && -T $source ); |
| 88 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Invalid -retryCount specified (>0)!\n" ) if not( $opt{retryCount} >= 0 ); |
| 89 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Invalid -retryFrequency specified (>0)!\n" ) if not( $opt{retryFrequency} > 0 ); |
| 90 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Invalid -lifeTime specified (>0)!\n" ) if not( $opt{lifeTime} > 0 ); |
| 91 |
|
| 92 |
# Create the ECaccess Controler |
| 93 |
my $ecaccess = ECMWF::ECaccess->new( $opt{retry}, $opt{debug}); |
| 94 |
|
| 95 |
# Get the Token (using the Certificate in $HOME) |
| 96 |
my $token = $ecaccess->getToken(); |
| 97 |
|
| 98 |
# Get the Control Channel |
| 99 |
my $controlChannel = $ecaccess->getControlChannel(); |
| 100 |
|
| 101 |
# If the jobName options is not set then let's use the name of the input file |
| 102 |
my $jobName; |
| 103 |
if ( not( $opt{jobName} ) ) { |
| 104 |
$jobName = basename($source); |
| 105 |
} else { |
| 106 |
$jobName = $opt{jobName}; |
| 107 |
} |
| 108 |
|
| 109 |
# If the file is local then transfer it first |
| 110 |
if ( not( $opt{distant} ) ) { |
| 111 |
|
| 112 |
# Upload the file |
| 113 |
open FILE, $source or die "Error opening file: " . $source . "\n"; |
| 114 |
$source = $controlChannel->getTemporaryFile($token)->result; |
| 115 |
my $handle = $controlChannel->getOutputFileHandle( $token, $source, 0, 640 )->result; |
| 116 |
while ( read( FILE, $data, $opt{bufsize} ) > 0 ) { |
| 117 |
$ecaccess->writeFileOutputStream( $handle, $data ); |
| 118 |
} |
| 119 |
|
| 120 |
# Close handles |
| 121 |
$controlChannel->closeHandle($handle); |
| 122 |
close FILE; |
| 123 |
} else |
| 124 |
{ |
| 125 |
|
| 126 |
# Copy the ECaccess file to a temporary file |
| 127 |
my $sourceECaccessFile = $source; |
| 128 |
$source = $controlChannel->getTemporaryFile($token)->result; |
| 129 |
$controlChannel->copyFile( $token, $sourceECaccessFile, $source, SOAP::Data->type( boolean => '0' ) ); |
| 130 |
} |
| 131 |
|
| 132 |
# Submit the Job |
| 133 |
$jobId = $controlChannel->submitJob( |
| 134 |
$token, |
| 135 |
SOAP::Data->name( |
| 136 |
"request" => \SOAP::Data->value( |
| 137 |
SOAP::Data->name( 'scheduledDate' => $opt{scheduledDate} ), |
| 138 |
SOAP::Data->name( 'userMailAddress' => $opt{mailTo} ), |
| 139 |
SOAP::Data->name( 'sendMailOnStart' => $opt{onStart} ? 'true' : 'false' )->type('xsd:boolean'), |
| 140 |
SOAP::Data->name( 'sendMailOnSuccess' => $opt{onSuccess} ? 'true' : 'false' )->type('xsd:boolean'), |
| 141 |
SOAP::Data->name( 'sendMailOnFailure' => $opt{onFailure} ? 'true' : 'false' )->type('xsd:boolean'), |
| 142 |
SOAP::Data->name( 'sendMailOnRetry' => $opt{onRetry} ? 'true' : 'false' )->type('xsd:boolean'), |
| 143 |
SOAP::Data->name( 'containsDirectives' => $opt{noDirectives} ? 'false' : 'true' )->type('xsd:boolean'), |
| 144 |
SOAP::Data->name( 'queueName' => $opt{queueName} ), |
| 145 |
SOAP::Data->name( 'name' => $jobName ), |
| 146 |
SOAP::Data->name( 'transferGatewayName' => $opt{gateway} ), |
| 147 |
SOAP::Data->name( 'transferRemoteLocation' => $opt{remote} ), |
| 148 |
SOAP::Data->name( 'transferOutputFile' => $opt{transferOutput} ? 'true' : 'false' )->type('xsd:boolean'), |
| 149 |
SOAP::Data->name( 'transferErrorFile' => $opt{transferError} ? 'true' : 'false' )->type('xsd:boolean'), |
| 150 |
SOAP::Data->name( 'transferInputFile' => $opt{transferInput} ? 'true' : 'false' )->type('xsd:boolean'), |
| 151 |
SOAP::Data->name( 'transferKeepInSpool' => $opt{keep} ? 'true' : 'false' )->type('xsd:boolean'), |
| 152 |
SOAP::Data->name( 'renewSubscription' => $opt{noRenew} ? 'false' : 'true' )->type('xsd:boolean'), |
| 153 |
SOAP::Data->name( 'errorToOutput' => $opt{sterr2Stdout} ? 'true' : 'false' )->type('xsd:boolean'), |
| 154 |
SOAP::Data->name( 'manPageContent' => $opt{manPage} ), |
| 155 |
SOAP::Data->name( 'lifeTime' => $opt{lifeTime} ), |
| 156 |
SOAP::Data->name( 'retryCount' => $opt{retryCount} ), |
| 157 |
SOAP::Data->name( 'retryFrequency' => $opt{retryFrequency} ), |
| 158 |
SOAP::Data->name( 'eventIds' => $opt{eventIds} ), |
| 159 |
SOAP::Data->name( 'inputFile' => $source ) |
| 160 |
) |
| 161 |
) |
| 162 |
)->result; |
| 163 |
print $jobId. "\n"; |
| 164 |
|
| 165 |
# Delete the temporary file |
| 166 |
$controlChannel->deleteFile( $token, $source, SOAP::Data->type( boolean => '1' ) ); |
| 167 |
|
| 168 |
# Logout |
| 169 |
END { |
| 170 |
$ecaccess->releaseToken($token) if ($token); |
| 171 |
} |
| 172 |
|
| 173 |
__END__ |
| 174 |
|
| 175 |
=head1 NAME |
| 176 |
|
| 177 |
ecaccess-job-submit - Submit a new ECaccess Job |
| 178 |
|
| 179 |
=head1 SYNOPSIS |
| 180 |
|
| 181 |
B<ecaccess-job-submit -version|-help|-manual> |
| 182 |
|
| 183 |
B<ecaccess-job-submit [-debug] [-distant] [-bufsize> I<length>B<] [-scheduledDate> I<date>B<] |
| 184 |
[-noDirectives] [-gateway> I<name>B<] [-remote> I<location>B<] [-transferOutput] [-transferError] |
| 185 |
[-transferInput] [-keep] [-eventIds> I<list>B<] [-sterr2Stdout] [-noRenew] [-mailTo> I<email>B<] |
| 186 |
[-onStart] [-onSuccess] [-onFailure] [-onRetry] [-jobName> I<name>B<] [-manPage> I<content>B<] |
| 187 |
[-lifeTime> I<days>B<] [-retryCount> I<number>B<] [-retryFrequency> I<frequency>B<] [-queueName> I<name>B<]> |
| 188 |
I<source> |
| 189 |
|
| 190 |
=head1 DESCRIPTION |
| 191 |
|
| 192 |
Allow submitting the I<source> script on either the default ECaccess batch queue or the ECaccess batch queue |
| 193 |
specified with the I<-queueName> option. ECaccess batch queue name can be obtained with the B<ecaccess-queue-list> |
| 194 |
command (the default queue is the first in the list). |
| 195 |
|
| 196 |
A special service (see option B<-eventIds>) allows to automatically submit jobs to be run when certain points in the daily |
| 197 |
ECMWF operational forecast suite have been reached. The main purpose is to ensure that certain data is available before |
| 198 |
e.g. submitting a MARS request. These events correspond to the different stages when the ECMWF operational activity |
| 199 |
has produced certain data or products. The list of events can be retrieved with the B<ecaccess-event-list> command. |
| 200 |
|
| 201 |
In order to facilitate the migration from the old ECtools (ecjreq/ecjput commands) the equivalents options can be set using |
| 202 |
their old names (e.g. B<-at> for B<-scheduledDate>). This should limit the scripts modifications for job submissions. |
| 203 |
|
| 204 |
=head1 ARGUMENTS |
| 205 |
|
| 206 |
=over 8 |
| 207 |
|
| 208 |
=item I<source> |
| 209 |
|
| 210 |
The name of the file which contains the job input script (depending of the -distant |
| 211 |
option this file is either at ECMWF or local to your workstation). |
| 212 |
|
| 213 |
=back |
| 214 |
|
| 215 |
=head1 OPTIONS |
| 216 |
|
| 217 |
=over 8 |
| 218 |
|
| 219 |
=item B<-distant> |
| 220 |
|
| 221 |
By default the I<source> is specifying a file which is local to your workstation. Using this option |
| 222 |
allow submitting a script which is already at ECMWF. |
| 223 |
|
| 224 |
=item B<-bufsize> I<length> |
| 225 |
|
| 226 |
Specify the I<length> of the buffer (in bytes) which is used to upload the file. |
| 227 |
The larger the buffer the smaller the number of http/s requests. By default a |
| 228 |
buffer of 524288 bytes (512KB) is used. This option only apply for local scripts |
| 229 |
(no B<-distant>). |
| 230 |
|
| 231 |
=item B<-at, -scheduledDate> I<date> |
| 232 |
|
| 233 |
Allow specifying the start I<date> for the Job. By default the job will start |
| 234 |
as soon as possible. The format for the date is 'yyyy-MM-dd HH:mm'. |
| 235 |
|
| 236 |
=item B<-nd, -noDirectives> |
| 237 |
|
| 238 |
Allow submitting a job with no scheduler directives. Some default directives |
| 239 |
will be added to your input script to allow processing the job. |
| 240 |
|
| 241 |
=item B<-tg, -gateway> I<name> |
| 242 |
|
| 243 |
This is the I<name> of the target ECaccess Gateway for the transfers. It is by default |
| 244 |
the Gateway you are connected to. In order to get the name of your current Gateway you |
| 245 |
can use the B<ecaccess-gateway-name> command. When using the commands at ECMWF the |
| 246 |
default Gateway is always "boaccess.ecmwf.int". |
| 247 |
|
| 248 |
=item B<-tr, -remote> I<location> |
| 249 |
|
| 250 |
Defines the target ECtrans I<location> in the format I<association-name>B<[>I<@protocol>B<]>. |
| 251 |
|
| 252 |
=item B<-to, -transferOutput> |
| 253 |
|
| 254 |
Request the transfer of the job standard output to the gateway and remote location defined |
| 255 |
in the B<-gateway> and B<-remote> options. |
| 256 |
|
| 257 |
=item B<-te, -transferError> |
| 258 |
|
| 259 |
Request the transfer of the job error output to the gateway and remote location defined |
| 260 |
in the B<-gateway> and B<-remote> options. |
| 261 |
|
| 262 |
=item B<-ti, -transferInput> |
| 263 |
|
| 264 |
Request the transfer of the job input to the gateway and remote location defined |
| 265 |
in the B<-gateway> and B<-remote> options. |
| 266 |
|
| 267 |
=item B<-tk, -keep> |
| 268 |
|
| 269 |
Allow keeping the transfers requests in the spool. |
| 270 |
|
| 271 |
=item B<-ni, -eventIds> I<list> |
| 272 |
|
| 273 |
Allow giving a I<list> of event-identifiers to subscribe to with the Job. The list should |
| 274 |
be separated by ';' or ','. Only one job will be launched when all the events in the list |
| 275 |
have been reached. To submit the same job to multiple events, one will need to submit the |
| 276 |
job to each event separately. |
| 277 |
|
| 278 |
=item B<-eo, -sterr2Stdout> |
| 279 |
|
| 280 |
Force redirection of the job standard error output (stderr) to the job standard output (stdout). |
| 281 |
|
| 282 |
=item B<-ro, -noRenew> |
| 283 |
|
| 284 |
The job subscriptions to events will not be renewed. |
| 285 |
|
| 286 |
=item B<-mu, -mailTo> I<email> |
| 287 |
|
| 288 |
Defines the target I<email> address (default: current ECMWF user identifier). |
| 289 |
|
| 290 |
=item B<-mb, -onStart> |
| 291 |
|
| 292 |
Allow sending a mail when the execution/transfer begins. |
| 293 |
|
| 294 |
=item B<-me, -onSuccess> |
| 295 |
|
| 296 |
Allow sending a mail when the execution/transfer ends. |
| 297 |
|
| 298 |
=item B<-mf, -onFailure> |
| 299 |
|
| 300 |
Allow sending a mail when the execution/transfer fails. |
| 301 |
|
| 302 |
=item B<-mr, -onRetry> |
| 303 |
|
| 304 |
Allow sending a mail when the execution/transfer retries. |
| 305 |
|
| 306 |
=item B<-queueName> I<name> |
| 307 |
|
| 308 |
The name of the ECaccess batch queue to submit the job to. |
| 309 |
|
| 310 |
=item B<-jn, -jobName> I<name> |
| 311 |
|
| 312 |
Allow specifying a I<name> for the new Job (other than the Job Identifier). If no name |
| 313 |
is specified then the name of the input script is used. |
| 314 |
|
| 315 |
=item B<-mp, -manPage> I<content> |
| 316 |
|
| 317 |
Allow giving the man page I<content> which will be displayed to the ECMWF operators in |
| 318 |
case of problems with your Job (e.g. what to do or who to contact). |
| 319 |
|
| 320 |
=item B<-lt, -lifeTime> I<days> |
| 321 |
|
| 322 |
Allow specifying the job input/output life time in I<days>. The default is 7 days. |
| 323 |
|
| 324 |
=item B<-rc, -retryCount> I<number> |
| 325 |
|
| 326 |
Defines the I<number> of retries. The default is 0. |
| 327 |
|
| 328 |
=item B<-rf, -retryFrequency> I<frequency> |
| 329 |
|
| 330 |
Defines the I<frequency> of retries in seconds. The default is 600 seconds. |
| 331 |
|
| 332 |
=item B<-version> |
| 333 |
|
| 334 |
Display version number and exits. |
| 335 |
|
| 336 |
=item B<-help> |
| 337 |
|
| 338 |
Print a brief help message and exits. |
| 339 |
|
| 340 |
=item B<-manual> |
| 341 |
|
| 342 |
Prints the manual page and exits. |
| 343 |
|
| 344 |
=item B<-retry> I<count> |
| 345 |
|
| 346 |
Number of SSL connection retries per 5s to ECMWF. This parameter only apply to the |
| 347 |
initial SSL connection initiated by the command to the ECMWF server. It does not |
| 348 |
apply to all the subsequent requests made afteward as it is mainly targeting errors |
| 349 |
that can happen from time to time during the SSL handshake. Default is no retry. |
| 350 |
|
| 351 |
=item B<-debug> |
| 352 |
|
| 353 |
Display the SOAP and SSL messages exchanged. |
| 354 |
|
| 355 |
=back |
| 356 |
|
| 357 |
=head1 EXAMPLES |
| 358 |
|
| 359 |
B<ecaccess-job-submit -noDirectives> I<./test.txt> |
| 360 |
|
| 361 |
Transfer the local file I<test.txt> to your ECMWF spool and submit the job to the default ECaccess batch queue. |
| 362 |
The source does not have any directives. |
| 363 |
|
| 364 |
=head1 SEE ALSO |
| 365 |
|
| 366 |
B<ecaccess-queue-list>, B<ecaccess-event-list>, B<ecaccess-job-delete>, B<ecaccess-job-get>, B<ecaccess-job-list> |
| 367 |
B<ecaccess-job-restart> and B<ecaccess>. |
| 368 |
|
| 369 |
=cut |