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

Attachment: 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

Reply via email to