You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

WLST脚本开发需求:获取已部署应用与主机、应用状态

WLST Scripts for WebLogic Deployment Queries

Got it, here are two polished WLST scripts tailored for your needs—ready to run directly in the WebLogic Scripting Tool console:

1. Query Deployed Applications and Their Runtime States

This script connects to your WebLogic domain, fetches all deployed apps, and reports their runtime state across each target server.

# Connect to your WebLogic Admin Server (update credentials/URL as needed)
connect('weblogic', 'your_actual_password', 't3://localhost:7001')

# Switch to Domain Config MBean tree to retrieve application targets
domainConfig()
cd('AppDeployments')
deploymentsList = cmo.getAppDeployments()

# Switch to Domain Runtime MBean tree to access runtime state data
domainRuntime()
cd('AppRuntimeStateRuntime/AppRuntimeStateRuntime')

# Loop through each deployed application
for app in deploymentsList:
    appName = app.getName()
    print(f"\n=== Application: {appName} ===")
    
    # Jump back to domain config to get the app's target servers
    domainConfig()
    cd(f'/AppDeployments/{appName}/Targets')
    targetsMap = ls(returnMap='true')
    
    # Return to domain runtime to check state for each target
    domainRuntime()
    cd('AppRuntimeStateRuntime/AppRuntimeStateRuntime')
    
    for targetName in targetsMap:
        # Fetch and print the app's state on this target
        appState = cmo.getAppState(appName, targetName)
        print(f"Target Server: {targetName} | State: {appState}")

# Clean up connection and exit
disconnect()
exit()

Note: Don’t forget to replace your_actual_password and the t3 URL with your domain’s real admin credentials and server address. States will show as values like ACTIVE, PREPARED, or UNKNOWN depending on deployment status.

2. Query Deployed Applications and Their Corresponding Hosts

This script lists each deployed app alongside the host machine where its target servers are running.

# Connect to your WebLogic Admin Server (update credentials/URL as needed)
connect('weblogic', 'your_actual_password', 't3://localhost:7001')

# Switch to Domain Config MBean tree
domainConfig()
cd('AppDeployments')
deploymentsList = cmo.getAppDeployments()

# Iterate through each application
for app in deploymentsList:
    appName = app.getName()
    print(f"\n=== Application: {appName} ===")
    
    # Get the app's target servers
    cd(f'/AppDeployments/{appName}/Targets')
    targetsMap = ls(returnMap='true')
    
    # For each target server, fetch its host address
    for targetName in targetsMap:
        cd(f'/Servers/{targetName}')
        hostName = cmo.getListenAddress()
        # Fallback to localhost if listen address isn't explicitly set
        if not hostName:
            hostName = 'localhost'
        print(f"Target Server: {targetName} | Host: {hostName}")
        
        # Navigate back to AppDeployments to process the next target
        cd('../../AppDeployments')

# Clean up connection and exit
disconnect()
exit()

Note: If your servers use the default host (no explicit ListenAddress set), the script falls back to localhost—adjust this fallback logic if your domain uses a different convention.


内容的提问来源于stack exchange,提问作者Oscar P

火山引擎 最新活动