Friday, November 14, 2014

WLST: Resume/Start all the Datasources

dbresume.py

A wlst script to suspend/start all the weblogic  datasources at one shot, can be used as healthcheck tool also



import re
print  "Enter Admin username used for logging into admin console (ex)ohsadmin"
username = raw_input("Enter username: ").strip()
print  "Enter Adminstrator password"
pwd = raw_input("Enter password: ").strip()
print  "Enter Admin server t3 url format t3://adminhost:adminport (ex)  t3://datahost.com:7001"

url = raw_input("Enter url : ").strip()

connect(username, pwd,url)
p=re.compile('Warning.*')
allServers=domainRuntimeService.getServerRuntimes();
if (len(allServers) > 0):
  for tempServer in allServers:
    jdbcServiceRT = tempServer.getJDBCServiceRuntime();
    dataSources = jdbcServiceRT.getJDBCDataSourceRuntimeMBeans();
    if (len(dataSources) > 0):
      for dataSource in dataSources:
        result=dataSource.testPool()
        m=p.match(str(result))
        if m or str(result)=='None':
          print 'The DS Name and state is '+dataSource.getName()+':Running'
        elif m or 'Suspended' in str(result):
          print 'The DS Name and state is '+dataSource.getName()+':Suspended , will be Resumed '
          dataSource.resume();
        elif m or 'not active' in str(result):
          print 'The DS Name and state is '+dataSource.getName()+':Shutdown, will be started'
          dataSource.start();
        else:
          print 'The DS Name and state is '+dataSource.getName()+':'+str(result).strip()
disconnect()
exit()

No comments:

Post a Comment