Search in sources :

Example 1 with LoadOptions

use of com.baidu.hugegraph.loader.executor.LoadOptions in project incubator-hugegraph-toolchain by apache.

the class LoadTaskService method buildLoadOptions.

private LoadOptions buildLoadOptions(GraphConnection connection, FileMapping fileMapping) {
    LoadOptions options = new LoadOptions();
    // Fill with input and server params
    options.file = fileMapping.getPath();
    // No need to specify a schema file
    options.host = connection.getHost();
    options.port = connection.getPort();
    options.graph = connection.getGraph();
    options.username = connection.getUsername();
    options.token = connection.getPassword();
    options.protocol = connection.getProtocol();
    options.trustStoreFile = connection.getTrustStoreFile();
    options.trustStoreToken = connection.getTrustStorePassword();
    // Fill with load parameters
    LoadParameter parameter = fileMapping.getLoadParameter();
    options.checkVertex = parameter.isCheckVertex();
    options.timeout = parameter.getInsertTimeout();
    options.maxReadErrors = parameter.getMaxParseErrors();
    options.maxParseErrors = parameter.getMaxParseErrors();
    options.maxInsertErrors = parameter.getMaxInsertErrors();
    options.retryTimes = parameter.getRetryTimes();
    options.retryInterval = parameter.getRetryInterval();
    // Optimized for hubble
    options.batchInsertThreads = 4;
    options.singleInsertThreads = 4;
    options.batchSize = 100;
    return options;
}
Also used : LoadParameter(com.baidu.hugegraph.entity.load.LoadParameter) LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions)

Example 2 with LoadOptions

use of com.baidu.hugegraph.loader.executor.LoadOptions in project incubator-hugegraph-toolchain by apache.

the class GraphStructV1 method of.

public static GraphStructV1 of(LoadContext context) {
    LoadOptions options = context.options();
    File file = FileUtils.getFile(options.file);
    try {
        String json = FileUtils.readFileToString(file, Constants.CHARSET);
        GraphStructV1 struct = JsonUtil.fromJson(json, GraphStructV1.class);
        struct.check();
        return struct;
    } catch (IOException | IllegalArgumentException e) {
        throw new LoadException("Failed to parse graph mapping description file '%s'", e, options.file);
    }
}
Also used : LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions) IOException(java.io.IOException) File(java.io.File) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Example 3 with LoadOptions

use of com.baidu.hugegraph.loader.executor.LoadOptions in project incubator-hugegraph-toolchain by apache.

the class FileLoadTest method testHttpsHolderClientValueMapping.

@Test
public void testHttpsHolderClientValueMapping() {
    ioUtil.write("vertex_person.csv", "marko,1,1,1", "vadas,2,2,2");
    String[] args = new String[] { "-f", structPath("value_mapping/struct.json"), "-s", configPath("value_mapping/schema.groovy"), "-g", GRAPH, "-h", SERVER, "-p", String.valueOf(HTTPS_PORT), "--protocol", HTTPS_PROTOCOL, "--trust-store-file", TRUST_STORE_FILE, "--trust-store-password", "hugegraph", "--batch-insert-threads", "2", "--test-mode", "true" };
    HugeGraphLoader.main(args);
    LoadOptions options = new LoadOptions();
    options.host = SERVER;
    options.port = HTTPS_PORT;
    options.graph = GRAPH;
    options.protocol = HTTPS_PROTOCOL;
    options.trustStoreFile = TRUST_STORE_FILE;
    options.trustStoreToken = "hugegraph";
    HugeClient httpsClient = null;
    try {
        httpsClient = HugeClientHolder.create(options);
        List<Vertex> vertices = httpsClient.graph().listVertices();
        Assert.assertEquals(2, vertices.size());
    } finally {
        clearAndClose(httpsClient, GRAPH);
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions) Test(org.junit.Test)

Example 4 with LoadOptions

use of com.baidu.hugegraph.loader.executor.LoadOptions in project incubator-hugegraph-toolchain by apache.

the class LoadTaskService method buildLoadTask.

private LoadTask buildLoadTask(GraphConnection connection, FileMapping fileMapping) {
    try {
        LoadOptions options = this.buildLoadOptions(connection, fileMapping);
        // NOTE: For simplicity, one file corresponds to one import task
        LoadMapping mapping = this.buildLoadMapping(connection, fileMapping);
        this.bindMappingToOptions(options, mapping, fileMapping.getPath());
        return new LoadTask(options, connection, fileMapping);
    } catch (Exception e) {
        Throwable rootCause = Ex.rootCause(e);
        throw new ExternalException("load.build-task.failed", rootCause);
    }
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions) ExternalException(com.baidu.hugegraph.exception.ExternalException) LoadMapping(com.baidu.hugegraph.loader.mapping.LoadMapping) ExternalException(com.baidu.hugegraph.exception.ExternalException) IOException(java.io.IOException) InternalException(com.baidu.hugegraph.exception.InternalException)

Example 5 with LoadOptions

use of com.baidu.hugegraph.loader.executor.LoadOptions in project incubator-hugegraph-toolchain by apache.

the class HugeGraphLoader method createSchema.

private void createSchema() {
    LoadOptions options = this.context.options();
    if (!StringUtils.isEmpty(options.schema)) {
        File file = FileUtils.getFile(options.schema);
        HugeClient client = this.context.client();
        GroovyExecutor groovyExecutor = new GroovyExecutor();
        groovyExecutor.bind(Constants.GROOVY_SCHEMA, client.schema());
        String script;
        try {
            script = FileUtils.readFileToString(file, Constants.CHARSET);
        } catch (IOException e) {
            throw new LoadException("Failed to read schema file '%s'", e, options.schema);
        }
        groovyExecutor.execute(script, client);
    }
    this.context.updateSchemaCache();
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) LoadOptions(com.baidu.hugegraph.loader.executor.LoadOptions) IOException(java.io.IOException) File(java.io.File) GroovyExecutor(com.baidu.hugegraph.loader.executor.GroovyExecutor) LoadException(com.baidu.hugegraph.loader.exception.LoadException)

Aggregations

LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)13 HugeClient (com.baidu.hugegraph.driver.HugeClient)4 IOException (java.io.IOException)3 LoadException (com.baidu.hugegraph.loader.exception.LoadException)2 LoadSummary (com.baidu.hugegraph.loader.metrics.LoadSummary)2 Vertex (com.baidu.hugegraph.structure.graph.Vertex)2 File (java.io.File)2 Test (org.junit.Test)2 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)1 LoadParameter (com.baidu.hugegraph.entity.load.LoadParameter)1 LoadTask (com.baidu.hugegraph.entity.load.LoadTask)1 ExternalException (com.baidu.hugegraph.exception.ExternalException)1 InternalException (com.baidu.hugegraph.exception.InternalException)1 GroovyExecutor (com.baidu.hugegraph.loader.executor.GroovyExecutor)1 LoadMapping (com.baidu.hugegraph.loader.mapping.LoadMapping)1 LoadProgress (com.baidu.hugegraph.loader.progress.LoadProgress)1