Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Strategies for WebLogic Domain Configuration

Scripting Options, part 2

In my previous article (WLDJ, Vol. 3, issue 8), I gave you a detailed overview of the different strategies available for domain creation and configuration and evaluated manual and templating options. In this article, I employ tools like WLShell, WebLogic Scripting Tool, Silent Scripts, and Ant for domain configuration. These tools leverage simple, high-level scripting languages.

Note: This article relies heavily on the common steps such as Domain Creation, Database Configuration, and Verifying the Domain Configu-ration described in part 1.

Scripting Language

There are many questions regarding the structure and semantics of the scripting language. How do you write comments? What, if any, is the line separator? What data-types does the language support? Does the language have variables and assignments? How do you perform query and navigation? How do you invoke behavior (i.e., methods)? Is there support for branching and looping? Fortunately, many scripting alternatives exist for domain configuration. Let's look at some of them.

WLShell
According to the WLShell Web site, "WLShell is a shell for WebLogic." WLShell uses a very simple scripting language to provide access to JMX Mbeans, and a familiar file and directory navigation model to navigate MBeans.

Installation of WLShell is easy. Download the appropriate installer and execute it. Follow the installer steps and complete the installation.

WLShell scripting language supports single-line comments. The comment character is a hash-mark (#). Everything from # is commented out. There is no special end-of-line character. The echo command is either print or echo.

WLShell uses the familiar concept of directories and files for navigating the WebLogic Server instance where the MBeans correspond to directories and the attributes of MBeans correspond to files. Hence, navigation happens with recognizable commands like cd and ls. The command to create an MBean is md and the command to delete an object is rd. For example, in order to create a connection pool named semJDBCConnectionPool, execute the following command:

md /JDBCConnectionPool/semJDBCConnectionPool

What if the name contains a forward slash? The forward slash is escaped by using an additional forward slash. For example, to create a data source named jdbc/semJDBCDataSource, execute the following command:

md /JDBCTxDataSource/jdbc//semJDBCDataSource

Setting the variable attribute of an object is done with the set command. To set a variable of the boolean type, invoke set variable-name true-or-false. For example, to set StdoutDebugEnabled variable to true, invoke the following command:

set StdoutDebugEnabled true

To set a variable of integer type, invoke set variable-name integer-value. For example, to set StdoutSeverityLevel to 64, invoke the following command:

set StdoutSeverityLevel 64

To set a variable of string type, invoke set variable-name "string-value." For example, to set URL to jdbc:pointbase:server://localhost:9093/workshop, invoke the following command:

set URL "jdbc:pointbase:server://localhost:9093/workshop"

Setting variables of primitive types is easy, but how do you set a variable of java.util.Properties type? To set a variable of java.util.Properties type, use the special syntax. Invoke set variable-name (java.util.Properties) "name=value pairs separated by semicolon." For example, to set the properties for the connection pool, use the following:

set Properties (java.util.Properties)
"user=weblogic;databaseName=jdbc:pointbase:server://localhost:9093/semdb"

So far, I have examined how to set variables of types boolean, int, String, and Properties. How do you set a variable of another MBean type? Just invoke set variable-name path-to-the-mbean. For example, to set the connection pool property of the JMS JDBC store, invoke the following command:

set ConnectionPool /JDBCConnectionPool/semJDBCConnectionPool

By executing the ls command, WLShell not only lists attributes that can be get or set, but also operations that can be invoked. How do you execute an operation? Using a special command called invoke. The syntax for the invoke command is: invoke method-name parameter-list-separated-by-space. For example, deploy the connection pool to the server, using the following command:

invoke addTarget /Server/$server

In the above example, the method name is addTarget. The method takes one parameter, the MBean of the server.

Deploying an application with WLShell is involved. Get a reference to /Deployer-Runtime/DeployerRuntime instance and create an instance to hold the deployment data. Associate the data with the server, and activate the application.

WLShell can be used in the script mode as well as in the interactive mode. In the interactive mode, a WLShell session is created and connected to a running WebLogic Server instance. Changes are made to the WebLogic Server instance by invoking commands in the WLShell session. To launch WLShell in interactive mode, execute the following command:

%wlsh

In the script mode, a script of WLShell commands is created and executed. The script can be created once and executed any number of times later to set up similar domains. The syntax to execute a script is wlsh -f script-file-name. To create the sample domain using script, execute the following command:

%wlsh -f sem_domain_wlshell.txt

In the above example, sem_domain_wlshell.txt file contains WLShell statements to configure the domain.

Before executing the WLShell script, configure an empty WebLogic Workshop domain by following the steps in the Domain Creation section using SEMDomain-WLShell as the Configuration Name. Setup the database instance by following the steps in the Database Configuration section. In order to run WLShell, just verify that wlshell/bin directory is available in the PATH environment variable. Now, execute the script:

wlsh -f sem_domain_wlshell.txt

Verify that the configuration is correct by running the tests as described in the Verifying the Domain Configuration section.

WLShell supports converting an existing config.xml file into WLShell script and commands via c2w command. WLShell supports working in off-line mode and connecting to config.xml instead of the running server. However, the implementation is not feature complete. For example, creation of a connection pool in the off-line mode results in a "feature not implemented" message.

WebLogic Scripting Tool (WLST)
WLST uses Jython as its scripting language. The Jython site states, "Jython is an implementation of high-level, dynamic, object-oriented language Python written in 100% Java, and seamlessly integrates with the Java platform." Instead of reinventing the wheel, WLST makes a very smart decision regarding the scripting infrastructure. WLST leverages the powerful scripting language of Jython.

Here are the installation instructions:

  • Download WLST (wlsScripting.zip) file and unzip the file (e.g., c:\WLST). The wlsScripting.zip file contains wlst_doc.pdf file. The wlst_doc.pdf contains all the details about WLST such as installation, configuration, and execution. Refer to the References section for detailed instructions on downloading and installing WLST.

Here are the configuration instructions for WLST:

  • Set the weblogic.jar in the CLASSPATH by executing setWLSEnv (e.g., %WLS_HOME%\server\bin\setWLSEnv.cmd).
  • Set wlst.jar in the CLASSPATH.
  • Set jython.jar in the CLASSPATH.
  • Verify that WLST is working by executing java weblogic.WLST. This executes WLST in the interactive mode.

Refer to the wlst_doc.pdf file for detailed instructions on configuring WLST.

WLST can be used in script mode as well as in interactive mode. In the interactive mode, a WLST session is created in offline mode. In this mode, WLST is not connected to a running instance of WebLogic Server. Once WLST is connected to a running WebLogic Server instance changes are made to the WebLogic Server instance by invoking commands in WLST session. In the script mode, a script of WLST commands is created and executed. Just as in the interactive mode, the script contains Jython statements. The script file is a Jython file. The script can be created once and executed any number of times later to setup similar domains.

To invoke WLST in interactive mode, invoke the following command:

java weblogic.WLST

To invoke WLST in script mode, pass in the name of the script. For example:

java weblogic.WLST sem_domain_wlst.py

Do not execute the above commands yet. At the end of this section, you will do additional setup and then execute the WLST script.

The following are the quick and basic notes on Python (and Jython). Specifying an end of statement character (;) is optional unless multiple statements are specified on a single line. The comment character is hash mark (#). All the characters from # onwards on a single line are considered part of the comment. The echo command is print. Strings can be passed in either single quotes (') or double-quotes (").

WLST uses the familiar concept of directories and files for navigating the MBeans. Hence, navigation happens with recognizable commands like cd and ls. However, every command is a function. Therefore, the commands look like cd('Servers/cgServer') and ls(). WLST defines a very special variable named cmo for the current managed object. Initially, cmo is assigned to the root. The value of cmo changes as you navigate the MBeans. In file system parlance, the value of cmo is the current working directory. Execute ls('a') to find attributes whose value can be changed. Prefix the name of the attribute with the word set to change the value of the attribute. For example, to change the value of attribute StdoutSeverityLevel to 64, invoke the following method: setStdoutSeverityLevel(64). However, on what object should the setStdoutSeverityLevel(64) method be invoked? Of course, cmo:

cmo.setStdoutSeverityLevel(64)

The other option is to assign cmo to a variable. The variable can later be used at any time throughout the current session. For example:

cgServer = cmo
cgServer.setStdoutSeverityLevel(64)

Suppose you want to set StdDebugEnabled value to true. However, neither Python nor Jython supports the boolean type. Fortunately, the integer equivalents, 1 for true and 0 for false, can be used. Therefore, set the value of StdDebugEnabled to true as follows:

cgServer.setStdoutDebugEnabled(1)

How do you create resources such as JDBC connections pools and JMS queues? Use WLST's built-in create() method. The create() method accepts two parameters. The first parameter is the name of the resource, whereas the second parameter is the type of resource. For example, to create a JDBC connection pool with semJDBCConnectionPool as its name, execute the following command:

create('semJDBCConnectionPool','JDBCConnectionPool')

Note: There is also a corresponding delete() method that works similarly.

WLST provides a special method named makePropertiesObject() to create a properties object out of a string of name and value pairs separated via semicolon. Therefore, set the properties of a JDBC connection pool as follows:

semCPProperties =
makePropertiesObject('user=weblogic;databaseName=jdbc:pointbase:server://localhost:9093/semdb')
semCP.setProperties(semCPProperties)

Deploying the newly created resource, such as the connection pool, to the server is easy. Invoke the addTarget() method of the source as follows:

semCP.addTarget(cgServer)

Deploying an application is very easy with WLST using the deploy() method. The deploy() method takes three parameters. The first parameter is the name of the application. The second parameter is the path to the location of the EAR file. The third parameter is the target or the server name. The following is the example of the deploy() method:

deploy('SEMApp','c:/Automate/SEMApp/SEMApp.ear','cgServer')

Before executing the WLST script, configure an empty WebLogic Workshop domain by following the steps in the Domain Creation section using SEMDomain-WLST as the Configuration Name. Setup the database instance by following the steps in the Database Configuration section. Now, execute the script:

java weblogic.WLST sem_domain_wlst.py

Restart the WebLogic Server instance and verify that the configuration is correct by running the tests as described in the Verifying the Domain Configuration section.

Is it possible to reverse engineer an existing domain into a WLST script? Absolutely. Using the configuretoscript() command, the contents of an existing domain are converted into a WLST script file. Use this feature to quickly incorporate WLST into your current process.

Silent Scripts

A silent script consists of statements that are executed by the configuration wizard in silent mode. The silent script uses a very simple language. The statements are terminated by semicolons (;). The language supports Java-style comments. Double forward slash (//) is used to comment to the end of the line whereas /* ? */ is used to comment sections. The language has no concept of data-types; everything is a string enclosed in double quotes. For example, to set boolean or integer types just enclose the value in double quotes, as shown below:

set cgServer.StdoutDebugEnabled "true";
set cgServer.StdoutSeverityLevel "64";

The simple types can be converted to their string equivalents, but what about objects? In the case of objects the name of the object is used. For example, to set the error destination for a queue:

set aq.ErrorDestination "SEMAppWeb.queue.AsyncDispatcher_error";

There is no support for branching and looping. There is no navigation. The structure of the silent script file is flat. The language does support variables. A variable can be assigned upon either creating a new object or finding a preexisting object. For example, a variable assignment on finding a preexisting object:

find Server "cgServer" as cgServer;

And, a variable assignment on creating a new object:

create JDBCConnectionPool "semJDBCConnectionPool" as semCP;

The script uses special syntax to deploy resources to their targets, i.e., calling the addTarget() method of an MBean. The special syntax is assign <resource type> "<resource name>" to Target "<server name>";. For example, to deploy semJDBCConnectionPool to cgServer use the following syntax:

assign JDBCConnectionPool "semJDBCConnectionPool" to Target "cgServer";

The silent script enables domain creation very nicely. Therefore, you can either create the domain using the Configuration Wizard as described in the Domain Configuration section or use the silent script. I will illustrate domain creation with a silent script. The sem_domain_silent_create.txt script illustrates domain creation. The silent script reads Basic WebLogic Workshop Domain template and creates a domain. But, how do you invoke the script? The syntax to invoke the silent script is:

> %BEA_HOME%/weblogic81/common/bin/config.cmd -mode=silent -silent_script=full path to script file
-log=full path to the log file

Now, create the domain using the sem_domain_silent_create.txt script.

The -log flag is optional, but highly recommended. When there are errors, the messages logged to the console are very terse, but the complete exception trace is logged to the log file. The log file is immensely important in debugging silent configuration scripts.

Please note that in sem_domain_silent_create.txt file, if the WebLogic user is not assigned a password, the script will fail. Also, newly created users by default are assigned to group Administrators. Therefore, upon creating a user system, the user system belongs to group Administrators. If the script tries to write a domain to a location that already exists, the script fails. In order to replace a preexisting domain, set the OverwriteDomain variable to true.

Next, set up the database as described in the Database Configuration section. Now, shut down the server if the server is running. Configure the server by executing the sem_domain_silent_config.txt script. Be aware that the order of setting driverName and URL is important. Otherwise, the creation of the connection pool fails!

Note the update domain; command at the end of sem_domain_silent_config.txt script. This command is very important. Without it, changes made to the domain will not be committed, and the domain will not be changed!

How do you deploy the application while configuring the domain using the silent script (Note: the server is not running)? Create a custom template that contains the application. The custom template is a JAR file that contains the EAR file, the relevant section of config.xml that will be merged into current config.xml, and some metadata in the template-info.xml file. In the silent script, add the template using the add Template ? command. Adding at least one template when updating the domain is necessary, otherwise the changes made to the domain are not persisted! A common technique, if you do not have your own template, is to use the DefaultWebApp template.

Verify that the configuration is correct by running the tests described in the Verifying the Domain Configuration section.

Special Ant Tasks

Apache Ant is an invaluable tool for building and deploying applications. An Ant file is an XML file that contains many targets. The targets invoke tasks. WebLogic ships special tasks such as wlconfig and wldeploy. The wlconfig Ant task helps with domain configuration. The wldeploy Ant task helps with application deployment.

WebLogic Server installation also includes Ant. Ant is automatically set up when setting up the environment by executing the setWLSEnv (bat or sh) script. The taskdefs for wlconfig and wldeploy are not required if this version of Ant is used.

The language of the Ant file is XML. Therefore, language specifics like comments are XML comments. Other features, like the echo are Ant-specific.

The wlconfig task contains nested elements such as query and create. The query element is used to find preexisting MBeans, whereas the create element is used to create new MBeans. Both query and create support get and set elements to get and set MBean attributes. The syntax for the set attribute is: <set attribute="MbeanAttributeName" value="NewValue"/>. All attribute values, regardless of type, are enclosed in double quotes and passed in as string. Consider setting the MBean attribute StdoutDebugEnabled value of type boolean to true.

<set attribute="StdoutDebugEnabled" value="true"/>

Similarly, consider setting the MBean attribute StdoutSeverityLevel value of type integer to 64.

<set attribute="StdoutSeverityLevel" value="64"/>

Once an object is queried, the object can optionally be set as an Ant property that is available throughout the file. For example, the server is queried and set into cgServer property. Later, in the build file, the cgServer property is utilized to target resources to the server.

Note: The wlconfig does not currently support the invoke command. Therefore, for example, targets are set as attributes instead of invoking the addTarget operation.

The wldeploy Ant task is used to deploy and undeploy the application. The wldeploy task takes actions such as deploy, undeploy, redeploy, cancel, start, stop, and distribute.

In order to execute the included Ant file, first create the domain by following the steps described in the Domain Creation section, giving a meaningful name like SEMDomain-Ant as the Configuration Name.

Note: Since the name of the domain is used in the Ant file, either use SEMDomain-ANT as the domain name or change the Ant file to match your domain name. Start the WebLogic server instance and use the steps described in the Database Configuration to configure the database. Launch a new command or shell window and execute the %WLS_HOME%/server/bin/setWLSEnv (cmd or sh) file to set up the environment. Execute the Ant using the following command:

ant -v -f sem_domain_ant_config.xml

Run the tests as described in Verifying the Domain Configuration section.

The verbose (-v) option to the Ant command displays the MBean commands issued to the server. The information is very valuable in debugging and troubleshooting.

An Ant file encourages very modular development of the automated script. Each individual resource is created and configured using a separate target. Using Ant dependencies, the all target calls the individual Ant targets and does the complete configuration. Ant encourages the creation of a clean target. The order of dependencies in the clean target is opposite that of the all target.

Conclusion: Choices, Choices, and More Choices

This article described domain configuration using WLShell, WLST, Silent Scripts, and Ant tasks. These tools employ simple and powerful high-level scripting languages. Whereas WLShell uses a custom scripting language, WLST leverages Jython. Once a domain configuration script is created, setting up another identical domain is a simple matter of executing the script. Scripting domain configuration is the way to go for automating domain configuration.

References

  • To discuss the article and ask questions start here: www.bartssandbox.com. Free membership is required.
  • WLShell: www.wlshell.net/
  • Download WLST from BEA dev2dev code library: http://dev2dev.bea.com/codelibrary/code/wlst.jsp
  • More Stories By Prakash Malani

    Prakash Malani has extensive experience in architecting, designing, and developing object-oriented software and has done software development in many application domains such as entertainment, retail, medicine, communications, and interactive television.He practices and mentors leading technologies such as J2EE, UML, and XML. Prakash has published various articles in industry- leading publications.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    IoT & Smart Cities Stories
    Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
    Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
    IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
    The standardization of container runtimes and images has sparked the creation of an almost overwhelming number of new open source projects that build on and otherwise work with these specifications. Of course, there's Kubernetes, which orchestrates and manages collections of containers. It was one of the first and best-known examples of projects that make containers truly useful for production use. However, more recently, the container ecosystem has truly exploded. A service mesh like Istio addr...
    Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
    Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
    Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
    To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
    In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
    Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...