Monday 17 November 2014

Script to List All the OSB projects, Business Services and Proxy Services deployed in sbconsole

blogger

Script to List All the OSB projects, Business Services and Proxy Services deployed in sbconsole.

Hello to viewer,

This script will provide you the list of all the OSB projects , business services and proxy services deployed in sbconsole in a .txt file.

Benefits: This is helpful for techies supporting non prod environment where lots of dummy projects are created by developers just for testing purpose. This script can help in performing the cleanup activity.It will provide the list of projects , BS and proxy services and later unused services and projects can be identified and deleted.

Here is the Flow :
Shell calls the python ---> python executes the wlst command.

Follow the below steps:

Step 1) : Create the directory structure as below:

cd /shared/fmw/build/script/List/


Step 2) : Under your current directory "List" create osbservices.py file with content below:

import sys
import os
import socket

connect('username', 'password', 't3://host:AdminPort')

from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean
from com.bea.wli.config import Ref
from java.lang import String
from com.bea.wli.sb.util import Refs
from com.bea.wli.sb.management.configuration import CommonServiceConfigurationMBean
from com.bea.wli.sb.management.configuration import SessionManagementMBean
from com.bea.wli.sb.management.configuration import ProxyServiceConfigurationMBean
from com.bea.wli.monitoring import StatisticType
from com.bea.wli.monitoring import ServiceDomainMBean
from com.bea.wli.monitoring import ServiceResourceStatistic
from com.bea.wli.monitoring import StatisticValue
from com.bea.wli.monitoring import ServiceDomainMBean
from com.bea.wli.monitoring import ServiceResourceStatistic
from com.bea.wli.monitoring import StatisticValue
from com.bea.wli.monitoring import ResourceType

domainRuntime()

alsbCore = findService(ALSBConfigurationMBean.NAME, ALSBConfigurationMBean.TYPE)
refs = alsbCore.getRefs(Ref.DOMAIN)
it = refs.iterator()
print "List of Project in OSB"
while it.hasNext():
    r = it.next()
    if r.getTypeId() == Ref.PROJECT_REF:      
        print "Project Name : " + (r.getProjectName())

allRefs= alsbCore.getRefs(Ref.DOMAIN)
print "List of Proxy Service"
for ref in allRefs:  
  typeId = ref.getTypeId()
  if typeId == "ProxyService":    
     print "Proxy Service: " + ref.getFullName()
allRefs= alsbCore.getRefs(Ref.DOMAIN)
print "List of Business Service"
for ref in allRefs:
  typeId = ref.getTypeId()
  if typeId == "BusinessService":         
     print "Business Service: " + ref.getFullName()
disconnect()
exit()


Step 3)  : Under your current directory "List" create "osbservices.sh" with the content below :


#!/bin/sh
# set up WL_HOME and OSBHOME the root directory of your WebLogic installation
WL_HOME="WL_HOME Directory"
OSBHOME="OSB_HOME Directory"
rm output.txt
umask 027

# set up common environment
WLS_NOT_BRIEF_ENV=true
. "${WL_HOME}/server/bin/setWLSEnv.sh"


CLASSPATH="${CLASSPATH}${CLASSPATHSEP}${FMWLAUNCH_CLASSPATH}${CLASSPATHSEP}${DERBY_CLASSPATH}${CLASSPATHSEP}${DERBY_TOOLS}${CLASSPATHSEP}${POINTBASE_CLASSPATH}${CLASSPATHSEP}${POINTBASE_TOOLS}"

CLASSPATH=$CLASSPATH:$OSBHOME/modules/com.bea.common.configfwk_1.6.0.0.jar:$OSBHOME/lib/sb-kernel-api.jar:$OSBHOME/lib/sb-kernel-impl.jar:$WL_HOME/server/lib/weblogic.jar:$OSBHOME/lib/alsb.jar;
export CLASSPATH


if [ "${WLST_HOME}" != "" ] ; then
        WLST_PROPERTIES="-Dweblogic.wlstHome='${WLST_HOME}'${WLST_PROPERTIES}"
        export WLST_PROPERTIES
fi
JVM_ARGS="-Dprod.props.file='${WL_HOME}'/.product.properties ${WLST_PROPERTIES} ${JVM_D64} ${MEM_ARGS} ${CONFIG_JVM_ARGS}"

ORACLE_HOME/common/bin/wlst.sh osbservices.py  >> output.txt
date >> output.txt







Note : Change the value of wl_home, oracle_home, OSBHOME according to your environment.

After this you just need to run the shell script : sh osbservices.sh and you will get the output in output.txt file.

Thanks a lot for your patience !!!! 

Regards
-Ashish