Also, I wanted to make sure that you were aware of a couple of STAX service requests that you might be interested in using from your Python program to log messages in the STAX Job User Log and to send a message to the STAX Monitor's Messages panel. To use them, you only need to know the STAXJobID (which you could make available to the Python process via a STAF variable) and the STAX service name. The STAX LOG and SEND requests are documented in the STAX User's Guide at http://staf.sourceforge.net/current/STAX/staxug.html#Header_Log.
C:\>STAF local STAX HELP Response -------- STAX Service Help: EXECUTE < <FILE <XML File Name> [MACHINE <Machine Name>]> | DATA <XML Data> > [JOBNAME <Job Name>] [FUNCTION <Function ID>] [ARGS <Arguments>] ... LOG JOB <Job ID> MESSAGE <Message> [LEVEL <Level>] [SEND] SEND JOB <Job ID> MESSAGE <Message> LOG allows you to log a message in the STAX Job User Log for a job that is currently running. It also allows you to optionally send a message to the STAX Monitor. It performs basically the same action as a <log> element (or <log message="1"> element) contained in a job's XML file. This request is useful if you want a process defined by a <process> element in a job to log one or more messages in the STAX Job User Log and, optionally, to send the message(s) to the STAX Monitor to be displayed in the "Message" panel when monitoring the job. This can be done by passing the value of the STAXJobID Python variable to the process (e.g. via the <parms> element or <env> element) so it can be used for the value of the JOB option and then submitting a LOG request from within the process. Syntax LOG JOB <Job ID> MESSAGE <Message> [LEVEL <Level>] [SEND] JOB specifies the ID of the job. MESSAGE specifies the message text to be logged in the STAX Job User Log and, optionally, sent to the STAX Monitor. LEVEL specifies the is the logging level of the message to be logged. It must be one of the STAF logging levels (e.g. Fatal, Error, Warning, Info, Trace, Trace2, Trace3, Debug, Debug2, Debug3, Start, Stop, Pass, Fail, Status, User1, User2, User3, User4, User5, User6, User7, or User8). It is not case-sensitive. It is optional and defaults to Info. SEND specifies to also send the message to the STAX Monitor. It is optional. Note that a message logged in the STAX Job User Log is persistent, unlike a message sent to the STAX Monitor which is only displayed if the job is currently being monitored by the STAX Monitor running on any machine(s). Security This request requires at least trust level 3. Results Upon successful return, the result buffer does not contain anything. Examples Goal: Log informational message "Running TestA on machine client1.company.com" for the STAX Job ID contained in variable myStaxJobID in the job's user log via a Python program. message = 'Running TestA on machine client1.company.com' request = 'LOG JOB %s MESSAGE "%s"' % (myStaxJobID, message) res = handle.submit('local', 'STAX', request) if (res.rc != 0): print "\nError: STAF local STAX %s failed. RC: %s, Result: %s\n" % (request, res.rc, res.result) Goal: Log error message "Error in Step 3 of TestA running on machine server2" for job 5 in the job's user log and send the message to the STAX Monitor. message = 'Error in Step 5 of TestA running on machine server2' request = 'LOG SEND JOB %s LEVEL Error MESSAGE "%s"' % (myStaxJobID, message) res = handle.submit('local', 'STAX', request) if (res.rc != 0): print "\nError: STAF local STAX %s failed. RC: %s, Result: %s\n" % (request, res.rc, res.result) -------------------------------------------------------------- Sharon Lucas IBM Austin, luc...@us.ibm.com (512) 286-7313 or Tieline 363-7313 ----- Forwarded by Sharon Lucas/Austin/IBM on 02/04/2009 09:57 AM ----- Sharon Lucas/Austin/IBM 02/03/2009 07:03 PM To dudeja.ra...@gmail.com cc staf-users@lists.sourceforge.net Subject Re: [staf-users] Unable to use Static Handle with the consecutive commands in a STAX job file Well, you have a few problems in your code. First, you are starting your Python program via your STAX job and the Python program is submitting a VAR RESOLVE request to resolve STAF variables PY_STATIC_HANDLE and MyTest/JobUserLogName before your STAX job has even had a chance to set them. So, your Python program ends up writing to the previous STAX Job User Log, not the current STAX job log. Instead, you should set these STAF variables on your PROCESS START request using the VAR options in your <process> element, instead of setting them later after starting the process. For example: <script> stdinFile = 'C:/tests/PyInt.py' request = 'START COMMAND python STDIN "%s"' % (stdinFile) + \ ' VAR PY_STATIC_HANDLE=%s VAR MyTest/JobUserLogName=%s' % (staticHandleNumber, STAXJobUserLogName) </script> <stafcmd> <location>'local'</location> <service>'PROCESS'</service> <request>request</request> </stafcmd> And remove the following code: <!-- 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> Also, you're not specifying the right request to log to the STAX Job User Log. The STAX Job User Log is a STAF machine log, not a handle log, so when logging to it you need to submit a request to the LOG service like the following (assuming variable myStaxJobUserLogName contains the correct log name for the STAX Job User log). You should also verify that the log request worked. For example: message = 'Testing 123' request = 'LOG MACHINE LOGNAME %s LEVEL Info MESSAGE %s' % (myStaxJobUserLogName, message) print '\nSTAF local LOG %s' % (request) result = handle.submit('local', 'LOG', request) if (result.rc != 0): print '\nSTAF local LOG %s failed, RC: %s, Result: %s\n' % (request, result.rc, result.result) Or, when using the STAFLog class, you need to specify that it's a machine log (not a handle log) and you need to specify the proper name for the STAX Job User log. For example: Log = STAFLog(handle, STAFLog.Machine, myStaxJobUserLogName) message = 'Testing 123' print '\nLog message %s to log %s' % (message, myStaxJobUserLogName) result = Log.log(STAFLog.Start, message) if (result.rc != 0): print '\nLogging to %s failed, RC: %s, Result: %s\n' % (myStaxJobUserLogName, result.rc, result.result) With these changes, the Python program was able to log messages to the appropriate STAX Job User Log and I was able to view them. -------------------------------------------------------------- Sharon Lucas IBM Austin, luc...@us.ibm.com (512) 286-7313 or Tieline 363-7313 dudeja.ra...@gmail.com 02/03/2009 12:08 PM To staf-users@lists.sourceforge.net cc Subject Re: [staf-users] Unable to use Static Handle with the consecutive commands in a STAX job file 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 ------------------------------------------------------------------------------ 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
PyInt.py
Description: Binary data
------------------------------------------------------------------------------ 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