2 Replies Latest reply: Apr 25, 2012 5:49 AM by 933130 RSS

    Use Jython Module/s in WLST

    emil bolokanov
      Hello,

      To start with I must admit that I`m fairly new to python/jython/wlst.
      Let me try to describe the problem. I wrote a wlst script that starts node manager and then Admin server + managed. It`s something like this :

      [weblogic@weblogic-wlst bin]$ vi StartNodeManager.py
      #Set Variables
      wls_home = '/opt/oracle/Middleware11115';
      pathseparator = '/';
      listen_port = '5556';
      listen_address = 'weblogic-wlst';

      node_manager_home = wls_home + pathseparator + 'wlserver_10.3' + pathseparator + 'common' + pathseparator + 'nodemanager';

      #Start Node Manager
      startNodeManager(verbose='true', NodeManagerHome=node_manager_home, ListenPort=listen_port, ListenAddress=listen_address);

      #Connect to NodeManager
      print 'CONNECT TO NODE MANAGER';
      nmConnect('weblogic','passwd','weblogic-wlst','5556','test','/opt/oracle/Middleware11115/user_projects/domains/test','ssl')

      #Connect to Admin Server

      print 'START ADMIN SERVER ONLY ON THE MACHINE WHERE THE ADMIN SERVER IS PRESENT';
      nmStart('AdminServer');

      #Start Admin Server
      print 'CONNECT TO ADMIN SERVER';
      connect(username='weblogic', password='passwd', url='t3://weblogic-wlst:7001')

      #Start Managed Servers
      print 'START MANAGED SERVERS ON THE MACHINE';
      start('MS1','Server');
      start('MS2','Server');

      This works just fine. I even have an init.d service that starts and stops servers on reboot.

      But now due to continuous integration we need a way to start managed servers via list.
      Ok , so i figured out to use CSV :

      http://www.jython.org/docs/library/csv.html

      But I cannot use module csv in WLST :

      [weblogic@weblogic-wlst ~]$ java weblogic.WLST

      Initializing WebLogic Scripting Tool (WLST) ...

      Welcome to WebLogic Server Administration Scripting Shell

      Type help() for help on available commands

      wls:/offline> import csv
      Traceback (innermost last):
      File "<console>", line 1, in ?
      ImportError: no module named csv
      wls:/offline>

      The main question is how to use/import CSV in WLST ?

      Thanks,
      Best Regards
      Emil Bolokanov
        • 1. Re: Use Jython Module/s in WLST
          AlissonSilva
          Do you really need to use csv? Do you just want to pass some parameters to wlst?

          In wlst you can use properties files with content like "var=value":
          var1=one
          var2=two

          And invoke in wlst with the command loadProperties('FILENAME'). The parameters at the property file will be available by the variable name, so, using the example (var1=one), it'll work like that:

          print var1
          Result: one


          -----

          If you just want to restart your managed servers, you could do something like that:
          connect()
          varServers = cmo.getServers()
          for server in varServers:
              #use this to not shutdown the admin server
              varServerName = server.getName()
              if varServerName == varAdminServerName:
                  continue
          
              #try to shutdown the server
              try:
                  shutdown(varServerName,force='true')
              except Exception:
                  print 'Server ' + varServerName +' already down.'
            
              #a look to try to start the server. Sometimes the process was not shutdowned already.
              for counter in range(1,10):
                  try:
                      start(varServerName)
                      break
                  except Exception:
                      os.system('sleep 30')
          
              else:
                  print 'Something went wrong starting ' + varServerName
                  exit(exitcode=1)
          Best Regards,
          Jimi

          Edited by: 904641 on Mar 29, 2012 12:36 PM
          • 2. Re: Use Jython Module/s in WLST
            933130
            Hi,

            Did you resolve this problem, I am having the same issue regarding the import csv module.

            Thanks,
            San