#!/bin/sh
# =====================================================================         
# PROPRIETARY-STATEMENT:                                                        
# Licensed Material - Property of IBM                                           
#                                                                               
# 5724-I63, 5724-H88, 5655-N01, 5733-W61                                        
# (C) Copyright IBM Corp. 1999, 2013                                            
# All Rights Reserved                                                           
# US Government Users Restricted Rights - Use, duplication or                   
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.             
# =====================================================================         
<!-- import documents/data/buildInfo.script -->
# =====================================================================        
#                                                                               
# Federates a managed node into a Network Deployment cell                    
#                                                                              
# =====================================================================        
<!--  Change Activity:                                                -->         
<!--                                                                  -->         
<!-- 739067    V8.5.5  20121113 PDOP: Initial version                 -->
<!-- ================================================================ -->

# Gets path of working directory
workDirPath=$(dirname "$0")
echo "Work directory path is $workDirPath"
<!-- if (${zNodeGroupName} != DefaultNodeGroup) -->

# Invokes script to create the node group
echo 'Creating node group ${zNodeGroupName}'
'${zConfigMountPoint}/${zWasServerDir}/bin/wsadmin.sh' \                                                            
  -host ${zFederateDmaNodeHostName} \                                                          
  -port ${zFederateDmaPort} \                                                           
  -conntype ${zFederateDmaPortType} \
<!-- if (${zFederateDmaSecurity} == true) -->
  -username ${zFederateDmaSecurityUserID} \                                                       
  -password ${zFederateDmaSecurityPassword} \                                                       
<!-- endif -->
  -f "$workDirPath/createNodeGroup.jacl" ${zNodeGroupName}                                         
rc="$?"

# Exits if an error occurred creating the node group
if [ "$rc" -ne 0 ]; then
	echo 'Unable to create node group ${zNodeGroupName}'
    exit "$rc"
fi
<!-- endif -->

# Invokes script to add the node to the target cell
echo 'Adding the managed node to the target cell'
${zConfigMountPoint}/${zWasServerDir}/bin/addNode.sh \                                                            
  ${zFederateDmaNodeHostName} \                                                                 
  ${zFederateDmaPort} \                                                                  
<!-- if (${zFederateDmaSecurity} == true) -->
  -username ${zFederateDmaSecurityUserID} \                                                        
  -password ${zFederateDmaSecurityPassword} \                                                        
<!-- endif -->
<!-- if (${zFederateDmaPortType} == RMI) -->
  -conntype RMI \
<!-- endif -->
<!-- if (${zFederateNodeAgentAfterFederation} == false) -->
  -noagent \                                                                   
<!-- endif -->
  -nodegroupname ${zNodeGroupName} \                                                  
  -nodeagentshortname ${zFederateServerShortName} \                                             
  -portprops "$workDirPath/portFile.props"                                  
rc="$?"

# Exits if the node federation failed
if [ "$rc" -ne 0 ]; then
	echo 'Unable to add the managed node to the target cell'
    exit "$rc"
fi

echo 'Managed node successfully added to the target cell'
exit 0
                                                                              
