Showing posts with label WLST. Show all posts
Showing posts with label WLST. Show all posts

How to Create Credential Mappings for a WebLogic Server Datasource Using WLST

This article describes how to create Credential Mappings for an existing WebLogic Server Datasource using WLST.

Fix

You can use a WLST Python script to create Credential Mappings for an existing WebLogic Server Datasource. Create the filename with a .py extention with the following content: for example, JDBCCredentialMapping.py. In the script make modifications according to your environment and requirement specifying the DataSource Name (), Domain Name (), remoteUsername (), remotePassword
(<remotePassword>) and WLST domain connect parameters specifying domain username, password and listen address.

resourceId = 'type=<jdbc>, application=, module=, resourceType=ConnectionPool, resource=<DataSource Name>, action=reserve'
wlsUsername = '<wlsUsername>'
remoteUsername = '<remoteUsername>'
remotePassword = '<remotePassword>'
domainName = ''
connect('<username>','<password>','t3://<listenaddress>:<PortNo>')
serverConfig()
cd("//")
rlm = cmo.getSecurityConfiguration().getDefaultRealm()
credMapProv = rlm.lookupCredentialMapper("DefaultCredentialMapper")
credMapProv.setUserPasswordCredential(resourceId, remoteUsername, remotePassword)
credMapProv.setUserPasswordCredentialMapping(resourceId, wlsUsername, remoteUsername)
disconnect()
exit()
Set the WebLogic Server environment variables by running setDomainEnv.cmd/sh script inside the ${DOMAIN_HOME}/bin folder and run the WLST python script as below. In this example. we assume the python script name JDBCCredentialMapping.py.
java weblogic.WLST JDBCCredentialMapping.py
Once the python script is executed in WLST, log in to the WLS console, navigate to Datasource -> Security -> Credential Mappings. You can see the specified WLS User and Remote User credentials created.

Weblogic Scripting Tool (WLST) Fundamentals

  • WLS command-line tools are useful :

- For automating common administrative activities
- As an alternative to the Administration Console
- When Graphical tools are not supported


  • WLST provides a command-line interface for :

- Creating new weblogic Domains
- Retrieving and updating Weblogic Domain Configurations
- Deploying Applications
- Obtaining run-time server statistics


  • WLST is implemented using Jython which in turn is a Java implementation of the Python scripting Languages:

-simple and clear syntax
-indentation to structure code
-interactive command mode
-custom commands
-integration with any Java libraries


Weblogic :GridLink data source using WLST


  1. Log in as a wls user to shell and start WLST:
    [wls@prod01]$ $WL_HOME/common/bin/wlst.sh
  2. Connect to the Administration Server using wlsadmin as the user, <pwd> as the password, and t3://adminhost.domain.local:7001 as the server URL:
    wls:/offline> connect("wlsadmin","<pwd>","t3://adminhost.domain.local:7001")
  3. Run the following WLST commands to create the GridLink data source:
    edit()
    startEdit()
    
    cmo.createJDBCSystemResource('ds-GridLinkXA')
    cd('/JDBCSystemResources/ds-GridLinkXA/JDBCResource/ds-GridLinkXA')
    cmo.setName('ds-GridLinkXA')
    cd('/JDBCSystemResources/ds-GridLinkXA/JDBCResource/ds-GridLinkXA/JDBCDataSourceParams/ds-GridLinkXA')
    set('JNDINames',jarray.array([String('jdbc/ds-GridLinkXA')], String))
    cd('/JDBCSystemResources/ds-GridLinkXA/JDBCResource/ds-GridLinkXA/JDBCDriverParams/ds-GridLinkXA')
    cmo.setUrl('jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost-rac01)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost-rac02)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=dbservice)))\r\n')
    cmo.setDriverName('oracle.jdbc.xa.client.OracleXADataSource')
    cmo.setPassword('dbpwd')
    cd('/JDBCSystemResources/ds-GridLinkXA/JDBCResource/ds-GridLinkXA/JDBCConnectionPoolParams/ds-GridLinkXA')
    cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n')
    
    cd('/JDBCSystemResources/ds-GridLinkXA/JDBCResource/ds-GridLinkXA/JDBCDriverParams/ds-GridLinkXA/Properties/ds-GridLinkXA')
    cmo.createProperty('user')
    cd('/JDBCSystemResources/ds-GridLinkXA/JDBCResource/ds-GridLinkXA/JDBCDriverParams/ds-GridLinkXA/Properties/ds-GridLinkXA/Properties/user')
    cmo.setValue('dbuser')
    cd('/JDBCSystemResources/ds-GridLinkXA/JDBCResource/ds-GridLinkXA/JDBCDataSourceParams/ds-GridLinkXA')
    cmo.setGlobalTransactionsProtocol('TwoPhaseCommit')
    cd('/JDBCSystemResources/ds-GridLinkXA/JDBCResource/ds-GridLinkXA/JDBCOracleParams/ds-GridLinkXA')
    cmo.setFanEnabled(true)
    cmo.setOnsWalletFile('')
    cmo.unSet('OnsWalletPasswordEncrypted')
    cmo.setOnsNodeList('onshost:6200 \r\n')
    cmo.setFanEnabled(true)
    cmo.setOnsWalletFile('')
    cmo.unSet('OnsWalletPasswordEncrypted')
    cmo.setOnsNodeList('onshost:6200 \r\n')
    cd('/JDBCSystemResources/ds-GridLinkXA')
    set('Targets',jarray.array([ObjectName('com.bea:Name=PROD_Cluster,Type=Cluster')], ObjectName))activate()
    exit()

Oracle Weblogic: Changing the multi data source algorithm type using WLST

  1. Log in as a wls user to shell and start WLST:
    [wls@prod01]$ $WL_HOME/common/bin/wlst.sh
  2. Connect to the Administration Server using wlsadmin as the user, <pwd> as the password, and t3://adminhost.domain.local:7001 as the server URL:
    wls:/offline> connect("wlsadmin","<pwd>","t3://adminhost.domain.local:7001")
  3. Run the following WLST commands to change the multi data source algorithm:
    edit()
    startEdit()
    
    cd('/JDBCSystemResources/ds-XA/JDBCResource/ds-XA/JDBCDataSourceParams/ds-XA')
    cmo.setAlgorithmType('Load-Balancing')activate()
    exit()

Oracle Weblogic Server : Creating the multi data source using WLST

  1. Log in as a wls user to shell and start WLST:
    [wls@prod01]$ $WL_HOME/common/bin/wlst.sh
  2. Connect to the Administration Server using wlsadmin as the user, <pwd> as the password, and t3://adminhost.domain.local:7001 as the server URL:
    wls:/offline> connect("wlsadmin","<pwd>","t3://adminhost.domain.local:7001")
  3. Run the following WLST commands to create the first data source:
    edit()
    startEdit()#create the ds-XA-rac01 data source
    cmo.createJDBCSystemResource('ds-XA-rac01')
    cd('/JDBCSystemResources/ds-XA-rac01/JDBCResource/ds-XA-rac01')
    cmo.setName('ds-XA-rac01')
    cd('/JDBCSystemResources/ds-XA-rac01/JDBCResource/ds-XA-rac01/JDBCDataSourceParams/ds-XA-rac01')
    set('JNDINames',jarray.array([String('jdbc/ds-XA-rac01')], String))
    cd('/JDBCSystemResources/ds-XA-rac01/JDBCResource/ds-XA-rac01/JDBCDriverParams/ds-XA-rac01')
    cmo.setUrl('jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost-rac01)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=dbservice-rac01)(INSTANCE_NAME=instance-rac01)))')
    cmo.setDriverName('oracle.jdbc.xa.client.OracleXADataSource')
    cmo.setPassword('dbpwd');
    cd('/JDBCSystemResources/ds-XA-rac01/JDBCResource/ds-XA-rac01/JDBCConnectionPoolParams/ds-XA-rac01')
    cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n')
    cd('/JDBCSystemResources/ds-XA-rac01/JDBCResource/ds-XA-rac01/JDBCDriverParams/ds-XA-rac01/Properties/ds-XA-rac01')
    cmo.createProperty('user')
    cd('/JDBCSystemResources/ds-XA-rac01/JDBCResource/ds-XA-rac01/JDBCDriverParams/ds-XA-rac01/Properties/ds-XA-rac01/Properties/user')
    cmo.setValue('dbuser')
    cd('/JDBCSystemResources/ds-XA-rac01/JDBCResource/ds-XA-rac01/JDBCDataSourceParams/ds-XA-rac01')
    cmo.setGlobalTransactionsProtocol('TwoPhaseCommit')
    cd('/JDBCSystemResources/ds-XA-rac01')
    set('Targets',jarray.array([ObjectName('com.bea:Name=PROD_Cluster,Type=Cluster')], ObjectName))
  4. Run the following WLST commands to create the second data source:
    #create the ds-XA-rac02 data source
    cd('/')
    cmo.createJDBCSystemResource('ds-XA-rac02')
    cd('/JDBCSystemResources/ds-XA-rac02/JDBCResource/ds-XA-rac02')
    cmo.setName('ds-XA-rac02')
    cd('/JDBCSystemResources/ds-XA-rac02/JDBCResource/ds-XA-rac02/JDBCDataSourceParams/ds-XA-rac02')
    set('JNDINames',jarray.array([String('jdbc/ds-XA-rac02')], String))
    cd('/JDBCSystemResources/ds-XA-rac02/JDBCResource/ds-XA-rac02/JDBCDriverParams/ds-XA-rac02')
    cmo.setUrl('jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost-rac02)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=dbservice-rac02)(INSTANCE_NAME=instance-rac02)))')
    cmo.setDriverName('oracle.jdbc.xa.client.OracleXADataSource')
    cmo.setPassword('dbpwd');
    cd('/JDBCSystemResources/ds-XA-rac02/JDBCResource/ds-XA-rac02/JDBCConnectionPoolParams/ds-XA-rac02')
    cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n')
    cd('/JDBCSystemResources/ds-XA-rac02/JDBCResource/ds-XA-rac02/JDBCDriverParams/ds-XA-rac02/Properties/ds-XA-rac02')
    cmo.createProperty('user')
    cd('/JDBCSystemResources/ds-XA-rac02/JDBCResource/ds-XA-rac02/JDBCDriverParams/ds-XA-rac02/Properties/ds-XA-rac02/Properties/user')
    cmo.setValue('dbuser')
    cd('/JDBCSystemResources/ds-XA-rac02/JDBCResource/ds-XA-rac02/JDBCDataSourceParams/ds-XA-rac02')
    cmo.setGlobalTransactionsProtocol('TwoPhaseCommit')
    cd('/JDBCSystemResources/ds-XA-rac02')
    set('Targets',jarray.array([ObjectName('com.bea:Name=PROD_Cluster,Type=Cluster')], ObjectName))
  5. Run the following WLST commands to create the multi data source:
    #create the multi data source ds-xa
    cd('/')
    cmo.createJDBCSystemResource('ds-XA')
    cd('/JDBCSystemResources/ds-XA/JDBCResource/ds-XA')
    cmo.setName('ds-XA')
    cd('/JDBCSystemResources/ds-XA/JDBCResource/ds-XA/JDBCDataSourceParams/ds-XA')
    set('JNDINames',jarray.array([String('jdbc/ds-XA')], String))
    cmo.setAlgorithmType('Failover')
    cmo.setDataSourceList('ds-XA-rac01,ds-XA-rac02')
    cd('/JDBCSystemResources/ds-XA')
    set('Targets',jarray.array([ObjectName('com.bea:Name=PROD_Cluster,Type=Cluster')], ObjectName))
    activate()
    exit()

Oracle Weblogic Server : Creating the JDBC data source using WLST

Creating the JDBC data source using WLST

  1. Log in as a wls user to shell and start WLST:
    [wls@prod01]$ $WL_HOME/common/bin/wlst.sh
  2. Connect to the Administration Server using wlsadmin as the user, <pwd> as the password, and t3://adminhost.domain.local:7001 as the server URL:
    wls:/offline> connect("wlsadmin","<pwd>","t3://adminhost.domain.local:7001")
  3. Run the following WLST commands to create the data source:
    edit()
    startEdit()

    cd('/')
    cmo.createJDBCSystemResource('ds-nonXA')
    cd('/JDBCSystemResources/ds-nonXA/JDBCResource/ds-nonXA')
    cmo.setName('ds-nonXA')
    cd('/JDBCSystemResources/ds-nonXA/JDBCResource/ds-nonXA/JDBCDataSourceParams/ds-nonXA')
    set('JNDINames',jarray.array([String('jdbc/ds-nonXA')], String))
    cd('/JDBCSystemResources/ds-nonXA/JDBCResource/ds-nonXA/JDBCDriverParams/ds-nonXA')
    cmo.setUrl('jdbc:oracle:thin:@dbhost:1521/dbservice')
    cmo.setDriverName('oracle.jdbc.OracleDriver')
    cmo.setPassword('dbpwd')
    cd('/JDBCSystemResources/ds-nonXA/JDBCResource/ds-nonXA/JDBCConnectionPoolParams/ds-nonXA')
    cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n')
    cd('/JDBCSystemResources/ds-nonXA/JDBCResource/ds-nonXA/JDBCDriverParams/ds-nonXA/Properties/ds-nonXA')
    cmo.createProperty('user')
    cd('/JDBCSystemResources/ds-nonXA/JDBCResource/ds-nonXA/JDBCDriverParams/ds-nonXA/Properties/ds-nonXA/Properties/user')
    cmo.setValue('dbuser')
    cd('/JDBCSystemResources/ds-nonXA/JDBCResource/ds-nonXA/JDBCDataSourceParams/ds-nonXA')
    cmo.setGlobalTransactionsProtocol('OnePhaseCommit')
    cd('/JDBCSystemResources/ds-nonXA')
    set('Targets',jarray.array([ObjectName('com.bea:Name=PROD_Cluster,Type=Cluster')], ObjectName))activate()
    exit()

Oracle Weblogic : Enabling the Administration Port by using WLST

  1. Log in to the shell as the user wls and start WLST:
    [wls@prod01]$ $WL_HOME/common/bin/wlst.sh 
  2. Connect to the Administration Server using wlsadmin as the user, <pwd> as the password, and t3://adminhost.domain.local:7001 as the server URL:
    wls:/offline> connect("wlsadmin","<pwd>","t3://adminhost.domain.local:7001")
  3. Run the following WLST commands:
    edit()
    startEdit()
    
    cmo.setAdministrationPortEnabled(true)
    cmo.setAdministrationPort(17002)activate()
    exit()

Ignoring the trusted CA certificate warnings when connecting to Node Manager using WLST nmConnect()

Symptoms

When using Weblogic Scripting Tool (WLST) nmConnect() to connect to the node manager, notice warnings are seen for unsupported certificates (after running setWLSEnv.cmd or .sh)


Connecting to Node Manager ...
CA certificate "CN=T-TeleSec GlobalRoot Class 3,OU=T-Systems Trust Center,O=T-Systems Enterprise Services GmbH,C=DE". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object:
1.2.840.113549.1.1.11.>
<Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=T-TeleSec GlobalRoot Class 2,OU=T-Systems Trust Center,O=T-Systems Enterprise Services GmbH,C=DE". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=GlobalSign,O=GlobalSign,OU=GlobalSign Root CA - R3". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "OU=Security Communication RootCA2,O=SECOM Trust Systems CO.\,LTD.,C=JP". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
<Notice> <Security> <BEA-090898> <Ignoring the trusted CA certificate "CN=KEYNECTIS ROOT CA,OU=ROOT,O=KEYNECTIS,C=FR". The loading of the trusted certificate list raised a certificate parsing exception PKIX: Unsupported OID in the AlgorithmIdentifier object: 1.2.840.113549.1.1.11.>
Successfully Connected to Node Manager.

Steps

Java.Lang.OutOfMemoryError In weblogic.WLST Remote Deploy Command


Symptoms


Failure to remotely deploy a very large enterprise application using WLST or the Admin console and getting out of memory error while loading the ear file.
WLSTException: 'Error occured while performing deploy : Target exception thrown while deploying application: Error occured while performing deploy :
Deployment Failed. Error occurred while performing deploy : Deployment Failed.

Use dumpStack() to view the full stacktrace.
The load of a remotely located ear file also fails via the Administration console with the following message:

An unexpected exception has occurred processing your request Message:
  Stack Trace: java.lang.NullPointerException
  at com.bea.console.actions.app.install.Flow.uploadApp(Flow.java:256)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

Cause


The issue was addressed in bug 9456759. As part of the fix, a system property flag weblogic.deploy.UploadLargeFile was added. In WLS 10.3.4 and higher, this flag should be added to the Java startup options for the deployment client if large files are to be deployed. For earlier versions, apply the patch below: no flag is needed.


Solution


Patches are available for Bug 9456759:
PATCH INFORMATION
WLS VersionPatch Number
9.2.2Patch 9456759
9.2.3Patch 9456759
10.0.1Patch 9456759
10.0.2Patch 9456759
10.3.0Patch 9456759
10.3.1Patch 9456759
10.3.2Patch 9456759

Fixed in: 9.2.4, 10.3.4
To apply one of these patches, click on the link for your WLS version and download the appropriate patch from My Oracle Support. You can also search in My Oracle Support for the patch number for your WLS version:


NOTE: Patches are applied per WLS installation and not per domain. That is, if you apply this patch on one WLS installation, then all of the servers from all the domains in that installation will have this patch. On the other hand, if you have a managed server in another machine in a domain (that is, set up with its own WLS installation), you need to install this patch on that other machine as well. Generally, patches can only be applied while the server is not running because WLS locks the needed files while it is running. If, however, you are able to apply a patch while WLS is running, you must restart WLS before the patch will take effect.

WLST Failed Authentication at connect() When Stopping WebLogic Server


Symptoms

Reports have occurred that users are unable to stop WebLogic Server using stopWebLogic.sh with the following error:

Connecting to t3://hostname.domainname:2001 with userid {AES}qFA3rQexfsasfgjdf560srqyGQ15UNglcziS0uR1yJQw= ...
This Exception occurred at Wed Feb 02 16:31:32 PST 2011.
javax.naming.AuthenticationException [Root exception is java.lang.SecurityException: User:
{AES}qFA3rQexfsasfgjdf560srqyGQ15UNglcziS0uR1yJQw, failed to be authenticated.]
at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:42)
at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:787)
at weblogic.jndi.WLInitialContextFactoryDelegate.pushSubject(WLInitialContextFactoryDelegate.java:681)
at weblogic.jndi.WLInitialContextFactoryDelegate.newContext(WLInitialContextFactoryDelegate.java:469)
at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:376)
at weblogic.jndi.Environment.getContext(Environment.java:315)

How to use WLST to generate report Of Oracle Weblogic Server.


  • WebLogic Server Uptime.
  • WebLogic Server State (Running, Admin, ... etc).
  • WebLogic Server CPU Usage.

Solution

WLST is a JMX Client that you can use to browse WebLogic Server MBeans. A WLST script can be run as the following:

  1. Add WebLogic Server classes to the CLASSPATH environment variable and WL_HOME\server\bin to the PATH environment variable, where WL_HOME refers to the top-level installation directory for WebLogic Server. You can use the setWLSEnv script to set the required variables:
    Windows: WL_HOME\server\bin\setWLSEnv.cmd
    UNIX: WL_HOME/server/bin/setWLSEnv.sh
  2. Execute:
    > java weblogic.WLST /etc/oracle/scripts/server_state.py
Consider the following example for server_state.py:

# Connect to a WebLogic Server:
connect('weblogic','weblogic1','t3://localhost:7001')

# Change from "serverConfig" JMX tree to "serverRuntime" tree.
serverRuntime()

# Use the following attribute to get the startup time,
# Note that value returned is java long file
# and you have to convert it to a readable date.
actTime = get('ActivationTime')

# Get WebLogic State
thisState = get('State')

# Navigate to the JVMRuntime MBean
cd('JVMRuntime/AdminServer')

# Use the following attribute to get the CPU of the JVM, hence the server:
# You might want to multiply this number by 100 to get a precentage
cpuTime = get('JvmProcessorLoad')*100

# Disconnect from the WebLogic Server
disconnect()

# Import python time package
import time
# Use method 'gmtime' to convert 'ActivationTime' to array of
# Year,Month,Day,Hour,and Seconds
x = time.gmtime(actTime/1000)

print
print
print "Start Time : " + str(x[0]) + "/" + str(x[1]) + "/" + str(x[2]) + " - " + str(x[3]) + ":" + str(x[4])
print "Activation Time: " + str(actTime)
print "State: " + thisState
print "CPU: " + str(cpuTime) + "%"
IMPORTANT: To use attribute 'JvmProcessorLoad', you need to make sure that your domain options "Platform MBean Server Enabled" and "isPlatformMBeanServerUsed" are enabled, so using 'WLS Administration Console,' go to your domain -> Configuration -> General -> Advanced and enable them. A restart is required here.
WLST should print output like:
Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'OHS'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)

Disconnected from weblogic server: AdminServer


Start Time : 2011/4/30 - 19:13
Activation Time: 1304190828812
State: RUNNING
CPU: 1.8867924528301887%

Deploying an Application using Production Redeployment Strategy with WLST


This document provides steps for deploying applications using the Production Redeployment strategy with WebLogic Scripting Tool (WLST). Production Redeployment provides application users with 24x7, high availability access without interrupted services.

Solution

In this example we assume that we are deploying application names "survey_web.war" (attached to this note) to an Admin Server running on localhost and port 7001. The username and password will be weblogic/weblogic.
  1. Set WebLogic environment variables by running the setDomainEnv script.
     
  2. Connect to WLST offline mode using below command
    java weblogic.WLST
  3. Connect to the domain using below connect command (to go online):
    connect('weblogic','weblogic','t3://localhost:7001')
  4. Initial deployment and subsequent deployments must be accomplished by naming the deployment versions to ensure high availability and continuity of service:
    Please refer below OTN documentation for more details on options
    http://www.oracle.com/pls/as1111/lookup?id=WLSTC202

    For the first time you deploy application, deploy the application using version number in this example, we will take version number as 10-2.

    Syntax: deploy ('<application name>','<source location>', targets='<target server or cluster>', stageMode='<stage, no stage or external stage>', versionIdentifier='<application version>'
    deploy('survey_web','D:/survey_web.war', targets='AdminServer', stageMode='nostage', versionIdentifier='10-2')

    After deploying the application you can use application name with version number "survey_web (10-2)" in active state in console.
     
  5. To deploy the same application with some updates, deploy the application as below in WLST.

    Syntax: deploy('<application name>','<source location>', archiveVersion='<current version of application>', appVersion='<new version of application>')
    deploy('survey_web','D:/survey_web.war', archiveVersion='10-2', appVersion='10-3')

    The new version of application, 10-3 in this case, will be active and the older archiveVersion 10-2 will go into the retire state after deploying the application with WLST command. So you will have two versions of application: one in active state, and other in retired state.

    The version of the application in the retired state will serve all the existing requests. All new requests will be routed to version of application which is active.


How To Delete JMS Messages from a Queue with the WLST

This document describes WebLogic Scripting Tool (WLST) commands to delete messages from a JMS message queue. Sometime, you may need to delete all the messages from JMS queues. However, using the Queues > Monitoring tab in the console, you might encounter an out of memory condition. This can happen because the console tries to load the messages prior to deleting them, leading to the out of memory condition.

Solution

Run the following sequence of WLST commands, substituting your own server's information where necessary:
wls:/offline> connect('weblogic','welcome1','t3://localhost:7001')

wls:/WLST_domain/serverConfig> serverRuntime()wls:/WLST_domain/serverRuntime> cd('JMSRuntime/AdminServer.jms/JMSServers/JMSServer-0/Destinations/SystemModule-0!Queue-0')wls:/WLST_domain/serverRuntime/JMSRuntime/AdminServer.jms/JMSServers/JMSServer-0/Destinations/SystemModule-0!Queue-0> ls()wls:/WLST_domain/serverRuntime/JMSRuntime/AdminServer.jms/JMSServers/JMSServer-0/Destinations/SystemModule-0!Queue-0> cmo.deleteMessages('')

WLST Script to Get WebLogic Server Patch Levels

Configuring


Make sure the user provided in the script can be authenticated in the domain where the script is run.

Instructions


  1. Save the script given as patchingLevel.py.
  2. Modify the parameters for the user and the connection string to the Admin Server.
  3. Set the domain environment using the script <domain_home>/bin/setDomainEnv.sh.
  4. Run the script as follows:
    $ java weblogic.WLST patchingLevel.py

Caution


This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.

Script

username = 'admin-username'
password = 'admin-password'
connect(username,password, 'wls-hostname:wls-port')
print version
print "\n"
disconnect()
exit()

How to Access PendingRestartSystemResources in ServerRuntime View via WLST

English: The logo of Oracle Corporation de:Bil...
English: The logo of Oracle Corporation de:Bild:Oracle-Logo.svg he:תמונה:Oracle Logo.jpg (Photo credit: Wikipedia)
When a WLST script is using an attribute “PendingRestartSystemResources” on the ServerRuntime to determine what need to restart automatically (i.e. what shows under the Changes and Restarts Checklist tab), it's observed through WLST that the attribute is either not exposed with 10.3.1 or moved somewhere else. In what circumstances is the “PendingRestartSystemResources” attribute accessible?  How can we make sure that this attribute is never missing from the “serverRuntime()” view?  First lets take a look at the WLST attribute dump snippets from serverRuntime() below:


FROM WLS 10.3.0 (working domain)
-r-- MANReplicationRuntime null
-r-- Name AdminServer
-r-- OpenSocketsCurrentCount 1
-rw- Parent null
-r-- PathServiceRuntime null
-r-- PendingRestartSystemResources null
-r-- RestartRequired false
-r-- RestartsTotalCount 0
-r-- SSLListenAddress null
-r-- SSLListenPort 7002
-r-- SSLListenPortEnabled false

FROM WLS 10.3.1 (Not Working Domain)
-r-- MANReplicationRuntime null
-r-- Name AdminServer
-r-- OpenSocketsCurrentCount 1
-r-- OracleHome C:\Oracle\Middleware
-rw- Parent null
-r-- PathServiceRuntime null
-r-- RestartRequired false
-r-- RestartsTotalCount 0
-r-- SSLListenAddress null
-r-- SSLListenPort 7002

Solution

"PendingRestartSystemResources" attribute has always been excluded in the API documentation.

WLST excludes such attributes from its list of displayed attributes but a couple of options are available:

1) This attribute should be available from a JMX Client (like JConsole) if the user wants to write his or her own JMXClient to retrieve it.
2) WLST has a hidden/unpublished option to set a parameter in the context. The parameter is called "showExcluded'

So, to view "PendingRestartSystemResources" in the serverRuntime() view, after connecting to the server, just execute the showExcluded() command. Then ls() should list all the excluded attributes, which will include "PendingRestartSystemResources".

How to rotate Oracle WebLogic Server logs to avoid large files using WLST

By default, when WebLogic Server instances are started in development mode, the server automatically renames (rotates) its local server log file as SERVER_NAME.log.n.  For the remainder of the server session, log messages accumulate in SERVER_NAME.log until the file grows to a size of 500 kilobytes.

Each time the server log file reaches this size, the server renames the log file and creates a new SERVER_NAME.log to store new messages. By default, the rotated log files are numbered in order of creation filenamennnnn, where filename is the name configured for the log file. You can configure a server instance to include a time and date stamp in the file name of rotated log files; for example, server-name-%yyyy%-%mm%-%dd%-%hh%-%mm%.log.



By default, when server instances are started in production mode, the server rotates its server log file whenever the file grows to 5000 kilobytes in size. It does not rotate the local server log file when the server is started. For more information about changing the mode in which a server starts, see Change to production mode” in the Administration Console Online Help.

You can change these default settings for log file rotation. For example, you can change the file size at which the server rotates the log file or you can configure a server to rotate log files based on a time interval. You can also specify the maximum number of rotated files that can accumulate. After the number of log files reaches this number, subsequent file rotations delete the oldest log file and create a new log file with the latest suffix.


Note: WebLogic Server sets a threshold size limit of 500 MB before it forces a hard rotation to prevent excessive log file growth.

Customizing Oracle WebLogic Server (WLS) Domain Template Log File Settings with WLST Fails

When using the WebLogic Server Scripting Too (WLST) to modify a domain template and customize the log file settings, some changes do not get saved. For example, this option is not saved when configured as true.

newLog.setRotateLogOnStartup(true)

After using the template to create a domain the option is being configured as false.

Cause

It appears that when using production mode, the default for the rotate logs on start-up option is false; but WLST does not recognize this, and will not allow the option to be enabled.

WLST defaults to development mode and will not set options that are standard defaults when in development mode.

Solution


The WLST application is designed to use the development defaults when using offline mode to create domains and will not update the config.xml with entries that are considered the default values.

After the domain has been created, then WLST can use online mode to make changes and it will use the values that exist or are set at that time.

1. Create the domain using the default parameters.

2. Connect in online mode to the newly created domain and modify the parameters that need to be configured for production mode.


Note:This document will apply to any parameter that is set using WLST in offline mode. If the parameter has a default for development mode this will be the default used with offline mode and the parameter can only be changed in online mode.

The documentation for each parameter will usually cover the default values for development and production modes.

Oracle Weblogic Server : How to Disable the Exception Stack Trace in a WLST Script

This document describes how to disable an exception stack trace from writing out to the screen from a WebLogic Scripting Tool (WLST) Python script file. A small demonstration is provided to show how the parameter works.
A Python script file, with try/catch code implemented, will display a stack trace to the screen when the script is executed with WLST.


Here is an example. The abc.py script file is using an invalid password:

try:
  connect('weblogic','invalid_password','t3://localhost:7001')
   print "Successfully connected"
except:
  print "Error while trying to connect!!!"
exit()
Execute the script file as follows, and observe the output shown:

/WLS/bea1030/wlserver_10.3/common/bin>wlst.sh abc.py
Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
This Exception occurred at Fri Apr 22 05:34:13 IST 2011.
javax.naming.AuthenticationException [Root exception is java.lang.SecurityExcept
ion: User: weblogic, failed to be authenticated.]
at weblogic.jndi.internal.ExceptionTranslator.toNamingException(Exceptio
nTranslator.java:42)
at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLIni
tialContextFactoryDelegate.java:783)
at weblogic.jndi.WLInitialContextFactoryDelegate.pushSubject(WLInitialCo
ntextFactoryDelegate.java:677)
.
.
.
.
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:473)
at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.jav
a:118)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Error while trying to connect!!!

Exiting WebLogic Scripting Tool.

Solution

To resolve the issue, use the following script which redirects the stack trace to a temp file and then deletes the temp file in the end:

import tempfile
import os
wlstOut = tempfile.mktemp(suffix="_wlst.txt")
redirect(wlstOut,"false")
try:
   connect('weblogic','weblogic','t3://localhost:7001')
   stopRedirect()
   print "Successfully connected"
except:
   stopRedirect()
   print "Error while trying to connect!!!"
os.remove(wlstOut)
exit()
Thus running the script now will give following output (excluding the stack trace for the exception), which is the goal:
/WLS/bea1030/wlserver_10.3/common/bin>wlst.sh abc.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...

Error while trying to connect!!!

Exiting WebLogic Scripting Tool.

How to Change Oracle Weblogic Server User Password Using WLST

1. Setting environment variable
    a. go to directory $WLS_HOME/wlserver_10.3/server/bin
    b. source file setWLSEnv.sh  as command: . setWLSEnv.sh .

My Configurations

1. Create a domain which name is test1032,
2. Weblogic admin user name is weblogic, password is weblogic1.
3. Create test user, which name is test and password is weblogic1.



Instructions

$java weblogic.WLST changepw.py <Domain Name> <Admin URI> <Admin user> <Admin password> <user name> <user password>

<Domain Name> : the domain name which need to change user password. e.g. test1032
<Admin URI>   : weblogic server adminstration URL, e.g. t3://localhost:7001
<Admin user>  : weblogic admin user, e.g. weblogic
<Admin password>  : admin user password, e.g. weblogic1
<user name>       : the user who need to change password. e.g. test
<user password>   : new user password. .e.g welcome1


Script

1. create file named /home/zsy/changepw.py which contents as below:

if len(sys.argv) != 7:
print 'Usage: java weblogic.WLST changepw.py <Domain Name> <Admin URI> <Admin user> <Admin password> <user name> <user password> '
sys.exit(1)

DomainName = sys.argv[1]
ADMINUrl = sys.argv[2]
ADMINuser = sys.argv[3]
ADMINPwd = sys.argv[4]
UserToChange = sys.argv[5]
NewUserPassword=sys.argv[6]

print "DomainName: %s" % (DomainName)
print "ADMINUrl: %s" % (ADMINUrl)
print "ADMINuser: %s" % (ADMINuser)
print "AdminPassword: %s" % (ADMINPwd)
print "UserToChange: %s" % (UserToChange)
print "NewUserPassword: %s" % (NewUserPassword)


print ' ---- Connecting to domain with user: '+ADMINuser+' ------- '
print ' '
connect(ADMINuser,ADMINPwd,ADMINUrl)
cd('/SecurityConfiguration/'+DomainName+'/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator')
print 'Changing password for user: '+UserToChange
cmo.resetUserPassword(UserToChange,NewUserPassword)

print ' ---- Password for User: '+UserToChange+' changed Successfully --- '
print ' '
disconnect()
print ' '

disconnect()

2. The command to run above script, e.g. change password from weblogic1 to weblogic
java weblogic.WLST changepw.py test1032 t3://localhost:7001 weblogic weblogic1 test welcome1

Sample Output

$ java weblogic.WLST changepw.py test1032 t3://localhost:7001 weblogic weblogic1 test welcome1

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

DomainName: test1032
ADMINUrl: t3://localhost:7001
ADMINuser: weblogic
AdminPassword: weblogic1
UserToChange: test
NewUserPassword: welcome1
---- Connecting to domain with user: weblogic -------

Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'test1032'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

Changing password for user: test
---- Password for User: test changed Successfully ---

Disconnected from weblogic server: AdminServer


You will need to be connected to a running server to execute this command