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

Friday, September 7, 2012

Modifying the targets of JDBC datasources through WLST script in weblogic server

Modifying the targets of JDBC datasources through WLST script in weblogic server

This tutorial explains the details on WLST script to change or add the targets for JDBC data sources in weblogic server.

The targeting can be enabled through weblogic admin console but the script helps us to automate the server configurations and reduce the manual effort if multiple data-sources need to be configured.
wlst-modify-jdbc-datasource-targets
The script will target the server MS3 and the Cluser1 to the data source with name “CRM6EAIReference”

Define JDBCProperties.properties with required configurations(sample script to show the configuration for multiple data-sources)

domain1.total.DS=2
domain1.prefix.1=om
domain1.om.datasource.name.1=CRM6EAIReference
domain1.om.datasource.target.1=Clusters/Cluster1,Servers/MS3
domain1.prefix.2=soa
domain1.soa.datasource.name.2=CRM6EAISOAMetadataSource
domain1.soa.datasource.target.2=Clusters/SOACluster

Before executing the script change the properties as required.If the target is a Server then it should be added like Servers/ServerName and if it is a cluster then it should be defined as Clusters/ClusterName. Configure domain1.total.DS with total number of data sources need to be configured.

Let us now define a WLST script file to change the targets using the property file defined above.

import re
from java.io import FileInputStream   

def UntargetTargetJDBCResources():
    edit()
    startEdit()
    propInputStream = FileInputStream('JDBCProperties.properties')
    configProps = Properties()
    configProps.load(propInputStream)    

    totalDataSource_to_untargetTarget=configProps.get("domain1.total.DS")
    
    server='AdminServer'
    cd("Servers/"+server)
       
    i=1
    while (i <= int(totalDataSource_to_untargetTarget)) :
    prefix = configProps.get("domain1.prefix."+ str(i))
    dsName = configProps.get("domain1."+prefix+".datasource.name."+ str(i))
    datasourceTargets = re.split(",",configProps.get("domain1."+prefix+".datasource.target."+ str(i)))
    targetArray=[] 
    
    for datasourceTarget in datasourceTargets:
   print 'DataSourceTargets',datasourceTargets
   print 'DataSourceTarget',datasourceTarget
   if datasourceTarget=='':
    print ''
   else:
    cd ('/JDBCSystemResources/'+dsName)
    set('Targets',jarray.array([], ObjectName))
    target=datasourceTarget[datasourceTarget.index("/")+1:len(datasourceTarget)]       
    if datasourceTarget.startswith('Cluster'):
     targetArray.append(ObjectName('com.bea:Name='+target+',Type=Cluster'))     
    elif datasourceTarget.startswith('Server'):
     targetArray.append(ObjectName('com.bea:Name='+target+',Type=Server'))         
   
    print 'Targets: ',targetArray
    set('Targets',jarray.array(targetArray, ObjectName))
    print 'DataSource: ',dsName,',Target has been updated Successfully !!!'
    print '========================================='    
    i = i + 1

    print '========================================='
    save()
    activate()
def main():
    adminURL='t3://localhost:7001'
    adminUserName='weblogic'
    adminPassword='weblogic1'
    connect(adminUserName, adminPassword, adminURL)
    UntargetTargetJDBCResources();
    print 'Successfully Modified the JDBC resources'
    disconnect()
main()

Script - 

The above script update the JDBC data source targets based on the configurations enabled in the property file.

Execute the script — <<Oracle_Home>>\oracle_common\common\bin\wlst.cmd ModifyJDBCResourcesTargets.py
wlst-modify-jdbc-datasource-targets
The JDBC data source targets changed now with the enabled configurations,the WLST script can be used to automate the server configurations and reduce the manual effort need for configurations.

Wednesday, September 5, 2012

Creating Socket Adapter connection factories through WLST script - Oracle SOA Suite

Creating Socket Adapter connection factories through WLST script - Oracle SOA Suite

The below WLST script will help us to create the Socket adapter connection factories in Oracle SOA Suite 11g or Oracle SOA Suite 12c

Change the Socket/SOA server details accordingly in the script.

Before executing the script make sure the SocketAdapter is targeted to the servers.

socket_adapter_target_servers

CreateSocketConnectionFactory.py

TargetServerName='AdminServer'

soaHome='C:\EnvSetup\MiddlewareBlog\Oracle_SOA1'

appPathSock=soaHome+'\soa\connectors\SocketAdapter.rar'
appNameSock='SocketAdapter'
moduleOverrideNameSock=appNameSock+'.rar'
SockJNDIName = 'eis/socket/SocketAdapterBlog'
#Socket Sever Details
HostName='101.63.203.129'
Password='blogenv1'
Port='7001'
UserName='weblogic'

moduleDescriptorName='META-INF/weblogic-ra.xml'
planPathSock='C:\EnvSetup\MiddlewareBlog\Oracle_SOA1\soa\connectors\Plan_Soket.xml'

def createSocketConnectionFactory(): 

        edit()
        startEdit()
        startApplication(appNameSock)
        myPlanSock=loadApplication(appPathSock, planPathSock)
        makeDeploymentPlanVariable(myPlanSock,'ConnectionInstance_eis/Socket_JNDIName_13102979357209', SockJNDIName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+SockJNDIName+'"]/jndi-name',moduleOverrideNameSock)
        makeDeploymentPlanVariable(myPlanSock, 'ConfigProperty_eis/Socket_JNDIName_Host_Name_13102979357210', HostName,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+SockJNDIName+'"]/connection-properties/properties/property/[name="Host"]/value',moduleOverrideNameSock)
        makeDeploymentPlanVariable(myPlanSock, 'ConfigProperty_eis/Socket_JNDIName_Port_13102979357212', Port,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+SockJNDIName+'"]/connection-properties/properties/property/[name="Port"]/value',moduleOverrideNameSock)
               
        myPlanSock.save();
        save();
        cd('/AppDeployments/SocketAdapter/Targets');
        updateApplication(appNameSock, planPathSock);
        startApplication(appNameSock);
        activate(block='true');
      
   
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath,overrideName, origin='planbased'):
    wlstPlan.destroyVariable(name)
    wlstPlan.destroyVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment = wlstPlan.createVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment.setXpath(xpath)
    variableAssignment.setOrigin(origin)
    wlstPlan.createVariable(name, value)
    print 'moduleDescriptorName=',moduleDescriptorName


def main():
       #SOA Server Details
       adminURL='t3://localhost:7001'
       adminUserName='weblogic'
       adminPassword='blogenv1'
       connect(adminUserName, adminPassword, adminURL)
       createSocketConnectionFactory()
       disconnect()
main()

Login to the server, cd to the folder where the script is available and execute the script as shown below.

%MIDDLEWARE_HOME%\wlserver_10.3\common\bin\wlst.cmd CreateSocketConnectionFactory.py




DOWNLOAD  CreateSocketConnectionFactory.py

Tuesday, September 4, 2012

Creating Oracle BAM Adapter connection factories through WLST script in Oracle SOA Suite

Creating Oracle BAM Adapter connection factories through WLST script in Oracle SOA Suite

The below WLST script will help us to create the Oracle  BAM adapter connection factories in Oracle SOA Suite.
Change the BAM/SOA server details accordingly.

Before executing the script make sure the OracleBamAdapter is targeted to the server.

oraclebamadapter_target_server

CreateBAMConnectionFactory.py

TargetServerName='AdminServer'

soaHome='C:\EnvSetup\MiddlewareBlog\Oracle_SOA1'

appPathBAM=soaHome+'\soa\connectors\OracleBamAdapter.rar'
appNameBAM='OracleBamAdapter'
moduleOverrideNameBAM=appNameBAM+'.rar'
BAMJNDIName = 'eis/BAM/Connection'
#BAM Server Details
HostName='localhost'
Password='blogenv1'
Port='7001'
UserName='weblogic'

moduleDescriptorName='META-INF/weblogic-ra.xml'
planPathBAM='C:\EnvSetup\MiddlewareBlog\Oracle_SOA1\soa\connectors\Plan_BAM.xml'

def createBAMConnectionFactory(): 

        edit()
        startEdit()
        startApplication(appNameBAM)
        myPlanBAM=loadApplication(appPathBAM, planPathBAM)
        makeDeploymentPlanVariable(myPlanBAM, 'ConnectionInstance_eis/BAM/BAM_JNDIName_13102979357209', BAMJNDIName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/jndi-name',moduleOverrideNameBAM)
       
        makeDeploymentPlanVariable(myPlanBAM, 'ConfigProperty_eis/BAM/BAM_JNDIName_Host_Name_13102979357210', HostName,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.bam.adapter.adc.RMIConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/connection-properties/properties/property/[name="HostName"]/value',moduleOverrideNameBAM)
       
        makeDeploymentPlanVariable(myPlanBAM, 'ConnectionInstance_eis/BAM/BAM_JNDIName_Password_13102979357211', Password , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.bam.adapter.adc.RMIConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/connection-properties/properties/property/[name="Password"]/value',moduleOverrideNameBAM)
       
        makeDeploymentPlanVariable(myPlanBAM, 'ConfigProperty_eis/BAM/BAM_JNDIName_Port_13102979357212', Port,'/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.bam.adapter.adc.RMIConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/connection-properties/properties/property/[name="PortNumber"]/value',moduleOverrideNameBAM)
       
        makeDeploymentPlanVariable(myPlanBAM, 'ConnectionInstance_eis/BAM/BAM_JNDIName_UserName_13102979357211', UserName , '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.bam.adapter.adc.RMIConnectionFactory"]/connection-instance/[jndi-name="'+BAMJNDIName+'"]/connection-properties/properties/property/[name="UserName"]/value',moduleOverrideNameBAM)
       
        myPlanBAM.save();
        save();
        cd('/AppDeployments/OracleBamAdapter/Targets');
        updateApplication(appNameBAM, planPathBAM);
        activate(block='true');
      
   
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath,overrideName, origin='planbased'):
    wlstPlan.destroyVariable(name)
    wlstPlan.destroyVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment = wlstPlan.createVariableAssignment(name, overrideName, moduleDescriptorName)
    variableAssignment.setXpath(xpath)
    variableAssignment.setOrigin(origin)
    wlstPlan.createVariable(name, value)
    print 'moduleDescriptorName=',moduleDescriptorName


def main():
       #SOA Server Details
       adminURL='t3://localhost:7001'
       adminUserName='weblogic'
       adminPassword='blogenv1'
       connect(adminUserName, adminPassword, adminURL)
       createBAMConnectionFactory()
       disconnect()
main()

Login to the server, cd to the folder where the script is available and execute the script as shown below.

%MIDDLEWARE_HOME%\wlserver_10.3\common\bin\wlst.cmd CreateBAMConnectionFactory.py




The same script will not work in Oracle SOA Suite 12c - the connection-factory-interface javax.resource.cci.ConnectionFactory is not working with 12c. Refer the attached script specific to 12c

DOWNLOAD CreateBAMConnectionFactory.py    CreateBAMConnectionFactory_12c.py

Wednesday, May 2, 2012

WLST script to reset data source password in weblogic server

WLST script to reset data source password in weblogic server


This tutorial explains the approach to reset the password of all the data sources in weblogic server. Sometime we may need to reset the password of all the data sources, the below WLST script can be used to achieve the same.

The reset through console takes more time, the below WLST script helps to reset the password quickly

WLST Script


ResetAllDataSourcePassword.py

adminIP = raw_input("Enter domain1.AdminIP:")
adminPort = raw_input("Enter domain1.AdminPort:")
adminPassword = raw_input("Enter adminPassword:")
DBPASSWORD= raw_input("Enter new DBPASSWORD:")
DOMAIN_PATH='C://Albin/SW/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain'
es = encrypt(DBPASSWORD,DOMAIN_PATH)
adminURL='t3://'+adminIP+':'+adminPort
adminUserName='weblogic'
connect(adminUserName, adminPassword, adminURL)
server='AdminServer'
cd('Servers/'+server)
target=cmo
edit()
startEdit()# SOADomain Datasource Configuration
cd('JDBCSystemResources')
allDS=cmo.getJDBCSystemResources()
for tmpDS in allDS:
    dsName=tmpDS.getName();
    print  'Changing the Password for DataSource ', dsName
    cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName)
    set('PasswordEncrypted',es)
save()
activate()
disconnect()


Script

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

Before executing the script, change the configurations as required.

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



Now the data sources password reset to new value.

Friday, February 3, 2012

WLST script to create JDBC Multi Data Source in weblogic server

Creating JDBC Multi Data Source through WLST in weblogic server

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

Refer the below URL for details on JDBC Multi data source.

https://www.albinsblog.com/2012/02/jdbc-multi-data-sources-in-weblogic.html

WLST Script


The below WLST script creates the JDBC Multi data source with enabled configurations

CreateMultiDataSource.py

adminURL='t3://localhost:7001'
adminUserName='weblogic'
adminPassword='weblogic1'
connect(adminUserName, adminPassword, adminURL)
edit()
startEdit()
jdbcSystemResource = create("MS1","JDBCSystemResource")
jdbcResource = jdbcSystemResource.getJDBCResource()
jdbcResource.setName("MS1")
dsParams = jdbcResource.getJDBCDataSourceParams()
jndiName='jdbc/MS1'
dsParams.setJNDINames([jndiName])
dsParams.setAlgorithmType('Failover')
dsParams.setDataSourceList('DS1,DS2')
dsParams.setFailoverRequestIfBusy(true)
jdbcSystemResource.addTarget(getMBean('Servers/AdminServer'))
print('MDS1 created successfully...')
save()
activate()
disconnect()



Script

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

Before executing the script, change the configurations as required.

The individual data sources(DS1 & DS2) should be created before executing the script




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

Now the JDBC Multi source is created with required configurations