package org.onap.music.main;
+import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
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
}
/**
*
* @param lockName
+ * @throws MusicLockingException
*/
- public static void deleteLock(String lockName) {
+ public static void deleteLock(String lockName) throws MusicLockingException {
long start = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Deleting lock for " + lockName);
try {
getLockingServiceHandle().deleteLock("/" + lockName);
} catch (MusicLockingException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DELTELOCK+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ throw new MusicLockingException(e.getMessage());
}
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to delete lock:" + (end - start) + " ms");
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());
}
ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
queryObject, lockId, conditionInfo);
long criticalPutTime = System.currentTimeMillis();
- voluntaryReleaseLock(lockId);
+ releaseLock(lockId, true);
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);
- destroyLockRef(lockId);
+ releaseLock(lockId, true);;
return lockAcqResult;
}
}
logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
ResultSet result =
criticalGet(keyspaceName, tableName, primaryKey, queryObject, lockId);
- voluntaryReleaseLock(lockId);
+ releaseLock(lockId, true);
return result;
} else {
- destroyLockRef(lockId);
+ releaseLock(lockId, true);
logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
return null;
}
operation);
if (!resultMap.isEmpty())
return resultMap;
- String isAAFApp = CachingUtil.isAAFApplication(nameSpace);
+ String isAAFApp = null;
+ try {
+ isAAFApp= CachingUtil.isAAFApplication(nameSpace);
+ } catch(MusicServiceException e) {
+ resultMap.put("Exception", e.getMessage());
+ return resultMap;
+ }
if(isAAFApp == null) {
resultMap.put("Exception", "Namespace: "+nameSpace+" doesn't exist. Please make sure ns(appName)"
+ " is correct and Application is onboarded.");
return resultMap;
}
boolean isAAF = Boolean.valueOf(isAAFApp);
- if (!isAAF && !(operation.equals("createKeySpace"))) {
- if(aid == null) {
- resultMap.put("Exception", "Aid is mandatory for nonAAF applications ");
- return resultMap;
- }
- resultMap = CachingUtil.authenticateAIDUser(aid, keyspace);
-
- if (!resultMap.isEmpty())
- return resultMap;
- }
- if (aid == null && (userId == null || password == null)) {
+ if (userId == null || password == null) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
logger.error(EELFLoggerDelegate.errorLogger,"One or more required headers is missing. userId: " + userId
+ " :: password: " + password);
"UserId and Password are mandatory for the operation " + operation);
return resultMap;
}
-
+ if(!isAAF && !(operation.equals("createKeySpace"))) {
+ resultMap = CachingUtil.authenticateAIDUser(nameSpace, userId, password, keyspace);
+ if (!resultMap.isEmpty())
+ return resultMap;
+
+ }
if (isAAF && nameSpace != null && userId != null && password != null) {
boolean isValid = true;
try {