blib/lib/MVS/JESFTP.pm

filter: Statementstmt 37.2% 16 / 43 Branchbran 5.0% 1 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 4 / 8 Podpod 100% 5 / 5 totaltotal 32.9% 26 / 79 CC 14 SCAR 27.9
CC
14
Cov
26%
wait_for_results
30.0
get_results
20.0
delete_results
20.0
CRAP 16.3
↑ Summary
1 # @(#)JESFTP.pm 1.1 03/07/09
2  
3 package MVS::JESFTP;
4  
5 =pod
6  
7 =head1 NAME
8  
9 MVS::JESFTP - Perl extension for submitting JCL to MVS systems through
10 FTP.
11  
12 =head1 SYNOPSIS
13  
14 use MVS::JESFTP;
15  
16 $jes = MVS::JESFTP->open($host, $logonid, $password) or die;
17  
18 $jes->submit($job);
19  
20 $aref = $jes->wait_for_results($jobname, $timeout);
21  
22 $jes->get_results($aref);
23  
24 $jes->delete_results($aref);
25  
26 $jes->quit;
27  
28 =head1 DESCRIPTION
29  
30 IBM mainframe MVS systems accept job input through the Job Entry
31 Subsystem (JES). This input is in the form of 80-byte I<card images>
32 that correspond to the punch cards of ancient times. The new releases of
33 MVS can accept this input via FTP to the MVS I<internal reader>
34 (equivalent to the physical card readers of older systems).
35  
36 This module uses the Net::FTP module under the hood to handle the FTP
37 chores.
38  
39 =cut
40  
41 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 1 require Exporter;
45 1 ▶use Net::FTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 1 @ISA = qw(Exporter Net::FTP);
48 1 @EXPORT = qw();
49 1 $VERSION = '1.1';
50  
51 =pod
52  
53 =head1 METHODS
54  
55 =head2 $jes = MVS::JESFTP->open($host, $logonid, $password);
56  
57 This method creates a connection to the MVS system JES. If the
58 connection is made, C<open> returns a reference C<$jes> to the JES
59 connection; otherwise C<open> returns C<undefined>.
60  
61 C<open> takes three arguments:
62  
63 =over 4
64  
65 =item C<$host>
66  
67 The IP address or DNS name of the MVS system.
68  
69 =item C<$logonid>
70  
71 A valid FTP logon ID for the host.
72  
73 =item C<$password>
74  
75 A valid FTP password for the host.
76  
77 =back
78  
79 =cut
80  
81 1 ▶sub open { #------------------------------------------------------------
Subroutine open: called CC=3 SCAR=17.3
Pod documented
82 1 my($pkg, $host, $logonid, $password) = @_;
83  
84 1 ▶ my $self = Net::FTP->new($host) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $self = "Net::FTP"->new($host) or return undef 0 1 1
85  
86 0 ▶ $self->login($logonid, $password) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->login($logonid, $password) or return undef 0 0 0
87  
88 0 bless $self, $pkg;
89  
90 0 return $self;
91 } #---------------------------------------------------------------------
92  
93 =pod
94  
95 =head2 $jes->submit($job);
96  
97 This method submits the jobstream contained in the file C<$job>. If the
98 submission is successful, C<submit> returns true; otherwise C<submit>
99 returns C<undefined>.
100  
101 =cut
102  
103 0 ▶sub submit { #----------------------------------------------------------
Subroutine submit: not called CC=2 SCAR=17.9
Pod documented
104 0 my($self, $job) = @_;
105  
106 0 ▶ $self->quot('SITE', 'FILETYPE=JES JESLRECL=80') or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->quot("SITE", "FILETYPE=JES JESLRECL=80") or return undef 0 0 0
107  
108 0 return $self->put($job);
109 } #---------------------------------------------------------------------
110  
111 =pod
112  
113 =head2 $aref = $jes->wait_for_results($jobname, $timeout);
114  
115 This method waits for the output of the submitted job to arrive in the
116 JES I<hold queue>. C<wait_for_results> returns an array reference
117 C<$aref> to the a list of output files for the job suitable for input to
118 C<get_results>, or C<undefined> if NO results could be obtained. (1)
119  
120 C<wait_for_results> takes two arguments:
121  
122 =over 4
123  
124 =item C<$jobname>
125  
126 The name of the job you presumedly submitted with the C<submit> method.
127  
128 =item C<$timeout>
129  
130 How many seconds to wait for the job output to arrive; defaults to 60.
131  
132 =back
133  
134 =cut
135  
136 0 ▶sub wait_for_results { #------------------------------------------------
Subroutine wait_for_results: not called CC=5 SCAR=34.0
Pod documented
137 0 my($self, $JOB, $TIMEOUT) = @_;
138  
139 0 $JOB =~ s/\..+$//;
140 0 ▶ $TIMEOUT ||= 60;
Condition0%0/2
$TIMEOUT ||= 60
l!l
00
MC/DC0%0/1
$TIMEOUT ||= 60
$TIMEOUT
Truth table0%0/2
A
A= $TIMEOUT
Aresult
11
00
141  
142 0 my @results = ();
143 0 my $i = 0;
144 0 ▶ while (++$i <= $TIMEOUT) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i <= $TIMEOUT) 0 0 0
145 # print "$i: waiting for $JOB...\n";
146 0 ▶ last if (@results = grep /^$JOB\s+JOB\d+\s+OUTPUT/, $self->dir);
Branch: 1 branch
BranchTrueFalseTotal
if @results = grep(/^$JOB\s+JOB\d+\s+OUTPUT/, $self->dir) 0 0 0
147 0 sleep(1);
148 }
149 0 ▶ return (@results) ? \@results : undef;
Branch: 1 branch
BranchTrueFalseTotal
@results ? : 0 0 0
150 } #---------------------------------------------------------------------
151  
152 =pod
153  
154 =head2 $result = $jes->get_results($aref);
155  
156 This method retrieves the output of the submitted job from the JES
157 I<hold queue>. C<get_results> returns C<undefined> if successful;
158 otherwise it returns a reference to an array of names of the files
159 it could NOT retrieve. (1)
160  
161 C<get_results> takes one argument:
162  
163 =over 4
164  
165 =item C<$aref>
166  
167 An array reference to the a list of output files from the job, such as
168 C<wait_for_results> generates. C<get_results> will retreive (via FTP)
169 each output file in turn and store them in the current subdirectory;
170 file names will be preserved.
171  
172 =back
173  
174 =cut
175  
176 0 ▶sub get_results { #-----------------------------------------------------
Subroutine get_results: not called CC=4 SCAR=30.0
Pod documented
177 0 my ($self, $ref) = @_;
178  
179 0 my @fails = ();
180 0 foreach my $line (@$ref) {
181 0 my $JOB = (split(/\s+/, $line))[1] . '.x';
182 0 ▶ $self->get($JOB) or push @fails, $JOB;
Branch: 1 branch
BranchTrueFalseTotal
$self->get($JOB) or push @fails, $JOB 0 0 0
183 }
184  
185 0 ▶ return (@fails) ? \@fails : undef;
Branch: 1 branch
BranchTrueFalseTotal
@fails ? : 0 0 0
186 } #---------------------------------------------------------------------
187  
188 =pod
189  
190 =head2 $result = $jes->delete_results($aref);
191  
192 This method deletes the output of the submitted job from the JES
193 I<hold queue>. C<delete_results> returns C<true> if successful;
194 otherwise it returns a reference to an array of names of the jobs
195 it could not delete.
196  
197 C<delete_results> takes one argument:
198  
199 =over 4
200  
201 =item C<$aref>
202  
203 An array reference to the a list of output files from the job, such as
204 C<wait_for_results> generates. C<delete_results> will delete each job
205 in turn.
206  
207 =back
208  
209 =cut
210  
211 0 ▶sub delete_results { #-----------------------------------------------------
Subroutine delete_results: not called CC=4 SCAR=30.0
Pod documented
212 0 my ($self, $ref) = @_;
213  
214 0 my @fails = ();
215 0 foreach my $line (@$ref) {
216 0 my $JOB = (split(/\s+/, $line))[1];
217 0 ▶ $self->delete($JOB) or push @fails, $JOB;
Branch: 1 branch
BranchTrueFalseTotal
$self->delete($JOB) or push @fails, $JOB 0 0 0
218 }
219  
220 0 ▶ return (@fails) ? \@fails : undef;
Branch: 1 branch
BranchTrueFalseTotal
@fails ? : 0 0 0
221 } #---------------------------------------------------------------------
222  
223 =pod
224  
225 =head2 $jes->quit;
226  
227 This method closes the connection to JES. It is just the Net::FTP
228 C<quit> method.
229  
230 =cut
231  
232 =pod
233  
234 (1) To use this method, your JCL I<JOB> card must specify a I<MSGCLASS>
235 that directs its output to the JES I<hold queue>. If you don't
236 understand what this means, B<don't use this method>, or you will hang
237 your calling program.
238  
239 =head1 PREREQUISITES
240  
241 You have to have Net::FTP installed.
242  
243 =head1 INSTALLATION
244  
245 tar xzf MVS-JESFTP-1.00.tar.gz
246 perl Makefile.PL
247 make
248 #
249 # Edit TEST.SEQ to contain your site-specific logonid,
250 # password, account, & node in the appropriate places.
251 #
252 make test
253 make install
254  
255 For Win32 systems, after unarchiving the the package, copy JESFTP.pm to
256 C:\Perl\site\lib\MVS (modifying this path for your installation of
257 Perl).
258  
259 =head1 AUTHOR
260  
261 Mike Owens
262  
263 mike.owens@state.nm.us
264  
265 Copyright (c) 2000 Mike Owens. All rights reserved. This program is free
266 software; you can redistribute it and/or modify it under the same terms
267 as Perl itself.
268  
269 This program is distributed in the hope that it will be useful, but
270 WITHOUT ANY WARRANTY; without even the implied warranty of
271 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the GNU
272 General Public License or the Artistic License for more details.
273  
274 =head1 SEE ALSO
275  
276 C<perl(1)>
277  
278 C<Net::FTP>
279  
280 =cut
281  
282 1 1;
↑ Summary