Why and when to perform this task
The basic concepts in this script can be used to communicate with
any MBean in the system. All that is required is the name and type of the
MBean and the methods and attributes available on the MBean. The
getAttribute and
setAttribute commands
are used for attributes. The
invoke command is used for
methods. Follow these steps to create a
.Jacl script that
manages the JMX Security MBean.
Note: The code in each step is prefaced with
a statement explaining what the code does.
Steps for this task
- Determine the nodename
The first part of the
script shown below determines the nodename. If the nodeName is
not specified correctly, the correct syntax is printed and the script exits.
# read and validate arguments
if {{$argc == 1 } && { [lindex $argv $i] == "-nodeName" } {
set nodeName [lindex $argv $i]
- Identify the MBean
An MBean is identified
by a type and a name.
Note: The name and type are hard coded in this case since
you know the specific MBean you want to use.
The second part of the
script identifies the MBean.
# these two variables, mbeanName and mbeanType are used
to uniquely identify the mbean.
# for this sample, the mbean that access relationship
services will be used.
set mbeanName"RelService"
set mbeanType"WBIRelServices"
- Locate and set the reference to the MBean.
You
use the code shown here to set the reference for the MBean.
# locate the mbean and set a reference to in in "relSvcsMBean" variable
set relSvcsMBean [$AdminControl queryNames
name=$mbeanName,node=$nodeName,type=$mbeanType,*]
- Call the relationship using the getAttribute command.
The documentation of this specific MBean defines an attribute named allRelationshipNames.
Ask the MBean for that attribute using the getAttribute command.
The attribute value will be a list that you step through in the next step
that invokes the command.
# request the list of relationships from the mbean
set relationships
[$AdminControl getAttribute $relSvcsMBean allRelationshipNames]
- Invoke the command for each relationship name, you print
the name, and then go back to the MBean for additional information.
For each relationship name, you print the name, and then go back
to the MBean for additional information. In this example the MBean defines
a method named
getAllRoleNames with a single parameter
for the specific relationship name. You use the
invoke command
to call this method, passing the current relationship name. For each role
in the relationship, a role name is printed.
# loop through the list of role names and print name
foreach roleName $roles {
puts " Role: $roleName"
}
}
} else {
# arguments were not correct, print correct syntax
puts "Usage: wsadmin -f RelServicesAdmin.jacl -nodeName nodeName"
}
Result
You have now written a script to call relationships.