Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFLY-17876] Have the MicroProfile LRA subsystems fully clean up afte… #16717

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
package org.wildfly.extension.microprofile.lra.coordinator._private;

import io.narayana.lra.LRAConstants;
import jakarta.servlet.ServletException;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.msc.service.StartException;

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

/**
Expand Down Expand Up @@ -58,4 +61,9 @@ public interface MicroProfileLRACoordinatorLogger extends BasicLogger {
@LogMessage(level = INFO)
@Message(id = 3, value = "Starting Narayana MicroProfile LRA Coordinator available at path %s/" + LRAConstants.COORDINATOR_PATH_NAME)
void startingCoordinator(String path);

@LogMessage(level = ERROR)
@Message(id = 4, value = "Failed to stop Narayana MicroProfile LRA Coordinator at path %s/" + LRAConstants.COORDINATOR_PATH_NAME)
void failedStoppingCoordinator(String path, @Cause ServletException cause);

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class LRACoordinatorService implements Service {

private final Supplier<Host> undertow;

private volatile DeploymentManager deploymentManager = null;
private volatile Deployment deployment = null;

public LRACoordinatorService(Supplier<Host> undertow) {
Expand Down Expand Up @@ -96,23 +97,33 @@ private DeploymentInfo getDeploymentInfo(final String name, final String context
}

private void deployServlet(final DeploymentInfo deploymentInfo) {
DeploymentManager manager = ServletContainer.Factory.newInstance().addDeployment(deploymentInfo);
manager.deploy();
deployment = manager.getDeployment();
deploymentManager = ServletContainer.Factory.newInstance().addDeployment(deploymentInfo);
deploymentManager.deploy();
deployment = deploymentManager.getDeployment();

try {
undertow.get()
.registerDeployment(deployment, manager.start());
.registerDeployment(deployment, deploymentManager.start());
} catch (ServletException e) {
deployment = null;
}
}

private void undeployServlet() {
if (deployment != null) {
undertow.get()
.unregisterDeployment(deployment);
deployment = null;
if (deploymentManager != null) {
if (deployment != null) {
undertow.get()
.unregisterDeployment(deployment);
deployment = null;
}
try {
deploymentManager.stop();
} catch (ServletException e) {
MicroProfileLRACoordinatorLogger.LOGGER.failedStoppingCoordinator(CONTEXT_PATH, e);
} finally {
deploymentManager.undeploy();
}
deploymentManager = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static org.jboss.as.controller.OperationContext.Stage.RUNTIME;
import static org.wildfly.extension.microprofile.lra.participant.MicroProfileLRAParticipantExtension.SUBSYSTEM_NAME;
import static org.wildfly.extension.microprofile.lra.participant.MicroProfileLRAParticipantSubsystemDefinition.ATTRIBUTES;
import static org.wildfly.extension.microprofile.lra.participant.MicroProfileLRAParticipantSubsystemDefinition.COORDINATOR_URL_PROP;

class MicroProfileLRAParticipantAdd extends AbstractBoottimeAddStepHandler {

Expand All @@ -57,7 +58,7 @@ class MicroProfileLRAParticipantAdd extends AbstractBoottimeAddStepHandler {
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
super.performBoottime(context, operation, model);
final String url = MicroProfileLRAParticipantSubsystemDefinition.LRA_COORDINATOR_URL.resolveModelAttribute(context, model).asString();
System.setProperty("lra.coordinator.url", url);
System.setProperty(COORDINATOR_URL_PROP, url);

context.addStep(new AbstractDeploymentChainStep() {
public void execute(DeploymentProcessorTarget processorTarget) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class MicroProfileLRAParticipantSubsystemDefinition extends PersistentRes

private static final String LRA_PARTICIPANT_CAPABILITY_NAME = "org.wildfly.microprofile.lra.participant";

public static final String COORDINATOR_URL_PROP = "lra.coordinator.url";

static final RuntimeCapability<Void> LRA_PARTICIPANT_CAPABILITY = RuntimeCapability.Builder
.of(LRA_PARTICIPANT_CAPABILITY_NAME)
.setServiceType(Void.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.wildfly.extension.microprofile.lra.participant._private;

import jakarta.servlet.ServletException;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.Cause;
Expand All @@ -30,6 +31,7 @@
import org.jboss.logging.annotations.MessageLogger;
import org.wildfly.extension.microprofile.lra.participant.service.LRAParticipantService;

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

Expand All @@ -56,4 +58,8 @@ public interface MicroProfileLRAParticipantLogger extends BasicLogger {
@Message(id = 3, value = "The CDI marker file cannot be created")
void cannotCreateCDIMarkerFile(@Cause Throwable e);

@LogMessage(level = ERROR)
@Message(id = 4, value = "Failed to stop Narayana MicroProfile LRA Participant Proxy at path %s/" + LRAParticipantService.CONTEXT_PATH)
void failedStoppingParticipant(String path, @Cause ServletException cause);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package org.wildfly.extension.microprofile.lra.participant.service;

import static org.wildfly.extension.microprofile.lra.participant.MicroProfileLRAParticipantSubsystemDefinition.COORDINATOR_URL_PROP;

import io.undertow.servlet.api.Deployment;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
Expand Down Expand Up @@ -50,6 +52,7 @@ public final class LRAParticipantService implements Service {

private final Supplier<Host> undertow;

private volatile DeploymentManager deploymentManager = null;
private volatile Deployment deployment = null;

public LRAParticipantService(Supplier<Host> undertow) {
Expand All @@ -63,7 +66,18 @@ public synchronized void start(final StartContext context) throws StartException

@Override
public synchronized void stop(final StopContext context) {
undeployServlet();
try {
undeployServlet();
} finally {
// If we are stopping the server is either shutting down or reloading.
// In case it's a reload and this subsystem will not be installed after the reload,
// clear the lra.coordinator.url prop so it doesn't affect the reloaded server.
// If the subsystem is still in the config, the add op handler will set it again.
// TODO perhaps set the property in this service's start and have LRAParticipantDeploymentDependencyProcessor
// add a dep on this service to the next DeploymentUnitPhaseService (thus ensuring the prop
// is set before any deployment begins creating services).
System.clearProperty(COORDINATOR_URL_PROP);
}
}

private void deployParticipantProxy() {
Expand Down Expand Up @@ -96,23 +110,33 @@ private DeploymentInfo getDeploymentInfo(final String name, final String context
}

private void deployServlet(final DeploymentInfo deploymentInfo) {
DeploymentManager manager = ServletContainer.Factory.newInstance().addDeployment(deploymentInfo);
manager.deploy();
deployment = manager.getDeployment();
deploymentManager = ServletContainer.Factory.newInstance().addDeployment(deploymentInfo);
deploymentManager.deploy();
deployment = deploymentManager.getDeployment();

try {
undertow.get()
.registerDeployment(deployment, manager.start());
.registerDeployment(deployment, deploymentManager.start());
} catch (ServletException e) {
deployment = null;
}
}

private void undeployServlet() {
if (deployment != null) {
undertow.get()
.unregisterDeployment(deployment);
deployment = null;
if (deploymentManager != null) {
if (deployment != null) {
undertow.get()
.unregisterDeployment(deployment);
deployment = null;
}
try {
deploymentManager.stop();
} catch (ServletException e) {
MicroProfileLRAParticipantLogger.LOGGER.failedStoppingParticipant(CONTEXT_PATH, e);
} finally {
deploymentManager.undeploy();
}
deploymentManager = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
@RunAsClient
@RunWith(Arquillian.class)
@ServerSetup(EnableLRAExtensionsSetupTask.class)
public class LRAParticipantSmokeTest {
public class LRAParticipantSmokeTestCase {

private static final String LRA_COORDINATOR_URL_KEY = "lra.coordinator.url";
private static final String CLOSE_PATH = "/close";
Expand All @@ -78,8 +78,12 @@ public void before() {

@After
public void after() throws IOException {
if (client != null) {
client.close();
try {
if (client != null) {
client.close();
}
} finally {
System.clearProperty(LRA_COORDINATOR_URL_KEY);
}
}

Expand All @@ -90,7 +94,7 @@ public static WebArchive getDeployment() {
.addPackages(true,
"org.wildfly.test.integration.microprofile.lra.participant.smoke.hotel",
"org.wildfly.test.integration.microprofile.lra.participant.smoke.model")
.addClasses(LRAParticipantSmokeTest.class,
.addClasses(LRAParticipantSmokeTestCase.class,
EnableLRAExtensionsSetupTask.class,
CLIServerSetupTask.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# JBoss, Home of Professional Open Source.
# Copyright 2020, 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.
#

# Additional logger names to configure (root logger is always configured)
loggers=

# Root logger level
logger.level=INFO

# Root logger handlers
logger.handlers=FILE

# File handler configuration
handler.FILE=org.jboss.logmanager.handlers.FileHandler
handler.FILE.properties=autoFlush,append,fileName
handler.FILE.autoFlush=true
handler.FILE.fileName=./target/test.log
handler.FILE.formatter=PATTERN
handler.FILE.append=true

# Formatter pattern configuration
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%e%n