Link to home
Start Free TrialLog in
Avatar of k_satish22
k_satish22

asked on

Jython Script for JDBC

Hello HonorGod,
As per our discussion in other Question I have opend a new question.
I need a Jython script to create to create different JDBCProvides and DataSources. I have seen that you have worked on similar kind of script in below the link. I need only JDBCProvides and DataSources part of that script. JDBC Provider should be created at specifed scope.
https://www.experts-exchange.com/questions/26219904/Need-help-in-jython-script-creation-of-cluster-datasource-creation-virtualhost.html
Properties file is provided below.
I really appreciate all you help.

#-------------------------------------------------
# For Environment verification
#-------------------------------------------------
cellName       = 
NodeName       =
Cluster        = 
#-------------------------------------------------
# For JAASAuthData:
#-------------------------------------------------
aliasName      = newAlias
username       = myUserName
password       = password


#-------------------------------------------------
# For DataBase types
#-------------------------------------------------
db2            = true
SQLserver      = false
oracle         = false

#-------------------------------------------------
# For DB2 JDBCProvider:
#-------------------------------------------------
Scope		   =	
db2.classpath      = 
db2.implClassName  = 
db2.JDBCname       = my DB2 JDBC Provider
db2.nodeName       = myNode01
db2.serverName     = server1

#-------------------------------------------------
# For DB2 DataSource
#-------------------------------------------------
db2.DataSourceName = myDSN
db2.JNDIname       = 

#-------------------------------------------------
# For SQL Server JDBCProvider:
#-------------------------------------------------
Scope                    =
SQLserver.classpath      = 
SQLserver.implClassName  = 
SQLserver.JDBCname       = my SQL Server JDBC Provider
SQLserver.nodeName       = myNode01
SQLserver.serverName     = server1

#-------------------------------------------------
# For SQL Server DataSource
#-------------------------------------------------
SQLserver.DataSourceName = myDSN
SQLserver.JNDIname       = 

#-------------------------------------------------
# For Oracle JDBCProvider:
#-------------------------------------------------
Scope                 =
oracle.classpath      = 
oracle.implClassName  = 
oracle.JDBCname       = my SQL Server JDBC Provider
oracle.nodeName       = myNode01
oracle.serverName     = server1

#-------------------------------------------------
# For Oracle Server DataSource
#-------------------------------------------------
oracle.DataSourceName = myDSN
oracle.JNDIname       =

Open in new window

Avatar of HonorGod
HonorGod
Flag of United States of America image

I haven't missed, or forgotten you. ;-)

I'm working through this...
Avatar of k_satish22
k_satish22

ASKER

Hello HonorGod,

Once again thank you very much for all you help. Do you have any update on this script please.

I have the first part (about 25-33%) done, and am continuing to work on the remainder.
Thank you.
Something like this perhaps?
createJDBC.py
createJDBC.prop.txt
Hello HonorGod,
The script is working as expected for DB2.

DB2 JDBC Provider and Datasource created as per infromation Properties file.

WASX7209I: Connected to process "dmgr" on node dmgr1ProcNode01 using SOAP connector;  The type of process is: DeploymentManager
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[createJDBC.prop.txt]"
JDBC Provider created successfully
Datasource created successfully
Saving configuration changes.

Thank you.
Is that what you wanted?

This script, as compared to the one referenced in the original question (i.e., https://www.experts-exchange.com/questions/26219904/Need-help-in-jython-script-creation-of-cluster-datasource-creation-virtualhost.html), uses the AdminTask scripting object, instead of the AdminConfig object.  This changes the way the configuration objects are defined.
I want even Oracle JDBCProvider and Datasource and JAASAuthData too...

#-------------------------------------------------
# For DataBase types
#-------------------------------------------------
db2            = true
SQLserver      = false
oracle         = false




#-------------------------------------------------
# For JAASAuthData:
#-------------------------------------------------
aliasName      = newAlias
username       = myUserName
password       = password


 For SQL Server JDBCProvider:
#-------------------------------------------------
Scope                    =
SQLserver.classpath      =
SQLserver.implClassName  =
SQLserver.JDBCname       = my SQL Server JDBC Provider
SQLserver.nodeName       = myNode01
SQLserver.serverName     = server1

#-------------------------------------------------
# For SQL Server DataSource
#-------------------------------------------------
SQLserver.DataSourceName = myDSN
SQLserver.JNDIname       =


Can't you use the original script, to do that?

The one that I provided should allow you to specify the parameters, as long as you know what to enter.

I'm going to have to configure one using the AdminConsole to see what is used in the individual steps.
Revised to add support for Oracle "URL" resource properties use entries like the following [which worked for me]
For an Oracle Database, have the properties file use something like:

...
dbType               = Oracle
providerType         = Oracle JDBC Driver
implementationType   = XA data source

#-------------------------------------------------
# DB/2 Resource Properties
#-------------------------------------------------
dbName               =
driverType           =
dbServerName         =
portNumber           =

#-------------------------------------------------
# Oracle Resource Properties
#-------------------------------------------------
URL                  = jdbc:oracle:thin:@<hostname OR IP>:<port#>:XE

Open in new window

createJDBC.py
Script failed with below error
WASX7209I: Connected to process "dmgr" on node dmgr1ProcNode01 using SOAP connector;  The type of process is: DeploymentManager
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[Oracle_prop]"
JDBC Provider created successfully
Error: createDSN() failed: com.ibm.ws.scripting.ScriptingException: com.ibm.ws.scripting.ScriptingException: WASX8015E: Invalid option value for step configureResourceProperties: [ [ URL java.lang.String  jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN ] )
Saving configuration changes.
hm.  Don't you just love those "exceedingly helpful" messages?

Wow, how much more helpful could you be?  "Invalid option value"...

That tells me exactly what is wrong.... NOT.

I'm going to need your help on this one.

What version is being used?

Execute the versionInfo command from the AppServer/bin directory.  And let me know what is in the "Installed product" section.
The URL which I have specified "jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN " is correct. When I am creating the datasource from Admin console It is getting created with the same URL.
Command generated by Command Assistance in Admin console.

AdminTask.createDatasource('"Oracle JDBC Driver (XA)(cells/APPCell01|resources.xml#JDBCProvider_1305816056861)"', '[-name Sample -jndiName jndi/sample -dataStoreHelperClassName com.ibm.websphere.rsadapter.Oracle10gDataStoreHelper -containerManagedPersistence true -componentManagedAuthenticationAlias -xaRecoveryAuthAlias -configureResourceProperties [[URL java.lang.String jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN]]]')

But I am not sure why I am getting that error

Installed Product
--------------------------------------------------------------------------------
Name                     IBM WebSphere Application Server - ND
Version                  7.0.0.13
ID                       ND
Build Level              cf131039.07
Build Date               10/2/10
Architecture             PPC32

Installed Product
--------------------------------------------------------------------------------
Excellent.

On the Admin Console, under System Administration, select Console preferences
Add checks to the boxes labelled:
- Enable command assistance notifications
- Log command assistance commands  
- Click the "Apply" button

Now, when you do something on the Admin Console, you should "often" (not always) see a link on the right "View administrative scripting command for last action"

- Configure (but don't save) an Oracle DSN,

copy / paste the Jython commands used to create it.

Thanks
Here is command from Command Assistance in Admin console

AdminTask.createDatasource('"Oracle JDBC Driver (XA)(cells/APPCell01|resources.xml#JDBCProvider_1305816056861)"', '[-name Sample -jndiName jndi/sample -dataStoreHelperClassName com.ibm.websphere.rsadapter.Oracle10gDataStoreHelper -containerManagedPersistence true -componentManagedAuthenticationAlias -xaRecoveryAuthAlias -configureResourceProperties [[URL java.lang.String jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN]]]')
ok, so you should be able to populate the properties file using this information, for example, maybe something like:

dbType               = Oracle
providerType         = Oracle JDBC Driver
implementationType   = XA data source

#-------------------------------------------------
# DataSource
#-------------------------------------------------
dataSourceName       = Sample
JNDIname             = jndi/sample
helperClassName      = com.ibm.websphere.rsadapter.Oracle10gDataStoreHelper
DSNdescript          =
category             =
CompManAuthAlias     = 
ContManPersist       = true
xaRecoveryAuthAlias  =

#-------------------------------------------------
# DB/2 Resource Properties
#-------------------------------------------------
dbName               =
driverType           = 
dbServerName         =
portNumber           =

#-------------------------------------------------
# Oracle Resource Properties
#-------------------------------------------------
URL                  = jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN

Open in new window

Sorry I forgot to mention earlier. I have used similar kind of properties as you suggested. But I am still getting the same error.
#-------------------------------------------------
# For Environment identification / verification
#-------------------------------------------------
cellName    = ProcCell01
nodeName    =
clusterName =
serverName  =
appName     =
scope       = Cell
#scope       = Cell | Node | Cluster | Server | Application

dbType               = Oracle
providerType         = Oracle JDBC Driver
implementationType   = XA data source

#-------------------------------------------------
# DataSource
#-------------------------------------------------
dataSourceName       = Sample
JNDIname             = jndi/sample
helperClassName      = com.ibm.websphere.rsadapter.Oracle10gDataStoreHelper
DSNdescript          =
category             =
CompManAuthAlias     =
ContManPersist       = true
xaRecoveryAuthAlias  =

#-------------------------------------------------
# DB/2 Resource Properties
#-------------------------------------------------
dbName               =
driverType           =
dbServerName         =
portNumber           =

#-------------------------------------------------
# Oracle Resource Properties
#-------------------------------------------------
URL                  = jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN

Open in new window

In the script, there should be two lines containing:

Change the "#" on the first line to a space.  Don't just delete it, replace it with a space.

This will cause the script to display exactly what is being passed to the createDataSource() method.

Thanks
Before:

#   print 'AdminTask.createDatasource( %s )' % `attr`
    result = AdminTask.createDatasource( Provider, attr )

After:

    print 'AdminTask.createDatasource( %s )' % `attr`
    result = AdminTask.createDatasource( Provider, attr )

Open in new window

I got below error...

WASX7017E: Exception received while running file "createJDBC.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  (no code object) at line 0
  File "<string>", line 183
            print AdminTask.createDatasource( %s )' % `attr`
                                              ^
SyntaxError: invalid syntax
I am sorry my bad. Please ignore my earlier comment.

Here is the the output....

WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[Oracle_prop_2]"
JDBC Provider created successfully
AdminTask.createDatasource( ['-name', 'Sample', '-jndiName', 'jndi/sample', '-dataStoreHelperClassName', 'com.ibm.websphere.rsadapter.Oracle10gDataStoreHelper', '-containerManagedPersistence', 'true', '-configureResourceProperties', '[ [ URL java.lang.String  jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN  ] )'] )
Error: createDSN() failed: com.ibm.ws.scripting.ScriptingException: com.ibm.ws.scripting.ScriptingException: WASX8015E: Invalid option value for step configureResourceProperties: [ [ URL java.lang.String  jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN  ] )
Saving configuration changes.
I found the error....

 [ [ URL java.lang.String  jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN  ] )
insted off
[ [ URL java.lang.String  jdbc:oracle:thin:@pitentracvip01.e05.acsenterprise.com:1521:ENV05_MMIS_OLN  ] ]

after correcting it. the script is working fine..

URL
So you're all set?
Can you please add one more module for JAAS to the script.

#-------------------------------------------------
# For JAASAuthData:
#-------------------------------------------------
aliasName      = newAlias
username       = myUserName
password       = password
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much for your help.
Thank you for the grade & points.

Goodluck & have a great day.