3 Replies Latest reply on Mar 10, 2015 2:55 AM by R V

    How Can I Call BladeLogic from Java?

    John Van Ommen

      BMC does not have a Java API for BladeLogic, or at least not one that is publically available.

       

      We *do* have BLCLI and we can call that from Jython.

       

      Has anyone figured out how to call it from Java?

       

      I did some poking around with Reflection, and it appears that it may be possible to reference the BladeLogic Java classes.

       

      If anyone wants to explore this themselves, here's how I did it:

       

      1) get all of your BladeLogic jars, copy them into a folder, and explode them with jar (jar tvf [your bladelogic jars])

      2) Oracle has a Java class named "ClassSpy" that can tell you what methods are available from a given class

      3) Using Oracle's "ClassSpy", you can get the BladeLogic methods like this:

       

      java -cp . ClassSpy com.bladelogic.om.infra.cli.CLIClient

       

      Class:

        com.bladelogic.om.infra.cli.CLIClient

       

      Package:

        com.bladelogic.om.infra.cli

       

      Constuctors:

        public com.bladelogic.om.infra.cli.CLIClient()

       

      Fields:

        -- No Fields --

       

      Methods:

        public static void com.bladelogic.om.infra.cli.CLIClient.main(java.lang.String[]) throws java.io.IOException

        public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException

        public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException

        public final void java.lang.Object.wait() throws java.lang.InterruptedException

        public boolean java.lang.Object.equals(java.lang.Object)

        public java.lang.String java.lang.Object.toString()

        public native int java.lang.Object.hashCode()

        public final native java.lang.Class<?> java.lang.Object.getClass()

        public final native void java.lang.Object.notify()

        public final native void java.lang.Object.notifyAll()

       

       

      Classes:

        -- No member interfaces, classes, or enums --

        • 1. Re: How Can I Call BladeLogic from Java?
          John Van Ommen

          Here's "CLI.py", which is how we use Jython to access BLCLI.
          If you want to access BLCLI from Java, there should be some hints on how to do it in here.



          import sys

           

           

          from com.bladelogic.om.infra.cli import CLIMain;

          from com.bladelogic.om.infra.app.option import BlOptionsManager;

           

           

          class CLI:

                  """The main class for accessing BLCLI commands"""

                  def __init__(self):

                          """Set defaults for every detail we need except the app server"""

                          # userfile has a default in the java, so we don't set one here

                          self.params = {

                                  "debug" : None,

                                  "optionsManager" : BlOptionsManager(),

                          }

           

           

                  def __getitem__(self,param):

                          return self.params[param]

           

           

                  def __setitem__(self,param,value):

                          self.params[param] = value

           

           

                  def debug(self,text):

                          """Basic operational debugging"""

                          if self["debug"]:

                                  print text

           

           

                  def setAppServerHost(self, host):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.APP_SERVER_HOST_OPT, host);

           

           

                  def setAppServerPort(self, port):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.APP_SERVER_PORT_OPT, port);

           

           

                  def setAppServerDirectoryPort(self, port):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.APP_SERVER_DIRECTORY_PORT_OPT, port);

           

           

                  def setOperatingMode(self, opmode):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.OPERATING_MODE_OPT, opmode);

           

           

                  def setRoleName(self, role):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.ROLE_NAME_OPT, role);

           

           

                  def setUserName(self, user):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.USER_NAME_OPT, user);

           

           

                  def setPassword(self, password):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.USER_PASSWORD_OPT, password);

           

           

                  def setInteractiveLogin(self, trueFalse):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.INTERACTIVE_LOGGIN_OPT, trueFalse);

           

           

                 def setLanguage(self, language):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.LANGUAGE_OPT, language);

           

           

                  def setServiceProfileName(self, name):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.SERVICE_PROFILE_NAME_OPT, name);

           

           

                  def setServiceProfileFile(self, file):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.SERVICE_PROFILES_FILE_OPT, file);

           

           

                  def setSsoCredentialCache(self, file):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.SSO_CRED_CACHE_OPT, file);

           

           

                  def setTrustedCertificateStore(self, file):

                          options = self.params["optionsManager"];

                          options.setOptionValue(BlOptionsManager.SSO_TRUSTED_CERT_KEYSTORE_OPT, file);

           

           

                  def connect(self):

                          options = self.params["optionsManager"];

                          CLIMain.initializeBRProfile(options);

                          cli = CLIMain(options);

                          self.params["cli"] = cli

                          cli.loginToAppServer();

                          dir(cli)

           

           

                  def run(self,ary):

                          """Execute a single BLCLI command"""

                          self.debug("> " + " ".join([str(item) for item in ary]))

           

           

                          try:

                                  nameSpace = ary.pop(0)

                                  commandName = ary.pop(0)

                          except TypeError,detail:

                                  print "uh, still a problem with types:", detail

                                  import sys

                                  sys.exit(11)

           

           

                          try:

                                  result = self.params["cli"].executeCommand(nameSpace, commandName, ary);

           

           

                                  if result.success():

                                          self.debug("=> " + str(result.returnValue))

                                          return result

                                  else:

                                          self.debug(": " + str(result.getError()))

                                          return result

           

           

                          except TypeError, detail:

                                  print "=> Type error:", detail

                          except com.bladelogic.cli.factory.CommandNotFoundException, detail:

                                  print "=> Factory error:", detail

          • 2. Re: How Can I Call BladeLogic from Java?

            John,

             

            I've found http://jd.benow.ca/#jd-gui useful for examining the JAR's.

             

            God bless,

            -John.

            • 3. Re: How Can I Call BladeLogic from Java?
              R V

              Another way of getting further is activating the API logging.

               

              In the NSH/br/deployments/default-dir (or any other <deployment>-subdir) we have log4j.properties to enable DEBUG-logging or any of the other predefined valuable logging-"definitions".

               

              Especially you could activate:

               

              # Be sure to include only the appenders you want:

              #log4j.logger.com.bladelogic.om.infra.message.app.APIUsage=DEBUG, APICONSOLE, APIFILE, SOCKET_APPENDER

              and the corresponding following lines. In my dev-environment I set:

               

              log4j.logger.com.bladelogic.om.infra.message.app.APIUsage=DEBUG, APIFILE

              log4j.appender.APIFILE=org.apache.log4j.RollingFileAppender

              log4j.appender.APIFILE.File=/tmp/server_api_usage.txt

              log4j.appender.APIFILE.layout=org.apache.log4j.PatternLayout

              log4j.appender.APIFILE.layout.ConversionPattern=%m%n

              Then you get a bunch of lines like:

              828, 46, 2, 359, 865, com.bladelogic.om.infra.model.server.ServerService_findAllDeviceHeaders()

              This is part of the output from "blcli_execute Server listAllServers" and as you can see, there is a class-reference (com.bladelogic.om.infra.model.server.ServerService) and a method-call (findAllDeviceHeaders()).

               

              The only problem seems to be to get the ServerService-object.