简体   繁体   中英

Changing DataSource Password Using WLST (Multiple Domains)

I am very new to WLST scripting & currently at beginner level. I have a script which prompts for a password for each datasource it reads. While that part is working fine, the challenge i am facing is that, in production environment, where we want to run this script, there will be multiple managed servers having same datasource with different name but same JNDI as both datasources connecting to same database.

In that scenario the way script is working currently, it will prompt for password for every datasource it finds, but i wanted to modify the script so that it check the JNDIName for datasource & if password was already prompted for any datasource with same JNDI then it should use the same password rather than prompting for password again.

Also there are multi datasources, how can those be handled? Is it possible? besides i am not aware how to get the JNDIName for each datasource. I was trying to get JNDIName as following, which is not working - jndiName = dataSource.getJNDIName()

This is error i am getting on command line -

Problem invoking WLST - Traceback (innermost last):
  File "C:\Script\PostDeploy-DataSourcePasswords.py", line 59, in ?
  File "C:\Script\PostDeploy-DataSourcePasswords.py", line 43, in updateJDBCPasswords
AttributeError: getJNDIName

This is the script i am working with -

import sys

#import wlstutility
#wlstutility.initialise(globals())
#from wlstutility import *
#from wlstutility.constructors import *

if len(sys.argv)<1:
    print 'Usage: wlst.sh wibble.py <host:port>' 
    print '   for example: wlst.sh wibble.py prfadmin:14801' 
exit()

hostPort = sys.argv[1]    
print ('host:port = %s' % hostPort )

connectionUrl = ('t3://%s' % hostPort)

WL_USER='weblogic'
commitChanges=True

WL_PWD=raw_input("Enter Weblogic console password: ")

connect(WL_USER, WL_PWD, connectionUrl)

def updateJDBCPasswords():

    PARAMS_TEMPLATE = '/JDBCSystemResources/%s/JDBCResource/%s/JDBCDriverParams/%s'

    domainConfig()

    # Get JDBC DataSources
    cd("JDBCSystemResources")
    dataSources = cmo.getJDBCSystemResources()

    edit()
    # For each DataSource update the password
    for dataSource in dataSources :
        dsName = dataSource.getName()
        print ('DataSource Name : = %s' % dsName)
        password=raw_input("Enter database password for " + dsName +" : ")
        cd(PARAMS_TEMPLATE % (dsName, dsName, dsName) )
        cmo.setPassword(password)

## ===========================================================
# Let's get going

edit()
startEdit()

updateJDBCPasswords()

# dump the changes made so far
print "=== START: The changes that will be applied ==="
showChanges()

if commitChanges :
    # =========================================================
    # commit the changes
    save()
    activate(block="true")
else:
    # =========================================================
    # rollback the changes
    print "=== ROLLBACK - cancelling the changes so that they don't get applied ==="
    cancelEdit('y')

# =========================================================
# all done - bye!
disconnect()
exit()

Any Help will be much appreciated.

Thanks & Regards,

Amrut Raut.

You try at your test/pre-live environments with simple WLST script that could fetch the JNDI names. You can fetch the JNDI names from the ds below:

cd('/JDBCSystemResource/' + dsName + '/JdbcResource/' + dsName + '/JDBCDataSourceParams/NO_NAME_0')
jarray_jndi_names=get('JNDINames')
jndi_names=[]
for jname in jarray_jndi_names:
  jndi_names.append(jname)

Change dsName values with your input or whatever you feel better for your environment. Once you got the JNDI names you need to use plain if condition to check it already exist then you can use your logic.

keep Note that all multidata sources configured with generic datasources only. After trying with above hint share your experience.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM