summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-core-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.java48
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java14
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java47
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml8
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java77
5 files changed, 155 insertions, 39 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 4bc8262439..18b4b06811 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
@@ -21,13 +21,21 @@
package org.openecomp.core.nosqldb.impl.cassandra;
import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.ConsistencyLevel;
+import com.datastax.driver.core.QueryOptions;
import com.datastax.driver.core.SSLOptions;
import com.datastax.driver.core.Session;
+import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
+import com.datastax.driver.core.policies.LoadBalancingPolicy;
+import com.datastax.driver.core.policies.TokenAwarePolicy;
import com.google.common.base.Optional;
+import org.apache.commons.lang.ArrayUtils;
import org.openecomp.core.nosqldb.util.CassandraUtils;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyManagementException;
@@ -37,8 +45,7 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManagerFactory;
+import java.util.Objects;
public class CassandraSessionFactory {
@@ -75,11 +82,46 @@ public class CassandraSessionFactory {
if (isAuthenticate) {
builder.withCredentials(CassandraUtils.getUser(), CassandraUtils.getPassword());
}
+
+ setConsistencyLevel(builder, addresses);
+
+ setLocalDataCenter(builder);
+
+
Cluster cluster = builder.build();
String keyStore = CassandraUtils.getKeySpace();
return cluster.connect(keyStore);
}
+ private static void setLocalDataCenter(Cluster.Builder builder) {
+ String localDataCenter = CassandraUtils.getLocalDataCenter();
+ if (Objects.nonNull(localDataCenter)) {
+ log.info("localDatacenter was provided, setting Cassndra client to use datacenter: {} as " +
+ "local.", localDataCenter);
+
+ LoadBalancingPolicy tokenAwarePolicy = new TokenAwarePolicy(
+ DCAwareRoundRobinPolicy.builder().withLocalDc(localDataCenter).build());
+ builder.withLoadBalancingPolicy(tokenAwarePolicy);
+ } else {
+ log.info(
+ "localDatacenter was provided, the driver will use the datacenter of the first contact point that was reached at initialization");
+ }
+ }
+
+ private static void setConsistencyLevel(Cluster.Builder builder, String[] addresses) {
+ if (ArrayUtils.isNotEmpty(addresses) && addresses.length > 1) {
+ String consistencyLevel = CassandraUtils.getConsistencyLevel();
+ if (Objects.nonNull(consistencyLevel)) {
+ log.info(
+ "consistencyLevel was provided, setting Cassandra client to use consistencyLevel: {}" +
+ " as "
+ , consistencyLevel);
+ builder.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf
+ (consistencyLevel)));
+ }
+ }
+ }
+
private static Optional<SSLOptions> getSslOptions() {
Optional<String> truststorePath = Optional.of(CassandraUtils.getTruststore());
Optional<String> truststorePassword = Optional.of(CassandraUtils.getTruststorePassword());
@@ -116,7 +158,7 @@ public class CassandraSessionFactory {
ctx.init(null, tmf.getTrustManagers(), new SecureRandom());
} catch (Exception exception) {
- log.debug("",exception);
+ log.debug("", exception);
} finally {
if (tsf != null) {
tsf.close();
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 7a70900873..cc9f626f62 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
@@ -50,8 +50,8 @@ public class CassandraUtils {
public static String getStatement(String statementName) {
if (statementMap.size() == 0) {
- statementMap = FileUtils.readViaInputStream(CASSANDRA_STATEMENT_DEFINITION_FILE,
- stream -> JsonUtil.json2Object(stream, Map.class));
+ statementMap = FileUtils.readViaInputStream(CASSANDRA_STATEMENT_DEFINITION_FILE,
+ stream -> JsonUtil.json2Object(stream, Map.class));
}
return statementMap.get(statementName);
@@ -90,4 +90,14 @@ public class CassandraUtils {
public static boolean isAuthenticate() {
return ConfigurationManager.getInstance().isAuthenticate();
}
+
+ public static String getConsistencyLevel() {
+
+ return ConfigurationManager.getInstance().getConsistencyLevel();
+
+ }
+
+ public static String getLocalDataCenter() {
+ return ConfigurationManager.getInstance().getLocalDataCenter();
+ }
}
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 bde9d06ae4..80adeb6e2a 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
@@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.function.Function;
/**
@@ -60,6 +61,10 @@ public class ConfigurationManager {
private static final String CASSANDRA_SSL_KEY = "ssl";
private static final String CASSANDRA_TRUSTSTORE_PATH_KEY = "truststorePath";
private static final String CASSANDRA_TRUSTSTORE_PASSWORD_KEY = "truststorePassword";
+ private static final String CONSISTENCY_LEVEL = "cassandra.consistencyLevel";
+ private static final String CONSISTENCY_LEVEL_KEY = "consistencyLevel";
+ private static final String LOCAL_DATA_CENTER_KEY = "localDataCenter";
+ private static final String LOCAL_DATA_CENTER = "cassandra.localDataCenter";
private static ConfigurationManager instance = null;
private final LinkedHashMap<String, Object> cassandraConfiguration;
@@ -78,8 +83,8 @@ public class ConfigurationManager {
try {
Map<String, LinkedHashMap<String, Object>> configurationMap = configurationYamlFile != null
- ? readFromFile(configurationYamlFile, reader) // load from file
- : FileUtils.readViaInputStream(CONFIGURATION_YAML_FILE, reader); // or from resource
+ ? readFromFile(configurationYamlFile, reader) // load from file
+ : FileUtils.readViaInputStream(CONFIGURATION_YAML_FILE, reader); // or from resource
cassandraConfiguration = configurationMap.get(CASSANDRA_KEY);
} catch (IOException e) {
@@ -93,7 +98,7 @@ public class ConfigurationManager {
* @return the instance
*/
public static ConfigurationManager getInstance() {
- if (instance == null) {
+ if (Objects.isNull(instance)) {
instance = new ConfigurationManager();
}
return instance;
@@ -107,7 +112,7 @@ public class ConfigurationManager {
public String[] getAddresses() {
String addresses = System.getProperty(CASSANDRA_ADDRESSES);
- if (addresses != null) {
+ if (Objects.isNull(addresses)) {
return addresses.split(",");
}
List lsAddresses = (ArrayList) cassandraConfiguration.get(CASSANDRA_HOSTS_KEY);
@@ -124,7 +129,7 @@ public class ConfigurationManager {
*/
public String getKeySpace() {
String keySpace = System.getProperty(CASSANDRA_DOX_KEY_STORE);
- if (keySpace == null) {
+ if (Objects.isNull(keySpace)) {
//keySpace = cassandraConfiguration.get(cassandraKeySpaceKey);
//if (keySpace == null)
keySpace = DEFAULT_KEYSPACE_NAME;
@@ -139,7 +144,7 @@ public class ConfigurationManager {
*/
public String getUsername() {
String username = System.getProperty(CASSANDRA_USER);
- if (username == null) {
+ if (Objects.isNull(username)) {
username = (String) cassandraConfiguration.get(CASSANDRA_USERNAME_KEY);
}
return username;
@@ -152,7 +157,7 @@ public class ConfigurationManager {
*/
public String getPassword() {
String password = System.getProperty(CASSANDRA_PASSWORD);
- if (password == null) {
+ if (Objects.isNull(password)) {
password = (String) cassandraConfiguration.get(CASSANDRA_PASSWORD_KEY);
}
return password;
@@ -165,7 +170,7 @@ public class ConfigurationManager {
*/
public String getTruststorePath() {
String truststorePath = System.getProperty(CASSANDRA_TRUSTSTORE);
- if (truststorePath == null) {
+ if (Objects.isNull(truststorePath)) {
truststorePath = (String) cassandraConfiguration.get(CASSANDRA_TRUSTSTORE_PATH_KEY);
}
return truststorePath;
@@ -178,7 +183,7 @@ public class ConfigurationManager {
*/
public String getTruststorePassword() {
String truststorePassword = System.getProperty(CASSANDRA_TRUSTSTORE_PASSWORD);
- if (truststorePassword == null) {
+ if (Objects.isNull(truststorePassword)) {
truststorePassword = (String) cassandraConfiguration.get(CASSANDRA_TRUSTSTORE_PASSWORD_KEY);
}
return truststorePassword;
@@ -192,9 +197,9 @@ public class ConfigurationManager {
public int getSslPort() {
int port;
String sslPort = System.getProperty(CASSANDRA_PORT);
- if (sslPort == null) {
+ if (Objects.isNull(sslPort)) {
sslPort = (String) cassandraConfiguration.get(CASSANDRA_PORT_KEY);
- if (sslPort == null) {
+ if (Objects.isNull(sslPort)) {
sslPort = "0";
}
}
@@ -240,4 +245,24 @@ public class ConfigurationManager {
return reader.apply(is);
}
}
+
+ public String getConsistencyLevel() {
+ String consistencyLevel = System.getProperty(CONSISTENCY_LEVEL);
+ if (Objects.isNull(consistencyLevel)) {
+ consistencyLevel = (String) cassandraConfiguration.get(CONSISTENCY_LEVEL_KEY);
+ }
+
+ if (Objects.isNull(consistencyLevel)) {
+ consistencyLevel = "LOCAL_QUORUM";
+ }
+ return consistencyLevel;
+ }
+
+ public String getLocalDataCenter() {
+ String localDataCenter = System.getProperty(LOCAL_DATA_CENTER);
+ if (Objects.isNull(localDataCenter)) {
+ localDataCenter = (String) cassandraConfiguration.get(LOCAL_DATA_CENTER_KEY);
+ }
+ return localDataCenter;
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml
index b172ec97ab..a792abbfbb 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/pom.xml
@@ -21,17 +21,17 @@
<dependency>
<groupId>com.amdocs.zusammen</groupId>
<artifactId>zusammen-commons-utils</artifactId>
- <version>${zusammen.version}</version>
+ <version>${zusammen.version}</version>
</dependency>
<dependency>
<groupId>com.amdocs.zusammen</groupId>
<artifactId>zusammen-adaptor-inbound-api</artifactId>
- <version>${zusammen.version}</version>
+ <version>${zusammen.version}</version>
</dependency>
<dependency>
<groupId>com.amdocs.zusammen</groupId>
<artifactId>zusammen-adaptor-inbound-impl</artifactId>
- <version>${zusammen.version}</version>
+ <version>${zusammen.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
@@ -53,7 +53,7 @@
<dependency>
<groupId>com.amdocs.zusammen.plugin</groupId>
<artifactId>zusammen-search-index-empty-plugin</artifactId>
- <version>${zusammen.version}</version>
+ <version>${zusammen-index-store.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java
index 47cb57c5f7..0115ab6d5b 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java
@@ -6,6 +6,7 @@ import org.openecomp.core.nosqldb.util.CassandraUtils;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
+import java.util.Objects;
/**
* @author Avrahamg
@@ -13,39 +14,77 @@ import javax.servlet.ServletContextListener;
*/
public class CassandraConnectionInitializer implements ServletContextListener {
+
+ private static String DATA_CENTER_PROPERTY_NAME = "cassandra.datacenter";
+ private static String CONSISTENCY_LEVEL_PROPERTY_NAME = "cassandra.consistency.level";
+ private static String NODES_PROPERTY_NAME = "cassandra.nodes";
+ private static String AUTHENTICATE_PROPERTY_NAME = "cassandra.authenticate";
+ private static String TRUE = "true";
+ private static String FALSE = "false";
+ private static String SSL_PROPERTY_NAME = "cassandra.ssl";
+ private static String TRUSTSTORE_PROPERTY_NAME = "cassandra.truststore";
+ private static String TRUSTSTORE_PASSWORD_PROPERTY_NAME = "cassandra.truststore.password";
+ private static String USER_PROPERTY_NAME = "cassandra.user";
+ private static String PASSWORD_PROPERTY_NAME = "cassandra.password";
+ private static String KEYSPACE_PROPERTY_NAME = "cassandra.keyspace";
+ private static String ZUSAMMEN = "zusammen";
+
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
setCassandraConnectionPropertiesToSystem();
}
public static void setCassandraConnectionPropertiesToSystem() {
- if (!System.getProperties().containsKey("cassandra.nodes")) {
- System.setProperty("cassandra.nodes", StringUtils.join(CassandraUtils.getAddresses(), ','));
+
+ if (!System.getProperties().containsKey(NODES_PROPERTY_NAME)) {
+ System.setProperty(NODES_PROPERTY_NAME, StringUtils.join(CassandraUtils.getAddresses(), ','));
+ }
+
+ if (!System.getProperties().containsKey(AUTHENTICATE_PROPERTY_NAME)) {
+ System.setProperty(AUTHENTICATE_PROPERTY_NAME,
+ CassandraUtils.isAuthenticate() ? TRUE : FALSE);
+ }
+ if (!System.getProperties().containsKey(SSL_PROPERTY_NAME)) {
+ System.setProperty(SSL_PROPERTY_NAME,
+ CassandraUtils.isSsl() ? TRUE : FALSE);
}
- if (!System.getProperties().containsKey("cassandra.authenticate")) {
- System
- .setProperty("cassandra.authenticate",
- CassandraUtils.isAuthenticate() ? "true" : "false");
+
+ if (!System.getProperties().containsKey(TRUSTSTORE_PROPERTY_NAME)) {
+ System.setProperty(TRUSTSTORE_PROPERTY_NAME, CassandraUtils.getTruststore());
}
- if (!System.getProperties().containsKey("cassandra.ssl")) {
- System.setProperty("cassandra.ssl",
- CassandraUtils.isSsl() ? "true" : "false");
+
+ if (!System.getProperties().containsKey(TRUSTSTORE_PASSWORD_PROPERTY_NAME)) {
+ System.setProperty(TRUSTSTORE_PASSWORD_PROPERTY_NAME, CassandraUtils.getTruststorePassword());
}
- if (!System.getProperties().containsKey("cassandra.truststore")) {
- System.setProperty("cassandra.truststore", CassandraUtils.getTruststore());
+
+ if (!System.getProperties().containsKey(USER_PROPERTY_NAME)) {
+ System.setProperty(USER_PROPERTY_NAME, CassandraUtils.getUser());
}
- if (!System.getProperties().containsKey("cassandra.truststore.password")) {
- System.setProperty("cassandra.truststore.password", CassandraUtils.getTruststorePassword());
+
+ if (!System.getProperties().containsKey(PASSWORD_PROPERTY_NAME)) {
+ System.setProperty(PASSWORD_PROPERTY_NAME, CassandraUtils.getPassword());
}
- if (!System.getProperties().containsKey("cassandra.user")) {
- System.setProperty("cassandra.user", CassandraUtils.getUser());
+
+ if (!System.getProperties().containsKey(KEYSPACE_PROPERTY_NAME)) {
+ System.setProperty(KEYSPACE_PROPERTY_NAME, ZUSAMMEN);
}
- if (!System.getProperties().containsKey("cassandra.password")) {
- System.setProperty("cassandra.password", CassandraUtils.getPassword());
+
+
+ if (!System.getProperties().containsKey(DATA_CENTER_PROPERTY_NAME)) {
+ String dataCenter = CassandraUtils.getLocalDataCenter();
+ if (Objects.nonNull(dataCenter)) {
+ System.setProperty(DATA_CENTER_PROPERTY_NAME, dataCenter);
+ }
}
- if (!System.getProperties().containsKey("cassandra.keyspace")) {
- System.setProperty("cassandra.keyspace", "zusammen");
+
+ if (!System.getProperties().containsKey(CONSISTENCY_LEVEL_PROPERTY_NAME)) {
+ String consistencyLevel = CassandraUtils.getConsistencyLevel();
+ if (Objects.nonNull(consistencyLevel)) {
+ System.setProperty(CONSISTENCY_LEVEL_PROPERTY_NAME, consistencyLevel);
+ }
}
+
+
}
// -Dcassandra.nodes=10.147.97.145 -Dcassandra.keyspace=zusammen -Dcassandra.authenticate=true -Dcassandra.ssl=true