Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2452
  • Last Modified:

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.
http://www.experts-exchange.com/Software/Server_Software/Application_Servers/Java/IBM_Websphere/Q_26219904.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

0
k_satish22
Asked:
k_satish22
  • 13
  • 13
1 Solution
 
HonorGodCommented:
I haven't missed, or forgotten you. ;-)

I'm working through this...
0
 
k_satish22Author Commented:
Hello HonorGod,

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

0
 
HonorGodCommented:
I have the first part (about 25-33%) done, and am continuing to work on the remainder.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
k_satish22Author Commented:
Thank you.
0
 
HonorGodCommented:
Something like this perhaps?
createJDBC.py
createJDBC.prop.txt
0
 
k_satish22Author Commented:
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.
0
 
HonorGodCommented:
Is that what you wanted?

This script, as compared to the one referenced in the original question (i.e., http://e-e.com/Q_26219904.html), uses the AdminTask scripting object, instead of the AdminConfig object.  This changes the way the configuration objects are defined.
0
 
k_satish22Author Commented:
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       =


0
 
HonorGodCommented:
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.
0
 
HonorGodCommented:
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
0
 
k_satish22Author Commented:
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.
0
 
HonorGodCommented:
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.
0
 
k_satish22Author Commented:
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
--------------------------------------------------------------------------------
0
 
HonorGodCommented:
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
0
 
k_satish22Author Commented:
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]]]')
0
 
HonorGodCommented:
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

0
 
k_satish22Author Commented:
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

0
 
HonorGodCommented:
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

0
 
k_satish22Author Commented:
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
0
 
k_satish22Author Commented:
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.
0
 
k_satish22Author Commented:
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
0
 
HonorGodCommented:
So you're all set?
0
 
k_satish22Author Commented:
Can you please add one more module for JAAS to the script.

#-------------------------------------------------
# For JAASAuthData:
#-------------------------------------------------
aliasName      = newAlias
username       = myUserName
password       = password
0
 
HonorGodCommented:
Like this?
createJDBC.py
0
 
k_satish22Author Commented:
Thank you so much for your help.
0
 
HonorGodCommented:
Thank you for the grade & points.

Goodluck & have a great day.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 13
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now