Skip to content
Snippets Groups Projects
Commit 3c1d32bc authored by Yifei Xu's avatar Yifei Xu
Browse files

Use MongoPropertiesReader from os-core-lib-aws and add maxIdelTimeMS setting

parent fc0ff54f
No related branches found
No related tags found
2 merge requests!229Merge branch 'dependency-upgrade' into 'master',!195Use MongoPropertiesReader from os-core-lib-aws and add maxIdelTimeMS setting
Pipeline #111883 passed with warnings
......@@ -57,7 +57,7 @@
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.14.0</version>
<version>0.15.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
......
......@@ -48,7 +48,7 @@ public class AwsKmsEncryptionClient {
@Value("${aws.kms.keyArn}")
private String keyArn;
@Value("${spring.data.mongodb.database}")
@Value("${osdu.mongodb.database}")
private String authDatabase;
private AWSCredentialsProvider amazonAWSCredentials;
......
......@@ -15,6 +15,7 @@
package org.opengroup.osdu.partition.provider.aws.util;
import org.opengroup.osdu.core.aws.mongodb.MongoDBSimpleFactory;
import org.opengroup.osdu.core.aws.mongodb.config.MongoPropertiesDefaultReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -23,9 +24,8 @@ import org.springframework.data.mongodb.core.MongoTemplate;
@Configuration
public class MongoConfig {
@Autowired
public @Bean MongoTemplate mongoTemplate(MongoDBSimpleFactory mongoDBFactory, MongoPropertiesReader propertiesReader) {
public @Bean MongoTemplate mongoTemplate(MongoDBSimpleFactory mongoDBFactory, MongoPropertiesDefaultReader propertiesReader) {
return mongoDBFactory.mongoTemplate(propertiesReader.getProperties());
}
}
// Copyright © 2021 Amazon Web Services
// Copyright MongoDB, Inc or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.partition.provider.aws.util;
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 javax.annotation.PostConstruct;
import java.util.Map;
@Component
public class MongoPropertiesReader {
@Value("${osdu.mongodb.username}")
private String username;
@Value("${osdu.mongodb.password}")
private String password;
@Value("${spring.data.mongodb.host}")
private String endpoint;
@Value("${osdu.mongodb.authDatabase}")
private String authDatabase;
@Value("${osdu.mongodb.port}")
private String port;
@Value("${osdu.mongodb.retryWrites}")
private String retryWrites;
@Value("${osdu.mongodb.writeMode}")
private String writeMode;
@Value("${osdu.mongodb.useSrvEndpoint}")
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 {
K8sLocalParameterProvider provider = new K8sLocalParameterProvider();
if (!provider.getLocalMode()) {
Map<String, String> credentials = provider.getCredentialsAsMap("mongodb_credentials");
if (credentials != null) {
username = credentials.get("username");
password = credentials.get("password");
authDatabase = credentials.get("authDB");
}
endpoint = provider.getParameterAsStringOrDefault("mongodb_host", endpoint);
port = provider.getParameterAsStringOrDefault("mongodb_port", port);
}
}
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();
}
}
......@@ -44,9 +44,9 @@ server.ssl.key-password=${SSL_KEY_PASSWORD:}
server.ssl.key-store-password=${SSL_KEY_STORE_PASSWORD:}
#MongoDB config
spring.data.mongodb.database=${ENVIRONMENT}_osdu_partitions
osdu.mongodb.database=${ENVIRONMENT}_osdu_partitions
osdu.mongodb.authDatabase=${MONGODB_AUTH_DATABASE:admin}
spring.data.mongodb.host=${MONGODB_ENDPOINT:}
osdu.mongodb.endpoint=${MONGODB_ENDPOINT:}
osdu.mongodb.port=${MONGODB_PORT:27017}
osdu.mongodb.username=${MONGODB_USERNAME:empty}
osdu.mongodb.password=${MONGODB_PASSWORD:empty}
......@@ -56,6 +56,7 @@ 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}
osdu.mongodb.maxIdleTimeMS=${MONGODB_MAX_IDLE_TIME_MS:30000}
#AWS KMS Config
aws.kms.keyArn=${KEY_ARN:empty}
......
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