Search in sources :

Example 1 with ToolsException

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

the class AuthBackupRestoreManager method readRestoreData.

private List<String> readRestoreData(HugeType type) {
    List<String> resultList = Lists.newArrayList();
    InputStream is = this.inputStream(type.string());
    try (InputStreamReader isr = new InputStreamReader(is, API.CHARSET);
        BufferedReader reader = new BufferedReader(isr)) {
        String line;
        while ((line = reader.readLine()) != null) {
            resultList.add(line);
        }
    } catch (IOException e) {
        throw new ToolsException("Failed to deserialize %s from %s", e, type.string(), resultList);
    }
    return resultList;
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 2 with ToolsException

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

the class AuthBackupRestoreManager method writeBackupData.

private long writeBackupData(HugeType type, List<?> list) {
    long count = 0L;
    try {
        OutputStream os = this.outputStream(type.string(), false);
        ByteArrayOutputStream baos = new ByteArrayOutputStream(LBUF_SIZE);
        StringBuilder builder = new StringBuilder(LBUF_SIZE);
        for (Object e : list) {
            count++;
            builder.append(JsonUtil.toJson(e)).append("\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, list, type.string());
    }
    return count;
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Belong(com.baidu.hugegraph.structure.auth.Belong)

Example 3 with ToolsException

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

the class BackupRestoreBaseManager method write.

protected long write(String path, HugeType type, List<?> list, boolean compress) {
    OutputStream os = this.outputStream(path, compress);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(LBUF_SIZE);
    try {
        String key = String.format("{\"%s\": ", type.string());
        baos.write(key.getBytes(API.CHARSET));
        this.client.mapper().writeValue(baos, list);
        baos.write("}\n".getBytes(API.CHARSET));
        os.write(baos.toByteArray());
    } catch (Throwable e) {
        throw new ToolsException("Failed to serialize %s to %s", e, type, path);
    }
    return list.size();
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with ToolsException

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

the class FileUtil method writeTestRestoreData.

public static long writeTestRestoreData(String filePath, List<?> list) {
    long count = 0L;
    try (FileOutputStream os = new FileOutputStream(filePath);
        ByteArrayOutputStream baos = new ByteArrayOutputStream(LBUF_SIZE)) {
        StringBuilder builder = new StringBuilder(LBUF_SIZE);
        for (Object e : list) {
            count++;
            builder.append(e).append("\n");
        }
        baos.write(builder.toString().getBytes(API.CHARSET));
        os.write(baos.toByteArray());
    } catch (IOException e) {
        throw new ToolsException("Failed write file path is %s", e, filePath);
    }
    return count;
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 5 with ToolsException

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

the class BackupManager method readShards.

private List<Shard> readShards(File file) {
    E.checkArgument(file.exists() && file.isFile() && file.canRead(), "Need to specify a readable filter file rather than:" + " %s", file.toString());
    List<Shard> shards = new ArrayList<>();
    try (InputStream is = new FileInputStream(file);
        InputStreamReader isr = new InputStreamReader(is, API.CHARSET);
        BufferedReader reader = new BufferedReader(isr)) {
        String line;
        while ((line = reader.readLine()) != null) {
            shards.addAll(this.readList("shards", Shard.class, line));
        }
    } catch (IOException e) {
        throw new ToolsException("IOException occur while reading %s", e, file.getName());
    }
    return shards;
}
Also used : ToolsException(com.baidu.hugegraph.exception.ToolsException) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Shard(com.baidu.hugegraph.structure.graph.Shard) FileInputStream(java.io.FileInputStream)

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