summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib
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 /openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib
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 'openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java31
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java5
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java51
3 files changed, 52 insertions, 35 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java
index 87c0055b44..f0945a4da1 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java
@@ -16,9 +16,6 @@
package org.openecomp.core.nosqldb.impl.cassandra;
-import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
-import com.datastax.driver.core.policies.LoadBalancingPolicy;
-import com.datastax.driver.core.policies.TokenAwarePolicy;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.QueryOptions;
@@ -27,6 +24,7 @@ import com.datastax.driver.core.SSLOptions;
import com.datastax.driver.core.Session;
+import com.datastax.driver.core.policies.*;
import org.openecomp.core.nosqldb.util.CassandraUtils;
import org.openecomp.sdc.common.errors.SdcConfigurationException;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
@@ -59,8 +57,19 @@ public class CassandraSessionFactory {
* @return the session
*/
public static Session newCassandraSession() {
- Cluster.Builder builder = Cluster.builder();
String[] addresses = CassandraUtils.getAddresses();
+ int cassandraPort = CassandraUtils.getCassandraPort();
+ Long reconnectTimeout = CassandraUtils.getReconnectTimeout();
+
+ Cluster.Builder builder = Cluster.builder();
+
+ if(null != reconnectTimeout) {
+ builder.withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectTimeout))
+ .withRetryPolicy(DefaultRetryPolicy.INSTANCE);
+ }
+
+ builder.withPort(cassandraPort);
+
for (String address : addresses) {
builder.addContactPoint(address);
}
@@ -70,10 +79,7 @@ public class CassandraSessionFactory {
if (isSsl) {
builder.withSSL(getSslOptions());
}
- int port = CassandraUtils.getCassandraPort();
- if (port > 0) {
- builder.withPort(port);
- }
+
//Check if user/pass
Boolean isAuthenticate = CassandraUtils.isAuthenticate();
if (isAuthenticate) {
@@ -84,18 +90,19 @@ public class CassandraSessionFactory {
setLocalDataCenter(builder);
-
Cluster cluster = builder.build();
String keyStore = SessionContextProviderFactory.getInstance().createInterface().get()
.getTenant();
+ LOGGER.info("Cassandra client created hosts: {} port: {} SSL enabled: {} reconnectTimeout",
+ addresses, cassandraPort, isSsl, reconnectTimeout);
return cluster.connect(keyStore);
}
private static void setLocalDataCenter(Cluster.Builder builder) {
String localDataCenter = CassandraUtils.getLocalDataCenter();
if (Objects.nonNull(localDataCenter)) {
- LOGGER.info("localDatacenter was provided, setting Cassndra client to use datacenter: {} as " +
- "local.", localDataCenter);
+ LOGGER.info("localDatacenter was provided, setting Cassndra client to use datacenter: {} as local.",
+ localDataCenter);
LoadBalancingPolicy tokenAwarePolicy = new TokenAwarePolicy(
DCAwareRoundRobinPolicy.builder().withLocalDc(localDataCenter).build());
@@ -165,6 +172,4 @@ public class CassandraSessionFactory {
// prevent instantiation
}
}
-
-
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java
index cc9f626f62..30bc0a72a3 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java
@@ -34,7 +34,10 @@ public class CassandraUtils {
public static String[] getAddresses() {
return ConfigurationManager.getInstance().getAddresses();
+ }
+ public static Long getReconnectTimeout() {
+ return ConfigurationManager.getInstance().getReconnectTimeout();
}
public static String getKeySpace() {
@@ -78,7 +81,7 @@ public class CassandraUtils {
}
public static int getCassandraPort() {
- return ConfigurationManager.getInstance().getSslPort();
+ return ConfigurationManager.getInstance().getCassandraPort();
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java
index 0694acbda1..a1d5246eee 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java
@@ -42,6 +42,7 @@ import java.util.function.Function;
public class ConfigurationManager {
static final String CONFIGURATION_YAML_FILE = "configuration.yaml";
+ static private final Integer DEFAULT_CASSANDRA_PORT = 9042;
private static final String CASSANDRA = "cassandra";
private static final String CASSANDRA_KEY = CASSANDRA + "Config";
private static final String DEFAULT_KEYSPACE_NAME = "dox";
@@ -50,13 +51,13 @@ public class ConfigurationManager {
private static final String CASSANDRA_AUTHENTICATE = CASSANDRA + ".authenticate";
private static final String CASSANDRA_USER = CASSANDRA + ".user";
private static final String CASSANDRA_PASSWORD = CASSANDRA + ".password";
- private static final String CASSANDRA_PORT = CASSANDRA + ".port";
private static final String CASSANDRA_SSL = CASSANDRA + ".ssl";
private static final String CASSANDRA_TRUSTSTORE = CASSANDRA + ".Truststore";
private static final String CASSANDRA_TRUSTSTORE_PASSWORD = CASSANDRA + ".TruststorePassword";
private static final String CASSANDRA_HOSTS_KEY = CASSANDRA + "Hosts";
- private static final String CASSANDRA_PORT_KEY = "port";
+ private static final String CASSANDRA_PORT_KEY = "cassandraPort";
private static final String CASSANDRA_USERNAME_KEY = "username";
+ private static final String CASSANDRA_RECONNECT_TIMEOUT = "reconnectTimeout";
@SuppressWarnings("squid:S2068")
private static final String CASSANDRA_PASSWORD_KEY = "password";
private static final String CASSANDRA_AUTHENTICATE_KEY = "authenticate";
@@ -130,6 +131,33 @@ public class ConfigurationManager {
}
/**
+ * Gets Cassandra port.
+ *
+ * @return the port
+ */
+ public int getCassandraPort() {
+ Integer cassandraPort = (Integer) cassandraConfiguration.get(CASSANDRA_PORT_KEY);
+ if (Objects.isNull(cassandraPort)) {
+ cassandraPort = DEFAULT_CASSANDRA_PORT;
+ }
+ return cassandraPort;
+ }
+
+ /**
+ * Gets Cassandra reconnection timeout
+ *
+ * @return
+ */
+ public Long getReconnectTimeout() {
+ Integer cassandraReconnectTimeout = (Integer) cassandraConfiguration.get(CASSANDRA_RECONNECT_TIMEOUT);
+ if (Objects.isNull(cassandraReconnectTimeout)) {
+ LOG.info("No Cassandra reconnect timeout are defined.");
+ return null;
+ }
+ return cassandraReconnectTimeout.longValue();
+ }
+
+ /**
* Gets key space.
*
* @return the key space
@@ -195,25 +223,6 @@ public class ConfigurationManager {
}
/**
- * Gets ssl port.
- *
- * @return the ssl port
- */
- public int getSslPort() {
- int port;
- String sslPort = System.getProperty(CASSANDRA_PORT);
- if (Objects.isNull(sslPort)) {
- sslPort = (String) cassandraConfiguration.get(CASSANDRA_PORT_KEY);
- if (Objects.isNull(sslPort)) {
- sslPort = "0";
- }
- }
- port = Integer.valueOf(sslPort);
- return port;
- }
-
-
- /**
* Is ssl boolean.
*
* @return the boolean