package org.onap.music.main;
-import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
public boolean testCondition() throws Exception {
// first generate the row
ResultSet results = quorumGet(selectQueryForTheRow);
- Row row = results.one();
+ Row row = null;
+ if(results != null) {
+ row = results.one();
+ }
return getDSHandle().doesRowSatisfyCondition(row, conditions);
}
}
long start = System.currentTimeMillis();
if (mDstoreHandle == null) {
// Quick Fix - Best to put this into every call to getDSHandle?
- if (! MusicUtil.getMyCassaHost().equals("localhost") ) {
+ if (! "localhost".equals(MusicUtil.getMyCassaHost())) {
mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
} else {
mDstoreHandle = new MusicDataStore();
MusicLockState newMls = null;
try {
currentMls = getMusicLockState(key);
- String currentLockHolder = currentMls.getLockHolder();
+ String currentLockHolder = null;
+ if(currentMls != null) { currentLockHolder = currentMls.getLockHolder(); };
if (lockId.equals(currentLockHolder)) {
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: You already have the lock!");
return new ReturnType(ResultType.SUCCESS, "You already have the lock!");
}
- if (currentMls.getLockStatus() != MusicLockState.LockStatus.UNLOCKED || currentMls.getLockHolder() != null) {
- logger.info("In acquire lock: the previous lock has not been released yet! current mls:"+currentMls.toString());
- return new ReturnType(ResultType.FAILURE, "The previous lock has not been released yet.");
- }
} catch (NullPointerException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK+lockId,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
public static void voluntaryReleaseLock(String lockId) throws MusicLockingException{
try {
getLockingServiceHandle().unlockAndDeleteId(lockId);
- String lockName = getLockNameFromId(lockId);
- String lockHolder = null;
- MusicLockState mls = new MusicLockState(MusicLockState.LockStatus.UNLOCKED, lockHolder);
- try {
- getLockingServiceHandle().setLockState(lockName, mls);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.RELEASELOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
} catch (KeeperException.NoNodeException e) {
// ??? No way
}
try {
MusicLockState mls = getLockingServiceHandle()
.getLockState(keyspaceName + "." + tableName + "." + primaryKey);
- logger.info("Got MusicLockState object... :"+mls.toString());
if (mls.getLockHolder().equals(lockId) == true) {
if (conditionInfo != null)
try {
"Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
+ e.getMessage());
}catch(MusicLockingException ex){
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage());
return new ReturnType(ResultType.FAILURE,ex.getMessage());
}
}
return results;
}
+
+ public static String getMyHostId() {
+ PreparedQueryObject pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString("SELECT HOST_ID FROM SYSTEM.LOCAL");
+ ResultSet rs = null;
+ try {
+ rs = getDSHandle().executeEventualGet(pQuery);
+ Row row = rs.one();
+ return (row == null) ? "UNKNOWN" : row.getUUID("HOST_ID").toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ }
+ logger.error(EELFLoggerDelegate.errorLogger, "Some issue during MusicCore.getMyHostId");
+ return "UNKNOW";
+ }
/**
* This method performs DDL operations on cassandra, if the the resource is available. Lock ID
ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
queryObject, lockId, conditionInfo);
long criticalPutTime = System.currentTimeMillis();
- releaseLock(lockId, true);
+ voluntaryReleaseLock(lockId);
long lockDeleteTime = System.currentTimeMillis();
String timingInfo = "|lock creation time:" + (lockCreationTime - start)
+ "|lock accquire time:" + (lockAcqTime - lockCreationTime)
return criticalPutResult;
} else {
logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
- releaseLock(lockId, true);;
+ destroyLockRef(lockId);
return lockAcqResult;
}
}
logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
ResultSet result =
criticalGet(keyspaceName, tableName, primaryKey, queryObject, lockId);
- releaseLock(lockId, true);
+ voluntaryReleaseLock(lockId);
return result;
} else {
- releaseLock(lockId, true);
+ destroyLockRef(lockId);
logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
return null;
}