+

Search Tips   |   Advanced Search

 

Example: Listing the modules in an appserver

 

This 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.

 1  #-----------------------------------------------------------------------------------
       2  # setting up variables to keep server name and node name 
       3  #-----------------------------------------------------------------------------------
       4  set  serverName  server1
       5  set  nodeName  node1
       6  #----------------------------------------------------------------------------------
       7  # setting up 2 global lists to keep the modules
       8  #----------------------------------------------------------------------------------
       9  set  ejbList {}
      10 set webList {}
11
12 #---------------------------------------------------------------------------------------------------
13 # gets all deployment objects and assigned it to deployments variable
14 #---------------------------------------------------------------------------------------------------
15 set deployments [$AdminConfig getid /Deployment:/]
16
17 #--------------------------------------------------------------------------------------------------------
18 # lines 22 thru 148 Iterates through all the deployment objects to get the modules
19 # and perform filtering to list application that has at least one module installed
20 # in server1 in node myNode
21 #--------------------------------------------------------------------------------------------------------
22 foreach deployment $deployments {
23
24     # --------------------------------------------------------------------------------------------
25     # reset the lists that hold modules for each application
26     #---------------------------------------------------------------------------------------------
27     set webList {}
28     set ejbList {}
29
30     #------------------------------------------
31     # get the application name
32     #------------------------------------------
33     set appName [lindex [split $deployment (] 0]
34
35     #------------------------------------------          
36     # get the deployedObjects
37     #------------------------------------------
38     set depObject [$AdminConfig showAttribute $deployment deployedObject]
39
40     #--------------------------------------------    
41     # get all modules in the application
42     #---------------------------------------------
43     set modules [lindex [$AdminConfig showAttribute $depObject modules] 0] 
44
45     #--------------------------------------------------------------------------------------------------------        
46     # initialize lists to save all the modules in the appropriate list to where they belong
47     #--------------------------------------------------------------------------------------------------------
48     set modServerMatch {}  
49     set modServerMoreMatch {}
50     set modServerNotMatch {}
51
52         #-------------------------------------------------------------------------------------------
53         # lines 55 to 112 iterate through all modules to get the targetMappings
54         #-------------------------------------------------------------------------------------------
55         foreach module $modules {
56             #-------------------------------------------------------------------------------------------------
57             # setting up some flag to do some filtering and get modules for server1 on node1
58             #-------------------------------------------------------------------------------------------------
59             set sameNodeSameServer "false"
60            set diffNodeSameServer "false"
61             set sameNodeDiffServer "false"
62             set diffNodeDiffServer "false"
63
64             #--------------------------------------------
65             # get the targetMappings
66             #--------------------------------------------
67             set targetMaps [lindex [$AdminConfig showAttribute $module targetMappings] 0]
68
69             #--------------------------------------------------------------------------------------------
70            # lines 72 to 111 iterate through all targetMappings to get the target
71             #--------------------------------------------------------------------------------------------
72             foreach targetMap $targetMaps { 
73                 #------------------------------
74                # get the target
75                 #------------------------------
76                 set target [$AdminConfig showAttribute $targetMap target]
77
78                 #--------------------------------------------------
79                 # do filtering to skip ClusteredTargets  
80                 #--------------------------------------------------
81                 set targetName [lindex [split $target #] 1]
82                if {[regexp "ClusteredTarget" $targetName] != 1} { 
83                     set sName [$AdminConfig showAttribute $target name]
84                     set nName [$AdminConfig showAttribute $target nodeName]
85              
86                     #----------------------------------------------
87                     # do the server name match
88                     #----------------------------------------------
89                     if {$sName == $serverName} {
90                       if {$nName == $nodeName} {
91                 set sameNodeSameServer "true"
92                         } else {
93                 set diffNodeSameServer "true"
94                         }
95                    } else {
96                          #--------------------------------------- 
97                          # do the node name match
98                          #---------------------------------------
99                          if {$nName == $nodeName} {
100                 set sameNodeDiffServer "true"
101                        } else {
102                            set diffNodeDiffServer "true"
103                        }
104                  }
1.5 
106                  if {$sameNodeSameServer == "true"} {
107                      if {$sameNodeDiffServer == "true" || $diffNodeDiffServer == "true" || 
                              $diffNodeSameServer == "true"} {
108                          break
109                      }
110                 }
111            }
112      }
113
114      #---------------------------------------------
1.5      # put it in the appropriate list
116      #---------------------------------------------   
117      if {$sameNodeSameServer == "true"} {
118          if {$diffNodeDiffServer == "true" || $diffNodeSameServer == "true" || $sameNodeDiffServer == "true"} {
119               set modServerMoreMatch [linsert $modServerMoreMatch end [$AdminConfig showAttribute $module uri]]
120           } else {
121               set modServerMatch [linsert $modServerMatch end [$AdminConfig showAttribute $module uri]]
122          }      
123     } else {
124          set modServerNotMatch [linsert $modServerNotMatch end [$AdminConfig showAttribute $module uri]]
1.5     }
126  }  
127
128
129  #----------------------------------------------------------------
130  # print the output with some notation as a mark
131  #----------------------------------------------------------------
132  if {$modServerMatch != {} || $modServerMoreMatch != {}} {
133      puts stdout "\tApplication name: $appName"
      134  }
      1.5
      136  #---------------------------------------------------------
      137  # do grouping to appropriate module and print
      138  #---------------------------------------------------------
      139  if {$modServerMatch != {}} {
      140      filterAndPrint $modServerMatch "+"
      141  }
      142  if {$modServerMoreMatch != {}} {
      143      filterAndPrint $modServerMoreMatch "*"
      144  }
      1.5  if {($modServerMatch != {} || $modServerMoreMatch != {}) "" $modServerNotMatch != {}} {
      146      filterAndPrint $modServerNotMatch ""
      147  }
      148}
      149
      150   
      151  proc filterAndPrint {lists flag} {
      152     global webList
      153     global ejbList
      154     set webExists "false"
      1.5     set ejbExists "false"
      156
      157     #------------------------------------------------------------------------------------------------------
      158     # If list already exists, flag it so as not to print the title more then once
      159     # and reset the list
      160     #------------------------------------------------------------------------------------------------------
      161     if {$webList != {}} {
      162         set webExists "true"
      163         set webList {}
      164     }   
      1.5     if {$ejbList != {}} {
      166         set ejbExists "true"
      167         set ejbList {}
      168     }
      169
      170     #------------------------------------------------------------------
      171     # do some filtering for web modules and ejb modules
      172     #------------------------------------------------------------------
      173     foreach list $lists {
      174          set temp [lindex [split $list .] 1]
      1.5          if {$temp == "war"} {
      176               set webList [linsert $webList end $list]
      177          } elseif {$temp == "jar"} {
      178               set ejbList [linsert $ejbList end $list]
      179          }
      180     }
      181
      182     #---------------------------------------
      183     # sort the list before printing
      184     #---------------------------------------
      1.5     set webList [lsort -dictionary $webList]
      186     set ejbList [lsort -dictionary $ejbList]
      187
      188     #----------------------------------------------------------------
      189     # print out all the web modules installed in server1
      190     #----------------------------------------------------------------
      191     if {$webList != {}} {
      192         if {$webExists == "false"} {
      193              puts stdout "\t\tWeb Modules:"
      194         }
      1.5         foreach web $webList {
      196             puts stdout "\t\t\t$web  $flag"
      197         }
      198     }
      199
      200     #--------------------------------------------------------------
      201     # print out all the ejb modules installed in server1
      202     #--------------------------------------------------------------
      203     if {$ejbList != {}} {
      204          if {$ejbExists == "false"} {
      205                puts stdout "\t\tEJB Modules:"
      206          }
      207          foreach ejb $ejbList {
      208                puts stdout "\t\t\t$ejb  $flag"
      209          }
      210     }
      211}
      
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

 

Reference topic