Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Implicit parameter passing

LinFu
2011-09-15
2013-06-12
  • LinFu
    LinFu
    2011-09-15

    I create a Main-Job named Job.xml and Sub-Job named Sleep.xml, respectively.

    In the Main-Job a STAXGlobal variable is uesd to implicit pass a parameter to Sub-Job

    But it seems that STAXGlobal cannot be used in this way…

    My question is i want to pass some parameters to Sub-Job, but there is some restriction in our system and i cannot pass them explicitly through Sub-Job-Interface. I want to find a method to implicit pass a parameter to Sub-Job

    Thx

    Job.xml
    <stax>
       <defaultcall function="main">{'Global_sleeptime':u'1s'}</defaultcall>
       <script>
    TaaSGlobal_JobInstanceID = STAXGlobal( 'JI_78909' )
       </script>
       <function name="main">
             <sequence>
                      <call function="'SubJob3323'"></call>
             </sequence>
       </function>
       <function name="SubJob3323">
          <sequence>
             <job name="'SubJob3323:Sleep'" clearlogs="'enabled'" monitor="1" logtcelapsedtime="'enabled'" logtcnumstarts="'enabled'" logtcstartstop="'enabled'" pythonoutput="'jobuserlogandmsg'">
                <job-file machine="'10.162.123.123'">'C:\\Sleep.xml'</job-file>
                <job-function>'main'</job-function>
                <job-function-args eval="1">{ 'sleepTime':Global_sleeptime }</job-function-args>
                <job-action>
                      <log message="1" level="'info'">"TaaSGlobal_JobInstanceID : %s ."%TaaSGlobal_JobInstanceID.get()</log>
                </job-action>
             </job>
          </sequence>
       </function>
    </stax>

    Sleep.xml
    <stax>
    <defaultcall function="main"/>
    <function name="main">
    <sequence>
    <log message="1" level="'info'">"TaaSGlobal_JobInstanceID : %s ."%TaaSGlobal_JobInstanceID.get()</log>
    </sequence>
    </function>
    </stax>

     
  • Sharon Lucas
    Sharon Lucas
    2011-09-15

    Each STAX job (including a sub-job) has its own set of STAX Python variables (including STAXGlobal variables).  STAX Python variables are not shared between jobs.  You can use the <job-function-args> element to pass STAX Python variables (including STAXGlobal variables) to a sub-job.  You had some errors in your STAX jobs, including not defining the map arguments for your functions.

    I updated your STAX jobs and the following works:

    Job.xml:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE stax SYSTEM "stax.dtd">
    <stax>
    <defaultcall function="main">{'Global_sleeptime': u'1s'}</defaultcall>
    <script>
      TaaSGlobal_JobInstanceID = STAXGlobal( 'JI_78909' )
    </script>
    <function name="main">
      <function-map-args>
        <function-required-arg name="Global_sleeptime"/>
      </function-map-args>
      <sequence>
        <call function="'SubJob3323'">Global_sleeptime</call>
      </sequence>
    </function>
    <function name="SubJob3323">
      <sequence>
        <job name="'SubJob3323:Sleep'" clearlogs="'enabled'" monitor="1" logtcelapsedtime="'enabled'"
               logtcnumstarts="'enabled'" logtcstartstop="'enabled'" pythonoutput="'jobuserlogandmsg'">
          <job-file machine="'10.162.123.123'">'C:\\Sleep.xml'</job-file>
          <job-function>'main'</job-function>
          <job-function-args eval="1">
           { 'sleeptime': Global_sleeptime, 'TaaSGlobal_JobInstanceID': TaaSGlobal_JobInstanceID }
          </job-function-args>
          <job-action>
            <log message="1" level="'info'">
              'TaaSGlobal_JobInstanceID : %s' % (TaaSGlobal_JobInstanceID.get())
            </log>
          </job-action>
        </job>
        <if expr="RC == 0">
          <log message="1">
            'Sub-job %s completed.  Status: %s  Result: %s' % (STAXSubJobID, STAXSubJobStatus, STAXResult)
          </log>
          <else>
            <log message="1" level="'Error'">
              'Sub-job could not be started. RC: %s  Result: %s' % (RC, STAFResult)
            </log>
          </else>
        </if>
      </sequence>
    </function>
    </stax>
    

    Sleep.xml:

    <!DOCTYPE stax SYSTEM "stax.dtd">
    <stax>
    <defaultcall function="main"/>
    <function name="main">
      <function-map-args>
        <function-required-arg name="sleeptime"/>
        <function-required-arg name="TaaSGlobal_JobInstanceID"/>
      </function-map-args>
      <sequence>
        <log message="1" level="'info'">
          'sleeptime = %s' % (sleeptime)
        </log>
        <log message="1" level="'info'">
          'TaaSGlobal_JobInstanceID = %s' % (TaaSGlobal_JobInstanceID)
        </log>
      </sequence>
    </function>
    </stax>
    
     
  • LinFu
    LinFu
    2011-09-16

    thx for your response

    is there any possible to pass STAX variables to SubJob without leavage <job-function-args> element?

     
  • Sharon Lucas
    Sharon Lucas
    2011-09-16

    Yes, you can set Python variables for a sub-job via the sub-job's <job-script> or <job-scriptfile> sub-elements.

     
  • LinFu
    LinFu
    2011-09-19

    thx

     
  • LinFu
    LinFu
    2012-06-15

    there is a sample to describe a sub-function could update a global variable :
    http://staf.sourceforge.net/current/STAX/staxug.html#STAXGlobal_Class

    is that possible to update a global variable in a sub-job

    in other words
    i want to pass a STAXGlobal variable to a subjob in the way mentioned above, and update the value of the global variable in the subjob.

     
  • LinFu
    LinFu
    2012-06-15

    is that possible to get the updated value in the outer-job

    i know it indeed could return the updated value to the outer-job, but in this case, the STAXGlobal variable wouldn't provide its special functional compared with normal variable. And the STAXGlobal could be replaced by a local variable.

     
  • Sharon Lucas
    Sharon Lucas
    2012-06-15

    No, each STAX job (including a sub-job) has its own set of STAX Python variables (including STAXGlobal variables).  STAX Python variables are not shared between jobs.  You can pass variables to sub-jobs and return variables from sub-jobs.

    There is an open Feature Request #3404743 "Provide global data for SubJobs" at http://sourceforge.net/tracker/?func=detail&aid=3404743&group_id=33142&atid=407384 that may be included in the future.

     
  • LinFu
    LinFu
    2012-06-18

    thank you