Forum Stats

  • 3,876,119 Users
  • 2,267,062 Discussions
  • 7,912,437 Comments

Discussions

Undeploy composites using Java API

805507
805507 Member Posts: 2
edited Dec 6, 2016 7:02AM in SOA Suite Discusssions
Hi,

My requirement is to undeploy(delete) unused composite revisions (not the composite instances) using Java api. I searched through the oracle.soa.management APIs but could not find required class/methods.

Please let me know how it can be done.

Thanks,
Datta

Best Answer

  • 805507
    805507 Member Posts: 2
    Answer ✓
    I found out the answer.

    First get the list of composites using Locator object. Use CompositeLifeCycleMbean to undeploy the composites as below.

    package be.telenet.bpel.main;

    import java.util.Hashtable;
    import java.util.Iterator;
    import java.util.List;
    import javax.naming.Context;
    import oracle.soa.management.facade.Composite;
    import oracle.soa.management.facade.CompositeInstance;
    import oracle.soa.management.facade.Locator;
    import oracle.soa.management.facade.LocatorFactory;
    import oracle.soa.management.util.CompositeFilter;
    import oracle.soa.management.util.CompositeInstanceFilter;

    public class TestComposite
    {
    public static void main(String[] args)
    {
    List<Composite> composites = null;
    String contextFactory = "weblogic.jndi.WLInitialContextFactory";
    String hostName = "myHost";
    String port = "7000";
    String user = "weblogic";
    String password = "my-password";
    String mbeanRuntime = "weblogic.management.mbeanservers.runtime";
    String jmxProtoProviderPackages = "weblogic.management.remote";
    String mBeanName = "oracle.soa.config:Application=my-infra,j2eeType=CompositeLifecycleConfig,name=my-infra";
    Locator locator = TestComposite.getLocator(hostName, port, user, password, contextFactory);

    try
    {
    //Get all composites based on the filter(empty). Here filter is //empty which means, list all
    CompositeFilter filter = new CompositeFilter();
    //Get locator object
    composites = locator.getComposites(filter);

    Iterator<Composite> itr = composites.iterator();

    //Get mbean server connection
    MBeanServerConnection mbsc = TestComposite.getMbeanServerConnection(hostName, port, user, password,mbeanRuntime,jmxProtoProviderPackages);
    //Get mbean object
    ObjectName mbean = new ObjectName(mBeanName);

    //Get all the CompositeData objects from MBean. They contain DNs
    //Note- this DN and composite.getDN()/getCompositeDN() are not same. This DN is required for undeploying
    Object compositeObjArray = mbsc.getAttribute(mbean, "DeployedComposites");
    CompositeData[] compositeData = (CompositeData[]) compositeObjArray;

    while (itr.hasNext())
    {
    Composite tmpCmp = itr.next();
    //Print composite details
    System.out.println("Composite Name " + tmpCmp.getDN());
    dnString = getDNToUndeploy(compositeData, cmp.getCompositeDN().toString());
    logger.debug("Composite DN: " + dnString);
    //Undeploys composite by calling mbean method
    mbsc.invoke(mbean, "removeCompositeForLabel", new Object[]{dnString},new String[]{"java.lang.String"});
    }
    } catch (Exception e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }


    //Get locator object using network details. This object is used for working on //composites
    public static Locator getLocator(String hostName, String port, String user, String password,
    String contextFactory)
    {
    Hashtable<String,String> jndiProps = new Hashtable<String,String>();
    String url = "t3://" + hostName + ":" + port + "/my-infra";

    jndiProps.put(Context.PROVIDER_URL, url);
    jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
    jndiProps.put(Context.SECURITY_PRINCIPAL,user);
    jndiProps.put(Context.SECURITY_CREDENTIALS, password);
    jndiProps.put("dedicated.connection", "true");

    Locator locator = null;
    try
    {
    locator = LocatorFactory.createLocator(jndiProps);
    } catch (Exception e)
    {
    e.printStackTrace();
    }
    return locator;
    }

    public static MBeanServerConnection getMbeanServerConnection(String hostName, String port, String user, String password
    , String mbeanRuntime, String jmxProtoProviderPackages)
    throws IOException
    {
    String url = "service:jmx:t3://" + hostName + ":" + port + "/jndi/" + mbeanRuntime;
    serviceURL = new JMXServiceURL(url);
    Hashtable<String,String> ht = new Hashtable<String,String>();
    ht.put("java.naming.security.principal", user);
    ht.put("java.naming.security.credentials", password);
    ht.put("jmx.remote.protocol.provider.pkgs", jmxProtoProviderPackages);

    try
    {
    jmxConnector = JMXConnectorFactory.newJMXConnector(serviceURL, ht);
    jmxConnector.connect();
    mbsc = jmxConnector.getMBeanServerConnection();

    } catch (IOException e)
    {
    logger.error("Exception: Exception occurred while connectiong to server...");
    throw e;

    }
    return mbsc;
    }

    private String getDNToUndeploy(CompositeData[] compositeData, String compositeToBeUndeployed) throws Exception
    {
    String dnString = null;
    for (CompositeData tmpCData : compositeData)
    {
    String tempDN = (String) tmpCData.get("DN");
    if ( tempDN.contains(compositeToBeUndeployed) )
    {
    dnString = tempDN;
    break;
    }
    }
    return dnString;
    }
    }

Answers

  • 805507
    805507 Member Posts: 2
    Answer ✓
    I found out the answer.

    First get the list of composites using Locator object. Use CompositeLifeCycleMbean to undeploy the composites as below.

    package be.telenet.bpel.main;

    import java.util.Hashtable;
    import java.util.Iterator;
    import java.util.List;
    import javax.naming.Context;
    import oracle.soa.management.facade.Composite;
    import oracle.soa.management.facade.CompositeInstance;
    import oracle.soa.management.facade.Locator;
    import oracle.soa.management.facade.LocatorFactory;
    import oracle.soa.management.util.CompositeFilter;
    import oracle.soa.management.util.CompositeInstanceFilter;

    public class TestComposite
    {
    public static void main(String[] args)
    {
    List<Composite> composites = null;
    String contextFactory = "weblogic.jndi.WLInitialContextFactory";
    String hostName = "myHost";
    String port = "7000";
    String user = "weblogic";
    String password = "my-password";
    String mbeanRuntime = "weblogic.management.mbeanservers.runtime";
    String jmxProtoProviderPackages = "weblogic.management.remote";
    String mBeanName = "oracle.soa.config:Application=my-infra,j2eeType=CompositeLifecycleConfig,name=my-infra";
    Locator locator = TestComposite.getLocator(hostName, port, user, password, contextFactory);

    try
    {
    //Get all composites based on the filter(empty). Here filter is //empty which means, list all
    CompositeFilter filter = new CompositeFilter();
    //Get locator object
    composites = locator.getComposites(filter);

    Iterator<Composite> itr = composites.iterator();

    //Get mbean server connection
    MBeanServerConnection mbsc = TestComposite.getMbeanServerConnection(hostName, port, user, password,mbeanRuntime,jmxProtoProviderPackages);
    //Get mbean object
    ObjectName mbean = new ObjectName(mBeanName);

    //Get all the CompositeData objects from MBean. They contain DNs
    //Note- this DN and composite.getDN()/getCompositeDN() are not same. This DN is required for undeploying
    Object compositeObjArray = mbsc.getAttribute(mbean, "DeployedComposites");
    CompositeData[] compositeData = (CompositeData[]) compositeObjArray;

    while (itr.hasNext())
    {
    Composite tmpCmp = itr.next();
    //Print composite details
    System.out.println("Composite Name " + tmpCmp.getDN());
    dnString = getDNToUndeploy(compositeData, cmp.getCompositeDN().toString());
    logger.debug("Composite DN: " + dnString);
    //Undeploys composite by calling mbean method
    mbsc.invoke(mbean, "removeCompositeForLabel", new Object[]{dnString},new String[]{"java.lang.String"});
    }
    } catch (Exception e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }


    //Get locator object using network details. This object is used for working on //composites
    public static Locator getLocator(String hostName, String port, String user, String password,
    String contextFactory)
    {
    Hashtable<String,String> jndiProps = new Hashtable<String,String>();
    String url = "t3://" + hostName + ":" + port + "/my-infra";

    jndiProps.put(Context.PROVIDER_URL, url);
    jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory);
    jndiProps.put(Context.SECURITY_PRINCIPAL,user);
    jndiProps.put(Context.SECURITY_CREDENTIALS, password);
    jndiProps.put("dedicated.connection", "true");

    Locator locator = null;
    try
    {
    locator = LocatorFactory.createLocator(jndiProps);
    } catch (Exception e)
    {
    e.printStackTrace();
    }
    return locator;
    }

    public static MBeanServerConnection getMbeanServerConnection(String hostName, String port, String user, String password
    , String mbeanRuntime, String jmxProtoProviderPackages)
    throws IOException
    {
    String url = "service:jmx:t3://" + hostName + ":" + port + "/jndi/" + mbeanRuntime;
    serviceURL = new JMXServiceURL(url);
    Hashtable<String,String> ht = new Hashtable<String,String>();
    ht.put("java.naming.security.principal", user);
    ht.put("java.naming.security.credentials", password);
    ht.put("jmx.remote.protocol.provider.pkgs", jmxProtoProviderPackages);

    try
    {
    jmxConnector = JMXConnectorFactory.newJMXConnector(serviceURL, ht);
    jmxConnector.connect();
    mbsc = jmxConnector.getMBeanServerConnection();

    } catch (IOException e)
    {
    logger.error("Exception: Exception occurred while connectiong to server...");
    throw e;

    }
    return mbsc;
    }

    private String getDNToUndeploy(CompositeData[] compositeData, String compositeToBeUndeployed) throws Exception
    {
    String dnString = null;
    for (CompositeData tmpCData : compositeData)
    {
    String tempDN = (String) tmpCData.get("DN");
    if ( tempDN.contains(compositeToBeUndeployed) )
    {
    dnString = tempDN;
    break;
    }
    }
    return dnString;
    }
    }
This discussion has been closed.