Managing active and prepared transactions using wsadmin scripting

You can use the wsadmin tool and scripting to manage active and prepared transactions that might need administrator action.

Before you begin

Before starting this task, the wsadmin tool must be running.

About this task

In normal circumstances, every effort is made to finish a transaction. However, because of Resource Recovery Services (RRS) and native contexts finishing, it might not be possible to finish the transaction. In this case, the transaction is marked rollback_only so that it rolls back at the next available window. In other situations, you might have to finish a transaction manually. For example, you might want to finish a transaction that is stuck polling a resource manager that you know will not become available again in the required time frame.

Note: If you choose to complete a transaction on an application server, it is recorded as having completed in the transaction service logs for that server, so it is not eligible for recovery during server start up. If you complete a transaction, you are responsible for cleaning up any in-doubt transactions on the resource managers affected.

For more information about the TransactionService and Transaction MBeans, see the application programming interface (API) documentation.

Procedure

Example

The following script is an example of how to use the TransactionService and Transaction MBeans to work with manual transactions. Run the script only against an application server, and not against the deployment manager or node agent.

Example Jacl script:

# get the TransactionService MBean
set servicembean [$AdminControl queryNames type=TransactionService,*]

# get the Transaction MBean
set mbean [$AdminControl queryNames type=Transaction,*]

set input 0
while {$input >= 0} {
        # invoke the listManualTransactions method
        set tranManualList [$AdminControl invoke $servicembean listManualTransactions]

        if {[llength $tranManualList] > 0} {
                puts "----Manual Transaction details---------------"
                set index 0
                foreach tran $tranManualList {
                        puts "   Index= $index tran= $tran"
                        incr index
                }
                puts "----End of Manual Transactions ---------------"
                puts "Select index of transaction to commit/rollback:"
                set input [gets stdin]
                if {$input < 0} {
                        puts "No index selected, exiting."
                } else {
                        set tran [lindex $tranManualList $input]
                        set commaPos [expr [string first "," $tran ]-1]
                        set localTID [string range $tran 0 $commaPos]
                        puts "Enter c to commit or r to rollback Transaction $localTID"
                        set input [gets stdin]
                        if {$input=="c"} {
                                puts "Committing transaction=$localTID"
                                $AdminControl invoke $mbean commit $localTID
                        }
                        if {$input=="r"} {
                                puts "Rolling back transaction=$localTID"
                                $AdminControl invoke $mbean rollback $localTID
                        }
                }
        } else {
                puts "No Manual transactions found, exiting"
                set input -1
        }
        puts " "

}

Working with manual transactions: example Jython script.

import sys
def wsadminToList(inStr):
        outList=[]
        if (len(inStr)>0 and inStr[0]=='[' and inStr[-1]==']'):
                tmpList = inStr[1:-1].split(" ")
        else:
                tmpList = inStr.split("\n")  #splits for Windows or Linux
        for item in tmpList:
                item = item.rstrip();        #removes any Windows "\r"
                if (len(item)>0):
                        outList.append(item)
        return outList
#endDef

servicembean = AdminControl.queryNames("type=TransactionService,*" )
mbean = AdminControl.queryNames("type=Transaction,*" )
input = 0

while (input >= 0):
        tranList = wsadminToList(AdminControl.invoke(servicembean, "listManualTransactions" ))

        tranLength = len(tranList) 
        if (tranLength > 0):
                print "----Manual Transaction details---------------"
                index = 0
                for tran in tranList:
                        print "   Index=" , index , " tran=" , tran
                        index = index+1
                #endFor 
                print "----End of Manual Transactions ---------------"
                print "Select index of transaction to commit/rollback:"
                input = sys.stdin.readline().strip()
                if (input == ""):
                        print "No index selected, exiting."
                        input = -1
                else:
                        tran = tranList[int(input)]
                        commaPos = (tran.find(",") -1)
                        localTID = tran[0:commaPos+1]
                        print "Enter c to commit or r to rollback transaction ", localTID
                        input = sys.stdin.readline().strip()
                        if (input == "c"):
                                print "Committing transaction=", localTID
                                AdminControl.invoke(mbean, "commit", localTID )
                        #endIf 
                        elif (input == "r"):
                                print "Rolling back transaction=", localTID
                                AdminControl.invoke(mbean, "rollback", localTID )
                        #endIf 
                        else:
                                input = -1
                        #endelse
                #endElse 
        else:
                print "No transactions found, exiting"
                input = -1
        #endElse 
        print " "

#endWhile



In this information ...


IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic Task topic    

Terms and conditions for information centers | Feedback

Last updatedLast updated: Aug 31, 2013 12:02:36 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=pix&product=was-nd-zos&topic=tjta_manage_scripts
File name: tjta_manage_scripts.html