import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
-import java.util.concurrent.TimeUnit;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.MusicDataStoreHandle;
import org.onap.music.main.ReturnType;
import org.onap.music.service.MusicCoreService;
-import com.att.eelf.configuration.EELFLogger;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
public class MusicCassaCore implements MusicCoreService {
- public static CassaLockStore mLockHandle = null;;
+ private static CassaLockStore mLockHandle = null;
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCassaCore.class);
- private static boolean unitTestRun=true;
private static MusicCassaCore musicCassaCoreInstance = null;
private MusicCassaCore() {
+ // not going to happen
+ }
+
+ public static CassaLockStore getmLockHandle() {
+ return mLockHandle;
+ }
+ public static void setmLockHandle(CassaLockStore mLockHandle) {
+ MusicCassaCore.mLockHandle = mLockHandle;
}
+
public static MusicCassaCore getInstance() {
if(musicCassaCoreInstance == null) {
return musicCassaCoreInstance;
}
+
+
+
public static CassaLockStore getLockingServiceHandle() throws MusicLockingException {
logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring lock store handle");
long start = System.currentTimeMillis();
}
public String createLockReference(String fullyQualifiedKey) throws MusicLockingException {
- return createLockReference(fullyQualifiedKey, LockType.WRITE);
+ return createLockReference(fullyQualifiedKey, LockType.WRITE);
}
public String createLockReference(String fullyQualifiedKey, LockType locktype) throws MusicLockingException {
public ReturnType acquireLockWithLease(String fullyQualifiedKey, String lockReference, long leasePeriod)
throws MusicLockingException, MusicQueryException, MusicServiceException {
- evictExpiredLockHolder(fullyQualifiedKey,leasePeriod);
- return acquireLock(fullyQualifiedKey, lockReference);
+ evictExpiredLockHolder(fullyQualifiedKey,leasePeriod);
+ return acquireLock(fullyQualifiedKey, lockReference);
}
private void evictExpiredLockHolder(String fullyQualifiedKey, long leasePeriod)
if (!lockInfo.getIsLockOwner()) {
return new ReturnType(ResultType.FAILURE, lockId + " is not a lock holder");//not top of the lock store q
}
-
+
//check to see if the value of the key has to be synced in case there was a forceful release
String syncTable = keyspace+".unsyncedKeys_"+table;
String query = "select * from "+syncTable+" where key='"+localFullyQualifiedKey+"';";
try {
LockObject lockOwner = getLockingServiceHandle().peekLockQueue(keyspace, table, primaryKeyValue);
if (!lockOwner.getIsLockOwner()) {
- return "No lock holder!";
+ return null;
}
return "$" + fullyQualifiedKey + "$" + lockOwner.getLockRef();
} catch (MusicLockingException | MusicServiceException | MusicQueryException e) {
PreparedQueryObject queryObject, String lockId, Condition conditionInfo) {
long start = System.currentTimeMillis();
try {
+ String keyLock = lockId.substring(lockId.lastIndexOf(".") + 1,lockId.lastIndexOf("$"));
+ if (lockId.contains(".") && !keyLock.equals(primaryKeyValue)) {
+ return new ReturnType(ResultType.FAILURE,"Lock value '" + keyLock + "' and key value '"
+ + primaryKeyValue + "' not match. Please check your values: "
+ + lockId + " .");
+ }
LockObject lockObject = getLockingServiceHandle().getLockInfo(keyspace, table, primaryKeyValue,
lockId.substring(lockId.lastIndexOf("$") + 1));
- if (!lockObject.getIsLockOwner()) {
+ if ( lockObject == null ) {
+ return new ReturnType(ResultType.FAILURE, lockId + " does not exist.");
+ } else if (!lockObject.getIsLockOwner()) {
return new ReturnType(ResultType.FAILURE, lockId + " is not the lock holder");
} else if (lockObject.getLocktype() != LockType.WRITE) {
return new ReturnType(ResultType.FAILURE,
- "Attempting to do write operation, but " + lockId + " is a write lock");
+ "Attempting to do write operation, but " + lockId + " is a read lock");
}
if (conditionInfo != null) {
dsHandle.executePut(queryObject, MusicUtil.CRITICAL);
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the critical put:" + (end - start) + " ms");
- }catch (MusicQueryException | MusicServiceException | MusicLockingException e) {
+ } catch (MusicQueryException | MusicServiceException | MusicLockingException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), e);
return new ReturnType(ResultType.FAILURE,
- "Exception thrown while doing the critical put\n"
+ "Exception thrown while doing the critical put: "
+ e.getMessage());
}
return new ReturnType(ResultType.SUCCESS, "Update performed");
*
*
*/
- public ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency) throws MusicServiceException {
+ public ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency) throws MusicServiceException,MusicQueryException {
// this is mainly for some functions like keyspace creation etc which does not
// really need the bells and whistles of Music locking.
boolean result = false;
- try {
- result = MusicDataStoreHandle.getDSHandle().executePut(queryObject, consistency);
- } catch (MusicQueryException | MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(), AppMessages.UNKNOWNERROR,
- ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR, ex);
- throw new MusicServiceException(ex.getMessage());
- }
+// try {
+ result = MusicDataStoreHandle.getDSHandle().executePut(queryObject, consistency);
+// } catch (MusicQueryException | MusicServiceException ex) {
+ // logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(), AppMessages.UNKNOWNERROR,
+ // ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR, ex);
+// throw new MusicServiceException(ex.getMessage(),ex);
+// }
return result ? ResultType.SUCCESS : ResultType.FAILURE;
}
public ResultSet criticalGet(String keyspace, String table, String primaryKeyValue,
PreparedQueryObject queryObject, String lockId) throws MusicServiceException {
ResultSet results = null;
-
+ String keyLock = lockId.substring(lockId.lastIndexOf(".") + 1,lockId.lastIndexOf("$"));
try {
+ if (lockId.contains(".") && !keyLock.equals(primaryKeyValue)) {
+ throw new MusicLockingException("Lock value '" + keyLock + "' and key value '"
+ + primaryKeyValue + "' do not match. Please check your values: "
+ + lockId + " .");
+ }
LockObject lockObject = getLockingServiceHandle().getLockInfo(keyspace, table, primaryKeyValue,
- lockId.substring(lockId.lastIndexOf("$") + 1));
- if (!lockObject.getIsLockOwner()) {
+ lockId.substring(lockId.lastIndexOf("$") + 1));
+ if (null == lockObject) {
+ throw new MusicLockingException("No Lock Object. Please check if lock name or key is correct."
+ + lockId + " .");
+ }
+ if ( !lockObject.getIsLockOwner()) {
return null;// not top of the lock store q
}
results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(queryObject);
- } catch (MusicQueryException | MusicServiceException | MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity
+ } catch ( MusicLockingException e ) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity
+ .WARN, ErrorTypes.MUSICSERVICEERROR);
+ throw new MusicServiceException(
+ "Cannot perform critical get for key: " + primaryKeyValue + " : " + e.getMessage());
+ } catch (MusicQueryException | MusicServiceException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity
.WARN, ErrorTypes.MUSICSERVICEERROR, e);
+ throw new MusicServiceException(
+ "Cannot perform critical get for key: " + primaryKeyValue + " : " + e.getMessage());
}
return results;
}
return null;
}
+
}