Reputation: 2025
We are using Jython to configure a data source in WAS. The data source created OK, with some default custom properties. Now I need to add another property, without deleting the other propertues. Any ideas?
Upvotes: 1
Views: 2107
Reputation: 13
More often you need to modify an existing property as many of the defaults might be already created. So, I would suggest the following approach:
def modifyJ2eeProperty(ds,name,value):
propset = AdminConfig.list('J2EEResourcePropertySet', ds)
for i in AdminConfig.list('J2EEResourceProperty', propset).splitlines():
if (name == AdminConfig.showAttribute(i, 'name')):
print AdminConfig.showAttribute(ds, 'name') + ': ' + name + ' = ' + str(AdminConfig.showAttribute(i, 'value'))
AdminConfig.modify(i, [['value', value]])
print 'modified to: ' + name + ' = ' + str(value)
def setJ2eeProperty(ds,name,value):
propset = AdminConfig.showAttribute(ds, 'propertySet')
if name not in AdminConfig.list('J2EEResourceProperty', propset):
print "creating new property"
AdminConfig.create('J2EEResourceProperty', propset, [['name', name], ['type', "java.lang.Integer"], ['description', ""], ['value', value], ['required', "false"]])
print AdminConfig.list('J2EEResourcePropertySet', ds)
else:
modifyJ2eeProperty(ds,name,value)
#just use as you wish, for instance:
for provider in AdminConfig.list('JDBCProvider', 'DB2*').splitlines():
for ds in AdminConfig.list('DataSource',provider).splitlines():
setJ2eeProperty(ds,'securityMechanism',3)
Notice the list: [['name', name], ['type', "java.lang.Integer"], ['description', ""], ['value', value], ['required', "false"]]
There are more types than Integer. This is just my example, you can tune however you need.
The required parameter is "name" as you can see in the docs or print AdminConfig.required('J2EEResourceProperty')
output.
Upvotes: 1
Reputation: 96
You can follow the instructions on the Knowledge Center link below to create a new data source custom property using Jython:
The link provides the following steps:
Identify the parent ID:
newds = AdminConfig.getid('/Cell:mycell/Node:mynode/JDBCProvider:JDBC1/DataSource:DS1/')
print newds
Example output:
DS1(cells/mycell/nodes/mynode|resources.xml$DataSource_1)
Get the J2EE resource property set:
propSet = AdminConfig.showAttribute(newds, 'propertySet')
print propSet
Example output:
(cells/mycell/nodes/mynode|resources.xml#J2EEResourcePropertySet_8)
Get required attribute:
print AdminConfig.required('J2EEResourceProperty')
Example output:
Attribute Type name String
Set up attributes:
name = ['name', 'RP4']
rpAttrs = [name]
Create a J2EE resource property:
print AdminConfig.create('J2EEResourceProperty', propSet, rpAttrs)
Example output:
RP4(cells/mycell/nodes/mynode|resources.xml#J2EEResourceProperty_8)
Save the configuration changes.
In a network deployment environment only, synchronize the node.
Upvotes: 1