aboutsummaryrefslogtreecommitdiffstats
path: root/music-core/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'music-core/src/main')
-rwxr-xr-xmusic-core/src/main/java/org/onap/music/datastore/MusicDataStore.java17
-rw-r--r--music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java5
-rw-r--r--music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java29
-rw-r--r--music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java88
-rw-r--r--music-core/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java2
-rw-r--r--music-core/src/main/java/org/onap/music/main/MusicUtil.java1
6 files changed, 65 insertions, 77 deletions
diff --git a/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java b/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java
index 9ccff828..2e17670f 100755
--- a/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java
+++ b/music-core/src/main/java/org/onap/music/datastore/MusicDataStore.java
@@ -61,10 +61,6 @@ import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
*
*/
public class MusicDataStore {
-
- public static final String CONSISTENCY_LEVEL_ONE = "ONE";
- public static final String CONSISTENCY_LEVEL_QUORUM = "QUORUM";
- public static final String CONSISTENCY_LEVEL_LOCAL_QUORUM = "LOCAL_QUORUM";
private Session session;
private Cluster cluster;
@@ -471,15 +467,16 @@ public class MusicDataStore {
try {
SimpleStatement statement = new SimpleStatement(queryObject.getQuery(), queryObject.getValues().toArray());
- if (consistencyLevel.equalsIgnoreCase(CONSISTENCY_LEVEL_ONE)) {
+ if (consistencyLevel.equalsIgnoreCase(MusicUtil.ONE)) {
if(queryObject.getConsistency() == null) {
statement.setConsistencyLevel(ConsistencyLevel.ONE);
} else {
statement.setConsistencyLevel(MusicUtil.getConsistencyLevel(queryObject.getConsistency()));
}
- }
- else if (consistencyLevel.equalsIgnoreCase(CONSISTENCY_LEVEL_QUORUM)) {
+ } else if (consistencyLevel.equalsIgnoreCase(MusicUtil.QUORUM)) {
statement.setConsistencyLevel(ConsistencyLevel.QUORUM);
+ } else if (consistencyLevel.equalsIgnoreCase(MusicUtil.LOCAL_QUORUM)) {
+ statement.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);
}
results = session.execute(statement);
@@ -501,7 +498,7 @@ public class MusicDataStore {
*/
public ResultSet executeOneConsistencyGet(PreparedQueryObject queryObject)
throws MusicServiceException, MusicQueryException {
- return executeGet(queryObject, CONSISTENCY_LEVEL_ONE);
+ return executeGet(queryObject, MusicUtil.ONE);
}
/**
@@ -512,7 +509,7 @@ public class MusicDataStore {
*/
public ResultSet executeLocalQuorumConsistencyGet(PreparedQueryObject queryObject)
throws MusicServiceException, MusicQueryException {
- return executeGet(queryObject, CONSISTENCY_LEVEL_LOCAL_QUORUM);
+ return executeGet(queryObject, MusicUtil.LOCAL_QUORUM);
}
/**
@@ -523,7 +520,7 @@ public class MusicDataStore {
*/
public ResultSet executeQuorumConsistencyGet(PreparedQueryObject queryObject)
throws MusicServiceException, MusicQueryException {
- return executeGet(queryObject, CONSISTENCY_LEVEL_QUORUM);
+ return executeGet(queryObject, MusicUtil.QUORUM);
}
}
diff --git a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java
index 57ff245a..2f685cfe 100644
--- a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java
+++ b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java
@@ -173,11 +173,6 @@ public class JsonInsert implements Serializable {
* @throws MusicQueryException
*/
public PreparedQueryObject genInsertPreparedQueryObj() throws MusicQueryException {
- if (logger.isDebugEnabled()) {
- logger.debug("Coming inside genTableInsertQuery method " + this.getKeyspaceName());
- logger.debug("Coming inside genTableInsertQuery method " + this.getTableName());
- }
-
PreparedQueryObject queryObject = new PreparedQueryObject();
TableMetadata tableInfo = null;
try {
diff --git a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java
index ef560144..0a277e08 100644
--- a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java
+++ b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java
@@ -144,11 +144,6 @@ public class JsonTable {
}
public PreparedQueryObject genCreateTableQuery() throws MusicQueryException {
- if (logger.isDebugEnabled()) {
- logger.debug("Coming inside genCreateTableQuery method " + this.getKeyspaceName());
- logger.debug("Coming inside genCreateTableQuery method " + this.getTableName());
- }
-
String primaryKey = null;
String partitionKey = this.getPartitionKey();
String clusterKey = this.getClusteringKey();
@@ -341,35 +336,11 @@ public class JsonTable {
}
/**
- *
- * @return
- */
- public PreparedQueryObject genCreateShadowLockingTableQuery() {
- if (logger.isDebugEnabled()) {
- logger.debug("Coming inside genCreateShadowLockingTableQuery method " + this.getKeyspaceName());
- logger.debug("Coming inside genCreateShadowLockingTableQuery method " + this.getTableName());
- }
-
- String tableName = "unsyncedKeys_" + this.getTableName();
- String tabQuery = "CREATE TABLE IF NOT EXISTS " + this.getKeyspaceName() + "." + tableName
- + " ( key text,PRIMARY KEY (key) );";
- PreparedQueryObject queryObject = new PreparedQueryObject();
- queryObject.appendQueryString(tabQuery);
-
- return queryObject;
- }
-
- /**
* genDropTableQuery
*
* @return PreparedQueryObject
*/
public PreparedQueryObject genDropTableQuery() {
- if (logger.isDebugEnabled()) {
- logger.debug("Coming inside genDropTableQuery method " + this.getKeyspaceName());
- logger.debug("Coming inside genDropTableQuery method " + this.getTableName());
- }
-
PreparedQueryObject query = new PreparedQueryObject();
query.appendQueryString("DROP TABLE " + this.getKeyspaceName() + "." + this.getTableName() + ";");
logger.info("Delete Query ::::: " + query.getQuery());
diff --git a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java
index 12508de0..cd767a44 100644
--- a/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java
+++ b/music-core/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java
@@ -65,7 +65,7 @@ public class JsonUpdate implements Serializable {
private Map<String, String> consistencyInfo;
private transient Map<String, Object> conditions;
private transient Map<String, Object> rowSpecification;
- private StringBuilder rowIdString;
+ private String rowIdString;
private String primarKeyValue;
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(JsonUpdate.class);
@@ -142,11 +142,11 @@ public class JsonUpdate implements Serializable {
this.values = values;
}
- public StringBuilder getRowIdString() {
+ public String getRowIdString() {
return rowIdString;
}
- public void setRowIdString(StringBuilder rowIdString) {
+ public void setRowIdString(String rowIdString) {
this.rowIdString = rowIdString;
}
@@ -176,11 +176,6 @@ public class JsonUpdate implements Serializable {
* @throws MusicQueryException
*/
public PreparedQueryObject genUpdatePreparedQueryObj(MultivaluedMap<String, String> rowParams) throws MusicQueryException {
- if (logger.isDebugEnabled()) {
- logger.debug("Coming inside genUpdatePreparedQueryObj method " + this.getKeyspaceName());
- logger.debug("Coming inside genUpdatePreparedQueryObj method " + this.getTableName());
- }
-
PreparedQueryObject queryObject = new PreparedQueryObject();
if((this.getKeyspaceName() == null || this.getKeyspaceName().isEmpty()) ||
@@ -205,20 +200,7 @@ public class JsonUpdate implements Serializable {
Map<String, Object> valuesMap = this.getValues();
- TableMetadata tableInfo;
-
- try {
- tableInfo = MusicDataStoreHandle.returnColumnMetadata(this.getKeyspaceName(), this.getTableName());
- } catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes
- .GENERALSERVICEERROR, e);
- /*return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();*/
- throw new MusicQueryException(e.getMessage(), Status.BAD_REQUEST.getStatusCode());
- }catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e, AppMessages.UNKNOWNERROR, ErrorSeverity.CRITICAL,
- ErrorTypes.GENERALSERVICEERROR);
- throw new MusicQueryException(e.getMessage(), Status.BAD_REQUEST.getStatusCode());
- }
+ TableMetadata tableInfo = getColumnMetadata(this.getKeyspaceName(), this.getTableName());
if (tableInfo == null) {
logger.error(EELFLoggerDelegate.errorLogger,"Table information not found. Please check input for table name= "+this.getTableName(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
@@ -289,7 +271,7 @@ public class JsonUpdate implements Serializable {
rowId = getRowIdentifier(this.getKeyspaceName(), this.getTableName(), rowParams, queryObject);
this.setRowIdString(rowId.rowIdString);
this.setPrimarKeyValue(rowId.primarKeyValue);
- if(rowId == null || rowId.primarKeyValue.isEmpty()) {
+ if(rowId == null || rowId.getPrimaryKeyValue().isEmpty()) {
/*return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
.setError("Mandatory WHERE clause is missing. Please check the input request.").toMap()).build();*/
@@ -312,7 +294,7 @@ public class JsonUpdate implements Serializable {
queryObject.appendQueryString(
- " SET " + fieldValueString + " WHERE " + rowId.rowIdString + ";");
+ " SET " + fieldValueString + " WHERE " + rowId.getRowIdString() + ";");
@@ -324,7 +306,7 @@ public class JsonUpdate implements Serializable {
// to avoid parsing repeatedly, just send the select query to obtain row
PreparedQueryObject selectQuery = new PreparedQueryObject();
selectQuery.appendQueryString("SELECT * FROM " + this.getKeyspaceName() + "." + this.getTableName() + " WHERE "
- + rowId.rowIdString + ";");
+ + rowId.getRowIdString() + ";");
selectQuery.addValue(rowId.primarKeyValue);
conditionInfo = new Condition(this.getConditions(), selectQuery);
}
@@ -348,20 +330,62 @@ public class JsonUpdate implements Serializable {
return queryObject;
}
+
+ TableMetadata getColumnMetadata(String keyspaceName, String tableName) throws MusicQueryException {
+ TableMetadata tableInfo;
+ try {
+ tableInfo = returnColumnMetadata(keyspaceName, tableName);
+ } catch (MusicServiceException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes
+ .GENERALSERVICEERROR, e);
+ /*return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();*/
+ throw new MusicQueryException(e.getMessage(), Status.BAD_REQUEST.getStatusCode());
+ }catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e, AppMessages.UNKNOWNERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.GENERALSERVICEERROR);
+ throw new MusicQueryException(e.getMessage(), Status.BAD_REQUEST.getStatusCode());
+ }
+ return tableInfo;
+ }
+
+ /** wrapper around static method for testing */
+ TableMetadata returnColumnMetadata(String keyspace, String tableName) throws MusicServiceException {
+ return MusicDataStoreHandle.returnColumnMetadata(keyspace, tableName);
+ }
- private class RowIdentifier {
- public String primarKeyValue;
- public StringBuilder rowIdString;
+ class RowIdentifier {
+ private String primarKeyValue;
+ private String rowIdString;
@SuppressWarnings("unused")
public PreparedQueryObject queryObject; // the string with all the row
// identifiers separated by AND
- public RowIdentifier(String primaryKeyValue, StringBuilder rowIdString,
+ public RowIdentifier(String primaryKeyValue, String rowIdString,
PreparedQueryObject queryObject) {
this.primarKeyValue = primaryKeyValue;
this.rowIdString = rowIdString;
this.queryObject = queryObject;
}
+
+ public String getPrimaryKeyValue() {
+ return this.primarKeyValue;
+ }
+
+ public void setPrimaryKeyValue(String primaryKeyValue) {
+ this.primarKeyValue = primaryKeyValue;
+ }
+
+ public String getRowIdString() {
+ return this.rowIdString.toString();
+ }
+
+ public void setRowIdString(String rowIdString) {
+ this.rowIdString = rowIdString;
+ }
+
+ public PreparedQueryObject getQueryObject() {
+ return this.queryObject;
+ }
}
/**
@@ -373,12 +397,12 @@ public class JsonUpdate implements Serializable {
* @return
* @throws MusicServiceException
*/
- private RowIdentifier getRowIdentifier(String keyspace, String tablename,
+ RowIdentifier getRowIdentifier(String keyspace, String tablename,
MultivaluedMap<String, String> rowParams, PreparedQueryObject queryObject)
throws MusicServiceException {
StringBuilder rowSpec = new StringBuilder();
int counter = 0;
- TableMetadata tableInfo = MusicDataStoreHandle.returnColumnMetadata(keyspace, tablename);
+ TableMetadata tableInfo = returnColumnMetadata(keyspace, tablename);
if (tableInfo == null) {
logger.error(EELFLoggerDelegate.errorLogger,
"Table information not found. Please check input for table name= "
@@ -410,7 +434,7 @@ public class JsonUpdate implements Serializable {
}
counter = counter + 1;
}
- return new RowIdentifier(primaryKey.toString(), rowSpec, queryObject);
+ return new RowIdentifier(primaryKey.toString(), rowSpec.toString(), queryObject);
}
}
diff --git a/music-core/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java b/music-core/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java
index edce3fff..cb6816e0 100644
--- a/music-core/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java
+++ b/music-core/src/main/java/org/onap/music/lockingservice/cassandra/CassaLockStore.java
@@ -129,7 +129,7 @@ public class CassaLockStore {
table = table_prepend_name+table;
String tabQuery = "CREATE TABLE IF NOT EXISTS "+keyspace+"."+table
+ " ( key text, lockReference bigint, createTime text, acquireTime text, guard bigint static, "
- + "lockType text, owner text, PRIMARY KEY ((key), lockReference) ) "
+ + "lockType text, leasePeriodTime bigint, owner text, PRIMARY KEY ((key), lockReference) ) "
+ "WITH CLUSTERING ORDER BY (lockReference ASC);";
PreparedQueryObject queryObject = new PreparedQueryObject();
diff --git a/music-core/src/main/java/org/onap/music/main/MusicUtil.java b/music-core/src/main/java/org/onap/music/main/MusicUtil.java
index d46e770e..db51322d 100644
--- a/music-core/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/music-core/src/main/java/org/onap/music/main/MusicUtil.java
@@ -73,6 +73,7 @@ public class MusicUtil {
public static final String EVENTUAL_NB = "eventual_nb";
public static final String ALL = "all";
public static final String QUORUM = "quorum";
+ public static final String LOCAL_QUORUM = "local_quorum";
public static final String ONE = "one";
public static final String ATOMICDELETELOCK = "atomic_delete_lock";