Saturday, March 1, 2014

How to Enable Monitoring on Proxy Services in OSB through WLST

We often get request to enable disable the monitoring on the Proxy Services which are deployed on the OSB, if we need to do it through console it might take a significant amount of time it;s fine when we have few projects deployed in the OSB when we have a lot and need to do it across the regions (dev, ist, perf, prod) it will take a significant time. 

We can use the WLST scripting to make the change on all the proxy services deployed in the OSB. 

Sample code for Time Saving and to get rid of boring of doing through obs consoles :)

---------------------------------------------------------------------------------------------------
# Scope    : To Enable the monitoring options on the proxy services deployed on the OSB.
# Process  :
#               1. Set the classpath
#                       CLASSPATH=/u01/app/oracle/product/fmw/Oracle_OSB1/lib/sb-kernel-api.jar:/u01/app/oracle/product/fmw/Oracle_OSB1/lib/sb-kernel-impl.jar:/u01/app/oracle/product/fmw/Oracle_OSB1/lib/modules/com.bea.alsb.configfwk-wls.jar:$CLASSPATH
#               2. export CLASSPATH
#               3. set the domain  eg : . ./bin/setDomain.sh
#               4. Update the sction below on the Enviroment specificaitons ( host,port,credentials)
#               5. execute the following command  java weblogic.WLST ProxyServiceMonotringOptions.py


import javax.management
import java.util
import javax.management.remote
import javax.naming
import weblogic.management.mbeanservers.domainruntime
import com.bea.wli.sb.management.configuration
import weblogic.management.jmx.MBeanServerInvocationHandler
from java.util import Hashtable
from java.util import HashSet
from java.util import ArrayList
from javax.management.remote import JMXServiceURL
from weblogic.management.mbeanservers.domainruntime import DomainRuntimeServiceMBean
from javax.naming import Context
from javax.management.remote import JMXConnectorFactory
from javax.management import ObjectName
from com.bea.wli.sb.management.configuration import SessionManagementMBean
from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean
from com.bea.wli.sb.management.configuration import CommonServiceConfigurationMBean
from com.bea.wli.config import Ref
from com.bea.wli.config.env import EnvValueQuery
from com.bea.wli.config.env import QualifiedEnvValue
from com.bea.wli.config.resource import DependencyQuery
from com.bea.wli.sb.management.query import ProxyServiceQuery
from com.bea.wli.sb.management.query import BusinessServiceQuery
from com.bea.wli.sb.util import EnvValueTypes
from java.util import Collection
from java.util import Collections


def setMonitoringAllProjectsAndServices(isEnabled):
    refs = configMBean.getRefs(Ref.DOMAIN)
    refsList = ArrayList()
    refsList.addAll(refs)

    for ref in refsList :
        if ref.getTypeId() == "ProxyService" :
            if ref.getTypeId() == "ProxyService" :
                isPS = "1"
            else:
                isPS =  "0"
            if isEnabled:
                print "enabling monitoring for ", ref.getFullName()
                proxyServiceConfigurationMBean.enableMonitoring(ref)
            else:
                print "disabling monitoring for ", ref.getFullName()
                proxyServiceConfigurationMBean.disableMonitoring(ref)

        else:
                print " This is Not a Proxy", ref.getFullName()

# Update the environment specific values belwo

sessionName = "MonitorUpdate"
hostname='localhost'
port=7001
username='xxxxxx'
password='xxxxxx'
serviceURL=JMXServiceURL("t3", hostname, port, "/jndi/" + DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME)
h=Hashtable()
h.put(Context.SECURITY_PRINCIPAL, username)
h.put(Context.SECURITY_CREDENTIALS, password)
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote")

conn = JMXConnectorFactory.connect(serviceURL, h)

mbconn = conn.getMBeanServerConnection()

sm = JMX.newMBeanProxy(mbconn, ObjectName.getInstance(SessionManagementMBean.OBJECT_NAME), SessionManagementMBean)

sm.createSession(sessionName)
configMBean = JMX.newMBeanProxy(mbconn, ObjectName.getInstance("com.bea:Name=" + ALSBConfigurationMBean.NAME + "." + sessionName + ",Type=" + ALSBConfigurationMBean.TYPE), ALSBConfigurationMBean)

domainService = weblogic.management.jmx.MBeanServerInvocationHandler.newProxyInstance(mbconn, ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME), DomainRuntimeServiceMBean, false)

proxyServiceConfigurationMBean = domainService.findService(String("ProxyServiceConfiguration.").concat(sessionName),'com.bea.wli.sb.management.configuration.ProxyServiceConfigurationMBean', None)

setMonitoringAllProjectsAndServices(true)

sm.activateSession(sessionName, "Complete enable/disable service monitoring")
conn.close()

-------------------------------------------------------------------------------------------------------

2 comments:

  1. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support in this area. same as your blog i found another one Oracle OSB Training .Actually I was looking for the same information on internet for Oracle OSB and came across your blog. I am impressed by the information that you have on this blog. Thanks once more for all the details.

    ReplyDelete
  2. I wish to show thanks to you just for bailing me out of this particular trouble. As a result of checking through the net and meeting techniques that were not productive, Same as your blog I found another one Oracle OSB 12c.Actually I was looking for the same information on internet for Oracle OSB 12c and came across your blog. I am impressed by the information that you have on this blog. Thanks once more for all the details.

    ReplyDelete