Class ControllerClientGrpc
A client for subscribing to state from the PersistentQueryController and manipulating persistent queries.
In order to connect to the Persistent Query Controller you must first add an ControllerClientGrpc.Observer then
authenticate(AuthToken). You can use the authentication client to
create an AuthToken for this. Once authenticated, a call to subscribe() or subscribeToAll()
will request a complete snapshot of queries that the authenticated user is allowed to see. Until you call
shutdown() the Persistent Query Controller will deliver updates to the queries to the ControllerClientGrpc.Observers, and
you may use the query manipulation methods to manage queries.
Warning:
Before authentication and subscription you must add an ControllerClientGrpc.Observer to handle
asynchronous events, like a successful connection or update delivery. If you instead call
authenticate(AuthToken) and subscribe() before adding an observer, you will miss delivery of the
initial snapshot of query configuration and state.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn object that will be notified of changes to the state of the Controller.static classA basicControllerClientGrpc.Observerimplementation with do-nothing methods. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AclApiGrpc.AclApiStubprotected final ControllerApiGrpc.ControllerApiStubprotected final RetryStrategystatic final longThis value indicates that the Controller should assign a new serial to the query when set asPersistentQueryConfigMessage.getSerial() -
Constructor Summary
ConstructorsConstructorDescriptionControllerClientGrpc(String who, io.deephaven.shadow.core.io.grpc.ManagedChannel channel, ScheduledExecutorService executorService, AuthenticationClient authenticationClient, long heartBeatPeriodMillis, long heartBeatTimeoutMillis) ControllerClientGrpc(String who, io.deephaven.shadow.core.io.grpc.ManagedChannel channel, ScheduledExecutorService executorService, TokenFactoryFactory.TokenFactory tokenFactory, long heartBeatPeriodMillis, long heartBeatTimeoutMillis) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObserver(ControllerClientGrpc.Observer observer) Add a status listener.longAdds a configuration to the controller's hash table.booleanauthenticate(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, AuthToken token) CompletableFuture<io.deephaven.shadow.core.com.google.protobuf.ByteString>authenticateAsync(AuthToken token) Use the specified auth token to authenticate this client to the hashtable server.determineDispatcher(PQDBServerConfigMessage serverConfig, int heapSizeMB, String workerKind) determineDispatcher(String serverConfigName, int heapSizeMB, String workerKind) String[]Returns the list of all groups.getAllScriptPaths(String loaderStateJson) Fetch all available script display paths based on the currently authenticated user.getAllScriptPaths(String loaderStateJson, boolean useRelativePath) Fetch all available script relative or display paths based on the currently authenticated user.String[]Returns the list of all users.Gets the server configuration from the controller.String[]getGroupsForUser(UserContext userContext) Return the groups which a user belongs to.getScriptBody(String scriptPath, String loaderStateJson, boolean isPathRelative) Fetch the body of the specified script as the currently authenticated user.getScriptBodyByOwner(String owner, String scriptPath, String loaderStateJson, boolean isPathRelative) Fetch the body of the specified script as the specified user.getScriptBodyBySerial(long querySerial, String scriptPath, String loaderStateJson, boolean isPathRelative) Fetch the body of the specified script using the details of the specified query.getScriptPathsByOwner(String owner, String loaderStateJson) Fetch all available script display paths based on the specified user.getScriptPathsByOwner(String owner, String loaderStateJson, boolean useRelativePath) Fetch all available script relative or display paths based on the specified user.getScriptPathsBySerial(long querySerial, String loaderStateJson) Fetch all available script display paths based on the configuration of a query.getScriptPathsBySerial(long querySerial, String loaderStateJson, boolean useRelativePath) Fetch all available script relative or display paths based on the configuration of a query.String[]getUsersForGroup(String group) Return the users which belong to a group.protected voidprotected voidbooleanisAclEditor(UserContext userContext) Returns true if the effective user is an ACL editorbooleanCheck if this client can communicate with the server.booleanisQueryManager(UserContext userContext) Returns true if the effective user is an Query ManagerbooleanisRunning(PersistentQueryStatusEnum status) booleanisSchemaManager(UserContext userContext) Returns true if the effective user is a Schema managerbooleanisSuperUser(UserContext userContext) Returns true if the effective user is a superuser.booleanisTerminal(PersistentQueryStatusEnum status) static NamedStringListmakeNamedStringList(String name, String[] list) Create aNamedStringListobject from a string array and name.static NamedStringListmakeNamedStringList(String name, Collection<String> list) Create aNamedStringListobject from a collection of strings and name.voidModifies a configuration in the controller's hash table, and restart the query if it was running.voidmodifyQueryConfiguration(PersistentQueryConfigMessage config, boolean restartIfRunning) Modifies a configuration in the controller's hash table.voidpublishStatusUpdate(long querySerial, String processInfoId, PersistentQueryStatusEnum status, Map<String, ExportedObjectInfoMessage> scopeFields, Map<String, String[]> tableGroups) Publish a status update for the specified query.voidCommand the PersistentQueryController to reload parts of its configuration without requiring a controller restart.voidremoveObserver(ControllerClientGrpc.Observer observer) voidRemoves a configuration from the controller's hash table.voidremoveQueryConfigurationBySerial(long serialId) Removes a configuration from the controller's hash table by serial ID.voidrestartQueries(List<PersistentQueryConfigMessage> 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.voidrestartReplicas(List<ReplicaSpecifier> replicas) serverSelectionAdmin(String command) Execute a server selection provider admin command.Gets the server selection provider status.voidSet the channel as ephemeral.voidshutdown()voidSimulate a connection lost for testingvoidstopQueries(List<PersistentQueryConfigMessage> 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) Stop a set of queries by their serials.voidSubscribe to the complete hash table.protected <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.
-
Field Details
-
UNASSIGNED_SERIAL
public static final long UNASSIGNED_SERIALThis value indicates that the Controller should assign a new serial to the query when set asPersistentQueryConfigMessage.getSerial()- See Also:
-
asyncStub
-
asyncAclStub
-
authRetryStrategy
-
-
Constructor Details
-
ControllerClientGrpc
public ControllerClientGrpc(@NotNull String who, @NotNull io.deephaven.shadow.core.io.grpc.ManagedChannel channel, @NotNull ScheduledExecutorService executorService, @NotNull AuthenticationClient authenticationClient, long heartBeatPeriodMillis, long heartBeatTimeoutMillis) -
ControllerClientGrpc
public ControllerClientGrpc(@NotNull String who, @NotNull io.deephaven.shadow.core.io.grpc.ManagedChannel channel, @NotNull ScheduledExecutorService executorService, @NotNull TokenFactoryFactory.TokenFactory tokenFactory, 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
-
authenticate
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
@NotNull public CompletableFuture<io.deephaven.shadow.core.com.google.protobuf.ByteString> authenticateAsync(@NotNull 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 AuthToken token) -
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. -
isTerminal
-
isRunning
-
addObserver
Add a status listener. If the service is already available, the listener will be invoked immediately on the thread pool.- Parameters:
observer- the listener to add
-
removeObserver
-
isConnected
public boolean isConnected()Check if this client can communicate with the server.- Returns:
- true if it can
-
subscribeToAll
public void subscribeToAll()Subscribe to the complete hash table. -
shutdown
- Throws:
IOException
-
getConfiguration
Gets the server configuration from the controller.- Returns:
- the currently loaded controller configuration
-
reloadConfiguration
public void reloadConfiguration()Command the PersistentQueryController to reload parts of its configuration without requiring a controller restart. The controller will broadcast the updated configuration to all connected clients.- ApiNote:
- Not all properties or configuration parameters may be reloaded.
-
serverSelectionStatus
Gets the server selection provider status.- Returns:
- the free-form status information
-
serverSelectionAdmin
Execute a server selection provider admin command.- Returns:
- the free-form result
-
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 PQDBServerConfigMessage determineDispatcher(@NotNull PQDBServerConfigMessage serverConfig, int heapSizeMB, String workerKind) -
determineDispatcher
public PQDBServerConfigMessage 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 PersistentQueryConfigMessage 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
-
restartReplicas
-
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
Stop a set of queries by their serials.- Parameters:
serials- the serials to stop
-
publishStatusUpdate
public void publishStatusUpdate(long querySerial, String processInfoId, @Nullable PersistentQueryStatusEnum status, @Nullable Map<String, ExportedObjectInfoMessage> scopeFields, @Nullable Map<String, String[]> tableGroups) Publish a status update for the specified query.- Parameters:
querySerial- The query serial to update.status- An optional status update, null if not presentscopeFields- an optional set of field updates, null if not presenttableGroups- an optional set of table groups, null if not present
-
getScriptPathsByOwner
@NotNull public Set<String> getScriptPathsByOwner(@NotNull String owner, @Nullable String loaderStateJson) Fetch all available script display paths based on the specified user.- Parameters:
owner- the userloaderStateJson- optional extra script loader state information in JSON format- Returns:
- the set of available script paths.
-
getScriptPathsBySerial
@NotNull public Set<String> getScriptPathsBySerial(long querySerial, @Nullable String loaderStateJson) Fetch all available script display paths based on the configuration of a query.- Parameters:
querySerial- the query serialloaderStateJson- optional extra script loader state information in JSON format- Returns:
- the set of available script paths.
-
getAllScriptPaths
Fetch all available script display paths based on the currently authenticated user.- Parameters:
loaderStateJson- optional extra script loader state information in JSON format- Returns:
- the set of available script paths.
-
getScriptPathsByOwner
@NotNull public Set<String> getScriptPathsByOwner(@NotNull String owner, @Nullable String loaderStateJson, boolean useRelativePath) Fetch all available script relative or display paths based on the specified user.- Parameters:
owner- the userloaderStateJson- optional extra script loader state information in JSON formatuseRelativePath- whether to return relative or display script paths- Returns:
- the set of available script paths.
-
getScriptPathsBySerial
@NotNull public Set<String> getScriptPathsBySerial(long querySerial, @Nullable String loaderStateJson, boolean useRelativePath) Fetch all available script relative or display paths based on the configuration of a query.- Parameters:
querySerial- the query serialloaderStateJson- optional extra script loader state information in JSON formatuseRelativePath- whether to return relative or display script paths- Returns:
- the set of available script paths.
-
getAllScriptPaths
@NotNull public Set<String> getAllScriptPaths(@Nullable String loaderStateJson, boolean useRelativePath) Fetch all available script relative or display paths based on the currently authenticated user.- Parameters:
loaderStateJson- optional extra script loader state information in JSON formatuseRelativePath- whether to return relative or display script paths- Returns:
- the set of available script paths.
-
getScriptBody
@Nullable public String getScriptBody(@NotNull String scriptPath, @Nullable String loaderStateJson, boolean isPathRelative) Fetch the body of the specified script as the currently authenticated user.- Parameters:
scriptPath- the path to the scriptloaderStateJson- optional extra script loader state information in JSON formatisPathRelative-trueif the path should be treated as a relative path- Returns:
- the text of the script body, or null if it could not be fetched
-
getScriptBodyBySerial
@Nullable public String getScriptBodyBySerial(long querySerial, @NotNull String scriptPath, @Nullable String loaderStateJson, boolean isPathRelative) Fetch the body of the specified script using the details of the specified query.- Parameters:
querySerial- the serial of the queryscriptPath- the path to the scriptloaderStateJson- optional extra script loader state information in JSON formatisPathRelative-trueif the path should be treated as a relative path- Returns:
- the text of the script body, or null if it could not be fetched
-
getScriptBodyByOwner
@Nullable public String getScriptBodyByOwner(@NotNull String owner, @NotNull String scriptPath, @Nullable String loaderStateJson, boolean isPathRelative) Fetch the body of the specified script as the specified user.- Parameters:
owner- the user to fetch the script asscriptPath- the path to the scriptloaderStateJson- optional extra script loader state information in JSON formatisPathRelative-trueif the path should be treated as a relative path- Returns:
- the text of the script body, or null if it could not be fetched
-
getGroupsForUser
Return the groups which a user belongs to.- Parameters:
userContext- theUserContextto 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 usernames that belong to the group
-
isSuperUser
Returns true if the effective user is a superuser.- Parameters:
userContext- theUserContextto query- Returns:
- true if the user is a member of the iris-superusers group.
-
isAclEditor
Returns true if the effective user is an ACL editor- Parameters:
userContext- theUserContextto query- Returns:
- true if the user is a member of the iris-acleditors group.
-
isSchemaManager
Returns true if the effective user is a Schema manager- Parameters:
userContext- theUserContextto query- Returns:
- true if the user is a member of the iris-schemamanagers group.
-
isQueryManager
Returns true if the effective user is an Query Manager- Parameters:
userContext- theUserContextto 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
-
handleConnectionLost
protected void handleConnectionLost() -
handleConnectionReestablished
protected void handleConnectionReestablished() -
makeNamedStringList
Create aNamedStringListobject from a string array and name.- Parameters:
name- the name to uselist- the array of values- Returns:
- a new
NamedStringList
-
makeNamedStringList
@NotNull public static NamedStringList makeNamedStringList(@NotNull String name, @Nullable Collection<String> list) Create aNamedStringListobject from a collection of strings and name.- Parameters:
name- the name to uselist- the collection of values- Returns:
- a new
NamedStringList
-
simulateConnectionLost
Simulate a connection lost for testing
-