Search in sources :

Example 1 with PathType

use of org.apache.solr.core.backup.repository.BackupRepository.PathType in project lucene-solr by apache.

the class BackupManager method uploadToZk.

private void uploadToZk(SolrZkClient zkClient, URI sourceDir, String destZkPath) throws IOException {
    Preconditions.checkArgument(repository.exists(sourceDir), "Path {} does not exist", sourceDir);
    Preconditions.checkArgument(repository.getPathType(sourceDir) == PathType.DIRECTORY, "Path {} is not a directory", sourceDir);
    for (String file : repository.listAll(sourceDir)) {
        String zkNodePath = destZkPath + "/" + file;
        URI path = repository.resolve(sourceDir, file);
        PathType t = repository.getPathType(path);
        switch(t) {
            case FILE:
                {
                    try (IndexInput is = repository.openInput(sourceDir, file, IOContext.DEFAULT)) {
                        // probably ok since the config file should be small.
                        byte[] arr = new byte[(int) is.length()];
                        is.readBytes(arr, 0, (int) is.length());
                        zkClient.makePath(zkNodePath, arr, true);
                    } catch (KeeperException | InterruptedException e) {
                        throw new IOException(e);
                    }
                    break;
                }
            case DIRECTORY:
                {
                    if (!file.startsWith(".")) {
                        uploadToZk(zkClient, path, zkNodePath);
                    }
                    break;
                }
            default:
                throw new IllegalStateException("Unknown path type " + t);
        }
    }
}
Also used : PathType(org.apache.solr.core.backup.repository.BackupRepository.PathType) IndexInput(org.apache.lucene.store.IndexInput) IOException(java.io.IOException) URI(java.net.URI)

Aggregations

IOException (java.io.IOException)1 URI (java.net.URI)1 IndexInput (org.apache.lucene.store.IndexInput)1 PathType (org.apache.solr.core.backup.repository.BackupRepository.PathType)1