aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/music/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/music/main')
-rwxr-xr-xsrc/main/java/org/onap/music/main/CachingUtil.java40
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java52
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java10
-rw-r--r--src/main/java/org/onap/music/main/ResultType.java5
4 files changed, 42 insertions, 65 deletions
diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java
index aee3abbf..16a02862 100755
--- a/src/main/java/org/onap/music/main/CachingUtil.java
+++ b/src/main/java/org/onap/music/main/CachingUtil.java
@@ -60,7 +60,6 @@ public class CachingUtil implements Runnable {
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CachingUtil.class);
private static CacheAccess<String, String> musicCache = JCS.getInstance("musicCache");
- private static CacheAccess<String, String> musicLockCache = JCS.getInstance("musicLockCache");
private static CacheAccess<String, Map<String, String>> aafCache = JCS.getInstance("aafCache");
private static CacheAccess<String, String> appNameCache = JCS.getInstance("appNameCache");
private static Map<String, Number> userAttempts = new HashMap<>();
@@ -98,7 +97,6 @@ public class CachingUtil implements Runnable {
String userId = row.getString("username");
String password = row.getString("password");
String keySpace = row.getString("application_name");
- String uuid = row.getUUID("uuid").toString();
try {
userAttempts.put(nameSpace, 0);
AAFResponse responseObj = triggerAAF(nameSpace, userId, password);
@@ -107,7 +105,6 @@ public class CachingUtil implements Runnable {
map.put(userId, password);
aafCache.put(nameSpace, map);
musicCache.put(nameSpace, keySpace);
- musicLockCache.put(nameSpace, uuid);
logger.debug("Cronjob: Cache Updated with AAF response for namespace "
+ nameSpace);
}
@@ -260,43 +257,6 @@ public class CachingUtil implements Runnable {
resultMap.put("aid", uuid);
return resultMap;
}
-
-
- public static Map<String, Object> authenticateAIDUserLock(String aid, String nameSpace)
- throws Exception {
- Map<String, Object> resultMap = new HashMap<>();
- String uuid = null;
-
- if (musicLockCache.get(nameSpace) == null) {
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "SELECT uuid from admin.keyspace_master where application_name = '"
- + nameSpace + "' allow filtering");
- Row rs = MusicCore.get(pQuery).one();
- try {
- uuid = rs.getUUID("uuid").toString();
- musicLockCache.put(nameSpace, uuid);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- resultMap.put("Exception", "Unauthorized operation. Check AID and Namespace. ");
- return resultMap;
- }
- if (!musicLockCache.get(nameSpace).toString().equals(aid)) {
- resultMap.put("Exception Message",
- "Unauthorized operation. Invalid AID for the Namespace");
- return resultMap;
- }
- } else if (musicLockCache.get(nameSpace) != null
- && !musicLockCache.get(nameSpace).toString().equals(aid)) {
- resultMap.put("Exception Message",
- "Unauthorized operation. Invalid AID for the Namespace");
- return resultMap;
- }
- return resultMap;
- }
-
-
-
public static void updateMusicCache(String aid, String keyspace) {
logger.info(EELFLoggerDelegate.applicationLogger,"Updating musicCache for keyspace " + keyspace + " with aid " + aid);
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
index 73a6ee55..6ce6b0d3 100644
--- a/src/main/java/org/onap/music/main/MusicCore.java
+++ b/src/main/java/org/onap/music/main/MusicCore.java
@@ -27,6 +27,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.KeeperException.NoNodeException;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonKeySpace;
@@ -244,7 +246,7 @@ public class MusicCore {
}
}
- public static ReturnType acquireLock(String key, String lockId) {
+ public static ReturnType acquireLock(String key, String lockId) throws MusicLockingException {
/*
* first check if I am on top. Since ids are not reusable there is no need to check
* lockStatus If the status is unlocked, then the above call will automatically return
@@ -255,6 +257,7 @@ public class MusicCore {
result = getLockingServiceHandle().isMyTurn(lockId);
} catch (MusicLockingException e2) {
logger.error(EELFLoggerDelegate.errorLogger,AppMessages.INVALIDLOCK + lockId + " " + e2);
+ throw new MusicLockingException();
}
if (!result) {
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Not your turn, someone else has the lock");
@@ -265,6 +268,7 @@ public class MusicCore {
}
} catch (MusicLockingException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK+lockId,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ throw new MusicLockingException();
}
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: returning failure");
return new ReturnType(ResultType.FAILURE, "Not your turn, someone else has the lock");
@@ -463,9 +467,9 @@ public class MusicCore {
long start = System.currentTimeMillis();
try {
getLockingServiceHandle().unlockAndDeleteId(lockId);
- } catch (MusicLockingException e) {
+ } catch (MusicLockingException | NoNodeException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DESTROYLOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
+ }
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to destroy lock reference:" + (end - start) + " ms");
}
@@ -476,6 +480,10 @@ public class MusicCore {
getLockingServiceHandle().unlockAndDeleteId(lockId);
} catch (MusicLockingException e1) {
logger.error(EELFLoggerDelegate.errorLogger,e1.getMessage(), AppMessages.RELEASELOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ } catch (KeeperException.NoNodeException nne) {
+ logger.error(EELFLoggerDelegate.errorLogger,"Failed to release Lock " + lockId + " " + nne);
+ MusicLockState mls = new MusicLockState("Lock doesn't exists. Release lock operation failed.");
+ return mls;
}
String lockName = getLockNameFromId(lockId);
MusicLockState mls;
@@ -500,7 +508,11 @@ public class MusicCore {
}
public static void voluntaryReleaseLock(String lockId) throws MusicLockingException{
- getLockingServiceHandle().unlockAndDeleteId(lockId);
+ try {
+ getLockingServiceHandle().unlockAndDeleteId(lockId);
+ } catch (KeeperException.NoNodeException e) {
+ // ??? No way
+ }
}
/**
@@ -601,6 +613,7 @@ public class MusicCore {
} catch (MusicServiceException | MusicQueryException ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() + " " + ex.getCause() + " " + ex);
+ return new ReturnType(ResultType.FAILURE, ex.getMessage());
}
if (result) {
return new ReturnType(ResultType.SUCCESS, "Success");
@@ -663,7 +676,7 @@ public class MusicCore {
*
*
*/
- public static boolean nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency) throws MusicServiceException {
+ public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency) throws MusicServiceException {
// 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;
@@ -673,7 +686,7 @@ public class MusicCore {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
throw new MusicServiceException(ex.getMessage());
}
- return result;
+ return result?ResultType.SUCCESS:ResultType.FAILURE;
}
/**
@@ -883,18 +896,13 @@ public class MusicCore {
resultMap.put("Exception", "Aid is mandatory for nonAAF applications ");
return resultMap;
}
- if(operation.contains("Lock")) {
- resultMap = CachingUtil.authenticateAIDUserLock(aid, nameSpace);
- }
- else {
- resultMap = CachingUtil.authenticateAIDUser(aid, keyspace);
- }
+ resultMap = CachingUtil.authenticateAIDUser(aid, keyspace);
if (!resultMap.isEmpty())
return resultMap;
}
if (aid == null && (userId == null || password == null)) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
+ 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);
resultMap.put("Exception",
@@ -958,4 +966,22 @@ public class MusicCore {
return resultMap;
}
+
+ /**
+ * @param lockName
+ * @return
+ */
+ public static Map<String, Object> validateLock(String lockName) {
+ Map<String, Object> resultMap = new HashMap<>();
+ String[] locks = lockName.split("\\.");
+ if(locks.length < 3) {
+ resultMap.put("Exception", "Invalid lock. Please make sure lock is of the type keyspaceName.tableName.primaryKey");
+ return resultMap;
+ }
+ String keyspace= locks[0];
+ if(keyspace.startsWith("$"))
+ keyspace = keyspace.substring(1);
+ resultMap.put("keyspace",keyspace);
+ return resultMap;
+ }
}
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
index 0f77614e..c0b968be 100755
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/src/main/java/org/onap/music/main/MusicUtil.java
@@ -475,14 +475,4 @@ public class MusicUtil {
}
return sqlString.toString();
}
-
- public static Map<String, HashMap<String, Object>> setErrorResponse(MusicServiceException ex) {
- Map<String, HashMap<String, Object>> results = new HashMap<>();
- HashMap<String, Object> tempMap = new HashMap<>();
- Map<String, Object> result = new HashMap<>();
- result.put("error-description", ex.getMessage());
- tempMap.put("error", result);
- results.put("result", tempMap);
- return results;
- }
}
diff --git a/src/main/java/org/onap/music/main/ResultType.java b/src/main/java/org/onap/music/main/ResultType.java
index 6b0c5252..61ba0295 100644
--- a/src/main/java/org/onap/music/main/ResultType.java
+++ b/src/main/java/org/onap/music/main/ResultType.java
@@ -23,8 +23,9 @@ package org.onap.music.main;
public enum ResultType {
SUCCESS("Success"), FAILURE("Failure"),
- SYNTAXERROR("SyntaxError"), EXCEPTION("Exception");
-
+ SYNTAXERROR("SyntaxError"), EXCEPTION("Exception"),
+ BODYMISSING("Incomplete Request body. Please correct your input request and retry.");
+
private String result;
ResultType(String result) {