Skip to content
Snippets Groups Projects
Commit 45a5fbbb authored by Aleh Shubko [EPAM]'s avatar Aleh Shubko [EPAM] Committed by Marc Burnie [AWS]
Browse files

Move MongoDB to core lib

parent 3c2f6296
No related branches found
No related tags found
2 merge requests!229Merge branch 'dependency-upgrade' into 'master',!156Move MongoDB to core lib
......@@ -57,7 +57,7 @@
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.13.0</version>
<version>0.14.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
......
......@@ -14,15 +14,12 @@
package org.opengroup.osdu.partition.provider.aws;
import org.opengroup.osdu.core.aws.mongodb.config.MongoDBAutoconfigExclude;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
@ComponentScan(
basePackages = {"org.opengroup.osdu"},
excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = MongoDBAutoconfigExclude.class)})
basePackages = {"org.opengroup.osdu"})
@SpringBootApplication
public class PartitionApplication {
......
......@@ -14,62 +14,18 @@
package org.opengroup.osdu.partition.provider.aws.util;
import com.mongodb.ConnectionString;
import org.opengroup.osdu.core.aws.mongodb.MongoDBSimpleFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoClientFactoryBean;
import javax.inject.Inject;
import org.springframework.data.mongodb.core.MongoTemplate;
@Configuration
public class MongoConfig {
@Inject
MongoProperties props;
public String getMongoURI() {
Boolean useSrvEndpoint = Boolean.parseBoolean(props.getUseSrvEndpointStr());
if (useSrvEndpoint) {
String srvUriFormat = "mongodb+srv://%s:%s@%s/%s?ssl=%s&retryWrites=%s&w=%s";
String srvUri = String.format(
srvUriFormat,
props.getUsername(),
props.getPassword(),
props.getEndpoint(),
props.getAuthDatabase(),
props.getEnableTLS(),
props.getRetryWrites(),
props.getWriteMode());
return srvUri;
}
else {
String uriFormat = "mongodb+srv://%s:%s@%s/%s?retryWrites=%s&w=%s";
String uri = String.format(
uriFormat,
props.getUsername(),
props.getPassword(),
props.getEndpoint(),
props.getAuthDatabase(),
// props.getEnableTLS(),
props.getRetryWrites(),
props.getWriteMode());
return uri;
}
}
public @Bean MongoClientFactoryBean mongo() {
ConnectionString connectionString = new ConnectionString(this.getMongoURI());
MongoClientFactoryBean mongo = new MongoClientFactoryBean();
mongo.setConnectionString(connectionString);
return mongo;
@Autowired
public @Bean MongoTemplate mongoTemplate(MongoDBSimpleFactory mongoDBFactory, MongoPropertiesReader propertiesReader) {
return mongoDBFactory.mongoTemplate(propertiesReader.getProperties());
}
}
......@@ -15,22 +15,18 @@
package org.opengroup.osdu.partition.provider.aws.util;
import java.util.Map;
import javax.annotation.PostConstruct;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.opengroup.osdu.core.aws.mongodb.config.MongoProperties;
import org.opengroup.osdu.core.aws.ssm.K8sLocalParameterProvider;
import org.opengroup.osdu.core.aws.ssm.K8sParameterNotFoundException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import lombok.Data;
import javax.annotation.PostConstruct;
import java.util.Map;
@Data
@Component
public class MongoProperties {
public class MongoPropertiesReader {
@Value("${osdu.mongodb.username}")
private String username;
......@@ -50,6 +46,12 @@ public class MongoProperties {
private String useSrvEndpointStr;
@Value("${osdu.mongodb.enableTLS}")
private String enableTLS;
@Value("${spring.data.mongodb.database}")
private String databaseName;
@Value("${osdu.mongodb.maxPoolSize}")
private String maxPoolSize;
@Value("${osdu.mongodb.readPreference}")
private String readPreference;
@PostConstruct
private void init() throws K8sParameterNotFoundException, JsonProcessingException {
......@@ -57,7 +59,7 @@ public class MongoProperties {
K8sLocalParameterProvider provider = new K8sLocalParameterProvider();
if (!provider.getLocalMode()) {
Map<String,String> credentials = provider.getCredentialsAsMap("mongodb_credentials");
Map<String, String> credentials = provider.getCredentialsAsMap("mongodb_credentials");
if (credentials != null) {
username = credentials.get("username");
......@@ -71,6 +73,20 @@ public class MongoProperties {
}
}
public MongoProperties getProperties() {
return MongoProperties.builder()
.username(username)
.password(password)
.endpoint(endpoint)
.authDatabase(authDatabase)
.port(port)
.retryWrites(retryWrites)
.writeMode(writeMode)
.useSrvEndpointStr(useSrvEndpointStr)
.enableTLS(enableTLS)
.databaseName(databaseName)
.maxPoolSize(maxPoolSize)
.readPreference(readPreference)
.build();
}
}
......@@ -54,10 +54,15 @@ osdu.mongodb.retryWrites=${MONGODB_RETRY_WRITES:true}
osdu.mongodb.writeMode=${MONGODB_WRITE_MODE:majority}
osdu.mongodb.useSrvEndpoint=${MONGODB_USE_SRV_ENDPOINT:true}
osdu.mongodb.enableTLS=${MONGODB_ENABLE_TLS:false}
osdu.mongodb.maxPoolSize=${MONGODB_MAX_POOL_SIZE:300}
osdu.mongodb.readPreference=${MONGODB_READ_PREFERENCE:nearest}
#AWS KMS Config
aws.kms.keyArn=${KEY_ARN:empty}
#Tomcat limits
server.tomcat.threads.max=${TOMCAT_THREADS_MAX:300}
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
## AWS ElastiCache configuration
aws.elasticache.cluster.endpoint=${CACHE_CLUSTER_ENDPOINT:null}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment