package RDA::Discover; # $Id: Discover.pm,v 1.17 2008/02/25 14:55:25 mschenke Exp $ # ARCS: $Header: /home/cvs/repository/RDA_4/src/scripting/lib/RDA/Discover.pm,v 1.17 2008/02/25 14:55:25 mschenke Exp $ # # Change History # 20080225 MSC Change the copyright notice. =head1 NAME RDA::Discover - Class Used to Manage the Auto Discovery Aspects =head1 SYNOPSIS require RDA::Discover; =head1 DESCRIPTION The objects of the C class are used to manage the auto discovery aspects. The following methods are available: =cut use strict; BEGIN { use Exporter; use File::Spec; use RDA::Object::Xml; } # Define the global public variables use vars qw($VERSION); $VERSION = sprintf("%d.%02d", q$Revision: 1.17 $ =~ /(\d+)\.(\d+)/); # Define the global private variables my %tb_inv = ( LOCATION => 'INST_LOC', VERSION => 'VER', ); my %tb_ocm = ( LOCATION => 'INSTALLED_LOCATION', VERSION => 'VERSION', ); # Report the module version number sub Version { $VERSION; } =head2 S<$h = RDA::Discover-Enew($agt)> The object constructor. It takes the agent reference as an argument. C is represented by a blessed hash reference. The following special keys are used: =over 16 =item B< '_agt' > Reference to the agent object =item B< '_inv' > Inventory object =item B< '_prd' > OCM product list =item B< '_typ' > Inventory type =back Internal keys are prefixed by an underscore. Defined types are as follows: =over 16 =item B< '' > No inventory found =item B< 'INV' > Oracle home inventory =item B< 'OCM' > OCM configuration information =back =cut sub new { my $slf = shift; my $cls = ref($slf) || $slf; my $agt = shift; my $dir = shift; my ($fil, $obj, $trc); # Create the render object $slf = bless { _agt => $agt, _typ => '' }, $cls; # Determine trace request $trc = $agt->get_setting('XML_TRACE', 0); # Examine the Oracle home inventory unless ($agt->get_setting('NO_INVENTORY')) { $fil = File::Spec->catfile($dir, 'inventory', 'ContentsXML', 'comps.xml'); if (-r $fil) { $slf->{'_inv'} = RDA::Object::Xml->new($trc)->parse_file($fil); $slf->{'_typ'} = 'INV'; return $slf; } } # Examine the OCM configuration informantion unless ($agt->get_setting('NO_OCM')) { if ($fil = _get_ocm_inv($dir)) { $slf->{'_inv'} = $obj = RDA::Object::Xml->new($trc)->parse_file($fil); $slf->{'_prd'} = [$obj->find(".../ROWSET TABLE='MGMT_LL_INV_COMPONENT'/ROW")]; $slf->{'_typ'} = 'OCM'; return $slf; } } # Return the object reference $slf; } sub _get_ocm_inv { my ($dir) = @_; my ($nam, $pth); foreach my $sub (qw(ccr livelink)) { if (-d ($pth = File::Spec->catdir($dir, $sub, 'state', 'review'))) { if (opendir(DIR, $pth)) { ($nam) = grep {/-oracle_home_config\.xml$/i} readdir(DIR); closedir(DIR); return $pth if $nam && -r ($pth = File::Spec->catfile($pth, $nam)); } last; } } ''; } =head2 S<$h-Eget_type> This method indicates the type of inventory used for the auto discovery. =cut sub get_type { shift->{'_typ'}; } =head1 AUTO DISCOVERY METHODS =head2 S<$h-Echeck($name,$prod)> This method determines if the product is installed. When it finds the product in the inventory, it sets the temporary settings CnameE_VERSION> and CnameE_LOCATION> and returns a true value. Otherwise, it returns an undefined value. =cut sub check { my ($slf, $nam, $prd) = @_; my ($agt, $res); # Validate the parameters return undef unless $nam =~ m/^\w+$/ && $prd =~ m/^\w+(\.\w+)*$/; # Check the product information $agt = $slf->{'_agt'}; if ($slf->{'_typ'} eq 'INV') { $prd =~ s/\./\\\./g; $res = _get_first($slf->{'_inv'},"PRD_LIST/COMP_LIST/PATCH NAME='^$prd\$'") || _get_first($slf->{'_inv'},"PRD_LIST/COMP_LIST/COMP NAME='^$prd\$'"); if ($res) { foreach my $key (keys %tb_inv) { $agt->set_temp_setting("$nam\_$key", $res->{$tb_inv{$key}}) if exists($res->{$tb_inv{$key}}); } return 1; } } elsif ($slf->{'_typ'} eq 'OCM') { foreach my $obj (@{$slf->{'_prd'}}) { if (_get_text($obj, 'NAME', '') eq $prd) { foreach my $key (keys %tb_ocm) { $agt->set_temp_setting("$nam\_$key", $res) if defined($res = _get_text($obj, $tb_ocm{$key})); } return 1; } } } undef; } =head2 S<$h-Efind($attr,$prod[,$dft])> This method finds the specified attribute for a given product and returns its value. It returns the default value when the product is not found. =cut sub find { my ($slf, $key, $prd, $val) = @_; my $res; # Validate the parameters $key = uc($key); return undef unless exists($tb_inv{$key}) && $prd =~ m/^\w+(\.\w+)*$/; # Find the attribute if ($slf->{'_typ'} eq 'INV') { $key = $tb_inv{$key}; $prd =~ s/\./\\\./g; $res = _get_first($slf->{'_inv'}, "PRD_LIST/COMP_LIST/PATCH NAME='^$prd\$'") || _get_first($slf->{'_inv'}, "PRD_LIST/COMP_LIST/COMP NAME='^$prd\$'"); $val = $res->{$key} if $res && exists($res->{$key}); } elsif ($slf->{'_typ'} eq 'OCM') { foreach my $obj (@{$slf->{'_prd'}}) { if (_get_text($obj, 'NAME', '') eq $prd) { $val = _get_text($obj, $tb_ocm{$key}); last; } } } $val; } # Get the first element from a query result sub _get_first { my ($xml, $qry, $nod) = @_; ($nod) = $xml->find($qry); $nod; } # Get the text of a specific XML element sub _get_text { my ($xml, $tag, $dft) = @_; my $nod; ($nod = _get_first($xml, $tag)) ? $nod->data : $dft; } 1; __END__ =head1 SEE ALSO See also L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L. =head1 COPYRIGHT NOTICE Copyright (c) 2002-2008, Oracle. All rights reserved. =head1 TRADEMARK NOTICE Oracle, JD Edwards, PeopleSoft, and Siebel are registered trademarks of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. =cut