# SCcloud.ctl: Start Scenario for Remote Data Collection in a Cluster # $Id: SCcloud.ctl,v 1.9 2013/10/30 07:18:24 RDA Exp $ # ARCS: $Header: /home/cvs/cvs/RDA_8/src/scripting/lib/collect/DB/SCcloud.ctl,v 1.9 2013/10/30 07:18:24 RDA Exp $ # # Change History # 20130820 MSC Replace CONTEXT by CONFIG. =head1 NAME SCcloud - Performs Initialization for Remote Data Collection in a Cluster =cut use Buffer,Remote =head1 START SECTION This start script initializes the remote data collection for a cluster. You can specify a user as an argument to get the cluster nodes from the database. The following user formats are supported: =over 14 =item B< user> To connect with the user in the database referenced by the C environment variable. =item B< user@SID> To connect with the user in the specified database. =item B< /> To connect as C to the database referenced by the C environment variable. =item B< /@SID> To connect as C to the specified database. =back Using C requires appropriate privileges. It deduces the related Oracle home and system identifier (SID) respectively from the C or C environment variables unless specified with the options C<-h> or C<-s>. If the user is not specified, the command uses an operating system command (C or C) to get the cluster nodes. In that case, the RDA collection must be initiated from one of the cluster nodes. You can also use the option C<-n> to specify the remote nodes as a comma-separated list. It gets the list of all nodes belonging to a cluster, gathers the related setup information (such as Oracle home and SID), and generates the corresponding setup files. The start script accepts an alternate list of remote profiles through the option C<-p>. =cut options 'h:n*p*s:' section start # Initialisation var $ORACLE_HOME = nvl($opt{'h'},${ENV.ORACLE_HOME}) var $ORACLE_SID = nvl($opt{'s'},${ENV.ORACLE_SID}) var $GRP = ['RDA'] var $SEP = ${RDA.T_LINE} var @tb_nod var @tb_sid var %set # Restrict its usage for UNIX and Cygwin if !or(isUnix(),isCygwin()) {echo 'Only UNIX platforms are currently supported' die 'Cluster data collection setup aborted' } # Define a macro to get the cleaned path of a peer directory macro getPeer {var ($dir,@sub) = @arg return cleanPath(catDir($dir,upDir(),@sub),true) } # Define a macro to indicate whether the collection is local macro is_local {var ($nod) = @arg loop $loc (${RDA.T_NODE},${RDA.T_HOST},'localhost','127.0.0.1') {if compare('eq',$nod,$loc) return 1 } return 0 } # Define the macros to get the nodes names macro get_db {var ($usr) = @arg var $cnt = 0 import @tb_nod,@tb_sid if $usr {debug 'In CRS start scenario, getting nodes using gv$instance' set $sql {SELECT instance_name || '|' || host_name " FROM gv$instance " ORDER BY thread#; } if loadSql($sql) {if grepLastSql('^(ORA|SP2)-\d{4,}:') return 0 loop $lin (grepLastSql('\|')) {incr $cnt var ($tb_sid[$cnt],$tb_nod[$cnt]) = split('\|',$lin,2) } } } return $cnt } macro get_nodes {var ($cmd) = @arg var $cnt = 0 import @tb_nod if loadCommand($cmd) {debug 'In CRS start scenario, getting nodes using ',$cmd loop $nod (getLines()) {incr $cnt var $tb_nod[$cnt] = $nod } } return $cnt } # Define the input and profile targets debug " Inside DFT scenario, define the input and profile targets" loop $tgt ($[COL]->get_targets) call defineTarget($tgt) # Check Oracle home or Middleware presence debug " Inside DFT scenario, check Oracle home or Middleware presence" var $top = getPeer(${AUX._.CONFIG.D_HOME}) var $par = getPeer($top) if ?nvl(testDir('d',$hom = getPeer($par,'oracle_common','ccr')),\ testDir('d',$hom = getPeer($par,'utils','ccr'))) var $tgt = defineTarget('MH',{D_MW_HOME=>getNativePath($par),\ T_TITLE =>'Middleware home'}) elsif ?nvl(testDir('d',$hom = getPeer($top,'oracle_common','ccr')),\ testDir('d',$hom = getPeer($top,'utils','ccr'))) var $tgt = defineTarget('MH',{D_MW_HOME=>getNativePath($top),\ T_TITLE =>'Middleware home'}) elsif ?nvl(testDir('d',catDir($top,'inventory')),\ testDir('d',catDir($top,'ccr'))) var $tgt = defineTarget('OH',{D_ORACLE_HOME=>getNativePath($top),\ T_TITLE =>'Software Oracle home'}) call $tgt->set_value('B_IPS',true,'IPS indicator') # Trigger a minimal setup var ${SET.RDA.LOAD.B_NO_LOAD/T} = true call $[COL]->add_setup(['RDA'],false,false,'RDA:DCend') call $[COL]->end_setup # Determine if the node list can be get from the database if ?$arg[0] {var $usr = last # Check ORACLE_HOME if !?testDir('d',$ORACLE_HOME) {echo 'ORACLE_HOME is not set in environment. Set it and try again.' die 'Cluster data collection setup aborted' } # Determine the user to connect to the database if match($usr,'^/$') {if $ORACLE_SID {call setSqlTarget({B_LOCAL =>true,\ B_SYSDBA =>true,\ D_ORACLE_HOME=>$ORACLE_HOME,\ T_ORACLE_HOME=>$ORACLE_HOME,\ T_ORACLE_SID =>$ORACLE_SID,\ T_USER =>$usr}) call ${RUN.REQUEST.T_USER} = '/' call ${RUN.REQUEST.B_SYSDBA} = true } else {echo 'ORACLE_SID is not set in environment. Set it and try again.' die 'Cluster data collection setup aborted' } } elsif match($usr,'^/(@.*)$') {call setSqlTarget({B_SYSDBA =>true,\ T_ORACLE_SID =>$ORACLE_SID,\ T_USER =>$usr}) call ${RUN.REQUEST.T_USER} = '/' call ${RUN.REQUEST.B_SYSDBA} = true } elsif match($usr,'/') {echo 'Invalid oracle user' die 'Cluster data collection setup aborted' } elsif match($usr,'^(.*)@') {var ($str) = (last) call setSqlTarget({T_ORACLE_SID =>$ORACLE_SID,\ T_USER =>$usr}) call ${RUN.REQUEST.T_USER} = uc($str) call ${RUN.REQUEST.B_SYSDBA} = false } else {if $ORACLE_SID {call setSqlTarget({B_LOCAL =>true,\ D_ORACLE_HOME=>$ORACLE_HOME,\ T_ORACLE_HOME=>$ORACLE_HOME,\ T_ORACLE_SID =>$ORACLE_SID,\ T_USER =>$usr}) call ${RUN.REQUEST.T_USER} = uc($usr) call ${RUN.REQUEST.B_SYSDBA} = false } else {echo 'ORACLE_SID is not set in environment. Set it and try again.' die 'Cluster data collection setup aborted' } } } else {var $usr = undef if ${DFT.B_NO_DIALOG} {call ${RUN.REQUEST.T_DFT_USER} = '/' call ${RUN.REQUEST.B_DFT_SYSDBA} = true } } # Get the node list if get_db($usr) var ($cnt,$typ) = (last,'db') else {# Determine CRS_HOME home var $CRS_HOME if ${SET.DB.CRS.D_CRS_HOME} var $CRS_HOME = last else run DB:CRSinit(\$CRS_HOME) if ?testDir('d',$CRS_HOME) var $cmd = concat(catCommand($CRS_HOME = last,'bin','olsnodes'),\ ' 2>/dev/null') else var $cmd = '' # Get the node list using operating system commands if exists($opt{'n'}) {var ($cnt,$typ) = (0,'os') loop $nod (@{$opt{'n'}}) {next !?isHost($nod,true) var $tb_nod[incr($cnt)] = last } if !$cnt {echo 'No valid cluster nodes specified' die 'Cluster data collection setup aborted' } } elsif get_nodes($cmd) var ($cnt,$typ) = (last,'os') elsif get_nodes('lsnodes 2>/dev/null') var ($cnt,$typ) = (last,'os') else {echo 'No cluster nodes found' die 'Cluster data collection setup aborted' } } # Align the remote environments on the local one var ${RUN.REQUEST.W_PHASE} = \ cond($spl = not(sameDir(${CFG.D_CWD},${CFG.D_RDA})),'split','common') # Get the common information echo $SEP echo 'Requesting common cluster information' echo $SEP if ${COL.REMOTE.T_USER} {call ${RUN.REQUEST.B_ALT_LOGIN/T} = true call ${RUN.REQUEST.T_OS_LOGIN/T} = last } var @prf = () if exists($opt{'p'}) {loop $prf (@{$opt{'p'}}) {if match($prf,'^((\w+\.)?\w+)$') call push(@prf,first) } } if @prf var @{RUN.REQUEST.W_PROFILE} = last if match(${COL.REMOTE.T_RDA_OPTIONS},\ '-[SRP]*p\s*((\w+\.)?\w+(,(\w+\.)?\w+)*)\b') var @{RUN.REQUEST.W_PROFILE} = split(',',last) call requestInput('DB:SCcloud') if ${RUN.REQUEST.T_OS_LOGIN} var ${COL.REMOTE.T_USER/T} = last else var ${COL.REMOTE.T_USER/T} = undef var $prf = ${RUN.REQUEST.W_PROFILE/VC} var $set{'D_HOME'} = ${RUN.REQUEST.T_RDA_HOME} var $set{'D_WORK'} = ${RUN.REQUEST.T_RDA_WORK} var $set{'T_USER'} = ${RUN.REQUEST.T_USER} var $set{'B_SYSDBA'} = ${RUN.REQUEST.B_SYSDBA:0} # Ping each nonlocal node. Any bad connect sets CLUSTER_UP to "N" var $hom = ${SET.RDA.BEGIN.D_ORACLE_HOME:${ENV.ORACLE_HOME}} var $dwn = 0 for $cur (1,$cnt) {var $nod = $tb_nod[$cur] if is_local($nod) {debug 'In CRS start scenario, getting local node information' if missing($tb_sid[$cur]) var $tb_sid[$cur] = nvl(${SET.DB.DB.I_BD/I}->get_first('T_ORACLE_SID'),\ ${ENV.ORACLE_SID}) } else {debug 'In CRS start scenario, pinging node ',$nod var $ses = addRemoteSession('CLOUD',$nod,${COL.REMOTE.T_USER}) if rexec('CLOUD','env',true) {var $tb_sta[$cur] = 'DOWN or INACCESSIBLE' incr $dwn } elsif missing($tb_sid[$cur]) {var $buf = $ses->get_input if $buf->grep('^ORACLE_SID=') var $tb_sid[$cur] = value(last) call $buf->close } call endRemoteSession('CLOUD') } } # Get association between each node and database sid var @tbl = () var ${RUN.REQUEST.W_PHASE} = $typ for $cur (1,$cnt) {var $uid = sprintf('NOD%03d',$cur) var $nod = $tb_nod[$cur] # Determine the contributing groups var @grp = ('COMMON',cond(is_local($nod),'LOCAL','REMOTE')) if expr('==',$cur,1) call push(@grp,'FIRST') if expr('==',$cur,$cnt) call push(@grp,'LAST') # Request or verify the ORACLE_HOME and ORACLE_SID of the remote node echo $SEP echo 'Requesting information for node ',$nod echo $SEP var ${RUN.REQUEST.T_ORACLE_HOME} = $hom if $tb_sid[$cur] var ${RUN.REQUEST.T_ORACLE_SID} = last else var ${RUN.REQUEST.T_ORACLE_SID} = undef var ${RUN.REQUEST.T_GROUP} = ${RUN.REQUEST.T_HOSTNAME} = $nod var ${RUN.REQUEST.W_GROUP} = $uid call requestInput('DB:SCcloud') var $hom = ${RUN.REQUEST.T_ORACLE_HOME} var $tb_sid[$cur] = ${RUN.REQUEST.T_ORACLE_SID} # Generate the corresponding setup file call genRemoteSetup($uid,'CLOUD',\ {CONFIG => {D_HOME => $set{'D_HOME'},\ D_WORK => $set{'D_WORK'},\ T_NODE => $nod},\ FILTER => 'FILTER',\ OUTPUT => {B_CLEAN => true},\ PACKAGE => {W_NAME => concat('RDA_',lc($uid),'_',${CUR.W_COLLECTOR})},\ SETUP => [@grp,$uid],\ 'TARGET.OH.OH_T0001' => {D_ORACLE_HOME => $hom,\ T_ORACLE_HOME => $hom,\ T_TITLE => 'RAC database Oracle home',\ W_CLASS => 'OH'},\ 'TARGET.DB.DB_T0001' => {B_PFILE_LOCAL => true,\ I_ORACLE_HOME => '[TARGET.OH.OH_T0001]',\ T_ORACLE_SID => $tb_sid[$cur],\ T_TITLE => 'RAC database',\ W_CLASS => 'DB'},\ 'TARGET.SQ.SQ_T0001' => {B_LOCAL => true,\ B_SYSDBA => $set{'B_SYSDBA'},\ I_DATABASE => '[TARGET.DB.DB_T0001]',\ T_ORACLE_SID => $tb_sid[$cur],\ T_TITLE => 'RAC database queries',\ T_USER => $set{'T_USER'},\ W_CLASS => 'SQ'},\ 'SETUP.RDA.BEGIN' => {D_ORACLE_HOME => $hom,\ T_ORACLE_HOME => $hom},\ 'SETUP.DB.DB' => {B_IN_USE => true,\ I_DB => '[TARGET.SQ.SQ_T0001]'}}) var ${<'COL/REMOTE',$uid,'B_SPLIT'>/T} = $spl var ${<'COL/REMOTE',$uid,'T_DESCRIPTION'>/T} = concat('Cluster node ',$nod) var ${<'COL/REMOTE',$uid,'T_HOME'>/T} = $set{'D_HOME'} var ${<'COL/REMOTE',$uid,'T_HOSTNAME'>/T} = $nod var ${<'COL/REMOTE',$uid,'T_STEP'>/T} = 'N' var ${<'COL/REMOTE',$uid,'T_WORK'>/T} = $set{'D_WORK'} call push(@tbl,$uid) } var @{COL.REMOTE.W_NODES/T} = @tbl var ${COL.REMOTE.T_RDA_OPTIONS/T} = concat('-vyXRda collect -SRPp',$prf) var ${COL.REMOTE.N_TIMEOUT/T} = 0 # Set up the remote data collection module var ${COL.REMOTE.B_COLLECTED/T} = true call $[COL]->add_setup($GRP, true, false, 'RDA:DCstatus') call $[COL]->end_setup() var $yes = $[COL]->set_isolated(true) var ${COL.REMOTE.B_DEFINED/T} = true call $[COL]->add_setup($GRP, true, false, 'RDA:DCload') call $[COL]->add_setup($GRP, true, true, 'RDA:DCremote') call $[COL]->end_setup() call $[COL]->set_isolated($yes) # Print the setup summary echo $SEP echo 'RAC Setup Summary' echo $SEP echo 'Nodes:' for $cur (1,$cnt) {var $uid = sprintf('NOD%03d',$cur) if $tb_sta[$cur] dump '* ',$uid,' ',$tb_nod[$cur],'/',$tb_sid[$cur],' (Node ',last,')' else dump '. ',$uid,' ',$tb_nod[$cur],'/',$tb_sid[$cur] } if $dwn echo $cnt,' nodes found (',$dwn,' down)' else echo $cnt,' nodes found' if !$spl {call command(join(' ',@{RDA.T_SELF},'-XRda check -R')) if status() echo tput('reverse'),\ 'Note: File alterations should be allowed to perform the collection',\ tput('off') } =head1 REFRESH SECTION Refresh the collector definition. =cut section refresh =head1 SEE ALSO L =begin credits =over 10 =item RDA 4.2: Roger Snowden. =item RDA 4.5: Bob Caldwell. =item RDA 8.0: Jamie Alcoreza. =back =end credits =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