5 Server Templates

This chapter describes server templates.

This chapter includes the following sections:

What Are Server Templates and Why Use Them?

Server templates enable you to define common, nondefault attributes that you can apply to different server instances. Because common attributes are located in the server template, you only need to change the attribute in one place and they take effect in all of the server instances that use the server template. You use server templates in a heterogeneous server environment where server instances have a common set of attributes but also a set of server-specific attributes that must be unique for each server instance.

The primary use for server templates is for creating dynamic clusters. See "Creating Dynamic Clusters" in Administering Clusters for Oracle WebLogic Server.

Configuring Server Templates

This section describes how to configure server templates.

For information about creating server templates using the Administration Console, see "Create server templates" in the Oracle WebLogic Server Administration Console Online Help.

Specifying Common Attributes in a Server Template

When you define a server template, you specify the common attributes for a group of server instances. For each server instance, you then specify the server template upon which to base the server configuration. If needed, you can override any attribute value that you defined in the server template directly in the server instance.

WebLogic Server determines the attribute value as follows:

  • The default value for a configuration element attribute will be returned unless it is overridden either in the server template or in the individual server configuration.

  • Values set in the server template override default values, so if the value is set in the server template, then that value will be returned.

  • Values set in the individual server configuration override default values and values set in the server template. If a value is set in the individual server configuration element, then that value will be returned.

Note:

After you set a value at the individual server level, this value will not be overridden even if you set it back to what is in the server template. To remove this value from the individual server level, use the unSet attribute command.

Using Macros in Server Templates

You can define a macro for any string attribute in a server template. Macros cannot be used for integers or references to other configuration elements. The valid macros available for use in server templates are:

  • ${id}: Instance ID of the dynamically created server; this ID starts at 1

  • ${serverName}: The name of the server to which this element belongs

  • ${clusterName}: The name of the cluster to which this element belongs

  • ${domainName}: The name of the domain to which this element belongs

  • ${system-property-name}: If this is not one of the predefined macro names listed previously, then it will be evaluated as a system property, and the value will be returned. If the system property does not exist, then an empty string will be substituted.

Using Server Templates Example

This section describes how to create two server instances with common attributes using a server template:

  1. Create a server template and name it my-cluster-server-template.

  2. Set all of the common attributes in my-cluster-server-template.

  3. Create server instances my-server1 and my-server2, and assign the my-cluster-server-template to each one.

  4. Set your server specific attributes.

The following example demonstrates using WebLogic Scripting Tool (WLST) to create two server instances with a server template. The example includes inline comments.

#
# This example demonstrates the WLST commands needed to create a server template
# (my-cluster-server-template) and server instances (my-server-1, my-server-2)
# that use that server template. The creation of the cluster (my-cluster) and
# machines (PrimaryMachine, SecondaryMachine) are not included in this example; 
# they must have been created before running this script. To keep this example 
# simple, error handling was omitted.
#
connect()
edit()
startEdit()
#
# Create the server template and set the common attributes that are used in all
# servers. Attributes such as Accept Backlog, Auto Restart, etc. are the same
# across all cluster members.
#
serverTemplate=cmo.createServerTemplate("my-cluster-server-template")
serverTemplate.setAcceptBacklog(2000)
serverTemplate.setAutoRestart(true)
serverTemplate.setRestartMax(10)
serverTemplate.setReverseDNSAllowed(true)
serverTemplate.setStagingMode("external_stage")
serverTemplate.setStartupTimeout(600)
myCluster=cmo.lookupCluster("my-cluster")
serverTemplate.setCluster(myCluster)
#
# Create the individual server instances, set the server specific attributes, and
# set the template so the server uses the common attributes from the template.  
# Attributes such as cluster weight, listen port, and machine are server-specific
# so they are not included in the server template.
#
server1=cmo.createServer("my-server-1")
server1.setClusterWeight(70)
server1.setListenPort(7010)
primary=cmo.lookupMachine("PrimaryMachine")
server1.setMachine(primary)
server1.setServerTemplate(serverTemplate)
#
server2=cmo.createServer("my-server-2")
server2.setClusterWeight(90)
server2.setListenPort(7020)
secondary=cmo.lookupMachine("SecondaryMachine")
server2.setMachine(secondary)
server2.setServerTemplate(serverTemplate)
#
# activate the changes
#
activate()

The resulting config.xml file is:

<server>
    <name>my-server-1</name>
     <cluster-weight>70</cluster-weight>
     <listen-port>7010</listen-port>
     <machine>PrimaryMachine</machine>
     <server-template>my-cluster-server-template</server-template>
</server>

<server>
     <name>my-server-2</name>
     <cluster-weight>90</cluster-weight>
     <listen-port>7020</listen-port>
     <machine>SecondaryMachine</machine>
     <server-template>my-cluster-server-template</server-template>
</server>

<server-template>
     <name>my-cluster-server-template</name>
     <accept-backlog>2000</accept-backlog>
     <auto-restart>true</auto-restart>
     <cluster>my-cluster</cluster>
     <restart-max>10</restart-max>
     <reverse-dns-allowed>true</reverse-dns-allowed>
     <staging-mode>external_stage</staging-mode>
     <startup-timeout>600</startup-timeout>
</server-template>