package RDA::Extern::Odi; # $Id: Odi.pm,v 1.6 2009/05/05 20:04:52 mschenke Exp $ # ARCS: $Header: /u02/webapps/workbench/cvs/RDA_4/src/scripting/lib/RDA/Extern/Odi.pm,v 1.6 2009/05/05 20:04:52 mschenke Exp $ # # Change History # 20090430 KRA Support ODI 11g. =head1 NAME RDA::Extern::Odi - Interface to Oracle Data Integrator =head1 SYNOPSIS require RDA::Extern::Odi; =head1 DESCRIPTION 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.6 $ =~ /(\d+)\.(\d+)/); # Define the global private variables my $MRP = 'ODI_M'; my $WRP = 'ODI_W'; my $ERR = "Therefore, this module cannot Oracle Data Integrator information."; my $WRN = "Therefore, this module has only limited information access."; my %tb_err = ( 1 => "Cannot extract login from 'odiparams.sh'. $WRN", 2 => "Cannot extract login from 'odiparams.bat'. $WRN", 4 => "Cannot extract logins from 'snps_login_security.xml'. $WRN", 5 => "Cannot extract logins from 'odiparams.sh' and ". "'snps_login_security.xml'. $ERR", 6 => "Cannot extract logins from 'odiparams.bat' and ". "'snps_login_security.xml'. $ERR", 8 => "Cannot extract logins from 'snps_login_work.xml'. $WRN", 9 => "Cannot extract logins from 'odiparams.sh' and ". "'snps_login_work.xml'. $ERR", 10 => "Cannot extract logins from 'odiparams.bat' and ". "'snps_login_work.xml'. $ERR", ); my %tb_sta = ( 1 => 1, 2 => 1, 4 => 1, 5 => 2, 6 => 2, 8 => 1, 9 => 2, 10 => 2, ); # Report the module version number sub Version { $VERSION; } =head2 S For versions earlier than 11g, this method searches Oracle Data Integrator master repositories in the F<$ODI_HOME/bin/odiparams.(bat|sh)> and F<$ODI_HOME/bin/snps_login_security.xml> files. For ODI 11g Standalone, searches Oracle Data Integrator master repositories in the F<$ODI_HOME/bin/odiparams.(bat|sh)> and F<$HOME/.odi/oracledi/snps_login_security.xml> (UNIX) and F<%USERPROFILE%\Application Data\odi\oracledi\snps_login_security.xml> (Windows) files. For ODI 11g Suite, searches Oracle Data Integrator master repositories in the F<$ODI_HOME/bin/odiparams.(bat|sh)> and F<$HOME/.jdeveloper/oracledi/snps_login_security.xml> (UNIX) and F<%USERPROFILE%\Application Data\jdeveloper\oracledi\snps_login_security.xml> (Windows) files. =cut sub search_master { my ($agt, $hom, $usr, $typ) = @_; my ($err, $off, $val, @tbl); $err = 0; # Extract login information from odiparams.(bat|sh) $hom = File::Spec->catdir($hom, 'agent') if (defined($usr) && length($usr)); ($off, $val) = $agt->is_windows ? (2, _grep_value(File::Spec->catfile($hom, 'bin', 'odiparams.bat'), qr/^\s*set ODI_SECU_USER=(.+)/i)) : (1, _grep_value(File::Spec->catfile($hom, 'bin', 'odiparams.sh'), qr/^\s*ODI_SECU_USER=([^#]+)/)); if (defined($val) && length($val)) { $agt->set_temp_setting("$MRP\_LOGIN", '[odiparams]'); push(@tbl, $MRP); } else { $err |= $off; } # Extract login information from snps_login_security.xml if (defined($usr) && length($usr)) { $err |= 4 unless _extract_logins($agt, \@tbl, $agt->is_windows ? File::Spec->catfile($usr, 'Application Data', $typ, 'oracledi', 'snps_login_security.xml') : File::Spec->catfile($usr, $typ, 'oracledi','snps_login_security.xml'), $MRP); } else { $err |= 4 unless _extract_logins($agt, \@tbl, File::Spec->catfile($hom, 'bin', 'snps_login_security.xml'), $MRP); } # Create the identifier list $agt->set_temp_setting('ODI_MASTER_SET', join(',', @tbl)); # Indicate the result $agt->set_temp_setting('ODI_MASTER_ERROR', $tb_err{$err}) if exists($tb_err{$err}); exists($tb_sta{$err}) ? $tb_sta{$err} : 0; } =head2 S For versions earlier than 11g, this method searches Oracle Data Integrator work repositories in the F<$ODI_HOME/bin/odiparams.(bat|sh)> and F<$ODI_HOME/bin/snps_login_work.xml> files. For ODI 11g Standalone, it searches Oracle Data Integrator work repositories in the F<$ODI_HOME/bin/odiparams.(bat|sh)> and F<$HOME/.odi/oracledi/snps_login_work.xml> (UNIX) and F<%USERPROFILE%\Application Data\odi\oracledi\snps_login_work.xml> (Windows) files. For ODI 11g Suite, it searches Oracle Data Integrator work repositories in the F<$ODI_HOME/bin/odiparams.(bat|sh)> and F<$HOME/.jdeveloper/oracledi/snps_login_work.xml> (UNIX) and F<%USERPROFILE%\Application Data\jdeveloper\oracledi\snps_login_work.xml> (Windows) files. =cut sub search_work { my ($agt, $hom, $usr, $typ) = @_; my ($err, $off, $val, @tbl); $err = 0; # Extract login information from odiparams.(bat|sh) $hom = File::Spec->catdir($hom, 'agent') if (defined($usr) && length($usr)); ($off, $val) = $agt->is_windows ? (2, _grep_value(File::Spec->catfile($hom, 'bin', 'odiparams.bat'), qr/^\s*set ODI_SECU_WORK_REP=(.+)/i)) : (1, _grep_value(File::Spec->catfile($hom, 'bin', 'odiparams.sh'), qr/^\s*ODI_SECU_WORK_REP=([^#]+)/)); if (defined($val) && length($val)) { $agt->set_temp_setting("$WRP\_LOGIN", '[odiparams]'); push(@tbl, $WRP); } else { $err |= $off; } # Extract login information from snps_login_work.xml if (defined($usr) && length($usr)) { $err |= 8 unless _extract_logins($agt, \@tbl, $agt->is_windows ? File::Spec->catfile($usr, 'Application Data', $typ, 'oracledi', 'snps_login_work.xml') : File::Spec->catfile($usr, $typ, 'oracledi','snps_login_work.xml'), $WRP); } else { $err |= 8 unless _extract_logins($agt, \@tbl, File::Spec->catfile($hom, 'bin', 'snps_login_work.xml'), $WRP); } # Create the identifier list $agt->set_temp_setting('ODI_WORK_SET', join(',', @tbl)); # Indicate the result $agt->set_temp_setting('ODI_WORK_ERROR', $tb_err{$err}) if exists($tb_err{$err}); exists($tb_sta{$err}) ? $tb_sta{$err} : 0; } # --- Internal functions ------------------------------------------------------ # Extract logins from a XML file sub _extract_logins { my ($agt, $tbl, $fil, $pre) = @_; my ($cnt, $nam, $num, $top); $cnt = 0; $top = RDA::Object::Xml->new->parse_file($fil); foreach my $xml ($top->find('SnpsLogin/Object')) { ($num) = $xml->find('Field name="ILogin"'); ($nam) = $xml->find('Field name="LoginName"'); next unless ref($num) && ref($nam); $num = sprintf("%s%d", $pre, $num->data); $agt->set_temp_setting("$num\_LOGIN", $nam->data); push(@$tbl, $num); ++$cnt; } $cnt; } # Grep a value from a file sub _grep_value { my ($fil, $pat) = @_; my $val; if (open(FIL, "<$fil")) { while () { if ($_ =~ $pat) { $val = $1; $val =~ s#[\n\r\s]+$##; # $val = $2 if $val =~ m/([\'\"])(.*?)\1/; last; } } close(FIL); } $val; } 1; =head1 COPYRIGHT NOTICE Copyright (c) 2002-2009, 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