Saturday 3 December 2016

Python Script - AQ Adapter Connection Pool JNDI Creation

AQ Adapter Connection Pool JNDI Creation



I want to create AQ 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_AQ_PlanPath=/u01/Middleware/Oracle_OSB1/soa/connectors/AQ_plan.xml
AQ_appPath =/u01/Middleware/Oracle_OSB1/soa/connectors/AqAdapter.rar

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

# AQ adapter JNDI entry
#Total how many AQ JNDI needs to be create
total.AQjndi=4

AQeisName.1=eis/AQ/OFM
AQds.1=jdbcOFMAQDS_OFM

AQeisName.2=eis/AQ/EventEngineOFMOI
AQds.2=jdbcEventEngineDSOFMOI

AQeisName.3=eis/AQ/EventEngineOFM
AQds.3=jdbcEventEngineDSOFM

AQeisName.4=eis/AQ/OFMOI
AQds.4=jdbcOFMAQDS_OFMOI

#################################################################################
Now, below python script you have to save as create_AQAdapters.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.AQjndi')

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

planPath = configProps.get('shared_AQ_PlanPath')
appPath = configProps.get('AQ_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 AqAdapter')
eisName = configProps.get('AQeisName.'+ str(i))
print('--> about to create a Adapter JNDI ' + eisName)
dsName = configProps.get("AQds."+ str(i))
print('--> about to assign a data source ' + dsName)
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')
print '___ DONE change plan'
print('--> saving plan')
plan.save();
save();
print('--> activating changes')
activate(block='true');
cd('/AppDeployments/AqAdapter/Targets');
print('--> redeploying the AqAdapter')
 
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_AQAdapters.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_AQAdapters.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