aboutsummaryrefslogtreecommitdiffstats
path: root/music-core/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'music-core/src/main/java')
-rwxr-xr-xmusic-core/src/main/java/org/onap/music/datastore/MusicDataStore.java133
-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.java12
-rw-r--r--music-core/src/main/java/org/onap/music/main/MusicUtil.java125
6 files changed, 206 insertions, 186 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..7f6c42ca 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
@@ -51,6 +51,7 @@ import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
+import com.datastax.driver.core.SocketOptions;
import com.datastax.driver.core.TableMetadata;
import com.datastax.driver.core.exceptions.AlreadyExistsException;
import com.datastax.driver.core.exceptions.InvalidQueryException;
@@ -90,7 +91,7 @@ public class MusicDataStore {
setCluster(cluster);
}
-
+
/**
* @param session
*/
@@ -111,10 +112,10 @@ public class MusicDataStore {
public void setCluster(Cluster cluster) {
EnumNameCodec<LockType> lockTypeCodec = new EnumNameCodec<LockType>(LockType.class);
cluster.getConfiguration().getCodecRegistry().register(lockTypeCodec);
-
+
this.cluster = cluster;
}
-
+
public Cluster getCluster() {
return this.cluster;
}
@@ -122,7 +123,7 @@ public class MusicDataStore {
private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStore.class);
-
+
/**
*
* @param remoteIp
@@ -155,38 +156,44 @@ public class MusicDataStore {
poolingOptions
.setConnectionsPerHost(HostDistance.LOCAL, 4, 10)
.setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
-
+
Cluster cluster;
if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) {
String cassPwd = CipherUtil.decryptPKC(MusicUtil.getCassPwd());
logger.info(EELFLoggerDelegate.applicationLogger,
"Building with credentials "+MusicUtil.getCassName()+" & "+ MusicUtil.getCassPwd());
cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort())
- .withCredentials(MusicUtil.getCassName(), cassPwd)
- //.withLoadBalancingPolicy(new RoundRobinPolicy())
- .withoutJMXReporting()
- .withPoolingOptions(poolingOptions)
- .addContactPoints(addresses).build();
+ .withCredentials(MusicUtil.getCassName(), cassPwd)
+ //.withLoadBalancingPolicy(new RoundRobinPolicy())
+ .withoutJMXReporting()
+ .withPoolingOptions(poolingOptions)
+ .withSocketOptions(
+ new SocketOptions().setConnectTimeoutMillis(MusicUtil.getCassandraConnectTimeOutMS())
+ .setReadTimeoutMillis(MusicUtil.getCassandraReadTimeOutMS()))
+ .addContactPoints(addresses).build();
} else {
cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort())
- .withoutJMXReporting()
- .withPoolingOptions(poolingOptions)
- .addContactPoints(addresses)
- .build();
+ .withoutJMXReporting()
+ .withPoolingOptions(poolingOptions)
+ .withSocketOptions(new SocketOptions()
+ .setConnectTimeoutMillis(MusicUtil.getCassandraConnectTimeOutMS())
+ .setReadTimeoutMillis(MusicUtil.getCassandraReadTimeOutMS()))
+ .addContactPoints(addresses)
+ .build();
}
-
+
this.setCluster(cluster);
Metadata metadata = this.cluster.getMetadata();
logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster "
- + metadata.getClusterName() + " at " + address);
+ + metadata.getClusterName() + " at " + address);
try {
session = this.cluster.connect();
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.CASSANDRACONNECTIVITY,
- ErrorSeverity.ERROR, ErrorTypes.SERVICEUNAVAILABLE, ex);
+ ErrorSeverity.ERROR, ErrorTypes.SERVICEUNAVAILABLE, ex);
throw new MusicServiceException(
- "Error while connecting to Cassandra cluster.. " + ex.getMessage());
+ "Error while connecting to Cassandra cluster.. " + ex.getMessage());
}
}
@@ -214,16 +221,16 @@ public class MusicDataStore {
KeyspaceMetadata ks = cluster.getMetadata().getKeyspace(keyspace);
return ks.getTable(tableName);
}
-
+
/**
- *
- * @param keyspace
- * @param tableName
- * @return TableMetadata
- */
- public KeyspaceMetadata returnKeyspaceMetadata(String keyspace) {
- return cluster.getMetadata().getKeyspace(keyspace);
- }
+ *
+ * @param keyspace
+ * @param tableName
+ * @return TableMetadata
+ */
+ public KeyspaceMetadata returnKeyspaceMetadata(String keyspace) {
+ return cluster.getMetadata().getKeyspace(keyspace);
+ }
/**
@@ -289,7 +296,7 @@ public class MusicDataStore {
*/
public Map<String, HashMap<String, Object>> marshalData(ResultSet results) {
Map<String, HashMap<String, Object>> resultMap =
- new HashMap<>();
+ new HashMap<>();
int counter = 0;
for (Row row : results) {
ColumnDefinitions colInfo = row.getColumnDefinitions();
@@ -301,7 +308,7 @@ public class MusicDataStore {
getBlobValue(row, definition.getName(), definition.getType()));
} else {
resultOutput.put(definition.getName(),
- getColValue(row, definition.getName(), definition.getType()));
+ getColValue(row, definition.getName(), definition.getType()));
}
}
}
@@ -313,7 +320,7 @@ public class MusicDataStore {
// Prepared Statements 1802 additions
-
+
public boolean executePut(PreparedQueryObject queryObject, String consistency)
throws MusicServiceException, MusicQueryException {
return executePut(queryObject, consistency, 0);
@@ -329,19 +336,19 @@ public class MusicDataStore {
* @throws MusicQueryException
*/
public boolean executePut(PreparedQueryObject queryObject, String consistency,long timeSlot)
- throws MusicServiceException, MusicQueryException {
+ throws MusicServiceException, MusicQueryException {
boolean result = false;
long timeOfWrite = System.currentTimeMillis();
if (!MusicUtil.isValidQueryObject(!queryObject.getValues().isEmpty(), queryObject)) {
logger.error(EELFLoggerDelegate.errorLogger, queryObject.getQuery(),AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
throw new MusicQueryException("Ill formed queryObject for the request = " + "["
- + queryObject.getQuery() + "]");
+ + queryObject.getQuery() + "]");
}
logger.debug(EELFLoggerDelegate.applicationLogger,
- "In preprared Execute Put: the actual insert query:"
- + queryObject.getQuery() + "; the values"
- + queryObject.getValues());
+ "In preprared Execute Put: the actual insert query:"
+ + queryObject.getQuery() + "; the values"
+ + queryObject.getValues());
SimpleStatement preparedInsert = null;
try {
@@ -381,12 +388,12 @@ public class MusicDataStore {
// logger.error(EELFLoggerDelegate.errorLogger,e.getClass().toString() + ":" + e.getMessage(),AppMessages.SESSIONFAILED + " ["
// + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, e);
throw new MusicServiceException("Executing Session Failure for Request = " + "["
- + queryObject.getQuery() + "]" + " Reason = " + e.getMessage(),e);
+ + queryObject.getQuery() + "]" + " Reason = " + e.getMessage(),e);
}
return result;
}
- /* *//**
+ /* *//**
* This method performs DDL operations on Cassandra using consistency level ONE.
*
* @param queryObject Object containing cassandra prepared query and values.
@@ -429,15 +436,15 @@ public class MusicDataStore {
return results;
}
- *//**
- *
- * This method performs DDL operation on Cassandra using consistency level QUORUM.
- *
- * @param queryObject Object containing cassandra prepared query and values.
- * @return ResultSet
- * @throws MusicServiceException
- * @throws MusicQueryException
- *//*
+ *//**
+ *
+ * This method performs DDL operation on Cassandra using consistency level QUORUM.
+ *
+ * @param queryObject Object containing cassandra prepared query and values.
+ * @return ResultSet
+ * @throws MusicServiceException
+ * @throws MusicQueryException
+ *//*
public ResultSet executeCriticalGet(PreparedQueryObject queryObject)
throws MusicServiceException, MusicQueryException {
if (!MusicUtil.isValidQueryObject(!queryObject.getValues().isEmpty(), queryObject)) {
@@ -460,50 +467,46 @@ public class MusicDataStore {
return results;
}
- */
+ */
public ResultSet executeGet(PreparedQueryObject queryObject,String consistencyLevel) throws MusicQueryException, MusicServiceException {
if (!MusicUtil.isValidQueryObject(!queryObject.getValues().isEmpty(), queryObject)) {
logger.error(EELFLoggerDelegate.errorLogger, "",AppMessages.QUERYERROR+ " [" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
throw new MusicQueryException("Error processing Prepared Query Object for the request = " + "["
- + queryObject.getQuery() + "]");
+ + queryObject.getQuery() + "]");
}
ResultSet results = null;
try {
SimpleStatement statement = new SimpleStatement(queryObject.getQuery(), queryObject.getValues().toArray());
-
if (consistencyLevel.equalsIgnoreCase(CONSISTENCY_LEVEL_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(CONSISTENCY_LEVEL_QUORUM)) {
statement.setConsistencyLevel(ConsistencyLevel.QUORUM);
+ } else if (consistencyLevel.equalsIgnoreCase(CONSISTENCY_LEVEL_LOCAL_QUORUM)) {
+ statement.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);
}
results = session.execute(statement);
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger, "Execute Get Error" + ex.getMessage(),AppMessages.UNKNOWNERROR+ "[" + queryObject
- .getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, ex);
+ .getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR, ex);
throw new MusicServiceException("Execute Get Error" + ex.getMessage());
}
-
+
return results;
-
+
}
-
+
/**
* This method performs DDL operations on Cassandra using consistency level ONE.
*
* @param queryObject Object containing cassandra prepared query and values.
*/
public ResultSet executeOneConsistencyGet(PreparedQueryObject queryObject)
- throws MusicServiceException, MusicQueryException {
+ throws MusicServiceException, MusicQueryException {
return executeGet(queryObject, CONSISTENCY_LEVEL_ONE);
}
-
+
/**
*
* This method performs DDL operation on Cassandra using consistency level LOCAL_QUORUM.
@@ -511,10 +514,10 @@ public class MusicDataStore {
* @param queryObject Object containing cassandra prepared query and values.
*/
public ResultSet executeLocalQuorumConsistencyGet(PreparedQueryObject queryObject)
- throws MusicServiceException, MusicQueryException {
+ throws MusicServiceException, MusicQueryException {
return executeGet(queryObject, CONSISTENCY_LEVEL_LOCAL_QUORUM);
}
-
+
/**
*
* This method performs DDL operation on Cassandra using consistency level QUORUM.
@@ -522,8 +525,8 @@ public class MusicDataStore {
* @param queryObject Object containing cassandra prepared query and values.
*/
public ResultSet executeQuorumConsistencyGet(PreparedQueryObject queryObject)
- throws MusicServiceException, MusicQueryException {
+ throws MusicServiceException, MusicQueryException {
return executeGet(queryObject, CONSISTENCY_LEVEL_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..e9533344 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();
@@ -478,7 +478,7 @@ public class CassaLockStore {
queryObject.appendQueryString(" WHERE lockType = ? ALLOW FILTERING");
queryObject.addValue(LockType.WRITE);
- DeadlockDetectionUtil ddu = new DeadlockDetectionUtil();
+ DeadlockDetectionUtil ddu = getDeadlockDetectionUtil();
ResultSet rs = dsHandle.executeLocalQuorumConsistencyGet(queryObject);
logger.debug("rs has " + rs.getAvailableWithoutFetching() + (rs.isFullyFetched()?"":" (or more!)") );
@@ -493,6 +493,14 @@ public class CassaLockStore {
return deadlock;
}
+ /**
+ * This is used for testing purpose
+ * @return new DeadlockDetectionUtil object
+ */
+ DeadlockDetectionUtil getDeadlockDetectionUtil() {
+ return new DeadlockDetectionUtil();
+ }
+
public List<String> getAllLocksForOwner(String ownerId, String keyspace, String table) throws MusicServiceException, MusicQueryException {
List<String> toRet = new ArrayList<String>();
String lockTable = table_prepend_name + table;
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..78d17c60 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";
@@ -117,8 +118,8 @@ public class MusicUtil {
// "clientId.header.prefix","messageId.header.prefix"};
// Consistency Constants and variables.
private static final String[] cosistencyLevel = new String[] {
- "ALL","EACH_QUORUM","QUORUM","LOCAL_QUORUM","ONE","TWO",
- "THREE","LOCAL_ONE","ANY","SERIAL","LOCAL_SERIAL"};
+ "ALL","EACH_QUORUM","QUORUM","LOCAL_QUORUM","ONE","TWO",
+ "THREE","LOCAL_ONE","ANY","SERIAL","LOCAL_SERIAL"};
private static final Map<String,ConsistencyLevel> consistencyName = new HashMap<>();
static {
consistencyName.put("ONE",ConsistencyLevel.ONE);
@@ -138,6 +139,8 @@ public class MusicUtil {
private static String cassPwd;
private static String myCassaHost = LOCALHOST;
private static int cassandraPort = 9042;
+ private static int cassandraConnectTimeOutMS;
+ private static int cassandraReadTimeOutMS;
// AAF
private static String musicAafNs = "org.onap.music.cadi";
@@ -149,11 +152,11 @@ public class MusicUtil {
// Response/Request tracking headers
private static String transIdPrefix = "false";
- private static String conversationIdPrefix = "false";
+ private static String conversationIdPrefix = "false";
private static String clientIdPrefix = "false";
private static String messageIdPrefix = "false";
- private static Boolean transIdRequired = false;
- private static Boolean conversationIdRequired = false;
+ private static Boolean transIdRequired = false;
+ private static Boolean conversationIdRequired = false;
private static Boolean clientIdRequired = false;
private static Boolean messageIdRequired = false;
private static String cipherEncKey = "";
@@ -161,7 +164,7 @@ public class MusicUtil {
public MusicUtil() {
throw new IllegalStateException("Utility Class");
}
-
+
public static String getLockUsing() {
return lockUsing;
}
@@ -199,15 +202,31 @@ public class MusicUtil {
return cassPwd;
}
+ public static int getCassandraConnectTimeOutMS() {
+ return cassandraConnectTimeOutMS;
+ }
+
+ public static void setCassandraConnectTimeOutMS(int cassandraConnectTimeOutMS) {
+ MusicUtil.cassandraConnectTimeOutMS = cassandraConnectTimeOutMS;
+ }
+
+ public static int getCassandraReadTimeOutMS() {
+ return cassandraReadTimeOutMS;
+ }
+
+ public static void setCassandraReadTimeOutMS(int cassandraReadTimeOutMS) {
+ MusicUtil.cassandraReadTimeOutMS = cassandraReadTimeOutMS;
+ }
+
/**
* Returns An array of property names that should be in the Properties
* files.
*
// * @return
// */
-// public static String[] getPropkeys() {
-// return propKeys.clone();
-// }
+ // public static String[] getPropkeys() {
+ // return propKeys.clone();
+ // }
/**
* Get MusicPropertiesFilePath - Default = /opt/music/music.properties
@@ -318,7 +337,7 @@ public class MusicUtil {
public static void setMyCassaHost(String myCassaHost) {
MusicUtil.myCassaHost = myCassaHost;
}
-
+
/**
* Gey default retry count
* @return
@@ -424,23 +443,23 @@ public class MusicUtil {
String value = "";
switch (type.getName()) {
- case UUID:
- value = valueObj + "";
- break;
- case TEXT:
- case VARCHAR:
- String valueString = valueObj + "";
- valueString = valueString.replace("'", "''");
- value = "'" + valueString + "'";
- break;
- case MAP: {
- Map<String, Object> otMap = (Map<String, Object>) valueObj;
- value = "{" + jsonMaptoSqlString(otMap, ",") + "}";
- break;
- }
- default:
- value = valueObj + "";
- break;
+ case UUID:
+ value = valueObj + "";
+ break;
+ case TEXT:
+ case VARCHAR:
+ String valueString = valueObj + "";
+ valueString = valueString.replace("'", "''");
+ value = "'" + valueString + "'";
+ break;
+ case MAP: {
+ Map<String, Object> otMap = (Map<String, Object>) valueObj;
+ value = "{" + jsonMaptoSqlString(otMap, ",") + "}";
+ break;
+ }
+ default:
+ value = valueObj + "";
+ break;
}
return value;
}
@@ -584,14 +603,14 @@ public class MusicUtil {
return ts;
}
-
+
public static MusicCoreService getMusicCoreService() {
if(getLockUsing().equals(MusicUtil.CASSANDRA))
return MusicCassaCore.getInstance();
else
return MusicCassaCore.getInstance();
}
-
+
/**
* @param lockName
* @return
@@ -616,9 +635,9 @@ public class MusicUtil {
}
public static void writeBackToQuorum(PreparedQueryObject selectQuery, String primaryKeyName,
- PreparedQueryObject updateQuery, String keyspace, String table,
- Object cqlFormattedPrimaryKeyValue)
- throws Exception {
+ PreparedQueryObject updateQuery, String keyspace, String table,
+ Object cqlFormattedPrimaryKeyValue)
+ throws Exception {
try {
ResultSet results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(selectQuery);
// write it back to a quorum
@@ -641,16 +660,16 @@ public class MusicUtil {
counter = counter + 1;
}
updateQuery.appendQueryString("UPDATE " + keyspace + "." + table + " SET "
- + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
+ + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
updateQuery.addValue(cqlFormattedPrimaryKeyValue);
MusicDataStoreHandle.getDSHandle().executePut(updateQuery, "critical");
} catch (MusicServiceException | MusicQueryException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery ,
- ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR, e);
+ ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR, e);
}
}
-
+
public static boolean getIsCadi() {
return MusicUtil.isCadi;
}
@@ -729,64 +748,64 @@ public class MusicUtil {
MusicUtil.messageIdPrefix = checkPrefix(messageIdPrefix);
}
- /**
- * @return the transIdRequired
- */
+ /**
+ * @return the transIdRequired
+ */
public static Boolean getTransIdRequired() {
return transIdRequired;
}
/**
- * @param transIdRequired the transIdRequired to set
- */
+ * @param transIdRequired the transIdRequired to set
+ */
public static void setTransIdRequired(Boolean transIdRequired) {
MusicUtil.transIdRequired = transIdRequired;
}
/**
- * @return the conversationIdRequired
- */
+ * @return the conversationIdRequired
+ */
public static Boolean getConversationIdRequired() {
return conversationIdRequired;
}
/**
- * @param conversationIdRequired the conversationIdRequired to set
- */
+ * @param conversationIdRequired the conversationIdRequired to set
+ */
public static void setConversationIdRequired(Boolean conversationIdRequired) {
MusicUtil.conversationIdRequired = conversationIdRequired;
}
/**
- * @return the clientIdRequired
- */
+ * @return the clientIdRequired
+ */
public static Boolean getClientIdRequired() {
return clientIdRequired;
}
/**
- * @param clientIdRequired the clientIdRequired to set
- */
+ * @param clientIdRequired the clientIdRequired to set
+ */
public static void setClientIdRequired(Boolean clientIdRequired) {
MusicUtil.clientIdRequired = clientIdRequired;
}
/**
- * @return the messageIdRequired
- */
+ * @return the messageIdRequired
+ */
public static Boolean getMessageIdRequired() {
return messageIdRequired;
}
/**
- * @param messageIdRequired the messageIdRequired to set
- */
+ * @param messageIdRequired the messageIdRequired to set
+ */
public static void setMessageIdRequired(Boolean messageIdRequired) {
MusicUtil.messageIdRequired = messageIdRequired;
}
@@ -800,7 +819,7 @@ public class MusicUtil {
public static void setCipherEncKey(String cipherEncKey) {
MusicUtil.cipherEncKey = cipherEncKey;
if ( null == cipherEncKey || cipherEncKey.equals("") ||
- cipherEncKey.equals("nothing to see here")) {
+ cipherEncKey.equals("nothing to see here")) {
logger.error(EELFLoggerDelegate.errorLogger, "Missing Cipher Encryption Key.");
}
}