WLST Guide: Creating WebLogic Domains with Advanced Configurations

1. Dynamic Domain Creation Using Python Dictionaries (Unique Approach)

Why? Avoid hardcoding values—use a reusable JSON/YAML-style structure.


WLST Script (createDomain_advanced.py)


# Define domain config as a dictionary (modular & editable)
domain_config = {
    "domain_name": "ProdClusterDomain",
    "admin_user": "weblogic",
    "admin_password": "S3cr3t#123",  # Encrypt in production!
    "java_home": "/usr/java/jdk1.8.0_301",
    "listen_address": "10.0.0.100",
    "listen_port": 7001,
    "clusters": [
        {"name": "ProdCluster", "multicast": "239.192.0.1", "servers": 4}
    ],
    "data_sources": {
        "jdbc/AppDS": {
            "url": "jdbc:oracle:thin:@db-host:1521/ORCL",
            "driver": "oracle.jdbc.OracleDriver"
        }
    }
}

# Create domain from dict
readTemplate('/oracle/wlserver/common/templates/wls/wls.jar')

# Apply config
cd('/Security/base_domain/User/weblogic')
cmo.setPassword(domain_config["admin_password"])

cd('/Servers/AdminServer')
cmo.setListenAddress(domain_config["listen_address"])
cmo.setListenPort(domain_config["listen_port"])

# Dynamic cluster creation
for cluster in domain_config["clusters"]:
    cd('/')
    create(cluster["name"], 'Cluster')
    for i in range(cluster["servers"]):
        create(f"ProdServer_{i}", 'Server')
        cd(f'/Servers/ProdServer_{i}')
        set('Cluster', cluster["name"])

# Save & exit
writeDomain(f"/oracle/domains/{domain_config['domain_name']}")
closeTemplate()
exit()

2. Domain Creation with Rollback on Failure (Robust Error Handling)

Why? Most tutorials ignore failure recovery.

WLST Script (createDomain_rollback.py)

import os
from java.lang import System

try:
    # Start
    print(">>> Creating domain...")
    readTemplate('/oracle/templates/wls.jar')
    
    # Simulate a failure (e.g., port conflict)
    if int(System.getProperty('simulate.failure')) == 1:
        raise Exception("Fake error for rollback testing")
    
    # Normal setup
    cd('/Security/base_domain/User/weblogic')
    cmo.setPassword('weblogic123')
    writeDomain('/oracle/domains/TestDomain')
    
except Exception, e:
    print("!!! ERROR: " + str(e))
    print(">>> Rolling back...")
    
    # Delete incomplete domain
    if os.path.exists('/oracle/domains/TestDomain'):
        shutil.rmtree('/oracle/domains/TestDomain')
    
    # Exit with error
    sys.exit(1)

finally:
    closeTemplate()

3. Template-Based Domain Creation (For DR/Replication)

Why? Clone domains with customizations.


Step 1: Dump Existing Domain as Template

$WL_HOME/common/bin/wlst.sh

wls:/offline> writeTemplate('/backups/prod_domain_template.jar')

Step 2: Modify Template (Add Custom Resources)

readTemplate('/backups/prod_domain_template.jar')

# Add a JMS module
cd('/')
create('MyJMSModule', 'JMSSystemResource')
cd('JMSSystemResource/MyJMSModule/JmsResource/NO_NAME_0')
create('MyQueue', 'Queue')
cd('Queue/MyQueue')
cmo.setJNDIName('jms/MyQueue')

# Save as new template
writeTemplate('/backups/prod_domain_with_jms.jar')

4. Silent Mode + Property Files (CI/CD Ready)

Why? Integrate with DevOps pipelines.

Property File (domain.properties)

domain.name=CI_Domain
admin.port=9001
cluster.name=CI_Cluster
servers=3

5. Post-Creation Validation (Automated Checks)

Why? Most guides skip verification.

WLST Script (verifyDomain.py)

domain_home = '/oracle/domains/ProdDomain'

try:
    readDomain(domain_home)
    
    # Check AdminServer
    cd('/Servers/AdminServer')
    port = get('ListenPort')
    if port != 7001:
        raise Exception(f"AdminServer port is {port}, expected 7001")
    
    # Check clusters
    clusters = ls('/Clusters', returnMap=True)
    if 'ProdCluster' not in clusters:
        raise Exception("ProdCluster missing!")
    
    print(">>> Validation passed!")
    
except Exception, e:
    print("!!! VALIDATION FAILED: " + str(e))
    dumpStack()


Comments

Popular posts from this blog

Interview question for File and FTP Adapter

What is boot.properties file and how to create

SSL Exceptions in Admin Server and Node Manager.