diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/AbstractSiteToSiteClient.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/AbstractSiteToSiteClient.java index 05cf1f9c53..c6b98a05f9 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/AbstractSiteToSiteClient.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/AbstractSiteToSiteClient.java @@ -33,7 +33,7 @@ public abstract class AbstractSiteToSiteClient implements SiteToSiteClient { siteInfoProvider.setConnectTimeoutMillis(commsTimeout); siteInfoProvider.setReadTimeoutMillis(commsTimeout); siteInfoProvider.setProxy(config.getHttpProxy()); - + siteInfoProvider.setLocalAddress(config.getLocalAddress()); } @Override diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteInfoProvider.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteInfoProvider.java index a1a9a9c32b..06b939dff1 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteInfoProvider.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/SiteInfoProvider.java @@ -17,6 +17,7 @@ package org.apache.nifi.remote.client; import java.io.IOException; +import java.net.InetAddress; import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; @@ -48,6 +49,7 @@ public class SiteInfoProvider { private Boolean siteToSiteSecure; private long remoteRefreshTime; private HttpProxy proxy; + private InetAddress localAddress; private final Map inputPortMap = new HashMap<>(); // map input port name to identifier private final Map outputPortMap = new HashMap<>(); // map output port name to identifier @@ -63,8 +65,6 @@ public class SiteInfoProvider { final ControllerDTO controller; final URI connectedClusterUrl; try (final SiteToSiteRestApiClient apiClient = createSiteToSiteRestApiClient(sslContext, proxy)) { - apiClient.setConnectTimeoutMillis(connectTimeoutMillis); - apiClient.setReadTimeoutMillis(readTimeoutMillis); controller = apiClient.getController(clusterUrls); try { connectedClusterUrl = new URI(apiClient.getBaseUrl()); @@ -100,7 +100,11 @@ public class SiteInfoProvider { } protected SiteToSiteRestApiClient createSiteToSiteRestApiClient(final SSLContext sslContext, final HttpProxy proxy) { - return new SiteToSiteRestApiClient(sslContext, proxy, EventReporter.NO_OP); + final SiteToSiteRestApiClient apiClient = new SiteToSiteRestApiClient(sslContext, proxy, EventReporter.NO_OP); + apiClient.setConnectTimeoutMillis(connectTimeoutMillis); + apiClient.setReadTimeoutMillis(readTimeoutMillis); + apiClient.setLocalAddress(localAddress); + return apiClient; } public boolean isWebInterfaceSecure() { @@ -271,4 +275,8 @@ public class SiteInfoProvider { public void setProxy(HttpProxy proxy) { this.proxy = proxy; } + + public void setLocalAddress(InetAddress localAddress) { + this.localAddress = localAddress; + } } diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/http/HttpClient.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/http/HttpClient.java index c933db789e..f0bdcf143e 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/http/HttpClient.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/client/http/HttpClient.java @@ -106,6 +106,7 @@ public class HttpClient extends AbstractSiteToSiteClient implements PeerStatusPr final int timeoutMillis = (int) config.getTimeout(TimeUnit.MILLISECONDS); apiClient.setConnectTimeoutMillis(timeoutMillis); apiClient.setReadTimeoutMillis(timeoutMillis); + apiClient.setLocalAddress(config.getLocalAddress()); final Collection peers = apiClient.getPeers(); if(peers == null || peers.size() == 0){ @@ -153,6 +154,7 @@ public class HttpClient extends AbstractSiteToSiteClient implements PeerStatusPr apiClient.setBaseUrl(peer.getUrl()); apiClient.setConnectTimeoutMillis(timeoutMillis); apiClient.setReadTimeoutMillis(timeoutMillis); + apiClient.setLocalAddress(config.getLocalAddress()); apiClient.setCompress(config.isUseCompression()); apiClient.setRequestExpirationMillis(config.getIdleConnectionExpiration(TimeUnit.MILLISECONDS)); diff --git a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/SiteToSiteRestApiClient.java b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/SiteToSiteRestApiClient.java index 5655d36205..ad7814352d 100644 --- a/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/SiteToSiteRestApiClient.java +++ b/nifi-commons/nifi-site-to-site-client/src/main/java/org/apache/nifi/remote/util/SiteToSiteRestApiClient.java @@ -1206,12 +1206,10 @@ public class SiteToSiteRestApiClient implements Closeable { public void setConnectTimeoutMillis(final int connectTimeoutMillis) { this.connectTimeoutMillis = connectTimeoutMillis; - setupRequestConfig(); } public void setReadTimeoutMillis(final int readTimeoutMillis) { this.readTimeoutMillis = readTimeoutMillis; - setupRequestConfig(); } public static String getFirstUrl(final String clusterUrlStr) { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java index 286b2dcef1..7aee480da7 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java @@ -880,6 +880,7 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup { try { this.networkInterfaceName = interfaceName; if (interfaceName == null) { + this.localAddress = null; this.nicValidationResult = null; } else { try { @@ -930,11 +931,7 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup { SiteToSiteRestApiClient apiClient = new SiteToSiteRestApiClient(sslContext, new HttpProxy(proxyHost, proxyPort, proxyUser, proxyPassword), getEventReporter()); apiClient.setConnectTimeoutMillis(getCommunicationsTimeout(TimeUnit.MILLISECONDS)); apiClient.setReadTimeoutMillis(getCommunicationsTimeout(TimeUnit.MILLISECONDS)); - - final InetAddress localAddress = getLocalAddress(); - if (localAddress != null) { - apiClient.setLocalAddress(localAddress); - } + apiClient.setLocalAddress(getLocalAddress()); return apiClient; }