d6840fedd12eaa83ebbac1389881db7ab128e268
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.core.nosqldb.util;
21
22 import java.util.HashMap;
23 import java.util.Map;
24 import org.openecomp.core.utilities.file.FileUtils;
25 import org.openecomp.core.utilities.json.JsonUtil;
26
27 public class CassandraUtils {
28
29     private static final String CASSANDRA_STATEMENT_DEFINITION_FILE = "cassandraStatements.json";
30     private static Map<String, String> statementMap = new HashMap<>();
31
32     public static String[] getAddresses() {
33         return ConfigurationManager.getInstance().getAddresses();
34     }
35
36     public static Long getReconnectTimeout() {
37         return ConfigurationManager.getInstance().getReconnectTimeout();
38     }
39
40     public static String getKeySpace() {
41         return ConfigurationManager.getInstance().getKeySpace();
42     }
43
44     /**
45      * Gets statement.
46      *
47      * @param statementName the statement name
48      * @return the statement
49      */
50     public static String getStatement(String statementName) {
51         if (statementMap.size() == 0) {
52             statementMap = FileUtils.readViaInputStream(CASSANDRA_STATEMENT_DEFINITION_FILE, stream -> JsonUtil.json2Object(stream, Map.class));
53         }
54         return statementMap.get(statementName);
55     }
56
57     public static String getUser() {
58         return ConfigurationManager.getInstance().getUsername();
59     }
60
61     public static String getPassword() {
62         return ConfigurationManager.getInstance().getPassword();
63     }
64
65     public static String getTruststore() {
66         return ConfigurationManager.getInstance().getTruststorePath();
67     }
68
69     public static String getTruststorePassword() {
70         return ConfigurationManager.getInstance().getTruststorePassword();
71     }
72
73     public static int getCassandraPort() {
74         return ConfigurationManager.getInstance().getCassandraPort();
75     }
76
77     public static boolean isSsl() {
78         return ConfigurationManager.getInstance().isSsl();
79     }
80
81     public static boolean isAuthenticate() {
82         return ConfigurationManager.getInstance().isAuthenticate();
83     }
84
85     public static String getConsistencyLevel() {
86         return ConfigurationManager.getInstance().getConsistencyLevel();
87     }
88
89     public static String getLocalDataCenter() {
90         return ConfigurationManager.getInstance().getLocalDataCenter();
91     }
92 }