From b8e2faf476202b6ffe61bc3a9a37df1304881d40 Mon Sep 17 00:00:00 2001 From: Avi Ziv Date: Tue, 18 Jul 2017 19:45:38 +0300 Subject: [SDC] Onboarding 1710 rebase. Change-Id: If3b6b81d221fde13908f1e8160db6f7d9433c535 Signed-off-by: Avi Ziv --- .../openecomp-nosqldb-api/pom.xml.versionsBackup | 45 +++++++ .../org/openecomp/core/nosqldb/api/NoSqlDb.java | 2 + .../openecomp-nosqldb-core/pom.xml | 7 +- .../openecomp-nosqldb-core/pom.xml.versionsBackup | 46 +++++++ .../impl/cassandra/CassandraNoSqlDbImpl.java | 133 +++++++++++---------- .../impl/cassandra/CassandraSessionFactory.java | 6 +- .../core/nosqldb/util/ConfigurationManager.java | 2 +- .../core/utilities/Yaml/YamlUtilTest.java | 2 +- .../openecomp-nosqldb-lib/pom.xml.versionsBackup | 35 ++++++ 9 files changed, 212 insertions(+), 66 deletions(-) create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/pom.xml.versionsBackup create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/pom.xml.versionsBackup create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/pom.xml.versionsBackup (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib') diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/pom.xml.versionsBackup new file mode 100644 index 0000000000..288274d728 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/pom.xml.versionsBackup @@ -0,0 +1,45 @@ + + 4.0.0 + + openecomp-nosqldb-api + openecomp-nosqldb-api + org.openecomp.core + + + openecomp-sdc-lib + org.openecomp.sdc + 1.0-SNAPSHOT + ../../.. + + + + + org.openecomp.core + openecomp-facade-api + 1.0-SNAPSHOT + + + com.datastax.cassandra + cassandra-driver-core + ${datasatx.version} + + + com.datastax.cassandra + cassandra-driver-mapping + ${datasatx.version} + + + org.openecomp.core + openecomp-facade-core + ${project.version} + + + org.openecomp.sdc + openecomp-sdc-logging-core + 1.0-SNAPSHOT + + + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java index 6b13ee71e4..56d15a88d4 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java @@ -34,4 +34,6 @@ public interface NoSqlDb { ResultSet execute(String statementName, Object... values); MappingManager getMappingManager(); + + String getVersion(); } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/pom.xml index 8270e1bf79..fdbb1ec2a4 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/pom.xml +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/pom.xml @@ -27,6 +27,11 @@ + + org.openecomp.sdc.common + openecomp-tosca-datatype + ${openecomp.sdc.common.version} + org.openecomp.sdc.core openecomp-nosqldb-api @@ -54,7 +59,7 @@ junit junit test - 4.11 + ${junit.version} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/pom.xml.versionsBackup new file mode 100644 index 0000000000..fa859a0db8 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/pom.xml.versionsBackup @@ -0,0 +1,46 @@ + + 4.0.0 + + openecomp-nosqldb-core + openecomp-nosqldb-core + org.openecomp.core + + openecomp-sdc-lib + org.openecomp.sdc + 1.0-SNAPSHOT + ../../.. + + + + + org.openecomp.core + openecomp-nosqldb-api + ${project.version} + + + org.mockito + mockito-all + test + 1.10.19 + + + org.testng + testng + test + 6.8.5 + + + snakeyaml + org.yaml + + + + + junit + junit + test + 4.11 + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbImpl.java index bcac5f8d79..4ecc26879a 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbImpl.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbImpl.java @@ -20,10 +20,7 @@ package org.openecomp.core.nosqldb.impl.cassandra; -import com.datastax.driver.core.BoundStatement; -import com.datastax.driver.core.PreparedStatement; -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.Session; +import com.datastax.driver.core.*; import com.datastax.driver.mapping.MappingManager; import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.util.CassandraUtils; @@ -32,73 +29,87 @@ import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; -class CassandraNoSqlDbImpl implements NoSqlDb { +import java.util.Set; +import java.util.stream.Collectors; - private final Session session; - private final String keySpace; - private final MappingManager mappingManager; +class CassandraNoSqlDbImpl implements NoSqlDb { + private final Session session; + private final String keySpace; + private final MappingManager mappingManager; - public CassandraNoSqlDbImpl(Session session) { - this.session = session; - this.keySpace = this.session.getLoggedKeyspace(); - this.mappingManager = new MappingManager(this.session); - } + public CassandraNoSqlDbImpl(Session session) { + this.session = session; + this.keySpace = this.session.getLoggedKeyspace(); + this.mappingManager = new MappingManager(this.session); - @Override - public void insert(String tableName, String[] colNames, Object[] values) { - if (colNames.length != values.length) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage( - "number of colmuns[" + colNames.length + "] is not equal to the number of values[" - + values.length + "].").withId("E0005").withCategory(ErrorCategory.APPLICATION) - .build()); } - StringBuilder sb = new StringBuilder(); - sb.append("insert into ") - .append(tableName) - .append(" (") - .append(CommonMethods.arrayToCommaSeparatedString(colNames)) - .append(") values (") - .append(CommonMethods.duplicateStringWithDelimiter("?", ',', values.length)) - .append(")"); - System.out.println(sb.toString()); - PreparedStatement prepared = session.prepare(sb.toString()); - - BoundStatement bound; - bound = prepared.bind(values); - session.execute(bound); - - } - - @Override - public ResultSet execute(String statement) { - return session.execute(statement); - } - - @Override - public ResultSet execute(String statementName, Object... values) { - - String statement = CassandraUtils.getStatement(statementName); - if (statement == null) { - statement = statementName; + @Override + public void insert(String tableName, String[] colNames, Object[] values) { + if (colNames.length != values.length) { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage( + "number of colmuns[" + colNames.length + "] is not equal to the number of values[" + + values.length + "].").withId("E0005").withCategory(ErrorCategory.APPLICATION) + .build()); + } + + StringBuilder sb = new StringBuilder(); + sb.append("insert into ") + .append(tableName) + .append(" (") + .append(CommonMethods.arrayToCommaSeparatedString(colNames)) + .append(") values (") + .append(CommonMethods.duplicateStringWithDelimiter("?", ',', values.length)) + .append(")"); + System.out.println(sb.toString()); + PreparedStatement prepared = session.prepare(sb.toString()); + + BoundStatement bound; + bound = prepared.bind(values); + session.execute(bound); + } - if (values != null) { - PreparedStatement prepared = session.prepare(statement); - - BoundStatement bound; - bound = prepared.bind(values); - return session.execute(bound); - } else { - return session.execute(statement); + + @Override + public ResultSet execute(String statement) { + return session.execute(statement); } - } + @Override + public ResultSet execute(String statementName, Object... values) { + + String statement = CassandraUtils.getStatement(statementName); + if (statement == null) { + statement = statementName; + } + if (values != null) { + PreparedStatement prepared = session.prepare(statement); - @Override - public MappingManager getMappingManager() { - return mappingManager; - } + BoundStatement bound; + bound = prepared.bind(values); + return session.execute(bound); + } else { + return session.execute(statement); + } + } + + @Override + public MappingManager getMappingManager() { + return mappingManager; + } + + @Override + public String getVersion() { + try { + Set allHosts = this.session.getCluster().getMetadata().getAllHosts(); + Set versions = allHosts.stream().map(host -> host.getCassandraVersion().toString()) + .collect(Collectors.toSet()); + return versions.stream().collect(Collectors.joining(",")); + } catch (Exception e){ + return "Failed to retrieve version"; + } + } } 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 4863e3df0f..7b9b2ca84f 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 @@ -36,6 +36,7 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; +import java.util.Objects; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; @@ -113,8 +114,9 @@ public class CassandraSessionFactory { } catch (Exception exception) { exception.printStackTrace(); } finally { - tsf.close(); - + if (tsf != null) { + tsf.close(); + } } return ctx; } 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 44623ff91b..c00db41ed9 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 @@ -20,7 +20,7 @@ package org.openecomp.core.nosqldb.util; -import org.openecomp.core.utilities.yaml.YamlUtil; +import org.openecomp.sdc.tosca.services.YamlUtil; import java.io.FileInputStream; import java.io.FileNotFoundException; diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/utilities/Yaml/YamlUtilTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/utilities/Yaml/YamlUtilTest.java index 1e3305ef18..578f3e4c4a 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/utilities/Yaml/YamlUtilTest.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/test/java/org/openecomp/core/utilities/Yaml/YamlUtilTest.java @@ -22,7 +22,7 @@ package org.openecomp.core.utilities.Yaml; import org.junit.Before; import org.junit.Test; -import org.openecomp.core.utilities.yaml.YamlUtil; +import org.openecomp.sdc.tosca.services.YamlUtil; import testobjects.yaml.YamlFile; diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/pom.xml.versionsBackup new file mode 100644 index 0000000000..3a4bfd4ba0 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/pom.xml.versionsBackup @@ -0,0 +1,35 @@ + + 4.0.0 + + openecomp-nosqldb-lib + openecomp-nosqldb-lib + org.openecomp.core + pom + + openecomp-sdc-lib + org.openecomp.sdc + 1.0-SNAPSHOT + ../.. + + + + openecomp-nosqldb-api + openecomp-nosqldb-core + + + + + org.openecomp.core + openecomp-nosqldb-api + ${project.version} + compile + + + org.openecomp.core + openecomp-nosqldb-core + ${project.version} + runtime + + + \ No newline at end of file -- cgit 1.2.3-korg