Search in sources :

Example 1 with LoadException

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);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 2 with LoadException

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());
    }
}
Also used : IOException(java.io.IOException) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 3 with LoadException

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;
}
Also used : FileSource(com.baidu.hugegraph.loader.source.file.FileSource) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 4 with LoadException

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);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 5 with LoadException

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);
    }
}
Also used : GraphMode(com.baidu.hugegraph.structure.constant.GraphMode) ServerException(com.baidu.hugegraph.exception.ServerException) IOException(java.io.IOException) LoadException(com.baidu.hugegraph.loader.exception.LoadException) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Aggregations

LoadException (com.baidu.hugegraph.loader.exception.LoadException)32 IOException (java.io.IOException)18 File (java.io.File)10 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 FileFilter (com.baidu.hugegraph.loader.source.file.FileFilter)3 Path (org.apache.hadoop.fs.Path)3 ServerException (com.baidu.hugegraph.exception.ServerException)2 InitException (com.baidu.hugegraph.loader.exception.InitException)2 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)2 LoadSummary (com.baidu.hugegraph.loader.metrics.LoadSummary)2 Readable (com.baidu.hugegraph.loader.reader.Readable)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 CompressorInputStream (org.apache.commons.compress.compressors.CompressorInputStream)2 CompressionInputStream (org.apache.hadoop.io.compress.CompressionInputStream)2 HugeClient (com.baidu.hugegraph.driver.HugeClient)1 HugeClientBuilder (com.baidu.hugegraph.driver.HugeClientBuilder)1 GroovyExecutor (com.baidu.hugegraph.loader.executor.GroovyExecutor)1 InputStruct (com.baidu.hugegraph.loader.mapping.InputStruct)1