From 98f19cf2c39a6416e22d3e9fd0a2838a97bc805b Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Mon, 27 Apr 2020 23:12:15 +0200 Subject: [PATCH] MODCLUSTER-711 Using "connectorPort" property fails if multiple services are configured in Tomcat --- .../tomcat/ConfigurableProxyConnectorProvider.java | 11 ++++++----- .../org/jboss/modcluster/ModClusterLogger.java | 8 ++++++-- .../org/jboss/modcluster/ModClusterService.java | 14 +++++++++++--- .../mcmp/impl/ResetRequestSourceImpl.java | 6 ++++++ .../mcmp/ResetRequestSourceTestCase.java | 3 +++ 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/container/tomcat/src/main/java/org/jboss/modcluster/container/tomcat/ConfigurableProxyConnectorProvider.java b/container/tomcat/src/main/java/org/jboss/modcluster/container/tomcat/ConfigurableProxyConnectorProvider.java index d3e5d4071..8eba5d2ca 100644 --- a/container/tomcat/src/main/java/org/jboss/modcluster/container/tomcat/ConfigurableProxyConnectorProvider.java +++ b/container/tomcat/src/main/java/org/jboss/modcluster/container/tomcat/ConfigurableProxyConnectorProvider.java @@ -21,16 +21,17 @@ */ package org.jboss.modcluster.container.tomcat; -import java.net.InetAddress; -import java.net.UnknownHostException; - import org.apache.catalina.Engine; import org.jboss.modcluster.ModClusterLogger; import org.jboss.modcluster.container.Connector; +import java.net.InetAddress; +import java.net.UnknownHostException; + /** * Connector provider implementation that picks a connector based on configured {@code connectorPort=".."} and/or {@code connectorAddress=".."}. - * Should multiple or no connectors match the defined values a {@link RuntimeException} is thrown. + * Should multiple connectors match a {@link RuntimeException} is thrown. + * If no connectors match for the given engine, {@code null} is returned. * * @author Radoslav Husar */ @@ -86,7 +87,7 @@ public Connector createProxyConnector(ConnectorFactory factory, Engine engine) { } if (candidate == null) { - throw ModClusterLogger.LOGGER.connectorNoMatch(format(connectorAddress, connectorPort)); + return null; } return factory.createConnector(candidate); diff --git a/core/src/main/java/org/jboss/modcluster/ModClusterLogger.java b/core/src/main/java/org/jboss/modcluster/ModClusterLogger.java index b318e7545..619cd0311 100644 --- a/core/src/main/java/org/jboss/modcluster/ModClusterLogger.java +++ b/core/src/main/java/org/jboss/modcluster/ModClusterLogger.java @@ -178,8 +178,8 @@ public interface ModClusterLogger { @Message(id = 46, value = "Starting to drain %d active sessions from %s:%s in %d seconds.") void startSessionDraining(int sessions, Host host, Context context, long timeout); - @Message(id = 47, value = "No configured connector matches specified host:port (%s)! Ensure connectorPort and/or connectorAddress are configured.") - RuntimeException connectorNoMatch(String connector); +// @Message(id = 47, value = "No configured connector matches specified host:port (%s)! Ensure connectorPort and/or connectorAddress are configured.") +// RuntimeException connectorNoMatch(String connector); @Message(id = 48, value = "Multiple connectors match specified host:port (%s)! Ensure connectorPort and/or connectorAddress are configured.") RuntimeException connectorMatchesMultiple(String connector); @@ -195,4 +195,8 @@ public interface ModClusterLogger { @LogMessage(level = INFO) @Message(id = 54, value = "Starting to drain %d active sessions from %s:%s waiting indefinitely until all remaining sessions are drained or expired.") void startSessionDrainingIndefinitely(int sessions, Host host, Context context); + + @LogMessage(level = WARN) + @Message(id = 55, value = "No configured connector for engine %s. If this engine should be used with mod_cluster check connector, connectorPort and/or connectorAddress configuration.") + void noConnectorForEngine(String engineName); } diff --git a/core/src/main/java/org/jboss/modcluster/ModClusterService.java b/core/src/main/java/org/jboss/modcluster/ModClusterService.java index 560ad29c8..bfaa41800 100644 --- a/core/src/main/java/org/jboss/modcluster/ModClusterService.java +++ b/core/src/main/java/org/jboss/modcluster/ModClusterService.java @@ -266,6 +266,10 @@ public boolean isEstablished() { public void connectionEstablished(InetAddress localAddress) { for (Engine engine : this.server.getEngines()) { Connector connector = engine.getProxyConnector(); + if (connector == null) { + ModClusterLogger.LOGGER.noConnectorForEngine(engine.getName()); + continue; + } InetAddress address = connector.getAddress(); // Set connector address @@ -399,13 +403,17 @@ protected void removeAll(Engine engine) { @Override public void status(Engine engine) { + Connector connector = engine.getProxyConnector(); + if (connector == null) { + // Skip status for Engines that don't have a connector available + return; + } + this.mcmpHandler.status(); if (this.established) { // Send STATUS request - Connector connector = engine.getProxyConnector(); - - int lbf = (connector != null) && connector.isAvailable() ? this.getLoadBalanceFactor(engine) : -1; + int lbf = connector.isAvailable() ? this.getLoadBalanceFactor(engine) : -1; ModClusterLogger.LOGGER.sendEngineCommand(MCMPRequestType.STATUS, engine); diff --git a/core/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java b/core/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java index 157991311..064b1a420 100644 --- a/core/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java +++ b/core/src/main/java/org/jboss/modcluster/mcmp/impl/ResetRequestSourceImpl.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.Set; +import org.jboss.modcluster.container.Connector; import org.jboss.modcluster.container.Context; import org.jboss.modcluster.container.Engine; import org.jboss.modcluster.container.Host; @@ -76,6 +77,11 @@ public List getResetRequests(Map> response List engineRequests = new LinkedList(); for (Engine engine : this.server.getEngines()) { + Connector connector = engine.getProxyConnector(); + if (connector == null) { + // Skip config for Engines that don't have any available connector + continue; + } engineRequests.add(this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig)); String jvmRoute = engine.getJvmRoute(); diff --git a/core/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java b/core/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java index d9307d6fd..eac041594 100755 --- a/core/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java +++ b/core/src/test/java/org/jboss/modcluster/mcmp/ResetRequestSourceTestCase.java @@ -30,6 +30,7 @@ import java.util.Set; import java.util.TreeSet; +import org.jboss.modcluster.container.Connector; import org.jboss.modcluster.container.Context; import org.jboss.modcluster.container.Engine; import org.jboss.modcluster.container.Host; @@ -86,6 +87,7 @@ public void getResetRequests() throws Exception { when(this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig)).thenReturn(configRequest); when(engine.getJvmRoute()).thenReturn("host1"); + when(engine.getProxyConnector()).thenReturn(mock(Connector.class)); when(engine.getHosts()).thenReturn(Collections.singleton(host)); when(host.getName()).thenReturn("host"); @@ -131,6 +133,7 @@ public void getResetRequestsDisableContexts() throws Exception { when(this.requestFactory.createConfigRequest(engine, this.nodeConfig, this.balancerConfig)).thenReturn(configRequest); when(engine.getJvmRoute()).thenReturn("host1"); + when(engine.getProxyConnector()).thenReturn(mock(Connector.class)); when(engine.getHosts()).thenReturn(Collections.singleton(host)); when(host.getName()).thenReturn("host");