Search in sources :

Example 1 with MongoImportExecutable

use of de.flapdoodle.embed.mongo.MongoImportExecutable in project drill by apache.

the class TestTableGenerator method generateTable.

public static void generateTable(String dbName, String collection, String jsonFile, Boolean jsonArray, Boolean upsert, Boolean drop) throws InterruptedException, IOException {
    logger.info("Started importing file {} into collection {} ", jsonFile, collection);
    IMongoImportConfig mongoImportConfig = new MongoImportConfigBuilder().version(Version.Main.PRODUCTION).net(new Net(MONGOS_PORT, Network.localhostIsIPv6())).db(dbName).collection(collection).upsert(upsert).dropCollection(drop).jsonArray(jsonArray).importFile(jsonFile).build();
    MongoImportExecutable importExecutable = MongoImportStarter.getDefaultInstance().prepare(mongoImportConfig);
    MongoImportProcess importProcess = importExecutable.start();
    // import is in a separate process, we should wait until the process exit
    while (importProcess.isProcessRunning()) {
        Thread.sleep(1000);
    }
    logger.info("Imported file {} into collection {} ", jsonFile, collection);
}
Also used : MongoImportProcess(de.flapdoodle.embed.mongo.MongoImportProcess) IMongoImportConfig(de.flapdoodle.embed.mongo.config.IMongoImportConfig) Net(de.flapdoodle.embed.mongo.config.Net) MongoImportConfigBuilder(de.flapdoodle.embed.mongo.config.MongoImportConfigBuilder) MongoImportExecutable(de.flapdoodle.embed.mongo.MongoImportExecutable)

Example 2 with MongoImportExecutable

use of de.flapdoodle.embed.mongo.MongoImportExecutable in project drill by axbaretto.

the class TestTableGenerator method generateTable.

public static void generateTable(String dbName, String collection, String jsonFile, Boolean jsonArray, Boolean upsert, Boolean drop) throws InterruptedException, IOException {
    logger.info("Started importing file {} into collection {} ", jsonFile, collection);
    IMongoImportConfig mongoImportConfig = new MongoImportConfigBuilder().version(Version.Main.PRODUCTION).net(new Net(MONGOS_PORT, Network.localhostIsIPv6())).db(dbName).collection(collection).upsert(upsert).dropCollection(drop).jsonArray(jsonArray).importFile(jsonFile).build();
    MongoImportExecutable importExecutable = MongoImportStarter.getDefaultInstance().prepare(mongoImportConfig);
    MongoImportProcess importProcess = importExecutable.start();
    // import is in a separate process, we should wait until the process exit
    while (importProcess.isProcessRunning()) {
        Thread.sleep(1000);
    }
    logger.info("Imported file {} into collection {} ", jsonFile, collection);
}
Also used : MongoImportProcess(de.flapdoodle.embed.mongo.MongoImportProcess) IMongoImportConfig(de.flapdoodle.embed.mongo.config.IMongoImportConfig) Net(de.flapdoodle.embed.mongo.config.Net) MongoImportConfigBuilder(de.flapdoodle.embed.mongo.config.MongoImportConfigBuilder) MongoImportExecutable(de.flapdoodle.embed.mongo.MongoImportExecutable)

Example 3 with MongoImportExecutable

use of de.flapdoodle.embed.mongo.MongoImportExecutable in project embedmongo-maven-plugin by joelittlejohn.

the class MongoImportMojo method sendImportScript.

private void sendImportScript() throws IOException, InterruptedException, MojoExecutionException {
    List<MongoImportProcess> pendingMongoProcess = new ArrayList<MongoImportProcess>();
    if (imports == null || imports.length == 0) {
        getLog().error("No imports found, check your configuration");
        return;
    }
    getLog().info("Default import database: " + defaultImportDatabase);
    for (ImportDataConfig importData : imports) {
        getLog().info("Import " + importData);
        verify(importData);
        String database = importData.getDatabase();
        if (StringUtils.isBlank(database)) {
            database = defaultImportDatabase;
        }
        IMongoImportConfig mongoImportConfig = new MongoImportConfigBuilder().version(getVersion()).net(new Net(getPort(), NetworkUtils.localhostIsIPv6())).db(database).collection(importData.getCollection()).upsert(importData.getUpsertOnImport()).dropCollection(importData.getDropOnImport()).importFile(importData.getFile()).jsonArray(true).timeout(new Timeout(importData.getTimeout())).build();
        MongoImportExecutable mongoImport = MongoImportStarter.getDefaultInstance().prepare(mongoImportConfig);
        MongoImportProcess importProcess = mongoImport.start();
        if (parallel) {
            pendingMongoProcess.add(importProcess);
        } else {
            waitFor(importProcess);
        }
    }
    for (MongoImportProcess importProcess : pendingMongoProcess) {
        waitFor(importProcess);
    }
}
Also used : MongoImportProcess(de.flapdoodle.embed.mongo.MongoImportProcess) IMongoImportConfig(de.flapdoodle.embed.mongo.config.IMongoImportConfig) Timeout(de.flapdoodle.embed.mongo.config.Timeout) ArrayList(java.util.ArrayList) Net(de.flapdoodle.embed.mongo.config.Net) MongoImportConfigBuilder(de.flapdoodle.embed.mongo.config.MongoImportConfigBuilder) MongoImportExecutable(de.flapdoodle.embed.mongo.MongoImportExecutable)

Aggregations

MongoImportExecutable (de.flapdoodle.embed.mongo.MongoImportExecutable)3 MongoImportProcess (de.flapdoodle.embed.mongo.MongoImportProcess)3 IMongoImportConfig (de.flapdoodle.embed.mongo.config.IMongoImportConfig)3 MongoImportConfigBuilder (de.flapdoodle.embed.mongo.config.MongoImportConfigBuilder)3 Net (de.flapdoodle.embed.mongo.config.Net)3 Timeout (de.flapdoodle.embed.mongo.config.Timeout)1 ArrayList (java.util.ArrayList)1