Example: List the modules in an application server

 

+

Search Tips   |   Advanced Search

 

The following example lists all of the modules on all of the enterprise applications that are installed on the server1 server in a node named node1:

An asterisk (*) means that the module is installed on server1 and node1 and another server or node. A plus sign (+) means that the module is installed on server1 and node1 only.


### set up variables to keep server name and node name 

set  serverName  server1
set  nodeName  node1

### set up 2 global lists to keep the modules

set  ejbList {}
set webList {}

### get all deployment objects and assigned it to deployments variable
set deployments [$AdminConfig getid /Deployment:/]


# Iterate through all the deployment objects to get the modules
# and perform filtering to list application that has at least one module installed
# in server1 in node myNode

foreach deployment $deployments {

   
   # reset the lists that hold modules for each application
   
   set webList {}
   set ejbList {}

   
   # get the application name
   
   set appName [lindex [split $deployment (] 0]

   
   # get the deployedObjects
   
   set depObject [$AdminConfig showAttribute $deployment deployedObject]

   
   # get all modules in the application
   
   set modules [lindex [$AdminConfig showAttribute $depObject modules] 0] 

   
   # initialize lists to save all the modules in the appropriate list to where they belong
   
   set modServerMatch {}  
   set modServerMoreMatch {}
   set modServerNotMatch {}

       
       # lines 55 to 112 iterate through all modules to get the targetMappings
       
       foreach module $modules {
           
           # set up some flag to do some filtering and get modules for server1 on node1
           
           set sameNodeSameServer "false"
           set diffNodeSameServer "false"
           set sameNodeDiffServer "false"
           set diffNodeDiffServer "false"

           
           # get the targetMappings
           
           set targetMaps [lindex [$AdminConfig showAttribute $module targetMappings] 0]

           
          # lines 72 to 111 iterate through all targetMappings to get the target
           
           foreach targetMap $targetMaps { 
               
              # get the target
               
               set target [$AdminConfig showAttribute $targetMap target]

               
               # do filtering to skip ClusteredTargets  
               
               set targetName [lindex [split $target #] 1]
               if {[regexp "ClusteredTarget" $targetName] != 1} { 
                   set sName [$AdminConfig showAttribute $target name]
                   set nName [$AdminConfig showAttribute $target nodeName]
            
                   
                   # do the server name match
                   
                   if {$sName == $serverName} {
                     if {$nName == $nodeName} {
                         set sameNodeSameServer "true"
                       } else {
                         set diffNodeSameServer "true"
                       }
                  } else {
                       
                       # do the node name match
                       
                       if {$nName == $nodeName} {
                            set sameNodeDiffServer "true"
                      } else {
                          set diffNodeDiffServer "true"
                      }
                }
 
                if {$sameNodeSameServer == "true"} {
                    if {$sameNodeDiffServer == "true" || $diffNodeDiffServer == "true" || $diffNodeSameServer == "true"} {
                        break
                    }
               }
          }
    }

    
    # put it in the appropriate list
    
    if {$sameNodeSameServer == "true"} {
        if {$diffNodeDiffServer == "true" || $diffNodeSameServer == "true" || $sameNodeDiffServer == "true"} {
             set modServerMoreMatch [linsert $modServerMoreMatch end [$AdminConfig showAttribute $module uri]]
         } else {
             set modServerMatch [linsert $modServerMatch end [$AdminConfig showAttribute $module uri]]
        }      
   } else {
        set modServerNotMatch [linsert $modServerNotMatch end [$AdminConfig showAttribute $module uri]]
   }
}  



# print the output with some notation as a mark

if {$modServerMatch != {} || $modServerMoreMatch != {}} {
    puts stdout "\tApplication name: $appName"
}


# do grouping to appropriate module and print

if {$modServerMatch != {}} {
    filterAndPrint $modServerMatch "+"
}
if {$modServerMoreMatch != {}} {
    filterAndPrint $modServerMoreMatch "*"
}
if {($modServerMatch != {} || $modServerMoreMatch != {}) "" $modServerNotMatch != {}} {
    filterAndPrint $modServerNotMatch ""
}
}

 
proc filterAndPrint {lists flag} {
   global webList
   global ejbList
   set webExists "false"
   set ejbExists "false"

   
   # If list already exists, flag it so as not to print the title more then once
   # and reset the list
   
   if {$webList != {}} {
       set webExists "true"
       set webList {}
   }   
   if {$ejbList != {}} {
       set ejbExists "true"
       set ejbList {}
   }

   
   # do some filtering for web modules and ejb modules
   
   foreach list $lists {
        set temp [lindex [split $list .] 1]
        if {$temp == "war"} {
             set webList [linsert $webList end $list]
        } elseif {$temp == "jar"} {
             set ejbList [linsert $ejbList end $list]
        }
   }

   
   # sort the list before printing
   
   set webList [lsort -dictionary $webList]
   set ejbList [lsort -dictionary $ejbList]

   
   # print out all the web modules installed in server1
   
   if {$webList != {}} {
       if {$webExists == "false"} {
            puts stdout "\t\tWeb Modules:"
       }
       foreach web $webList {
           puts stdout "\t\t\t$web  $flag"
       }
   }

   
   # print out all the ejb modules installed in server1
   
   if {$ejbList != {}} {
        if {$ejbExists == "false"} {
              puts stdout "\t\tEJB Modules:"
        }
        foreach ejb $ejbList {
              puts stdout "\t\t\t$ejb  $flag"
        }
   }
}

Example output for server1 on node node1:
 Application name: TEST1
        EJB Modules: deplmtest.jar  +
        Web Modules: mtcomps.war  *
Application name: TEST2
        Web Modules: mtcomps.war  +
        EJB Modules: deplmtest.jar  +
Application name: TEST3
        Web Modules: mtcomps.war  *
        EJB Modules: deplmtest.jar  *
Application name: TEST4
        EJB Modules: deplmtest.jar  *
        Web Modules: mtcomps.war


 

Related Tasks


Listing the modules in an installed application with scripting