WebSphere Application Server & Liberty

WebSphere Application Server & Liberty

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

if condition under for loop in jython scripting

  • 1.  if condition under for loop in jython scripting

    Posted Tue October 15, 2013 02:45 AM
    My script to check Messaging Listener ports on a particular app server is as follow :

     


    import sys
    import java
    from java.io import FileInputStream
    from org.python.modules import time
    from com.ibm.websphere.management.exception import AdminException
    lineSep = java.lang.System.getProperty('line.separator')
    global AdminConfig
    global AdminApp
    global AdminControl
    global AdminTask
     
    lPorts = AdminControl.queryNames('type=ListenerPort,cell=Cell01,node=node1,process=server1,*')
    lPortsArray = lPorts.split(lineSep)
    for lPort in lPortsArray:
            lcfgid = AdminControl.getConfigId(lPort)
            lname = AdminConfig.showAttribute(lcfgid, 'name')
            state = AdminControl.getAttribute(lPort, 'started')
    if state == 'true':
                       print "Listner Ports are started\n"


                    ##Here it takes only last listner port status.
    else:
            print "Listner Port" +lname+ "is stopped, starting it\n"
            AdminControl.invoke(lPort, 'start')

    #endIf
     


    The issue is ; it takes only last listener port status from this script , not for all, Please assist, where am i doing wrong ..



  • 2.  if condition under for loop in jython scripting

    Posted Tue October 15, 2013 04:28 AM
    Hi Saurabh ,

      I think that you need to indent your if/else block to right.  If you put "for" and "if" at the same level they are different conditions and is not evaluating "if/else" for each lport in lPortsArray.

      Hope this helps.

    Regards 


  • 3.  if condition under for loop in jython scripting

    Posted Tue October 15, 2013 04:38 AM
    Thanks a ton, it worked.