+

Search Tips   |   Advanced Search

 

# This program may be used, executed, copied, modified and distributed
# without royalty for the purpose of developing, using, marketing, or distribution

#-----------------------------------------------------------------
# addapp2.jacl - Jacl implementation of example script 12
#-----------------------------------------------------------------
#
#  The purpose of this example is to show  methods for
#  updating configuration attributes that are lists.  Some attributes #  (the "transports" attribute of the WebContainer in this example) are 
#  lists of objects.  If we request a list of attributes for the WebContainer
#  object you will see:
# 
#  transports Transport(IIOPTransport, JMSTransport, HTTPTransport)*  
#
#  This means that the transports attribute is a list (signified by the asterisk
#  at the end) of objects of type "Transport."  Individual members of the 
#  list may have type IIOPTransport, JMSTransport, or HTTPTransport, as well
#  as the base Transport class.
#
#  If we modify an attribute that is a list you set it in it's entirety.  There
#  is no syntax for adding or deleting from a list-type attribute by operating
#  on the attribute itself.  But since the members of the list are objects themselves,
#  they can be added, modified, and removed individually.
#  
#  This is a bi-modal script: it can be included in the wsadmin 
#  command invocation like this:
#     wsadmin -f addapp2.jacl mynode myserv 
#
#  or the script can be sourced from the wsadmin command line if:
#     wsadmin> source addapp2.jacl
#     wsadmin> addapp2 mynode myserv 
# 
#  The script expects some parameters:
#      arg1 - node name
#      arg2 - server name
#
#  This example demonstrates many wsadmin features:
#
#   - The use of the AdminConfig object to create objects in the configuration
#   - The use of the AdminConfig object to find objects in the configuration
#   - The use of the AdminConfig object to modify objects in the configuration
#   - The use of the AdminConfig object to save the configuration
#-----------------------------------------------------------------

proc addapp2 {nodeName serverName} {

   #--------------------------------------------------------------
   # set up globals
   #--------------------------------------------------------------
   global AdminConfig
   global AdminControl
   global AdminApp

   #--------------------------------------------------------------
   # do some sanity checking 
   #     -- do we have a node by this name? 
   #--------------------------------------------------------------
   set node [$AdminConfig getid /Node:$nodeName/]
   puts "addapp2: checking for existence of node $nodeName"
   if {[llength $node] == 0} {
      puts "addapp2: Error -- node not found for name $nodeName"
      return 
   }

   #--------------------------------------------------------------
   #     -- and a server?..... 
   #--------------------------------------------------------------
   set server [$AdminConfig getid /Node:$nodeName/Server:$serverName/]
   puts "addapp2: checking for existence of server $serverName"
   if {[llength $server] == 0} {
      puts "addapp2: Error -- server not found for name $serverName"
      return 
   }

   #--------------------------------------------------------------
   #     -- and a web container? 
   #--------------------------------------------------------------
   set wc [$AdminConfig list WebContainer $server] 
   puts "addapp2: checking for existence of WebContainer in $serverName"
   if {[llength $wc] == 0} {
      puts "addapp2: Error -- WebContainer not found in name $serverName"
      return 
   }

   #--------------------------------------------------------------
   # Manipulate list -- change one transport 
   #--------------------------------------------------------------
   puts "addapp2: change a member in the list."
   set trans_list [$AdminConfig showAttribute $wc transports]
   set transports [lindex $trans_list 0]
   
   # pick the first transport for this example
   set t0    [lindex $transports 0]
   set t_before [$AdminConfig showall $t0]

   set host_attr    [list host {}]
   set port_attr    [list port 9081]
   set address_attr [list address [list $host_attr $port_attr]]
   set attrs        [list $address_attr]
   $AdminConfig modify $t0 $attrs 
   set t_after [$AdminConfig showall $t0]
   puts "addapp2: transport before: "
   puts "$t_before"
   puts ""
   puts "addapp2: transport after: "
   puts "$t_after"
   puts ""

   #--------------------------------------------------------------
   # Manipulate list -- remove one transport 
   #--------------------------------------------------------------
   puts "addapp2: Remove a new member from the list."
   set t1    [lindex $transports 1]
   $AdminConfig remove $t1

   #--------------------------------------------------------------
   # Manipulate list -- add one 
   #--------------------------------------------------------------
   puts "addapp2: Add a new member to the list."
   set ssle_attr    [list sslEnabled true]
   set sslc_attr    [list sslConfig DefaultSSLSettings]
   set host_attr    [list host {}]
   set port_attr    [list port 7777]
   set address_attr [list address [list $host_attr $port_attr]]
   set attrs        [list $ssle_attr $sslc_attr $address_attr]
   $AdminConfig create HTTPTransport $wc $attrs 

   #--------------------------------------------------------------
   # Save all the changes 
   #--------------------------------------------------------------
   puts "addapp2: saving the configuration"
   $AdminConfig save

}

#-----------------------------------------------------------------
# Main
#-----------------------------------------------------------------
if { !($argc == 2) } {
   puts "addapp2: this script requires 2 parameters: node name, server name"
   puts "e.g.:     addapp2  mynode myserv"
} else { 
   set nodeName         [lindex $argv 0]  
   set serverName       [lindex $argv 1]  

   addapp2 $nodeName $serverName
}