[jboss-cvs] JBossAS SVN: r89851 - in trunk: testsuite/src/main/org/jboss/test/cluster/defaultcfg/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jun 4 18:14:47 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-06-04 18:14:47 -0400 (Thu, 04 Jun 2009)
New Revision: 89851

Modified:
   trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
   trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/ClusterPartitionManagedObjectsTestCase.java
Log:
[JBAS-6094] Expose DRM ManagedOperations via ClusterPartition

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2009-06-04 20:26:39 UTC (rev 89850)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/ClusterPartition.java	2009-06-04 22:14:47 UTC (rev 89851)
@@ -31,8 +31,10 @@
 import java.net.InetAddress;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.Vector;
@@ -57,8 +59,8 @@
 import org.jboss.managed.api.annotation.ManagementComponent;
 import org.jboss.managed.api.annotation.ManagementObject;
 import org.jboss.managed.api.annotation.ManagementObjectID;
-import org.jboss.managed.api.annotation.ManagementObjectRef;
 import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementParameter;
 import org.jboss.managed.api.annotation.ManagementProperties;
 import org.jboss.managed.api.annotation.ManagementProperty;
 import org.jboss.managed.api.annotation.ViewUse;
@@ -104,10 +106,7 @@
 @ManagementObject(componentType=@ManagementComponent(type="MCBean", subtype="HAPartition"),
                   properties=ManagementProperties.CLASS_AND_EXPLICIT,
                   classProperties={@ManagementProperty(name="stateString",use={ViewUse.STATISTIC})},
-                  operations={@ManagementOperation(name="create",description="Bring the service to the CREATED state",impact=Impact.WriteOnly),
-                              @ManagementOperation(name="start",description="Bring the service to the STARTED state",impact=Impact.WriteOnly),
-                              @ManagementOperation(name="stop",description="Bring the service to the STOPPED state",impact=Impact.WriteOnly),
-                              @ManagementOperation(name="destroy",description="Bring the service to the DESTROYED state",impact=Impact.WriteOnly)})
+                  isRuntime=true)
 public class ClusterPartition
    extends ServiceMBeanSupport
    implements ExtendedMembershipListener, HAPartition,
@@ -1768,25 +1767,23 @@
       return Version.description + "( " + Version.cvs + ")";
    }
    
-   @ManagementProperty(name="distributedReplicantManager", use={ViewUse.STATISTIC}, description="The DistributedReplicantManager")
-   @ManagementObjectRef(type="DistributedReplicantManager")
-   public String getDRMName()
-   {
-      return getPartitionName();
-   }
+//   @ManagementProperty(name="distributedReplicantManager", use={ViewUse.STATISTIC}, description="The DistributedReplicantManager")
+//   @ManagementObjectRef(type="DistributedReplicantManager")
+//   public String getDRMName()
+//   {
+//      return getPartitionName();
+//   }
    
    public DistributedReplicantManagerImpl getDistributedReplicantManagerImpl()
    {
       return this.replicantManager;
    }
 
-   // FIXME -- Make this a @ManagementProperty
    public ChannelFactory getChannelFactory()
    {
       return this.channelFactory;
    }
 
-   // FIXME -- Make this a @ManagementProperty
    public HAPartitionCacheHandler getCacheHandler()
    {
       return this.cacheHandler;
@@ -1857,6 +1854,57 @@
       super.unsetKernelControllerContext(controllerContext);
       this.kernelControllerContext = null;
    }
+   
+   // ManagedObject interface for DRM ---------------------------------------
+   
+   @ManagementOperation(description="List all known DistributedReplicantManager keys and the nodes that have registered bindings",
+         impact=Impact.ReadOnly)
+   public String listDRMContent() throws Exception
+   {
+      return this.replicantManager == null ? null : this.replicantManager.listContent();
+   }
+   
+   @ManagementOperation(description="List in XML format all known DistributedReplicantManager keys and the nodes that have registered bindings",
+         impact=Impact.ReadOnly)
+   public String listDRMContentAsXml() throws Exception
+   {
+      return this.replicantManager == null ? null : this.replicantManager.listXmlContent();
+   }
+   
+   @ManagementOperation(description="Returns the names of the nodes that have registered objects with the DistributedReplicantManager under the given key",
+                        impact=Impact.ReadOnly,
+                        params={@ManagementParameter(name="key",
+                                                     description="The name of the service")})
+   @SuppressWarnings("deprecation")
+   public List<String> lookupDRMNodeNames(String key)
+   {
+      return this.replicantManager == null ? null : this.replicantManager.lookupReplicantsNodeNames(key);
+   }
+   
+   @ManagementOperation(description="Returns a hash of the list of nodes that " +
+                                    "have registered an object with the DistributedReplicantManager under  the given key",
+                        impact=Impact.ReadOnly,
+                        params={@ManagementParameter(name="key",
+                                                     description="The name of the service")})
+   public int getDRMServiceViewId(String key)
+   {
+      return this.replicantManager == null ? null : this.replicantManager.getReplicantsViewId(key);
+   }
+   
+   @ManagementOperation(description="Returns whether the DistributedReplicantManager considers this node to be the master for the given service",
+         impact=Impact.ReadOnly,
+         params={@ManagementParameter(name="key", description="The name of the service")})
+   public boolean isDRMMasterForService(String key)
+   {
+      return this.replicantManager == null ? null : this.replicantManager.isMasterReplica(key);
+   }
+   
+   @ManagementOperation(description="Get a collection of the names of all keys for which the DistributedReplicantManager has bindings",
+         impact=Impact.ReadOnly)
+   public Collection<String> getDRMServiceNames()
+   {
+      return this.replicantManager == null ? null : this.replicantManager.getAllServices();
+   }
 
    // Protected --------------------------------------------------------------
       

Modified: trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java	2009-06-04 20:26:39 UTC (rev 89850)
+++ trunk/cluster/src/main/org/jboss/ha/framework/server/DistributedReplicantManagerImpl.java	2009-06-04 22:14:47 UTC (rev 89851)
@@ -44,15 +44,15 @@
 import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
 import org.jboss.ha.framework.interfaces.HAPartition;
 import org.jboss.logging.Logger;
-import org.jboss.managed.api.ManagedOperation.Impact;
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementObjectID;
-import org.jboss.managed.api.annotation.ManagementOperation;
-import org.jboss.managed.api.annotation.ManagementParameter;
-import org.jboss.managed.api.annotation.ManagementProperties;
-import org.jboss.managed.api.annotation.ManagementProperty;
-import org.jboss.managed.api.annotation.ViewUse;
+//import org.jboss.managed.api.ManagedOperation.Impact;
+//import org.jboss.managed.api.annotation.ManagementComponent;
+//import org.jboss.managed.api.annotation.ManagementObject;
+//import org.jboss.managed.api.annotation.ManagementObjectID;
+//import org.jboss.managed.api.annotation.ManagementOperation;
+//import org.jboss.managed.api.annotation.ManagementParameter;
+//import org.jboss.managed.api.annotation.ManagementProperties;
+//import org.jboss.managed.api.annotation.ManagementProperty;
+//import org.jboss.managed.api.annotation.ViewUse;
 
 
 /**
@@ -65,7 +65,6 @@
  * @author  <a href="mailto:pferraro at redhat.com">Paul Ferraro</a>
  * @version $Revision$
  */
- at ManagementObject(isRuntime=true, properties=ManagementProperties.EXPLICIT)
 public class DistributedReplicantManagerImpl
    implements DistributedReplicantManagerImplMBean,
               HAPartition.HAMembershipExtendedListener,
@@ -197,8 +196,8 @@
       return new ObjectName("jboss:service=" + SERVICE_NAME + ",partition=" + this.partition.getPartitionName());
    }
    
-   @ManagementProperty(use={ViewUse.STATISTIC}, description="The partition's name")
-   @ManagementObjectID(type="HAPartition")
+//   @ManagementProperty(use={ViewUse.STATISTIC}, description="The partition's name")
+//   @ManagementObjectID(type="DistributedReplicantManager")
    public String getPartitionName()
    {
       return this.partition.getPartitionName();
@@ -209,9 +208,9 @@
 //      this.partition = clusterPartition;
 //   }
    
-   @ManagementOperation(name="listDRMContent",
-         description="List all known keys and the nodes that have registered bindings",
-         impact=Impact.ReadOnly)
+//   @ManagementOperation(name="listDRMContent",
+//         description="List all known keys and the nodes that have registered bindings",
+//         impact=Impact.ReadOnly)
    public String listContent() throws Exception
    {
       StringBuilder result = new StringBuilder();
@@ -255,9 +254,9 @@
       return result.toString();
    }
    
-   @ManagementOperation(name="listDRMContentAsXml",
-         description="List in XML format all known services and the nodes that have registered bindings",
-         impact=Impact.ReadOnly)
+//   @ManagementOperation(name="listDRMContentAsXml",
+//         description="List in XML format all known services and the nodes that have registered bindings",
+//         impact=Impact.ReadOnly)
    public String listXmlContent() throws Exception
    {
       StringBuilder result = new StringBuilder();
@@ -350,9 +349,9 @@
       new MembersPublisher().start();
    }
       
-   @ManagementOperation(name="getAllDRMServices",
-         description="Get a collection of the names of all keys for which we have bindings",
-         impact=Impact.ReadOnly)
+//   @ManagementOperation(name="getAllDRMServices",
+//         description="Get a collection of the names of all keys for which we have bindings",
+//         impact=Impact.ReadOnly)
    public Collection<String> getAllServices()
    {
       Set<String> services = new HashSet<String>();
@@ -524,13 +523,13 @@
       
       return result;
    }
-   
+
+//   @ManagementOperation(name="lookupDRMNodeNames",
+//         description="Returns the names of the nodes that have registered objects under the given key",
+//                        impact=Impact.ReadOnly,
+//                        params={@ManagementParameter(name="key",
+//                                                     description="The name of the service")})
    @Deprecated
-   @ManagementOperation(name="lookupDRMNodeNames",
-         description="Returns the names of the nodes that have registered objects under the given key",
-                        impact=Impact.ReadOnly,
-                        params={@ManagementParameter(name="key",
-                                                     description="The name of the service")})
    public List<String> lookupReplicantsNodeNames(String key)
    {
       List<ClusterNode> nodes = this.lookupReplicantsNodes(key);
@@ -599,12 +598,12 @@
       }
    }
    
-   @ManagementOperation(name="getDRMServiceViewId",
-         description="Returns a hash of the list of nodes that " +
-   		                            "have registered an object for the given key",
-   		                impact=Impact.ReadOnly,
-                        params={@ManagementParameter(name="key",
-                                                     description="The name of the service")})
+//   @ManagementOperation(name="getDRMServiceViewId",
+//         description="Returns a hash of the list of nodes that " +
+//   		                            "have registered an object for the given key",
+//   		                impact=Impact.ReadOnly,
+//                        params={@ManagementParameter(name="key",
+//                                                     description="The name of the service")})
    public int getReplicantsViewId(String key)
    {
       Integer result = this.intraviewIdCache.get(key);
@@ -612,10 +611,10 @@
       return (result != null) ? result.intValue() : 0;
    }
    
-   @ManagementOperation(name="isDRMMasterForService",
-         description="Returns whether the DRM considers this node to be the master for the given service",
-         impact=Impact.ReadOnly,
-         params={@ManagementParameter(name="key", description="The name of the service")})
+//   @ManagementOperation(name="isDRMMasterForService",
+//         description="Returns whether the DRM considers this node to be the master for the given service",
+//         impact=Impact.ReadOnly,
+//         params={@ManagementParameter(name="key", description="The name of the service")})
    public boolean isMasterReplica(String key)
    {
       if (this.log.isTraceEnabled())
@@ -643,6 +642,7 @@
          return true;
       }
 
+      @SuppressWarnings("unchecked")
       Vector<String> allNodes = this.partition.getCurrentView();
       for (String node: allNodes)
       {
@@ -967,6 +967,7 @@
                
                Object[] objs = (Object[]) o;
                String node = (String) objs[0];
+               @SuppressWarnings("unchecked")
                Map<String, Serializable> replicants = (Map<String, Serializable>) objs[1];
                
                //FIXME: We don't remove keys in the merge process but only add new keys!

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/ClusterPartitionManagedObjectsTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/ClusterPartitionManagedObjectsTestCase.java	2009-06-04 20:26:39 UTC (rev 89850)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/ClusterPartitionManagedObjectsTestCase.java	2009-06-04 22:14:47 UTC (rev 89851)
@@ -21,6 +21,7 @@
  */
 package org.jboss.test.cluster.defaultcfg.test;
 
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
@@ -35,6 +36,10 @@
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.managed.api.ManagedOperation;
 import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
 import org.jboss.profileservice.spi.ProfileService;
 import org.jboss.test.JBossClusteredTestCase;
 import org.jboss.virtual.VFS;
@@ -48,6 +53,8 @@
 public class ClusterPartitionManagedObjectsTestCase
    extends JBossClusteredTestCase
 {
+   private static final String HAJNDI = "HAJNDI";
+   
    protected ManagementView activeView;
    private String partitionName = System.getProperty("jbosstest.partitionName", "DefaultPartition");
 
@@ -74,26 +81,84 @@
       assertEquals("HAPartition", mc.getNameType());
       assertEquals("DefaultPartition", mc.getName());
       
-      Set<String> operationNames = new HashSet<String>();
+      Map<String, ManagedOperation> operations = new HashMap<String, ManagedOperation>();
       getLog().debug(mc);
       for (ManagedOperation mo : mc.getOperations())
       {
          getLog().debug("name="+mo.getName()+",description="+mo.getDescription()+",impact="+mo.getImpact());
-         operationNames.add(mo.getName());
+         operations.put(mo.getName(), mo);
       }
       
-      assertTrue("HAPartition has showHistoryAsXML", operationNames.contains("showHistoryAsXML"));      
-      assertTrue("HAPartition has showHistory", operationNames.contains("showHistory"));       
+      ManagedOperation mgdop = operations.get("showHistory");
+      assertNotNull("HAPartition has showHistory", mgdop); 
+      MetaValue result = mgdop.invoke();
+      assertNotNull(result);
+      
+      mgdop = operations.get("showHistoryAsXML");
+      assertNotNull("HAPartition has showHistoryAsXML", mgdop); 
+      result = mgdop.invoke();
+      assertNotNull(result);
+      
+      mgdop = operations.get("getDRMServiceNames");
+      assertNotNull("HAPartition has getDRMServiceNames", mgdop);
+      result = mgdop.invoke();
+      assertTrue(result instanceof CollectionValue);
+      MetaValue[] elements = ((CollectionValue) result).getElements();
+      assertNotNull(elements);
+      boolean found = false;
+      for (MetaValue element : elements)
+      {
+         assertTrue(element instanceof SimpleValue);
+         if (HAJNDI.equals(((SimpleValue) element).getValue()))
+         {
+            found = true;
+            break;
+         }
+      }
+      assertTrue(found);
+      
+      mgdop = operations.get("listDRMContent");      
+      assertNotNull("HAPartition has listDRMContent", mgdop); 
+      result = mgdop.invoke();
+      assertTrue(result instanceof SimpleValue);
+      Object val = ((SimpleValue) result).getValue();
+      assertTrue(val instanceof String);
+      assertTrue(((String) val).indexOf(HAJNDI) > -1);
+      
+      mgdop = operations.get("listDRMContentAsXml");
+      assertNotNull("HAPartition has listDRMContentAsXml", mgdop); 
+      result = mgdop.invoke();
+      assertTrue(result instanceof SimpleValue);
+      val = ((SimpleValue) result).getValue();
+      assertTrue(val instanceof String);
+      assertTrue(((String) val).indexOf(HAJNDI) > -1);
+      
+      mgdop = operations.get("getDRMServiceViewId");
+      assertNotNull("HAPartition has getDRMServiceViewId", mgdop);  
+      MetaValue hajndiparam = SimpleValueSupport.wrap(HAJNDI);
+      MetaValue[] hajndiparams = new MetaValue[]{hajndiparam}; 
+      result = mgdop.invoke(hajndiparams);
+      assertNotNull(result);
+      
+      mgdop = operations.get("lookupDRMNodeNames");
+      assertNotNull("HAPartition has lookupDRMNodeNames", mgdop);
+      result = mgdop.invoke(hajndiparams);
+      assertTrue(result instanceof CollectionValue);
+      elements = ((CollectionValue) result).getElements();
+      assertNotNull(elements);
+      assertEquals(2, elements.length);
+      
+      mgdop = operations.get("isDRMMasterForService");
+      assertNotNull("HAPartition has isDRMMasterForService", mgdop); 
+      result = mgdop.invoke(hajndiparams);
+      assertTrue(result instanceof SimpleValue);
+      val = ((SimpleValue) result).getValue();
+      assertTrue(val instanceof Boolean);
+      
       // FIXME test for service lifecycle
-      // FIXME test for DRM operations pseudo-name defined via @ManagementProperty.name  
-//      assertTrue("HAPartition has getAllDRMServices", operationNames.contains("getAllDRMServices"));      
-//      assertTrue("HAPartition has listDRMContentAsXml", operationNames.contains("listDRMContentAsXml")); 
-//      assertTrue("HAPartition has getDRMServiceViewId", operationNames.contains("getDRMServiceViewId"));      
-//      assertTrue("HAPartition has lookupDRMNodeNames", operationNames.contains("lookupDRMNodeNames"));
-//      assertTrue("HAPartition has listDRMContent", operationNames.contains("listDRMContent"));     
-//      assertTrue("HAPartition has isDRMMasterForService", operationNames.contains("isDRMMasterForService"));
-      assertEquals("Correct number of operations", 8, operationNames.size());
       
+      assertEquals("Correct number of operations", 8, operations.size());
+      
       for (Map.Entry<String, ManagedProperty> entry : mc.getProperties().entrySet())
       {
          getLog().debug(entry.getKey() + " == " + entry.getValue());
@@ -103,7 +168,105 @@
             getLog().debug(entry.getKey() + " -- ManagedObject == " + mo);
          }
       }
-      // FIXME validate the properties
+      
+      ManagedProperty prop = mc.getProperty("stateString");
+      assertNotNull("HAPartition has property stateString", prop);
+      MetaValue metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof String);
+      
+      prop = mc.getProperty("nodeName");
+      assertNotNull("HAPartition has property nodeName", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof String);
+      
+      prop = mc.getProperty("partitionName");
+      assertNotNull("HAPartition has property partitionName", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof String);
+      
+      prop = mc.getProperty("currentViewId");
+      assertNotNull("HAPartition has property currentViewId", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof Long);
+      
+      prop = mc.getProperty("currentView");
+      assertNotNull("HAPartition has property currentView", prop);
+      
+      prop = mc.getProperty("currentNodeCoordinator");
+      assertNotNull("HAPartition has property currentNodeCoordinator", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof Boolean);
+      
+      prop = mc.getProperty("allowSynchronousMembershipNotifications");
+      assertNotNull("HAPartition has property allowSynchronousMembershipNotifications", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof Boolean);
+      
+      prop = mc.getProperty("bindIntoJndi");
+      assertNotNull("HAPartition has property bindIntoJndi", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof Boolean);
+      
+      prop = mc.getProperty("JGroupsVersion");
+      assertNotNull("HAPartition has property JGroupsVersion", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof String);
+      
+      prop = mc.getProperty("cacheConfigName");
+      assertNotNull("HAPartition has property cacheConfigName", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof String);
+      
+      prop = mc.getProperty("channelStackName");
+      assertNotNull("HAPartition has property channelStackName", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof String);
+      
+      prop = mc.getProperty("stateTransferTimeout");
+      assertNotNull("HAPartition has property stateTransferTimeout", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof Long);
+      
+      prop = mc.getProperty("methodCallTimeout");
+      assertNotNull("HAPartition has property methodCallTimeout", prop);
+      metaVal = prop.getValue();
+      assertTrue(metaVal instanceof SimpleValue);
+      val = ((SimpleValue) metaVal).getValue();
+      assertNotNull(val);
+      assertTrue(val instanceof Long);
    }
 
    /**




More information about the jboss-cvs-commits mailing list