For an execution task, is there some other methodology to run tasks in sequence? It seems like for any normal job there is a executeJobAndWait command that allows you to wait for the job to complete within a script. Also, you can get results for a JobRun and easily list the most recent job run. I'd like to be able to:
Run Discovery for a given Component Template
Execute a compliance job
without having to move the target server into any of the jobs. Is there an easy way to use the CLI to script this that I'm missing?
make a batch job?
A batch job seemed like the easy way, and I felt stupid for not thinking of it, but I'm missing something to get it to work. I can run the discovery and compliance job on a target of the batch job without having to add the server as a target of the batch's constituent jobs, but I can't find any convenient way to export the results. Utility exportComplianceRunLatest doesn't work because it will export the wrong run if two jobs are running at the same time. So the basic options I see (and no idea if either is actually feasible given the limitations of the blcli)
1. Iterate through each Run of the compliance job, check the target list (does this get returned as something usable?), and check to see if the target includes the server in question. This seems like it could take too long as the number of job runs increases.
2. Find the run id of the parent batch job (not sure if this is available) and use that to find the run id's of the member jobs, then figure out which of those corresponds to the compliance job. I'm not sure if this is possible because I don't know of any way to get any information about the parent batch job from within an nsh script.
the child jobs in the batch should be run sequentially. So that last job should be able to get the latest run of the compliance job, maybe add a sleep to the nsh job to see if you just need to wait for the other job to show as finished (even though it should be finished).
You might be able to pull the compliance job run by using the targets of the nsh job
It does get the last run the compliance job. However, if another instance of the batch job is running against a different target, it will pick up this run of compliance job instead of the one included in the batch. E.g. if you start the batch against targetA, start it against targetB, then by the time the batch job that includes targetA gets to the exporting job of the batch the latest run of the compliance job is the one that uses targetB and this is the one that gets exported.
There is a JobRun getServerTargetsForJobRunId but it returns a java.util.Set so I'm not sure how to use that. Also I would be worried this would take a long time to iterate through each JobRunId, check the list of target servers, and see if the target server is included.
Is there no way to get the runid of the batch job from within a member job run?
instead of doing this in a batch job, what about doing it in a nsh script.
use the 'ComplianceJob.executeJobAndWait' - this will run your job and return the jobrunkey, which you can convert to a jobrunid or whatever elese you need to feed to the next command to dump your reults.
would that work?
That was my original idea from the first post, but the problem that I find is that there is no 'Execute Against' option in the CLI. So my understanding is that I would have to add the target server to the job's default targets and then run ComplianceJob.executeJobAndWait. But then when another job starts, it will still have the target from the first job. It might be possible to use another execution method that just gets the runId and quickly remove the the target server before the job has finished (and use a loop to periodically check if the job has completed before moving on on the script) but that risks two jobs being run at exactly the same time colliding with each other.
For this problem, I've found a way that I think works at least in our situation. I've been using Component.getAllDBKeyByTemplateAndServer to get the Component for our compliance template for a specific server (the function name indicates there could be more than one component for a template/server combination but I'm not sure how). Then with Component.findHeaderViewByDBKey and ComplianceJobResult.findJobRunsForComponent I can find a list of the RunIds for the compliance job that were run against a component (which in our situation will be a much smaller number than the total number of runs of the job, and usually will be only one run since its a QA compliance job for newly-provisioned servers). From there it doesn't take long to iterate through the small number of job runs to find the most recent one and export.