12 Replies Latest reply on Feb 12, 2015 11:58 AM by Bill Robinson

    Store output to memory for later retrieval

    Narahari Lakshminarayana

      Friends:

       

      I have a job that will try to get the type of a Job by looping thru.  I followed the example here on the forum.

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

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

       

       

      jobGroup=$1

      targetJobName=$2

       

       

      blcli_execute JobGroup groupNameToId "${jobGroup}"

      if [ "$?" -ne "0" ]; then echo "error occured, exitting"; exit 1; fi

       

       

      blcli_storeenv jobGroupId

       

      blcli_execute Job findAllHeadersByGroup ${jobGroupId}

      if [ "$?" -ne "0" ]; then echo "error occured, exitting"; exit 1; fi

       

       

      blcli_execute Utility storeTargetObject jobHeaders

       

       

      blcli_execute Utility listLength

       

       

      blcli_storeenv listLength

       

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

      do

       

       

              blcli_execute Utility setTargetObject jobHeaders

       

       

              blcli_exeacute Utility listItemSelect ${i}

       

       

              blcli_execute Utility setTargetObject

       

       

              blcli_execute SJobHeader getName

       

       

              blcli_storeenv jobName

       

       

              if [[ "${targetJobName}" = "${jobName}" ]]

              then

       

       

                      blcli_execute SJobHeader getDBKey

       

       

                      blcli_storeenv jobKey

       

                      echo "Do some stuff to ${jobKey}"

       

       

                      break

              fi

       

       

      done

       

       

      if [ "${jobKey}" = "" ]; then echo "No job key found, exitting"; exit 1; fi

      blcli_execute Job findByDBKey ${jobKey}

      if [ "$?" -ne "0" ]; then echo "error occured, exitting"; exit 1; fi

      blcli_execute Job getType

      if [ "$?" -ne "0" ]; then echo "error occured, exitting"; exit 1; fi

      blcli_storeenv jobTypeId

       

       

      echo "$jobTypeId"

      Now once I find the job type, I want to store it in memory so I can access it later, in the same session from another job.

       

      What is the process to store it in memory for later usage from another job inside the same session ?

       

      Right now thru WebServices I have read the output of the job and parse that to get my jobType.

       

      -Narahari

        • 1. Re: Store output to memory for later retrieval
          Bill Robinson

          if you are using a shell script then you would store the job type in a shell variable and you could use it later.  for webservices you can put it into a variable in the script driving your webservices calls.

           

          but i'm not sure what you mean by "in the same session from another job."  how will another job be in the same session ?  you are adding more to this script that will manipulate another job ?

          • 2. Re: Store output to memory for later retrieval
            Narahari Lakshminarayana

            Coming to web services approach, What I am trying to do is write the NSHScriptJob and test it.

             

            I have Job-A and Job-B and Job-C

             

            Job-A determines JobType of a given JobGroup/JobName.  This is a common generic job and I can choose to use from any other job.

             

            Job-B calls Job-A by passing the necessary parameters(JobGroupForX and JobX)  and gets the JobType.

            It then decides to call the JobX as appropriate.

             

            Job-C calls Job-A by passing the necessary parameters(JobGroupForN and JobN).  Using the return type Job-C then does something else.

             

            See how Job-B and Job-C are using Job-A for diff purposes.  Job-A is now reusable many times.

             

            When Job-B calls Job-A, how can Job-B get back the output of Job-A

            can I do (pseudo code)

            blcli_execute Job getJobDBKey JobGroupForA Job-A

            blcli_storeenv jobKeyForJobA

            bcli_execute NSHScriptJob executeAndWait jobKeyForJobA JobGroupForX JobX

            blcli_storeenv outputFromJobA

             

            Do I need to do something inside of Job-A so that the output is available for Job-B to make use of that.

             

            -Narahari

            • 3. Re: Store output to memory for later retrieval
              Bill Robinson

              What is ‘output from job x’ here ?  script output ?  success/fail ?

              • 4. Re: Store output to memory for later retrieval
                Narahari Lakshminarayana

                Nothing.  Infact JobX is not important right.

                 

                I am trying to reuse Job-A from other Jobs, in this case Job-B and Job-C.

                 

                This way I can modularize my Jobs and write re-usable Jobs.

                 

                But for that to work I need to be able return values from Job-A.

                 

                -Narahari

                • 5. Re: Store output to memory for later retrieval
                  Narahari Lakshminarayana

                  Any input on this is very much appreciated.

                  • 6. Re: Store output to memory for later retrieval
                    Santhosh Kurimilla

                    How about writting a function (instead of a job) to determine the job type?

                    • 7. Re: Store output to memory for later retrieval
                      Bill Robinson

                      ok, 'return values from job A' - what does that mean ?  can you give an example case w/ some more specifics ?

                      • 8. Re: Re: Store output to memory for later retrieval
                        Narahari Lakshminarayana

                        Sorry for the delayed response.

                         

                        Here is the Job-A

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

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

                         

                        jobGroup=$1

                        targetJobName=$2

                         

                        blcli_execute JobGroup groupNameToId "${jobGroup}"

                        if [ "$?" -ne "0" ]; then echo "error occured, exitting"; exit 1; fi

                        blcli_storeenv jobGroupId

                         

                        blcli_execute Job findAllHeadersByGroup ${jobGroupId}

                        if [ "$?" -ne "0" ]; then echo "error occured, exitting"; exit 1; fi

                        blcli_execute Utility storeTargetObject jobHeaders

                         

                        blcli_execute Utility listLength

                        blcli_storeenv listLength

                         

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

                        do

                                blcli_execute Utility setTargetObject jobHeaders

                                blcli_exeacute Utility listItemSelect ${i}

                                blcli_execute Utility setTargetObject

                                blcli_execute SJobHeader getName

                                blcli_storeenv jobName

                                if [[ "${targetJobName}" = "${jobName}" ]]

                                then

                                        blcli_execute SJobHeader getDBKey

                                        blcli_storeenv jobKey

                                        echo "Do some stuff to ${jobKey}"

                                        break

                                fi

                        done

                         

                        if [ "${jobKey}" = "" ]; then echo "No job key found, exitting"; exit 1; fi

                        blcli_execute Job findByDBKey ${jobKey}

                        if [ "$?" -ne "0" ]; then echo "error occured, exitting"; exit 1; fi

                        blcli_execute Job getType

                        if [ "$?" -ne "0" ]; then echo "error occured, exitting"; exit 1; fi

                        blcli_storeenv jobTypeId

                         

                        echo "$jobTypeId"

                         

                        As you can see the Job-A has the sole purpose of determining the job Type of a given JobGroup/Job-Name combination.

                        At the end of the Job-A, I am currently doing

                        blcli_storeenv jobTypeId

                        echo "$jobTypeId"


                        In a job I call Job-B, I want to be able to execute Job-A, passing in a JobGroup/Job-Name combo, there by obtaining the job-type to do decision making.


                        At the same time, I have another job, Job-C which I want to use to do something else but Job-C also needs to determine the job type of another JobGroup/JobName combination and wants to utilize the services of Job-A.


                        The fact that Job-A is generic and its only purpose is to give out JobType, I want to be able to reuse JobA both inside Job-B and Job-C.

                        The question is if I do blcli_storeenv jobTypeId  in Job-A, can I use that variable  in Job-B or Job-C ?


                        If you need more info please don't hesitate to ask.

                         

                        -Narahari

                        • 9. Re: Re: Store output to memory for later retrieval
                          Santhosh Kurimilla

                          As suggested earlier, Just a thought of creating function for Job-A here.

                          1. Paste the above script for Job-A in a function names findJobType() with the 2 input arguments JobGroup, TargetJobName and save it as some.fun text file. Add it to Depot as File.

                          2. In the script for job-B, load /path/to/some.fun

                          3. Whenever you want to validate the job type, try JbType=$(findJobType "${JobGroup}" "${TargetJobame}") to save the job type in the JbType.


                          Does it help? I will try the same from my side once and confirm it.

                          • 10. Re: Re: Store output to memory for later retrieval
                            Bill Robinson

                            yeah - i would not try and do this in different jobs - you should use a script function for this.  and you can clean up the script a bit:

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

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

                             

                                jobGroup="${1}"

                            targetJobName="${2}"

                             

                                blcli_execute JobGroup groupExists "${jobGroup}"

                                blcli_storeenv groupExists

                               

                                if [[ "${groupExists}" = "false" ]]

                               then
                               echo "Cannot find ${jobGroup}"

                                else

                               blcli_execute JobGroup groupNameToId "${jobGroup}"
                               blcli_storeenv jobGroupId
                               blcli_execute Job findAllHeadersByGroup ${jobGroupId}
                               blcli_execute Utility storeTargetObject jobHeaders
                               blcli_execute Utility listLength
                               blcli_storeenv listLength

                             

                               for i in {0..$((${listLength}-1))}
                               do
                                    blcli_execute Utility setTargetObject jobHeaders
                                    blcli_exeacute Utility listItemSelect ${i}
                                    blcli_execute Utility setTargetObject
                                    blcli_execute SJobHeader getName
                                    blcli_storeenv jobName
                                    if [[ "${targetJobName}" = "${jobName}" ]]
                                    then
                                            blcli_execute SJobHeader getDBKey
                                            blcli_storeenv jobKey
                                            echo "Do some stuff to ${jobKey}"
                                            break
                                    fi
                               jobKey=""
                               done

                             

                               if [[ "${jobKey}" = "" ]]
                               then
                               echo "No job key found, exiting"
                               exit 1
                               fi
                               blcli_execute Job findByDBKey ${jobKey}
                               blcli_execute Job getType
                                blcli_storeenv jobTypeId
                               echo "${jobTypeId}"

                                fi

                             

                             

                             

                            however, i'm still unclear why you need to do this.  if you want to run a job then you can do that from REST w/o knowing the type.  why do you need to get the job type ?

                            • 11. Re: Re: Store output to memory for later retrieval
                              Narahari Lakshminarayana

                              Sorry for the real late response.

                               

                              The reason this is needed is this.

                               

                              I want to create Job-A whose only purpose is to determine the type of job for a give JobFolder JobName combination.

                               

                              I want to be able to use Job-A from another job and also I want to be able to call Job-A from a WebService as well.

                               

                              As a programming pattern, I should be able to write the Job-A once and use it from another BL Job at the same time

                              Job-A is a utility job that I can call from the web service as well.

                               

                              May be it is not possible to store the output of a Job in memory so it can be retrieved from another job.

                               

                              -Narahari

                              • 12. Re: Re: Store output to memory for later retrieval
                                Bill Robinson

                                you are trying to use a job like a script function.  this is not how bsa was designed.  there is no 'output' from a job like you want.  the right way to do this is to have a script function that gets the information you want.

                                 

                                i'd also ask - why do you even need to do this ?  if you have the job information why do you not know the type and what do you want to do w/ it ?