Search in sources :

Example 11 with ToolsException

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

the class BackupManager method removeShardsFilesIfExists.

protected void removeShardsFilesIfExists() {
    File logDir = new File(this.logDir());
    E.checkArgument(logDir.exists() && logDir.isDirectory(), "The log directory '%s' not exists or is file", logDir);
    for (File file : logDir.listFiles()) {
        if (file.getName().endsWith(SHARDS_SUFFIX)) {
            try {
                FileUtils.forceDelete(file);
            } catch (IOException e) {
                throw new ToolsException("Failed to delete shard file " + "'%s'", file);
            }
        }
    }
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) IOException(java.io.IOException) File(java.io.File)

Example 12 with ToolsException

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

the class BackupManager method backupVertexShard.

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

Example 13 with ToolsException

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

the class BackupRestoreBaseManager method writeText.

protected long writeText(String path, HugeType type, List<?> list, boolean compress, String label, boolean allProperties, List<String> properties) {
    OutputStream os = this.outputStream(path, compress);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(LBUF_SIZE);
    StringBuilder builder = new StringBuilder(LBUF_SIZE);
    long count = 0L;
    try {
        for (Object e : list) {
            GraphElement element = (GraphElement) e;
            if (label != null && !label.equals(element.label())) {
                continue;
            }
            count++;
            if (type == HugeType.VERTEX) {
                builder.append(element.id()).append("\t");
            } else {
                Edge edge = (Edge) e;
                builder.append(edge.sourceId()).append("\t").append(edge.targetId()).append("\t");
            }
            if (allProperties) {
                for (Object value : element.properties().values()) {
                    builder.append(value).append(",");
                }
            } else {
                for (String property : properties) {
                    builder.append(element.property(property)).append(",");
                }
            }
            builder.setCharAt(builder.length() - 1, '\n');
        }
        baos.write(builder.toString().getBytes(API.CHARSET));
        os.write(baos.toByteArray());
    } catch (Throwable e) {
        throw new ToolsException("Failed to serialize %s to %s", e, type, path);
    }
    return count;
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) GraphElement(com.baidu.hugegraph.structure.GraphElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 14 with ToolsException

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

the class FileUtil method readTestRestoreData.

public static List<String> readTestRestoreData(String filePath) {
    List<String> results = Lists.newArrayList();
    try (InputStream is = new FileInputStream(filePath);
        InputStreamReader isr = new InputStreamReader(is, API.CHARSET)) {
        BufferedReader reader = new BufferedReader(isr);
        String line;
        while ((line = reader.readLine()) != null) {
            results.add(line);
        }
    } catch (IOException e) {
        throw new ToolsException("Failed read file path is %s", e, filePath);
    }
    return results;
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 15 with ToolsException

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

the class RetryManager method retry.

public <R> R retry(Supplier<R> supplier, String description) {
    int retries = 0;
    R r = null;
    do {
        try {
            r = supplier.get();
        } catch (Exception e) {
            if (retries == this.retry) {
                throw new ToolsException("Exception occurred while %s(after %s retries)", e, description, this.retry);
            }
            // Ignore exception and retry
            continue;
        }
        break;
    } while (retries++ < this.retry);
    return r;
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) ExecutionException(java.util.concurrent.ExecutionException) ToolsException(com.baidu.hugegraph.exception.ToolsException)

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