Target cannot be assigned issue when using WLST Creating Datasource offline

 There are 2 ways to create datasource offline. The reason to create datasource offline, basically because we want to create those datasource durning create new domain. So that we don’t need to boot up domain before create datasource in online mode.

We offen can google the result to create datasource via WLST offline like following.

 

print 'create wlsbjmsrpDataSource'
create('wlsbjmsrpDataSource', 'JDBCSystemResource')
cd('/JDBCSystemResource/wlsbjmsrpDataSource')
set('Target','AdminServer,osb_server1')
 
cd('/JDBCSystemResource/wlsbjmsrpDataSource/JdbcResource/wlsbjmsrpDataSource')
cmo.setName('wlsbjmsrpDataSource')
 
print 'create JDBCDataSourceParams'
cd('/JDBCSystemResource/wlsbjmsrpDataSource/JdbcResource/wlsbjmsrpDataSource')
create('myJdbcDataSourceParams','JDBCDataSourceParams')
cd('JDBCDataSourceParams/NO_NAME_0')
set('JNDIName', java.lang.String('wlsbjmsrpDataSource'))
set('GlobalTransactionsProtocol', java.lang.String('None'))
 
print 'create JDBCDriverParams'
cd('/JDBCSystemResource/wlsbjmsrpDataSource/JdbcResource/wlsbjmsrpDataSource')
create('myJdbcDriverParams','JDBCDriverParams')
cd('JDBCDriverParams/NO_NAME_0')
set('DriverName','oracle.jdbc.OracleDriver')
set('URL','jdbc:oracle:thin:@wintermute:1521:mysid')
set('PasswordEncrypted', 'manager')
set('UseXADataSourceInterface', 'false')
 
print 'create JDBCDriverParams Properties'
create('myProperties','Properties')
cd('Properties/NO_NAME_0')
create('user','Property')
cd('Property')
cd('user')
set('Value', 'scott')
 
print 'create JDBCConnectionPoolParams'
cd('/JDBCSystemResource/wlsbjmsrpDataSource/JdbcResource/wlsbjmsrpDataSource')
create('myJdbcConnectionPoolParams','JDBCConnectionPoolParams')
cd('JDBCConnectionPoolParams/NO_NAME_0')
set('TestTableName','SQL SELECT 1 FROM DUAL')

 

The refference: 

http://theheat.dk/blog/?p=565

But above code sample missing very important part, which would cause problems if you directly copy to use.

Check here:

 

cd('/JDBCSystemResource/wlsbjmsrpDataSource')
set('Target','AdminServer,osb_server1')

 

We know that each of datasource in weblogic require to assign a target, so that the datasource would be working.

But above code would be not working if you want to create datasource directly during using "readTemplate" to load default template to create your domain.

For example:

When you using the codes in first block to create datasource in WLST offline mode. You would write something like this:

 

readTemplate(templateDir)
 
#codes from first block create datasouce...
 
writeDomain(domainDir)
exit()

 

But if you using above code to create the datasource. The target cannot be assigned. Not sure the reason. To make it working you need to change as follows:

 

readTemplate(templateDir)
 
#Codes from block1 to create datasource offline
 
writeDomain(domainDir)  # This is very important, you need to create domain first
 
closeTemplate()
 
readDomain(domainDir)
 
cd('/JDBCSystemResource/'+dsName)
set('Targets',target)   #Notice, here set is "Targets" not "Target"

 

The basic idea to make it working is to create the datasource on the fly, but set the target after domain generated on the disk.

Of course, you can also create datasource after domain generated. 

But if you still insist on creating everything in one shot.

Try use another WLST function assign.

Refference:

http://docs.oracle.com/cd/E13222_01/wls/docs92/config_scripting/domains.html#wp1013450

 

readTemplate(templateDir)
 
# create datasource
 
cd('/')
assign('JDBCSystemResource', dsName, 'Target', target)
 
writeDomain(domainDir)
closeDomain()

 

Please note, the propertie we set here is "Target" not "Targets".

This artical just for a note for my refference in the future.