use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class LoadProgress method parse.
public static LoadProgress parse(LoadOptions options) {
if (!options.incrementalMode) {
return new LoadProgress();
}
String dir = LoadUtil.getStructDirPrefix(options);
File dirFile = FileUtils.getFile(dir);
if (!dirFile.exists()) {
return new LoadProgress();
}
File[] subFiles = dirFile.listFiles((d, name) -> {
return name.startsWith(Constants.LOAD_PROGRESS);
});
if (subFiles == null || subFiles.length == 0) {
return new LoadProgress();
}
// Sort progress files by time, then get the last progress file
List<File> progressFiles = Arrays.asList(subFiles);
progressFiles.sort(Comparator.comparing(File::getName));
File lastProgressFile = progressFiles.get(progressFiles.size() - 1);
try {
return LoadProgress.read(lastProgressFile);
} catch (IOException e) {
throw new LoadException("Failed to read progress file", e);
}
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class FailWriter method write.
public void write(ReadException e) {
try {
this.writeLine("#### READ ERROR: " + e.getMessage());
this.writeLine(e.line());
} catch (IOException ex) {
throw new LoadException("Failed to write read error '%s'", ex, e.line());
}
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class LoadMapping method structsForFailure.
public List<InputStruct> structsForFailure(LoadOptions options) {
List<InputStruct> targetStructs = new ArrayList<>();
String dir = LoadUtil.getStructDirPrefix(options);
String path = Paths.get(dir, Constants.FAILURE_DATA).toString();
File pathDir = FileUtils.getFile(path);
// It means no failure data if the path directory does not exist
if (!pathDir.exists()) {
return targetStructs;
}
Map<String, FailureFile> failureFiles = this.groupFailureFiles(pathDir);
for (String inputId : failureFiles.keySet()) {
InputStruct struct = this.struct(inputId);
String charset = struct.input().charset();
FailureFile failureFile = failureFiles.get(inputId);
FileSource source = struct.input().asFileSource();
if (failureFile.headerFile != null) {
// It means that header file existed
String json;
try {
json = FileUtils.readFileToString(failureFile.headerFile, charset);
} catch (IOException e) {
throw new LoadException("Failed to read header file %s", failureFile.headerFile);
}
List<String> header = JsonUtil.convertList(json, String.class);
source.header(header.toArray(new String[] {}));
}
// Set failure data path
source.path(failureFile.dataFile.getAbsolutePath());
source.skippedLine().regex(Constants.SKIPPED_LINE_REGEX);
struct.input(source);
// Add to target structs
targetStructs.add(struct);
}
return targetStructs;
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class FailLogger method writeHeaderIfNeeded.
/**
* Write head to a specialized file, every input struct has one
*/
private void writeHeaderIfNeeded() {
// header() == null means no need header
if (this.struct.input().header() == null) {
return;
}
String header = JsonUtil.toJson(this.struct.input().header());
/*
* The files under failure path are like:
* mapping/failure-data/input-1.header
*/
String fileName = this.struct.id() + Constants.HEADER_SUFFIX;
String filePath = Paths.get(this.file.getParent(), fileName).toString();
File headerFile = new File(filePath);
String charset = this.struct.input().charset();
try {
FileUtils.writeStringToFile(headerFile, header, charset);
} catch (IOException e) {
throw new LoadException("Failed to write header '%s'", e);
}
}
use of com.baidu.hugegraph.loader.exception.LoadException in project incubator-hugegraph-toolchain by apache.
the class LoadContext method unsetLoadingMode.
public void unsetLoadingMode() {
try {
String graph = this.client.graph().graph();
GraphMode mode = this.client.graphs().mode(graph);
if (mode.loading()) {
this.client.graphs().mode(graph, GraphMode.NONE);
}
} catch (Exception e) {
throw new LoadException("Failed to unset mode %s for server", e, GraphMode.LOADING);
}
}
Aggregations