Guys,
With the above approach, I found that I'm unable to log Monitor or Log
messages from my Python programs. I used STAFMon and STAFLog to these and
have tried sending these messages using the Static Handle and the handle of
Python program.
Just to refresh, I used static handle to queue messsages between stax job
and python program.
It seems to me that the code in xml where I'm actually waiting for queue
messages is stopping the monitor and log messages from displaying in the
STAX monitor window.
Here is the code snippet:
The STAX xml job:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
<defaultcall function="startHere"></defaultcall>
<script>
from com.ibm.staf import *
STAXMessageLog = 1
STAXLogMessage = 1
handle3 = STAFHandle("MyApplication")
result = handle3.submit2("local", "HANDLE", "CREATE HANDLE NAME
MyStaticHandle")
staticHandleNumber = int(result.result)
staticHandle = STAFHandle(staticHandleNumber)
</script>
<function name="startHere">
<sequence>
<stafcmd>
<location>'local'</location>
<service>'PROCESS'</service>
<request>
'START COMMAND python STDIN
"C:/workspaces/test-workspace-xml/testProject1/src/TestSuite1/PyInt.py"'
</request>
</stafcmd>
<if expr="RC == 0">
<script>handle2 = STAFResult</script>
<!--<log>handle.handle</log>-->
<!--<log>handle</log>-->
<else>
<log>'RC = %s, STAFResult = %s' %(RC, STAFResult)</log>
</else>
</if>
<log>'handle2 = %s' %(handle2)</log>
<!-- Inform Python about this static handle by setting a STAF
env. variable -->
<stafcmd name="'Set STAF ENV var'">
<location>'local'</location>
<service>'VAR'</service>
<request>'SET SHARED VAR PY_STATIC_HANDLE=%s VAR
MyTest/JobUserLogName=%s'\
%(staticHandleNumber,
STAXJobUserLogName)</request>
</stafcmd>
<if expr="RC == 0">
<log>'Handle shared'</log>
<else>
<log>'Could not share handle, RC = %s, STAFResult =f %s'
%(RC, STAFResult)</log>
</else>
</if>
<!-- ************ Queue WAIT REQUEST ************ -->
<script>
#submit STAF Queue message request
result1 = staticHandle.submit2("local", "queue", "QUEUE
PRIORITY 1 MESSAGE WAIT")
</script>
<if expr="result1.rc == STAFRC.Ok">
<log>'REQUEST sent: WAIT'</log>
</if>
<!-- WAIT on EVENT -->
<stafcmd name = "'Wait on Event'">
<location>'local'</location>
<service>'SEM'</service>
<request>'WAIT EVENT RESPONSE1/Ready'</request>
</stafcmd>
<log>'Got Event'</log>
<script>
# Submit a STAF request using this handle
request = 'GET WAIT 60000 PRIORITY 2'
result = staticHandle.submit2('local', 'QUEUE', request)
</script>
<if expr="result.rc == STAFRC.Ok">
<sequence>
mc = STAFMarshalling.unmarshall(result.result)
queueMsgMap = mc.getRootObject();
</script>
<log message="1">
STAFMarshalling.formatObject(mc)
</log>
<log message="1">
'RESPONSE received: %s' % (queueMsgMap['message'])
</log>
</sequence>
</if>
<!-- ************ Queue BootSigGen REQUEST ************ -->
<script>
#submit STAF Queue message request
result1 = staticHandle.submit2("local", "queue", "QUEUE
PRIORITY 1 MESSAGE
C:/workspaces/test-workspace-xml/testProject1/src/TestSuite1/bootSigGen.py")
</script>
<if expr="result1.rc == STAFRC.Ok">
<log>'REQUEST sent - bootSigGen.py'</log>
</if>
<!-- WAIT on EVENT -->
<log>staticHandleNumber</log>
*<stafcmd name = "'Wait on Event'">
<location>'local'</location>
<service>'SEM'</service>
<request>'WAIT EVENT RESPONSE3/Ready'</request>
</stafcmd>
<log>'Got Event'</log>
<!-- Get Message from Queue -->
<!--<parallel>-->
<script>
# Submit a STAF request using this handle
request = 'GET WAIT 60000 PRIORITY 2'
result = staticHandle.submit2('local', 'QUEUE', request)
</script>
<!--</parallel>-->*
<if expr="result.rc == STAFRC.Ok">
<sequence>
<script>
mc = STAFMarshalling.unmarshall(result.result)
queueMsgMap = mc.getRootObject();
</script>
<log message="1">
STAFMarshalling.formatObject(mc)
</log>
<log message="1">
'RESPONSE received: %s' % (queueMsgMap['message'])
</log>
</sequence>
</if>
</sequence>
</function>
</stax>
The corresponding Python Code: (Attached with the mail)
Please suggest is there some thing silly that I'm missing
from PySTAF import *
from PySTAFMon import *
from PySTAFLog import *
def main(handle1):
#global handle, fd
global obj
global handle, myStaxJobUserLogName
#handle = res.result
#WAIT = 1
#while WAIT == 1:
print "Inside main: Got: %s", handle1.handle
while 1:
"""import os
staticHandleNumber = os.environ.get('STAF_STATIC_HANDLE')
if staticHandleNumber == None:
print "Error: STAF_STATIC_HANDLE environment variable does not exist"
else:
"""
res1 = handle1.submit("local", "QUEUE", "GET PRIORITY 1 WAIT")
#res1 = handle1.submit("local", "QUEUE", "GET WAIT")
if (res1.rc != 0):
print "\nError submitting request Queue Get handle, RC: %d, Result: %s\n" % (res1.rc, res1.result)
else:
print "\nSome REQUEST received\n"
print "\n"
print res1.result
print "\nOK"
ro = res1.resultObj
mc = res1.resultContext
print "\n%s\n" %(mc)
print "Handle in message: %s" %(ro['handle'])
filePath = ro['message'] #Check if the message element is not empty
print "\n%s" %(ro['message'])
if ro['message'] == "WAIT":
#WAIT = 1
result1 = handle1.submit('local', 'QUEUE', 'QUEUE PRIORITY 2 HANDLE %s MESSAGE "OKEY!"' %(handle1.handle))
#result = handle.submit('local', 'QUEUE', 'QUEUE HANDLE %s MESSAGE "OKEY!"' %(handle.handle))
if (result1.rc != 0):
print "\nError submitting RESPONSE 'OK', RC: %d, Result: %s\n" % (result1.rc, result1.result)
else:
print "\nRESPONSE - OK submitted\n"
result2 = handle1.submit('local', 'SEM', 'POST EVENT RESPONSE1/Ready')
print 'Event 1 Posted'
elif ro['message'] == "CLEAN-UP":
result8 = handle1.submit('local', 'QUEUE', 'QUEUE PRIORITY 2 HANDLE %s MESSAGE "Clean-up Done"' %(handle1.handle))
if (result8.rc != 0):
print "\nError submitting RESPONSE 'Clean-up Done', RC: %d, Result: %s\n"\
% (result8.rc, result8.result)
else:
print "\nRESPONSE - 'Clean-up Done' submitted\n"
return
else:
#WAIT = 0
import sys, os.path
dir = os.path.dirname(ro['message'])
file = os.path.basename(ro['message'])
print "dir: ", dir
dir = os.path.abspath(dir)
print "dir: ", dir
sys.path.append(dir)
sys.path.append(os.path.dirname(dir))
print dir, "file:", file
print "\n%s"%(file)
head, tail = file.split(".py")
file = head
print "file: ", file
print 'PID: ', os.getpid()
if file == "createSigGen":
print 'Inside If'
exec("from " + file + " import *")
print 'PID: ', os.getpid()
global obj
obj = main()
print 'Called'
result3 = handle1.submit('local', 'QUEUE', \
'QUEUE PRIORITY 2 HANDLE %s MESSAGE "OBJ!"' \
%(handle1.handle))
if (result3.rc != 0):
print "\nError submitting RESPONSE 'Obj', RC: %d, Result: %s\n"\
% (result3.rc, result3.result)
else:
print "\nRESPONSE - OBJ submitted\n"
result4 = handle1.submit('local', 'SEM', 'POST EVENT RESPONSE2/Ready')
print 'Event 2 Posted'
elif file == 'bootSigGen':
print "Starting"
print handle
print handle.handle
monitor = STAFMonitor(handle)
monitorMessage = ("Beginning section ABC of test")
result7 = monitor.log(monitorMessage)
#result7 = handle.submit('local', 'MONITOR', 'LOG MESSAGE Recovered NAME monitor')
if (result7.rc != STAFResult.Ok):
print "Error on STAFMonitorDoLog, RC: %d, Result: %s" % \
(result7.rc, result7.result)
#sys.exit(result.rc)
else:
print result7
Log = STAFLog(handle, STAFLog.Machine, "MyLog",
[STAFLog.Fatal, STAFLog.Error, STAFLog.Warning])
result9 = Log.log(STAFLog.Start, "Booting SigGen")
print result9
result10 = Log.log(STAFLog.Warning, "Got Some ambiguous results")
print result10
message = 'Testing 1, 2, 3...'
request = 'LOG HANDLE LOGNAME %s LEVEL Info MESSAGE %s' % (myStaxJobUserLogName, message)
result = handle.submit('local', "LOG", request)
exec("from " + file + " import main as bootSigGen")
print 'PID: ', os.getpid()
#exec("import " + file)
bootSigGen(obj)
result5 = handle1.submit('local', 'QUEUE', 'QUEUE PRIORITY 2 HANDLE %s MESSAGE "BOOT!"' %(handle1.handle))
if (result3.rc != 0):
print "\nError submitting RESPONSE 'BOOT', RC: %d, Result: %s\n"\
% (result5.rc, result5.result)
else:
print "\nRESPONSE - BOOT submitted\n"
result6 = handle1.submit('local', 'SEM', 'POST EVENT RESPONSE3/Ready')
print 'Event 3 Posted'
print "\nOK 2"
if __name__ == "__main__":
obj = None
import sys, os
resFile = "C:\\raj.txt"
#sys.stdout = sys.stderr
sys.stdout = open(resFile, "w")
#fd.write("Hello World\n")
print "Hello World"
try:
handle = STAFHandle("MyTest")
except STAFException, e:
print "Error registering with STAF, RC: %d\n" % e.rc
sys.exit(e.rc)
print "\nHandle : %s" % (handle)
print "MyTest Handle : %s" %(handle.handle)
res = handle.submit("local", "var", "resolve string {PY_STATIC_HANDLE} string {MyTest/JobUserLogName}")
if (res.rc != 0):
print "\nError submitting request var resolve, RC: %d, Result: %s\n" % (res.rc, res.result)
else:
print res.result
#print "\nGot Handle: %s" % res.result
#print "\n"
#print res.result
#print "\n"
mc = unmarshall(res.result)
varResultList = mc.getRootObject()
#print 'Formatted output:\n%s' % formatObject(varResultList)
staticHandleNumber = varResultList[0]['result']
myStaxJobUserLogName = varResultList[1]['result'] # STAXJobUserLog
print 'StaticHandleNumber: %s Job User Log: %s' % \
(staticHandleNumber, myStaxJobUserLogName)
#handle.unRegister()
#Register with this static handle
#handle1 = STAFHandle(int(res.result), STAFHandle.Static)
handle1 = STAFHandle(int(staticHandleNumber), STAFHandle.Static)
print handle1
print handle1.handle
"""
staticHandleNumber = os.environ.get('STAF_STATIC_HANDLE')
if staticHandleNumber == None:
print "Error: STAF_STATIC_HANDLE environment variable does not exist"
sys.exit(1)
staticHandleNumber = int(staticHandleNumber)
print "Using STAF static handle: %s" %(staticHandleNumber)
try:
handle = STAFHandle(staticHandleNumber, STAFHandle.Static)
except STAFException, e:
print "Error registering with STAF, RC: %d", e.rc
sys.exit(e.rc)
"""
#handle = sys.argv[1]
#print 'Handle: %s' %(handle)
#main(handle)
main(handle1)
fd.close()
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
handle.unregister()
------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users