Skip to content

Commit

Permalink
issue JPPF-589 fixing management host resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
lolocohen committed May 21, 2019
1 parent 0421bab commit 464434b
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 22 deletions.
2 changes: 1 addition & 1 deletion JPPF/bin/docker/driver/jppf-driver.properties
Expand Up @@ -22,7 +22,7 @@
# to disable, specify a negative port number #
#------------------------------------------------------------------------------#

jppf.resolve.node.host.from.sysinfo = true
#jppf.resolve.node.host.from.sysinfo = true
jppf.server.port = 11111

#------------------------------------------------------------------------------#
Expand Down
8 changes: 4 additions & 4 deletions JPPF/bin/docker/node/jppf-node.properties
Expand Up @@ -307,7 +307,7 @@ jppf.length.buffer.pool.size = 100
# Network settings #
#------------------------------------------------------------------------------#

jppf.bind.include.ipv4 = 172.16.238.0/24
#jppf.bind.exclude.ipv4 = 192.168.1.128-; 192.168.1.0/25
#jppf.bind.include.ipv6 = 1080:0:0:0:8:800:200C-20FF:-; ::1/80
jppf.bind.exclude.ipv6 = -
jppf.management.host.include.ipv4 = 172.16.238.0/24
#jppf.management.host.exclude.ipv4 = 192.168.1.128-; 192.168.1.0/25
#jppf.management.host.include.ipv6 = 1080:0:0:0:8:800:200C-20FF:-; ::1/80
jppf.management.host.exclude.ipv6 = -
3 changes: 2 additions & 1 deletion JPPF/bin/docker/node/log4j-node.properties
Expand Up @@ -67,7 +67,8 @@ log4j.logger.org.jppf.jmxremote.nio.JMXNioServer=INFO
#log4j.logger.org.jppf.nio=DEBUG
log4j.logger.org.jppf.nio.PlainNioObject=INFO
#log4j.logger.org.jppf.nio.SelectorSynchronizerLock=TRACE
#log4j.logger.org.jppf.nio.StateTransitionTask=DEBUG
#log4j.logger.org.jppf.nio.acceptor=DEBUG
log4j.logger.org.jppf.nio.acceptor.AcceptorNioServer=DEBUG
log4j.logger.org.jppf.node=DEBUG
#log4j.logger.org.jppf.node.idle=DEBUG
#log4j.logger.org.jppf.node.NodeRunner=DEBUG
Expand Down
11 changes: 9 additions & 2 deletions common/src/java/org/jppf/comm/discovery/IPFilter.java
Expand Up @@ -42,11 +42,11 @@ public class IPFilter {
/**
* List of accepted IP address patterns.
*/
private List<AbstractIPAddressPattern> includePatterns = new ArrayList<>();
private final List<AbstractIPAddressPattern> includePatterns = new ArrayList<>();
/**
* List of rejected IP address patterns.
*/
private List<AbstractIPAddressPattern> excludePatterns = new ArrayList<>();
private final List<AbstractIPAddressPattern> excludePatterns = new ArrayList<>();
/**
* The loaded configuration.
*/
Expand Down Expand Up @@ -154,4 +154,11 @@ private static boolean matches(final int[] ipComps, final List<AbstractIPAddress
}
return false;
}

/**
* @return whether there is at least one pattern.
*/
public boolean hasPattern() {
return !includePatterns.isEmpty() || !excludePatterns.isEmpty();
}
}
2 changes: 1 addition & 1 deletion common/src/java/org/jppf/nio/NioHelper.java
Expand Up @@ -29,7 +29,7 @@
import org.slf4j.*;

/**
*
* Utility methods to help with managing nio servers.
* @author Laurent Cohen
*/
public class NioHelper {
Expand Down
10 changes: 5 additions & 5 deletions common/src/java/org/jppf/nio/NioServer.java
Expand Up @@ -163,7 +163,7 @@ protected void init() throws Exception {
/**
* Initialize the underlying server sockets for the specified array of ports.
* @param portsToInit the array of ports to initiialize.
* @param ssl <code>true</code> if the server sockets should be initialized with SSL enabled, <code>false</code> otherwise.
* @param ssl {@code true} if the server sockets should be initialized with SSL enabled, {@code false} otherwise.
* @throws Exception if any error occurs while initializing the server sockets.
*/
private void init(final int[] portsToInit, final boolean ssl) throws Exception {
Expand All @@ -173,7 +173,7 @@ private void init(final int[] portsToInit, final boolean ssl) throws Exception {
/**
* Initialize the underlying server sockets for the spcified array of ports.
* @param portToInit the array of ports to initiialize.
* @param ssl <code>true</code> if the server sockets should be initialized with SSL enabled, <code>false</code> otherwise.
* @param ssl {@code true} if the server sockets should be initialized with SSL enabled, {@code false} otherwise.
* @param env optional map of parameters to associate with the server socket channel.
* @param retryOnException whether to retry if an exception occurs when binding the server.
* @throws Exception if any error occurs while initializing the server sockets.
Expand Down Expand Up @@ -251,11 +251,11 @@ protected void doAccept(final SelectionKey key) {
/**
* Register an incoming connection with this server's selector.
* The channel is registered with an empty set of initial interest operations,
* which means a call to the corresponding {@link SelectionKey}'s <code>interestOps()</code> method will return 0.
* which means a call to the corresponding {@link SelectionKey}'s {@code interestOps()} method will return 0.
* @param serverSocketChannel the server socket channel accepting the connection.
* @param channel the socket channel representing the connection.
* @param sslHandler an sslEngine eventually passed on from a different server.
* @param ssl specifies whether an <code>SSLHandler</code> should be initialized for the channel.
* @param ssl specifies whether an {@code SSLHandler} should be initialized for the channel.
* @param peer specifiies whether the channel is for a peer driver.
* @param params optional parameters.
* @throws Exception if any error occurs.
Expand All @@ -266,7 +266,7 @@ public abstract void accept(final ServerSocketChannel serverSocketChannel, final
/**
* Define a context for a newly created channel.
* @param params optional parameters.
* @return an <code>NioContext</code> instance.
* @return an {@code NioContext} instance.
*/
public abstract NioContext createNioContext(final Object...params);

Expand Down
4 changes: 3 additions & 1 deletion common/src/java/org/jppf/nio/acceptor/AcceptorNioServer.java
Expand Up @@ -194,7 +194,9 @@ public void addServer(final int portToInit, final boolean ssl, final Map<String,
final int maxBindRetries = retryOnException ? JPPFConfiguration.getProperties().getInt("jppf.acceptor.bind.maxRetries", 3) : 1;
final long retryDelay = JPPFConfiguration.getProperties().getLong("jppf.acceptor.bind.retryDelay", 3000L);
final ServerSocketChannel server = ServerSocketChannel.open().setOption(StandardSocketOptions.SO_RCVBUF, IO.SOCKET_BUFFER_SIZE);
final InetSocketAddress addr = new InetSocketAddress(port);
final InetAddress bindAddress = NetworkUtils.getInetAddress("jppf.bind.");
if (debugEnabled) log.debug("bind address: {}", bindAddress);
final InetSocketAddress addr = (bindAddress == null) ? new InetSocketAddress(port) : new InetSocketAddress(bindAddress, port);
if (debugEnabled) log.debug("binding server socket channel to address {}", addr);
RetryUtils.runWithRetry(maxBindRetries, retryDelay, () -> server.bind(addr));
if (debugEnabled) log.debug("server socket channel bound to address {}", addr);
Expand Down
45 changes: 41 additions & 4 deletions common/src/java/org/jppf/utils/NetworkUtils.java
Expand Up @@ -21,6 +21,7 @@
import java.net.*;
import java.util.*;

import org.jppf.comm.discovery.IPFilter;
import org.jppf.utils.configuration.JPPFProperties;
import org.slf4j.*;

Expand All @@ -47,6 +48,10 @@ public final class NetworkUtils {
* Constant for empty array of host/ip pairs.
*/
private static final HostIP[] NO_ADDRESS = new HostIP[0];
/**
* The list on non-local IP addresses fgor the current host.
*/
private static final List<InetAddress> nonLocalIPAddresses = new ArrayList<>();

/**
* Instantiation opf this class is not permitted.
Expand Down Expand Up @@ -147,10 +152,13 @@ private static List<InetAddress> getIPAddresses(final InetAddressFilter filter)
* @return a List of <code>InetAddress</code> instances, may be empty but never null.
*/
public static List<InetAddress> getNonLocalIPAddresses() {
final List<InetAddress> addresses = new ArrayList<>();
addresses.addAll(getNonLocalIPV4Addresses());
addresses.addAll(getNonLocalIPV6Addresses());
return addresses;
synchronized(nonLocalIPAddresses) {
if (nonLocalIPAddresses.isEmpty()) {
nonLocalIPAddresses.addAll(getNonLocalIPV4Addresses());
nonLocalIPAddresses.addAll(getNonLocalIPV6Addresses());
}
return new ArrayList<>(nonLocalIPAddresses);
}
}

/**
Expand Down Expand Up @@ -322,4 +330,33 @@ public static HostIP[] parseAddresses(final String addresses) {
}
return result;
}

/**
* @param propertyPrefix prefix for the properties deifining include and exclude IP address patterns.
* @return an {@link InetAddress} to bind to, or {@code null} to bind to all interfaces.
*/
public static InetAddress getInetAddress(final String propertyPrefix) {
return getInetAddress(JPPFConfiguration.getProperties(), propertyPrefix);
}

/**
* @param config the config to use.
* @param propertyPrefix prefix for the properties deifining include and exclude IP address patterns.
* @return an {@link InetAddress} to bind to, or {@code null} to bind to all interfaces.
*/
public static InetAddress getInetAddress(final TypedProperties config, final String propertyPrefix) {
final IPFilter filter = new IPFilter(config, propertyPrefix);
if (!filter.hasPattern()) return null;
final List<InetAddress> addresses = NetworkUtils.getNonLocalIPAddresses();
if ((addresses != null) && !addresses.isEmpty()) {
final List<InetAddress> accepted = new ArrayList<>();
for (final InetAddress addr: addresses) {
if (filter.isAddressAccepted(addr)) accepted.add(addr);
}
if (debugEnabled) log.debug("accepted addresses for '{}' prefix: {}", propertyPrefix, accepted);
if (accepted.size() == addresses.size()) return null;
return accepted.isEmpty() ? null : accepted.get(0);
}
return null;
}
}
14 changes: 13 additions & 1 deletion node/src/java/org/jppf/server/node/JPPFNode.java
Expand Up @@ -18,6 +18,7 @@
package org.jppf.server.node;

import java.io.IOException;
import java.net.InetAddress;
import java.util.*;

import org.jppf.*;
Expand Down Expand Up @@ -243,6 +244,8 @@ private void checkInitialBundle(final TaskBundle bundle) throws Exception {
}
} else {
if (!throttlingHandler.check()) bundle.setParameter(BundleParameter.NODE_ACCEPTS_NEW_JOBS, false);
final String ip = getManagementAddress();
if (ip != null) bundle.setParameter(BundleParameter.NODE_MANAGEMENT_HOST_PARAM, ip);
throttlingHandler.start();
}
if (isJmxEnabled()) setupBundleParameters(bundle);
Expand Down Expand Up @@ -366,7 +369,7 @@ private boolean checkStopped() {
if (isStopped()) throw new IllegalStateException("this node is shutting down");
return false;
}

/**
* @return the slave node manager.
* @exclude
Expand Down Expand Up @@ -421,4 +424,13 @@ public JobWriter getJobWriter() {
public List<String> getHandshakeUuidPath() {
return handshakeUuidPath;
}


/**
* @return an {@link InetAddress} to bind to, or {@code null} to bind to all interfaces.
*/
private String getManagementAddress() {
final InetAddress addr = NetworkUtils.getInetAddress(getConfiguration(), "jppf.management.host.");
return (addr != null) ? addr.getHostAddress() : null;
}
}
Expand Up @@ -136,8 +136,12 @@ public void handshakeReceived(final AsyncNodeContext context, final AbstractTask
} else if (debugEnabled) log.debug("no system info received for node {}", context);
final int port = bundle.getParameter(NODE_MANAGEMENT_PORT_PARAM, -1);
if (debugEnabled) log.debug("management port = {} for node = {}", port, context);
String host = getChannelHost(context);
final HostIP hostIP = context.isLocal() ? new HostIP(host, host) : resolveHost(context);
String host = bundle.getParameter(NODE_MANAGEMENT_HOST_PARAM, null);
HostIP hostIP = null;
if (host == null) {
host = getChannelHost(context);
hostIP = context.isLocal() ? new HostIP(host, host) : resolveHost(context);
} else hostIP = NetworkUtils.getHostIP(host);
final boolean sslEnabled = !context.isLocal() && context.getSSLHandler() != null;
final boolean hasJmx = driver.getConfiguration().get(JPPFProperties.MANAGEMENT_ENABLED);
final String masterUuid = bundle.getParameter(NODE_PROVISIONING_MASTER_UUID);
Expand Down

0 comments on commit 464434b

Please sign in to comment.