简体   繁体   English

使用WLST(多个域)更改数据源密码

[英]Changing DataSource Password Using WLST (Multiple Domains)

I am very new to WLST scripting & currently at beginner level. 我对WLST脚本非常陌生,目前还处于初学者水平。 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. 尽管这部分工作正常,但我面临的挑战是,在生产环境中,我们要运行此脚本,将有多个托管服务器具有相同的数据源,但名称不同,但JNDI相同,因为两个数据源都连接到相同的数据库。

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. 在那种情况下,脚本当前的工作方式,它将提示输入找到的每个数据源的密码,但是我想修改脚本,以便它检查JNDIName的数据源,如果已经使用相同的JNDI的任何数据源提示了密码,那么它将应该使用相同的密码,而不是再次提示输入密码。

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. 此外,我不知道如何获取每个数据源的JNDIName。 I was trying to get JNDIName as following, which is not working - jndiName = dataSource.getJNDIName() 我试图按以下方式获取JNDIName,但无法正常工作-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. 阿姆鲁特·劳特(Amrut Raut)。

You try at your test/pre-live environments with simple WLST script that could fetch the JNDI names. 您可以使用简单的WLST脚本在测试/预发布环境中进行尝试,该脚本可以获取JNDI名称。 You can fetch the JNDI names from the ds below: 您可以从下面的ds中获取JNDI名称:

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. 使用您的输入或对环境感觉更好的更改dsName值。 Once you got the JNDI names you need to use plain if condition to check it already exist then you can use your logic. 一旦获得了JNDI名称,就需要使用普通的if条件来检查它是否已经存在,那么就可以使用逻辑了。

keep Note that all multidata sources configured with generic datasources only. 请注意,所有多数据源仅配置有通用数据源。 After trying with above hint share your experience. 尝试以上提示后,分享您的经验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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