InfoCenter Home >
6: Administer applications >
6.6: Tools and resources quick reference >
6.6.0: About user assistance >
6.6.0.2: Command line administration >
6.6.0.2.2: WebSphere Control Program (wscp) >
6.6.0.2.2.4: Example wscp commands, procedures, and scripts >
6.6.0.2.2.4.2: Configuring objects

6.6.0.2.2.4.2: Configuring objects

The following examples demonstrate how to create and modify objects using the wscp interface:


Creating an object

The wscp create operation creates an object instance. The syntax is as follows:

object_type create object_name -attribute attr_list

The arguments are as follows:

  • object_type. Specifies the object type of the instance.

  • object_name. Specifies the object instance to be created.

  • -attribute attr_list. Specifies a Tcl list of attribute-value pairs to set.

The following interactive wscp command creates an application server. The object_type argument (ApplicationServer) specifies that an application server object is to be operated on. The operation argument (create) specifies that an object is to be created. The object_name argument (/Node:dev-pc/ApplicationServer:myServer/) is the name of the server object to be created.

wscp> ApplicationServer create /Node:dev-pc/ApplicationServer:myServer/

The following wscp command creates a DataSource object named ds1.

wscp> DataSource create /JDBCDriver:Db2Jdbc/DataSource:ds1/

You must specify the name of the desired JDBC provider when creating a data source -- in this case, the driver /JDBCDriver:Db2Jdbc/


Working with the default values of attributes

An object type's attributes can have default values. When you create an object instance, the instance inherits any default values (unless you explicit set them in the create operation). For example, the SecurityEnabled attribute of an ApplicationServer object has a default value of False. Some attributes have a default value of null or the empty list--for example, the value of the Environment attribute of ApplicationServer objects defaults to the empty list.

The defaults operation is used to view the default values for attributes. (All object types support the defaults operation with the exception of the ServerGroup object type.) The syntax is as follows:

<object_type> defaults  [-all] [-attribute <attribute list>]

If you do not specify any options, the defaults operation displays the default values for attributes of the specified object type. The following example displays the default values for attributes of the DataSource object type. Note that, while other attributes exist for this object type, the defaults operation displays only those attributes that have default values.

wscp> DataSource defaults
{Description {}} {ConfigProperties {}} {ConnTimeout 180}
{DefaultPassword {}} {DefaultUser {}} {DisableAutoConnectionCleanup
False} {IdleTimeout 1800} {JNDIName {}} {MaxPoolSize 10} {MinPoolSize
1} {OrphanTimeout 1800} {StatementCacheSize 100}

The -all option displays all attributes (those that have default values as well as those that are not set). The following example displays all attributes of the DataSource object type. Even though unset attributes do not have an initial setting, they are displayed as having the string value AttributeNotSet.

wscp> DataSource defaults -all
{Name AttributeNotSet} {FullName AttributeNotSet} {Description {}}
{ConfigProperties {}} {ConnTimeout 180} {DatabaseName AttributeNotSet}
{DefaultPassword {}} {DefaultUser {}} {DisableAutoConnectionCleanup
False} {IdleTimeout 1800} {JNDIName {}} {MaxPoolSize 10} {MinPoolSize
1} {OrphanTimeout 1800} {StatementCacheSize 100}

The -attribute option is used to display the default value for one or more specified attributes. Its argument must be a Tcl list. If the specified attribute has a default value, the value is displayed. The following example displays the default values of the MinPoolSize and MaxPoolSize attributes of DataSource objects:

wscp> DataSource defaults -attribute {MaxPoolSize MinPoolSize}
{MaxPoolSize 10} {MinPoolSize 1}

Modifying an object

The wscp modify operation sets the value of one or more attributes. If a value already exists for an attribute, that value is replaced. The syntax is as follows:

object_type modify  object_name -attribute  attr_list

The arguments are as follows:

  • object_type. Specifies the object type of the instance.

  • object_name. Specifies the object instance whose attributes are to be modified.

  • -attribute attr_list. Specifies a Tcl list of attribute-value pairs to set.

The following example shows how to modify the value of the PingInterval attribute of an application server:

wscp> ApplicationServer show /Node:dev-pc/ApplicationServer:myServer/  \
-attribute PingInterval

{PingInterval 60}
wscp> ApplicationServer modify /Node:dev-pc/ApplicationServer:myServer/ \
-attribute {{PingInterval 120}}
wscp> ApplicationServer show /Node:dev-pc/ApplicationServer:myServer/  \
-attribute PingInterval
{PingInterval 120}

Modifying an Environment attribute (modEnv procedure)

The following Tcl procedure, modEnv, can be used to modify the Environment attribute of one or more application servers in a domain. The value of the Environment attribute is a list of strings of the form name=value. This procedure modifies a specified element of the list (or adds the element if it is not present) and retains the values of the other elements. The procedure takes three arguments: a server name, an environment variable name, and the value to which the variable is to be set.

The procedure does the following:

  1. Sets a Tcl variable named oldEnv to the existing value of the Environment attribute.

  2. Searches the variable names in oldEnv for the variable name supplied as an argument to the command. If the supplied variable name is not in oldEnv, the procedure appends the supplied variable and value to oldEnv in the form name=value, and sets the variable newEnv to the value of oldEnv. If the supplied variable name is in oldEnv, the procedure replaces the variable's value with the supplied value and sets newEnv to the value of oldEnv.

  3. Modifies the server's Environment attribute so that it is equal to the value of newEnv.
#
# modEnv - procedure for modifying the Environment attribute of one or
# more application servers in a domain.  The specified environment variable
# is modified (or added if it is not present), and the values of other
# variables are retained.
#
# Arguments:
#
# server - the fully qualified name of the application server whose
# Environment attribute is to be modified.
#
# variable - the name of the environment variable to modify.
#
# value - the new value of the environment variable.
#
# To modify the Environment attribute of multiple servers, use
# the Tcl foreach command, for example
# wscp> foreach server [ApplicationServer list] {modEnv $server TEST_VARIABLE 3.5}
#
# The file init.tcl must be loaded prior to using this procedure.


proc modEnv {server variable value} {
set oldEnv {}
getAttrs $server attr Environment
if {[info exists attr(Environment)]} {set oldEnv $attr(Environment)}
# append to environment if not found; replace if it is found
set i [lsearch -regexp $oldEnv ^$variable=]
if {$i == -1} {
set newEnv [lappend oldEnv "$variable=$value"]
} else {
set newEnv [lreplace $oldEnv $i $i "$variable=$value"]
}
set attr(Environment) $newEnv
setAttrs $server attr
}
modEnv


The following example shows the use of the modEnv procedure to modify the value of the PATH variable in two application servers in a domain (or to add the PATH variable if it does not exist). The existing value of the Environment attribute of each server is as follows:

wscp> ApplicationServer show $serv1 -attribute {Environment}
{Environment PATH=/myPath}
wscp> ApplicationServer show $serv2 -attribute {Environment}
{Environment {{OTHERVARIABLE=word1 word2}}}

The following calls to the modEnv procedure modify each Environment attribute. The resulting change is shown for the two example servers:

wscp> modEnv $serv1 PATH /revisedPath
wscp> ApplicationServer show $serv1 -attribute {Environment}
{Environment PATH=/revisedPath}
wscp> modEnv $serv2 PATH /revisedPath
wscp> ApplicationServer show $serv2 -attribute {Environment}
{Environment {{OTHERVARIABLE=word1 word2} PATH=/revisedPath}}

The modEnv procedure can be used to change the Environment attribute of multiple servers of the same type. In the following example, the Tcl foreach command is used to call the modEnv procedure on each ApplicationServer instance in a domain. The value TEST_VARIABLE=1 is added (or appended) to the attribute as needed.

wscp> foreach server [ApplicationServer list] {modEnv $server TEST_VARIABLE 1}
Go to previous article: 6.6.0.2.2.4.1: Initialization and general-purpose procedures Go to next article: 6.6.0.2.2.4.3: Starting and stopping live repository objects

 

 
Go to previous article: 6.6.0.2.2.4.1: Initialization and general-purpose procedures Go to next article: 6.6.0.2.2.4.3: Starting and stopping live repository objects