Showing posts with label DATASOURCE. Show all posts
Showing posts with label DATASOURCE. 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 :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 : The multi data source HA Strategy

The multi data source has two strategy options for highly available connections for an Oracle RAC database. The strategy is defined by the Algorithm Type parameter.

Carry out the following steps to configure the high availability strategy for the multi data source:
  1. Access the Administration Console with your web browser at http://adminhost.domain.local:7001/console.
  2. Click on the Lock & Edit button to start a new edit session.
  3. Expand the Services tree on the left, and then click on Data Sources.
  4. Click on the ds-XA multi data source.
  5. Change Algorithm Type to Load Balance. Then click on the Save button.
  6. Finally, click on the Activate Changes button.

How it works...

With the Load Balance algorithm, the multi data source is responsible for load balancing the application requests to reserve a database connection in a round-robin fashion. If one Oracle RAC node goes down, the multi data source continues to return good connections transparently to the applications from the other RAC node.
The Failover algorithm returns a connection from the first data source of the member list. If the connection fails or all connections of the pool are in use, the other data source members will be used.

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 a multi data source

The multi data source should be used when connecting to an Oracle RAC database. The multi data source is a data source abstraction that groups all the individual data sources that connect to each node of the Oracle RAC database.
Consider that the DBApp application requires an XA connection with a JNDI name jdbc/ds-XA added to a database.
The database is an Oracle RAC database with two nodes. The first node has an instance name instance-rac01 and runs in the dbhost-rac01 hostname and listens to the port 1521. The listener accepts requests to the service name dbservice-rac01. The second node is the instance instance-rac02, and it runs in the dbhost-rac02 hostname, listens to the port 1521, and has a service name dbservice-rac02.


Before creating the multi data source, the individual data sources pointing to each RAC node must be created. Two data sources will be created with the names ds-XA-rac01 and ds-XA-rac02 and with the JNDI names jdbc/ds-XA-rac01 and jdbc/ds-XA-rac02.
The multi data source will be named ds-XA and includes both data sources.


Carry out the following steps to create a multi data source:
  1. Access the Administration Console with your web browser at http://adminhost.domain.local:7001/console.
  2. Click on the Lock & Edit button to start a new edit session.
  3. Click on the plus sign to open the Services tree on the left, and then click on Data Sources.
  4. Click on the New button and then click on Generic Data Source.
  5. Type ds-XA-rac01 in the Name field and jdbc/ds-XA-rac01 in the JNDI Name field. Leave the Database Type drop-down menu with the Oracle option selected. Click on the Next button.
  6. Choose *Oracle's Driver (Thin XA) for RAC Service-Instance connections; Versions:10 and later from the Database Driver drop-down menu. Click on the Next button.
  7. Then, click on the Next button in the Transaction Options page.
  8. On the Connection Properties page, type dbservice-rac01 in the Service Name field, instance-rac01 in the Database Name field, dbhost-rac01 in the Host Name field, and 1521 in the Port field. Complete the Database User Name, Password, and Confirm Password fields by typing dbuser, and dbpwd as the username and password respectively. Click on the Next button.
  9. Click on the Next button in the Test Database Connection page.
  10. Select the All servers in the cluster radio button from the PROD_Cluster cluster. Click on the Finish button.
  11. Repeat the previous steps and create another data source. Add ds-XA-rac02 as Name, jdbc/ds-XA-rac02 as JNDI Name, dbservice-rac02 as Service Name, instance-rac02 as Database Name, and dbhost-rac02 in the Host Name field.
    How to do it...
  12. Create the multi data source by clicking on the New button then on the Multi Data Source link.
  13. Type ds-XA in the Name field and jdbc/ds-XA in the JNDI Name field. Leave the other options as their default values. Click on the Next button.
  14. Select the All servers in the cluster radio button from the PROD_Cluster cluster. Click on the Next button.
  15. Select the XA Driver option. Click on Next.
  16. Select both data sources ds-XA-rac01 and ds-XA-rac02 from the left of the Add Data Source page. Click on the >> button in the center of both sides to move them to the right. Click on Finish.
    How to do it...
  17. Finally, click on the Activate Changes button.
The multi data source ds-XA was created with the data sources ds-XA-rac01 and ds-XA-rac02 as members.
The multi data source manages the application requests for a database connection and uses Algorithm Type to define the strategy for high availability.
If using the Failover algorithm, be sure to enable the Failover Request if Busy checkbox of the multi data source.

The multi data source is responsible for managing the load and failover; so if the Oracle database uses the SCAN address feature, it's recommended to set up a GridLink data source instead.

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 Server: Creating a JDBC data source

The data source will be named ds-nonXA using the required JNDI jdbc/ds-nonXA. The target will be the cluster PROD_Cluster, the same target as that of the DBApp application. The database username is dbuser and the password is dbpwd.

Carry out the following steps to create a JDBC data source:
  1. Access the Administration Console with your web browser at http://adminhost.domain.local:7001/console.
  2. Click on the Lock & Edit button to start a new edit session.
  3. Click on the plus sign to open the Services tree on the left, and then click on Data Sources.
  4. Click on the New button and then click on Generic Data Source.
  5. Type ds-nonXA in the Name field and jdbc/ds-nonXA in the JNDI Name field.
  6. Select the Oracle option from the Database Type drop-down menu. Click on the Next button.
  7. Choose *Oracle's Driver (Thin) for Service connections; Versions:9.0.1 and later from the Database Driver drop-down menu. Click on the Next button.
  8. Leave the default values for the Transaction options and click on the Next button.
  9. On the Connection Properties page, type dbservice in the Database Name field, dbhost in the Host Name field, and 1521 in the Port field. Complete the Database User Name, Password, and Confirm Password fields by typing dbuser and dbpwd as the username and password respectively. Click on the Next button.
  10. Click on the Next button on the Test Database Connection page.
  11. Select the All servers in the cluster radio button from the PROD_Cluster cluster. Click on the Finish button.
  12. Then, click on the Activate Changes button.
A new non-XA JDBC data source was created with the parameters required by the DBApp application. The non-XA Oracle JDBC driver is the thin version. All other parameters were left as their default values.
How it works...
The Oracle driver class name used for non-XA data sources is oracle.jdbc.OracleDriver.