7 Replies Latest reply on Dec 8, 2015 7:01 PM by Bill Robinson

    [ NSH ] JobRun findLastRunByJobKey issue

    Clement BARRET

      Hi,

       

      I'll describe the way to reproduce this behavior.

       

      NB: We're using BladeLogic 8.3.02.332

       

      Step 1) Create a NSH Script Job (like a simple one that would only do some echo "youpi" for example) in the BladeLogic Console.

       

      Step 2) Run it using a blcli as follow :

       

      Step 2.1) We'll clear the targets and set a new one (only one for this example)

       

      # retrieve the job DBKey and context

      blcli_execute NSHScriptJob getDBKeyByGroupAndName "${JOB_PATH}" "${JOB_NAME}";

      blcli_storeenv JOB_DBKEY;

       

      # storing the NSH Script Job context

      blcli_execute Utility storeTargetObject "NSH_SJ";

       

      # clear the targets

      blcli_execute Job clearTargetServers "$JOB_DBKEY";

       

      # new version of the Job => new DBKey

      blcli_storeenv JOB_DBKEY;

       

      # set the context to our Job (useless here since we're already in this context but it doesn't hurt for the example)

      blcli_execute Utility setTargetObject "NSH_SJ";

       

      # set the new target server (only one for the example) named "my_test_server"

      blcli_execute Job addTargetServers "$JOB_DBKEY" my_test_server;

       

      # new version of the Job => new DBKey

      blcli_storeenv JOB_DBKEY;

       

      Ok, we're good to go.

       

      Step 2.2) Execute the Job via a blcli call*

       

      (*) can be done with the "wait" version of the blcli or the other one, that doesn't change anything on the behavior

       

      # this call actually returns a job run DBKey and not a JobRun ID... really odd

      blcli_execute  Job executeJobAndWaitForRunID "$JOB_DBKEY";

      blcli_storeenv JOB_RUN_DBKEY

       

       

      ----------------------------------------------------------------------------------------

      Here is the blcli_call documentation :

       

      Command Name : executeJobAndWaitForRunID

      Name space : Job

      Command Type : Complex

      Release command : true

      Author :

      Andrew Mellors

      Description :

      This command executes a job and waits for the Job Run ID before returning the job run key.

      Return type : com.bladelogic.om.infra.app.service.job.JobRunKey

      ----------------------------------------------------------------------------------------

       

      Step 3) So, now our Job is started. Let it finish.

       

      # retrieve the JobRun context

      blcli_execute JobRun findByJobRunKey "$JOB_RUN_DBKEY";

      # We should get "false" doing this

      blcli_execute JobRun getIsRunning;

      blcli_storeenv JOB_IS_RUNNING;

       

      NB : you can put that in a loop with a sleep in it if you want to automate this detection

       

      Step 4) Let's retrieve it's Job results !

       

      # retrieve the last JobRun results using the NSH Script Job DBKey

      blcli_execute JobRun findLastRunByJobKey "$JOB_DBKEY";

      Command execution failed. com.bladelogic.om.infra.mfw.util.NotFoundException: job run with id 0 not found

       

      "But Woooot ??" would I scream...

       

      So, let's open the console, check your job results manually (right click, job results)

      It's here...

       

      Now, let's do it, here it is : right click => execute againts => choose your target ( my_test_server )

      Let it finish.

       

      Redo the Step 4)

       

       

      # retrieve the last JobRun results using the NSH Script Job DBKey

      blcli_execute JobRun findLastRunByJobKey "$JOB_DBKEY";

      com.bladelogic.om.infra.model.job.jobrun.JobRunImpl@a4e92fc3

       

      # IT WORKED !!

       

      Step 5) Write the JobRun log content to a file

       

      # get the JobRunId

      blcli_execute JobRun getJobRunId

      blcli_storeenv JOBRUN_ID;

       

      # retrieve the JobRun content

      blcli_execute Utility exportNSHScriptRun "${JOBRUN_ID}" "/tmp/my_jobrun_content.log";

       

       

      ------------------------------------------------------

       

      So, the conclusion is simple :

       

      • If you run a Job with a blcli call (execute, executeJobAndWait, executeJobAndWaitForRunID) you won't be able to retrieve its JobRun results.


      • If you run the same job manually, it will work.

       

       

      Now... I would like to know your insight about this issue before opening a support case.

       

      Best Regards.

       

       

      Clément BARRET

      ORANGE BUSNESS SERVICES

        • 1. Re: [ NSH ] JobRun findLastRunByJobKey issue
          Bill Robinson

          This is QM001804227 which is fixed in 8.3.03 and 8.5.00.

           

          are you sure that the job isn't being altered between your last save and the findLastRun command?  that's the way to trigger this.

           

          take your last db key and run:

          blcli_execute Job jobKeyToJobId $JOB_KEY

          blcli_storeenv jobId

          blcli_execute Job findLatestById ${jobId}

          blcli_execute Job  getJobVersionId

           

          blcli_execute Job getJobVersionId

           

          then

          blcli_execute JobRun findByJobRunKey $JOBRUN_KEY

          blcli_execute JobRun getJobKey

          bcli_storeenv jobKey

          blcli_execute Job findByDBKey $jobKey

          blcli_execute Job getJobVersionId

           

           

          if those versions are mismatched that would be the problem.

          1 of 1 people found this helpful
          • 2. Re: [ NSH ] JobRun findLastRunByJobKey issue
            Clement BARRET

            Hi Bill Robinson

             

            Thanks for the update. So yes my job hasn't been altered while I'm testing this (I'm alone working on this test platform atm).

             

            I'm glad to know there is a fix available... I will ask our BladeLogic architect to send a request to BMC to get this patch and to apply it on our current platform. That will definitely make my life easier :°)

             

            Cheers.

            • 3. Re: [ NSH ] JobRun findLastRunByJobKey issue
              Bill Robinson

              well - if your job hasn't been changed you should not encounter the problem ...

               

              also - blcli_execute Utility setTargetObject "NSH_SJ";

              you don't need to do that because the blcli calls you are using aren't operating on the job object in memory.  they all load the job object them selves.

               

              can you try running the below:

              blcli_setjvmoption -Dcom.bladelogic.cli.execute.quietmode.enabled=true

              blcli_setoption serviceProfileName defaultProfile

              blcli_setoption roleName BLAdmins

              blcli_connect

               

              JOB_PATH="/Workspace/Sleep Test"

              JOB_NAME="sleep1"

              SERVER="blapp"

               

              blcli_execute NSHScriptJob getDBKeyByGroupAndName "${JOB_PATH}" "${JOB_NAME}";

              blcli_storeenv JOB_DBKEY;

              blcli_execute Job clearTargetServers "$JOB_DBKEY";

              blcli_storeenv JOB_DBKEY;

              blcli_execute Job addTargetServers "$JOB_DBKEY" ${SERVER}

              blcli_storeenv JOB_DBKEY;

              blcli_execute Job findByDBKey ${JOB_DBKEY}

              blcli_execute Job getJobId

              blcli_storeenv jobId

              blcli_execute Job findLatestById ${jobId}

              blcli_execute Job getJobVersionId

              blcli_storeenv jobVersionId

              echo "JobVersion before run: ${jobVersionId}:${JOB_DBKEY}"

              blcli_execute  Job executeJobAndWaitForRunID "$JOB_DBKEY";

              blcli_storeenv JOB_RUN_DBKEY

              JOB_IS_RUNNING=true

              while [[ ${JOB_IS_RUNNING} = true ]]

                      do

                      blcli_execute JobRun findByJobRunKey "$JOB_RUN_DBKEY";

                      blcli_execute JobRun getIsRunning;

                      blcli_storeenv JOB_IS_RUNNING;

              done

              echo "JOB_DBKEY: ${JOB_DBKEY}"

              blcli_execute JobRun findLastRunByJobKey "$JOB_DBKEY";

              blcli_execute JobRun getDBKey

              blcli_storeenv jobRunKey

              blcli_execute Job findByDBKey ${JOB_DBKEY}

              blcli_execute Job getJobId

              blcli_storeenv jobId

              blcli_execute Job findLatestById ${jobId}

              blcli_execute Job getJobVersionId

              blcli_storeenv jobVersionId

              echo "JobVersion after run: ${jobVersionId}"

              1 of 1 people found this helpful
              • 4. Re: [ NSH ] JobRun findLastRunByJobKey issue
                Clement BARRET

                HI Bill Robinson,

                 

                Thanks for the answer.

                 

                I've run your script on my test NSH Script Job :

                 

                % ./bill_robinson.nsh

                JobVersion before run: 495:DBKey:SJobModelKeyImpl:2030171-495-2228349

                JOB_DBKEY: DBKey:SJobModelKeyImpl:2030171-495-2228349

                JobVersion after run: 495

                 

                 

                What does this flag ?

                 

                blcli_setjvmoption -Dcom.bladelogic.cli.execute.quietmode.enabled=true

                 

                Regards,

                 

                               Clément BARRET

                1 of 1 people found this helpful
                • 5. Re: [ NSH ] JobRun findLastRunByJobKey issue
                  Bill Robinson

                  https://docs.bmc.com/docs/display/public/bsa86/NSH+performance+commands

                  -Dcom.bladelogic.cli.execute.quietmode.enabled=true

                  Suppresses output in the console if ablcli_execute command completedsuccessfully.

                   

                   

                  so that's strange - you should only get that error if the job is changed between when you run it and when you dump the results.  from what i recall the problem was that the job run was associated w/ an older version of the job and was not getting pulled w/ the newer db key.  in think instead i'd dump all the run keys and pull the last one out.

                  1 of 1 people found this helpful
                  • 6. Re: [ NSH ] JobRun findLastRunByJobKey issue
                    Clement BARRET

                    I've found the solution out !

                     

                    Every time you clear the targets of a given job, it will create a new version of this job in the BladeLogic database so this job will be given a new DBKey *but* its current jobId won't change !

                     

                    So I modified my code to retrieve the JobId instead of the DBKey and it worked.

                     

                    Basically my code looks like this :

                     

                    blcli_exec_silent JobRun findLastRunByJobId "${MY_JOB_ID}";

                     

                    blcli_exec_silent JobRun getJobRunId;

                     

                    JOBRUN_ID="$BLCLI_OUTPUT";

                     

                    blcli_exec_silent Utility exportNSHScriptRun "${JOBRUN_ID}" "/path/to/my/logfile}";

                     

                     

                    Sorry for the messed up questions...

                     

                    Regards

                    • 7. Re: [ NSH ] JobRun findLastRunByJobKey issue
                      Bill Robinson

                      yes - that's what i said in april:

                       

                      This is QM001804227 which is fixed in 8.3.03 and 8.5.00.