Search in sources :

Example 6 with ToolsException

use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.

the class BackupManager method backupEdgeShard.

private void backupEdgeShard(Shard shard) {
    String desc = String.format("backing up edges[shard %s]", shard);
    Edges edges = null;
    String page = this.initPage();
    TraverserManager g = client.traverser();
    do {
        try {
            String p = page;
            if (page == null) {
                edges = retry(() -> g.edges(shard), desc);
            } else {
                edges = retry(() -> g.edges(shard, p), desc);
            }
        } catch (ToolsException e) {
            this.exceptionHandler(e, HugeType.EDGE, shard);
        }
        if (edges == null) {
            return;
        }
        List<Edge> edgeList = edges.results();
        if (edgeList == null || edgeList.isEmpty()) {
            return;
        }
        long count = this.backup(HugeType.EDGE, suffix.get(), edgeList);
        this.edgeCounter.getAndAdd(count);
        Printer.printInBackward(this.edgeCounter.get());
    } while ((page = edges.page()) != null);
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) Edges(com.baidu.hugegraph.structure.graph.Edges) Edge(com.baidu.hugegraph.structure.graph.Edge) TraverserManager(com.baidu.hugegraph.driver.TraverserManager)

Example 7 with ToolsException

use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.

the class LocalDirectory method removeDirectory.

private static void removeDirectory(String directory) {
    File dir = new File(directory);
    E.checkState(dir.exists() && dir.isDirectory(), "The directory does not exist: '%s'", dir.getAbsolutePath());
    try {
        FileUtils.deleteDirectory(dir);
    } catch (IOException e) {
        throw new ToolsException("Failed to delete directory '%s'", dir.getAbsolutePath());
    }
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) IOException(java.io.IOException) File(java.io.File)

Example 8 with ToolsException

use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.

the class HdfsDirectory method removeDirectory.

@Override
public void removeDirectory() {
    FileSystem fs = this.fileSystem();
    Path path = new Path(this.directory());
    try {
        E.checkState(fs.exists(path) && fs.getFileStatus(path).isDirectory(), "The directory does not exist: '%s'", this.directory());
        fs.delete(path, true);
    } catch (IOException e) {
        throw new ToolsException("Failed to delete directory '%s'", path);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ToolsException(com.baidu.hugegraph.exception.ToolsException) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException)

Example 9 with ToolsException

use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.

the class HdfsDirectory method files.

@Override
public List<String> files() {
    FileSystem fs = this.fileSystem();
    FileStatus[] statuses;
    try {
        statuses = fs.listStatus(new Path(this.directory()));
    } catch (IOException e) {
        throw new ToolsException("Failed to get file list in directory " + "'%s'", e, this.directory());
    }
    List<String> files = new ArrayList<>();
    for (FileStatus status : statuses) {
        if (status.isFile()) {
            files.add(status.getPath().getName());
        }
    }
    return files;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) ToolsException(com.baidu.hugegraph.exception.ToolsException) FileSystem(org.apache.hadoop.fs.FileSystem) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 10 with ToolsException

use of com.baidu.hugegraph.exception.ToolsException in project incubator-hugegraph-toolchain by apache.

the class HdfsDirectory method ensureDirectoryExist.

@Override
public void ensureDirectoryExist(boolean create) {
    FileSystem fs = this.fileSystem();
    Path path = new Path(this.directory());
    try {
        if (fs.exists(path)) {
            E.checkState(fs.getFileStatus(path).isDirectory(), "Can't use directory '%s' because " + "a file with same name exists.", this.directory());
        } else {
            if (create) {
                E.checkState(fs.mkdirs(path), "The directory does not exist and created " + "failed: '%s'", path.toString());
            } else {
                E.checkState(false, "The directory does not exist: '%s'", path.toString());
            }
        }
    } catch (IOException e) {
        throw new ToolsException("Invalid directory '%s'", e, this.directory());
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ToolsException(com.baidu.hugegraph.exception.ToolsException) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException)

Aggregations

ToolsException (com.baidu.hugegraph.exception.ToolsException)15 IOException (java.io.IOException)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 BufferedReader (java.io.BufferedReader)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 OutputStream (java.io.OutputStream)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 Path (org.apache.hadoop.fs.Path)3 TraverserManager (com.baidu.hugegraph.driver.TraverserManager)2 Edge (com.baidu.hugegraph.structure.graph.Edge)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 GraphElement (com.baidu.hugegraph.structure.GraphElement)1 Belong (com.baidu.hugegraph.structure.auth.Belong)1 Edges (com.baidu.hugegraph.structure.graph.Edges)1 Shard (com.baidu.hugegraph.structure.graph.Shard)1 Vertex (com.baidu.hugegraph.structure.graph.Vertex)1 Vertices (com.baidu.hugegraph.structure.graph.Vertices)1