Class HttpClient

java.lang.Object
org.apache.nifi.remote.client.AbstractSiteToSiteClient
org.apache.nifi.remote.client.http.HttpClient
All Implemented Interfaces:
Closeable, AutoCloseable, PeerStatusProvider, SiteToSiteClient

public class HttpClient extends AbstractSiteToSiteClient implements PeerStatusProvider
  • Field Details

  • Constructor Details

  • Method Details

    • getBootstrapPeerDescription

      public PeerDescription getBootstrapPeerDescription() throws IOException
      Description copied from interface: PeerStatusProvider

      Returns a PeerDescription instance, which represents a bootstrap remote NiFi node. The bootstrap node is always used to fetch remote peer statuses.

      Once the PeerSelector successfully got remote peer statuses, it periodically fetches remote peer statuses, so that it can detect remote NiFi cluster topology changes such as addition or removal of nodes. To refresh remote peer statuses, PeerSelector calls PeerStatusProvider.fetchRemotePeerStatuses(org.apache.nifi.remote.PeerDescription) with one of query-able nodes lastly fetched from the remote NiFi cluster, until it gets a successful result, or throws IOException if none of them responds successfully.

      This mechanism lets PeerSelector works even if the bootstrap remote NiFi node goes down.

      Specified by:
      getBootstrapPeerDescription in interface PeerStatusProvider
      Returns:
      peer description of a bootstrap remote NiFi node
      Throws:
      IOException - thrown when it fails to retrieve the bootstrap remote node information
    • fetchRemotePeerStatuses

      public Set<PeerStatus> fetchRemotePeerStatuses(PeerDescription peerDescription) throws IOException
      Description copied from interface: PeerStatusProvider
      Fetch peer statuses from a remote NiFi cluster. Implementation of this method should fetch peer statuses from the node represented by the passed PeerDescription using its transport protocol.
      Specified by:
      fetchRemotePeerStatuses in interface PeerStatusProvider
      Parameters:
      peerDescription - a bootstrap node or one of query-able nodes lastly fetched successfully
      Returns:
      Remote peer statuses
      Throws:
      IOException - thrown when it fails to fetch peer statuses of the remote cluster from the specified peer
    • getRemoteInstanceUris

      public String getRemoteInstanceUris()
      Description copied from interface: PeerStatusProvider
      Returns the remote instance URIs.
      Specified by:
      getRemoteInstanceUris in interface PeerStatusProvider
      Returns:
      the instance URIs
    • fetchRemotePeerStatuses

      private Set<PeerStatus> fetchRemotePeerStatuses(SiteToSiteRestApiClient apiClient) throws IOException
      Throws:
      IOException
    • createTransaction

      public Transaction createTransaction(TransferDirection direction) throws IOException
      Description copied from interface: SiteToSiteClient

      Creates a new Transaction that can be used to either send data to a remote NiFi instance or receive data from a remote NiFi instance, depending on the value passed for the direction argument.

      Note: If all of the nodes are penalized (See SiteToSiteClient.Builder.nodePenalizationPeriod(long, TimeUnit)), then this method will return null.

      Specified by:
      createTransaction in interface SiteToSiteClient
      Parameters:
      direction - specifies which direction the data should be transferred. A value of TransferDirection.SEND indicates that this Transaction will send data to the remote instance; a value of TransferDirection.RECEIVE indicates that this Transaction will be used to receive data from the remote instance.
      Returns:
      a Transaction to use for sending or receiving data, or null if all nodes are penalized.
      Throws:
      IOException - ioe
    • resolveNodeApiUrl

      private String resolveNodeApiUrl(PeerDescription description)
    • isSecure

      public boolean isSecure() throws IOException
      Description copied from interface: SiteToSiteClient

      In order to determine whether the server is configured for secure communications, the client may have to query the server's RESTful interface. Doing so could result in an IOException.

      Specified by:
      isSecure in interface SiteToSiteClient
      Returns:
      true if site-to-site communications with the remote instance are secure, false if site-to-site communications with the remote instance are not secure. Whether or not communications are secure depends on the server, not the client
      Throws:
      IOException - if unable to query the remote instance's RESTful interface or if the remote instance is not configured to allow site-to-site communications
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getTransportProtocol

      public SiteToSiteTransportProtocol getTransportProtocol()
      Description copied from interface: PeerStatusProvider
      Returns the transport protocol being used.
      Specified by:
      getTransportProtocol in interface PeerStatusProvider
      Returns:
      the transport protocol