Skip to content

Commit

Permalink
Merge pull request #459 from rhusar/MODCLUSTER-711-1.4
Browse files Browse the repository at this point in the history
[1.4] MODCLUSTER-711 Using "connectorPort" property fails if multiple servi…
  • Loading branch information
pferraro committed Jul 22, 2020
2 parents fe5757a + 98f19cf commit 4190321
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/org/jboss/modcluster/ModClusterLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
14 changes: 11 additions & 3 deletions core/src/main/java/org/jboss/modcluster/ModClusterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +77,11 @@ public List<MCMPRequest> getResetRequests(Map<String, Set<VirtualHost>> response
List<MCMPRequest> engineRequests = new LinkedList<MCMPRequest>();

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 4190321

Please sign in to comment.