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);
}
}
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations