Tuesday, November 11, 2014

Export current messages from weblogic JMS Queue using WLST

Many a times it is required to export oracle weblogic JMS Messages from weblogic JMS queue to an XML file. One way of achieving this is using Weblogic Console. However doing it using WLST is a little tricky. I am providing a WLST snippet that can export jms messages for into a files. For distributed queue, one file will be created for each server on which it is targeted. So if a distributed queue is targeted on a cluster of two servers and contains messages, then two separate jms files will be created. After exporting all the messages from the queue, this script will delete the messages.

def exportMessages(serverName,server,jms_module,destination,messageSelector):
    try:
        serverRuntime()
        cd('JMSRuntime/' + serverName + '.jms/JMSServers/' + server + '/Destinations/'
+ jms_module + '!' + server + '@' +  destination)
        if cmo.getMessagesCurrentCount() > 0 :
            print ("No. of current messages are: ")
            print cmo.getMessagesCurrentCount()
            msgCursor=cmo.getMessages(messageSelector,1000,1)
            amountOfMessages=cmo.getCursorSize(msgCursor)
            allDestinationMessages=cmo.getNext(msgCursor,amountOfMessages)
            print allDestinationMessages
            outf = open (server+'-jmsmessages.xml','w')
            outf.write('<?xml version="1.0" encoding="UTF-8"?>' + '\n'
+ '<JMSMessageExport>' + '\n')
            for jmsmessage in allDestinationMessages:
                jmsmsginfo = JMSMessageInfo(jmsmessage)
                wlmsg = jmsmsginfo.getMessage()
                wlmsgid = wlmsg.getJMSMessageID()
                completeMsg = cmo.getMessage(msgCursor,wlmsgid)
                outf.write(completeMsg.get("MessageXMLText") + '\n')
            outf.write('</JMSMessageExport>')
            outf.close()
            cmo.closeCursor(msgCursor)
   cmo.deleteMessages(messageSelector)
        else:
            print ("No current message")
    except Exception, e:
        print('Exception is ')
        print e
        dumpStack()
        raise

serverName- Managed Server Name

server- JMS Server Name ( Domain_Name --> Messaging --> JMS Servers )

jms_module- JMS Module name ( Domain_Name --> Messaging --> JMS Modules )

destination- Queue Name

messageSelector- Selecting messages based on jms message properties such as JMS Priority etc. 

To modify the script to export pending messages, replace

msgCursor=cmo.getMessages(messageSelector,1000,1)

with

msgCursor=cmo.getMessages(messageSelector,1000,4)

The syntax for getMessages function is:
String getMessages(String selector, Integer timeout, Integer state)
where state is various message states such as 1 for current weblogic jms messages and 4 for pending weblogic jms messages

Tuesday, November 4, 2014

The WebLogic Server encountered a critical failure

ERROR:-

INFO: Notification event sent for activating changes.
***************************************************************************
The WebLogic Server encountered a critical failure
Reason: PermGen space
***************************************************************************

So I received this error while trying to start Admin Server. Even though how much I increase MaxPermSize, this error kept on coming.

CAUSE:-

Well the error came because by mistake I setup USER_MEM_ARGS in setDomainEnv.sh.(Well stop laughing at me :( . Remember "To err is human" ) This variable  override the standard memory arguments (MEM_ARGS) passed to java.

USER_MEM_ARGS="-Djava.security.egd=file:///dev/./urandom"
export USER_MEM_ARGS

Since I did not pass any other required JVM parameter. All the default values were used by JVM (Admin Server) while coming up which was insufficient.

I kept on hitting the error even though I increased MaxPermSize to 4GB :( Coz this paramter was part of MEM_ARGS which was overridden by USER_MEM_ARGS.

SOLUTION:-

Remove the USER_MEM_ARGS or set is as NULL (whatever you prefer :P )

USER_MEM_ARGS=""
export USER_MEM_ARGS

( Also I am not sure why but some how even after removing the USER_MEM_ARGS, it was still overriding MEM_ARGS. May be the value got saved in some GHOST cache. Open new putty session and then try starting the Admin Server )

Monday, October 6, 2014

To get TARGETS for application deployed on Weblogic using WLST

This function will return the list of Targets on which application has been deployed. 
It will take application name as the input parameter (i.e. APPNAME). 
It is using regular expression to extract server name or cluster name from the string. 
The FOR loop will run for each cluster/server. 
You need to import below classes for this function to work:

import re
import java.util.ArrayList as ArrayList

So the function will look like below:

def Target(APPNAME):
    try:
        print('#######################################################')
        print('Below are the Targets for '), APPNAME
        print('#######################################################')
        cd('AppDeployments/'+APPNAME)
        arr = ArrayList()
        arr=get('Targets')
        for myStr in arr:
            m = re.search('=(\w+),', str(myStr))
            print m.group(1)
        print('#######################################################')
    except Exception, e:
        print('Exception is ')
        print e
        dumpStack()
        raise

Sample Output:

#######################################################
Below are the Targets for  ServerState
#######################################################
SOA_MngdSvr1
SOA_MngdSvr2
#######################################################
.
.
.
.
#######################################################
Below are the Targets for  ServerState
#######################################################
B2B_Cluster
BAM_Cluster
SOA_Cluster
#######################################################

Thursday, October 2, 2014

Update weblogic keystores and SSL tab keystore location and password using WLST

We can use WLST to update identity and trust keystore location and password for admin and manager server under Configuration --> Keystores tab. It will also update Private Key Alias and Private Key Passphrase under Configuration --> SSL tab.

So I will create a function keystoreSSLSetup which will have below input arguments

Input Parameter Description
serverName Name of Admin or Managed Server where update is required
CustIdentityKeyStoreName  Identity Keystore containing the private and public key of the server 
CustIdentityKeyStorePassPhrase Password of Identity Keystore
CustTrustKeyStoreFileName Trust keystore containing CA certificates
CustServerPrivateKeyAlias Alias/name of the private key stored in identity keystore
CustServerPrivateKeyPassPhrase Password for private key. (Generally it is kept same as password of identity keystore)
domainHome Absolute path of domain

We will also encrypt the password for security reasons.

Now the function will look like below:

def keystoreSSLSetup(serverName,CustIdentityKeyStoreName,CustIdentityKeyStorePassPhrase,CustTrustKeyStoreFileName,CustServerPrivateKeyAlias,CustServerPrivateKeyPassPhrase,domainHome):  
    try:
        print "Setup KeyStore and SSL"
        cd ("/Servers/" + serverName)
        CustIdentityKeyStorePassPhraseEncrypted = encrypt (CustIdentityKeyStorePassPhrase, domainHome)
        set ("KeyStores", "CustomIdentityAndCustomTrust")
        set ("CustomIdentityKeyStoreFileName", CustIdentityKeyStoreName)
        set ("CustomIdentityKeyStorePassPhrase", CustIdentityKeyStorePassPhrase)
        set ("CustomIdentityKeyStorePassPhraseEncrypted", CustIdentityKeyStorePassPhraseEncrypted)
        set ("CustomIdentityKeyStoreType", "JKS")
        set ("CustomTrustKeyStoreFileName", CustTrustKeyStoreFileName)
        set ("CustomTrustKeyStorePassPhrase", CustIdentityKeyStorePassPhrase)
        set ("CustomTrustKeyStorePassPhraseEncrypted", CustIdentityKeyStorePassPhraseEncrypted)
        set ("CustomIdentityKeyStoreType", "JKS")
        print "Keystore Setup Successful"
        cd ("SSL/"+ serverName)
        set ("ServerPrivateKeyAlias", CustServerPrivateKeyAlias)
        set ("ServerPrivateKeyPassPhrase", CustServerPrivateKeyPassPhrase)
        CustServerPrivateKeyPassPhraseEncrypted = encrypt (CustOutboundPrivateKeyPassPhrase, domainHome)
        set ("ServerPrivateKeyPassPhraseEncrypted", CustServerPrivateKeyPassPhraseEncrypted)
        print "SSL Setup Successful"  
    except Exception, e:
        print e
        print "Error while trying to Setup KeyStore and SSL!!!"
        dumpStack()
        raise
        cancelEdit('y')
        activateTheChanges()
        disconnectFromServer()      
        exit() 

Thursday, August 7, 2014

Puppet Installation on Linux Master and Node

Master Machine OS - Red Hat Enterprise Linux Server release 6.3 (Santiago)
Client Machine OS - Red Hat Enterprise Linux Server release 6.3 (Santiago)

Reference URL - https://puppetlabs.com