aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/music/conductor/conditionals/MusicContional.java14
-rw-r--r--src/main/java/org/onap/music/lockingservice/MusicLockState.java7
-rwxr-xr-xsrc/main/java/org/onap/music/main/CachingUtil.java10
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java21
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCore.java6
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicData.java2
6 files changed, 41 insertions, 19 deletions
diff --git a/src/main/java/org/onap/music/conductor/conditionals/MusicContional.java b/src/main/java/org/onap/music/conductor/conditionals/MusicContional.java
index 93e34721..492f7c62 100644
--- a/src/main/java/org/onap/music/conductor/conditionals/MusicContional.java
+++ b/src/main/java/org/onap/music/conductor/conditionals/MusicContional.java
@@ -95,7 +95,7 @@ public class MusicContional {
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
ReturnType criticalPutResult = conditionalInsertAtomic(lockId, keyspace, tablename, primaryKey,
queryBank);
- MusicCore.destroyLockRef(lockId);
+ MusicCore.releaseLock(lockId, true);
if (criticalPutResult.getMessage().contains("insert"))
criticalPutResult
.setMessage("Insert values: ");
@@ -105,11 +105,11 @@ public class MusicContional {
return criticalPutResult;
} else {
- MusicCore.destroyLockRef(lockId);
+ MusicCore.releaseLock(lockId, true);
return lockAcqResult;
}
} catch (Exception e) {
- MusicCore.destroyLockRef(lockId);
+ MusicCore.releaseLock(lockId, true);
return new ReturnType(ResultType.FAILURE, e.getMessage());
}
@@ -163,15 +163,17 @@ public class MusicContional {
try {
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- return updateAtomic(lockId, keyspace, tableName, primaryKey,primaryKeyValue, queryBank,planId,cascadeColumnValues,cascadeColumnName);
+ ReturnType updateResult= updateAtomic(lockId, keyspace, tableName, primaryKey,primaryKeyValue, queryBank,planId,cascadeColumnValues,cascadeColumnName);
+ MusicCore.releaseLock(lockId, true);
+ return updateResult;
} else {
- MusicCore.destroyLockRef(lockId);
+ MusicCore.releaseLock(lockId, true);
return lockAcqResult;
}
} catch (Exception e) {
- MusicCore.destroyLockRef(lockId);
+ MusicCore.releaseLock(lockId, true);
return new ReturnType(ResultType.FAILURE, e.getMessage());
}
diff --git a/src/main/java/org/onap/music/lockingservice/MusicLockState.java b/src/main/java/org/onap/music/lockingservice/MusicLockState.java
index 6c31410f..448a36e5 100644
--- a/src/main/java/org/onap/music/lockingservice/MusicLockState.java
+++ b/src/main/java/org/onap/music/lockingservice/MusicLockState.java
@@ -134,4 +134,11 @@ public class MusicLockState implements Serializable {
}
return (MusicLockState) o;
}
+
+ @Override
+ public String toString() {
+ // TODO Auto-generated method stub
+ return "lockStatus:"+ (lockStatus == null ? null : lockStatus.toString())+" |needToSyncQuorum:"+needToSyncQuorum+" |lockHolder:"+lockHolder
+ +" |leasePeriod:"+leasePeriod+" |leaseStartTime:"+leaseStartTime;
+ }
}
diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java
index 26491302..b34721bb 100755
--- a/src/main/java/org/onap/music/main/CachingUtil.java
+++ b/src/main/java/org/onap/music/main/CachingUtil.java
@@ -133,9 +133,9 @@ public class CachingUtil implements Runnable {
String keySpace) throws Exception {
if (aafCache.get(nameSpace) != null) {
- if (keySpace != null && !musicCache.get(keySpace).equals(nameSpace)) {
+ /* if (keySpace != null && !musicCache.get(keySpace).equals(nameSpace)) {
logger.info(EELFLoggerDelegate.applicationLogger,"Create new application for the same namespace.");
- } else if (aafCache.get(nameSpace).get(userId).equals(password)) {
+ } else */if (aafCache.get(nameSpace).get(userId).equals(password)) {
logger.info(EELFLoggerDelegate.applicationLogger,"Authenticated with cache value..");
// reset invalid attempts to 0
userAttempts.put(nameSpace, 0);
@@ -167,9 +167,9 @@ public class CachingUtil implements Runnable {
if (aafRresponse) {
//TODO
//if (responseObj.getNs().get(0).getAdmin().contains(userId)) {
- //Map<String, String> map = new HashMap<>();
- //map.put(userId, password);
- //aafCache.put(nameSpace, map);
+ Map<String, String> map = new HashMap<>();
+ map.put(userId, password);
+ aafCache.put(nameSpace, map);
return true;
//}
}
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
index cc147d57..661d7adc 100644
--- a/src/main/java/org/onap/music/main/MusicCore.java
+++ b/src/main/java/org/onap/music/main/MusicCore.java
@@ -294,6 +294,10 @@ public class MusicCore {
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);
}
@@ -511,6 +515,14 @@ public class MusicCore {
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
}
@@ -641,6 +653,7 @@ public class MusicCore {
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 {
@@ -762,7 +775,7 @@ public class MusicCore {
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)
@@ -772,7 +785,7 @@ public class MusicCore {
return criticalPutResult;
} else {
logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
- destroyLockRef(lockId);
+ releaseLock(lockId, true);;
return lockAcqResult;
}
}
@@ -842,10 +855,10 @@ public class MusicCore {
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;
}
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCore.java b/src/test/java/org/onap/music/unittests/TestMusicCore.java
index e798aaf1..d1da3195 100644
--- a/src/test/java/org/onap/music/unittests/TestMusicCore.java
+++ b/src/test/java/org/onap/music/unittests/TestMusicCore.java
@@ -136,11 +136,11 @@ public class TestMusicCore {
@Test
public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandDontHaveLock() throws MusicLockingException {
MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id2");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
+ Mockito.when(mLockHandle.isMyTurn("id2")).thenReturn(true);
Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
+ ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id2");
assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
+ Mockito.verify(mLockHandle).isMyTurn("id2");
Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
}
diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
index b9fd058a..4234c88e 100644
--- a/src/test/java/org/onap/music/unittests/TestRestMusicData.java
+++ b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
@@ -470,7 +470,7 @@ public class TestRestMusicData {
JsonDelete jsonDelete = new JsonDelete();
Map<String, String> consistencyInfo = new HashMap<>();
MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- consistencyInfo.put("type", "atomic");
+ consistencyInfo.put("type", "eventual");
jsonDelete.setConsistencyInfo(consistencyInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Mockito.when(info.getQueryParameters()).thenReturn(row);