Oracle Service Bus: WLST Fundamentals

Oracle Service Bus: WLST Fundamentals

Gepubliceerd: Categorie: Oracle

In my series of blogs about the Oracle Service Bus and WLST scripting I’d like to focus some more on the fundamentals, which will guide you through building smart generic scripts for your OSB/WebLogic domain. As you might know, WebLogic uses the WLST build on Python and Jython for getting tasks programmatically standardized and, if necessary, automated. Now, before you start using WLST together with Oracle Service Bus, it may be useful to understand some fundamentals.

Just as the MBeans in a standard WebLogic Domain, Oracle Service Bus uses its own MBeans on top of it. You can use this to request specific information about the configuration, resources such as proxy and business services. You also can export and import a certain configuration like you do in the Service Bus Console.

When you want to create a WLST script for some purpose, the following MBeans are the most important to start with:

  • SessionManagementBean: Used to create, save or discard a session, the same way as in the console. For doing this you can use the following methods:
  1. Creates the session ( can also be multiple )
  2. Commit your changes
  3. Rollback your changes before activate
  4. Exit when actions are done or rollbacked.
  1. createSession()
  2. activateSession()
  3. discardSession()
  4. sessionExists()

These actions you normally do in the console using these buttons:

  • ALSBConfgurationMBean: For the import and export of OSB configurations, updating specific information such as endpoint URI’s, and investigate configurations and resources. With this MBean you can manage your OSB configuration, which, packaged in a JAR file, can be Proxy and BusinessServices, WSDL’s or other resources.
  • ServiceDomainMBean: This MBean finds any service enabled for monitoring, and get or reset statistics for services which are enabled for monitoring.

When you start WLST, standard WebLogic modules are loaded but specific OSB you should import in your script to use are:

  1. from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean
  2. from com.bea.wli.monitoring import ServiceDomainMBean

to be found in com.bea.common.configfwk_1.5.0.0.jar, sb-kernel-api.jar and sb-kernel-impl.jar in your OSB library home.

Creating the session:

  1. sessionManager = findService(SessionManagementMBean.NAME, SessionManagementMBean.TYPE)
  2. sessionManager.createSession(sessionName)

Then do some stuff….

And save the session or discard when something went wrong:

  1. # Activate the change session
  2. print 'Activating my session...'
  3. sessionManager.activateSession(sessionName, 'Doing stuff session activated')
  4. except:
  5. if sessionManager != None:
  6. sessionManager.discardSession(sessionName)
  7. raise

Use of resource references

For the identification of projects, folders and other resources you can use the Ref() class, and you will use it with the ALSBConfgurationMBean. You can create, delete or export projects and folders with the following methods:

  1. createProject(Ref project, String Description)
  2. createFolder(Ref folder, String Description)
  3. delete()
  4. importUploaded(ALSBImportPlan plan) to implement a customization plan
  5. Customize(List customizations)
  6. ExportProjects(Collection Refs, String.

Normally it’s done through this section in the sbconsole:

Below you see a snippet of how to import a Customization (with the customization stored in an XML file):

  1. from com.bea.wli.sb.management.configuration import SessionManagementMBean
  2. from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean
  3. from com.bea.wli.config import Ref ..
  4. sessionName = createSessionName()
  5. print 'Created session', sessionName
  6. SessionMBean = getSessionMBean(sessionName)
  7. print 'SessionMBean started session'
  8. ALSBConfigurationMBean = findService(String("ALSBConfiguration.").concat(sessionName), "com.bea.wli.sb.management.configuration.ALSBConfigurationMBean")
  9. print "ALSBConfiguration MBean found", ALSBConfigurationMBean
  10. #customize if a customization file is specified
  11. #affects only the created resources
  12. if customFile != None :
  13. print 'Loading customization File', customFile
  14. iStream = FileInputStream(customFile)
  15. customizationList = Customization.fromXML(iStream)
  16. for customization in customizationList:
  17. print '\n customization', customization.getDescription()
  18. print customizationList.size()
  19. ALSBConfigurationMBean.customize(customizationList)
  20. print 'Customization applied'
  21. SessionMBean.commitSession(sessionName)
  22. print 'session committed'
  23. except:
  24. print "Unexpected error:", sys.exc_info()[0]
  25. if SessionMBean != None:
  26. SessionMBean.discardSession(sessionName)
  27. raise

… and so on.

ServiceDomainMBean

Through this interface you can get loads of statistics of your services. Some of the methods to use are:

  • Determining which services are enabled for monitoring
  1. getMonitoredBusinessServiceRefs()
  2. getMonitoredProxyServiceRefs
  • Gives back runtime statistics collected. You can specify a server name, or get back cluster wide statistics from an aggregated view of statistics of all managed servers).
  1. getBusinessServiceStatistics()
  2. getProxyServiceStatistics()

A short sample below:

  1. stats = cmo.getProxyServiceStatistics([ref],ResourceType.SERVICE.value(),'')
  2. for ps in stats[ref].getAllResourceStatistics():
  3. for s in ps.getStatistics():
  4. if s.getType() == StatisticType.COUNT:
  5. print s.getName() + "("+ str(s.getType()) +"): " + str(s.getCount())
  6. if s.getType() == StatisticType.INTERVAL:
  7. print ( s.getName() + "("+ str(s.getType()) +"): " + str(s.getMin()) + " " + str(s.getMax()) + " " + str(s.getAverage()) + " " + str(s.getSum())
  8. if s.getType() == StatisticType.STATUS:
  9. print s.getName() + "("+ str(s.getType()) +"): " + str(s.getCurrentStatus()) + "(" + str(s.getInitialStatus()) + ")"

Now, these are some basics to help you build your own customized and nifty scripts, have fun and good luck with it!

Michel Schildmeijer
Over auteur Michel Schildmeijer

Michel started his career as a medical officer in the Royal Dutch Airforce, with a focus on pharma. After the air force, he continued in pharma, followed by time working in clinical pharmacology. While there, he transitioned to IT by learning UNIX and MUMPS, and developed a system for managing patients’ medical records. As his career developed, his responsibility shifted from a deep technical perspective to a more visionary role. At the end of 2011, Michel authored a book on WebLogic Administration for beginners. He joined Qualogy in April 2012 where he expanded his repertoire significantly, serving a wide range of customers with his knowledge about Java Application Servers, Middleware and Application Integration. He also increased his multiple-industry knowledge in his role as Solutions or IT architect by working for customers in a range of sectors, including financials, telecom, public transportation and government organizations. In 2012, he received the IT Industry-recognized title of Oracle ACE for being an ambassador and community leader in his area of expertise. In 2019, this was enhanced to Oracle ACE Director. Michel is asked regularly to speak about technology and the impact of innovation at national and international conferences such as KubeCon, Oracle OpenWorld, Groundbreakers Developers Tours and others. He contributes actively to the OpenSource community and solutions regarding containerization, CI/CD and DevOps. In October 2021, Michel took an exciting step in his career by becoming Business Unit Manager for Qualogy Managed Services. While he still has a finger on the pulse in terms of technology, he is expanding his scope by combining his experience with the new insights gained in his new position. Read more via blog: https://bit.ly/3fAxrqf | Medium: https://mschildmeijer.medium.com/ | Books: Oracle Weblogic Server 11gR1 PS2: Administration Essentials: https://bit.ly/3IhALmf | Oracle WebLogic Server 12c: First Look1: https://bit.ly/31olbpj

Meer posts van Michel Schildmeijer
Reacties (1)
  1. om 03:03

    Very good article. I need help on creating JNDI Providers using WLST. Can you please give me sample script to do that.? Thanks in advanced

Reactie plaatsen