Package com.illumon.iris.controller
Class PersistentQueryControllerClient
java.lang.Object
com.illumon.iris.controller.ControllerHashtable
com.illumon.iris.controller.PersistentQueryControllerClient
- All Implemented Interfaces:
ControllerHashtableEventSource,PersistentQueryScriptSource,RemoteScriptSource,Map<Long,PersistentQueryInfo>
public class PersistentQueryControllerClient
extends ControllerHashtable
implements PersistentQueryScriptSource
Client for subscribing to state from the PersistentQueryController and manipulating persistent queries.
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final io.deephaven.proto.controller.grpc.AclApiGrpc.AclApiStubprotected final io.deephaven.proto.controller.grpc.ControllerApiGrpc.ControllerApiStubprotected final RetryStrategyprotected final com.fishlib.io.logger.LoggerFields inherited from class com.illumon.iris.controller.ControllerHashtable
data, handlers -
Constructor Summary
ConstructorsConstructorDescriptionPersistentQueryControllerClient(String who, com.fishlib.io.logger.Logger log, io.deephaven.shadow.core.io.grpc.ManagedChannel channel) PersistentQueryControllerClient(String who, com.fishlib.io.logger.Logger log, io.deephaven.shadow.core.io.grpc.ManagedChannel channel, ScheduledExecutorService executorService) PersistentQueryControllerClient(String who, com.fishlib.io.logger.Logger log, io.deephaven.shadow.core.io.grpc.ManagedChannel channel, ScheduledExecutorService executorService, long heartBeatPeriodMillis, long heartBeatTimeoutMillis) -
Method Summary
Modifier and TypeMethodDescriptionlongAdds a configuration to the controller's hash table.voidaddReloadConfigurationListener(Consumer<PersistentQueryControllerConfiguration> reloadListener) voidAdd a status listener.booleanauthenticate(io.deephaven.enterprise.auth.AuthToken token) Use the specified auth token to authenticate this client to the hashtable server.protected CompletableFuture<io.deephaven.shadow.core.com.google.protobuf.ByteString>authenticateAsync(long maxTimeToDeadlineMillis, io.deephaven.enterprise.auth.AuthToken token) CompletableFuture<io.deephaven.shadow.core.com.google.protobuf.ByteString>authenticateAsync(io.deephaven.enterprise.auth.AuthToken token) Use the specified auth token to authenticate this client to the hashtable server.determineDispatcher(PersistentQueryDbServerConfig serverConfig, int heapSizeMB, String workerKind) determineDispatcher(String serverConfigName, int heapSizeMB, String workerKind) protected ExecutorServiceString[]Returns the list of all groups.String[]Returns the list of all users.protected io.deephaven.shadow.core.com.google.protobuf.ByteStringgetAuthCookie(String who, RetryBackoffContext backoffContext) getControllerClient(com.fishlib.io.logger.Logger log) getControllerClient(com.fishlib.io.logger.Logger log, boolean doSubscription) getControllerClient(String who, com.fishlib.io.logger.Logger log) getControllerClient(String who, com.fishlib.io.logger.Logger log, boolean doSubscription) String[]getGroupsForUser(io.deephaven.enterprise.auth.UserContext userContext) Return the groups which a user belongs to.getPersistentQueryConfiguration(long configSerial) getPersistentQueryConfiguration(long configSerial, String owner, String name) getPersistentQueryConfiguration(String owner, String name) getScriptBody(boolean relative, String scriptPath, long configSerial, ScriptPathLoaderState scriptLoaderState) Get a script by path for a specific serial ID and a specific state.getScriptBody(boolean relative, String scriptPath, ScriptPathLoaderState scriptLoaderState) getScriptBody(boolean relative, String scriptPath, String scriptLoaderStateJson) Get a script by path and state.getScriptBody(boolean relative, String scriptPath, String ownerName, ScriptPathLoaderState scriptLoaderState) getScriptBodyByOwner(boolean relative, String scriptPath, String ownerName, String scriptLoaderStateJson) Get a script by path for a specific owner and state.getScriptDisplayPaths(long configSerial, ScriptPathLoaderState scriptLoaderState) Get all display paths available to a specific PersistentQuery serial ID and a specific state..getScriptDisplayPaths(ScriptPathLoaderState scriptLoaderState) getScriptDisplayPaths(String scriptLoaderStateJson) Get all available display paths for a specific state.getScriptDisplayPaths(String ownerName, ScriptPathLoaderState scriptLoaderState) getScriptDisplayPathsByOwner(String ownerName, String scriptLoaderStateJson) Get all display paths available to a specific owner and state.Gets the server configuration from the controller.String[]getUsersForGroup(String group) Return the users which belong to a group.protected voidprotected voidprotected voidbooleanisAclEditor(io.deephaven.enterprise.auth.UserContext userContext) Returns true if the effective user is an ACL editorbooleanCheck if this client can communicate with the server.booleanisQueryManager(io.deephaven.enterprise.auth.UserContext userContext) Returns true if the effective user is an Query ManagerbooleanisSchemaManager(io.deephaven.enterprise.auth.UserContext userContext) Returns true if the effective user is a Schema managerbooleanisSuperUser(io.deephaven.enterprise.auth.UserContext userContext) Returns true if the effective user is a superuser.protected RetryBackoffContextmakeAndStartAuthRetryBackoffContext(long timeOfDeadlineMillis) voidModifies a configuration in the controller's hash table, and restart the query if it was running.voidmodifyQueryConfiguration(PersistentQueryConfiguration config, boolean restartIfRunning) Modifies a configuration in the controller's hash table.voidpublishTemporaryQueries(com.fishlib.io.logger.Logger log, PersistentQueryConfiguration... configs) voidReloads the controller configuration.voidRemoves a configuration from the controller's hash table.voidremoveQueryConfigurationBySerial(long serialId) Removes a configuration from the controller's hash table by serial ID.voidvoidrestartQueries(List<PersistentQueryConfiguration> configs) Restarts one or more persistent queries.voidrestartQueriesBySerial(long[] serialIds) Restarts one or more persistent queries.voidrestartQueriesBySerial(List<Long> serials) Restarts one or more persistent queries.voidRestart a persistent query.voidSet the channel as ephemeral.protected io.deephaven.proto.controller.grpc.AclApiGrpc.AclApiStubsetupAsyncAclStub(long deadlineAfterMillis) protected io.deephaven.proto.controller.grpc.ControllerApiGrpc.ControllerApiStubsetupAsyncStub(long deadlineAfterMillis) voidshutdown()voidstopQueries(List<PersistentQueryConfiguration> configs) Stops one or more persistent queries.voidStops a persistent query.voidstopQueryBySerial(long[] serials) Stops one or more persistent query by serial id.voidstopQueryBySerial(List<Long> serials) voidSubscribe to the complete hash table.voidprotected <ReqT,RespT, Stub>
RespTwithRetriesAndReAuth(String who, Function<io.deephaven.shadow.core.com.google.protobuf.ByteString, ReqT> authCookieToRequestFun, LongFunction<Stub> stubFun, Function<Stub, BiConsumer<ReqT, io.deephaven.shadow.core.io.grpc.stub.StreamObserver<RespT>>> callFun, long timeToDeadlineMillis) protected <ReqT,RespT, Stub, V>
VwithRetriesAndReAuth(String who, Function<io.deephaven.shadow.core.com.google.protobuf.ByteString, ReqT> authCookieToRequestFun, LongFunction<Stub> stubFun, Function<Stub, BiConsumer<ReqT, io.deephaven.shadow.core.io.grpc.stub.StreamObserver<RespT>>> callFun, Function<RespT, V> responseMapping, long timeToDeadlineMillis) Perform an RPC call with retries if necessary, including both call retries and necessary authentication retries depending on type of failure.Methods inherited from class com.illumon.iris.controller.ControllerHashtable
addEventHandler, addEventHandlerAndGetData, clear, containsKey, containsValue, entrySet, get, getData, isEmpty, keySet, notifyHandlers, put, putAll, remove, removeEventHandler, size, valuesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllMethods inherited from interface com.illumon.iris.controller.PersistentQueryScriptSource
getScriptBody, getScriptDisplayPathsMethods inherited from interface com.illumon.iris.controller.RemoteScriptSource
getScriptBody, getScriptBodyByOwner, getScriptDisplayPaths, getScriptDisplayPathsByOwner
-
Field Details
-
log
protected final com.fishlib.io.logger.Logger log -
asyncStub
protected final io.deephaven.proto.controller.grpc.ControllerApiGrpc.ControllerApiStub asyncStub -
asyncAclStub
protected final io.deephaven.proto.controller.grpc.AclApiGrpc.AclApiStub asyncAclStub -
authRetryStrategy
-
-
Constructor Details
-
PersistentQueryControllerClient
public PersistentQueryControllerClient(@NotNull String who, @NotNull com.fishlib.io.logger.Logger log, @NotNull io.deephaven.shadow.core.io.grpc.ManagedChannel channel) -
PersistentQueryControllerClient
public PersistentQueryControllerClient(@NotNull String who, @NotNull com.fishlib.io.logger.Logger log, @NotNull io.deephaven.shadow.core.io.grpc.ManagedChannel channel, @NotNull ScheduledExecutorService executorService) -
PersistentQueryControllerClient
public PersistentQueryControllerClient(@NotNull String who, @NotNull com.fishlib.io.logger.Logger log, @NotNull io.deephaven.shadow.core.io.grpc.ManagedChannel channel, @NotNull ScheduledExecutorService executorService, long heartBeatPeriodMillis, long heartBeatTimeoutMillis)
-
-
Method Details
-
withRetriesAndReAuth
protected <ReqT,RespT, RespT withRetriesAndReAuthStub> (String who, Function<io.deephaven.shadow.core.com.google.protobuf.ByteString, ReqT> authCookieToRequestFun, LongFunction<Stub> stubFun, Function<Stub, BiConsumer<ReqT, io.deephaven.shadow.core.io.grpc.stub.StreamObserver<RespT>>> callFun, long timeToDeadlineMillis) -
withRetriesAndReAuth
protected <ReqT,RespT, V withRetriesAndReAuthStub, V> (String who, Function<io.deephaven.shadow.core.com.google.protobuf.ByteString, ReqT> authCookieToRequestFun, LongFunction<Stub> stubFun, Function<Stub, BiConsumer<ReqT, io.deephaven.shadow.core.io.grpc.stub.StreamObserver<RespT>>> callFun, Function<RespT, V> responseMapping, long timeToDeadlineMillis) Perform an RPC call with retries if necessary, including both call retries and necessary authentication retries depending on type of failure. The implementation assumes the existence of a service configuration file at channel creation that enables retries on all stubs that this method will be used with; the retry strategy for the non-reauthentication retries (meaning the stub call itself) will be done according to the strategy defined in that service config. Authentication retries are done when the stub call fails withStatus.UNAUTHENTICATED, and follow the strategy defined byauthRetryStrategy- Type Parameters:
ReqT- The type of the request for the RPC callRespT- The type of the response for the RPC callStub- The type for the stub where the RPC call is madeV- The return value of theresponseMappingand this method- Parameters:
who- A string identifier for the caller used for loggingauthCookieToRequestFun- A function taking an auth cookie and expected to return the request object to provide as an argument to the RPC call to makestubFun- A function taking a time in milliseconds to deadline and expected to return a stub configured with that deadline and any other necessary configuration options for the desired retry strategy (eg, wait for ready)callFun- A function taking a stub (the one produced viaauthCookieToRequestFunand expected to return the RPC call to makeresponseMapping- A function taking the RPC call's response and expected to return a value to be returned by this function. Pass the identity function to get the actual RPC return type and value.timeToDeadlineMillis- A time in milliseconds from now to a deadline when to stop retrying- Returns:
- The result of the RPC call mapped using
responseMapping
-
addQueryConfiguration
Adds a configuration to the controller's hash table.- Parameters:
config- the configuration to add- Returns:
- the serial number of the added configuration
-
determineDispatcher
public PersistentQueryDbServerConfig determineDispatcher(@NotNull PersistentQueryDbServerConfig serverConfig, int heapSizeMB, String workerKind) -
determineDispatcher
public PersistentQueryDbServerConfig determineDispatcher(@NotNull String serverConfigName, int heapSizeMB, String workerKind) -
modifyQueryConfiguration
Modifies a configuration in the controller's hash table, and restart the query if it was running.- Parameters:
config- the updated configuration
-
modifyQueryConfiguration
public void modifyQueryConfiguration(@NotNull PersistentQueryConfiguration config, boolean restartIfRunning) Modifies a configuration in the controller's hash table.- Parameters:
config- the updated configurationrestartIfRunning- restart the query when it is running if set to true
-
removeQueryConfiguration
Removes a configuration from the controller's hash table.- Parameters:
config- the configuration to remove
-
removeQueryConfigurationBySerial
public void removeQueryConfigurationBySerial(long serialId) Removes a configuration from the controller's hash table by serial ID.- Parameters:
serialId- the serial ID of configuration to remove
-
restartQuery
Restart a persistent query. This implementation delegates torestartQueries(List))}.- Parameters:
config- the persistent query configuration to be restarted.
-
restartQueries
Restarts one or more persistent queries.- Parameters:
configs- the persistent query configurations to be restarted
-
restartQueriesBySerial
public void restartQueriesBySerial(@NotNull long[] serialIds) Restarts one or more persistent queries.- Parameters:
serialIds- an array of serial ids to restart
-
restartQueriesBySerial
Restarts one or more persistent queries.- Parameters:
serials- a list of serial ids to restart
-
stopQuery
Stops a persistent query.- Parameters:
config- the persistent query configuration to be stopped.
-
stopQueries
Stops one or more persistent queries.- Parameters:
configs- the persistent query configurations to be stopped
-
stopQueryBySerial
public void stopQueryBySerial(@NotNull long[] serials) Stops one or more persistent query by serial id.- Parameters:
serials- the serial ids of the persistent query configurations to be stopped
-
stopQueryBySerial
-
reloadConfiguration
public void reloadConfiguration()Reloads the controller configuration.
This function causes the PersistentQueryController to reload parts of its configuration without requiring a controller restart. The controller will broadcast the updated configuration to all connected clients.
Note that not all properties or configuration parameters may be reloaded. -
getServerConfiguration
Gets the server configuration from the controller.- Returns:
- the currently loaded controller configuration
-
getScriptDisplayPaths
public Set<String> getScriptDisplayPaths(@NotNull String ownerName, @Nullable ScriptPathLoaderState scriptLoaderState) -
getScriptDisplayPathsByOwner
public Set<String> getScriptDisplayPathsByOwner(@NotNull String ownerName, @Nullable String scriptLoaderStateJson) Description copied from interface:RemoteScriptSourceGet all display paths available to a specific owner and state.- Specified by:
getScriptDisplayPathsByOwnerin interfaceRemoteScriptSource- Parameters:
ownerName- A specific user.scriptLoaderStateJson- The JSON encoded state produced byScriptPathLoaderState.encodeJSON()to get paths from or null to get the latest version.- Returns:
- The paths available to ownerName.
-
getScriptDisplayPaths
-
getScriptDisplayPaths
Description copied from interface:RemoteScriptSourceGet all available display paths for a specific state.- Specified by:
getScriptDisplayPathsin interfaceRemoteScriptSource- Parameters:
scriptLoaderStateJson- The JSON encoded state produced byScriptPathLoaderState.encodeJSON()to get paths from or null to get the latest version.- Returns:
- All display paths.
-
getScriptDisplayPaths
public Set<String> getScriptDisplayPaths(long configSerial, @Nullable ScriptPathLoaderState scriptLoaderState) Description copied from interface:PersistentQueryScriptSourceGet all display paths available to a specific PersistentQuery serial ID and a specific state..- Specified by:
getScriptDisplayPathsin interfacePersistentQueryScriptSource- Parameters:
configSerial- Aserial ID.scriptLoaderState- A specific state to retrieve scripts from orScriptPathLoaderState.NONEto get the latest version.- Returns:
- The paths available to the serial ID.
-
getScriptBody
public String getScriptBody(boolean relative, @NotNull String scriptPath, @Nullable ScriptPathLoaderState scriptLoaderState) -
getScriptBody
public String getScriptBody(boolean relative, @NotNull String scriptPath, @Nullable String scriptLoaderStateJson) Description copied from interface:RemoteScriptSourceGet a script by path and state.- Specified by:
getScriptBodyin interfaceRemoteScriptSource- Parameters:
relative- Is the path a relative path?scriptPath- The path string.scriptLoaderStateJson- The JSON encoded state produced byScriptPathLoaderState.encodeJSON()to get the script from or null to get the latest version.- Returns:
- The contents of the script.
-
getScriptBody
public String getScriptBody(boolean relative, @NotNull String scriptPath, long configSerial, @Nullable ScriptPathLoaderState scriptLoaderState) Description copied from interface:PersistentQueryScriptSourceGet a script by path for a specific serial ID and a specific state.- Specified by:
getScriptBodyin interfacePersistentQueryScriptSource- Parameters:
relative- Is the path a relative path?scriptPath- The path string.configSerial- The Serial ID.scriptLoaderState- A specific state to retrieve scripts from orScriptPathLoaderState.NONEto get the latest version.- Returns:
- The contents of the script.
-
getScriptBody
public String getScriptBody(boolean relative, @NotNull String scriptPath, @NotNull String ownerName, @Nullable ScriptPathLoaderState scriptLoaderState) -
getScriptBodyByOwner
public String getScriptBodyByOwner(boolean relative, @NotNull String scriptPath, @NotNull String ownerName, @Nullable String scriptLoaderStateJson) Description copied from interface:RemoteScriptSourceGet a script by path for a specific owner and state.- Specified by:
getScriptBodyByOwnerin interfaceRemoteScriptSource- Parameters:
relative- Is the path a relative path?scriptPath- The path string.ownerName- The owner.scriptLoaderStateJson- The JSON encoded state produced byScriptPathLoaderState.encodeJSON()to get script from or null to get the latest version.- Returns:
- The contents of the script.
-
getGroupsForUser
Return the groups which a user belongs to.- Parameters:
userContext- the userContext to get membership for- Returns:
- an array of group names that the effective user belongs to
-
getUsersForGroup
Return the users which belong to a group.- Parameters:
group- the group to get membership for- Returns:
- an array of user names that belong to the group
-
isSuperUser
public boolean isSuperUser(@NotNull io.deephaven.enterprise.auth.UserContext userContext) Returns true if the effective user is a superuser.- Parameters:
userContext- the usercontext to query- Returns:
- true if the user is a member of the iris-superusers group.
-
isAclEditor
public boolean isAclEditor(@NotNull io.deephaven.enterprise.auth.UserContext userContext) Returns true if the effective user is an ACL editor- Parameters:
userContext- the usercontext to query- Returns:
- true if the user is a member of the iris-acleditors group.
-
isSchemaManager
public boolean isSchemaManager(@NotNull io.deephaven.enterprise.auth.UserContext userContext) Returns true if the effective user is a Schema manager- Parameters:
userContext- the usercontext to query- Returns:
- true if the user is a member of the iris-schemamanagers group.
-
isQueryManager
public boolean isQueryManager(@NotNull io.deephaven.enterprise.auth.UserContext userContext) Returns true if the effective user is an Query Manager- Parameters:
userContext- the usercontext to query- Returns:
- true if the user is a member of the iris-querymanagers group.
-
getAllGroups
Returns the list of all groups.- Returns:
- an array of all group names
-
getAllUsers
Returns the list of all users.- Returns:
- an array of all user names
-
getPersistentQueryConfiguration
-
getPersistentQueryConfiguration
public PersistentQueryConfiguration getPersistentQueryConfiguration(@NotNull String owner, @NotNull String name) -
getPersistentQueryConfiguration
public PersistentQueryConfiguration getPersistentQueryConfiguration(long configSerial, @Nullable String owner, @Nullable String name) -
publishTemporaryQueries
public void publishTemporaryQueries(@NotNull com.fishlib.io.logger.Logger log, @NotNull PersistentQueryConfiguration... configs) -
updateQueryStatus
- Throws:
IOException
-
getControllerClient
@NotNull public static PersistentQueryControllerClient getControllerClient(@NotNull com.fishlib.io.logger.Logger log) -
getControllerClient
@NotNull public static PersistentQueryControllerClient getControllerClient(@NotNull com.fishlib.io.logger.Logger log, boolean doSubscription) -
getControllerClient
@NotNull public static PersistentQueryControllerClient getControllerClient(@NotNull String who, @NotNull com.fishlib.io.logger.Logger log) -
getControllerClient
@NotNull public static PersistentQueryControllerClient getControllerClient(@NotNull String who, @NotNull com.fishlib.io.logger.Logger log, boolean doSubscription) -
setupAsyncStub
protected io.deephaven.proto.controller.grpc.ControllerApiGrpc.ControllerApiStub setupAsyncStub(long deadlineAfterMillis) -
setupAsyncAclStub
protected io.deephaven.proto.controller.grpc.AclApiGrpc.AclApiStub setupAsyncAclStub(long deadlineAfterMillis) -
makeAndStartAuthRetryBackoffContext
-
getAuthCookie
protected io.deephaven.shadow.core.com.google.protobuf.ByteString getAuthCookie(String who, RetryBackoffContext backoffContext) -
executorService
-
addServiceStatusListener
Add a status listener. If the service is already available, the listener will be invoked immediately on the thread pool.- Parameters:
listener- the listener to add
-
removeServiceStatusListener
-
addReloadConfigurationListener
public void addReloadConfigurationListener(Consumer<PersistentQueryControllerConfiguration> reloadListener) -
isConnected
public boolean isConnected()Check if this client can communicate with the server.- Returns:
- true if it can
-
authenticate
public boolean authenticate(@NotNull io.deephaven.enterprise.auth.AuthToken token) Use the specified auth token to authenticate this client to the hashtable server.- Parameters:
token- the token for authentication- Returns:
- true if authentication was successful.
-
authenticateAsync
public CompletableFuture<io.deephaven.shadow.core.com.google.protobuf.ByteString> authenticateAsync(@NotNull io.deephaven.enterprise.auth.AuthToken token) Use the specified auth token to authenticate this client to the hashtable server.- Parameters:
token- the token for authentication- Returns:
- a CompletableFuture that can be used to asynchronously wait for authentication to complete.
-
authenticateAsync
protected CompletableFuture<io.deephaven.shadow.core.com.google.protobuf.ByteString> authenticateAsync(long maxTimeToDeadlineMillis, @NotNull io.deephaven.enterprise.auth.AuthToken token) -
invalidateCookie
protected void invalidateCookie() -
subscribeToAll
public void subscribeToAll()Subscribe to the complete hash table. -
shutdown
- Throws:
IOException
-
handleConnectionLost
protected void handleConnectionLost() -
handleConnectionReestablished
protected void handleConnectionReestablished() -
setEphemeral
public void setEphemeral()Set the channel as ephemeral. In this mode when a heartbeat is missed, the client halts further heartbeats, ends any active grpc stream, and generates no further connection events.
-