I got a requirement from our client to create a JAVA API that can abort all the RUNNING composite instances. This was required as purging script do not purge composite instances in running instances.
import java.util.Hashtable;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.Component;
import oracle.soa.management.facade.ComponentInstance;
import oracle.soa.management.facade.Composite;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.ComponentInstanceFilter;
import oracle.soa.management.util.CompositeInstanceFilter;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.CompositeDN;
public class abortComposite {
public abortComposite() {
super();
}
public void abortRunningComposite() {
Locator locator = null;
Hashtable jndiProps = new Hashtable();
//Connection Details to Connect to Server
jndiProps.put(Context.PROVIDER_URL, "t3://hostname:portnumber/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
jndiProps.put(Context.SECURITY_CREDENTIALS, "password");
jndiProps.put("dedicated.connection", "true");
try {
//Connect to SOA Server
locator = LocatorFactory.createLocator(jndiProps);
System.out.println("Connected to SOA Server.");
java.util.List compositeDN=locator.listComposites();
CompositeInstanceFilter filter = new CompositeInstanceFilter();
//Set Minimum Creation Time
filter.setMinCreationDate(new java.util.Date("Tue Aug 10 13:22:02 PDT 2013"));
//Set Maximum Creation Time
filter.setMaxCreationDate(new java.util.Date("Tue Aug 30 13:22:02 PDT 2013"));
//Set for RUNNING State
filter.setState(0);
Composite composite=null;
List obInstances=null;
//For each of the returned composite
for (CompositeDN compositeDN1 : compositeDN) {
composite = locator.lookupComposite(compositeDN1);
//Get composite instances by filter
obInstances = composite.getInstances(filter);
//for each of the returned composite instances
for (CompositeInstance instance : obInstances) {
System.out.println(" DN: " + instance.getCompositeDN() + " Instance: " + instance.getId() + " creation-date: " + instance.getCreationDate() + " state (" + instance.getState() + "): " + getStateAsString(instance.getState()));
//Set up a component filter
ComponentInstanceFilter cInstanceFilter = new ComponentInstanceFilter();
//Get child component instances
List childComponentInstances = instance.getChildComponentInstances(cInstanceFilter);
//For each child component instance
for (ComponentInstance cInstance : childComponentInstances) {
System.out.println(" -> componentinstance: " + cInstance.getComponentName() + " type: " + cInstance.getServiceEngine().getEngineType() + " state: " +getStateAsString(cInstance.getState()));
System.out.println("State: "+cInstance.getNormalizedStateAsString());
}
instance.abort();
}
obInstances=null;
}
}
catch (Exception e) {
System.out.println("Exception in API " + e);
}
}
private String getStateAsString(int state){
//Note that this is dependent on whether the composite state is captured or not
if (state == CompositeInstance.STATE_COMPLETED_SUCCESSFULLY)
return ("success");
else if (state == CompositeInstance.STATE_FAULTED)
return ("faulted");
else if (state == CompositeInstance.STATE_RECOVERY_REQUIRED)
return ("recovery required");
else if (state == CompositeInstance.STATE_RUNNING)
return ("running");
else if (state == CompositeInstance.STATE_STALE)
return ("stale");
else
return ("unknown");
}
public static void main(String[] args) {
abortComposite abortcomposite=new abortComposite();
abortcomposite.abortRunningComposite();
}
}
Steps:-
Set Classpath
export CLASSPATH=$CLASSPATH:$ORACLE_FMW_HOME/oracle_common/soa/modules/oracle.soa.mgmt_11.1.1/soa-infra-mgmt.jar:$ORACLE_FMW_HOME/oracle_common/modules/oracle.fabriccommon_11.1.1/fabric-common.jar:$ORACLE_FMW_HOME/wlserver_10.3/server/lib/weblogic.jar:$ORACLE_FMW_HOME/oracle_common/modules/oracle.jrf_11.1.1/jrf-api.jar
Compile the code
javac abortComposite.java
Execute the Code
java abortComposite
JAVA API Source Code-
import java.util.Hashtable;
import java.util.List;
import javax.naming.Context;
import oracle.soa.management.facade.Component;
import oracle.soa.management.facade.ComponentInstance;
import oracle.soa.management.facade.Composite;
import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;
import oracle.soa.management.util.ComponentInstanceFilter;
import oracle.soa.management.util.CompositeInstanceFilter;
import oracle.soa.management.facade.CompositeInstance;
import oracle.soa.management.CompositeDN;
public class abortComposite {
public abortComposite() {
super();
}
public void abortRunningComposite() {
Locator locator = null;
Hashtable jndiProps = new Hashtable();
//Connection Details to Connect to Server
jndiProps.put(Context.PROVIDER_URL, "t3://hostname:portnumber/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
jndiProps.put(Context.SECURITY_CREDENTIALS, "password");
jndiProps.put("dedicated.connection", "true");
try {
//Connect to SOA Server
locator = LocatorFactory.createLocator(jndiProps);
System.out.println("Connected to SOA Server.");
java.util.List
CompositeInstanceFilter filter = new CompositeInstanceFilter();
//Set Minimum Creation Time
filter.setMinCreationDate(new java.util.Date("Tue Aug 10 13:22:02 PDT 2013"));
//Set Maximum Creation Time
filter.setMaxCreationDate(new java.util.Date("Tue Aug 30 13:22:02 PDT 2013"));
//Set for RUNNING State
filter.setState(0);
Composite composite=null;
List
//For each of the returned composite
for (CompositeDN compositeDN1 : compositeDN) {
composite = locator.lookupComposite(compositeDN1);
//Get composite instances by filter
obInstances = composite.getInstances(filter);
//for each of the returned composite instances
for (CompositeInstance instance : obInstances) {
System.out.println(" DN: " + instance.getCompositeDN() + " Instance: " + instance.getId() + " creation-date: " + instance.getCreationDate() + " state (" + instance.getState() + "): " + getStateAsString(instance.getState()));
//Set up a component filter
ComponentInstanceFilter cInstanceFilter = new ComponentInstanceFilter();
//Get child component instances
List
//For each child component instance
for (ComponentInstance cInstance : childComponentInstances) {
System.out.println(" -> componentinstance: " + cInstance.getComponentName() + " type: " + cInstance.getServiceEngine().getEngineType() + " state: " +getStateAsString(cInstance.getState()));
System.out.println("State: "+cInstance.getNormalizedStateAsString());
}
instance.abort();
}
obInstances=null;
}
}
catch (Exception e) {
System.out.println("Exception in API " + e);
}
}
private String getStateAsString(int state){
//Note that this is dependent on whether the composite state is captured or not
if (state == CompositeInstance.STATE_COMPLETED_SUCCESSFULLY)
return ("success");
else if (state == CompositeInstance.STATE_FAULTED)
return ("faulted");
else if (state == CompositeInstance.STATE_RECOVERY_REQUIRED)
return ("recovery required");
else if (state == CompositeInstance.STATE_RUNNING)
return ("running");
else if (state == CompositeInstance.STATE_STALE)
return ("stale");
else
return ("unknown");
}
public static void main(String[] args) {
abortComposite abortcomposite=new abortComposite();
abortcomposite.abortRunningComposite();
}
}
Steps:-
Set Classpath
export CLASSPATH=$CLASSPATH:$ORACLE_FMW_HOME/oracle_common/soa/modules/oracle.soa.mgmt_11.1.1/soa-infra-mgmt.jar:$ORACLE_FMW_HOME/oracle_common/modules/oracle.fabriccommon_11.1.1/fabric-common.jar:$ORACLE_FMW_HOME/wlserver_10.3/server/lib/weblogic.jar:$ORACLE_FMW_HOME/oracle_common/modules/oracle.jrf_11.1.1/jrf-api.jar
Compile the code
javac abortComposite.java
Execute the Code
java abortComposite
No comments:
Post a Comment