Create new web server definition websphere

ibm websphere
Below script snippet can be used to create node definition and webserver definition in IBM WAS ND
###############################################################################
#                                                                             #
#                  ---------------------------------                          #
#    		Author: Techpaste(dot)com                                       #
#                                                                             #
#                                                                             #
# Purpose:                                                                    #
#                                                                             #
#    This script is designed to configure the Web server                      #
#    A) Create an unmanaged node definition                                   #
#    B) Create the web server defintion                                       #
#    C) Map the existing application to the web server defintion              #
#                                                                             #
#                                                                             #
###############################################################################

proc configwebserverdef {} {

	puts "****************************************************************"
	puts "--		CREATE-CONFIGURE-MAP WEBSERVER		     --"
	puts "****************************************************************"

	puts "Webserver Configuration started ..."
	puts "--------------------------------------------------------------------"

#--------------------------------------------------------------
# Check if the plugin install location is correct
#--------------------------------------------------------------
	if { (!(($webserverNodeType == "unmanaged") || ($webserverNodeType == "managed"))) } {

	puts " "
	puts "Invalid node type is specified. Using unmanaged as the default."
	# Use unmanaged as the default node type 
	set webserverNodeType unmanaged
	}

#--------------------------------------------------------------
# Compute the cellType
#--------------------------------------------------------------
	puts " "
	puts "Start computing the cell Type."
	if {[catch {set cellID [$AdminConfig list Cell]} result]} {

	puts "Cell ID is not computed, exception = $result"
	return
	} else {
	# Set the cell name
	set cellName [lindex [split $cellID (] 0]
	if {[catch {set cellPropertiesList [$AdminConfig showall $cellID]} result]} {
	puts "Cell properties is not computed, exception = $result"
	return
	} else {
	foreach cellProperty $cellPropertiesList {
	set idx [string first STANDALONE $cellProperty]
	if { ($idx > 0) } {
	puts "StandAlone profile found."
	# Use unmanaged as the default node type 
	set webserverNodeType unmanaged
	# Set the node suffix
	set nodeSuffix _node
	# Set the Web server node name
#	set webserverNodeName $webserverName$nodeSuffix
	break
	}
	}   
	}
	}
	#--------------------------------------------------------------
	# Display the input parameters
	#--------------------------------------------------------------
	puts "---------------------------------------------------------------"
	puts " "
	puts "Input parameters: "
	puts " "
	puts "   Admin Web server Username   - $adminUserID "
	puts "   Web server name             - $webserverName "
	puts "   Web server type             - $webserverType "
	puts "   Web server install location - $webserverInstallLocation "
	puts "   Web server config location  - $webserverConfigLocation "
	puts "   Web server port             - $webserverPort "
	puts "   Map Applications            - $mapApplications "
	puts "   Plugin install location     - $pluginInstallLocation "
	puts "   Web server node type        - $webserverNodeType "
	puts "   Web server node name        - $webserverNodeName "
	puts "---------------------------------------------------------------"


	if { ($webserverNodeType == "unmanaged") } {
	puts "   Web server host name        - $webserverHostName "
	puts "   Web server operating system - $webserverOS "
	}
	#--------------------------------------------------------------
	# Check if the Web server type is valid 
	#--------------------------------------------------------------
	if { (!(($webserverType == "IHS") || ($webserverType == "APACHE") || ($webserverType == "SUNJAVASYSTEM") || ($webserverType == "DOMINO") || ($webserverType == "IIS"))) } {
	   
	puts " "
	puts "Invalid webserver type specified. Using IHS as the default."
	# Use IHS as the default web server type
	set webserverType IHS
	}

	#--------------------------------------------------------------
	# Check if the Web server install location is specified
	#--------------------------------------------------------------
	if { ($webserverInstallLocation == "NULL") } {
	
   	puts " "
  	puts "Web server install location is not specified. Using defaults."
	
   	# Use the default webserver install location
  	set webserverInstallLocation  \"\"   
	}
	#--------------------------------------------------------------
	# Check if the Web server config location is specified
	#--------------------------------------------------------------
	if { ($webserverConfigLocation == "NULL") } {
	
	puts " "
	puts "Web server config location is not specified. Using defaults."
	  
	# Use the default webserver config location
	set webserverConfigLocation  \"\"   
	}


	#--------------------------------------------------------------
	# Check if the Web server node type is unmanaged
	#--------------------------------------------------------------
	if { ($webserverNodeType == "unmanaged") } {
	
	#--------------------------------------------------------------
	# Check if the Web server opertating system is valid 
	#--------------------------------------------------------------
	if { (!(($webserverOS == "windows") || ($webserverOS == "solaris") || ($webserverOS == "aix") || ($webserverOS == "hpux") || ($webserverOS == "linux") || ($webserverOS == "os400")|| ($webserverOS == "os390"))) } {
	   
	puts " "
       puts "Invalid webserver operating system specified. Using windows as the default."
	
	  
       # Use windows as the default operating system
	set webserverOS windows
	}
	
	#--------------------------------------------------------------
	# Check if the webserver node already exists
	#--------------------------------------------------------------
	set webserverNodeID [$AdminConfig getid /Node:$webserverNodeName]
	if { ($webserverNodeID == "") } {
	
       #--------------------------------------------------------------
       # Create the unmanaged Web server node
       #--------------------------------------------------------------
	
       puts " "
       puts "Creating the unmanaged node $webserverNodeName ."
       
       if {[catch {$AdminTask createUnmanagedNode "-nodeName $webserverNodeName -hostName $webserverHostName  -nodeOperatingSystem $webserverOS "} result]} {
	
       puts "Unmanged node $webserverNodeName is not created, exception = $result"
	   
	return
	      
       } else {
	   
       puts "Unmanged node $webserverNodeName is created."
       }
	} else {
	
       puts " "
       puts "Web server node definition $webserverNodeName already exists."
	}
	} else {
	
	#--------------------------------------------------------------
	# Compute the operating system of the managed node
	#--------------------------------------------------------------
	if {[catch {set webserverOS [$AdminTask getMetadataProperty "-nodeName $webserverNodeName -propertyName com.ibm.websphere.nodeOperatingSystem"] } result]} {
	   
	puts " "
       puts "Operating system of the managed node is not computed, exception = $result"
	}
	}
	

	#--------------------------------------------------------------
	# Check if the webserver already exists
	#--------------------------------------------------------------
	set webserverID [$AdminConfig getid /Node:$webserverNodeName/Server:$webserverName]
	if { ($webserverID == "") } {
	
	#--------------------------------------------------------------
	# Create the Web server defintion
	#--------------------------------------------------------------
	   
	puts " "
	puts "Creating the web server definition for $webserverName."
	
	#--------------------------------------------------------------
	# Define other parameters for creating webserver definition
	# Can be changed to suit the current environment
	#--------------------------------------------------------------
	set serviceName    \"\"
	set errorLogfile   \"\"
	set accessLogfile  \"\"   
	set webProtocol    \"\"   
	
	#--------------------------------------------------------------
	# Define other parameters for administering IHS webserver
	# Can be changed to suit the current environment
	#--------------------------------------------------------------
	#set adminPort      \"\"
	#set adminUserID    \"\"
	#set adminPasswd    \"\"   
	set adminProtocol  \"\"      
	 
	#--------------------------------------------------------------
	# Compute webserver steps
	#--------------------------------------------------------------
	set serverConfigStep  "$webserverPort \"$webserverInstallLocation\" \"$pluginInstallLocation\" \"$webserverConfigLocation\" $serviceName $errorLogfile $accessLogfile $webProtocol"
	set remoteServerConfigStep  "$adminPort $adminUserID $adminPasswd $adminProtocol"
	
	if { ($webserverType == "IHS") } {
	   
	puts "Parameters for administering IHS web server should be updated using wsadmin script or admin console."
	
	}
	
	#--------------------------------------------------------------
	# Check if webserver is running on os390
	#--------------------------------------------------------------
	if { (($webserverType == "IHS") && ($webserverOS == "os390")) } {
	      
	# Set the Web server template for os390
	set webserverType IHSZOS
	      
	puts "The template IHSZOS is used for creating the webserver."
	}
	  
	if {[catch {$AdminTask createWebServer $webserverNodeName [subst {-name $webserverName -templateName $webserverType -serverConfig {{ $serverConfigStep }} -remoteServerConfig {{ $remoteServerConfigStep }} } ] } result]} {
	
	puts "Web server definition for $webserverName is not created, exception = $result"
	return
	     
	} else {
	   
	set webserverID [$AdminConfig getid /Node:$webserverNodeName/Server:$webserverName]
	   
	puts "Web server definition for $webserverName is created."
	}
	   
	} else {
	
	puts " "
	puts "Web server definition for $webserverName already exists."
	}
	
	#--------------------------------------------------------------------------
	
	#--------------------------------------------------------------
	# Compute the plugin properties config ID
	#--------------------------------------------------------------
	puts " "
	puts "Start computing the plugin properties ID."
	
	if {[catch {set pluginPropertiesIDList [$AdminConfig list PluginProperties]} result]} {
	
	puts "Plugin properties ID is not computed, exception = $result"
	
	} else {
	   
	set endIndex [string first | $webserverID]
	set webID    [string range $webserverID 0 $endIndex]
	   
	foreach webserverPluginPropertiesID $pluginPropertiesIDList {
	
	set endIndex    [string first | $webserverPluginPropertiesID]
	set pluginWebID [string range $webserverPluginPropertiesID 0 $endIndex]
	
	set idx [string first $pluginWebID $webID]
	if { ($idx > 0) } {
	
	puts "Plugin properties ID is computed."
	break
       }
	}
	}
	
	#--------------------------------------------------------------
	# Set the attribute plugin install root
	#--------------------------------------------------------------
	puts " "
	puts "Start updating the plugin install location."
	
	if {[catch {$AdminConfig modify $webserverPluginPropertiesID "{PluginInstallRoot {$pluginInstallLocation}}"} result]} {
	
	puts "Plugin install location is not updated, exception = $result"
	         
	} else {
	   
	puts "Plugin install location is updated."
	}
	
	#--------------------------------------------------------------
	# Set the attribute plugin log location
	#--------------------------------------------------------------
	puts " "
	puts "Start updating the plugin log file location."
	
	if {[catch {$AdminConfig modify $webserverPluginPropertiesID "{LogFilename {$pluginInstallLocation/logs/$webserverName/http_plugin.log}}"} result]} {
	
	puts "Plugin log file location is not updated, exception = $result"
	         
	} else {
	   
	puts "Plugin log file location is updated."
	}
	
	#--------------------------------------------------------------
	# Save the configuration
	#--------------------------------------------------------------
	puts " "
	puts "Start saving the configuration."
	
	if {[catch {$AdminConfig save} result]} {
	
	puts " "
	puts "Configuration save is not complete, exception = $result"
	         
	} else {
	   
	puts " "
	puts "Configuration save is complete."
	}
	
	#--------------------------------------------------------------
	# Check if applications should be mapped to the Web server
	#--------------------------------------------------------------
	
	if { ($mapApplications == "MAP_NONE") } {
	
	puts " "
	puts "Applications are not mapped to the Web server."
	
	return
	
	} else {
	
	#--------------------------------------------------------------
	# Compute the target name for the Web server
	#-------------------------------------------------------------- 
	set newTarget WebSphere:cell=$cellName,node=$webserverNodeName,server=$webserverName
	
	#--------------------------------------------------------------
	# Get the list of installed application
	#-------------------------------------------------------------- 
	if {[catch {set ApplicationList [$AdminApp list]]} result]} {   
	puts " "
       puts "Unable to compute the list of installed applications, exception = $result"
	       
	return
         
	} else {
	   
	puts " "
       puts "Computed the list of installed applications."
	}
	   	
	#--------------------------------------------------------------
	# Looping through all the applications
	#--------------------------------------------------------------    
	foreach Application $ApplicationList {
	
       #--------------------------------------------------------------
       # Remove end of list character if it exists
       #--------------------------------------------------------------
       set lastListChar "]"
       set lastListCharIndex [string first $lastListChar $Application]
       if { ($lastListCharIndex > 0) } {
	set Application [string range $Application 0 [expr $lastListCharIndex - 1] ]
       }
       
       #--------------------------------------------------------------
       # Check if the end of list has reached
       #--------------------------------------------------------------
       if { (!($Application == "]")) }  {
	
	puts " "       
	puts "Processing the application $Application."
	
	if { (($mapApplications == "MAP_ALL") || (($mapApplications == "MAP_DEFAULT") && ($Application == "DefaultApplication"))) }  {
	    
	puts "Get the current target mapping for the application $Application."
	
	#--------------------------------------------------------------
	# Get the current target mapping
	#--------------------------------------------------------------
	if {[catch {set MapModulesResultList [$AdminApp view $Application "-MapModulesToServers"]} result]} {   
	
	puts "Unable to compute the current target mapping for the application $Application, exception = $result"
	
	} else {
	   
	puts "Computed the current target mapping for the application $Application."
	            
	#--------------------------------------------------------------
	# Initialize the result entries
	#--------------------------------------------------------------
	set moduleEntry false               
	set uriEntry false
	set serverEntry false
	set firstColonHit false
	
	set moduleName    ""
	set targetMapList ""
	           
	#--------------------------------------------------------------
	# Loop through the all the mapped modules
	#--------------------------------------------------------------
	foreach resultEntry $MapModulesResultList {
	
	#--------------------------------------------------------------
	# Check if the moduleEntry list is over
	#--------------------------------------------------------------
	if { ($resultEntry == "URI:") }  {
	
	set moduleEntry false
	}
	
       #--------------------------------------------------------------
       # Check if the previousEntry is module
       #--------------------------------------------------------------
	if { ($moduleEntry == "true") }  {
	                 
	set moduleName "$moduleName$resultEntry "
	
	#--------------------------------------------------------------
	#Check if the previousEntry is URI
	#--------------------------------------------------------------
	} elseif  { ($uriEntry == "true") }  {
	               
	set moduleUri $resultEntry
	
	#--------------------------------------------------------------
	# Check if the previousEntry is serverEntry
	#--------------------------------------------------------------
	} elseif { ($serverEntry == "true") }  {
	               
	set currentTargets $resultEntry
	
	#--------------------------------------------------------------
	# Check if web server is already defined as the target
	#--------------------------------------------------------------
	set index [string first $newTarget $currentTargets]
	if {($index > 0) } {
	set targetMapList "$targetMapList { {$moduleName} $moduleUri $currentTargets }"
	} else {
	set targetMapList "$targetMapList { {$moduleName} $moduleUri $currentTargets+$newTarget }"                  
	}
	                     
	#--------------------------------------------------------------
	# Initialize the result entries
	#--------------------------------------------------------------
	set serverEntry false
	set moduleName    ""
	}
	
	#--------------------------------------------------------------
	# Check if the current result entry is URI
	#--------------------------------------------------------------
	if { ($resultEntry == "URI:") }  {
	set uriEntry true
	set moduleEntry false
	set serverEntry false
	} else {
	set uriEntry false
	                           
	#--------------------------------------------------------------
	# Skip the token MapModulesToServers:
	#--------------------------------------------------------------
	if { ($resultEntry != "MapModulesToServers:") }  {
	                          
	#--------------------------------------------------------------
	# Skip the token WebSphere:
	#--------------------------------------------------------------
	set index [string first WebSphere: $resultEntry]
	if {($index < 0) } {
	#--------------------------------------------------------------
	# Check if the result entry has : 
	#--------------------------------------------------------------
	set index [string first : $resultEntry]
	if {($index > 0) } {
	if { ($firstColonHit == "false") }  {
	
	#--------------------------------------------------------------
	# Current result entry is module
	#--------------------------------------------------------------
	set moduleEntry true
	set serverEntry false
	set firstColonHit true
	
	} else {
	
	#--------------------------------------------------------------
	# Current result entry is server
	#--------------------------------------------------------------
	set serverEntry true
	set moduleEntry false                   
	set firstColonHit false
	}
	} 
	}
	}
	}
	}
	#--------------------------------------------------------------
	# Compute the revised targetMapping
	#--------------------------------------------------------------         
	
	#--------------------------------------------------------------
	#  Update the target mapping for each application
	#--------------------------------------------------------------
	puts "Start updating the target mappings for the application $Application."
	
	if {[catch {$AdminApp edit $Application [subst {-MapModulesToServers { $targetMapList } } ]} result]} {
	puts "Target mapping is not updated for the application $Application, exception = $result"
	} else {
	puts "Target mapping is updated for the application $Application."
	}
	#--------------------------------------------------------------
	#  Check if only default application is to be mapped
	#--------------------------------------------------------------
	if { ($mapApplications == "MAP_DEFAULT") }  {
	# No need to process further
	break
	}
	}           
	}
	}
	}
	}
	#--------------------------------------------------------------
	# Save the configuration
	#--------------------------------------------------------------
	puts " "
	puts "Start saving the configuration."
	
	if {[catch {$AdminConfig save} result]} {
	
	puts " "
	puts "Configuration save is not complete, exception = $result"
	         
	} else {
	   
	puts " "
	puts "Configuration save is complete."
	}
	#-----------------------------------------------------------------------
	#End of Procedure
	#-----------------------------------------------------------------------
	}
	#########################################################################

In case of any ┬ęCopyright or missing credits issue please check CopyRights page for faster resolutions.

Leave a Reply