Debian Codegraph @

script/ecaccess-ectrans-request

raw
1 #!/usr/bin/perl -w
2 #
3 # ecaccess-ectrans-request: Request a new ECtrans transfer
4 #
5 # [email protected] - 2010-10-15
6
7 use ECMWF::ECaccess;
8 use Getopt::Long;
9 use Pod::Usage;
10
11 my %opt = (
12 gateway => undef,
13 target => undef,
14 mailTo => undef,
15 retryCount => 144,
16 retryFrequency => 600,
17 priority => 99,
18 lifeTime => '7d',
19 onSuccess => 0,
20 onFailure => 0,
21 onRetry => 0,
22 deleteSource => 0,
23 keep => 0,
24 reject => 0,
25 append => 0,
26 resume => 0,
27 overwrite => 0,
28 maximumDuration => undef,
29 minimumDuration => undef,
30 minimumRate => undef,
31 version => 0,
32 help => 0,
33 manual => 0,
34 retry => 0,
35 debug => 0
36 );
37
38 pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if !GetOptions(
39 \%opt,
40 qw(
41 gateway=s
42 target=s
43 mailTo=s
44 retryCount=i
45 retryFrequency=i
46 priority=i
47 lifeTime=s
48 onSuccess
49 onFailure
50 onRetry
51 deleteSource
52 keep
53 reject
54 append
55 resume
56 overwrite
57 maximumDuration=s
58 minimumDuration=s
59 minimumRate=i
60 version
61 help|?
62 manual
63 retry=i
64 debug
65 )
66 );
67
68 # Display version if requested
69 die ECMWF::ECaccess->VERSION . "\n" if ( $opt{version} );
70
71 my $remote = $ARGV[0];
72 my $source = $ARGV[1];
73
74 pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if ( $opt{help} );
75 pod2usage( -noperldoc => 1, -exit => 1, verbose => 2 ) if ( $opt{manual} );
76 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No remote specified!\n" ) if not($remote);
77 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No source specified!\n" ) if not($source);
78 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Invalid -retryCount specified (>0)!\n" ) if not( $opt{retryCount} >= 0 );
79 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Invalid -retryFrequency specified (>0)!\n" ) if not( $opt{retryFrequency} > 0 );
80 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Invalid -priority specified (0-99)!\n" ) if not( $opt{priority} >= 0 && $opt{priority} <= 99 );
81 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Incompatible options (-append,-resume)!\n" ) if ( $opt{append} && $opt{resume} );
82 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Incompatible options (-append,-overwrite)!\n" ) if ( $opt{append} && $opt{overwrite} );
83 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Incompatible options (-append,-reject)!\n" ) if ( $opt{append} && $opt{reject} );
84 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Incompatible options!(-resume,-overwrite)\n" ) if ( $opt{resume} && $opt{overwrite} );
85 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Incompatible options!(-resume,-reject)\n" ) if ( $opt{resume} && $opt{reject} );
86 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Incompatible options!(-reject,-overwrite)\n" ) if ( $opt{reject} && $opt{overwrite} );
87
88 # Create the ECaccess Controler
89 my $ecaccess = ECMWF::ECaccess->new( $opt{retry}, $opt{debug});
90
91 # Get the Token (using the Certificate in $HOME)
92 my $token = $ecaccess->getToken();
93
94 # Get the Control Channel
95 my $controlChannel = $ecaccess->getControlChannel();
96
97 # Value for "ifTargetFileExists" option
98 my $ifTargetFileExists = 'reject';
99 $ifTargetFileExists = 'append' if ( $opt{append} );
100 $ifTargetFileExists = 'resume' if ( $opt{resume} );
101 $ifTargetFileExists = 'overwrite' if ( $opt{overwrite} );
102
103 # Request for the new ECTrans
104 $ectransId = $controlChannel->requestTransfer(
105 $token,
106 SOAP::Data->name(
107 "request" => \SOAP::Data->value(
108 SOAP::Data->name( 'gatewayName' => $opt{gateway} ),
109 SOAP::Data->name( 'remoteLocation' => $remote ),
110 SOAP::Data->name( 'sourceFileName' => $source ),
111 SOAP::Data->name( 'targetFileName' => $opt{target} ),
112 SOAP::Data->name( 'retryCount' => $opt{retryCount} ),
113 SOAP::Data->name( 'retryFrequency' => $opt{retryFrequency} ),
114 SOAP::Data->name( 'priority' => $opt{priority} ),
115 SOAP::Data->name( 'lifeTime' => $opt{lifeTime} ),
116 SOAP::Data->name( 'maximumDuration' => $opt{maximumDuration} ),
117 SOAP::Data->name( 'minimumDuration' => $opt{minimumDuration} ),
118 SOAP::Data->name( 'minimumRate' => $opt{minimumRate} ),
119 SOAP::Data->name( 'deleteSource' => $opt{deleteSource} ? 'true' : 'false' )->type('xsd:boolean'),
120 SOAP::Data->name( 'keepInSpool' => $opt{keep} ? 'true' : 'false' )->type('xsd:boolean'),
121 SOAP::Data->name( 'userMailAddress' => $opt{mailTo} ),
122 SOAP::Data->name( 'sendMailOnSuccess' => $opt{onSuccess} ? 'true' : 'false' )->type('xsd:boolean'),
123 SOAP::Data->name( 'sendMailOnFailure' => $opt{onFailure} ? 'true' : 'false' )->type('xsd:boolean'),
124 SOAP::Data->name( 'sendMailOnRetry' => $opt{onRetry} ? 'true' : 'false' )->type('xsd:boolean'),
125 SOAP::Data->name( 'ifTargetFileExists' => $ifTargetFileExists )
126 )
127 )
128 )->result;
129 print $ectransId. "\n";
130
131 # Logout
132 END {
133 $ecaccess->releaseToken($token) if ($token);
134 }
135
136 __END__
137
138 =head1 NAME
139
140 ecaccess-ectrans-request - Request a new ECtrans transfer
141
142 =head1 SYNOPSIS
143
144 B<ecaccess-ectrans-request -version|-help|-manual>
145
146 B<ecaccess-ectrans-request [-debug] [-gateway> I<name>B<] [-target> I<file-name>B<] [-retryCount> I<number>B<] [-retryFrequency> I<frequency>B<]
147 [-priority> I<priority>B<] [-lifeTime> I<duration>B<] [-mailTo> I<email>B<] [-onSuccess] [-onFailure] [-onRetry] [-deleteSource] [-keep]
148 [-reject>|B<-append>|B<-resume>|B<-overwrite] [-maximumDuration> I<duration>B<] [-minimumDuration> I<duration>B<] [-minimumRate> I<rate>B<]>
149 I<association-name>B<[>I<@protocol>B<]> I<source>
150
151 =head1 DESCRIPTION
152
153 Allow Member State users to initiate file transfers between ECMWF and Member State servers. The ECaccess Server
154 will spool the ECMWF file specified by the I<source> parameter in the user's ECtrans transfer queue: if the connection
155 between the ECMWF and Member State gateways is down or if any error occurs, the file will be kept in the spool area at
156 ECMWF and you can resume the transfer through the web interface or with the B<ecaccess-ectrans-restart> command. If
157 required the transfer can be retried automatically (see the B<-retryCount> and B<-retryFrequency> options to tailor the
158 retry mechanism).
159
160 The B<-reject>, B<-append>, B<-resume> and B<-overwrite> options are mutually exclusive and determine what to do if there is an
161 existing target file. The B<-mailTo> option specifies an I<email> address to be notified in case of a successful (option
162 B<-onSuccess>) and/or a failed transfer (option B<-onFailure>).
163
164 When a request has been spooled successfully, an I<ectrans-id> is returned immediately. The I<ectrans-id> can be used to reference
165 the transfer, using the web interface or with the B<ecaccess-ectrans-delete>, B<ecaccess-ectrans-list> or B<ecaccess-ectrans-restart>
166 commands.
167
168 =head1 ARGUMENTS
169
170 =over 8
171
172 =item I<association-name>B<[>I<@protocol>B<]>
173
174 The ECtrans Association with optionaly the name of the protocol to use.
175
176 =item I<source>
177
178 Name of the file at ECMWF to spool in ECtrans.
179
180 =back
181
182 =head1 OPTIONS
183
184 =over 8
185
186 =item B<-gateway> I<name>
187
188 This is the I<name> of the ECaccess Gateway where the ECtrans Association I<association-name>
189 is defined. It is by default the Gateway you are connected to. In order to get the name
190 of your current Gateway you can use the B<ecaccess-gateway-name> command. When using
191 the commands at ECMWF the default Gateway is always "boaccess.ecmwf.int".
192
193 =item B<-target> I<file-name>
194
195 Defines the target I<file-name> (default: same as I<source>).
196
197 =item B<-retryCount> I<number>
198
199 Defines the I<number> of retries (default: 144).
200
201 =item B<-retryFrequency> I<frequency>
202
203 Defines the I<frequency> of retries in seconds (default: 600 seconds).
204
205 =item B<-priority> I<priority>
206
207 Defines the transmission I<priority> 0-99 (default: 99).
208
209 =item B<-lifeTime> I<duration>
210
211 Defines the lifetime of the request (default: 7 days). The I<duration> is specified
212 in [w]eeks, [d]ays, [h]ours, [m]inutes or [s]econds (e.g. I<1w> or I<2d>).
213
214 =item B<-mailTo> I<email>
215
216 Defines the target I<email> address (default: <user-id>@ecmwf.int).
217
218 =item B<-onSuccess>
219
220 Allow sending a mail when the transfer is successful.
221
222 =item B<-onFailure>
223
224 Allow sending a mail when the transfer has failed.
225
226 =item B<-onRetry>
227
228 Allow sending a mail when the transfer is retried.
229
230 =item B<-deleteSource>
231
232 Allow deleting the original I<source> file once it is safe in the spool.
233
234 =item B<-keep>
235
236 Allow keeping the request in the spool until the duration specified in the
237 B<-lifeTime> option has passed. By default a successful transfer is removed
238 from the spool.
239
240 =item B<-reject>
241
242 Allow failing if there is an existing target file (default).
243
244 =item B<-append>
245
246 Allow appending if there is an existing target file.
247
248 =item B<-resume>
249
250 Allow resuming if there is an existing target file.
251
252 =item B<-overwrite>
253
254 Allow overwriting if there is an existing target file.
255
256 =item B<-maximumDuration> I<duration>
257
258 Define the maximum transfer I<duration>. The I<duration> is specified in [w]eeks,
259 [d]ays, [h]ours, [m]inutes or [s]econds (e.g. I<10m> or I<1h>). A value <=0 will
260 deactivate the feature (default: 12h).
261
262 =item B<-minimumDuration> I<duration>
263
264 Allow setting the I<duration> before to control a transmission (e.g. for the first 10 minutes
265 ECtrans don't try to check the transfer rate, which allow not to enforce some minimum transfer
266 rates for very small files). The I<duration> is specified in [w]eeks, [d]ays, [h]ours,
267 [m]inutes or [s]econds (e.g. I<30s> or I<10m>). A value <=0 will deactivate the feature
268 (default: 10m).
269
270 =item B<-minimumRate> I<rate>
271
272 Allow setting a minimum transfer I<rate> for a transmission (expressed in bytes/s). This is an
273 average value, not the transmission I<rate> at one particular moment in time (e.g. if a big file
274 is stuck for 5 minutes but then transmit much faster later on then it will not be interrupted
275 as long as the overall transfer rate is above the minimum). A value <=0 will deactivate the
276 feature (default: 10240).
277
278 =item B<-version>
279
280 Display version number and exits.
281
282 =item B<-help>
283
284 Print a brief help message and exits.
285
286 =item B<-manual>
287
288 Prints the manual page and exits.
289
290 =item B<-retry> I<count>
291
292 Number of SSL connection retries per 5s to ECMWF. This parameter only apply to the
293 initial SSL connection initiated by the command to the ECMWF server. It does not
294 apply to all the subsequent requests made afteward as it is mainly targeting errors
295 that can happen from time to time during the SSL handshake. Default is no retry.
296
297 =item B<-debug>
298
299 Display the SOAP and SSL messages exchanged.
300
301 =back
302
303 =head1 EXAMPLES
304
305 B<ecaccess-ectrans-request -lifeTime> I<2d> B<-overwrite -onFailure -onRetry> I<test@genericFtp> I<ec:test.txt>
306
307 Request a file transfer of the I<ec:test.txt> file to the default gateway with the association I<test> and the
308 protocol I<genericFtp>. If the target file already exists then the original file is deleted. If the transfer is retried
309 or fail then an email is sent to the default email address (<user-id>@ecmwf.int). After 2 days the file is removed from
310 the spool (whatever the status of the transmission is).
311
312 B<ecaccess-ectrans-request -minimumDuration> I<10m> B<-maximumDuration> I<35m> B<-minimumRate> I<8192> I<test@genericFtp>
313 I<ec:test.txt>
314
315 After 10 minutes ECtrans will start to control the transfer rate. If after 35 minutes the file is still not transmitted or
316 if at a certain point in time the average transmission rate is less than 8Kbytes/s then the transmission will be canceled.
317 If canceled, the transmission will be retried 144 times (with a 10 minutes interval).
318
319 =head1 SEE ALSO
320
321 B<ecaccess-ectrans-delete>, B<ecaccess-ectrans-list>, B<ecaccess-ectrans-restart> and B<ecaccess>.
322
323 =cut