Skip to content

Commit

Permalink
WFLY-8540 Former singleton provider node leaving cluster after re-ele…
Browse files Browse the repository at this point in the history
…ction causes another re-election
  • Loading branch information
pferraro committed Apr 24, 2017
1 parent 75728fd commit c139267
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 51 deletions.
15 changes: 15 additions & 0 deletions clustering/singleton/extension/pom.xml
Expand Up @@ -59,6 +59,21 @@
<artifactId>metainf-services</artifactId> <artifactId>metainf-services</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.wildfly</groupId> <groupId>org.wildfly</groupId>
<artifactId>wildfly-clustering-common</artifactId> <artifactId>wildfly-clustering-common</artifactId>
Expand Down
Expand Up @@ -36,7 +36,6 @@
import org.jboss.as.network.OutboundSocketBinding; import org.jboss.as.network.OutboundSocketBinding;
import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.ValueService; import org.jboss.msc.service.ValueService;
import org.jboss.msc.value.Value; import org.jboss.msc.value.Value;
Expand Down Expand Up @@ -65,7 +64,7 @@ protected ElectionPolicyBuilder(PathAddress policyAddress) {
@Override @Override
public ServiceBuilder<SingletonElectionPolicy> build(ServiceTarget target) { public ServiceBuilder<SingletonElectionPolicy> build(ServiceTarget target) {
Value<SingletonElectionPolicy> value = () -> this.preferences.isEmpty() ? this.getValue() : new PreferredSingletonElectionPolicy(this.getValue(), this.preferences); Value<SingletonElectionPolicy> value = () -> this.preferences.isEmpty() ? this.getValue() : new PreferredSingletonElectionPolicy(this.getValue(), this.preferences);
ServiceBuilder<SingletonElectionPolicy> builder = target.addService(this.getServiceName(), new ValueService<>(value)).setInitialMode(ServiceController.Mode.ON_DEMAND); ServiceBuilder<SingletonElectionPolicy> builder = target.addService(this.getServiceName(), new ValueService<>(value));
this.dependencies.forEach(dependency -> dependency.register(builder)); this.dependencies.forEach(dependency -> dependency.register(builder));
return builder; return builder;
} }
Expand Down
@@ -0,0 +1,46 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.extension.clustering.singleton;

import static org.jboss.logging.Logger.Level.INFO;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.wildfly.clustering.singleton.SingletonPolicy;

/**
* @author Paul Ferraro
*/
@MessageLogger(projectCode = "WFLYCLSNG", length = 4)
public interface SingletonLogger extends BasicLogger {
String ROOT_LOGGER_CATEGORY = "org.wildfly.extension.clustering.singleton";

SingletonLogger ROOT_LOGGER = Logger.getMessageLogger(SingletonLogger.class, ROOT_LOGGER_CATEGORY);

@LogMessage(level = INFO)
@Message(id = 1, value = "Singleton deployment detected. Deployment will reset using %s policy.")
void singletonDeploymentDetected(SingletonPolicy policy);
}
Expand Up @@ -102,4 +102,9 @@ public <T> Builder<T> createSingletonServiceBuilder(ServiceName name, Service<T>
.requireQuorum(this.quorum) .requireQuorum(this.quorum)
; ;
} }

@Override
public String toString() {
return this.address.getLastElement().getValue();
}
} }
Expand Up @@ -42,12 +42,12 @@ public class SingletonDeploymentDependencyProcessor implements DeploymentUnitPro
@Override @Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException { public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
DeploymentUnit unit = context.getDeploymentUnit(); DeploymentUnit unit = context.getDeploymentUnit();
DeploymentUnit parent = unit.getParent(); if (unit.getParent() == null) {
// If this is a sub-deployment, any configuration will be attached to the parent deployment unit SingletonDeploymentConfiguration config = unit.getAttachment(CONFIGURATION_KEY);
SingletonDeploymentConfiguration config = ((parent != null) ? parent : unit).getAttachment(CONFIGURATION_KEY); if (config != null) {
if (config != null) { CapabilityServiceSupport support = unit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
CapabilityServiceSupport support = unit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); context.addDependency(SingletonServiceNameFactory.SINGLETON_POLICY.getServiceName(support, config.getPolicy()), SingletonDeploymentProcessor.POLICY_KEY);
context.addDependency(SingletonServiceNameFactory.SINGLETON_POLICY.getServiceName(support, config.getPolicy()), SingletonDeploymentProcessor.POLICY_KEY); }
} }
} }


Expand Down
Expand Up @@ -26,10 +26,13 @@
import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitPhaseBuilder;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.msc.service.AbstractServiceListener;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceController.Mode;
import org.wildfly.clustering.singleton.SingletonPolicy; import org.wildfly.clustering.singleton.SingletonPolicy;
import org.wildfly.extension.clustering.singleton.SingletonLogger;


/** /**
* DUP that attaches the singleton DeploymentUnitPhaseBuilder if a deployment policy is attached. * DUP that attaches the singleton DeploymentUnitPhaseBuilder if a deployment policy is attached.
Expand All @@ -41,11 +44,27 @@ public class SingletonDeploymentProcessor implements DeploymentUnitProcessor {


@Override @Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException { public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
SingletonPolicy policy = context.getAttachment(POLICY_KEY); DeploymentUnit unit = context.getDeploymentUnit();
if (policy != null) { if (unit.getParent() == null) {
DeploymentUnit parent = context.getDeploymentUnit().getParent(); SingletonPolicy policy = context.getAttachment(POLICY_KEY);
DeploymentUnitPhaseBuilder builder = (parent == null) ? new SingletonDeploymentUnitPhaseBuilder(policy) : new SingletonSubDeploymentUnitPhaseBuilder(parent, context.getPhase().next()); if (policy != null) {
context.putAttachment(Attachments.DEPLOYMENT_UNIT_PHASE_BUILDER, builder); // Ideally, we would just install the next phase using the singleton policy, however deployment unit phases do not currently support restarts
// Restart the deployment using the attached phase builder, but only if a builder was not already attached
if (unit.putAttachment(Attachments.DEPLOYMENT_UNIT_PHASE_BUILDER, new SingletonDeploymentUnitPhaseBuilder(policy)) == null) {
SingletonLogger.ROOT_LOGGER.singletonDeploymentDetected(policy);
ServiceController<?> controller = context.getServiceRegistry().getRequiredService(unit.getServiceName());
controller.addListener(new AbstractServiceListener<Object>() {
@Override
public void transition(final ServiceController<?> controller, final ServiceController.Transition transition) {
if(transition.getAfter().equals(ServiceController.Substate.DOWN)) {
controller.setMode(Mode.ACTIVE);
controller.removeListener(this);
}
}
});
controller.setMode(Mode.NEVER);
}
}
} }
} }


Expand Down

This file was deleted.

0 comments on commit c139267

Please sign in to comment.