diff options
Diffstat (limited to 'music-core/src')
-rwxr-xr-x | music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java | 57 | ||||
-rw-r--r-- | music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java | 2 |
2 files changed, 30 insertions, 29 deletions
diff --git a/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java b/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java index 5a658688..97fc1d33 100755 --- a/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java +++ b/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java @@ -78,6 +78,28 @@ public class MusicDataStore { /** + * Connect to default Cassandra address + */ + public MusicDataStore() { + try { + connectToCassaCluster(MusicUtil.getMyCassaHost()); + } catch (MusicServiceException e) { + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), e); + } + } + + + /** + * @param cluster + * @param session + */ + public MusicDataStore(Cluster cluster, Session session) { + this.session = session; + setCluster(cluster); + } + + + /** * @param session */ public void setSession(Session session) { @@ -95,6 +117,9 @@ public class MusicDataStore { * @param cluster */ public void setCluster(Cluster cluster) { + EnumNameCodec<LockType> lockTypeCodec = new EnumNameCodec<LockType>(LockType.class); + cluster.getConfiguration().getCodecRegistry().register(lockTypeCodec); + this.cluster = cluster; } @@ -105,27 +130,7 @@ public class MusicDataStore { private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStore.class); - /** - * Connect to default Cassandra address - */ - public MusicDataStore() { - try { - connectToCassaCluster(MusicUtil.getMyCassaHost()); - } catch (MusicServiceException e) { - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), e); - } - } - - - /** - * @param cluster - * @param session - */ - public MusicDataStore(Cluster cluster, Session session) { - this.session = session; - this.cluster = cluster; - } - + /** * * @param remoteIp @@ -159,6 +164,7 @@ public class MusicDataStore { .setConnectionsPerHost(HostDistance.LOCAL, 4, 10) .setConnectionsPerHost(HostDistance.REMOTE, 2, 4); + Cluster cluster; if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) { String cassPwd = CipherUtil.decryptPKC(MusicUtil.getCassPwd()); logger.info(EELFLoggerDelegate.applicationLogger, @@ -177,16 +183,13 @@ public class MusicDataStore { .build(); } - - Metadata metadata = cluster.getMetadata(); + this.setCluster(cluster); + Metadata metadata = this.cluster.getMetadata(); logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster " + metadata.getClusterName() + " at " + address); - - EnumNameCodec<LockType> lockTypeCodec = new EnumNameCodec<LockType>(LockType.class); - cluster.getConfiguration().getCodecRegistry().register(lockTypeCodec); try { - session = cluster.connect(); + session = this.cluster.connect(); } catch (Exception ex) { logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.CASSANDRACONNECTIVITY, ErrorSeverity.ERROR, ErrorTypes.SERVICEUNAVAILABLE, ex); diff --git a/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java b/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java index 7b116bc8..582744fb 100644 --- a/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java +++ b/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java @@ -236,8 +236,6 @@ public class CassandraCQL { EmbeddedCassandraServerHelper.startEmbeddedCassandra(); Cluster cluster = new Cluster.Builder().withoutJMXReporting().withoutMetrics().addContactPoint(address).withPort(9142).build(); cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(5000); - EnumNameCodec<LockType> lockTypeCodec = new EnumNameCodec<LockType>(LockType.class); - cluster.getConfiguration().getCodecRegistry().register(lockTypeCodec); Session session = cluster.connect(); |