6 Replies Latest reply on Jan 22, 2014 10:02 AM by Olivier RENAULT

    How to get if a run batch job had errors ?

      Hi !

       

      I'm using jython to retrieve some informations from bladelogic.

       

      I've written some code in order to launch a job and to find if it's ok or not.

       

      For a deploy job, all is ok, I can find the result (failed or pass) for the job run.

      But for the batch job, I don't know how to get this information.

       

      This is an extract of my code:

       

       

      def BatchGetDBKeyByGroupAndName(self,groupName,jobName):

            cmd = ['BatchJob','getDBKeyByGroupAndName',groupName,jobName]

            handle = self.jli.run(cmd)

            if(handle.success()):

                getDBKeyByGroupAndName = handle.returnValue

                returnvalue = handle.returnValue

            else:

                print "Failed to retrieve the BatchgetDBKeyByGroupAndName for batchJob groupName,jobName "+groupName+","+jobName+"."

                returnvalue = 0

            return returnvalue

       

      def BatchExecuteJobAndWait(self,jobKey):

            cmd = ['BatchJob','executeJobAndWait',jobKey]

            handle = self.jli.run(cmd)

            if(handle.success()):

                returnvalue = handle.returnValue

                print "DEBUG: Launch BatchJob %s ..." % returnvalue

            else:

                print "Failed to launch the batchjob job."

                returnvalue = 0

            return returnvalue

       

      def jobRunKeyToJobRunId(self,jobRunKey):

            cmd = ['JobRun','jobRunKeyToJobRunId',jobRunKey]

            handle = self.jli.run(cmd)

            if(handle.success()):

                returnvalue =  handle.returnValue

                print "DEBUG: jobRunKeyToJobRunId %s" % returnvalue

            else:

                print "ERROR, can't retrieve the job run ID from a job run key."

                returnvalue = -1

          return returnvalue

       

       

      The main call is:

       

            BatchJobKey = self.BatchGetDBKeyByGroupAndName(blGroupName,blJobName)

            if(BatchJobKey != 0):

                 BatchJobRunKey = self.BatchExecuteJobAndWait(BatchJobKey)

                 if(BatchJobRunKey != 0):

                      BatchJobRunId = self.jobRunKeyToJobRunId(BatchJobRunKey)

                      if(BatchJobRunId != 0):

                         batchJobHadErrors = ???? (I want to use the getHadErrors here...)

       

      Thanks for your help

       

      Olivier