8 Replies Latest reply on Sep 19, 2013 2:13 AM by Stéphane Leibovitsch

    How to handle java.util.Set objects in BLCLI ?

      Hi all,

       

      Some API functions return java.util.Set objects but, unlike java.util.List, I can find to API function to handle these objects.

       

      Thanks for your help.

       

      Stéphane

        • 1. Re: How to handle java.util.Set objects in BLCLI ?

          Hi Stephane,

           

          How are you calling the API?  Are you using standard NSH or are you using Jython?

           

          God bless,

          -John.

          • 2. Re: How to handle java.util.Set objects in BLCLI ?

            Hi John

             

            I'm using blcli_execute with NSH. Things would be much easier with Jython since we can handle native Java types.

             

            King regards

            Stéphane

            • 3. Re: How to handle java.util.Set objects in BLCLI ?
              Bill Robinson

              most of the time i've found you can't...  can you provide an example of what you are doing ?

              • 4. Re: How to handle java.util.Set objects in BLCLI ?

                Hi Stephane,

                 

                I had a similar issue a while back and ended up simply moving to Jython to resolve it.  I found that often the data that is available purely through NSH gets converted to a string representation, rather than making the underlying objects available.  That's one of the reasons I advise my clients to use Jython in many cases!

                 

                God bless,

                -John.

                • 5. Re: How to handle java.util.Set objects in BLCLI ?

                  Hi Bill,

                   

                  I'd like to find the name of the repeater server for any target server, and for my first tacklings at the problem, I'm trying to find all Routing Policies using the following call :

                   

                  /bmc/bladelogic/NSH # blcli_execute RoutingPolicy findAll-api
                  [com.bladelogic.om.infra.model.route.RepeaterRoutingPolicyImpl@6f7e982f, com.bladelogic.om.infra.model.route.JobRoutingPolicyImpl@42c71191, com.bladelogic.om.infra.model.route.NetProxyRoutingPolicyImpl@2e1ed620, com.bladelogic.om.infra.model.route.RemoteHostAuthenticationRoutingPolicyImpl@71784911, com.bladelogic.om.infra.model.route.WorkItemRoutingPolicyImpl@5b2bc407]

                   

                  BAS001:/opt/bmc/bladelogic/NSH # blcli_execute Utility setTargetObject
                  [com.bladelogic.om.infra.model.route.RepeaterRoutingPolicyImpl@6f7e982f, com.bladelogic.om.infra.model.route.JobRoutingPolicyImpl@42c71191, com.bladelogic.om.infra.model.route.NetProxyRoutingPolicyImpl@2e1ed620, com.bladelogic.om.infra.model.route.RemoteHostAuthenticationRoutingPolicyImpl@71784911, com.bladelogic.om.infra.model.route.WorkItemRoutingPolicyImpl@5b2bc407]

                   

                  bladmin@VUHPLABSPBAS001:/opt/bmc/bladelogic/NSH # blcli_execute Utility listLength
                  Command execution failed. java.lang.IllegalArgumentException: Input object was not a list : [com.bladelogic.om.infra.model.route.RepeaterRoutingPolicyImpl@6f7e982f, com.bladelogic.om.infra.model.route.JobRoutingPolicyImpl@42c71191, com.bladelogic.om.infra.model.route.NetProxyRoutingPolicyImpl@2e1ed620, com.bladelogic.om.infra.model.route.RemoteHostAuthenticationRoutingPolicyImpl@71784911, com.bladelogic.om.infra.model.route.WorkItemRoutingPolicyImpl@5b2bc407]
                  bladmin@VUHPLABSPBAS001:/opt/bmc/bladelogic/NSH #

                  • 6. Re: How to handle java.util.Set objects in BLCLI ?

                    John,

                     

                    unfortunately, this is not the choice made in my team. If I were to make a choice I wouldn't choose NSH.

                     

                    Kind regards

                    Stéphane

                    • 7. Re: How to handle java.util.Set objects in BLCLI ?
                      R V

                      Hi Stéphane,

                       

                      unfortunately - as you already found out - there is no such "Set"-function like there are "List"-functions. That's why "Utility.listPrint" in your code throws an exception. But you could work around this with not that much extra-effort. First - find the following code (as I have no RoutingPolicy I used RBACRole.findAllAuthsForRole to generate a java.util.Set-object) - and yes, one word of warning - BLAdmins role has a LOT of authorizations, so better use some other role to test ;-)

                       

                      # to make the output readable...

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

                       

                      blcli_execute RBACRole getRoleIdByName BLAdmins
                      blcli_storeenv roleId
                      blcli_execute RBACRole findAllAuthsForRole $roleId
                      blcli_execute Utility setTargetObject
                      blcli_execute Authorization getBlAuthId
                      blcli_storeenv authIdSet
                      for authId in $authIdSet; do
                        myAuthId=$(echo $authId | tr -d '[],')
                        blcli_execute Authorization findById $myAuthId
                        blcli_execute Authorization getName
                        blcli_storeenv myAuthName
                        echo "MyAuthId: $myAuthId, MyAuthName: $myAuthName"
                      done

                       

                      The Authorization.getBlAuthId generates a Set of Ids which is stored as string in "authIdSet". Through this authIdSet you could loop just using the NSH. The first "authId" which is extracted from this string start with the "[" and ends with a "," while all but the last extracted authIds only have the ending ",". The last one just ends with a "]". All this you could see, if you echo the authIdSet-variable. The "tr -d '[],'" now deletes all of these three characters from the variable content - et voila - here you have your single auth-ID, which you could use further.

                       

                      Be sure to have some values in "authIdSet" that do not contain spaces! I.e. IDs, DBKeys, or - mmh, maybe these two are the only good candidates for the iteration.

                       

                      Of course if the task was to get the single Authorization's-names there would be an easier way, but as an example for processing a Set-object, this may help ;-)

                       

                      Regards,

                      Reinhard

                      • 8. Re: How to handle java.util.Set objects in BLCLI ?

                        Hi Reinhard,

                         

                        Thanks for your very detailed answer.

                         

                        I was so much focused on using BLCLI API that I forgot I could parse the result using classical shell tricks.

                         

                        Kind regards

                        Stéphane