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