Thursday, November 10, 2011

Oracle SOA Suite - Changing the state and mode of a composite through JAVA.

Oracle SOA Suite - Changing the state and mode of a composite through JAVA:


Some scenario's we may required to change the state and mode of the composite the below java code snippet will help you to change the same.

Change the SOA server details and the composite details accordingly.

package changecompositestate;

import java.util.Hashtable;
import java.util.Set;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import javax.naming.Context;

public class ChangeCompositeStateAndMode {
static MBeanServerConnection m_connection=null;
public static void changeCompositeStateAndMode()
{
String jndiroot = "/jndi/";
String revision=null;
try
{
Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.SECURITY_PRINCIPAL,"weblogic");
jndiProps.put(Context.SECURITY_CREDENTIALS,"xxxxx");
jndiProps.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote");
JMXServiceURL serviceURL = new JMXServiceURL("t3","eaidev2",8000,jndiroot + "weblogic.management.mbeanservers.runtime");
JMXConnector m_connector = JMXConnectorFactory.newJMXConnector(serviceURL,jndiProps);
m_connector.connect();
m_connection = m_connector.getMBeanServerConnection();
ObjectName compositeLifeCycleMBean = null;
Set queryResult = m_connection.queryNames(new ObjectName("*:j2eeType=CompositeLifecycleConfig,*"), null);
if (!queryResult.isEmpty()) {
compositeLifeCycleMBean = (ObjectName)queryResult.iterator().next();
}
//CompositeDN - DomainName/CompositeName
String compositeDN = "default" + "/" + "GetDomainID!1.0";
setCompositeModeAndState(compositeLifeCycleMBean, compositeDN);
}catch(Exception e)
{
e.printStackTrace();
}
}
public static void setCompositeModeAndState(ObjectName compositeLifeCycleMBean, String compositeDN)
throws Exception {
m_connection.invoke(compositeLifeCycleMBean,"setCompositeMode", new Object[] { compositeDN,"retired" }, new String[] { String.class.getName() ,String.class.getName()});
m_connection.invoke(compositeLifeCycleMBean,"setCompositeState", new Object[] { compositeDN ,"off"}, new String[] { String.class.getName(),String.class.getName() });
}

public static void main(String args[]) {
changeCompositeStateAndMode();
}

}
Logout and login to EM console to see the changes,the component will be down now as shown below.

In Oracle SOA 11g:



In Oracle SOA 12c:
oracle_soa_12c_composite_status

2 comments:

  1. Good one... If MDS gets corrupted the whole soa-infra doesnt startup properly. Probably, during such scenario this code will be very useful. Also undeploying all the older version of components can be automated based on the revisions

    ReplyDelete
  2. Can we also change the version of the deployed composite in this? Just for research..

    ReplyDelete