10 Replies Latest reply on Apr 12, 2016 3:41 PM by richard mcleod

    blcli with batch job members

    richard mcleod

      so i have a member nsh script job which i want to run
      blcli_execute Job findBatchJobKeysByMemberJob

       

      this returns a list ~ [DBKey:SBatchJobJobKeyImpl:1094915-34-1260734-1-11, DBKey:SBatchJobJobKeyImpl:1094915-35-1260734-1-10]

       

      i am able to iterate through the list but i am at a loss for what namespace to use with these values to get more info (like name, etc...)

       

      I've tried Job, JobRun, BatchJob, BatchJobRun, SJobHeader...

       

      need some help

        • 1. Re: blcli with batch job members
          Bill Robinson

          Utility listPrint will convert it to a list.  you then have a list of job keys.  What do you want to do ?

          • 2. Re: blcli with batch job members
            richard mcleod

            I've converted it to a list already. I am having a problem finding the proper namespace to extract meaningful data from the dbkey...

             

            this is what im using (loose -- borrowed some code from you)

             

             

            blcli_execute Job findBatchJobJobKeysByMemberJob "DBKey:SJobModelKeyImpl:1260734-3-45890595"

            blcli_execute Utility storeTargetObject tlBatchJobKeys

            blcli_execute Utility listLength

            blcli_storeenv tlBatchLength

            echo "\ntlBatchLength: ${tlBatchLength}\n"

            blcli_execute Utility setTargetObject tlBatchJobKeys

            blcli_execute Utility listPrint

            blcli_storeenv tlBatchJobKeys

             

             

            for k in {0..$((${tlBatchLength}-1))}

            do

            blcli_execute Utility setTargetObject tlBatchJobKeys

            blcli_execute Utility listItemSelect ${k}

            blcli_execute Utility setTargetObject

            blcli_execute JobRun getJobRunId

            blcli_storeenv bjobName

            echo "\n ::NAME:: $bjobName :: $k \n"

            done

            • 3. Re: blcli with batch job members
              Bill Robinson

              so if you have this:

              blcli_execute Utility storeTargetObject tlBatchJobKeys

              and you do:

              for k in {0..$((${tlBatchLength}-1))}

              do

              blcli_execute Utility setTargetObject tlBatchJobKeys

              blcli_execute Utility listItemSelect ${k}

               

              you are selecting objects from the java list object tlBatchJobKeys.

               

              if you do this:

              blcli_execute Utility setTargetObject tlBatchJobKeys

              blcli_execute Utility listPrint

              blcli_storeenv tlBatchJobKeys

               

              then it's a shell variable w/ a string list and you'd do like:

              while read jobKey

              do

              blcli_execute Job findByDBKey ${jobKey}

              ...

              done <<< "${tlBatchJobKeys}"

              • 4. Re: blcli with batch job members
                richard mcleod

                yes but my main problem is the SBatchJobKeyImpl cannot be used by the Job namespace...

                 

                Command execution failed. com.bladelogic.om.infra.mfw.util.BlException: Unexpected exception while handling request.com.bladelogic.om.infra.app.api.JobService_findByDBKey(com.bladelogic.om.infra.model.base.keys.DBKey): java.lang.ClassCastException: com.bladelogic.om.infra.model.base.keys.SBatchJobJobKeyImpl cannot be cast to com.bladelogic.om.infra.model.base.keys.SJobKey

                Command execution failed. java.lang.Throwable: Command Execution Failed: java.lang.Throwable: Command Execution Failed

                Cannot store a failed command result

                • 5. Re: blcli with batch job members
                  Bill Robinson

                  oh - i see.  what are you trying to do - find the batch keys that a job is a member of ?  then what ?

                  • 6. Re: blcli with batch job members
                    richard mcleod

                    from my nsh script which is a member of a batch job i am trying to find the other jobs that are part of the batch and then grabbing info about each job (name, job id, location, etc)

                    • 7. Re: blcli with batch job members
                      Bill Robinson

                      Another option is the dependency dump and some text processing.

                      • 8. Re: blcli with batch job members
                        richard mcleod

                        Eventually what i want to get to is a nested batch job which runs compliance + auto-remediation. I want to find that auto-remediation job and ensure it ran. (We've been seeing randomly where the remediation compliance runs, there are non-compliant rules but the auto-remediation job is never run but there are no errors reported by bladelogic so we end up with servers saying they've completed successfully when infact they haven't.) If I am able to confirm the auto-remediation job did not run then i can have our nsh script exit 1 as a bandaid for the bsa issue.

                        • 9. Re: blcli with batch job members
                          Bill Robinson

                          yeah - i don't see anything to handle objects of type DBKey:SBatchJobJobKeyImpl.

                           

                          you could use:

                          -----

                          blcli_execute Delete findAllDependentObjects 30 ${jobKey} false false

                          and scrape the results for any 'type=200' (batch job)

                          |

                          |---Model Object : cve1 @2016-03-15 21:59:37:728-0400, type=30, db_key=DBKey:SJobKeyImpl:2000465-1, address=3590aa10

                          |   |

                          |   |---Model Object : cve1 @2016-03-15 21:59:37:779-0400, type=200, db_key=DBKey:SJobKeyImpl:2000466-2, address=8e897301

                          |   |   |

                          |   |   |---Model Object : , type=394, db_key=DBKey:SJobRunKeyImpl:2008722, address=a0903cfc

                          |   |   |

                          |   |   |---Model Object : , type=394, db_key=DBKey:SJobRunKeyImpl:2008821, address=a09040bc

                          |   |

                          |   |---Model Object : , type=380, db_key=DBKey:SJobRunKeyImpl:2008723, address=faa3ff5a

                          |   |   |

                          |   |   |---Model Object : , type=394, db_key=DBKey:SJobRunKeyImpl:2008722, address=a0903cfc

                          |   |

                          |   |---Model Object : , type=380, db_key=DBKey:SJobRunKeyImpl:2008822, address=faa4031a

                          |   |   |

                          |   |   |---Model Object : , type=394, db_key=DBKey:SJobRunKeyImpl:2008821, address=a09040bc

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

                           

                          or use the Utility.exportDependencyGraph and scrape that.

                          • 10. Re: blcli with batch job members
                            richard mcleod

                            You should be able to run this inside of any nsh script which is inside of a batch and mostly piece together the entire batch. needs some better recursion to truly traverse all levels but this will go 3 batch jobs deep

                             

                             

                             

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

                            NSH_JOB_LRUN_ID=$(echo $NSHSCRIPTINFO|awk -F'/' '{print $13}'|awk -F'_' '{print $2}'|awk -F'-' '{print $3}')

                            blcli_execute Job getLastJobDBKeyByJobId ${NSH_JOB_LRUN_ID}

                            blcli_storeenv NSH_JOB_DBKEY

                            blcli_execute Job findBatchJobJobKeysByMemberJob "$NSH_JOB_DBKEY"

                            blcli_execute Utility listPrint

                            blcli_storeenv jobKeys

                            BATCHJOBID=$(echo $jobKeys|head -1|awk -F':' '{print $3}'|awk -F'-' '{print $1}')

                            blcli_execute Job getLastJobDBKeyByJobId $BATCHJOBID

                            blcli_storeenv batchJobDBKey

                            blcli_execute BatchJob getName

                            blcli_storeenv batchJobName

                            blcli_execute BatchJob getMemberJobCountByJobKey "$batchJobDBKey"

                            blcli_storeenv memberCount

                            blcli_execute BatchJob getFullyQualifiedPath

                            blcli_storeenv batchJobPath

                            blcli_execute BatchJob getExecutionUser

                            blcli_storeenv batchJobExecutedByUser

                            blcli_execute BatchJob getExecutionRole

                            blcli_storeenv batchJobExecutedByRole

                            echo "Name=$batchJobName , JobID=$BATCHJOBID , DBKey=$batchJobDBKey"

                            echo "FQPath=$batchJobPath"

                            echo "Execution User=$batchJobExecutedByUser , Execution Role=$batchJobExecutedByRole"

                             

                             

                            blcli_execute BatchJob findAllSubJobHeadersByBatchJobKey "$batchJobDBKey"

                            blcli_execute Utility storeTargetObject sJobHeaders

                            blcli_execute Utility listLength

                            blcli_storeenv memberCount1

                             

                             

                            for i in {0..$((${memberCount1}-1))}

                            do

                              blcli_execute Utility setTargetObject sJobHeaders

                              blcli_execute Utility listItemSelect ${i}

                              blcli_execute Utility setTargetObject

                              blcli_execute SJobHeader getName

                              blcli_storeenv sJobName

                              blcli_execute SJobHeader getJobId

                              blcli_storeenv sJobId

                              blcli_execute SJobHeader getDBKey

                              blcli_storeenv sJobDBKey

                              blcli_execute SJobHeader getObjectTypeId

                              blcli_storeenv sJobType

                             

                              echo "Name=$sJobName , JobID=$sJobId , DBKey=$sJobDBKey , Type=$sJobType"

                             

                              if [[ "$sJobType" = "200" ]]; then

                              blcli_execute BatchJob findAllSubJobHeadersByBatchJobKey "$sJobDBKey"

                              blcli_execute Utility storeTargetObject sJobHeaders2

                              blcli_execute Utility listLength

                              blcli_storeenv memberCount2

                             

                              for j in {0..$((${memberCount2}-1))}

                              do

                              blcli_execute Utility setTargetObject sJobHeaders2

                              blcli_execute Utility listItemSelect ${j}

                              blcli_execute Utility setTargetObject

                              blcli_execute SJobHeader getName

                              blcli_storeenv sJobName

                              blcli_execute SJobHeader getJobId

                              blcli_storeenv sJobId

                              blcli_execute SJobHeader getDBKey

                              blcli_storeenv sJobDBKey

                              blcli_execute SJobHeader getObjectTypeId

                              blcli_storeenv sJobType

                              echo " |--Name=$sJobName , JobID=$sJobId , DBKey=$sJobDBKey , Type=$sJobType"

                             

                              if [[ "$sJobType" = "200" ]]; then

                              blcli_execute BatchJob findAllSubJobHeadersByBatchJobKey "$sJobDBKey"

                              blcli_execute Utility storeTargetObject sJobHeaders3

                              blcli_execute Utility listLength

                              blcli_storeenv memberCount3

                             

                              for k in {0..$((${memberCount3}-1))}

                              do

                              blcli_execute Utility setTargetObject sJobHeaders3

                              blcli_execute Utility listItemSelect ${k}

                              blcli_execute Utility setTargetObject

                              blcli_execute SJobHeader getName

                              blcli_storeenv sJobName

                              blcli_execute SJobHeader getJobId

                              blcli_storeenv sJobId

                              blcli_execute SJobHeader getDBKey

                              blcli_storeenv sJobDBKey

                              blcli_execute SJobHeader getObjectTypeId

                              blcli_storeenv sJobType

                              echo " | |--Name=$sJobName , JobID=$sJobId , DBKey=$sJobDBKey , Type=$sJobType"

                              done

                              fi

                              done

                              fi

                            done