Class SolrZkClient
- All Implemented Interfaces:
Closeable,AutoCloseable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfaceA function that takes a transaction builder and returns a curator operation.static interfacestatic classprotected static interface -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidatomicUpdate(String path, BiFunction<org.apache.zookeeper.data.Stat, byte[], byte[]> editor) voidatomicUpdate(String path, Function<byte[], byte[]> editor) static ThrowableCheck to see if a Throwable is an InterruptedException, and if it is, set the thread interrupt flagvoidvoidvoidclose()static booleancontainsChroot(String zkHost) Validates if zkHost contains a chroot.Returns path of created nodecreate(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.data.Stat stat) Returns path of created nodeprotected org.apache.curator.framework.api.ACLProviderprotected ZkCredentialsInjectorprotected ZkCredentialsProvidervoidvoiddownConfig(String confName, Path confPath) voiddownloadFromZK(String zkPath, Path dir) voidensureExists(String path) Create a node if it does not existvoidensureExists(String path, byte[] data) Create a node if it does not existvoidensureExists(String path, byte[] data, org.apache.zookeeper.CreateMode createMode) Create a node if it does not existvoidensureExists(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, int skipPathParts) Create a node if it does not existReturns true if path existsorg.apache.zookeeper.data.StatReturn the stat of the node of the given path.getAbsolutePath(String path) List<org.apache.zookeeper.data.ACL> getChildren(String path, org.apache.zookeeper.Watcher watcher) Returns children of the node at the pathgetChildren(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat) Returns children of the node at the pathGets the raw config node /zookeeper/config as returned by server.org.apache.curator.framework.CuratorFrameworkbyte[]Returns node's dataorg.apache.curator.framework.api.ACLProviderintlongintbooleanisClosed()booleanReturns true if client is connectedvoidCreates the path in ZooKeeper, creating each node as necessary.voidvoidCreates the path in ZooKeeper, creating each node as necessary.voidvoidCreates the path in ZooKeeper, creating each node as necessary.voidmakePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher) Creates the path in ZooKeeper, creating each node as necessary.voidmakePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists) Creates the path in ZooKeeper, creating each node as necessary.voidmakePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists, int skipPathParts) Creates the path in ZooKeeper, creating each node as necessary.voidvoidvoidmakePath(String zkPath, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher) voidList<org.apache.curator.framework.api.transaction.CuratorTransactionResult> List<org.apache.curator.framework.api.transaction.CuratorTransactionResult> multi(SolrZkClient.CuratorOpBuilder... ops) voidprintLayout(String path, int indent, StringBuilder string) Fills string with printout of current ZooKeeper layout.voidprotected <T> TrunWithCorrectThrows(String action, SolrZkClient.SupplierWithException<T> func) org.apache.zookeeper.data.StatSet the ACL on a single node in ZooKeeper.org.apache.zookeeper.data.StatWrite data to ZooKeeper.org.apache.zookeeper.data.StatReturns node's stateorg.apache.zookeeper.data.StatWrite file to ZooKeeper - default system encoding used.voidvoidupdateACLs(String root) Update all ACLs for a zk tree based on our configuredZkACLProvider.voiduploadToZK(Path rootPath, String zkPath, Pattern filenameExclusions) org.apache.zookeeper.WatcherwrapWatcher(org.apache.zookeeper.Watcher watcher) Wraps the watcher so that it doesn't fire off ZK's event queue.void
-
Field Details
-
ZK_CRED_PROVIDER_CLASS_NAME_VM_PARAM_NAME
- See Also:
-
ZK_ACL_PROVIDER_CLASS_NAME_VM_PARAM_NAME
- See Also:
-
ZK_CREDENTIALS_INJECTOR_CLASS_NAME_VM_PARAM_NAME
- See Also:
-
-
Constructor Details
-
SolrZkClient
-
-
Method Details
-
getMetrics
-
getZkClientTimeout
public int getZkClientTimeout() -
getCuratorFramework
public org.apache.curator.framework.CuratorFramework getCuratorFramework() -
createZkCredentialsToAddAutomatically
-
createACLProvider
protected org.apache.curator.framework.api.ACLProvider createACLProvider() -
createZkCredentialsInjector
-
isConnected
public boolean isConnected()Returns true if client is connected -
delete
public void delete(String path, int version) throws InterruptedException, org.apache.zookeeper.KeeperException - Throws:
InterruptedExceptionorg.apache.zookeeper.KeeperException
-
wrapWatcher
public org.apache.zookeeper.Watcher wrapWatcher(org.apache.zookeeper.Watcher watcher) Wraps the watcher so that it doesn't fire off ZK's event queue. In order to guarantee that a watch object will only be triggered once for a given notification, users need to wrap their watcher using this method before callingexists(String, org.apache.zookeeper.Watcher)orgetData(String, org.apache.zookeeper.Watcher, org.apache.zookeeper.data.Stat). -
exists
public org.apache.zookeeper.data.Stat exists(String path, org.apache.zookeeper.Watcher watcher) throws org.apache.zookeeper.KeeperException, InterruptedException Return the stat of the node of the given path. Return null if no such a node exists.If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that creates/delete the node or sets the data on the node.
- Parameters:
path- the node pathwatcher- explicit watcher- Returns:
- the stat of the node of the given path; return null if no such a node exists.
- Throws:
org.apache.zookeeper.KeeperException- If the server signals an errorInterruptedException- If the server transaction is interrupted.IllegalArgumentException- if an invalid path is specified
-
exists
public Boolean exists(String path) throws org.apache.zookeeper.KeeperException, InterruptedException Returns true if path exists- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
getChildren
public List<String> getChildren(String path, org.apache.zookeeper.Watcher watcher) throws org.apache.zookeeper.KeeperException, InterruptedException Returns children of the node at the path- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
getChildren
public List<String> getChildren(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, InterruptedException Returns children of the node at the path- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
getData
public byte[] getData(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, InterruptedException Returns node's data- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
getNode
public SolrZkClient.NodeData getNode(String path, org.apache.zookeeper.Watcher watcher) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
setData
public org.apache.zookeeper.data.Stat setData(String path, byte[] data, int version) throws org.apache.zookeeper.KeeperException, InterruptedException Returns node's state- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
atomicUpdate
public void atomicUpdate(String path, Function<byte[], byte[]> editor) throws org.apache.zookeeper.KeeperException, InterruptedException- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
atomicUpdate
public void atomicUpdate(String path, BiFunction<org.apache.zookeeper.data.Stat, byte[], throws org.apache.zookeeper.KeeperException, InterruptedExceptionbyte[]> editor) - Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
create
public String create(String path, byte[] data, org.apache.zookeeper.CreateMode createMode) throws org.apache.zookeeper.KeeperException, InterruptedException Returns path of created node- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
create
public String create(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, InterruptedException Returns path of created node- Parameters:
stat- Output argument that captures created node details- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
Creates the path in ZooKeeper, creating each node as necessary.e.g. If
path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String path, boolean failOnExists) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String path, byte[] data, boolean failOnExists) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String path, Path data) throws IOException, org.apache.zookeeper.KeeperException, InterruptedException - Throws:
IOExceptionorg.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String path, org.apache.zookeeper.CreateMode createMode) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String path, byte[] data) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.- Parameters:
data- to set on the last zkNode- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.e.g. If
path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.- Parameters:
data- to set on the last zkNode- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.e.g. If
path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.- Parameters:
data- to set on the last zkNode- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.e.g. If
path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.- Parameters:
data- to set on the last zkNode- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists, int skipPathParts) throws org.apache.zookeeper.KeeperException, InterruptedException Creates the path in ZooKeeper, creating each node as necessary.e.g. If
path=/solr/group/nodeand none of the nodes, solr, group, node exist, each will be created.skipPathParts will force the call to fail if the first skipPathParts do not exist already.
Note: if failOnExists == false then we will always overwrite the existing data with the given data
- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
makePath
public void makePath(String zkPath, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
ensureExists
public void ensureExists(String path) throws org.apache.zookeeper.KeeperException, InterruptedException Create a node if it does not exist- Parameters:
path- the path at which to create the znode- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
ensureExists
public void ensureExists(String path, byte[] data) throws org.apache.zookeeper.KeeperException, InterruptedException Create a node if it does not exist- Parameters:
path- the path at which to create the znodedata- the optional data to set on the znode- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
ensureExists
public void ensureExists(String path, byte[] data, org.apache.zookeeper.CreateMode createMode) throws org.apache.zookeeper.KeeperException, InterruptedException Create a node if it does not exist- Parameters:
path- the path at which to create the znodedata- the optional data to set on the znodecreateMode- the mode with which to create the znode- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
ensureExists
public void ensureExists(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, int skipPathParts) throws org.apache.zookeeper.KeeperException, InterruptedException Create a node if it does not exist- Parameters:
path- the path at which to create the znodedata- the optional data to set on the znodecreateMode- the mode with which to create the znodeskipPathParts- how many path elements to skip- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
setData
public org.apache.zookeeper.data.Stat setData(String path, byte[] data) throws org.apache.zookeeper.KeeperException, InterruptedException Write data to ZooKeeper.- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
setData
public org.apache.zookeeper.data.Stat setData(String path, Path source) throws IOException, org.apache.zookeeper.KeeperException, InterruptedException Write file to ZooKeeper - default system encoding used.- Parameters:
path- path to upload file to e.g. /solr/conf/solrconfig.xmlsource- a filepath to read data from- Throws:
IOExceptionorg.apache.zookeeper.KeeperExceptionInterruptedException
-
multi
public List<org.apache.curator.framework.api.transaction.CuratorTransactionResult> multi(SolrZkClient.CuratorOpBuilder... ops) throws InterruptedException, org.apache.zookeeper.KeeperException - Throws:
InterruptedExceptionorg.apache.zookeeper.KeeperException
-
multi
public List<org.apache.curator.framework.api.transaction.CuratorTransactionResult> multi(List<SolrZkClient.CuratorOpBuilder> ops) throws InterruptedException, org.apache.zookeeper.KeeperException - Throws:
InterruptedExceptionorg.apache.zookeeper.KeeperException
-
printLayout
public void printLayout(String path, int indent, StringBuilder string) throws org.apache.zookeeper.KeeperException, InterruptedException Fills string with printout of current ZooKeeper layout.- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
printLayoutToStream
public void printLayoutToStream(PrintStream out) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isClosed
public boolean isClosed() -
getZkSessionId
public long getZkSessionId() -
getZkSessionTimeout
public int getZkSessionTimeout() -
containsChroot
Validates if zkHost contains a chroot. See http://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#ch_zkSessions -
checkInterrupted
Check to see if a Throwable is an InterruptedException, and if it is, set the thread interrupt flag- Parameters:
e- the Throwable- Returns:
- the Throwable
-
getZkServerAddress
- Returns:
- the address of the zookeeper cluster
-
getChroot
- Returns:
- the ChRoot that this client is using for the ZK cluster
-
getAbsolutePath
- Returns:
- the given path's absolute path in the ZK cluster
-
getConfig
Gets the raw config node /zookeeper/config as returned by server. Response may look likeserver.1=localhost:2780:2783:participant;localhost:2791 server.2=localhost:2781:2784:participant;localhost:2792 server.3=localhost:2782:2785:participant;localhost:2793 version=400000003
- Returns:
- Multi line string representing the config. For standalone ZK this will return empty string
-
getZkACLProvider
public org.apache.curator.framework.api.ACLProvider getZkACLProvider() -
getACL
public List<org.apache.zookeeper.data.ACL> getACL(String path, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, InterruptedException - Returns:
- the ACLs on a single node in ZooKeeper.
- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
setACL
public org.apache.zookeeper.data.Stat setACL(String path, List<org.apache.zookeeper.data.ACL> acls) throws InterruptedException, org.apache.zookeeper.KeeperException Set the ACL on a single node in ZooKeeper. This will replace all existing ACL on that node.- Parameters:
path- path to set ACL on e.g. /solr/conf/solrconfig.xmlacls- a list ofACLs to be applied- Returns:
- the stat of the node
- Throws:
InterruptedExceptionorg.apache.zookeeper.KeeperException
-
updateACLs
public void updateACLs(String root) throws org.apache.zookeeper.KeeperException, InterruptedException Update all ACLs for a zk tree based on our configuredZkACLProvider.- Parameters:
root- the root node to recursively update- Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
runWithCorrectThrows
protected <T> T runWithCorrectThrows(String action, SolrZkClient.SupplierWithException<T> func) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
clean
- Throws:
InterruptedExceptionorg.apache.zookeeper.KeeperException
-
clean
public void clean(String path, Predicate<String> nodeFilter) throws InterruptedException, org.apache.zookeeper.KeeperException - Throws:
InterruptedExceptionorg.apache.zookeeper.KeeperException
-
upConfig
- Throws:
IOException
-
listZnode
public String listZnode(String path, Boolean recurse) throws org.apache.zookeeper.KeeperException, InterruptedException - Throws:
org.apache.zookeeper.KeeperExceptionInterruptedException
-
downConfig
- Throws:
IOException
-
zkTransfer
public void zkTransfer(String src, Boolean srcIsZk, String dst, Boolean dstIsZk, Boolean recurse) throws org.apache.solr.client.solrj.SolrServerException, org.apache.zookeeper.KeeperException, InterruptedException, IOException - Throws:
org.apache.solr.client.solrj.SolrServerExceptionorg.apache.zookeeper.KeeperExceptionInterruptedExceptionIOException
-
moveZnode
public void moveZnode(String src, String dst) throws org.apache.solr.client.solrj.SolrServerException, org.apache.zookeeper.KeeperException, InterruptedException - Throws:
org.apache.solr.client.solrj.SolrServerExceptionorg.apache.zookeeper.KeeperExceptionInterruptedException
-
uploadToZK
- Throws:
IOException
-
downloadFromZK
- Throws:
IOException
-