blib/lib/Ingres/Utility/IINamu.pm

filter: Statementstmt 15.5% 14 / 90 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 4 / 10 Podpod 100% 6 / 6 totaltotal 16.3% 24 / 147 CC 20 SCAR 31.1
CC
20
Cov
11%
new
30.0
show
30.0
add
30.0
CRAP 22.5
↑ Summary
1 package Ingres::Utility::IINamu;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Expect::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Ingres::Utility::IINamu - API to C<iinamu> Ingres RDBMS utility
11  
12 =head1 VERSION
13  
14 Version 0.07
15  
16 =cut
17  
18 2 our $VERSION = '0.07';
19  
20 =head1 SYNOPSIS
21  
22 List registered INGRES (IIDBMS) services:
23  
24 use Ingres::Utility::IINamu;
25  
26 my $foo = Ingres::Utility::IINamu->new();
27
28 # list all INGRES-type servers (iidbms)
29 print $foo->show('INGRES');
30
31 # process each server separately
32 while (my @server = $foo->getServer()) {
33
34 print "Server type: $server[0]\tname:$server[1]\tid:$server[2]";
35  
36 if (defined($server[3])) {
37  
38 print "\t$server[3]";
39  
40 }
41  
42 print "\n";
43  
44 }
45
46 # stop IIGCN server (no more connections to all of Ingres services)
47 $ret = $foo->stop();
48
49 ...
50  
51  
52 =head1 DESCRIPTION
53  
54 This module provides an API to the C<iinamu> utility for Ingres RDBMS,
55 which provides local interaction and control of IIGCN server,
56 in charge of registering all Ingres services.
57  
58 Through this interface, it is possible to obtain a list of all
59 registered services, for later processing (eg. C<iimonitor>), and
60 also stopping the IIGCN server (EXTREME CAUTION: Ingres may need
61 to be restarted!).
62  
63  
64 =head1 FUNCTIONS
65  
66 =over
67  
68 =item C<new()>
69  
70 Create a new instance, checking environment prerequisites
71 and preparing for interfacing with C<iinamu> utility.
72  
73 $namu = Ingres::Utility::IINamu->new();
74  
75 =cut
76  
77 0 ▶sub new() {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
78 0 my $class = shift;
79 0 my $this = {};
80 0 ▶ $class = ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
81 0 bless $this, $class;
82 0 ▶ if (! defined($ENV{'II_SYSTEM'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ENV{"II_SYSTEM"}) 0 0 0
83 0 carp "Ingres environment variable II_SYSTEM not set";
84 0 return {};
85 }
86 0 my $iigcn_file = $ENV{'II_SYSTEM'} . '/ingres/bin/iinamu';
87
88 0 ▶ if (! -x $iigcn_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $iigcn_file) 0 0 0
89 0 carp "Ingres utility cannot be executed: $iigcn_file";
90 0 return {};
91 }
92 0 $this->{cmd} = $iigcn_file;
93 $this->{xpct} = new Expect::Simple {
94 Cmd => $iigcn_file,
95 Prompt => [ -re => 'IINAMU>\s+' ],
96 DisconnectCmd => 'QUIT',
97 Verbose => 0,
98 Debug => 0,
99 Timeout => 10
100 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
$this->{"xpct"} = "Expect::Simple"->new({"Cmd", $iigcn_file, "Prompt", ["-re", "IINAMU>\\s+"], "DisconnectCmd", "QUIT", "Verbose", 0, "Debug", 0, "Timeout", 10}) or do { carp("Module Expect::Simple cannot be instanciated."); return {} } 0 0 0
101 0 carp "Module Expect::Simple cannot be instanciated.";
102 0 return {};
103 };
104 0 $this->{stream} = '';
105 0 $this->{streamPtr} = 0;
106 0 $this->{svrType} = '';
107 0 return $this;
108 }
109  
110 =item C<show(;$serverType)>
111  
112 Returns the output of C<SHOW> command, and prepares for
113 parsing the servers sequentially with C<getServer()>.
114  
115 Takes one optional argument for the service: C<'INGRES'>(IIDBMS, default),
116 C<'COMSVR'> (IIGCC), etc.
117  
118 print $namu->show('COMSVR'); # show IIGCN servers
119  
120 =cut
121  
122 0 ▶sub show(;$) {
Subroutine show: not called CC=5 SCAR=34.0
Pod documented
123 0 my $this = shift;
124 0 ▶ my $server_type = uc (@_ ? shift : 'INGRES');
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
125 #print $this . ": cmd = $cmd";
126 0 my $obj = $this->{xpct};
127 0 my $cmd = 'SHOW ' . $server_type;
128 0 $obj->send($cmd);
129 0 my $before = $obj->before;
130 0 ▶ while ($before =~ /\ \ /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before =~ /\ \ /) 0 0 0
131 0 $before =~ s/\ \ /\ /g;
132 }
133 0 my @antes = split(/\r\n/,$before);
134 0 ▶ if ($#antes >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#antes >= 0) 0 0 0
135 0 ▶ if ($antes[0] eq $cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($antes[0] eq $cmd) 0 0 0
136 0 shift @antes;
137 }
138 }
139 0 $this->{stream} = join($/,@antes);
140 0 $this->{streamPtr} = 0;
141 0 $this->{svrType} = $server_type;
142 0 return $this->{stream};
143 }
144  
145 =item C<getServer()>
146  
147 Returns sequentially (call-after-call) each server reported by C<show()> as an array of
148 3~4 elements:
149  
150 # getServer()[0]: server type (INGRES, COMSVR, etc.)
151 # getServer()[1]: server name (as registered with IINAMU or add() method)
152 # getServer()[2]: server GCA address (given by INGSTART)
153 # getServer()[3]: extra info
154
155 $namu->show('INGRES'); # prepare to show all INGRES (IIDBMS ) servers
156
157 while (@svrs = $namu->getServer()) {
158 print "Server name: $svrs[1]\t address: $svrs[2]";
159 print "\t($svrs[3])" if (defined $svrs[3]);
160 print "\n"
161 }
162  
163 =cut
164  
165 0 ▶sub getServer() {
Subroutine getServer: not called CC=3 SCAR=24.8
Pod documented
166 0 my $this = shift;
167 0 ▶ if (! $this->{stream}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"stream"}) 0 0 0
168 0 return ();
169 }
170 0 my @antes = split($/,$this->{stream});
171 0 ▶ if ($#antes < $this->{streamPtr}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#antes < $this->{"streamPtr"}) 0 0 0
172 0 $this->{streamPtr} = 0;
173 0 return ();
174 }
175 0 my $line = $antes[$this->{streamPtr}++];
176 0 return split(/\ /, $line);
177 }
178  
179 =item C<stop()>
180  
181 Shuts down the IIGCN daemon, making it no longer possible to
182 stablish new connections to any Ingres service.
183 After this, a total restart of Ingres will most probably be necessary.
184  
185 $namu->stop(); # no more connections (local remote, etc...)
186  
187 =cut
188  
189 0 ▶sub stop() {
Subroutine stop: not called CC=2 SCAR=17.9
Pod documented
190 0 my $this = shift;
191 0 my $obj = $this->{xpct};
192 0 $obj->send( 'STOP');
193 0 my $before = $obj->before;
194 0 ▶ while ($before =~ /\ \ /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before =~ /\ \ /) 0 0 0
195 0 $before =~ s/\ \ /\ /g;
196 }
197 0 my @antes = split(/\r\n/,$before);
198 0 return;
199 }
200  
201 =item C<add($serverType,$serverName,$serverAddr)>
202  
203 Register another server with IIGCN, so that it can be available
204 to clients.
205  
206 Parameters:
207  
208 # serverType: type of server (INGRES, COMSVR, etc.)
209 # serverName: '*' or a name to individualize the server from the others
210 # serverAddr: GCA address attributed during ingstart utility
211
212 print $namu->add('COMSVR', '*', '123456'); # register IIGCN server
213  
214 =cut
215  
216 0 ▶sub add($$$) {
Subroutine add: not called CC=5 SCAR=34.0
Pod documented
217 0 my $this = shift;
218 0 ▶ my $server_type = uc (@_ ? shift : '');
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
219 0 ▶ my $server_name = @_ ? shift : '';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
220 0 ▶ my $server_addr = @_ ? shift : '';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
221 0 my $obj = $this->{xpct};
222 0 my $cmd = "ADD $server_type $server_name $server_addr";
223 0 $obj->send($cmd);
224 0 my $before = $obj->before;
225 0 ▶ while ($before =~ /\ \ /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before =~ /\ \ /) 0 0 0
226 0 $before =~ s/\ \ /\ /g;
227 }
228 0 my @antes = split(/\r\n/,$before);
229 0 return $before;
230 }
231  
232 =item C<del($serverType,$serverName,$serverAddr)>
233  
234  
235 Unregister another server with IIGCN, so that it will not be
236 available to clients.
237  
238 A server can be registered later again.
239  
240 Parameters:
241  
242 # serverType: type of server (INGRES, COMSVR, etc.)
243 # serverName: '*' or a name to individualize the server from the others
244 # serverAddr: GCA address attributed during ingstart utility
245
246 print $namu->del('COMSVR', '*', '123456'); # this one is not seen anymore.
247  
248 =cut
249  
250 0 ▶sub del($$$) {
Subroutine del: not called CC=5 SCAR=34.0
Pod documented
251 0 my $this = shift;
252 0 ▶ my $server_type = uc (@_ ? shift : '');
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
253 0 ▶ my $server_name = @_ ? shift : '';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
254 0 ▶ my $server_addr = @_ ? shift : '';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
255 0 my $obj = $this->{xpct};
256 0 my $cmd = "DEL $server_type $server_name $server_addr";
257 0 $obj->send($cmd);
258 0 my $before = $obj->before;
259 0 ▶ while ($before =~ /\ \ /) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before =~ /\ \ /) 0 0 0
260 0 $before =~ s/\ \ /\ /g;
261 }
262 0 my @antes = split(/\r\n/,$before);
263 0 return $before;
264 }
265  
266 =back
267  
268 =head1 DIAGNOSTICS
269  
270 =over
271  
272 =item C<< Ingres environment variable II_SYSTEM not set >>
273  
274 Ingres environment variables should be set on the user session running
275 this module.
276 C<II_SYSTEM> provides the root install dir (the one before C<ingres> dir).
277 C<LD_LIBRARY_PATH> also. See Ingres RDBMS docs.
278  
279 =item C<< Ingres utility cannot be executed: _COMMAND_FULL_PATH_ >>
280  
281 The C<iinamu> command could not be found or does not permits execution for
282 the current user.
283  
284 =item C<< Module Expect::Simple cannot be instanciated. >>
285  
286 The L<Expect::Simple> module could not be instanciated.
287 The module is reponsible for interections with C<iinamu>
288 utility. Debugging will be required.
289  
290 =back
291  
292  
293 =head1 CONFIGURATION AND ENVIRONMENT
294
295 Requires Ingres environment variables, such as C<II_SYSTEM> and C<LD_LIBRARY_PATH>.
296  
297 See Ingres RDBMS documentation.
298  
299  
300 =head1 DEPENDENCIES
301  
302 L<Expect::Simple>
303  
304  
305 =head1 INCOMPATIBILITIES
306  
307 None reported.
308  
309  
310 =head1 BUGS AND LIMITATIONS
311  
312 No bugs have been reported.
313  
314 Please report any bugs or feature requests to C<bug-ingres-utility-iinamu at rt.cpan.org>,
315 or through the web interface at L<http://rt.cpan.org>.
316  
317  
318 =head1 SUPPORT
319  
320 You can find documentation for this module with the perldoc command.
321  
322 perldoc Ingres::Utility::IINamu
323  
324 You can also look for information at:
325  
326 =over 4
327  
328 =item * AnnoCPAN: Annotated CPAN documentation
329  
330 L<http://annocpan.org/dist/Ingres-Utility-IINamu>
331  
332 =item * CPAN Ratings
333  
334 L<http://cpanratings.perl.org/d/Ingres-Utility-IINamu>
335  
336 =item * RT: CPAN's request tracker
337  
338 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Ingres-Utility-IINamu>
339  
340 =item * Search CPAN
341  
342 L<http://search.cpan.org/dist/Ingres-Utility-IINamu>
343  
344 =back
345  
346  
347 =head1 ACKNOWLEDGEMENTS
348  
349 Thanks to Computer Associates (CA) for licensing Ingres as
350 open source, and let us hope for Ingres Corp to keep it that way.
351  
352  
353 =head1 AUTHOR
354  
355 Joner Cyrre Worm C<< <FAJCNLXLLXIH at spammotel.com> >>
356  
357  
358 =head1 LICENSE AND COPYRIGHT
359  
360 Copyright (c) 2006, Joner Cyrre Worm C<< <FAJCNLXLLXIH at spammotel.com> >>. All rights reserved.
361  
362  
363 Ingres is a registered brand of Ingres Corporation.
364  
365  
366 This program is free software; you can redistribute it and/or modify it
367 under the same terms as Perl itself. See L<perlartistic>.
368  
369  
370 =head1 DISCLAIMER OF WARRANTY
371  
372 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
373 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
374 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
375 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
376 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
377 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
378 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
379 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
380 NECESSARY SERVICING, REPAIR, OR CORRECTION.
381  
382 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
383 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
384 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
385 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
386 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
387 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
388 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
389 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
390 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
391 SUCH DAMAGES.
392  
393 =cut
394  
395 2 1; # End of Ingres::Utility::IINamu
396 __END__
↑ Summary