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