|
|
@ -27,26 +27,24 @@ import com.mongodb.MongoClientSettings;
|
|
|
|
import de.flapdoodle.embed.mongo.Command;
|
|
|
|
import de.flapdoodle.embed.mongo.Command;
|
|
|
|
import de.flapdoodle.embed.mongo.MongodExecutable;
|
|
|
|
import de.flapdoodle.embed.mongo.MongodExecutable;
|
|
|
|
import de.flapdoodle.embed.mongo.MongodStarter;
|
|
|
|
import de.flapdoodle.embed.mongo.MongodStarter;
|
|
|
|
import de.flapdoodle.embed.mongo.config.DownloadConfigBuilder;
|
|
|
|
import de.flapdoodle.embed.mongo.config.Defaults;
|
|
|
|
import de.flapdoodle.embed.mongo.config.ExtractedArtifactStoreBuilder;
|
|
|
|
import de.flapdoodle.embed.mongo.config.ImmutableMongodConfig;
|
|
|
|
import de.flapdoodle.embed.mongo.config.IMongodConfig;
|
|
|
|
import de.flapdoodle.embed.mongo.config.MongodConfig;
|
|
|
|
import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
|
|
|
|
|
|
|
|
import de.flapdoodle.embed.mongo.config.Net;
|
|
|
|
import de.flapdoodle.embed.mongo.config.Net;
|
|
|
|
import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder;
|
|
|
|
|
|
|
|
import de.flapdoodle.embed.mongo.config.Storage;
|
|
|
|
import de.flapdoodle.embed.mongo.config.Storage;
|
|
|
|
import de.flapdoodle.embed.mongo.distribution.Feature;
|
|
|
|
import de.flapdoodle.embed.mongo.distribution.Feature;
|
|
|
|
import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion;
|
|
|
|
import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion;
|
|
|
|
import de.flapdoodle.embed.mongo.distribution.Version;
|
|
|
|
import de.flapdoodle.embed.mongo.distribution.Version;
|
|
|
|
import de.flapdoodle.embed.mongo.distribution.Versions;
|
|
|
|
import de.flapdoodle.embed.mongo.distribution.Versions;
|
|
|
|
import de.flapdoodle.embed.process.config.IRuntimeConfig;
|
|
|
|
import de.flapdoodle.embed.process.config.RuntimeConfig;
|
|
|
|
import de.flapdoodle.embed.process.config.io.ProcessOutput;
|
|
|
|
import de.flapdoodle.embed.process.config.io.ProcessOutput;
|
|
|
|
import de.flapdoodle.embed.process.config.store.IDownloadConfig;
|
|
|
|
import de.flapdoodle.embed.process.config.store.DownloadConfig;
|
|
|
|
import de.flapdoodle.embed.process.distribution.GenericVersion;
|
|
|
|
import de.flapdoodle.embed.process.config.store.ImmutableDownloadConfig;
|
|
|
|
import de.flapdoodle.embed.process.io.Processors;
|
|
|
|
import de.flapdoodle.embed.process.io.Processors;
|
|
|
|
import de.flapdoodle.embed.process.io.Slf4jLevel;
|
|
|
|
import de.flapdoodle.embed.process.io.Slf4jLevel;
|
|
|
|
import de.flapdoodle.embed.process.io.progress.Slf4jProgressListener;
|
|
|
|
import de.flapdoodle.embed.process.io.progress.Slf4jProgressListener;
|
|
|
|
import de.flapdoodle.embed.process.runtime.Network;
|
|
|
|
import de.flapdoodle.embed.process.runtime.Network;
|
|
|
|
import de.flapdoodle.embed.process.store.ArtifactStoreBuilder;
|
|
|
|
import de.flapdoodle.embed.process.store.ExtractedArtifactStore;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
@ -81,6 +79,7 @@ import org.springframework.data.mongodb.core.ReactiveMongoClientFactoryBean;
|
|
|
|
* @author Yogesh Lonkar
|
|
|
|
* @author Yogesh Lonkar
|
|
|
|
* @author Mark Paluch
|
|
|
|
* @author Mark Paluch
|
|
|
|
* @author Issam El-atif
|
|
|
|
* @author Issam El-atif
|
|
|
|
|
|
|
|
* @author Paulius Dambrauskas
|
|
|
|
* @since 1.3.0
|
|
|
|
* @since 1.3.0
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
@ -97,14 +96,14 @@ public class EmbeddedMongoAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
private final MongoProperties properties;
|
|
|
|
private final MongoProperties properties;
|
|
|
|
|
|
|
|
|
|
|
|
public EmbeddedMongoAutoConfiguration(MongoProperties properties, EmbeddedMongoProperties embeddedProperties) {
|
|
|
|
public EmbeddedMongoAutoConfiguration(MongoProperties properties) {
|
|
|
|
this.properties = properties;
|
|
|
|
this.properties = properties;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean(initMethod = "start", destroyMethod = "stop")
|
|
|
|
@Bean(initMethod = "start", destroyMethod = "stop")
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
public MongodExecutable embeddedMongoServer(IMongodConfig mongodConfig, IRuntimeConfig runtimeConfig,
|
|
|
|
public MongodExecutable embeddedMongoServer(MongodConfig mongodConfig, RuntimeConfig runtimeConfig,
|
|
|
|
ApplicationContext context) throws IOException {
|
|
|
|
ApplicationContext context) {
|
|
|
|
Integer configuredPort = this.properties.getPort();
|
|
|
|
Integer configuredPort = this.properties.getPort();
|
|
|
|
if (configuredPort == null || configuredPort == 0) {
|
|
|
|
if (configuredPort == null || configuredPort == 0) {
|
|
|
|
setEmbeddedPort(context, mongodConfig.net().getPort());
|
|
|
|
setEmbeddedPort(context, mongodConfig.net().getPort());
|
|
|
@ -113,7 +112,7 @@ public class EmbeddedMongoAutoConfiguration {
|
|
|
|
return mongodStarter.prepare(mongodConfig);
|
|
|
|
return mongodStarter.prepare(mongodConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private MongodStarter getMongodStarter(IRuntimeConfig runtimeConfig) {
|
|
|
|
private MongodStarter getMongodStarter(RuntimeConfig runtimeConfig) {
|
|
|
|
if (runtimeConfig == null) {
|
|
|
|
if (runtimeConfig == null) {
|
|
|
|
return MongodStarter.getDefaultInstance();
|
|
|
|
return MongodStarter.getDefaultInstance();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -122,8 +121,8 @@ public class EmbeddedMongoAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
public IMongodConfig embeddedMongoConfiguration(EmbeddedMongoProperties embeddedProperties) throws IOException {
|
|
|
|
public MongodConfig embeddedMongoConfiguration(EmbeddedMongoProperties embeddedProperties) throws IOException {
|
|
|
|
MongodConfigBuilder builder = new MongodConfigBuilder().version(determineVersion(embeddedProperties));
|
|
|
|
ImmutableMongodConfig.Builder builder = MongodConfig.builder().version(determineVersion(embeddedProperties));
|
|
|
|
EmbeddedMongoProperties.Storage storage = embeddedProperties.getStorage();
|
|
|
|
EmbeddedMongoProperties.Storage storage = embeddedProperties.getStorage();
|
|
|
|
if (storage != null) {
|
|
|
|
if (storage != null) {
|
|
|
|
String databaseDir = storage.getDatabaseDir();
|
|
|
|
String databaseDir = storage.getDatabaseDir();
|
|
|
@ -149,9 +148,11 @@ public class EmbeddedMongoAutoConfiguration {
|
|
|
|
return version;
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Versions.withFeatures(new GenericVersion(embeddedProperties.getVersion()));
|
|
|
|
return Versions
|
|
|
|
|
|
|
|
.withFeatures(de.flapdoodle.embed.process.distribution.Version.of(embeddedProperties.getVersion()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Versions.withFeatures(new GenericVersion(embeddedProperties.getVersion()),
|
|
|
|
return Versions.withFeatures(
|
|
|
|
|
|
|
|
de.flapdoodle.embed.process.distribution.Version.of(embeddedProperties.getVersion()),
|
|
|
|
embeddedProperties.getFeatures().toArray(new Feature[0]));
|
|
|
|
embeddedProperties.getFeatures().toArray(new Feature[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -189,29 +190,29 @@ public class EmbeddedMongoAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@ConditionalOnClass(Logger.class)
|
|
|
|
@ConditionalOnClass(Logger.class)
|
|
|
|
@ConditionalOnMissingBean(IRuntimeConfig.class)
|
|
|
|
@ConditionalOnMissingBean(RuntimeConfig.class)
|
|
|
|
static class RuntimeConfigConfiguration {
|
|
|
|
static class RuntimeConfigConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
IRuntimeConfig embeddedMongoRuntimeConfig(
|
|
|
|
RuntimeConfig embeddedMongoRuntimeConfig(
|
|
|
|
ObjectProvider<DownloadConfigBuilderCustomizer> downloadConfigBuilderCustomizers) {
|
|
|
|
ObjectProvider<DownloadConfigBuilderCustomizer> downloadConfigBuilderCustomizers) {
|
|
|
|
Logger logger = LoggerFactory.getLogger(getClass().getPackage().getName() + ".EmbeddedMongo");
|
|
|
|
Logger logger = LoggerFactory.getLogger(getClass().getPackage().getName() + ".EmbeddedMongo");
|
|
|
|
ProcessOutput processOutput = new ProcessOutput(Processors.logTo(logger, Slf4jLevel.INFO),
|
|
|
|
ProcessOutput processOutput = new ProcessOutput(Processors.logTo(logger, Slf4jLevel.INFO),
|
|
|
|
Processors.logTo(logger, Slf4jLevel.ERROR),
|
|
|
|
Processors.logTo(logger, Slf4jLevel.ERROR),
|
|
|
|
Processors.named("[console>]", Processors.logTo(logger, Slf4jLevel.DEBUG)));
|
|
|
|
Processors.named("[console>]", Processors.logTo(logger, Slf4jLevel.DEBUG)));
|
|
|
|
return new RuntimeConfigBuilder().defaultsWithLogger(Command.MongoD, logger).processOutput(processOutput)
|
|
|
|
|
|
|
|
|
|
|
|
return Defaults.runtimeConfigFor(Command.MongoD, logger).processOutput(processOutput)
|
|
|
|
.artifactStore(getArtifactStore(logger, downloadConfigBuilderCustomizers.orderedStream()))
|
|
|
|
.artifactStore(getArtifactStore(logger, downloadConfigBuilderCustomizers.orderedStream()))
|
|
|
|
.daemonProcess(false).build();
|
|
|
|
.isDaemonProcess(false).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ArtifactStoreBuilder getArtifactStore(Logger logger,
|
|
|
|
private ExtractedArtifactStore getArtifactStore(Logger logger,
|
|
|
|
Stream<DownloadConfigBuilderCustomizer> downloadConfigBuilderCustomizers) {
|
|
|
|
Stream<DownloadConfigBuilderCustomizer> downloadConfigBuilderCustomizers) {
|
|
|
|
DownloadConfigBuilder downloadConfigBuilder = new DownloadConfigBuilder()
|
|
|
|
ImmutableDownloadConfig.Builder downloadConfigBuilder = Defaults.downloadConfigFor(Command.MongoD);
|
|
|
|
.defaultsForCommand(Command.MongoD);
|
|
|
|
|
|
|
|
downloadConfigBuilder.progressListener(new Slf4jProgressListener(logger));
|
|
|
|
downloadConfigBuilder.progressListener(new Slf4jProgressListener(logger));
|
|
|
|
downloadConfigBuilderCustomizers.forEach((customizer) -> customizer.customize(downloadConfigBuilder));
|
|
|
|
downloadConfigBuilderCustomizers.forEach((customizer) -> customizer.customize(downloadConfigBuilder));
|
|
|
|
IDownloadConfig downloadConfig = downloadConfigBuilder.build();
|
|
|
|
DownloadConfig downloadConfig = downloadConfigBuilder.build();
|
|
|
|
return new ExtractedArtifactStoreBuilder().defaults(Command.MongoD).download(downloadConfig);
|
|
|
|
return Defaults.extractedArtifactStoreFor(Command.MongoD).withDownloadConfig(downloadConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|