use of ai.grakn.client.GraknClient in project grakn by graknlabs.
the class Migrator method load.
/**
* Migrate data constrained by this migrator using a loader configured
* by the provided parameters.
*
* @param template Template used to extract the data
* @param data Data being migrated
*/
public void load(String template, Stream<Map<String, Object>> data) {
GraknClient graknClient = GraknClient.of(uri);
AtomicInteger queriesExecuted = new AtomicInteger(0);
try (BatchExecutorClient loader = BatchExecutorClient.newBuilder().taskClient(graknClient).maxRetries(retries).maxDelay(maxDelayMs).metricRegistry(metricRegistry).build()) {
checkKeyspace(graknClient);
Stream<Query> queryStream = data.flatMap(d -> template(template, d, failFast));
if (maxLines > -1) {
queryStream = queryStream.limit(maxLines);
}
queryStream.forEach(q -> {
LOG.trace("Adding query {}", q);
totalMeter.mark();
// We add get a hot observable. It starts immediately
Observable<QueryResponse> observable = loader.add(q, keyspace, failFast);
subscribeToReportOutcome(failFast, observable, queriesExecuted);
});
}
System.out.println("Loaded " + queriesExecuted + " statements");
}
Aggregations