aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/music/datastore/MusicDataStore.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/music/datastore/MusicDataStore.java')
-rw-r--r--src/main/java/org/onap/music/datastore/MusicDataStore.java104
1 files changed, 7 insertions, 97 deletions
diff --git a/src/main/java/org/onap/music/datastore/MusicDataStore.java b/src/main/java/org/onap/music/datastore/MusicDataStore.java
index 1ea10054..deb65edd 100644
--- a/src/main/java/org/onap/music/datastore/MusicDataStore.java
+++ b/src/main/java/org/onap/music/datastore/MusicDataStore.java
@@ -65,13 +65,6 @@ public class MusicDataStore {
/**
- * Constructs DataStore by connecting to local Cassandra
- */
- public MusicDataStore() {
- connectToLocalCassandraCluster();
- }
-
- /**
* Constructs DataStore by providing existing cluster and session
* @param cluster
* @param session
@@ -82,94 +75,6 @@ public class MusicDataStore {
}
/**
- * Constructs DataStore by connecting to provided remote Cassandra
- * @param remoteAddress
- * @throws MusicServiceException
- */
- public MusicDataStore(String remoteAddress) {
- try {
- connectToRemoteCassandraCluster(remoteAddress);
- } catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
- }
-
- private void createCassandraSession(String address) throws NoHostAvailableException {
- cluster = Cluster.builder().withPort(9042)
- .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd())
- .addContactPoint(address).build();
- Metadata metadata = cluster.getMetadata();
- logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster "
- + metadata.getClusterName() + " at " + address);
- session = cluster.connect();
- }
-
- /**
- *
- * @return
- */
- private ArrayList<String> getAllPossibleLocalIps() {
- ArrayList<String> allPossibleIps = new ArrayList<String>();
- try {
- Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
- while (en.hasMoreElements()) {
- NetworkInterface ni = (NetworkInterface) en.nextElement();
- Enumeration<InetAddress> ee = ni.getInetAddresses();
- while (ee.hasMoreElements()) {
- InetAddress ia = (InetAddress) ee.nextElement();
- allPossibleIps.add(ia.getHostAddress());
- }
- }
- } catch (SocketException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.CONNCECTIVITYERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- }catch(Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), ErrorSeverity.ERROR, ErrorTypes.GENERALSERVICEERROR);
- }
- return allPossibleIps;
- }
-
- /**
- * This method iterates through all available local IP addresses and tries to connect to first successful one
- */
- private void connectToLocalCassandraCluster() {
- ArrayList<String> localAddrs = getAllPossibleLocalIps();
- localAddrs.add(0, "localhost");
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Connecting to cassa cluster: Iterating through possible ips:"
- + getAllPossibleLocalIps());
- for (String address: localAddrs) {
- try {
- createCassandraSession(address);
- break;
- } catch (NoHostAvailableException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.HOSTUNAVAILABLE, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- }
- }
- }
-
- /**
- * This method connects to cassandra cluster on specific address.
- *
- * @param address
- */
- private void connectToRemoteCassandraCluster(String address) throws MusicServiceException {
- try {
- createCassandraSession(address);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.CASSANDRACONNECTIVITY, ErrorSeverity.ERROR, ErrorTypes.SERVICEUNAVAILABLE);
- throw new MusicServiceException(
- "Error while connecting to Cassandra cluster.. " + ex.getMessage());
- }
- }
-
- /**
- *
- */
- public void close() {
- session.close();
- }
-
- /**
*
* @param keyspace
* @param tableName
@@ -203,7 +108,7 @@ public class MusicDataStore {
* @param colType
* @return
*/
- public Object getColValue(Row row, String colName, DataType colType) {
+ public static Object getColValue(Row row, String colName, DataType colType) {
switch (colType.getName()) {
case VARCHAR:
@@ -237,7 +142,7 @@ public class MusicDataStore {
return data;
}
- public boolean doesRowSatisfyCondition(Row row, Map<String, Object> condition) throws Exception {
+ public static boolean doesRowSatisfyCondition(Row row, Map<String, Object> condition) throws Exception {
ColumnDefinitions colInfo = row.getColumnDefinitions();
for (Map.Entry<String, Object> entry : condition.entrySet()) {
@@ -453,5 +358,10 @@ public class MusicDataStore {
TimeMeasureInstance.instance().exit();
}
}
+
+ @Deprecated
+ public void close() {
+ session.close();
+ }
}