# WlHome.pm: Class Used to Interface the Oracle WebLogic Server Homes package RDA::Target::WlHome; # $Id: WlHome.pm,v 1.15 2015/05/08 18:21:28 RDA Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_8/src/scripting/lib/RDA/Target/WlHome.pm,v 1.15 2015/05/08 18:21:28 RDA Exp $ # # Change History # 20150505 MSC Improve the documentation. =head1 NAME RDA::Target::WlHome - Class Used to Interface the Oracle WebLogic Server Homes =head1 SYNOPSIS require RDA::Target::WlHome; =head1 DESCRIPTION The objects of the C class are used to interface with the Oracle WebLogic Server homes. It is a subclass of L. The following methods are available: =cut use strict; BEGIN { use Exporter; use IO::File; use RDA::Text qw(get_string); use RDA::Object; use RDA::Object::Rda; use RDA::Object::Target; } # Define the global public variables use vars qw($STRINGS $VERSION @DUMP @ISA %SDCL); $VERSION = sprintf('%d.%02d', q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/); @DUMP = ( hsh => {'RDA::Target::Base' => 1, 'RDA::Target::Common' => 1, 'RDA::Target::Database' => 1, 'RDA::Target::Db' => 1, 'RDA::Target::Dbi' => 1, 'RDA::Target::Domain' => 1, 'RDA::Target::Home' => 1, 'RDA::Target::Instance' => 1, 'RDA::Target::MwHome' => 1, 'RDA::Target::System' => 1, 'RDA::Target::WlHome' => 1, }, ); @ISA = qw(RDA::Object::Target RDA::Object Exporter); %SDCL = ( inc => [qw(RDA::Object::Target RDA::Object)], met => {'get_version' => {ret => 0}, }, ); # Define the global private constants # Define the global private variables my %tb_nat = map {$_ => 1} qw(wlh); # Report the package version sub Version { return $VERSION; } =head2 S<$h = RDA::Target::WlHome-Enew($oid,$col,$def,$par[,$edt])> The object constructor. It takes the object identifier, the collector object reference, the definition item reference, the parent target reference, and an optional initial attribute hash reference as arguments. Do not use this constructor directly. Create all targets using L methods. C is represented by a blessed hash reference. The following special keys are used: =over 12 =item S< B<'col' > > Reference to the collector object =item S< B<'jdk' > > JDK directory =item S< B<'oid' > > Object identifier =item S< B<'par' > > Reference to the parent target =item S< B<'raw' > > Raw value indicator =item S< B<'wlh' > > Oracle WebLogic Server home directory =item S< B<'_abr'> > Symbol definition hash =item S< B<'_bkp'> > Backup of environment variables =item S< B<'_chg'> > Symbol change hash =item S< B<'_chl'> > List of the child keys =item S< B<'_def'> > Reference to the target definition item =item S< B<'_env'> > Environment specifications =item S< B<'_fcs'> > Focus hash =item S< B<'_mwh'> > Reference to the Middleware home target =item S< B<'_prs'> > Symbol detection parse tree =item S< B<'_shr'> > Share indicator =item S< B<'_typ'> > Target type =item S< B<'_ver'> > Version of the Oracle WebLogic Server =back Internal keys are prefixed by an underscore. =cut sub new { my ($cls, $oid, $col, $def, $par, $edt) = @_; my ($flg, $key, $raw, $slf, $tgt, $val); # Create the system object $raw = $def->get_first('B_RAW', 0); $slf = bless { col => $col, oid => $par->get_unique($oid), par => $par, raw => $raw, _chl => [], _def => $def, _fcs => {}, _shr => $def->get_first(['B_DEDICATED_WL_HOME','B_DEDICATED']) ? 0 : 1, _typ => 'WH', }, ref($cls) || $cls; # Load the target definition $slf->{'wlh'} = $val if defined($val = $def->get_first('D_WL_HOME', undef, $raw)); # Add the initial attributes if ($edt) { foreach my $key (keys(%{$edt})) { $slf->{$key} = exists($tb_nat{$key}) ? RDA::Object::Rda->native($edt->{$key}) : $edt->{$key}; } } # Validate the configuration die get_string('NO_HOME', $oid) unless exists($slf->{'wlh'}); # Load the associated Oracle home target unless ($def->get_first('B_MISSING_MW_HOME')) { if (defined($val = $def->get_first('I_MW_HOME'))) { $slf->{'_mwh'} = $slf->add_target($val); push(@{$slf->{'_chl'}}, '_mwh'); } elsif (defined($val = $def->get_first('W_MW_HOME'))) { $slf->{'_mwh'} = $slf->get_target($val); push(@{$slf->{'_chl'}}, '_mwh'); } elsif (defined($val = _find_mw_home($slf, $def))) { $oid =~ s/^WH_/MH_/i; $tgt = ($flg = $def->get_prime('B_DEDICATED_MW_HOME')) ? undef : $par->find_target('MH', mwh => RDA::Object::Rda->native($val)); $slf->{'_mwh'} = $tgt || $slf->add_target($oid, {B_DEDICATED_COMMON => $def->get_prime('B_DEDICATED_COMMON'), B_DEDICATED_MW_HOME => $flg, B_MISSING_COMMON => $def->get_prime('B_MISSING_COMMON'), B_RAW => $raw, D_COMMON_HOME => $def->get_prime('D_COMMON_HOME'), D_MW_HOME => $val, I_COMMON_HOME => $def->get_prime('I_COMMON_HOME'), T_CH_ABBR => $def->get_prime('T_CH_ABBR'), T_MH_ABBR => $def->get_prime('T_MH_ABBR'), W_COMMON_HOME => $def->get_prime('W_COMMON_HOME'), }); push(@{$slf->{'_chl'}}, '_mwh'); } } # Get the Java home $slf->{'jdk'} = $val if defined($val = _find_java_home($slf, $def)); # Initiate the symbol management when applicable unless (RDA::Object::Rda->is_vms) { $slf->{'_abr'} = {}; $slf->set_symbol($def->get_first('T_WH_ABBR'), $slf->{'wlh'}); delete($slf->{'_chg'}); } # Return the object reference return $slf; } =head2 S<$h-Eadjust_env($env)> This method adjusts environment variable specifications for the Oracle WebLogic Server home. =cut sub adjust_env { my ($slf, $env) = @_; my ($lib, $sep, $wlh, %tbl, @dir); # Apply Oracle middleware specifications $slf->{'_mwh'}->adjust_env($env) if exists($slf->{'_mwh'}); # Add the target specifications $env->{'WL_HOME'} = $wlh = $slf->{'wlh'}; # Add the operating system-specific target specifications unless (RDA::Object::Rda->is_vms) { $sep = RDA::Object::Rda->get_separator; # Adapt the command path @dir = split(/$sep/, $env->{'PATH'}); %tbl = map {$_ => 1} @dir; foreach my $dir (RDA::Object::Rda->cat_dir($wlh, 'server', 'adr'), RDA::Object::Rda->cat_dir($wlh, 'common', 'bin')) { unshift(@dir, $dir) unless exists($tbl{$dir}) ## no critic (Unless) || !defined($dir = $slf->get_top('sys')->is_restricted($dir)); } $env->{'PATH'} = join($sep, @dir); # Adapt the shared library path if (defined($lib = RDA::Object::Rda->get_shlib)) { @dir = split(/$sep/, $env->{$lib}); %tbl = map {$_ => 1} @dir; foreach my $dir (RDA::Object::Rda->cat_dir($wlh, 'server', 'adr'), RDA::Object::Rda->cat_dir($wlh, 'common', 'lib')) { unshift(@dir, $dir) if -d $dir && !exists($tbl{$dir}); } $env->{$lib} = join($sep, @dir); } } return; } =head2 S<$h-Efind_jars($typ,$src,$jdk)> This method returns the list of C files required to connect to the specified database. =cut sub find_jars { my ($slf, $typ, $src, $jdk) = @_; my ($dir, $jar, $ver, @nam, @jar); $dir = RDA::Object::Rda->cat_dir($slf->{'wlh'}, 'server', 'lib'); if (-d RDA::Object::Rda->cat_dir($slf->{'wlh'}, 'inventory')) { # Get Oracle 11g contributions if ($typ eq 'oracle') { (undef, $ver) = $slf->get_jdk_version($jdk); if (defined($ver)) { return $jar if -f ($jar = RDA::Object::Rda->cat_file($dir, "ojdbc$ver.jar")); @jar = _grep_oracle_jar($dir, 5, $ver); return pop(@jar) if @jar; } else { @jar = _grep_oracle_jar($dir, 0, 99); return shift(@jar) if @jar; } return; } # Identify other 11g contributions @nam = ("wl$typ.jar", 'wlclient.jar', 'wlutil.jar'); } else { # Get upper 12c contributions @jar = $slf->{'_mwh'}->find_jars($typ, $src, $jdk) if exists($slf->{'_mwh'}); return @jar if $typ eq 'oracle'; # Identify local 12c contributions @nam = ('wlclient.jar'); } # Add local contributions foreach my $nam (@nam) { push(@jar, $jar) if -f ($jar = RDA::Object::Rda->cat_file($dir, $nam)); } return @jar; } sub _grep_oracle_jar { my ($dir, $min, $max) = @_; my (@jar); if (opendir(DIR, $dir)) { foreach my $fil (readdir(DIR)) { push(@jar, RDA::Object::Rda->cat_file($dir, $fil)) if $fil =~ m/^ojdbc(\d+)\.jar$/ && $1 >= $min && $1 <= $max; } closedir(DIR); } return (sort @jar); } =head2 S<$h-Eget_env> This method returns the environment variable specifications as a hash reference. =cut sub get_env { my ($slf) = @_; # Determine the environment specifications on first usage adjust_env($slf, $slf->{'_env'} = {%{$slf->get_default->get_env}}) unless exists($slf->{'_env'}); # Return the environment specifications return $slf->{'_env'}; } =head2 S<$h-Eget_version> This method returns the Oracle WebLogic Server version when found. =cut sub get_version { my ($slf) = @_; my ($ifh); unless (exists($slf->{'_ver'})) { $slf->{'_ver'} = undef; $ifh = IO::File->new; if ($ifh->open('<'.RDA::Object::Rda->cat_file($slf->{'wlh'}, '.product.properties'))) { while (<$ifh>) { if (m/^[^\043]*\bWLS_PRODUCT_VERSION=(.*)$/) { $slf->{'_ver'} = $1; last; } } $ifh->close; } } return $slf->{'_ver'}; } # --- Internal routines ------------------------------------------------------- # Find the Java home directory sub _find_java_home { my ($slf, $def) = @_; return $def->get_prime('D_JAVA_HOME', undef, $slf->{'raw'}) || _get_item($slf, 'jdk'); } # Find the Oracle Middleware home sub _find_mw_home { my ($slf, $def) = @_; my ($dir, @dir); # Check the definition return $dir if defined($dir = $def->get_prime('D_MW_HOME', undef, $slf->{'raw'})); # Derive the Oracle Middleware home from the Oracle WebLogic Server home @dir = RDA::Object::Rda->split_dir($slf->{'wlh'}); pop(@dir); return RDA::Object::Rda->cat_dir(@dir); } # Detect the Oracle WebLogic Server-associated homes sub _get_homes { my ($slf) = @_; my ($det, $ifh); # Return the detection result when already available return $slf->{'_det'} if exists($slf->{'_det'}); # Detect the associated home directories on first use $slf->{'_det'} = $det = {}; _get_homes_prop($slf, $det) unless $slf->{'_def'}->{'B_NO_DETECT'}; return $det; } sub _get_homes_prop { my ($slf, $det) = @_; my ($ifh, $val); $ifh = IO::File->new; if ($ifh->open('<'.RDA::Object::Rda->cat_file($slf->{'wlh'}, '.product.properties'))) { while (<$ifh>) { if (m/^[^\043]*\bJAVA_HOME=(.*)$/) { if (length($val = $1)) { $val =~ s/(\w+)\\:/$1:/; $det->{'jdk'} = RDA::Object::Rda->cat_dir($val); } last; } } $ifh->close; } return; } # Get a detected item sub _get_item { my ($slf, $key, $dft) = @_; my ($det); $det = _get_homes($slf); return exists($det->{$key}) ? $det->{$key} : $dft; } 1; __END__ =head1 SEE ALSO L, L, L, L, L, L, L, L, L =head1 COPYRIGHT NOTICE Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. =head1 TRADEMARK NOTICE Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. =cut