使用wsadmin为Web Provider创建DataSource(Websphere Application Server 8.5)

时间:2015-02-18 08:46:21

标签: db2 websphere datasource jython wsadmin

我有一个脚本,它使用Websphere Application Server 8.5中的DB2 JDBC Provider创建数据源。所以我在运行脚本时遇到错误,我需要一些帮助。

我的剧本:

def createDB2(list):
    print 'Creating DB2 Data Source...'
    for dataSource in list:
        datasourceName=dataSource[0]
        dsJNDIName=dataSource[1]
        compAuthAlias=dataSource[2]
        providerName=dataSource[3]
        dataStoreHelperClassName=dataSource[4]
        description=dataSource[5]
        serverName=dataSource[6]
        databaseMaxConnections=dataSource[7]
        databaseMinConnections=dataSource[8]
        databaseconnTimeout=dataSource[9]
        databasereapTime=dataSource[10]
        databaseunusedTimeout=dataSource[11]
        databaseagedTimeout=dataSource[12]

    #Creare sursa de date
    dataSourceId = AdminJDBC.createDataSourceAtScope( scope, providerName, datasourceName, dsJNDIName, dataStoreHelperClassName, serverName, [['componentManagedAuthenticationAlias',compAuthAlias],['containerManagedPersistence','true'],['description',description]] )

    connectionPoolList = AdminConfig.list('ConnectionPool', dataSourceId)
    connectionPoolList = AdminUtilities.convertToList(connectionPoolList)
    connectionPoolId = connectionPoolList[0]
    AdminConfig.modify(connectionPoolId, [["maxConnections", databaseMaxConnections], ["minConnections", databaseMinConnections], ["connectionTimeout", databaseconnTimeout], ["reapTime", databasereapTime], ["unusedTimeout", databaseunusedTimeout], ["agedTimeout", databaseagedTimeout]])

    print 'Saving configuration...'
    AdminConfig.save()
    print "Configuration saved."

我的输入列表:

[datasourceName, JNDIName, AuthAlias, providerName, dataStoreHelperClassName, description, srvName,  maxConnections, minConnections, connTimeout, reapTime, unusedTimeout, agedTimeout]

我使用相同的脚本创建没有错误的Oracle数据源。我所知道的theese进程之间的区别是serverName。对于DB2是ServerName,对于Oracle是URL。还有另一个我不知道的区别吗?有没有人在我的代码中看到错误或错误?

我的错误:

Exception: com.ibm.ws.scripting.ScriptingException com.ibm.ws.scripting.ScriptingException: com.ibm.ws.scripting.ScriptingException: WASX8018E: Cannot find a match for option value [databaseName, java.lang.String, TestSRV] for step configureResourceProperties 
WASX7017E: Exception received while running file "createDataSource.py"; exception information: com.ibm.ws.scripting.ScriptingException: WASX8018E: Cannot find a match for option value [databaseName, java.lang.String, TestSRV] for step configureResourceProperties

如果您需要更多信息,请发表评论。提前谢谢!

编辑03.03.2015

我在IBM的RedBook中找到了一些例子。

DB2数据库类型的示例脚本:

以下示例脚本包含字符串格式的可选属性:

AdminJDBC.createDataSourceAtScope("Cell=IBM-F4A849C57A0Cell01,Node=IBM-F4A849C57A0Node01,Server=server1", "MyTestJDBCProviderName", "newds2", "newds2/jndi", "com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper", "db1", " category=myCategory, componentManagedAuthenticationAlias=CellManager01/AuthDataAliase, containerManagedPersistence=true, description=’My description’, xaRecoveryAuthAlias=CellManager01/xaAliase", "serverName=localhost, driverType=4,portNumber=50000")

以下示例脚本包含列表格式的可选属性:

AdminJDBC.createDataSourceAtScope("Cell=IBM-F4A849C57A0Cell01,Node=IBM-F4A849C57A0Node01,Server=server1", "MyTestJDBCProviderName", "newds2", "newds2/jndi", "com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper", "db1", [[’category’, ’myCategory’], [’componentManagedAuthenticationAlias’, ’CellManager01/AuthDataAliase’], [’containerManagedPersistence’, ’true’], [’description’, ’My description’], [’xaRecoveryAuthAlias’, ’CellManager01/xaAliase’]] , [[’serverName’, ’localhost’], [’driverType’, 4], [’portNumber’, 50000]])

编辑16.04.2015

我正在使用内置函数 createDataSourceAtScope ,我有另一个例子:

def createDataSourceAtScope( scope, JDBCName, datasourceName, jndiName, dataStoreHelperClassName, dbName, otherAttrsList=[], resourceAttrsList=[],  failonerror=AdminUtilities._BLANK_ ):

我必须调用上面的函数。有没有人看到这个问题? :)

内置脚本位于:dmgrProfile/scriptLibraries/resources/JDBC/V70

我仍然不知道如何解决我的问题。如果有人有想法,请发表评论或回答。非常感谢你!

1 个答案:

答案 0 :(得分:0)

我知道为时已晚,但我在 Docker 上为 Websphere 遇到了同样的问题。然后,我想分享我的解决方案。

用于调试 ibmcom/websphere-traditional:8.5.5.18 上的脚本的命令

/opt/IBM/WebSphere/AppServer/bin/wsadmin.sh -conntype None -f exportConfig.py

Jython 脚本


import os
import sys

newjdbc = AdminConfig.getid('/JDBCProvider:"DB2 Universal JDBC Driver Provider"/')

ds = AdminTask.createDatasource(newjdbc, '[-name NameDataSource -jndiName jdbc/NameDataSource -description "DB2 Universal Driver Datasource" -dataStoreHelperClassName com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper -containerManagedPersistence true -componentManagedAuthenticationAlias db2inst1 -configureResourceProperties [[databaseName java.lang.String SAMPLE][portNumber java.lang.Integer 50000][serverName java.lang.String 172.17.0.3]]]')
AdminConfig.create('MappingModule', ds, '[[authDataAlias db2inst1] [mappingConfigAlias "DefaultPrincipalMapping"]]')


AdminConfig.save()