Monday, April 28, 2014

WLST script to set the JDBC Connection timeout properties in weblogic server

WLST script to set the JDBC Connection timeout properties in weblogic server


There are different timeout properties in JDBC connection, this tutorial explains the approach to set some of the important JDBC Connection timeout properties in weblogic server through WLST script.

Inactive Connection Timeout


The number of inactive seconds on a reserved connection before WebLogic Server reclaims the connection and releases it back into the connection pool.
You can use the Inactive Connection Timeout feature to reclaim leaked connections — connections that were not explicitly closed by the application.


Connection Reserve Timeout


The number of seconds after which a call to reserve a connection from the connection pool will timeout.
When set to 0, a call will never timeout.
When set to -1, a call will timeout immediately.


Statement Timeout


The time after which a statement currently being executed will time out.
A value of -1 disables this feature.
A value of 0 means that statements will not time out.


oracle.jdbc.ReadTimeout


The property oracle.jdbc.ReadTimeout helps to set read timeout while reading from the socket.

oracle.net.READ_TIMEOUT for jdbc versions < 10.1.0.5 oracle.jdbc.ReadTimeout for jdbc versions >=10.1.0.5


oracle.net.CONNECT_TIMEOUT


The property oracle.net.CONNECT_TIMEOUT helps to set the login time out in Oracle.
WLST Script

The below WLST script will help us to set the JDBC connection timeout properties

SetJDBCTimeoutProperties.py
def setJDBCTimeoutProperties():
   dsName='CRM6EAIReference'
   edit()
   startEdit()
       
   server='AdminServer'
   cd("Servers/"+server)
   target=cmo
 
   print '========================================='
   print 'Setting the timeout properties for DataSource....'
   print '========================================='  
           
   cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName)
   #cmo.destroyProperty(getMBean('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'/Properties/oracle.net.CONNECT_TIMEOUT'))
   cmo.createProperty('oracle.net.CONNECT_TIMEOUT')


Script

https://github.com/techforum-repo/youttubedata/blob/master/scripts/wlst/SetJDBCTimeoutProperties.py

Before executing the script, change the configurations as required.

Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd SetJDBCTimeoutProperties.py



Restart the server after successful execution. Now the JDBC connection timeout properties are set to the datasource.



Under advanced section



Saturday, April 26, 2014

A timeout occurred while interacting with sever. Limited information is available - Weblogic

A timeout occurred while interacting with sever. Limited information is available  - Weblogic 

We were getting the error "A timeout occurred while interacting with Server. Limited information is available" while accessing the Server Page from the admin console in clustered weblogic environment and the health of the server is shown as empty but the state is shown as running.
Login to the admin console and accessing the Server page also was taking more time
But the individual servers and the node managers are running fine in all the nodes.


The issue seems to be because of the delay in the communication between the node manager and the managed servers.

Steps to resolve the issue:

  • Stop all the managed servers from all the nodes.
  • Kill the node managers from all the nodes.
  • Stop the Admin server.
  • Start the node manager in all the nodes.
  • Start the Admin server.
  • Start all the managed server.



Wednesday, April 23, 2014

Error while creating datasource using WLST - java.lang.ClassCastException

Error while creating datasource using WLST - java.lang.ClassCastException

When we are creating the datasource through WLST script in weblogic server may may receive the following exception in create method.

Creating DataSource:  EAISOAMetadataSource  ....
Problem invoking WLST - Traceback (innermost last):
  File "/reuters/oracle/as01/wlst/GridLinkDatasourceCreation.py", line 115, in ?
  File "/reuters/oracle/as01/wlst/GridLinkDatasourceCreation.py", line 108, in main
  File "/reuters/oracle/as01/wlst/GridLinkDatasourceCreation.py", line 39, in createGridLinkJDBCResources
  File "<iostream>", line 528, in create
        at weblogic.management.scripting.EditHandler.create(EditHandler.java:531)
        at weblogic.management.scripting.WLScriptContext.create(WLScriptContext.java:332)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)

java.lang.ClassCastException: java.lang.ClassCastException: java.lang.reflect.InvocationTargetException cannot be cast to weblogic.management.scripting.ScriptException

I colud not able to find the exact root cause but able to resolve the issue "Undo All Changes" from weblogic console and re-exectiong the script.

Steps to resolve the issue

Login to weblogic admin console
Verify whether any changes are pending to be activated.
Perform Activate Changes or Undo All Changes


Re-execute the script, this time script will create the datasource successfully.


Different approaches for connecting Weblogic Server to RAC database

Different approaches for connecting Weblogic Server to RAC database

Oracle Real Application Clusters (RAC) is a software component you can add to a high-availability solution that enables users on multiple machines to access a single database with increased performance. RAC comprises two or more Oracle database instances running on two or more clustered machines and accessing a shared storage device via cluster technology.


If your application requires load balancing across RAC nodes, WebLogic Server supports this capability through use of Using Connect-Time Load Balancing/Failover with Oracle RAC(JDBC URL based Load Balancing/Failover), JDBC Multi Data sources with Oracle RAC nodes and Gridlink Data Source.

Multi Data Source:

Refer the below URL's for details on Multi Data Source.

http://www.albinsblog.com/2012/02/jdbc-multi-data-sources-in-weblogic.html#.U1YNuvmukdQ
http://www.albinsblog.com/2012/02/creating-jdbc-multi-data-source-through.html

Connect-Time Load Balancing/Failover with Oracle RAC(JDBC URL based Load Balancing/Failover):

The JDBC connection string can be configure with single data source to support the load balancing and failover with RAC data source nodes.
Create a Generic Data source in weblogic server and provide the JDBC URL as below.Enable and disable the load balancing and failover accordingly.

jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=on)(FAILOVER=on)(ADDRESS=(PROTOCOL=tcp)(HOST=RAC node1)(PORT=1521))(ADDRESS=(PROTOCOL=tcp)(HOST=RAC node2)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=servicename)))

There are some limitation using this approach like the Global XA transactions are not supported.



WLST script to create Gridlink data source in weblogic

WLST script to create Gridlink data source in weblogic

This tutorial explains the approach to create Gridlink data source through WLST script in weblogic

Refer the below URL for details on Gridlink data source

https://www.albinsblog.com/2014/04/different-approaches-for-connecting.html


WLST Script


The below WLST script creates the Gridlink datasource with enabled configurations

GridLinkDataSource.properties

dbURL=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost1)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost2)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=SERVICENAME)))
connectionpool.test.query=SQL SELECT * FROM DUAL
connectionpool.driver.class=oracle.jdbc.OracleDriver
connectionpool.username=SOA_EAIOWNER
connectionpool.password=orasoa11g
connectionpool.initCapacity=10
connectionpool.maxCapacity=60
datasource.name=EAISOAMetadataSource
datasource.jndi.name=eai/ds/EAISOAMetadataSource
datasource.target=Servers/AdminServer

domain.AdminIP=localhost
domain.AdminPort=7201

domain.AdminPasswd=Albin123!

GridLinkDatasourceCreation.py

from java.io import FileInputStreamdef createGridLinkJDBCResources(configProps):
   edit()
   startEdit()
        
   server='AdminServer'
   cd("Servers/"+server)
   target=cmo
   cd("../..")
   print '========================================='
   print 'Creating GridLink DataSource....'
   print '========================================='
   dsTestQuery=configProps.get("connectionpool.test.query")
   dsDriverName=configProps.get("connectionpool.driver.class")
  
            
   cd('/')
   dbURL= configProps.get("dbURL")           
   dsUserName = configProps.get("connectionpool.username")
   dsPassword = configProps.get("connectionpool.password")
   initCapacity = configProps.get("connectionpool.initCapacity")
   maxCapacity = configProps.get("connectionpool.maxCapacity")
   dsName = configProps.get("datasource.name")
   jndiname = configProps.get("datasource.jndi.name")
   datasourceTargets = configProps.get("datasource.target").split(",")print 'dsUserName',dsUserName
   print 'dsPassword',dsPassword
   print 'initCapacity',initCapacity
   print 'maxCapacity',maxCapacity
   print 'dsName',dsName
   print 'jndiname',jndiname
   print 'datasourceTargets',datasourceTargetsprint 'Creating DataSource: ',dsName,' ....'
  
   myResourceName = dsName   
   jdbcSystemResource = create(myResourceName,"JDBCSystemResource")     
   myFile = jdbcSystemResource.getDescriptorFileName()     
   jdbcResource = jdbcSystemResource.getJDBCResource()     
   jdbcResource.setName(myResourceName)# Create the DataSource Params     
   dpBean = jdbcResource.getJDBCDataSourceParams()     
   myName=jndiname 
   dpBean.setJNDINames([myName]) 
   dpBean.setGlobalTransactionsProtocol('TwoPhaseCommit')
    
   # Create the Driver Params     
   drBean = jdbcResource.getJDBCDriverParams()     
   drBean.setPassword(dsPassword)     
   drBean.setUrl(dbURL)     
   drBean.setDriverName(dsDriverName)#Create the Oracle params
   orapr=jdbcResource.getJDBCOracleParams()
   orapr.setFanEnabled(true)
   orapr.setOnsNodeList('node1:6200,node2:6200')
   propBean = drBean.getProperties()
   driverProps = Properties()     
   driverProps.setProperty("user",dsUserName)
   e = driverProps.propertyNames()
   while e.hasMoreElements() :             
  propName = e.nextElement()             
  myBean = propBean.createProperty(propName)           
  myBean.setValue(driverProps.getProperty(propName))   
  
  # Create the ConnectionPool Params     
  ppBean = jdbcResource.getJDBCConnectionPoolParams()     
  ppBean.setInitialCapacity(int(initCapacity))     
  ppBean.setMaxCapacity(int(maxCapacity))     
  ppBean.setTestConnectionsOnReserve(true)     
  ppBean.setTestTableName('SQL SELECT 1 FROM DUAL')xaParams = jdbcResource.getJDBCXAParams()     
  xaParams.setKeepXaConnTillTxComplete(1)# Add Target
   for datasourceTarget in datasourceTargets:
  print 'DataSourceTargets',datasourceTargets
  print 'DataSourceTarget',datasourceTarget
  if datasourceTarget=='':
   print ''
  else:
   jdbcSystemResource.addTarget(getMBean(datasourceTarget))     
  
 
   print 'DataSource: ',dsName,', has been created Successfully !!!'
   print '========================================='   
        
  
   save()
   activate()def main():
    propInputStream1 = FileInputStream("GridLinkDataSource.properties")
    configProps = util.Properties()
    configProps.load(propInputStream1)
  
    adminURL='t3://'+configProps.get('domain.AdminIP')+':'+configProps.get('domain.AdminPort')
    adminUserName='weblogic'
    adminPassword=configProps.get("domain.AdminPasswd")
    connect(adminUserName, adminPassword, adminURL)
  
    createGridLinkJDBCResources(configProps); 
  
    print 'Successfully created JDBC resources for SOACoreDomain'disconnect()main()

Script

https://github.com/techforum-repo/youttubedata/tree/master/scripts/wlst/GridLinkDatasourceCreation

Before executing the script, change the configurations as required.Change the ONS node details in the script.

Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd GridLinkDatasourceCreation.py



After the successful execution of the script login to console and verify the Gridlink datasource created.