8 Replies Latest reply on Feb 3, 2011 7:36 AM by Jim Campbell

    BLCLI to run jobs

    Jim Campbell

      Looking at the BLCLI documentation, it looks like the way to run a job using an nsh script is something like:

      Job addTargetServer jobkey servername

      Job executeJobAndWait jobkey

      Job clearTargetServers jobkey


      So it looks like a script of this sort would add the server as a default target of the job (similar to adding it as a target using the UI), execute the job, and then reset the target servers for the job.  Is there nothing similar in terms of blcli functions to the UI's 'Execute Against' option?  If i were to use this methodology, could it interfere with an instance of the job already running, and if someone else were to run the job would it use the targets I had added (perhaps inadvertently?) during the time when the job is running?  Is it a better idea to add the servers, use some other execution function (and i'm not sure which), and remove the servers from the job before the job its finished running?

        • 1. BLCLI to run jobs
          Bill Robinson

          well, there's this:



          or you could use an execution task (8.0)

          • 2. BLCLI to run jobs
            Jim Campbell

            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

            Export Results


            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?

            • 3. Re: BLCLI to run jobs
              Bill Robinson

              make a batch job?

              • 4. Re: BLCLI to run jobs
                Jim Campbell

                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.

                • 5. Re: BLCLI to run jobs
                  Bill Robinson

                  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

                  • 6. Re: BLCLI to run jobs
                    Jim Campbell

                    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?

                    • 7. Re: BLCLI to run jobs
                      Bill Robinson

                      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?

                      • 8. Re: BLCLI to run jobs
                        Jim Campbell

                        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.