Share:|

Continuing the series of listallthethings, iIf I want to list all the jobs in a group there's an existing command:

blcli_execute Job listAllByGroup "/Workspace/MyJobs"

And that lists out all the Job names in the (static) group.  Unfortunately that list isn't very actionable unless you already know what type of jobs they all are.  And I can't use the same command and a Smart Job Group. Instead I'd like a way to list the contents of a Static or Smart Job Group that gives me the DBKey or Id to the Job.  Most of the time when working with objects in BSA you need the DBKey to do anything with the object - update a property, run the job, rename it, etc.  And if you do need the name and path to the object, if you have the DBKey you can figure out the name, type, group path, etc.  I mentioned having only the name and path (e.g. the Job.listAllByGroup) isn't actionable because I won't know the type, and you need to know the type in order to use the specific namespace commands like AuditJob, SnapshotJob, etc.

 

Let's look in the Job.listAllByGroup command in the Unreleased blcli commands and documentation and see what's being run:

CommandInputReturn value stored name
JobGroup.groupNameToId$qualifiedGroupName$groupId
Job.findAllHeadersByGroupNAMED_OBJECT=groupId-
SJobHeader.getNameno input-
Utility.setTargetObjectno input-
Utility.listPrintno input-

So just like the List All The Servers it's using the object header and getting the name.  And just like what we did in that post we will look in the SJobHeader namespace to see if there's a command to get the DBKey or id.  And there is, so we can do:

blcli_execute SmartJobGroup groupNameToId "/Workspace/All Jobs"
# or JobGroup.groupNameToId with a Static Job Group
blcli_storelocal jobGroupId
blcli_execute Job findAllHeadersByGroup ${jobGroupId}
blcli_execute SJobHeader getDBKey
blcli_execute Utility setTargetObject
blcli_execute Utility listPrint
blcli_storelocal jobKeys

And as in the Server post we can use SJobHeader.getJobId to get the Job Id instead of the DBKey.

 

and then as before we could iterate through the list of Job Keys and do something like update a property value:

while read jobKey
  do
  blcli_execute Job setPropertyValue ${jobKey} RESULTS_RETENTION_TIME 30
done <<< "$(awk 'NF' <<< "${jobKeys}")"

 

Or maybe I want to update the parallelism setting on the job.  Since I can't find a blcli command to do that directly, it looks like I need to use one of the primitives - Job.setParallelProcs to do it.  That will involve loading the job object and then acting on it, and we can still use same list of job keys we get above:

while read jobKey
   do
    blcli_execute Job findByDBKey ${jobKey}
    blcli_execute Utility storeTargetObject job
    blcli_execute Job setParallelProcs 30
    blcli_execute Job update NAMED_OBJECT=job
done <<< "$(awk 'NF' <<< "${jobKeys}")"

 

Sometimes though I might just want to list out the job, the group path where it exists, the job type, etc.  All of that information seems to be available in commands in SJobHeader.  In that case I want to load the JobHeader object and run some commands against it.

blcli_execute SmartJobGroup groupNameToId "/Workspace/All Jobs"
# or JobGroup.groupNameToId with a Static Job Group
blcli_storelocal jobGroupId
blcli_execute Job findAllHeadersByGroup ${jobGroupId}
blcli_execute Utility storeTargetObject jobHeaders
blcli_execute Utility listLength
blcli_storelocal listLength
for i in {0..$((${listLength}-1))}
    do
    blcli_execute Utility setTargetObject jobHeaders
    blcli_execute Utility listItemSelect ${i}
    blcli_execute Utility setTargetObject
    blcli_execute SJobHeader getName
    blcli_storelocal jobName
    blcli_execute SJobHeader getObjectTypeId
    blcli_storelocal jobTypeId
    blcli_execute SJobHeader getDescription
    blcli_storelocal jobDesc
    blcli_execute SJobHeader getGroupId
    blcli_storelocal jobGrpId
    blcli_execute Group getQualifiedGroupName 5005 ${jobGrpId}
    blcli_storelocal groupPath
    echo "${groupPath}/${jobName},${jobDesc},${jobTypeId}"
done

This will echo out the Job Folder and Name, the description and the object type id for the job.

 

We built on the first post a bit and in addition to listing the objects in a group we pulled some information about them using more from the Unreleased blcli commands and documentation