将值从WLST脚本返回到Ant脚本

时间:2015-08-17 05:26:10

标签: ant wlst

<?xml version="1.0" encoding="iso-8859-1"?>
<project name="monitorResources" default="help" basedir=".">
<taskdef name = "wlst" classname="weblogic.ant.taskdefs.management.WLSTTask">
  <classpath>
    <pathelement location="${oracle.home}/wlserver_10.3/jdeveloper/ant/lib/weblogic.jar"/>
  </classpath>
</taskdef>

<property file="Test_Build.properties"/>
<property name="ant-contrib.jar" location="${oracle.home}/ant/lib/ant-contrib-1.0b3.jar"/>
<property name="weblogic.jar" location="${oracle.home}/wlserver_10.3/server/lib/weblogic.jar"/>

<target name="fetchConnections"> 
  <wlst executescriptbeforefile="true" debug="false"> 
    <script>
      def monitorJmsAdapter(serverName):
        cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/JmsAdapter/ComponentRuntimes/JmsAdapter/ConnectionPools")
        connectionPools = ls(returnMap='true')
        excessConnectionsList = [];
        print '--------------------------------------------------------------------------------------'
        print 'JmsAdapter Runtime details for '+ serverName
        print '                                                                                       '
        print '                                                                                       '
        print '--------------------------------------------------------------------------------------'
        print '%10s %13s %15s %18s' % ('Connection Pool', 'State', 'Current', 'Max')
        print '%10s %10s %24s %21s' % ('', '', 'Capacity', 'Capacity')
            print '                                                                                       '
            print '--------------------------------------------------------------------------------------'
            for connectionPool in connectionPools:
                cd('/')
          cd("ServerRuntimes/"+str(serverName)+"/ApplicationRuntimes/JmsAdapter/ComponentRuntimes/JmsAdapter/ConnectionPools/"+str(connectionPool))
                connectionName=cmo.getName()
                print 'Name is' +connectionPool
                currentCapacity=cmo.getCurrentCapacity()
                maxCapacity=cmo.getMaxCapacity()
          preferedCapacity=maxCapacity-190
          if currentCapacity >= preferedCapacity:
                        excessConnectionsList.append(cmo.getName())
            print excessConnectionsList
          print '%15s %15s %10s %20s' % (cmo.getName(), cmo.getState(), +currentCapacity, +maxCapacity)
            print '                                                                                       '
            print '--------------------------------------------------------------------------------------'
        return excessConnectionsList

      def main():
        connect('weblogic','****','t3://localhost:7001')
        servers = cmo.getServers()
        domainRuntime()
        for server in servers:
          if server.getName()=='soa_server1':
            monitorJmsAdapter(server.getName())

      disconnect()
      main()  
    </script>
  </wlst> 
</target>
<target name = "checkConnections">
  <echo>###</echo>
</target>
</project>

上述脚本用于获取超出其当前容量的连接值。 WLST脚本已嵌入Ant脚本中。

如何在“checkConnections”目标中获取“excessConnectionsList”WLST变量的值?

1 个答案:

答案 0 :(得分:0)

经过一番研究后,我设法做到这一点的唯一方法是使用时态属性文件:

<wlst debug="false" failOnError="true" executeScriptBeforeFile="false" fileName="${script}" > 
  <script>
    import os
    f = open('wlstOutput.properties','w')
    f.write('propertyKey1=propertyValue1\n')
    f.close()                    
  </script>
</wlst>

<loadproperties srcFile="wlstOutput.properties"/>

<delete file="wlstOutput.properties"/>

<echo>WLST RESULT: ${propertyKey1}</echo>