From f54f44d747c8744c62184ccb0f1cb75681ae79b6 Mon Sep 17 00:00:00 2001 From: "Vikram Potturi(apotturi)" Date: Mon, 30 Apr 2018 18:32:55 -0400 Subject: Added loadbalancing Change-Id: I513e5add00620fc9ba39cf49af3b8ba25e91d124 Issue-ID: MUSIC-73 Signed-off-by: Vikram Potturi(apotturi) --- .../org/onap/music/datastore/MusicDataStore.java | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/jar/src/main/java/org/onap/music/datastore/MusicDataStore.java b/jar/src/main/java/org/onap/music/datastore/MusicDataStore.java index 5daeb76c..78389be5 100644 --- a/jar/src/main/java/org/onap/music/datastore/MusicDataStore.java +++ b/jar/src/main/java/org/onap/music/datastore/MusicDataStore.java @@ -171,13 +171,14 @@ public class MusicDataStore { "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd()); cluster = Cluster.builder().withPort(9042) .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd()) - .withLoadBalancingPolicy(new RoundRobinPolicy()) + //.withLoadBalancingPolicy(new RoundRobinPolicy()) .withPoolingOptions(poolingOptions) .addContactPoints(addresses).build(); } else cluster = Cluster.builder().withPort(9042) - .withLoadBalancingPolicy(new RoundRobinPolicy()) + //.withLoadBalancingPolicy(new RoundRobinPolicy()) + .withPoolingOptions(poolingOptions) .addContactPoints(addresses).build(); Metadata metadata = cluster.getMetadata(); @@ -206,9 +207,27 @@ public class MusicDataStore { * @param address */ private void connectToCassaCluster(String address) throws MusicServiceException { - cluster = Cluster.builder().withPort(9042) - .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd()) - .addContactPoint(address).build(); + String[] addresses = null; + addresses = address.split(","); + PoolingOptions poolingOptions = new PoolingOptions(); + poolingOptions + .setConnectionsPerHost(HostDistance.LOCAL, 4, 10) + .setConnectionsPerHost(HostDistance.REMOTE, 2, 4); + if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) { + logger.info(EELFLoggerDelegate.applicationLogger, + "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd()); + cluster = Cluster.builder().withPort(9042) + .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd()) + .withLoadBalancingPolicy(new RoundRobinPolicy()) + .withPoolingOptions(poolingOptions) + .addContactPoints(addresses).build(); + } + else { + cluster = Cluster.builder().withPort(9042) + .withLoadBalancingPolicy(new RoundRobinPolicy()) + .withPoolingOptions(poolingOptions) + .addContactPoints(addresses).build(); + } Metadata metadata = cluster.getMetadata(); logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster " + metadata.getClusterName() + " at " + address); -- cgit 1.2.3-korg