Debian Codegraph @

script/ecaccess-event-send

raw
1 #!/usr/bin/perl -w
2 #
3 # ecaccess-event-send: Trigger an ECaccess Event
4 #
5 # [email protected] - 2010-10-15
6
7 use ECMWF::ECaccess;
8 use Getopt::Long;
9 use Pod::Usage;
10 use Term::ReadKey;
11
12 my %opt = ( environment => undef, delay => undef, at => undef, 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 environment:s
18 delay:s
19 at:s
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 $eventid = $ARGV[0];
32 my $sequence = $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 event-id specified!\n" ) if not($eventid);
37 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No sequence specified!\n" ) if not($sequence);
38 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Invalid sequence number!\n" ) if not( ( ( $sequence * 1 ) eq $sequence ) && abs($sequence) <= 2147483647 );
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 # Trigger the event
50 my $updates = $controlChannel->sendEvent(
51 $token,
52 $eventid,
53 SOAP::Data->name(
54 "request" => \SOAP::Data->value(
55 SOAP::Data->name( 'env' => $opt{environment} ),
56 SOAP::Data->name( 'delay' => $opt{delay} ),
57 SOAP::Data->name( 'at' => $opt{at} ),
58 SOAP::Data->name( 'seq' => $sequence )
59 )
60 )
61 )->result;
62 print "Notification sent for ", $eventid, " (", $updates, " subscription(s) updated)\n";
63
64 # Logout
65 END {
66 $ecaccess->releaseToken($token) if ($token);
67 }
68
69 __END__
70
71 =head1 NAME
72
73 ecaccess-event-send - Trigger an ECaccess Event
74
75 =head1 SYNOPSIS
76
77 B<ecaccess-event-send -version|-help|-manual>
78
79 B<ecaccess-event-send [-debug] [-environment> I<variables>B<] [-delay> I<duration>B<] [-at> I<date>B<]> I<event-id> I<sequence>
80
81 =head1 DESCRIPTION
82
83 Allow triggering the event specified by its I<event-id>. The I<sequence> number should always be greater
84 than the last I<sequence> submitted. The specified environment parameters are passed to the jobs before
85 submissions. The triggering of the event can also be delayed or started at a later time if required.
86 As a result the number of notification(s) updated is displayed.
87
88 =head1 ARGUMENTS
89
90 =over 8
91
92 =item I<event-id>
93
94 The identifier of the Event to trigger.
95
96 =item I<sequence>
97
98 The sequence number for the triggering (must be an integer between 0 and 2147483647).
99
100 =back
101
102 =head1 OPTIONS
103
104 =over 8
105
106 =item B<-environment> I<variables>
107
108 Specify which environment I<variables> to pass to the jobs. Multiple variables should be
109 separated by a semi-column (e.g. I<"PARAM1=xxx;PARAM2=yyy">).
110
111 =item B<-delay> I<duration>
112
113 Allow delaying the submission of the event (default: no delay). The I<duration> is
114 specified in [w]eeks, [d]ays, [h]ours, [m]inutes or [s]econds (e.g. I<1w> or I<2d>).
115
116 =item B<-at> I<date>
117
118 Specify the starting I<date> for the event (default: immediate submission). The
119 format of the date is "yyyy-MM-dd HH:mm" (e.g. I<"2011-01-19 12:17">).
120
121 =item B<-version>
122
123 Display version number and exits.
124
125 =item B<-help>
126
127 Print a brief help message and exits.
128
129 =item B<-manual>
130
131 Prints the manual page and exits.
132
133 =item B<-retry> I<count>
134
135 Number of SSL connection retries per 5s to ECMWF. This parameter only apply to the
136 initial SSL connection initiated by the command to the ECMWF server. It does not
137 apply to all the subsequent requests made afteward as it is mainly targeting errors
138 that can happen from time to time during the SSL handshake. Default is no retry.
139
140 =item B<-debug>
141
142 Display the SOAP and SSL messages exchanged.
143
144 =back
145
146 =head1 EXAMPLES
147
148 B<ecaccess-event-send> I<167> I<2000>
149
150 Trigger the event I<167> with a sequence number of I<2000>.
151
152 B<ecaccess-event-send -delay> I<1d> I<167> I<2000>
153
154 Trigger the same event as in the previous example in 24 hours.
155
156 =head1 SEE ALSO
157
158 B<ecaccess-event-grant>, B<ecaccess-event-clear>, B<ecaccess-event-list>, B<ecaccess-event-delete>,
159 B<ecaccess-event-create> and B<ecaccess>.
160
161 =cut