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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 10 10:30:37 EST 2007


Author: AlexFu.Novell
Date: 2007-12-10 10:30:37 -0500 (Mon, 10 Dec 2007)
New Revision: 68109

Modified:
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicy.java
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java
   trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonElectionPolicyTestCase.java
   trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml
Log:
JBAS-4228: Preferred server HASingletonElectionPolicy

Modified: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicy.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicy.java	2007-12-10 15:04:52 UTC (rev 68108)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicy.java	2007-12-10 15:30:37 UTC (rev 68109)
@@ -27,6 +27,16 @@
    HAPartition getHAPartition();
 
    /**
+    * Sets the preferred master node. As long as the preferred master node
+    * presents in the cluster, it will be always selected as master node,
+    * no matter what the election policy is.
+    * @param node String format of ip_address:port_number
+    */
+   void setPreferredMaster(String node);
+   
+   String getPreferredMaster();
+   
+   /**
     * Return the elected master node.
     * @return the master node
     */

Modified: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java	2007-12-10 15:04:52 UTC (rev 68108)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java	2007-12-10 15:30:37 UTC (rev 68109)
@@ -21,10 +21,8 @@
  */
 package org.jboss.ha.singleton;
 
-
+import org.jboss.ha.framework.interfaces.ClusterNode;
 import org.jboss.ha.framework.interfaces.HAPartition;
-import org.jboss.ha.framework.server.ClusterPartition;
-import org.jboss.logging.Logger;
 import org.jboss.system.ServiceMBeanSupport;
 
 /**
@@ -40,6 +38,7 @@
 {
    private Object mManagedSingleton;
    private HAPartition mPartition;
+   private String mPreferredMaster;
    
    /**
     * @see HASingletonElectionPolicyMBean#setManagedSingleton(Object)
@@ -58,6 +57,22 @@
    }
 
    /**
+    * @see HASingletonElectionPolicyMBean#setPreferredMaster(ClusterNode)
+    */
+   public void setPreferredMaster(String node)
+   {
+       this.mPreferredMaster = node;
+   }
+   
+   /**
+    * @see HASingletonElectionPolicyMBean#getPreferredMaster()
+    */
+   public String getPreferredMaster()
+   {
+       return this.mPreferredMaster;
+   }
+   
+   /**
     * @see HASingletonElectionPolicyMBean#setHAPartition(HAPartition)
     */
    public void setHAPartition(HAPartition partition)
@@ -94,4 +109,37 @@
 
       return pickSingleton(partition).equals(partition.getClusterNode());
    }
+   
+   /**
+    * @see HASingletonElectionPolicyMBean#pickSingleton()
+    */
+   public  ClusterNode pickSingleton()
+   {
+       if (null == this.mPartition)
+           throw new IllegalStateException("HAPartition is not set");
+       
+       return pickSingleton(this.mPartition);
+   }
+   
+   /**
+    * @see HASingletonElectionPolicyMBean#pickSingleton(HAPartition)
+    */
+   public ClusterNode pickSingleton(HAPartition partition) 
+   {
+       if (null == partition)
+           throw new IllegalStateException("parameter cannot be null");
+
+       // If preferred master is defined and contained in cluster, return it
+       if (null != this.mPreferredMaster) {
+           ClusterNode[] nodes = partition.getClusterNodes();
+           for (int i = 0; i < nodes.length; i++) {
+               if (nodes[i].getName().equals(this.mPreferredMaster))
+                   return nodes[i];
+           }
+       }
+       // Preferred master is not available, election policy is in effect
+       return elect(partition);    
+   }
+   
+   protected abstract ClusterNode elect(HAPartition partition);
 }

Modified: trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java	2007-12-10 15:04:52 UTC (rev 68108)
+++ trunk/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java	2007-12-10 15:30:37 UTC (rev 68109)
@@ -71,13 +71,8 @@
       return this.mPosition;
    }
 
-   public ClusterNode pickSingleton()
+   protected ClusterNode elect(HAPartition partition) 
    {
-      return pickSingleton(getHAPartition());
-   }
-   
-   public ClusterNode pickSingleton(HAPartition partition) 
-   {
       ClusterNode[] nodes = partition.getClusterNodes();
       
       int size = nodes.length;

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonElectionPolicyTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonElectionPolicyTestCase.java	2007-12-10 15:04:52 UTC (rev 68108)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonElectionPolicyTestCase.java	2007-12-10 15:30:37 UTC (rev 68109)
@@ -112,6 +112,22 @@
          assertEquals(Boolean.FALSE, n2);
       }
       
+      // 5th policy is the oldest (position = 0), preferredMaster is set to 127.0.0.1:1099
+      // 6th policy is the youngest (position = -1), preferredMaster is set to 127.0.0.1:1099
+      // So the master node of example 5 and 6 should be the same - the preferred master
+      {
+          ObjectName mbean5 = new ObjectName("jboss.examples:service=HASingletonMBeanExample_5");
+          ObjectName mbean6 = new ObjectName("jboss.examples:service=HASingletonMBeanExample_6");
+
+          Boolean n51 = (Boolean)adaptors[0].getAttribute(mbean5, "MasterNode");
+          Boolean n61 = (Boolean)adaptors[0].getAttribute(mbean6, "MasterNode");
+          Boolean n52 = (Boolean)adaptors[size - 1].getAttribute(mbean5, "MasterNode");
+          Boolean n62 = (Boolean)adaptors[size - 1].getAttribute(mbean6, "MasterNode");
+          
+          assertEquals(n51, n61);
+          assertEquals(n52, n62);
+       }
+       
       return;
    }
    
@@ -140,6 +156,12 @@
       exampleNumber = 4;
       shouldHaveHaSingletonDeployed(namingUrls[0], exampleNumber);
       shouldNotHaveHaSingletonDeployed(namingUrls[size - 1], exampleNumber);
+      
+      // 6th policy is the youngest (position = -1)
+      // however, preferred master is set to 127.0.0.1:1099 (which is the 1st node)
+      exampleNumber = 6;
+      shouldHaveHaSingletonDeployed(namingUrls[0], exampleNumber);
+      shouldNotHaveHaSingletonDeployed(namingUrls[size - 1], exampleNumber);
    }
    
    private void shouldHaveHaSingletonDeployed(String namingUrl, int exampleNumber) throws Exception

Modified: trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml
===================================================================
--- trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml	2007-12-10 15:04:52 UTC (rev 68108)
+++ trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml	2007-12-10 15:30:37 UTC (rev 68109)
@@ -96,6 +96,55 @@
       <property name="targetStopMethodArgument">true</property>
    </bean>
    
+   <!-- 5th HASingleton, PreferredMaster set to localhost:0. Election policy is to choose the oldest node as master -->
+   <bean class="org.jboss.ha.singleton.examples.HASingletonMBeanExample" 
+          name="HASingletonMBeanExample_5">
+      <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.examples:service=HASingletonMBeanExample_5", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
+   </bean>
+
+   <bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
+          name="HASingletonElectionPolicySimple_5">
+     <property name="position">0</property>
+     <property name="preferredMaster">127.0.0.1:1099</property>
+   </bean>
+
+   <bean class="org.jboss.ha.singleton.HASingletonController" 
+          name="HASingletonController_5">
+      
+      <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:service=HASingletonController_5", exposedInterface=org.jboss.ha.singleton.HASingletonControllerMBean.class, registerDirectly=true)</annotation>       
+      
+      <property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
+      <property name="electionPolicy"><inject bean="HASingletonElectionPolicySimple_5"/></property>
+      <property name="target"><inject bean="HASingletonMBeanExample_5"/></property>
+      <property name="targetStartMethod">startSingleton</property>
+      <property name="targetStopMethod">stopSingleton</property>
+      <property name="targetStopMethodArgument">true</property>
+   </bean>
+
+   <!-- 6th HASingleton, PreferredMaster set to localhost:0. Election policy is to choose the youngest node as master -->
+   <bean class="org.jboss.ha.singleton.examples.HASingletonMBeanExample" 
+          name="HASingletonMBeanExample_6">
+      <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.examples:service=HASingletonMBeanExample_6", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
+   </bean>
+
+   <bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
+          name="HASingletonElectionPolicySimple_6">
+     <property name="position">-1</property>
+     <property name="preferredMaster">127.0.0.1:1099</property>
+   </bean>
+
+   <bean class="org.jboss.ha.singleton.HASingletonController" 
+          name="HASingletonController_6">
+      
+      <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:service=HASingletonController_6", exposedInterface=org.jboss.ha.singleton.HASingletonControllerMBean.class, registerDirectly=true)</annotation>       
+      
+      <property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
+      <property name="electionPolicy"><inject bean="HASingletonElectionPolicySimple_6"/></property>
+      <property name="target"><inject bean="HASingletonMBeanExample_6"/></property>
+      <property name="targetStartMethod">startSingleton</property>
+      <property name="targetStopMethod">stopSingleton</property>
+      <property name="targetStopMethodArgument">true</property>
+   </bean>
    <!-- ==================================================================== -->
    <!-- Pojo style HA singleton election definition                          -->
    <!-- ==================================================================== -->
@@ -162,6 +211,22 @@
       <property name="targetStartMethod">startSingleton</property>
       <property name="targetStopMethod">stopSingleton</property>
    </bean>   
+
+   <!-- 6th HASingleton, Election policy is to choose the youngest node as master -->
+   <bean class="org.jboss.ha.singleton.examples.HASingletonPojoExample" 
+         name="HASingletonPojoExample_6">
+      <constructor><parameter>test/cluster/hasingleton/simplepojo/6</parameter></constructor>
+   </bean>
+
+   <bean class="org.jboss.ha.singleton.HASingletonController" 
+          name="HASingletonControllerForBean_6">
+          
+      <property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
+      <property name="electionPolicy"><inject bean="HASingletonElectionPolicySimple_6"/></property>
+      <property name="target"><inject bean="HASingletonPojoExample_6"/></property>
+      <property name="targetStartMethod">startSingleton</property>
+      <property name="targetStopMethod">stopSingleton</property>
+   </bean>
       
    <bean name="ElectionPolicyTestCacheConfig" 
    		class="org.jboss.cache.config.Configuration">




More information about the jboss-cvs-commits mailing list