--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.api.config;\r
+\r
+import com.mongodb.MongoClient;\r
+import com.mongodb.MongoClientOptions;\r
+import com.mongodb.MongoCredential;\r
+import com.mongodb.ServerAddress;\r
+import java.util.ArrayList;\r
+import org.springframework.beans.factory.annotation.Value;\r
+import org.springframework.context.annotation.Bean;\r
+import org.springframework.context.annotation.Configuration;\r
+import org.springframework.context.annotation.Profile;\r
+import org.springframework.data.mongodb.config.AbstractMongoConfiguration;\r
+import org.springframework.data.mongodb.core.MongoTemplate;\r
+import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;\r
+\r
+@Configuration\r
+@EnableMongoRepositories(basePackages = "org.oran.otf.common.repository")\r
+@Profile("!test")\r
+public class DataConfig extends AbstractMongoConfiguration {\r
+\r
+ @Value("${otf.mongo.hosts}")\r
+ private String hosts;\r
+\r
+ @Value("${otf.mongo.username}")\r
+ private String username;\r
+\r
+ @Value("${otf.mongo.password}")\r
+ private String password;\r
+\r
+ @Value("${otf.mongo.replicaSet}")\r
+ private String replicaSet;\r
+\r
+ @Value("${otf.mongo.database}")\r
+ private String database;\r
+\r
+ public DataConfig() {}\r
+\r
+ @Override\r
+ protected String getDatabaseName() {\r
+ return database;\r
+ }\r
+\r
+ @Override\r
+ public MongoClient mongoClient() {\r
+ MongoCredential credential =\r
+ MongoCredential.createScramSha1Credential(username, database, password.toCharArray());\r
+\r
+ MongoClientOptions options =\r
+ MongoClientOptions.builder().sslEnabled(false).requiredReplicaSetName(replicaSet).build();\r
+\r
+ String[] hostArray = hosts.split(",");\r
+ ArrayList<ServerAddress> hosts = new ArrayList<>();\r
+\r
+ for (String host : hostArray) {\r
+ String[] hostSplit = host.split(":");\r
+ hosts.add(new ServerAddress(hostSplit[0], Integer.parseInt(hostSplit[1])));\r
+ }\r
+\r
+ return new MongoClient(hosts, credential, options);\r
+ }\r
+\r
+ @Override\r
+ @Bean\r
+ public MongoTemplate mongoTemplate() {\r
+ return new MongoTemplate(mongoClient(), database);\r
+ }\r
+}\r