8 Replies Latest reply on Nov 3, 2011 9:27 AM by Lou Troise

    BatchJob removeMemberJobByJobKeyAndIndex

    R V

      Hi all,

       

      I have to remove a deploy-job from a batch job and the only possibility seems to be the named function.

       

      But: how can I get this "index"? There should be a "getIndexForMemberJob"-function but I didn't find something like that.

       

      Regards,

      Reinhard

        • 1. Re: BatchJob removeMemberJobByJobKeyAndIndex
          Bill Robinson

          maybe something w/ the output of findAllSubJobHeadersByBatchJobKey and Utility.listItemSelect

           

          you can try to dump the member jobs, and then w/ the key or name of the job you want to remove, find the index number.

          • 2. Re: BatchJob removeMemberJobByJobKeyAndIndex
            Bill Robinson

            I couldn't find a way to do this w/ the blcli entirely.  i had to use some shell logic.  here's what I did:

             

            blcli_execute BatchJob getDBKeyByGroupAndName "/path/to/batchjob" "batchJobName"

            blcli_storeenv batchJobKey

            # This is the job I want to remove from the batch.

            blcli_execute NSHScriptJob getDBKeyByGroupAndName "/Sample Workspace/All Jobs by User/BLAdmin" "foo"
            blcli_storeenv removeKey

            blcli_execute BatchJob findAllSubJobHeadersByBatchJobKey ${batchJobKey}

            blcli_execute Job getDBKey
            blcli_execute Utility setTargetObject
            blcli_execute Utility listPrint
            blcli_storeenv jobList
            count=0

            for job in $jobList

            do

                 if [ $job = $removeKey ]

                      then

                      removeIndex=$count

                 else

                      count=$((count+1))

                 fi

            done

            blcli_execute BatchJob removeMemberJobByJobKeyAndIndex $batchJobKey $removeIndex

             

            I tried this w/ the job names, but there does not seem to be a way to get the job names from the memberjob headers. so you need to find the dbkey to the job you are removing.

            • 3. Re: BatchJob removeMemberJobByJobKeyAndIndex

              Yes, indeed, getName doesn't seem to work from the list of sub jobs. However, you can get the job Name from your list in shell:

               

              blcli_execute BatchJob getDBKeyByGroupAndName "/path/to/batchjob" "batchJobName"

              blcli_storeenv batchJobKey

              # This is the job I want to remove from the batch.

              blcli_execute NSHScriptJob getDBKeyByGroupAndName "/Sample Workspace/All Jobs by User/BLAdmin" "foo"
              blcli_storeenv removeKey

              blcli_execute BatchJob findAllSubJobHeadersByBatchJobKey ${batchJobKey}

              blcli_execute Job getDBKey
              blcli_execute Utility setTargetObject
              blcli_execute Utility listPrint
              blcli_storeenv jobList
              count=0

              for job in $jobList

              do

                  blcli_execute Job getJobNameByDBKey $job
                   blcli_storeenv jobName

               

              # Change the logic below to compare by job name

                   if [ $job = $removeKey ]

                        then

                        removeIndex=$count

                   else

                        count=$((count+1))

                   fi

              done

              blcli_execute BatchJob removeMemberJobByJobKeyAndIndex $batchJobKey $removeIndex

              1 of 1 people found this helpful
              • 4. Re: BatchJob removeMemberJobByJobKeyAndIndex
                R V

                Thank you VERY MUCH guys!!! You saved my life ;-)

                 

                There is also a currently open ticket (ISS03529316) which hopefully will lead to a brandnew function in the blcli (Utility saveMyLife, no, just kidding) BatchJob getMemberIndexByDBKeyAndName.

                 

                Thanks again!

                 

                Additional info: the important step was "Utility setTargetObject" so I could operate on the DBKEY-list instead of the SubJobHeader-list (how are these items which are output by "BatchJob findAllSubJobHeadersByBatchJobKey" - like "com.bladelogic.model.base.header.SJobHeaderImpl@18e8541" called?)

                 

                Nachricht geändert durch rvielhaber: added "Additional info"-stuff

                • 5. Re: BatchJob removeMemberJobByJobKeyAndIndex
                  Bill Robinson

                  w/ the job name it would be easier to match, assuming you do not have 2 jobs of the same name in the batch.

                  • 6. Re: BatchJob removeMemberJobByJobKeyAndIndex

                    Hello,

                     

                    I found this thread helpful in understanding the Utility commands used, but I'm having a difficult time getting the Job getDBKey command working.

                    I have a BatchJob that contains numerous NSHScriptJobs.  I need to scan through the member jobs and remove a target one, just like the original question in this thread.

                     

                    But, my Job getDBKey command consistently returns "Object not an instance of declaring class" error.

                     

                    Here are the suspect lines of my code, which pretty much duplicate this thread: 

                     

                    blcli_execute BatchJob getDBKeyByGroupAndName "/Blah/Blah" "Batch_Job"

                    blcli_storeenv BATCH_KEY

                    echo

                     

                    echo "Find sub job headers"
                        blcli_execute BatchJob findAllSubJobHeadersByBatchJobKey ${BATCH_KEY}
                        echo


                        echo "get DBKey"
                        blcli_execute Job getDBKey
                    #...declaring class error every time right here

                        echo


                        echo "Set Target Object"
                        blcli_execute Utility setTargetObject
                        echo


                        echo "List Print"
                        blcli_execute Utility listPrint
                        blcli_storeenv JOB_LIST
                        echo

                     

                     

                    I'm completely stumped....any help is appreciated as always.

                     

                    Thank You.

                    • 7. Re: BatchJob removeMemberJobByJobKeyAndIndex
                      Bill Robinson

                      try SJobHeader getDBKey

                      • 8. Re: BatchJob removeMemberJobByJobKeyAndIndex

                        That was exactly the issue.  Thanks, Bill!