File Coverage

blib/lib/Ingres/Utility/IINamu.pm
Criterion Covered Total %
statement 12 88 13.6
branch 0 28 0.0
condition 0 3 0.0
subroutine 4 10 40.0
pod 6 6 100.0
total 22 135 16.3


line stmt bran cond sub pod time code
1             package Ingres::Utility::IINamu;
2              
3 1     1   29964 use warnings;
  1         2  
  1         36  
4 1     1   7 use strict;
  1         2  
  1         40  
5 1     1   911 use Expect::Simple;
  1         53228  
  1         37  
6 1     1   12 use Carp;
  1         3  
  1         1054  
7              
8             =head1 NAME
9              
10             Ingres::Utility::IINamu - API to C Ingres RDBMS utility
11              
12             =head1 VERSION
13              
14             Version 0.07
15              
16             =cut
17              
18             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 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), 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
69              
70             Create a new instance, checking environment prerequisites
71             and preparing for interfacing with C utility.
72              
73             $namu = Ingres::Utility::IINamu->new();
74              
75             =cut
76              
77             sub new() {
78 0     0 1   my $class = shift;
79 0           my $this = {};
80 0   0       $class = ref($class) || $class;
81 0           bless $this, $class;
82 0 0         if (! defined($ENV{'II_SYSTEM'})) {
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 0         if (! -x $iigcn_file) {
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 0         } or do {
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
111              
112             Returns the output of C command, and prepares for
113             parsing the servers sequentially with C.
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             sub show(;$) {
123 0     0 1   my $this = shift;
124 0 0         my $server_type = uc (@_ ? shift : 'INGRES');
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 =~ /\ \ /) {
131 0           $before =~ s/\ \ /\ /g;
132             }
133 0           my @antes = split(/\r\n/,$before);
134 0 0         if ($#antes >= 0) {
135 0 0         if ($antes[0] eq $cmd) {
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
146              
147             Returns sequentially (call-after-call) each server reported by C 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             sub getServer() {
166 0     0 1   my $this = shift;
167 0 0         if (! $this->{stream}) {
168 0           return ();
169             }
170 0           my @antes = split($/,$this->{stream});
171 0 0         if ($#antes < $this->{streamPtr}) {
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
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             sub stop() {
190 0     0 1   my $this = shift;
191 0           my $obj = $this->{xpct};
192 0           $obj->send( 'STOP');
193 0           my $before = $obj->before;
194 0           while ($before =~ /\ \ /) {
195 0           $before =~ s/\ \ /\ /g;
196             }
197 0           my @antes = split(/\r\n/,$before);
198 0           return;
199             }
200              
201             =item C
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             sub add($$$) {
217 0     0 1   my $this = shift;
218 0 0         my $server_type = uc (@_ ? shift : '');
219 0 0         my $server_name = @_ ? shift : '';
220 0 0         my $server_addr = @_ ? shift : '';
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 =~ /\ \ /) {
226 0           $before =~ s/\ \ /\ /g;
227             }
228 0           my @antes = split(/\r\n/,$before);
229 0           return $before;
230             }
231              
232             =item C
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             sub del($$$) {
251 0     0 1   my $this = shift;
252 0 0         my $server_type = uc (@_ ? shift : '');
253 0 0         my $server_name = @_ ? shift : '';
254 0 0         my $server_addr = @_ ? shift : '';
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 =~ /\ \ /) {
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 provides the root install dir (the one before C dir).
277             C also. See Ingres RDBMS docs.
278              
279             =item C<< Ingres utility cannot be executed: _COMMAND_FULL_PATH_ >>
280              
281             The C 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 module could not be instanciated.
287             The module is reponsible for interections with C
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 and C.
296              
297             See Ingres RDBMS documentation.
298              
299              
300             =head1 DEPENDENCIES
301              
302             L
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,
315             or through the web interface at L.
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
331              
332             =item * CPAN Ratings
333              
334             L
335              
336             =item * RT: CPAN's request tracker
337              
338             L
339              
340             =item * Search CPAN
341              
342             L
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<< >>
356              
357              
358             =head1 LICENSE AND COPYRIGHT
359              
360             Copyright (c) 2006, Joner Cyrre Worm C<< >>. 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.
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             1; # End of Ingres::Utility::IINamu
396             __END__