displayapps.jacl

 



###
### set up variables to keep server name and node name 
###
set  serverName  servername
set  nodeName  node1

###
### set up 2 global lists to keep the modules
###
set  ejbList {}
set webList {}

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

##
## lines 22 thru 148 Iterates through all the deployment objects to get the modules
## and perform filtering to list application that has at least one module installed
## in servername 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 {
             ###
             ### setting up some flag to do some filtering and get modules for servername 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 servername
     ###
     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 servername
     ###
     if {$ejbList != {}} {
          if {$ejbExists == "false"} {
                puts stdout "\t\tEJB Modules:"
          }
          foreach ejb $ejbList {
                puts stdout "\t\t\t$ejb  $flag"
          }
     }
}