public class SiteToSiteRestApiClient extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
class |
SiteToSiteRestApiClient.HttpGetFailedException |
private class |
SiteToSiteRestApiClient.HttpsResponseInterceptor |
private static class |
SiteToSiteRestApiClient.RemoteGroupContents |
| Constructor and Description |
|---|
SiteToSiteRestApiClient(SSLContext sslContext,
HttpProxy proxy,
EventReporter eventReporter) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
private void |
closeSilently(Closeable closeable) |
TransactionResultEntity |
commitReceivingFlowFiles(String transactionUrl,
ResponseCode clientResponse,
String checksum) |
TransactionResultEntity |
commitTransferFlowFiles(String transactionUrl,
ResponseCode clientResponse) |
private org.apache.http.client.methods.HttpDelete |
createDelete(String path) |
private org.apache.http.client.methods.HttpGet |
createGet(String path) |
private org.apache.http.client.methods.HttpGet |
createGetControllerRequest() |
private org.apache.http.client.methods.HttpPost |
createPost(String path) |
private org.apache.http.client.methods.HttpPut |
createPut(String path) |
private void |
debugProxyAuthState(org.apache.http.protocol.HttpContext context)
Print AuthState in HttpContext for debugging purpose.
|
private String |
execute(org.apache.http.client.methods.HttpGet get) |
private <T> T |
execute(org.apache.http.client.methods.HttpGet get,
Class<T> entityClass) |
TransactionResultEntity |
extendTransaction(String transactionUrl) |
private ControllerDTO |
fetchController() |
void |
finishTransferFlowFiles(CommunicationsSession commSession) |
String |
getBaseUrl() |
private ControllerDTO |
getController() |
ControllerDTO |
getController(Set<String> clusterUrls)
Try each URL in clusterUrls one by one to get a controller resource
from those remote NiFi instances until a controller is successfully returned or try out all URLs.
|
ControllerDTO |
getController(String clusterUrls)
Parse the clusterUrls String, and try each URL in clusterUrls one by one to get a controller resource
from those remote NiFi instances until a controller is successfully returned or try out all URLs.
|
private org.apache.http.client.CredentialsProvider |
getCredentialsProvider() |
static String |
getFirstUrl(String clusterUrlStr) |
private org.apache.http.impl.nio.client.CloseableHttpAsyncClient |
getHttpAsyncClient() |
private org.apache.http.impl.client.CloseableHttpClient |
getHttpClient() |
Collection<PeerDTO> |
getPeers() |
private org.apache.http.client.config.RequestConfig |
getRequestConfig() |
Integer |
getTransactionProtocolVersion() |
String |
getTrustedPeerDn() |
private URI |
getUri(String path) |
private IOException |
handleErrResponse(int responseCode,
InputStream in) |
String |
initiateTransaction(TransferDirection direction,
String portId) |
private org.apache.http.HttpResponse |
initiateTransactionForReceive(org.apache.http.client.methods.HttpPost post)
Initiate a transaction for receiving data.
|
private org.apache.http.HttpResponse |
initiateTransactionForSend(org.apache.http.client.methods.HttpPost post)
Initiate a transaction for sending data.
|
boolean |
openConnectionForReceive(String transactionUrl,
Peer peer) |
void |
openConnectionForSend(String transactionUrl,
Peer peer) |
static Set<String> |
parseClusterUrls(String clusterUrlStr)
Parse the comma-separated URLs string for the remote NiFi instances.
|
private void |
pruneCache() |
private TransactionResultEntity |
readResponse(InputStream inputStream) |
private String |
readTransactionUrl(org.apache.http.HttpResponse response) |
private static String |
resolveBaseUrl(String clusterUrl) |
private static String |
resolveBaseUrl(URI clusterUrl)
Resolve NiFi API url with leniency.
|
void |
setBaseUrl(String baseUrl)
Set the baseUrl as it is, without altering or adjusting the specified url string.
|
void |
setBaseUrl(String scheme,
String host,
int port) |
private void |
setBaseUrl(String scheme,
String host,
int port,
String path) |
void |
setBatchCount(int batchCount) |
void |
setBatchDurationMillis(long batchDurationMillis) |
void |
setBatchSize(long batchSize) |
void |
setCacheExpirationMillis(long expirationMillis) |
void |
setCompress(boolean compress) |
void |
setConnectTimeoutMillis(int connectTimeoutMillis) |
private void |
setHandshakeProperties(org.apache.http.client.methods.HttpRequestBase httpRequest) |
void |
setLocalAddress(InetAddress localAddress) |
void |
setReadTimeoutMillis(int readTimeoutMillis) |
void |
setRequestExpirationMillis(long requestExpirationMillis) |
private void |
setupAsyncClient() |
private void |
setupClient() |
private void |
setupCredentialsProvider() |
private void |
setupRequestConfig() |
private boolean |
shouldCheckProxyAuth() |
private void |
startExtendingTransaction(String transactionUrl) |
private void |
stopExtendingTransaction() |
private IOException |
toIOException(ExecutionException e) |
private static void |
validateUriString(String s) |
private static final String EVENT_CATEGORY
private static final int DATA_PACKET_CHANNEL_READ_BUFFER_SIZE
private static final int RESPONSE_CODE_OK
private static final int RESPONSE_CODE_CREATED
private static final int RESPONSE_CODE_ACCEPTED
private static final int RESPONSE_CODE_BAD_REQUEST
private static final int RESPONSE_CODE_FORBIDDEN
private static final int RESPONSE_CODE_NOT_FOUND
private static final org.slf4j.Logger logger
private String baseUrl
protected final SSLContext sslContext
protected final HttpProxy proxy
private final AtomicBoolean proxyAuthRequiresResend
private final EventReporter eventReporter
private org.apache.http.client.config.RequestConfig requestConfig
private org.apache.http.client.CredentialsProvider credentialsProvider
private org.apache.http.impl.client.CloseableHttpClient httpClient
private org.apache.http.impl.nio.client.CloseableHttpAsyncClient httpAsyncClient
private boolean compress
private InetAddress localAddress
private long requestExpirationMillis
private int serverTransactionTtl
private int batchCount
private long batchSize
private long batchDurationMillis
private final TransportProtocolVersionNegotiator transportProtocolVersionNegotiator
private String trustedPeerDn
private final ScheduledExecutorService ttlExtendTaskExecutor
private ScheduledFuture<?> ttlExtendingFuture
private int connectTimeoutMillis
private int readTimeoutMillis
private long cacheExpirationMillis
private static final Pattern HTTP_ABS_URL
private Future<org.apache.http.HttpResponse> postResult
private CountDownLatch transferDataLatch
private static final ConcurrentMap<String,SiteToSiteRestApiClient.RemoteGroupContents> contentsMap
private volatile long lastPruneTimestamp
public SiteToSiteRestApiClient(SSLContext sslContext, HttpProxy proxy, EventReporter eventReporter)
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionprivate org.apache.http.impl.client.CloseableHttpClient getHttpClient()
private org.apache.http.impl.nio.client.CloseableHttpAsyncClient getHttpAsyncClient()
private org.apache.http.client.config.RequestConfig getRequestConfig()
private org.apache.http.client.CredentialsProvider getCredentialsProvider()
private void setupRequestConfig()
private void setupCredentialsProvider()
private void setupClient()
private void setupAsyncClient()
public ControllerDTO getController(String clusterUrls) throws IOException
clusterUrls - url of the remote NiFi instance, multiple urls can be specified in comma-separated formatIllegalArgumentException - when it fails to parse the URLs string,
URLs string contains multiple protocols (http and https mix),
or none of URL is specified.IOExceptionpublic ControllerDTO getController(Set<String> clusterUrls) throws IOException
IOExceptionprivate ControllerDTO getController() throws IOException
IOExceptionprivate ControllerDTO fetchController() throws IOException
IOExceptionprivate void pruneCache()
private org.apache.http.client.methods.HttpGet createGetControllerRequest()
public Collection<PeerDTO> getPeers() throws IOException
IOExceptionpublic String initiateTransaction(TransferDirection direction, String portId) throws IOException
IOExceptionprivate org.apache.http.HttpResponse initiateTransactionForReceive(org.apache.http.client.methods.HttpPost post)
throws IOException
post - a POST request to establish transactionIOException - thrown if the post request failedprivate org.apache.http.HttpResponse initiateTransactionForSend(org.apache.http.client.methods.HttpPost post)
throws IOException
Initiate a transaction for sending data.
If a proxy server requires auth, the proxy server returns 407 response with available auth schema such as basic or digest. Then client has to resend the same request with its credential added. This mechanism is problematic for sending data from NiFi.
In order to resend a POST request with auth param, NiFi has to either read flow-file contents to send again, or keep the POST body somewhere. If we store that in memory, it would causes OOM, or storing it on disk slows down performance. Rolling back processing session would be overkill. Reading flow-file contents only when it's ready to send in a streaming way is ideal.
Additionally, the way proxy authentication is done is vary among Proxy server software. Some requires 407 and resend cycle for every requests, while others keep a connection between a client and the proxy server, then consecutive requests skip auth steps. The problem is, that how should we behave is only told after sending a request to the proxy.
In order to handle above concerns correctly and efficiently, this method do the followings:openConnectionForSend(java.lang.String, org.apache.nifi.remote.Peer) can determine when to produce contents.The above special sequence is only executed when a proxy instance is set, and its username is set.
post - a POST request to establish transactionIOException - thrown if the post request failedprivate void debugProxyAuthState(org.apache.http.protocol.HttpContext context)
If the proxy server requires 407 and resend cycle, this method logs as followings, for Basic Auth:
For Digest Auth:
But if the proxy uses the same connection, it doesn't return 407, in such case this method is called only once with:
private IOException toIOException(ExecutionException e)
private boolean shouldCheckProxyAuth()
public boolean openConnectionForReceive(String transactionUrl, Peer peer) throws IOException
IOExceptionpublic void openConnectionForSend(String transactionUrl, Peer peer) throws IOException
IOExceptionpublic void finishTransferFlowFiles(CommunicationsSession commSession) throws IOException
IOExceptionprivate void startExtendingTransaction(String transactionUrl)
private void closeSilently(Closeable closeable)
public TransactionResultEntity extendTransaction(String transactionUrl) throws IOException
IOExceptionprivate void stopExtendingTransaction()
private IOException handleErrResponse(int responseCode, InputStream in) throws IOException
IOExceptionprivate TransactionResultEntity readResponse(InputStream inputStream) throws IOException
IOExceptionprivate String readTransactionUrl(org.apache.http.HttpResponse response)
private void setHandshakeProperties(org.apache.http.client.methods.HttpRequestBase httpRequest)
private org.apache.http.client.methods.HttpGet createGet(String path)
private org.apache.http.client.methods.HttpPost createPost(String path)
private org.apache.http.client.methods.HttpPut createPut(String path)
private org.apache.http.client.methods.HttpDelete createDelete(String path)
private String execute(org.apache.http.client.methods.HttpGet get) throws IOException
IOExceptionprivate <T> T execute(org.apache.http.client.methods.HttpGet get,
Class<T> entityClass)
throws IOException
IOExceptionpublic String getBaseUrl()
public void setBaseUrl(String baseUrl)
resolveBaseUrl(String) method before passing it to this method.baseUrl - url to setpublic void setConnectTimeoutMillis(int connectTimeoutMillis)
public void setReadTimeoutMillis(int readTimeoutMillis)
public void setCacheExpirationMillis(long expirationMillis)
public static Set<String> parseClusterUrls(String clusterUrlStr)
IllegalArgumentException - when it fails to parse the URLs string,
URLs string contains multiple protocols (http and https mix),
or none of URL is specified.private static void validateUriString(String s)
private static String resolveBaseUrl(URI clusterUrl)
clusterUrl - url to be resolvedpublic void setCompress(boolean compress)
public void setLocalAddress(InetAddress localAddress)
public void setRequestExpirationMillis(long requestExpirationMillis)
public void setBatchCount(int batchCount)
public void setBatchSize(long batchSize)
public void setBatchDurationMillis(long batchDurationMillis)
public Integer getTransactionProtocolVersion()
public String getTrustedPeerDn()
public TransactionResultEntity commitReceivingFlowFiles(String transactionUrl, ResponseCode clientResponse, String checksum) throws IOException
IOExceptionpublic TransactionResultEntity commitTransferFlowFiles(String transactionUrl, ResponseCode clientResponse) throws IOException
IOExceptionCopyright © 2023 Apache NiFi Project. All rights reserved.