push addional code
[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.io.InputStream;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 public class CassandraUtils {
31
32
33   private static final String CASSANDRA_STATEMENT_DEFINITION_FILE = "cassandraStatements.json";
34   private static Map<String, String> statementMap = new HashMap<>();
35
36   public static String[] getAddresses() {
37     return ConfigurationManager.getInstance().getAddresses();
38
39   }
40
41   public static String getKeySpace() {
42     return ConfigurationManager.getInstance().getKeySpace();
43   }
44
45   /**
46    * Gets statement.
47    *
48    * @param statementName the statement name
49    * @return the statement
50    */
51   public static String getStatement(String statementName) {
52     if (statementMap.size() == 0) {
53       InputStream statementJson = FileUtils.getFileInputStream(CASSANDRA_STATEMENT_DEFINITION_FILE);
54       statementMap = JsonUtil.json2Object(statementJson, Map.class);
55     }
56     return statementMap.get(statementName);
57   }
58
59   public static String getUser() {
60
61     return ConfigurationManager.getInstance().getUsername();
62   }
63
64   public static String getPassword() {
65     return ConfigurationManager.getInstance().getPassword();
66
67   }
68
69   public static String getTruststore() {
70     return ConfigurationManager.getInstance().getTruststorePath();
71
72   }
73
74   public static String getTruststorePassword() {
75     return ConfigurationManager.getInstance().getTruststorePassword();
76
77   }
78
79   public static int getCassandraPort() {
80     return ConfigurationManager.getInstance().getSslPort();
81
82   }
83
84   public static boolean isSsl() {
85     return ConfigurationManager.getInstance().isSsl();
86
87   }
88
89   public static boolean isAuthenticate() {
90     return ConfigurationManager.getInstance().isAuthenticate();
91   }
92 }