# OCMlib.ctl: Defines Common OCM Macros # $Id: OCMlib.ctl,v 1.8 2013/11/19 15:56:02 RDA Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_8/src/scripting/lib/collect/RDA/OCMlib.ctl,v 1.8 2013/11/19 15:56:02 RDA Exp $ # # Change History # 20131119 MSC Fix the distribution property. =head1 NAME RDA:OCMlib - Defines Common OCM Macros =head1 DESCRIPTION This persistent submodule regroups macros that are common to several OCM modules. The following macros are available: =cut use Log # Make the module persistent and share macros keep $KEEP_BLOCK,@RESET_MACROS,@SHARE_MACROS var @SHARE_MACROS = ('do_collect','do_status','do_upgrade',\ 'dsp_collect','dsp_status',\ 'get_ocm_home','get_ocm_mode','get_wls_config') var @RESET_MACROS = @SHARE_MACROS =head2 S This macro triggers an OCM collection. =cut macro do_collect {var ($toc,$rps,$rpc,$cmd,$dir,$not,$flg,$ttl) = @arg import $TOC,$TOP # Get the OCM status call dsp_status($toc,$rps,$cmd,$ttl) # Perform an OCM collection decr $dur,time() call loadCommand(concat($cmd,' -annotation=',quote($not),' collect'),false,4) incr $dur,time() var $sta = status() call log('OCM','collect',$not,$dur,$sta,$ttl) if $sta return 0 # Report collection overview when the collect is successful call dsp_collect($toc,$rpc,$dir,$not,$ttl) return $flg } macro dsp_status {var ($toc,$rpt,$cmd,$ttl) = @arg import $TOC if $rpt->is_locked var $rpt = $rpt->clone elsif !$rpt->is_created write {$toc} '3:[[',$rpt->get_report,'][rda_report][Initial Status]]' if $ttl write {$rpt} '---+ ',$ttl,' ' call writeCommand($rpt,concat($cmd,' status 2>&1')) write {$rpt} '**Note:** Status collected before executing any OCM command' if $rpt->is_cloned call $rpt->render } macro dsp_collect {var ($toc,$rpt,$dir,$not,$ttl) = @arg import $TOC,$TOP if $rpt->is_locked var $rpt = $rpt->clone elsif !$rpt->is_created write {$toc} '3:[[',$rpt->get_report,\ '][rda_report][Configuration Collection]]' if $ttl {write {$rpt} '---+ ',$ttl,' ' var $lvl = '---++!! ' } else var $lvl = '---+ ' write {$rpt} $lvl,'Collection Identification' write {$rpt} '|*Annotation*|',$not,'|' write {$rpt} $TOP prefix $rpt {write {$rpt} $lvl,'Collection Details' write {$rpt} '|*Name*|*File*|*Time Stamp*|' } var $xml = xmlLoadFile(catFile($dir,'state','review','targetMap.xml')) loop $itm (xmlFind($xml,'.../Collection')) write {$rpt} '|',xmlValue($itm,'name'),' |',xmlValue($itm,'file'),' |',\ xmlValue($itm,'collection_timestamp'),' |' if $rpt->has_output(true) write {$rpt} $TOP if $rpt->is_cloned call $rpt->render } =head2 S This macro gets the OCM status. =cut macro do_status {var ($toc,$rps,$rpc,$cmd,$dir,$not,$ttl) = @arg import $TOC,$TOP # Get the OCM status call dsp_status($toc,$rps,$cmd,$ttl) # Report collection overview when an annotation is provided if ?$not call dsp_collect($toc,$rpc,$dir,$not,$ttl) } =head2 S This macro upgrades an OCM installation. =cut macro do_upgrade {var ($cmd,$ccr,$ttl) = @arg if ?testDir('d',$top = getGroupDir('D_RDA','ccr')) {# Search for an OCM software kit if ?${SET.RDA.OCM.F_DISTRIBUTION} var $kit = catFile(last) else {# Look for a distribution kit for the current operating system var %map = ('aix', 'AIX',\ 'dec_osf','OSF1',\ 'hpux', 'HP-UX',\ 'linux', 'Linux',\ 'solaris','SunOS',\ 'MSWin32','Windows') var $plt = getOsName() var $plt = nvl($map{$plt},$plt) loop $fil (grepDir($top,concat('^ccr-Production\-\d+(\.\d+){2,}\-',$plt,\ '(\-.*)?\.zip$'),'i')) {next !?testFile('r',catFile($top,$fil)) if $kit return log('OCM','upgrade','','?',0,-9008,$ttl) var $kit = $fil } } } if $kit {var $log = catFile($ccr,'upgrade.rda') if or(${SET.RDA.OCM.B_UPGRADE_RETRY},\ not(grepFile($log,concat('^',verbatim($kit),'='),'fi'))) {# Perform an OCM upgrade debug ' Inside OCM module, trying OCM software upgrade (can take time)' decr $dur,time() call loadCommand(concat($cmd,' update_components -distribution=',\ catCommand($top,$kit)),false,4) incr $dur,time() var $sta = status() call log('OCM','upgrade','',field('-',2,$kit),$dur,$sta,'',$ttl) # Record the upgrade result call command(concat('echo ',quote($kit),'=',quote($sta), '>>',quote($log))) } } } =head2 S This macro indicates if the current directory is an OCM directory and returns the corresponding OCM command. =cut macro get_ocm_home {var ($ccr,$ttl) = @arg # Validate the context and determine the command path if !and(testDir('d',$ccr),\ testFile(cond(isUnix(),'fx','f'),\ catFile($ccr,'bin',${AS.BATCH:'emCCR'}))) return undef var $cmd = lastCommand() # Try to upgrade the OCM software call do_upgrade($cmd,$ccr,$ttl) # Return the OCM command return $cmd } =head2 S This macro determines the OCM connection mode and generates the corresponding annotation. =cut macro get_ocm_mode {var ($cfg,$tgt) = @arg var $fil = catFile($cfg,'config','collector.properties') var ($lin) = grepFile($fil,'ccr.disconnected','fi') # Determine the annotation (in disconnected mode) if match(value($lin),'true',true) {var $hsh = digest(${RDA.T_NODE},${RDA.T_DOMAIN},$cfg) return (true,join('_','D',$hsh,'RDA',${RDA.N_PID},${RDA.T_TIMESTAMP})) } # Determine the annotation (in connected mode) var ($fil) = grepDir(catDir($cfg,'state','review'),\ concat('-',$tgt,'\.xml'),'i') var ($not) = match($fil,'^([0-9A-Z]+)\-',true) return (false,\ join('_','C',uc(nvl($not,'OCM')),'RDA',${RDA.N_PID},${RDA.T_TIMESTAMP})) } =head2 S This macro returns the values for the C and C environment variables. =cut macro get_wls_config {var ($top) = @arg var $wls = undef loop $dir (grepDir($top,'^wlserver_\d+(\.\d+)+','np')) {if ?testDir('d',$dir) var $wls = $dir } if ?$wls return($top,$wls) return (getEnv('BEA_HOME',$top),getEnv('WL_HOME')) } =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