Saturday, 3 December 2016

Python Script - DB Adapter Connection Pool JNDI Creation

DB Adapter Connection Pool JNDI Creation



I want to create Database adapter connection pool JNDI using Python Script.

My Server Details are,

Cluster Environment: 1 Admin Server and 2 Managed Server (wls_osb1 and wls_osb2) 
Domain Name: soa_domain
Cluster Name: osb_cluster

Save below weblogic.properties file as weblogic.properties


#################################################################################

# admin server url
admin.url=t3://localhost:7001


#################################################################################

#Domain Name:
domainName=soa_domain
osbServer1=wls_osb1
osbServer2=wls_osb2

#Manage Server Name:
targetServer.1=wls_osb1
targetServer.2=wls_osb2

#Cluster Name:
osb_ClusterName=osb_cluster
migrateServerType=MigratableTarget
clusterServerType=Cluster
normalServerType=Server


#################################################################################
#Plan and Adapter Path
shared_DB_PlanPath=/u01/Middleware/Oracle_OSB1/soa/connectors/DB_plan.xml
DB_appPath =/u01/Middleware/Oracle_OSB1/soa/connectors/DbAdapter.rar


#################################################################################

#DB adapter JNDI entry

#Total how many DB JNDI needs to be create
total.DBjndi=6

eisName.1=eis/DB/OFM
ds.1=jdbcOFMDBDS_OFM
dataSourceName.1=
platformClassName.1=org.eclipse.persistence.platform.database.Oracle10Platform

eisName.2=eis/DB/OFMXref
ds.2=jdbcOFMCrossRefDS
dataSourceName.2=
platformClassName.2=org.eclipse.persistence.platform.database.Oracle10Platform

eisName.3=eis/DB/OFMOI
ds.3=jdbcOFMDBDS_OFMOI
dataSourceName.3=
platformClassName.3=org.eclipse.persistence.platform.database.Oracle10Platform

eisName.4=eis/DB/ExceptionHandlerOFMOI
ds.4=jdbcExceptionOFMOIDS
dataSourceName.4=
platformClassName.4=org.eclipse.persistence.platform.database.Oracle10Platform

eisName.5=eis/DB/ExceptionHandlerOFM
ds.5=jdbcExceptionOFMDS
dataSourceName.5=
platformClassName.5=org.eclipse.persistence.platform.database.Oracle10Platform

eisName.6=eis/DB/OFMOIXref
ds.6=jdbcOFMCrossRefDS
dataSourceName.6=
platformClassName.6=org.eclipse.persistence.platform.database.Oracle10Platform


#################################################################################

Now, below python script you have to save as create_DBAdapters.py


#################################################################################


#!/usr/bin/python
from java.io import FileInputStream
import time

propInputStream= FileInputStream('weblogic.properties')
configProps = Properties()
configProps.load(propInputStream)

adminURL= configProps.get('admin.url')
# Enter username and password
adminUserName= ''
adminPassword= ''
total_jndi_to_create=configProps.get('total.DBjndi')

appName              = 'DbAdapter'
moduleOverrideName   = appName+'.rar'
moduleDescriptorName = 'META-INF/weblogic-ra.xml'

planPath = configProps.get('shared_DB_PlanPath')
appPath = configProps.get('DB_appPath')


def makeDeploymentPlanVariable(wlstPlan, name, value, xpath, origin='planbased'):
  """Create a varaible in the Plan.
  This method is used to create the variables that are needed in the Plan in order
  to add an entry for the outbound connection pool for the new data source.
  """
  try:

    variableAssignment = wlstPlan.createVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
    variableAssignment.setXpath(xpath)
    variableAssignment.setOrigin(origin)
    wlstPlan.createVariable(name, value)
  except:
    print('--> was not able to create deployment plan variables successfully')
def main():
  #
  # generate a unique string to use in the names
  #
  uniqueString =''
  uniqueString = str(int(time.time()))
  #
  # Create a JDBC Data Source.
  #
  try:
    print('--> about to connect to weblogic')
    connect(adminUserName, adminPassword, adminURL)
    edit()

#
# update the deployment plan
#
    startEdit()
    i=1
    while (i <= int(total_jndi_to_create)):
cd('/')
print('--> about to update the deployment plan for the DbAdapter')
eisName = configProps.get("eisName."+ str(i))
print('--> about to create a Adapter JNDI' + eisName)
dsName = configProps.get("ds."+ str(i))
print('--> about to assign a data source ' + dsName)
DataSourceName = configProps.get("dataSourceName."+ str(i))
print('--> about to assign a data source ' + DataSourceName)
PlatformClassName = configProps.get("platformClassName."+ str(i))
print('--> about to assign a PlatformClassName ' + PlatformClassName)
startEdit()
print('--> Using plan ' + planPath)
plan = loadApplication(appPath, planPath)
print('--> adding variables to plan')
print '___ BEGIN change plan'
makeDeploymentPlanVariable(plan, 'ConnectionInstance_'+ eisName +'_JNDIName_'+ uniqueString, eisName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ eisName + '"]/jndi-name')
makeDeploymentPlanVariable(plan, 'ConfigProperty_xADataSourceName_'+ dsName + '_',dsName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ eisName + '"]/connection-properties/properties/property/[name="xADataSourceName"]/value')
makeDeploymentPlanVariable(plan, 'ConfigProperty_xADataSourceName_'+ DataSourceName + '_',DataSourceName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ eisName + '"]/connection-properties/properties/property/[name="dataSourceName"]/value')
makeDeploymentPlanVariable(plan, 'ConfigProperty_xADataSourceName_'+ PlatformClassName + '_',PlatformClassName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ eisName + '"]/connection-properties/properties/property/[name="platformClassName"]/value')
print '___ DONE change plan'
print('--> saving plan')
plan.save();
save();
print('--> activating changes')
activate(block='true');
cd('/AppDeployments/DbAdapter/Targets');
print('--> redeploying the DbAdapter')
 
redeploy(appName, planPath, targets=cmo.getTargets());
print('--> done')
i=i+1
  except:
     print('--> something went wrong, bailing out', sys.exc_info()[0])
     stopEdit('y')
     raise SystemExit

main()

#################################################################################



Procedure to run above python script,

Step1: Copy your weblogic.properties and create_DBAdapters.py        
           in <Middleware_Home>/wlserver_10.3/common/bin location. Where wlst.sh or wlst.cmd present
Step2: Run ./wlst.sh (if you install middleware in UNIX) or wlst.cmd (if you install middleware in 
            windows)
           ./wlst.sh arcd_create_DBAdapters.py then press enter
Step 3: When Username and Password asked that time you have to pass weblogic console username and password.

No comments:

Post a Comment