Java program to abort composites

Submitted by code_admin on Mon, 07/23/2018 - 09:30

The following java program will abort weblogic composites:

  1. import java.util.Hashtable;
  2. import java.util.List;
  3. import java.util.Date;
  4. import java.util.Calendar;
  5. import javax.naming.Context;
  6. import oracle.soa.management.facade.Component;
  7. import oracle.soa.management.facade.ComponentInstance;
  8. import oracle.soa.management.facade.Composite;
  9. import oracle.soa.management.facade.Locator;
  10. import oracle.soa.management.facade.LocatorFactory;
  11. import oracle.soa.management.util.ComponentInstanceFilter;
  12. import oracle.soa.management.util.CompositeInstanceFilter;
  13. import oracle.soa.management.facade.CompositeInstance;
  14. import oracle.soa.management.CompositeDN;
  15.  
  16. public class abort_running {
  17.         public abort_running() {
  18.             super();
  19.         }
  20.        
  21.         public void abortRunningComposite(String p_PROVIDER_URL) {
  22.         Locator locator = null;
  23.         Hashtable jndiProps = new Hashtable();
  24.         //Connection Details to Connect to Server
  25.  
  26.         System.out.println("Trying to connect to " + p_PROVIDER_URL);
  27.        
  28.         jndiProps.put(Context.PROVIDER_URL, p_PROVIDER_URL);
  29.         jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,  "weblogic.jndi.WLInitialContextFactory");
  30.         jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
  31.         jndiProps.put(Context.SECURITY_CREDENTIALS, "weblogic1");
  32.         jndiProps.put("dedicated.connection", "true");
  33.  
  34.         long num_aborted = 0;
  35.         long tot_instances = 0;
  36.         long num_instance = 0;
  37.         long display_interval = 20;
  38.         String prefix = "";
  39.        
  40.         try {
  41.                 //Connect to SOA Server
  42.                 locator = LocatorFactory.createLocator(jndiProps);
  43.                 System.out.println("Connected to SOA Server.");
  44.                 java.util.List compositeDN=locator.listComposites();
  45.                 CompositeInstanceFilter filter = new CompositeInstanceFilter();
  46.                
  47.                 Date start = new java.util.Date("Aug 4 00:00:01 GMT 2015");
  48.                
  49.                 Calendar cal = Calendar.getInstance();
  50.                 cal.setTime(start);
  51.                 cal.add(Calendar.DAY_OF_MONTH, 1); //delete for one full day
  52.                 Date end = cal.getTime();
  53.                
  54.                 System.out.println("Listing from " + start);
  55.                 System.out.println("Listing to " + end);
  56.                
  57.                 //Set Minimum Creation Time
  58.                 filter.setMinCreationDate(start);
  59.                 //Set Maximum Creation Time
  60.                 filter.setMaxCreationDate(end);
  61.                 //Set for RUNNING State
  62.                 filter.setState(0);
  63.                 Composite composite=null;
  64.                 List obInstances=null;
  65.                 //For each of the returned composite
  66.                 System.out.println("There were " + compositeDN.size() + " composites returned");
  67.                 for (Object RJMOBJ : compositeDN) {
  68.                     oracle.soa.management.CompositeDN compositeDN1 = (oracle.soa.management.CompositeDN) RJMOBJ;
  69.                     composite = locator.lookupComposite(compositeDN1);
  70.                         //System.out.println("Outer Loop");
  71.                         //Get composite instances by filter
  72.                         obInstances = composite.getInstances(filter);
  73.                         //for each of the returned composite instances
  74.                         tot_instances = obInstances.size();
  75.                         display_interval = 20;
  76.                         if (tot_instances<10000) display_interval = 20;
  77.                         if (tot_instances<5000) display_interval = 10;
  78.                         if (tot_instances<1000) display_interval = 5;
  79.                         if (tot_instances<100) display_interval = 1;
  80.                         if (tot_instances>0) {
  81.                             System.out.println("  " + compositeDN1.getCompositeName() + " has " + obInstances.size() + " instances");
  82.                             System.out.println("Displaying every " + display_interval);
  83.                         };
  84.                         num_instance = 0;
  85.                         for (Object RJMOBJ2 : obInstances) {
  86.                                 num_instance++;
  87.                                 oracle.soa.management.facade.CompositeInstance instance = (oracle.soa.management.facade.CompositeInstance) RJMOBJ2;
  88.                                 if ((num_instance % display_interval)==0) {
  89.                                     prefix = compositeDN1.getCompositeName() + "(" + num_instance + "/" + tot_instances + ")";
  90.                                     System.out.println(prefix + " DN: " + instance.getCompositeDN() + " Instance: " + instance.getId() + " creation-date: " + instance.getCreationDate() + " state (" + instance.getState() + "): " + getStateAsString(instance.getState()));
  91.                                 }
  92.                                 //Set up a component filter
  93.                                 ComponentInstanceFilter cInstanceFilter = new ComponentInstanceFilter();
  94.                                 //Get child component instances
  95.                                 List childComponentInstances = instance.getChildComponentInstances(cInstanceFilter);
  96.                                 //For each child component instance
  97.                                     /*for (Object RJMOBJ3 : childComponentInstances) {
  98.                                         oracle.soa.management.facade.ComponentInstance cInstance = (oracle.soa.management.facade.ComponentInstance) RJMOBJ3;
  99.                                         System.out.println(prefix + "  -> componentinstance: " + cInstance.getComponentName() + " type: " + cInstance.getServiceEngine().getEngineType() + " state: " +getStateAsString(cInstance.getState()));
  100.                                         System.out.println(prefix + "  State: "+cInstance.getNormalizedStateAsString());
  101.                                     }*/
  102.                                     instance.abort();
  103.                                     num_aborted++;
  104.                                 }
  105.                                 obInstances=null;
  106.                                
  107.                 } //for
  108.                
  109.         } catch (Exception e) {
  110.             System.out.println("Exception in API " + e);
  111.         }
  112.        
  113.         System.out.println("Number aborder = " + num_aborted);
  114.        
  115.         }
  116.         private String getStateAsString(int state){
  117.                 //Note that this is dependent on whether the composite state is captured or not
  118.                 if (state == CompositeInstance.STATE_COMPLETED_SUCCESSFULLY)
  119.                         return ("success");
  120.                 else if (state == CompositeInstance.STATE_FAULTED)
  121.                         return ("faulted");
  122.                 else if (state == CompositeInstance.STATE_RECOVERY_REQUIRED)
  123.                         return ("recovery required");
  124.                 else if (state == CompositeInstance.STATE_RUNNING)
  125.                         return ("running");
  126.                 else if (state == CompositeInstance.STATE_STALE)
  127.                         return ("stale");
  128.                 else
  129.                         return ("unknown");
  130.         }
  131.  
  132.         public static void main(String[] args) {
  133.             System.out.println("Start abort_running");
  134.             String PROVIDER_URL_ADMIN = "";
  135.             String PROVIDER_URL_SOA1 = "";
  136.             String PROVIDER_URL_SOA2 = "";
  137.             PROVIDER_URL_ADMIN = "t3://devsoavip1.ad.ic.ac.uk:7001/soa-infra";
  138.             PROVIDER_URL_SOA1 = "t3://devsoavip2.ad.ic.ac.uk:8001/soa-infra";
  139.             PROVIDER_URL_SOA2 = "t3://devsoavip3.ad.ic.ac.uk:8001/soa-infra";
  140.            
  141.             abort_running  abortcomposite=new abort_running();
  142.             abortcomposite.abortRunningComposite(PROVIDER_URL_SOA1);
  143.             System.out.println("End abort_running");
  144.         }
  145. }

Sql to watch abort process (Run as DSVSOAINFRA)

  1. select
  2.   trunc(created_time), count('x'), min(created_time), max(created_time)
  3. from composite_instance
  4. where state=0
  5. --and trunc(created_time) = trunc(to_date('05-AUG-2015','DD-MON-YYYY'))
  6. group by trunc(created_time)
  7. order by trunc(created_time)
  8. ;
RJM Article Type
Work Notes