Advertisement
m4ly

Oracle Service Bus database purger

Aug 18th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.81 KB | None | 0 0
  1. # Author: Dawid Mocek
  2. # WLST Jython script which purges Oracle Service Bus Reports Data logs
  3.  
  4. import weblogic.security.internal.SerializedSystemIni
  5. import weblogic.security.internal.encryption.ClearOrEncryptedService
  6. import sys
  7.  
  8. from time import sleep
  9. from com.ziclix.python.sql import zxJDBC
  10.  
  11. try:
  12.     # print 'Connecting'
  13.     connect(AdminServerUser, AdminServerPassword, AdminServerURL)
  14.  
  15.     # print 'Location change to domainConfig'
  16.     domainConfig()
  17.  
  18.     rootdir = cmo.getRootDirectory()
  19.     securedir = rootdir + '/security'
  20.  
  21.     # print 'Reading datasource parameters'
  22.  
  23.     # Get datasource params
  24.     cd('/JDBCSystemResources/'+DataSourceName+'/JDBCResource/'+DataSourceName+'/JDBCDriverParams/'+DataSourceName)
  25.     dburl=cmo.getUrl()
  26.     dbdriver=cmo.getDriverName()
  27.     dbpass_encrypted=cmo.getPasswordEncrypted()
  28.  
  29.     # Decrypt db password
  30.     es=weblogic.security.internal.SerializedSystemIni.getEncryptionService(securedir)
  31.     ces=weblogic.security.internal.encryption.ClearOrEncryptedService(es)
  32.     dbpass=str(ces.decrypt("".join(map(chr, dbpass_encrypted))))
  33.  
  34.     # Get db username
  35.     cd('/JDBCSystemResources/'+DataSourceName+'/JDBCResource/'+DataSourceName+'/JDBCDriverParams/'+DataSourceName+'/Properties/'+DataSourceName+'/Properties/user')
  36.     dbuser = cmo.getValue()
  37.  
  38.     # print 'Connection string: ', dburl
  39.     # print 'Driver: ', dbdriver
  40.     # print 'User: ', dbuser
  41.     # print 'Pass: ******'
  42.  
  43.     # print 'Location change to domainRuntime'
  44.     domainRuntime()
  45.  
  46.     cd('AppRuntimeStateRuntime/AppRuntimeStateRuntime')
  47.     jmsrp_state=cmo.getCurrentState(JMSRP, ManagedServerName)
  48.  
  49.     # Be sure that jms rp is running
  50.     if jmsrp_state == 'STATE_ACTIVE':
  51.         # print 'Stopping application'
  52.         stopApplication(JMSRP, block='true')
  53.     sleep(10)
  54.  
  55.     # Be sure again - jms rp must be stopped
  56.     jmsrp_state=cmo.getCurrentState(JMSRP, ManagedServerName)
  57.     if jmsrp_state == 'STATE_PREPARED':
  58.         # print 'Purging error queue'
  59.         cd('/ServerRuntimes/'+ManagedServerName+'/JMSRuntime/'+ManagedServerName+'.jms/JMSServers/wlsbJMSServer/Destinations/jmsResources!wli.reporting.jmsprovider_error.queue')
  60.         cmo.deleteMessages('')
  61.         con = zxJDBC.connect(dburl, dbuser, dbpass, dbdriver)
  62.         c = con.cursor()
  63.         c.execute("ALTER TABLE WLI_QS_REPORT_DATA DISABLE CONSTRAINT FK_WLI_QS_REPORT_DATA")
  64.         c.execute("TRUNCATE TABLE WLI_QS_REPORT_DATA")
  65.         c.execute("TRUNCATE TABLE WLI_QS_REPORT_ATTRIBUTE")
  66.         c.execute("ALTER TABLE WLI_QS_REPORT_DATA ENABLE CONSTRAINT FK_WLI_QS_REPORT_DATA")
  67.         c.close()
  68.         con.close()
  69.         # print 'Starting application'
  70.         startApplication(JMSRP, block='true')
  71.  
  72.     serverConfig()
  73.  
  74.     #print 'Disconnecting'
  75.     disconnect()
  76. except Exception, e:
  77.     sys.exit('FAILED: ' + str(e))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement