Class ProxiedResource

java.lang.Object
org.graylog2.shared.rest.resources.RestResource
org.graylog2.shared.rest.resources.ProxiedResource
Direct Known Subclasses:
ClusterDeflectorResource, ClusterInputStatesResource, ClusterJournalResource, ClusterLoadBalancerStatusResource, ClusterLoggersResource, ClusterLookupTableResource, ClusterMetricsResource, ClusterNodeMetricsResource, ClusterProcessingStatusResource, ClusterSystemJobResource, ClusterSystemPluginResource, ClusterSystemProcessingResource, ClusterSystemResource, ClusterSystemShutdownResource, SearchJobsStatusResource, SupportBundleClusterResource

public abstract class ProxiedResource extends RestResource
  • Field Details

  • Constructor Details

  • Method Details

    • getDefaultProxyCallTimeout

      protected Duration getDefaultProxyCallTimeout()
    • processAsync

      protected void processAsync(jakarta.ws.rs.container.AsyncResponse asyncResponse, Supplier<Object> responseSupplier)
    • authenticationToken

      public static String authenticationToken(jakarta.ws.rs.core.HttpHeaders httpHeaders)
    • getAuthenticationToken

      @Nullable protected String getAuthenticationToken()
      Gets an authentication token to be used in an Authorization header of forwarded requests. It was extracted from the authentication information of the original request.
      Returns:
      An authentication token if the request was authenticated and one could be extracted from the original
    • getForAllNodes

      @Deprecated protected <RemoteInterfaceType, RemoteCallResponseType> Map<String,Optional<RemoteCallResponseType>> getForAllNodes(Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> fn, Function<String,Optional<RemoteInterfaceType>> interfaceProvider)
      Deprecated.
      Prefer using requestOnAllNodes(Class, Function) instead. The new method properly handles the case of `No-Content` response and provides detailed report per each node API call.
    • getForAllNodes

      @Deprecated protected <RemoteInterfaceType, RemoteCallResponseType> Map<String,Optional<RemoteCallResponseType>> getForAllNodes(Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> fn, Function<String,Optional<RemoteInterfaceType>> interfaceProvider, Duration timeout)
      Deprecated.
      Prefer using requestOnAllNodes(Class, Function, Duration) instead. The new method properly handles the case of `No-Content` response and provides detailed report per each node API call.
    • getForAllNodes

      @Deprecated protected <RemoteInterfaceType, FinalResponseType, RemoteCallResponseType> Map<String,Optional<FinalResponseType>> getForAllNodes(Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> fn, Function<String,Optional<RemoteInterfaceType>> interfaceProvider, Function<RemoteCallResponseType,FinalResponseType> transformer)
      Deprecated.
      Prefer using requestOnAllNodes(Class, Function, Function) instead. The new method properly handles the case of `No-Content` response and provides detailed report per each node API call.
    • getForAllNodes

      @Deprecated protected <RemoteInterfaceType, FinalResponseType, RemoteCallResponseType> Map<String,Optional<FinalResponseType>> getForAllNodes(Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> fn, Function<String,Optional<RemoteInterfaceType>> interfaceProvider, Function<RemoteCallResponseType,FinalResponseType> transformer, Duration timeout)
      Deprecated.
      Prefer using requestOnAllNodes(Class, Function, Function, Duration) instead. The new method properly handles the case of `No-Content` response and provides detailed report per each node API call.
    • createRemoteInterface

      protected <RemoteInterfaceType> Function<String,Optional<RemoteInterfaceType>> createRemoteInterface(Class<RemoteInterfaceType> interfaceClass, @Nullable Duration timeout)
    • requestOnAllNodes

      protected <RemoteInterfaceType, RemoteCallResponseType> Map<String,ProxiedResource.CallResult<RemoteCallResponseType>> requestOnAllNodes(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> fn)
    • requestOnAllNodes

      protected <RemoteInterfaceType, RemoteCallResponseType> Map<String,ProxiedResource.CallResult<RemoteCallResponseType>> requestOnAllNodes(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> fn, Duration timeout)
    • requestOnAllNodes

      protected <RemoteInterfaceType, RemoteCallResponseType, FinalResponseType> Map<String,ProxiedResource.CallResult<FinalResponseType>> requestOnAllNodes(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> remoteInterfaceCallProvider, Function<RemoteCallResponseType,FinalResponseType> responseTransformer)
    • requestOnAllNodes

      protected <RemoteInterfaceType, RemoteCallResponseType, FinalResponseType> Map<String,ProxiedResource.CallResult<FinalResponseType>> requestOnAllNodes(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> remoteInterfaceCallProvider, Function<RemoteCallResponseType,FinalResponseType> responseTransformer, @Nullable Duration timeout)
      This method concurrently performs an API call on all active nodes.
      Type Parameters:
      RemoteInterfaceType - Type of the Retrofit HTTP client
      RemoteCallResponseType - Type of the API call response body
      FinalResponseType - Type after applying the transformations
      Parameters:
      interfaceClass - The class of the Retrotfit interface for this call
      remoteInterfaceCallProvider - provides an invocation of a Retrofit method for the intended API call.
      responseTransformer - applies transformations to HTTP response body
      Returns:
      Detailed report on call results per each active node.
    • requestOnLeader

      protected <RemoteInterfaceType, RemoteCallResponseType> ProxiedResource.NodeResponse<RemoteCallResponseType> requestOnLeader(Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> remoteInterfaceFunction, Class<RemoteInterfaceType> interfaceClass, Duration timeout) throws IOException
      Execute the given remote interface function on the leader node.

      This is used to forward an API request to the leader node. It is useful in situations where an API call can only be executed on the leader node.

      The returned ProxiedResource.NodeResponse object is constructed from the remote response's status code and body.

      Throws:
      IOException
    • requestOnLeader

      protected <RemoteInterfaceType, RemoteCallResponseType> ProxiedResource.NodeResponse<RemoteCallResponseType> requestOnLeader(Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> remoteInterfaceFunction, Class<RemoteInterfaceType> interfaceClass) throws IOException
      Execute the given remote interface function on the leader node.

      This is used to forward an API request to the leader node. It is useful in situations where an API call can only be executed on the leader node.

      The returned ProxiedResource.NodeResponse object is constructed from the remote response's status code and body.

      Throws:
      IOException
    • requestOnNode

      protected <RemoteInterfaceType, RemoteCallResponseType> ProxiedResource.NodeResponse<RemoteCallResponseType> requestOnNode(String nodeId, Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> remoteInterfaceFunction, Class<RemoteInterfaceType> interfaceClass, Duration timeout) throws IOException
      Execute the given remote interface function on the given node.

      This is used to forward an API request to the given node. It is useful in situations where an API call has to be executed on a particular, chosen node.

      The returned ProxiedResource.NodeResponse object is constructed from the remote response's status code and body.

      Throws:
      IOException
    • requestOnNode

      protected <RemoteInterfaceType, RemoteCallResponseType> ProxiedResource.NodeResponse<RemoteCallResponseType> requestOnNode(String nodeId, Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> remoteInterfaceFunction, Class<RemoteInterfaceType> interfaceClass) throws IOException
      Execute the given remote interface function on the given node.

      This is used to forward an API request to the given node. It is useful in situations where an API call has to be executed on a particular, chosen node.

      The returned ProxiedResource.NodeResponse object is constructed from the remote response's status code and body.

      Throws:
      IOException
    • doNodeApiCall

      protected <RemoteInterfaceType, RemoteCallResponseType, FinalResponseType> ProxiedResource.NodeResponse<FinalResponseType> doNodeApiCall(String nodeId, Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType,retrofit2.Call<RemoteCallResponseType>> remoteInterfaceFunction, Function<RemoteCallResponseType,FinalResponseType> transformer, @Nullable Duration timeout) throws IOException
      Throws:
      IOException
    • stripCallResult

      protected <T> Map<String,Optional<T>> stripCallResult(Map<String,ProxiedResource.CallResult<T>> input)
      Helper function to remove the ProxiedResource.CallResult wrapper
      Parameters:
      input - responses that are wrapped with a ProxiedResource.CallResult
      Returns:
      the response in the legacy format of Map<String, Optional<T>>