Monday, November 3, 2014

Creating JMS Resources iteratively using Maven and WLST script in 12c

In the previous post we have seen how to create a JMSSserver and JMSModule using WLST.

To extent this script further, with multiple sets of JMSServer and JMSModules we can follow the below approach


Create jms.properties file for each set of configuration.

Please note use the convention as jms1, jms2,jms3 for the properties files

===========jms1.properties=================
domain.name=DefaultDomain
admin.url=t3://localhost:7101
admin.userName=weblogic
admin.password=weblogic1

jms.jmsserver=TEST_JMSSerer1
jms.jmssystemresource=TEST_JMSSystemResource1
jms.subdeployment=TEST_JMSSubdeployment1
jms.queue=TEST_JMSQUEUE1
jms.queue.jndi=jms/TEST_JMSQUEUE1
jms.topic=TEST_JMSTOPIC1
jms.topic.jndi=jms/TEST_JMSTOPIC1
jms.targetserver=DefaultServer

============end of properties================



===========jms2.properties=================

domain.name=DefaultDomain
admin.url=t3://localhost:7101
admin.userName=weblogic
admin.password=weblogic1

jms.jmsserver=TEST_JMSSerer2
jms.jmssystemresource=TEST_JMSSystemResource2
jms.subdeployment=TEST_JMSSubdeployment2
jms.queue=TEST_JMSQUEUE2
jms.queue.jndi=jms/TEST_JMSQUEUE2
jms.topic=TEST_JMSTOPIC2
jms.topic.jndi=jms/TEST_JMSTOPIC2
jms.targetserver=DefaultServer




============end of properties================

Save the following python script as jmsobjects.py

================start of python script============

 from java.io import FileInputStream

for i in 1,2:

  
    propInputStream = FileInputStream("path\\to\\jms"+str(i)+".properties")
    configProps = Properties()
    configProps.load(propInputStream)

    domainName=configProps.get("domain.name")
  
    adminURL=configProps.get("admin.url")
    adminUserName=configProps.get("admin.userName")
    adminPassword=configProps.get("admin.password")

    jms_server=configProps.get("jms.jmsserver")
    print 'jms_server : '+jms_server
    jms_systemResource=configProps.get("jms.jmssystemresource")
    print 'jms_systemResource : '+jms_systemResource
    jms_queue=configProps.get("jms.queue")
    print 'jms_queue : '+jms_queue
    jms_queue_jndi=configProps.get("jms.queue.jndi")
    print 'jms_queue_jndi : '+jms_queue_jndi
    jms_subdeployment=configProps.get("jms.subdeployment")
    print 'jms_subdeployment : '+jms_subdeployment
    jms_topic=configProps.get("jms.topic")
    print 'jms_topic : '+jms_topic
    jms_topic_jndi=configProps.get("jms.topic.jndi")
    print 'jms_topic_jndi :'+jms_topic_jndi
    jms_targetserver=configProps.get("jms.targetserver")
    print 'jms_targetserver : '+jms_targetserver


    #connect('weblogic','weblogic1', 't3://localhost:7101')
    connect(adminUserName, adminPassword, adminURL)

    # Creating a JMS Server

    edit()
    startEdit()
    cd('/')
    print 'Creating JMS Server.'
    cmo.createJMSServer(jms_server)
    cd('/JMSServers/'+jms_server)
    cmo.addTarget(getMBean('/Servers/'+jms_targetserver))
    activate()

    # Creating a Module

    startEdit()
    cd('/')
    cmo.createJMSSystemResource(jms_systemResource)
    cd('/JMSSystemResources/'+jms_systemResource)
    cmo.addTarget(getMBean('/Servers/'+jms_targetserver))
    cmo.createSubDeployment(jms_subdeployment)
    activate()

    # Creating Queue

    startEdit()
    print 'Creating Queue & Topic '
    cd('/')
    cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource)
    cmo.createQueue(jms_queue)
    cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource+'/Queues/'+jms_queue)
    set('JNDIName',jms_queue_jndi)
    set('SubDeploymentName',jms_subdeployment)
    cd('/JMSSystemResources/'+jms_systemResource+'/SubDeployments/'+jms_subdeployment)
    cmo.addTarget(getMBean('/JMSServers/'+jms_server))
    activate()

    # Creating Topic

    startEdit()
    cd('/')
    cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource)
    cmo.createTopic(jms_topic)
    cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource+'/Topics/'+jms_topic)
    set('JNDIName',jms_topic_jndi)
    set('SubDeploymentName',jms_subdeployment)
    cd('/JMSSystemResources/'+jms_systemResource+'/SubDeployments/'+jms_subdeployment)
    set('Targets',jarray.array([ObjectName('com.bea:Name='+jms_server+',Type=JMSServer')],ObjectName))
 
    
activate()
   

=================end of python script===========

Now open command prompt
Execute the following command after correcting the path as per your soa installation
mvn wls:wlst -DfileName=path/to/jmsobjects.py  - DmiddlewareHome=path/to/oraclehome 
-DdomainHome=path/to/domainhome

Creating JMS Resources using Maven and WLST in 12c


As a first step we need to install maven plugin wls-maven-plugin.

This plugin present in the ORACLE_HOME/wlserver_12.1/server/lib

Open a command prompt and navigate to the above location

Now we need to install this plugin to our repository( here by default the repository will be the local repository which is present at  c:/users/<username>/.m2  (for windows)).

To install the plugin use the following command


mvn install:install-file -Dfile=wls-maven-plugin.jar -DpomFile=pom.xml

Once the installation is successful we can verify whether the required goals are available using the following command

mvn com.oracle.weblogic:wls-maven-plugin:help

Here we can see the wlst task is available. 

Now we are ready to execute the WLST script using maven

Create a jms.properties file as shown below(change the values as per your requirement)
==================
domain.name=DefaultDomain
admin.url=t3://localhost:7101
admin.userName=weblogic
admin.password=weblogic1

jms.jmsserver=TEST_JMSSerer
jms.jmssystemresource=TEST_JMSSystemResource
jms.subdeployment=TEST_JMSSubdeployment
jms.queue=TEST_JMSQUEUE
jms.queue.jndi=jms/TEST_JMSQUEUE
jms.topic=TEST_JMSTOPIC
jms.topic.jndi=jms/TEST_JMSTOPIC
jms.targetserver=DefaultServer
============================================

Save the following python script as jmsobjects.py

note : remember to give the exact path to the jms.properties file)

========start of python script ==========

from java.io import FileInputStream

propInputStream = FileInputStream("path\\to\\jms.properties")
configProps = Properties()
configProps.load(propInputStream)

domainName=configProps.get("domain.name")
adminURL=configProps.get("admin.url")
adminUserName=configProps.get("admin.userName")
adminPassword=configProps.get("admin.password")

jms_server=configProps.get("jms.jmsserver")
jms_systemResource=configProps.get("jms.jmssystemresource")
jms_queue=configProps.get("jms.queue")
jms_queue_jndi=configProps.get("jms.queue.jndi")
jms_subdeployment=configProps.get("jms.subdeployment")
jms_topic=configProps.get("jms.topic")
jms_topic_jndi=configProps.get("jms.topic.jndi")
jms_targetserver=configProps.get("jms.targetserver")


#connect('weblogic','weblogic1', 't3://localhost:7101')
connect(adminUserName, adminPassword, adminURL)

# Creating a JMS Server

edit()
startEdit()
cd('/')
print 'Creating JMS Server.'
cmo.createJMSServer(jms_server)
cd('/JMSServers/'+jms_server)
cmo.addTarget(getMBean('/Servers/'+jms_targetserver))
activate()

# Creating a Module

startEdit()
cd('/')
cmo.createJMSSystemResource(jms_systemResource)
cd('/JMSSystemResources/'+jms_systemResource)
cmo.addTarget(getMBean('/Servers/'+jms_targetserver))
cmo.createSubDeployment(jms_subdeployment)
activate()

# Creating Queue

startEdit()
print 'Creating Queue & Topic '
cd('/')
cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource)
cmo.createQueue(jms_queue)
cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource+'/Queues/'+jms_queue)
set('JNDIName',jms_queue_jndi)
set('SubDeploymentName',jms_subdeployment)
cd('/JMSSystemResources/'+jms_systemResource+'/SubDeployments/'+jms_subdeployment)
cmo.addTarget(getMBean('/JMSServers/'+jms_server))
activate()

# Creating Topic

startEdit()
cd('/')
cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource)
cmo.createTopic(jms_topic)
cd('/JMSSystemResources/'+jms_systemResource+'/JMSResource/'+jms_systemResource+'/Topics/'+jms_topic)
set('JNDIName',jms_topic_jndi)
set('SubDeploymentName',jms_subdeployment)
cd('/JMSSystemResources/'+jms_systemResource+'/SubDeployments/'+jms_subdeployment)
set('Targets',jarray.array([ObjectName('com.bea:Name='+jms_server+',Type=JMSServer')],ObjectName))

activate()

========================end of python script===============

Now open command prompt

Execute the following command after correcting the path as per your soa installation

mvn wls:wlst -DfileName=path/to/jmsobjects.py  - DmiddlewareHome=path/to/oraclehome 
-DdomainHome=path/to/domainhome 

No plugin found for prefix 'wls' in the current project

Even though the wls-maven-plugin is successfully installed, referring the goal via prefix might throw the above error.

mvn wls:wlst

Here wls is the prefix.

In such cases the following approach can be attempted

use the command in following format

mvn groupId:pluginname:goalname

For eg: To invoke the wlst goal on wls-maven-plugin use the following format

mvn com.oracle.weblogic:wls-maven-plugin:wlst


Sunday, November 2, 2014

Disabling logging and reporting globally in OSB 12c

The global disabling/enabling of logging,reporting etc can be performed from em console in 12c.

In 11g this can be done in service bus console

In 12c to  disable logging /reporting follow the below steps


1.       Logon to em console
2.       Under SOA select ServiceBus
3.       Right click on Service Bus which will open the properties as shown in the screenshot
4.       Go to Global Settings tab
5.       Uncheck logging option

6.       Apply the changes


The connection pool associated with it has already been destroyed

This error happens when WLS server invalidates the connections when we redeploy the adapter after adding a new JNDI . In such cases WLS server invalidates all the previous connection pool.

Though the connection pool JNDIs are visible at adapter configuration at run time it may fail with the error message "The connection pool associated with it has already been destroyed".

This seems to be a bug in weblogic

This mostly happens when we perform Adapter redeployment frequently.

To avoid this issue,

1.Delete all the existing connection pool JNDIs
2.Redeploy the Adatper
3.Restart your server
4.Add a new connection pool JNDI
5.Redeploy the Adapter

After this for any new JNDI added to the adapter ,ensure you only update the Adapter, not redeploy.



Thursday, October 30, 2014

Weblogic : Load balancer URL for a cluster

Sometimes in a clustered environment we would like to know whether load balancer is configured.

The easiest way to locate this is by logon to Weblogic Admin Console

Goto Envrioment->Clusters

Select your cluster

Open the HTTP tab

If load balancer is configured it will be available as Frontend Host



Weblogic : Creating Datasource using MAVEN and WLST Script

One of the interesting features of 12c is the option of using Maven for many of the administration tasks.

Maven along with WLST becomes the most convenient and powerful option to perform many of the administration tasks like creating domain,start and stop servers, listing deployed composites etc..

In this post I would like to introduce how maven plugin can be used to invoke a WLST script which creates a datasource in the weblogic domain.

As a first step we need to install maven plugin wls-maven-plugin.

This plugin present in the ORACLE_HOME/wlserver_12.1/server/lib

Open a command prompt and navigate to the above location

Now we need to install this plugin to our repository( here by default the repository will be the local repository which is present at  c:/users/<username>/.m2  (for windows)).

To install the plugin use the following command


mvn install:install-file -Dfile=wls-maven-plugin.jar -DpomFile=pom.xml

Once the installation is successful we can verify whether the required goals are available using the following command

mvn com.oracle.weblogic:wls-maven-plugin:help

Here we can see the wlst task is available. 

Now we are ready to execute the WLST script using maven

Create a datasource.properties file as shown below(change the values as per your requirement)
==================
domain.name=base_domain
admin.url=t3://localhost:7101
admin.userName=weblogic
admin.password=weblogic1

datasource.name=MyDataSource
datasource.database.name=XE
datasource.target=DefaultServer
datasource.filename=DS_One.xml
datasource.jndiname=DS_One_JNDI
datasource.driver.class=oracle.jdbc.xa.client.OracleXADataSource
datasource.url=jdbc:oracle:thin:@localhost:1521:XE
datasource.username=aq_user
datasource.password=aq_user

datasource.test.query=SQL SELECT * FROM DUAL
============================================

Save the following python script as datasource.py

note : remember to give the exact path to the datasource.properties file)

========start of python script ==========

from java.io import FileInputStream

propInputStream = FileInputStream("\\path\\to\\datasource.properties")
configProps = Properties()
configProps.load(propInputStream)

domainName=configProps.get("domain.name")
adminURL=configProps.get("admin.url")
adminUserName=configProps.get("admin.userName")
adminPassword=configProps.get("admin.password")

dsName=configProps.get("datasource.name")
dsFileName=configProps.get("datasource.filename")
dsDatabaseName=configProps.get("datasource.database.name")
datasourceTarget=configProps.get("datasource.target")
dsJNDIName=configProps.get("datasource.jndiname")
dsDriverName=configProps.get("datasource.driver.class")
dsURL=configProps.get("datasource.url")
dsUserName=configProps.get("datasource.username")
dsPassword=configProps.get("datasource.password")
dsTestQuery=configProps.get("datasource.test.query")

connect(adminUserName, adminPassword, adminURL)
edit()
startEdit()
cd('/')
cmo.createJDBCSystemResource(dsName)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName)
cmo.setName(dsName)

cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDataSourceParams/' + dsName )
set('JNDINames',jarray.array([String('jdbc/' + dsName )], String))

cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName )
cmo.setUrl(dsURL)
cmo.setDriverName(dsDriverName)
cmo.setPassword(dsPassword)

cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCConnectionPoolParams/' + dsName )
cmo.setTestTableName(dsTestQuery)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
cmo.createProperty('user')

cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/user')
cmo.setValue(dsUserName)

cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
cmo.createProperty('databaseName')

cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/databaseName')
cmo.setValue(dsDatabaseName)

cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDataSourceParams/' + dsName )
cmo.setGlobalTransactionsProtocol('OnePhaseCommit')

cd('/SystemResources/' + dsName )
set('Targets',jarray.array([ObjectName('com.bea:Name=' + datasourceTarget + ',Type=Server')], ObjectName))

save()
activate()

========================end of python script===============

Now open command prompt

Execute the following command after correcting the path as per your soa installation

mvn wls:wlst -DfileName=path/to/datasource.py  - DmiddlewareHome=path/to/oraclehome 
-DdomainHome=path/to/domainhome 

Once the script is executed successfully. Open the weblogic console and verify the datasource is created successfully