Make Cassandra port configurable.
[sdc.git] / openecomp-be / lib / openecomp-core-lib / openecomp-nosqldb-lib / openecomp-nosqldb-core / src / main / java / org / openecomp / core / nosqldb / util / CassandraUtils.java
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
21 package org.openecomp.core.nosqldb.util;
22
23 import org.openecomp.core.utilities.file.FileUtils;
24 import org.openecomp.core.utilities.json.JsonUtil;
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29 public class CassandraUtils {
30
31
32   private static final String CASSANDRA_STATEMENT_DEFINITION_FILE = "cassandraStatements.json";
33   private static Map<String, String> statementMap = new HashMap<>();
34
35   public static String[] getAddresses() {
36     return ConfigurationManager.getInstance().getAddresses();
37   }
38
39   public static Long getReconnectTimeout() {
40     return ConfigurationManager.getInstance().getReconnectTimeout();
41   }
42
43   public static String getKeySpace() {
44     return ConfigurationManager.getInstance().getKeySpace();
45   }
46
47   /**
48    * Gets statement.
49    *
50    * @param statementName the statement name
51    * @return the statement
52    */
53   public static String getStatement(String statementName) {
54
55     if (statementMap.size() == 0) {
56       statementMap = FileUtils.readViaInputStream(CASSANDRA_STATEMENT_DEFINITION_FILE,
57           stream -> JsonUtil.json2Object(stream, Map.class));
58     }
59
60     return statementMap.get(statementName);
61   }
62
63   public static String getUser() {
64
65     return ConfigurationManager.getInstance().getUsername();
66   }
67
68   public static String getPassword() {
69     return ConfigurationManager.getInstance().getPassword();
70
71   }
72
73   public static String getTruststore() {
74     return ConfigurationManager.getInstance().getTruststorePath();
75
76   }
77
78   public static String getTruststorePassword() {
79     return ConfigurationManager.getInstance().getTruststorePassword();
80
81   }
82
83   public static int getCassandraPort() {
84     return ConfigurationManager.getInstance().getCassandraPort();
85
86   }
87
88   public static boolean isSsl() {
89     return ConfigurationManager.getInstance().isSsl();
90
91   }
92
93   public static boolean isAuthenticate() {
94     return ConfigurationManager.getInstance().isAuthenticate();
95   }
96
97   public static String getConsistencyLevel() {
98
99     return ConfigurationManager.getInstance().getConsistencyLevel();
100
101   }
102
103   public static String getLocalDataCenter() {
104     return ConfigurationManager.getInstance().getLocalDataCenter();
105   }
106 }