Commit 979fc2ac authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

434: Fix mongodb configuration bias (OPENED)

Task-Url: #434
parent 09021378
Pipeline #24701 passed with stage
in 56 seconds
...@@ -9,7 +9,7 @@ allprojects { ...@@ -9,7 +9,7 @@ allprojects {
apply plugin: 'eclipse' apply plugin: 'eclipse'
group = 'eu.dariah.de.minfba' group = 'eu.dariah.de.minfba'
version = '4.1.2-SNAPSHOT' version = '4.1.3-SNAPSHOT'
repositories { repositories {
mavenLocal() mavenLocal()
......
...@@ -38,7 +38,6 @@ public class UpdateServiceImpl implements InitializingBean { ...@@ -38,7 +38,6 @@ public class UpdateServiceImpl implements InitializingBean {
private final static String versionHashPrefix = "GenericSearch"; private final static String versionHashPrefix = "GenericSearch";
private String backupsBasePath; private String backupsBasePath;
private String database;
private final MessageDigest md; private final MessageDigest md;
...@@ -47,10 +46,9 @@ public class UpdateServiceImpl implements InitializingBean { ...@@ -47,10 +46,9 @@ public class UpdateServiceImpl implements InitializingBean {
@Autowired private VersionDao versionDao; @Autowired private VersionDao versionDao;
public UpdateServiceImpl(String backupsBasePath, String database) throws NoSuchAlgorithmException { public UpdateServiceImpl(String backupsBasePath) throws NoSuchAlgorithmException {
this.md = MessageDigest.getInstance("MD5"); this.md = MessageDigest.getInstance("MD5");
this.backupsBasePath = backupsBasePath; this.backupsBasePath = backupsBasePath;
this.database = database;
} }
public UpdateServiceImpl() throws NoSuchAlgorithmException { public UpdateServiceImpl() throws NoSuchAlgorithmException {
...@@ -145,7 +143,7 @@ public class UpdateServiceImpl implements InitializingBean { ...@@ -145,7 +143,7 @@ public class UpdateServiceImpl implements InitializingBean {
Files.createDirectories(Paths.get(new File(backupPath).toURI()), new FileAttribute<?>[0]); Files.createDirectories(Paths.get(new File(backupPath).toURI()), new FileAttribute<?>[0]);
try { try {
Runtime.getRuntime().exec(String.format("mongodump --out %s --db %s", backupPath, database)); Runtime.getRuntime().exec(String.format("mongodump --out %s --db %s", backupPath, mongoTemplate.getDb().getName()));
} catch (Exception e) { } catch (Exception e) {
log.error("Failed to create mongodb backup", e); log.error("Failed to create mongodb backup", e);
throw e; throw e;
......
...@@ -15,6 +15,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -15,6 +15,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.data.mongodb.config.MongoConfigurationSupport;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -34,7 +35,6 @@ import lombok.EqualsAndHashCode; ...@@ -34,7 +35,6 @@ import lombok.EqualsAndHashCode;
@ConfigurationProperties @ConfigurationProperties
public class MainConfig extends MainConfigProperties { public class MainConfig extends MainConfigProperties {
@Autowired MongoConfig mongoConfig;
@Autowired ResourceLoader resourceLoader; @Autowired ResourceLoader resourceLoader;
@PostConstruct @PostConstruct
...@@ -122,7 +122,7 @@ public class MainConfig extends MainConfigProperties { ...@@ -122,7 +122,7 @@ public class MainConfig extends MainConfigProperties {
@Bean @Bean
public UpdateServiceImpl updateService() throws NoSuchAlgorithmException { public UpdateServiceImpl updateService() throws NoSuchAlgorithmException {
return new UpdateServiceImpl(paths.getBackups(), mongoConfig.getDatabase()); return new UpdateServiceImpl(paths.getBackups());
} }
@Bean @Bean
......
package eu.dariah.de.search.config;
import java.util.Collection;
import java.util.Collections;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Getter
@Setter
@Slf4j
@Configuration
@ConfigurationProperties(prefix = "mongo")
@EnableMongoRepositories(basePackages = "eu.dariah.de.search.dao.db")
public class MongoConfig extends AbstractMongoClientConfiguration {
private String host = "localhost";
private Integer port = 27017;
private String database = "search";
@Override
protected String getDatabaseName() {
return database;
}
@Override
public MongoClient mongoClient() {
String connectionString = String.format("mongodb://%s:%s/%s", host, port, database);
log.debug("Mongo client initializing with connection: {}", connectionString);
ConnectionString connectionStringObj = new ConnectionString(connectionString);
MongoClientSettings mongoClientSettings = MongoClientSettings.builder()
.applyConnectionString(connectionStringObj)
.build();
return MongoClients.create(mongoClientSettings);
}
@Override
public Collection<String> getMappingBasePackages() {
return Collections.singleton("eu.dariah.de.search.model");
}
}
Subproject commit ca479bb95e8f7dac66ac4718192f1374710bb06e Subproject commit 11e3a70be8ceffdcf95b0e6429f3cee814349daa
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment