summaryrefslogtreecommitdiffstats
path: root/catalog-dao
diff options
context:
space:
mode:
authorTal Gitelman <tal.gitelman@att.com>2019-03-28 11:00:54 +0200
committerTal Gitelman <tal.gitelman@att.com>2019-04-04 16:33:03 +0300
commitc4d387d216e72911f80c1ebee91b73aba191b91b (patch)
treec12066b7a213d34ca7c84375fb4bb2d6f0b23138 /catalog-dao
parentac3aca69dbeae29c9aeca2053adc7aedbb75e149 (diff)
Make Cassandra port configurable.
SDC-BE & Onboarding - BE. Reviewer: Evgenia A & Areli F. Change-Id: Iaf86d647b0560764ef65d9148c85bffaf934992d Issue-ID: SDC-2077 Signed-off-by: Tal Gitelman <tal.gitelman@att.com>
Diffstat (limited to 'catalog-dao')
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java10
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java9
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtilsTest.java20
3 files changed, 30 insertions, 9 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java
index 8889cc212e..028247d75a 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/CassandraClient.java
@@ -49,15 +49,16 @@ public class CassandraClient {
try {
cassandraHosts = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig()
.getCassandraHosts();
+ Integer cassandraPort = ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig()
+ .getCassandraPort();
Long reconnectTimeout = ConfigurationManager.getConfigurationManager().getConfiguration()
.getCassandraConfig().getReconnectTimeout();
-
- logger.debug("creating cluster to hosts:{} with reconnect timeout:{}", cassandraHosts, reconnectTimeout);
+ logger.debug("creating cluster to hosts:{} port:{} with reconnect timeout:{}", cassandraHosts, cassandraPort, reconnectTimeout);
Cluster.Builder clusterBuilder = Cluster.builder()
.withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectTimeout))
.withRetryPolicy(DefaultRetryPolicy.INSTANCE);
- cassandraHosts.forEach(clusterBuilder::addContactPoint);
+ cassandraHosts.forEach(host -> clusterBuilder.addContactPoint(host).withPort(cassandraPort));
setSocketOptions(clusterBuilder);
enableAuthentication(clusterBuilder);
enableSsl(clusterBuilder);
@@ -154,8 +155,7 @@ public class CassandraClient {
return Either.right(CassandraOperationStatus.KEYSPACE_NOT_CONNECTED);
}
} catch (Throwable e) {
- logger.debug("Failed to connect to keyspace [{}], error ,", keyspace);
- logger.debug("Exception :", e);
+ logger.debug("Failed to connect to keyspace [{}], error :", keyspace, e);
return Either.right(CassandraOperationStatus.KEYSPACE_NOT_CONNECTED);
}
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java
index 7531ad4c0a..e6b091b72f 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java
@@ -44,13 +44,14 @@ public class SdcSchemaUtils {
public Cluster createCluster() {
final Configuration.CassandrConfig config = getCassandraConfig();
List<String> nodes = config.getCassandraHosts();
- if (nodes == null) {
- log.info("no nodes were supplied in configuration.");
+ Integer cassandraPort = config.getCassandraPort();
+ if (nodes == null || cassandraPort == null) {
+ log.info("no nodes or port were supplied in configuration.");
return null;
}
- log.info("connecting to node:{}.", nodes);
+ log.info("connecting to node:{} port{}.", nodes, cassandraPort);
Cluster.Builder clusterBuilder = Cluster.builder();
- nodes.forEach(clusterBuilder::addContactPoint);
+ nodes.forEach(node -> clusterBuilder.addContactPoint(node).withPort(cassandraPort));
clusterBuilder.withMaxSchemaAgreementWaitSeconds(60);
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtilsTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtilsTest.java
index ca8bdea30a..39a19641f0 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtilsTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtilsTest.java
@@ -37,6 +37,7 @@ public class SdcSchemaUtilsTest {
private static final String SINGLE_STATEMENT = "SELECT COUNT(*) FROM system.peers";
private static final String[] MULTIPLE_STATEMENTS = new String[] {SINGLE_STATEMENT, SINGLE_STATEMENT};
private static final List<String> CASSANDRA_HOSTS = Collections.singletonList(CassandraTestHelper.SERVER);
+ private static final Integer CASSANDRA_PORT = 9042;
private static final String CASSANDRA_USERNAME = "username";
private static final String CASSANDRA_PASSWORD = "password";
private static final String TRUSTSTORE_PATH = "pathToTruststore";
@@ -80,6 +81,7 @@ public class SdcSchemaUtilsTest {
public void testCreateClusterNoAuthNoSsl() {
Configuration.CassandrConfig cfg = new Configuration.CassandrConfig();
cfg.setCassandraHosts(CASSANDRA_HOSTS);
+ cfg.setCassandraPort(CASSANDRA_PORT);
SdcSchemaUtils sdcSchemaUtils = Mockito.mock(SdcSchemaUtils.class);
when(sdcSchemaUtils.getCassandraConfig()).thenReturn(cfg);
@@ -105,10 +107,26 @@ public class SdcSchemaUtilsTest {
}
@Test
+ public void testCreateClusterWithDefaultOnLackOfCassandraPort() {
+ Configuration.CassandrConfig cfg = new Configuration.CassandrConfig();
+ cfg.setCassandraHosts(CASSANDRA_HOSTS);
+ cfg.setCassandraPort(null);
+
+ SdcSchemaUtils sdcSchemaUtils = Mockito.mock(SdcSchemaUtils.class);
+ when(sdcSchemaUtils.getCassandraConfig()).thenReturn(cfg);
+ when(sdcSchemaUtils.createCluster()).thenCallRealMethod();
+
+ try(Cluster cluster = sdcSchemaUtils.createCluster()) {
+ Assert.assertNotNull(cluster);
+ }
+ }
+
+ @Test
public void testCreateClusterFailOnAuthEnabledWithNoCredentials() {
Configuration.CassandrConfig cfg = new Configuration.CassandrConfig();
cfg.setAuthenticate(true);
cfg.setCassandraHosts(CASSANDRA_HOSTS);
+ cfg.setCassandraPort(CASSANDRA_PORT);
cfg.setUsername(null);
cfg.setPassword(null);
@@ -125,6 +143,7 @@ public class SdcSchemaUtilsTest {
public void testCreateClusterFailOnSSLWithNoCredentials() {
Configuration.CassandrConfig cfg = new Configuration.CassandrConfig();
cfg.setCassandraHosts(CASSANDRA_HOSTS);
+ cfg.setCassandraPort(CASSANDRA_PORT);
cfg.setSsl(true);
cfg.setTruststorePath(null);
cfg.setTruststorePassword(null);
@@ -143,6 +162,7 @@ public class SdcSchemaUtilsTest {
Configuration.CassandrConfig cfg = new Configuration.CassandrConfig();
cfg.setAuthenticate(true);
cfg.setCassandraHosts(CASSANDRA_HOSTS);
+ cfg.setCassandraPort(CASSANDRA_PORT);
cfg.setUsername(CASSANDRA_USERNAME);
cfg.setPassword(CASSANDRA_PASSWORD);
cfg.setSsl(true);