[Clustering/JBoss] - HASingletonElectionPolicy
by smeng@unique
I have setup 2 nodes (say Node A and B) in a cluster using Jboss 4.2.2 GA.
My requirement is:
1. Node A is set as the preferred master. If both nodes are running, Node A will always become the master i.e. in the event Node B was started before Node A, it will stop the service and Node A will take over running as the master.
2. If the master node goes down, then the next available node in the cluster becomes the master.
My problem is:
When Nodes A & B are running, Node A as master, and Node A is properly shutdown, Node B still detects Node A in the cluster view and continues to elect Node A as the master rather than taking over.
Here is my HASingletonElectionPolicy implementation:
package com.unique.ha.singleton;
|
| import org.apache.commons.logging.Log;
| import org.apache.commons.logging.LogFactory;
| import org.jboss.ha.framework.interfaces.ClusterNode;
| import org.jboss.ha.framework.interfaces.HAPartition;
| import org.jboss.ha.singleton.HASingletonElectionPolicySimple;
|
| public class HASingletonElectionPolicyUnique extends HASingletonElectionPolicySimple
| implements HASingletonElectionPolicyUniqueMBean {
|
| private String preferredMasterAddress;
|
| private static final Log log = LogFactory.getLog(HASingletonElectionPolicyUnique.class);
|
| public void setPreferredMasterAddress(String preferredMasterAddress) {
|
| this.preferredMasterAddress = preferredMasterAddress;
| }
|
| public String getPreferredMasterAddress() {
|
| return this.preferredMasterAddress;
| }
|
| public ClusterNode pickSingleton() {
|
| return pickSingleton(getHAPartition());
| }
|
| public ClusterNode pickSingleton(HAPartition partition) {
|
| log.info( "Running HASingletonElectionPolicyUnique..." );
|
| ClusterNode[] nodes = partition.getClusterNodes();
| log.info( "CurrentView for " + partition.getPartitionName() + " is " + partition.getCurrentView().toString() );
|
| if( this.preferredMasterAddress != null ) {
|
| for ( int x=0; x < nodes.length; x++ ) {
|
| ClusterNode node = nodes[x];
|
| if ( node.getIpAddress().getHostAddress().equals( this.preferredMasterAddress ) ) {
|
| log.info("Set Master Status to preferred master address " + this.preferredMasterAddress);
| return node;
| }
| }
| }
|
| log.warn("Unable to select preferred Master at address " +
| this.preferredMasterAddress + ". Will select next available node.");
|
| return super.pickSingleton(partition);
| }
|
|
| }
|
jboss-service.xml
<server>
|
| <mbean code="com.unique.ha.singleton.HASingletonElectionPolicyUnique"
| name="com.unique.ha:name=HASingletonElectionPolicyUnique">
| <attribute name="PreferredMasterAddress">${unique.ha.preferred_master_address}</attribute>
| </mbean>
|
| <mbean code="com.unique.system.mbean.MyService"
| name="com.unique.system.mbean:name=MyService">
| </mbean>
|
| <mbean code="org.jboss.ha.singleton.HASingletonController"
| name="com.unique.system.mbean:service=MyService-HASingletonController">
| <depends>jboss:service=${jboss.partition.name}</depends>
| <depends optional-attribute-name="ElectionPolicy" proxy-type="attribute">com.unique.ha:name=HASingletonElectionPolicyUnique</depends>
| <depends optional-attribute-name="TargetName">com.unique.system.mbean:name=MyService</depends>
| <attribute name="PartitionName">${jboss.partition.name}</attribute>
| <attribute name="TargetStartMethod">startSingleton</attribute>
| <attribute name="TargetStopMethod">stopSingleton</attribute>
| </mbean>
|
| </server>
Thanks
Meng
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4118011#4118011
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4118011
18 years, 3 months
[JBoss Seam] - Re: Creating a simple selectOneMenu
by mars1412
i think this should be possible using s:enumItem and s:convertEnum,
but you should also consider using a java-enumeration at entity-bean level:
public enum CustomerStatus {
| INACTIVE,
| ACTIVE;
| public String getLabel() {
| return this.name(); //return whatever name you wanna see
| }
| }
then use this enum on your entity bean:
| @Enumerated(EnumType.STRING)
| @NotNull
| public CustomerStatus getStatus() {
| return status;
| }
|
then make the enum values available in the pages via a factory:
| @Name("customerStatusFactory")
| public class CustomerStatusFactory {
|
| @Factory("customerStatus")
| public CustomerStatus[] getCustomerStatus() {
| return CustomerStatus.values();
| }
| }
|
in your page, use the enum:
| <h:selectOneMenu value="#{customerHome.instance.status}">
| <s:selectItems value="#{customerStatus}" var="cus"
| label="#{cus.label}"
| noSelectionLabel="Please select" />
| <s:convertEnum />
| </h:selectOneMenu>
|
U may also checkout the examples\ui\src\org\jboss\seam\example\ui example (Person-entity)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117994#4117994
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117994
18 years, 3 months
[Installation, Configuration & DEPLOYMENT] - Strange workers.properties problem (Apache / mod_jk)
by Spuds
We have a production cluster and a qa / dev cluster.
All are using Apache and mod_jk.
We have staging sites set up on the production cluster that point to the QA site and IP addresses in the QA cluster... we have several of these "staging" sites that work just fine and point to the same QA cluster with no problems.
I just recently added another, but when I uncomment the block in workers.properties, suddenly all of the sites on the whole box go down EXCEPT for the staging site, which works fine.
Comment the block out, restart apache-- now everything comes right back instantly, but of course the staging site doesn't work.
Here is the relevant block in workers.properties:
########################################################
#qa.bpp worker configuration
#Q-bpp Node1
worker.qa-bpp1.port=8009
worker.qa-bpp1.host=10.2.2.185
worker.qa-bpp1.type=ajp13
worker.qa-bpp1.lbfactor=1
#
#Q-bpp Node2
worker.qa-bpp2.port=8009
worker.qa-bpp2.host=10.2.2.186
worker.qa-bpp2.type=ajp13
worker.qa-bpp2.lbfactor=1
#
# Load-balancing behaviour
worker.qa-bpp.type=lb
worker.qa-bpp.balance_workers=qa-bpp1,qa-bpp2
##########################################################
Here is what I have in mod_jk.conf:
<VirtualHost *:80>
ServerAdmin ULadmin
DocumentRoot /var/www/html
ServerName stag.bpp
ErrorLog /var/log/http/stag.bpp-error_log
CustomLog /var/log/http/stag.bpp-access_log common
JkMount /* qa-bpp
The blocks look right to me, I have looked at the file for extra whitespace / codes and have found none, I have looked at the block before and after this block to see if there are any errors in those and have found none.
The QA and DEV site are working fine in those clusters.
The block above *IS* in the workers.list list.
Any ideas?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117993#4117993
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117993
18 years, 3 months