Class ProxiedResource
- Direct Known Subclasses:
ClusterDeflectorResource
,ClusterInputStatesResource
,ClusterJournalResource
,ClusterLoadBalancerStatusResource
,ClusterLoggersResource
,ClusterLookupTableResource
,ClusterMetricsResource
,ClusterNodeMetricsResource
,ClusterProcessingStatusResource
,ClusterSystemJobResource
,ClusterSystemPluginResource
,ClusterSystemProcessingResource
,ClusterSystemResource
,ClusterSystemShutdownResource
,SupportBundleClusterResource
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
This wrapper is intended to provide additional server error information if something went wrong beyond the actual API HTTP call.static class
Deprecated.static class
-
Field Summary
Modifier and TypeFieldDescriptionprotected final NodeService
protected final RemoteInterfaceProvider
Fields inherited from class org.graylog2.shared.rest.resources.RestResource
configuration, userService
-
Constructor Summary
ModifierConstructorDescriptionprotected
ProxiedResource
(javax.ws.rs.core.HttpHeaders httpHeaders, NodeService nodeService, RemoteInterfaceProvider remoteInterfaceProvider, ExecutorService executorService) -
Method Summary
Modifier and TypeMethodDescriptionstatic String
authenticationToken
(javax.ws.rs.core.HttpHeaders httpHeaders) createRemoteInterface
(Class<RemoteInterfaceType> interfaceClass, Duration timeout) protected <RemoteInterfaceType,
RemoteCallResponseType, FinalResponseType>
ProxiedResource.NodeResponse<FinalResponseType>doNodeApiCall
(String nodeId, Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> remoteInterfaceFunction, Function<RemoteCallResponseType, FinalResponseType> transformer, Duration timeout) protected String
Gets an authentication token to be used in an Authorization header of forwarded requests by extracting authentication information from the original request.protected Duration
getForAllNodes
(Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> fn, Function<String, Optional<RemoteInterfaceType>> interfaceProvider) Deprecated.getForAllNodes
(Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> fn, Function<String, Optional<RemoteInterfaceType>> interfaceProvider, Duration timeout) 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.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.protected void
processAsync
(javax.ws.rs.container.AsyncResponse asyncResponse, Supplier<Object> responseSupplier) protected <RemoteInterfaceType,
RemoteCallResponseType>
Map<String,ProxiedResource.CallResult<RemoteCallResponseType>> requestOnAllNodes
(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> fn) protected <RemoteInterfaceType,
RemoteCallResponseType>
Map<String,ProxiedResource.CallResult<RemoteCallResponseType>> requestOnAllNodes
(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> fn, Duration timeout) protected <RemoteInterfaceType,
RemoteCallResponseType, FinalResponseType>
Map<String,ProxiedResource.CallResult<FinalResponseType>> requestOnAllNodes
(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> remoteInterfaceCallProvider, Function<RemoteCallResponseType, FinalResponseType> responseTransformer) protected <RemoteInterfaceType,
RemoteCallResponseType, FinalResponseType>
Map<String,ProxiedResource.CallResult<FinalResponseType>> requestOnAllNodes
(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> remoteInterfaceCallProvider, Function<RemoteCallResponseType, FinalResponseType> responseTransformer, Duration timeout) This method concurrently performs an API call on all active nodes.protected <RemoteInterfaceType,
RemoteCallResponseType>
ProxiedResource.NodeResponse<RemoteCallResponseType>requestOnLeader
(Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> remoteInterfaceFunction, Class<RemoteInterfaceType> interfaceClass) Execute the given remote interface function on the leader node.protected <RemoteInterfaceType,
RemoteCallResponseType>
ProxiedResource.NodeResponse<RemoteCallResponseType>requestOnLeader
(Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> remoteInterfaceFunction, Class<RemoteInterfaceType> interfaceClass, Duration timeout) Execute the given remote interface function on the leader node.stripCallResult
(Map<String, ProxiedResource.CallResult<T>> input) Helper function to remove theProxiedResource.CallResult
wrapperMethods inherited from class org.graylog2.shared.rest.resources.RestResource
checkAnyPermission, checkPermission, checkPermission, getCurrentUser, getIndexSet, getSubject, getUriBuilderToSelf, isAnyPermitted, isAnyPermitted, isPermitted, isPermitted, setPrettyPrint
-
Field Details
-
nodeService
-
remoteInterfaceProvider
-
-
Constructor Details
-
ProxiedResource
protected ProxiedResource(@Context javax.ws.rs.core.HttpHeaders httpHeaders, NodeService nodeService, RemoteInterfaceProvider remoteInterfaceProvider, ExecutorService executorService)
-
-
Method Details
-
getDefaultProxyCallTimeout
-
processAsync
-
authenticationToken
-
getAuthenticationToken
Gets an authentication token to be used in an Authorization header of forwarded requests by extracting authentication information from the original request.Only extracts an auth token from the request if the request is authenticated. This is to make sure that forwarded requests will also not be authenticated.
If the request is authenticated, but not by means of an authentication token, this method will fail with a
NotAuthorizedException
because we can't easily make up a token to use for forwarded requests in that case.- Returns:
- An authentication token if the request was authenticated and one could be extracted from the original request. Null otherwise.
- Throws:
javax.ws.rs.NotAuthorizedException
- if the original request was authenticated, but no authentication token could be created from the request headers.
-
getForAllNodes
@Deprecated protected <RemoteInterfaceType,RemoteCallResponseType> Map<String,Optional<RemoteCallResponseType>> getForAllNodes(Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> fn, Function<String, Optional<RemoteInterfaceType>> interfaceProvider) Deprecated.Prefer usingrequestOnAllNodes(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 usingrequestOnAllNodes(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, Map<String,RemoteCallResponseType> Optional<FinalResponseType>> getForAllNodes(Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> fn, Function<String, Optional<RemoteInterfaceType>> interfaceProvider, Function<RemoteCallResponseType, FinalResponseType> transformer) Deprecated.Prefer usingrequestOnAllNodes(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, Map<String,RemoteCallResponseType> Optional<FinalResponseType>> getForAllNodes(Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> fn, Function<String, Optional<RemoteInterfaceType>> interfaceProvider, Function<RemoteCallResponseType, FinalResponseType> transformer, Duration timeout) Deprecated.Prefer usingrequestOnAllNodes(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
-
requestOnAllNodes
protected <RemoteInterfaceType,RemoteCallResponseType> Map<String,ProxiedResource.CallResult<RemoteCallResponseType>> requestOnAllNodes(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> fn) -
requestOnAllNodes
-
requestOnAllNodes
protected <RemoteInterfaceType,RemoteCallResponseType, Map<String,FinalResponseType> ProxiedResource.CallResult<FinalResponseType>> requestOnAllNodes(Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> remoteInterfaceCallProvider, Function<RemoteCallResponseType, FinalResponseType> responseTransformer) -
requestOnAllNodes
protected <RemoteInterfaceType,RemoteCallResponseType, Map<String,FinalResponseType> 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 clientRemoteCallResponseType
- Type of the API call response bodyFinalResponseType
- Type after applying the transformations- Parameters:
interfaceClass
- The class of the Retrotfit interface for this callremoteInterfaceCallProvider
- 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 IOExceptionExecute 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 IOExceptionExecute 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
-
doNodeApiCall
protected <RemoteInterfaceType,RemoteCallResponseType, ProxiedResource.NodeResponse<FinalResponseType> doNodeApiCallFinalResponseType> (String nodeId, Class<RemoteInterfaceType> interfaceClass, Function<RemoteInterfaceType, retrofit2.Call<RemoteCallResponseType>> remoteInterfaceFunction, Function<RemoteCallResponseType, throws IOExceptionFinalResponseType> transformer, @Nullable Duration timeout) - Throws:
IOException
-
stripCallResult
protected <T> Map<String,Optional<T>> stripCallResult(Map<String, ProxiedResource.CallResult<T>> input) Helper function to remove theProxiedResource.CallResult
wrapper- Parameters:
input
- responses that are wrapped with aProxiedResource.CallResult
- Returns:
- the response in the legacy format of
Map<String, Optional<T>>
-
ProxiedResource.NodeResponse
instead.