Usage
Usage: Enable/Disable Proxy services setProxyState [-d|-e] [-v] [-f proxy-list-file] admin-url wls-password [path-to-proxy ] -v verbose output -d disable the proxy state -e enable the proxy state -f file with a list of proxy services
Note:
The python script must by started from the common/bin directory in which the OSB is installed (ORACLE_HOME). I assume that the connection is made through the default 'weblogic' user. Make sure you have set the domain environment (setDomainEnv.sh).
Example Single Service (enable)
$ORACLE_HOME/common/bin/wlst.sh setproxystate.py -e t3://osb.vijfhuizen.com:7001 welcome1 MyProxyProject/MyProxyService_v2r0
Example via a file (disable)
$ORACLE_HOME/common/bin/wlst.sh setproxystate.py -d -f listofproxies.txt t3://osb.vijfhuizen.com:7001 welcome1
The listofproxies.txt file is a list of Proxy Services that includes the whole project path without a beginning '/'. Example:
listofproxies.txt ================= # # This is a list of services that are read in this sequence # to be enabled or enabled. # MyProxyProject/MyProxyService_v1r0 MyProxyProject/MyProxyService_v2r0 MyProxyProject/MyProxyService_v2r1
The whole python script is here.
setproxystate.py:
#
# Make sure you have set the domain environment settings:
#
# . $WLS_DOMAIN/bin/setDomainEnv.sh
#
# Usage:
#
# /opt/weblogic/Middleware/Oracle_OSB/common/bin/wlst.sh setproxystate.py -e -f listofproxies.txt t3://l2-mslfonapp02:7001 webl0gic
#
import getopt
import sys
import os
from com.bea.wli.sb.management.configuration import SessionManagementMBean
from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean
from com.bea.wli.config import Ref
from com.bea.wli.monitoring import StatisticType
from com.bea.wli.sb.util import Refs
from com.bea.wli.sb.management.configuration import CommonServiceConfigurationMBean
wl_user="weblogic"
verbose=False
#########################################################################################
def ConnectToWLS(u, p, h):
msg("Connect to " + h + " as user " + u)
connect(u,p, h)
domainRuntime()
def DisconnectFromWLS():
msg("Disconnect")
disconnect()
def CreateOSBSession():
sessionName = "SetProxyStateSession_" + str(System.currentTimeMillis())
sessionMBean = findService(SessionManagementMBean.NAME, SessionManagementMBean.TYPE)
sessionMBean.createSession(sessionName)
msg("OSB Session Created: " + sessionName)
return sessionMBean, sessionName
def ActivateSession(b, n, s, a):
msg("Activate OSB Session: " + n)
b.activateSession(n, a + " " + s)
def FindService(f, s, session, n):
msg("Find proxy service: " + f + "/" + s)
pxyConf = "ProxyServiceConfiguration." + n
mbean = findService(pxyConf, 'com.bea.wli.sb.management.configuration.ProxyServiceConfigurationMBean')
folderRef = Refs.makeParentRef(f + '/')
serviceRef = Refs.makeProxyRef(folderRef, s)
return serviceRef, mbean
def setStateService(b, s, a):
if a == 'disable':
msg("Disable Service")
b.disableService(s)
else:
msg("Enable Service")
b.enableService(s)
#########################################################################################
def usage():
print "Usage: Enable/Disable Proxy services"
print "setProxyState [-d|-e] [-v] [-f list-of-proxy-services] admin-url wls-password [proxy-service]"
print "-v verbose output"
print "-d disable the proxy state"
print "-e enable the proxy state"
print "-f file with a list of proxy services"
def main():
############################################################
## Parse Arguments
##
proxy_file=""
noofargs = 3
try:
opts, args = getopt.getopt(sys.argv[1:], "vdehf:", ["help"])
for o, a in opts:
if o == '-h':
usage()
exit()
elif o == '-v':
global verbose
verbose = True
elif o == '-d':
state = "disable"
elif o == '-e':
state = "enable"
elif o == '-f':
proxy_file = a
noofargs = noofargs - 1
else:
print "Unknown argument."
print ""
usage()
exit()
if len(args) != noofargs:
print "Invalid number of arguments."
print ""
usage()
exit()
admin_server = args[0]
wl_password = args[1]
if len(proxy_file) > 0:
setStateListOfProxyService(proxy_file, state, wl_password, admin_server)
else:
proxy_service = args[2]
setStateOfProxyService(proxy_service, state, wl_password, admin_server)
except getopt.GetoptError, err:
# print help information and exit:
print str(err)
print ""
usage()
############################################################
def msg(m):
if verbose:
print m
def setStateListOfProxyService(pfile, stateOnOff, wl_password, admin_server):
try:
ConnectToWLS(wl_user, wl_password, admin_server)
file = open(pfile, "r")
osbSession, sessionName = CreateOSBSession()
appliedServices = ""
for line in file.readlines():
line = line.lstrip().rstrip()
msg("Read line: " + line)
if line.find("#") < 0 and len(line) > 0:
relativePath = os.path.dirname(line)
pServiceName = os.path.basename(line)
appliedServices = appliedServices + " " + pServiceName
service, sessionBean = FindService(relativePath, pServiceName, osbSession, sessionName)
setStateService(sessionBean, service, stateOnOff)
file.close()
ActivateSession(osbSession, sessionName, appliedServices, stateOnOff)
DisconnectFromWLS()
except:
print "Unexpected error: ", sys.exc_info()[0]
dumpStack()
raise
def setStateOfProxyService(pservice, stateOnOff, wl_password, admin_server):
try:
ConnectToWLS(wl_user, wl_password, admin_server)
osbSession, sessionName = CreateOSBSession()
relativePath = os.path.dirname(pservice)
pServiceName = os.path.basename(pservice)
service, sessionBean = FindService(relativePath, pServiceName, osbSession, sessionName)
setStateService(sessionBean, service, stateOnOff)
ActivateSession(osbSession, sessionName, pServiceName, stateOnOff)
DisconnectFromWLS()
except:
print "Unexpected error: ", sys.exc_info()[0]
dumpStack()
raise
############################################################
main()
exit()
6 comments:
setStateService(sessionBean, service, stateOnOff) needs to be in the for-loop
thnx, happens when you test with one service :-)
Marc,
I'm not sure whether you have seen my comment on your blog post - if you have, sorry, please ignore this one.
I'm using your script and having a problem.
I'm running OSB10.3.1 on Windows and if I call the script using the following command
java weblogic.WLST setproxystate.py -e -v t3://d8uatesb01:7001 weblogic ICSProcessing\ProxyServices\Destin8Listeners\ICSListenerUATWLS05
I get the following error.
java.lang.IllegalArgumentException: Project or folder name "ICSProcessing\ProxyServices\Destin8Listeners" contains an illegal character "\".
It's coming from the findService method and on this line
folderRef = Refs.makeParentRef(f + '/' )
Have you any suggestions on what could be going wrong?
Thanks, Pete
Many thanks! How can I call this script from SOAPUI?
Thanks a ton marc
Is there a way of enabling/disabling proxy when Adminserver is down ?
Hi,
Is there a way we can enable and disable a proxy when Admin server is unavailable and so is sbConsole ?
I tried using WLST/Java scripts but all is dependent on Admin server to be up and running else it does not work.
I sometimes face a situation where in our node having Adminsever installed is under maintenance and there is a need of enabling/disabling proxy's.
Post a Comment