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.java79
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java114
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java872
-rwxr-xr-xsrc/main/java/org/onap/music/main/PropertiesListener.java4
-rw-r--r--src/main/java/org/onap/music/main/ResultType.java3
5 files changed, 568 insertions, 504 deletions
diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java
index 4b2b4824..aee3abbf 100755
--- a/src/main/java/org/onap/music/main/CachingUtil.java
+++ b/src/main/java/org/onap/music/main/CachingUtil.java
@@ -36,6 +36,9 @@ import org.codehaus.jackson.map.ObjectMapper;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.AAFResponse;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
+import org.onap.music.eelf.logging.format.AppMessages;
+import org.onap.music.eelf.logging.format.ErrorSeverity;
+import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicServiceException;
import com.att.eelf.configuration.EELFLogger;
@@ -83,8 +86,8 @@ public class CachingUtil implements Runnable {
try {
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), false));
} catch (Exception e1) {
+ logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.CACHEERROR, ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
e1.printStackTrace();
- logger.error(EELFLoggerDelegate.errorLogger,"Exception is "+ e1.getMessage() + "during initalizeAafCache");
}
ResultSet rs = MusicCore.get(pQuery);
Iterator<Row> it = rs.iterator();
@@ -109,11 +112,9 @@ public class CachingUtil implements Runnable {
+ nameSpace);
}
} catch (Exception e) {
- // TODO Auto-generated catch block
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Something at AAF was changed for ns: " + nameSpace+" So not updating Cache for the namespace. ");
e.printStackTrace();
- logger.error("Something at AAF was changed for ns: " + nameSpace
- + ". So not updating Cache for the namespace. ");
- logger.error("Exception is " + e.getMessage());
}
}
@@ -121,11 +122,11 @@ public class CachingUtil implements Runnable {
@Override
public void run() {
- logger.debug("Scheduled task invoked. Refreshing Cache...");
+ logger.info(EELFLoggerDelegate.applicationLogger,"Scheduled task invoked. Refreshing Cache...");
try {
initializeAafCache();
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR);
}
}
@@ -134,9 +135,9 @@ public class CachingUtil implements Runnable {
if (aafCache.get(nameSpace) != null) {
if (keySpace != null && !musicCache.get(nameSpace).equals(keySpace)) {
- logger.debug("Create new application for the same namespace.");
+ logger.info(EELFLoggerDelegate.applicationLogger,"Create new application for the same namespace.");
} else if (aafCache.get(nameSpace).get(userId).equals(password)) {
- logger.debug("Authenticated with cache value..");
+ logger.info(EELFLoggerDelegate.applicationLogger,"Authenticated with cache value..");
// reset invalid attempts to 0
userAttempts.put(nameSpace, 0);
return true;
@@ -154,10 +155,11 @@ public class CachingUtil implements Runnable {
logger.info(EELFLoggerDelegate.applicationLogger,"Resetting failed attempt.");
userAttempts.put(nameSpace, 0);
} else {
+ logger.info(EELFLoggerDelegate.applicationLogger,"No more attempts allowed. Please wait for atleast 2 min.");
throw new Exception("No more attempts allowed. Please wait for atleast 2 min.");
}
}
- logger.error(EELFLoggerDelegate.errorLogger,"Cache not authenticated..");
+ logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.CACHEAUTHENTICATION,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
logger.info(EELFLoggerDelegate.applicationLogger,"Check AAF again...");
}
}
@@ -178,6 +180,7 @@ public class CachingUtil implements Runnable {
private static AAFResponse triggerAAF(String nameSpace, String userId, String password)
throws Exception {
if (MusicUtil.getAafEndpointUrl() == null) {
+ logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
throw new Exception("AAF endpoint is not set. Please specify in the properties file.");
}
Client client = Client.create();
@@ -213,6 +216,7 @@ public class CachingUtil implements Runnable {
response.bufferEntity();
String x = response.getEntity(String.class);
AAFResponse responseObj = new ObjectMapper().readValue(x, AAFResponse.class);
+
return responseObj;
}
@@ -235,7 +239,7 @@ public class CachingUtil implements Runnable {
musicCache.put(keyspace, uuid);
} catch (Exception e) {
String msg = e.getMessage();
- logger.error("Exception occured during uuid retrieval from DB." + e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
resultMap.put("Exception", "Unauthorized operation. Check AID and Keyspace. "
+ "Exception from MUSIC is: "
+ (msg == null ? "Keyspace is new so no AID should be passed in Header."
@@ -273,8 +277,8 @@ public class CachingUtil implements Runnable {
uuid = rs.getUUID("uuid").toString();
musicLockCache.put(nameSpace, uuid);
} catch (Exception e) {
- logger.error("Exception occured during uuid retrieval from DB." + e.getMessage());
- resultMap.put("Exception", "Unauthorized operation. Check AID and Namespace. ");
+ 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)) {
@@ -295,7 +299,7 @@ public class CachingUtil implements Runnable {
public static void updateMusicCache(String aid, String keyspace) {
- logger.info("Updating musicCache for keyspace " + keyspace + " with aid " + aid);
+ logger.info(EELFLoggerDelegate.applicationLogger,"Updating musicCache for keyspace " + keyspace + " with aid " + aid);
musicCache.put(keyspace, aid);
}
@@ -316,12 +320,11 @@ public class CachingUtil implements Runnable {
isAAF = String.valueOf(rs.getBool("is_aaf"));
appNameCache.put(namespace, isAAF);
} catch (Exception e) {
- logger.error("Exception occured during uuid retrieval from DB." + e.getMessage());
- e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
+ e.printStackTrace();
}
}
-
return Boolean.valueOf(isAAF);
}
@@ -354,7 +357,7 @@ public class CachingUtil implements Runnable {
try {
appName = rs.getString("application_name");
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Exception occured during uuid retrieval from DB."+e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
e.printStackTrace();
}
return appName;
@@ -378,31 +381,49 @@ public class CachingUtil implements Runnable {
}
- public static Map<String, Object> verifyOnboarding(String ns, String userId, String password)
- throws Exception {
+ public static Map<String, Object> verifyOnboarding(String ns, String userId, String password) {
Map<String, Object> resultMap = new HashMap<>();
if (ns == null || userId == null || password == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"One or more required headers is missing. userId: "+userId+" :: password: "+password);
+ 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",
"One or more required headers appName(ns), userId, password is missing. Please check.");
return resultMap;
}
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString(
- "select * from admin.keyspace_master where application_name = ? and username = ? and password = ? allow filtering");
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
- Row rs = MusicCore.get(queryObject).one();
+ "select * from admin.keyspace_master where application_name = ? allow filtering");
+ try {
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
+ } catch(Exception e) {
+ resultMap.put("Exception",
+ "Unable to process input data. Invalid input data type. Please check ns, userId and password values. "+e.getMessage());
+ return resultMap;
+ }
+ Row rs = null;
+ try {
+ rs = MusicCore.get(queryObject).one();
+ } catch (MusicServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
+ return resultMap;
+ }
if (rs == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"Namespace, UserId and password doesn't match. namespace: "+ns+" and userId: "+userId);
-
- resultMap.put("Exception", "Namespace, UserId and password doesn't match. namespace: "+ns+" and userId: "+userId);
+ logger.error(EELFLoggerDelegate.errorLogger,"Application is not onboarded. Please contact admin.");
+ resultMap.put("Exception", "Application is not onboarded. Please contact admin.");
} else {
+ if(!(rs.getString("username").equals(userId)) && !(rs.getString("password").equals("password"))) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,"Namespace, UserId and password doesn't match. namespace: "+ns+" and userId: "+userId);
+ resultMap.put("Exception", "Namespace, UserId and password doesn't match. namespace: "+ns+" and userId: "+userId);
+ return resultMap;
+ }
boolean is_aaf = rs.getBool("is_aaf");
String keyspace = rs.getString("keyspace_name");
if (!is_aaf) {
if (!keyspace.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
logger.error(EELFLoggerDelegate.errorLogger,"Non AAF applications are allowed to have only one keyspace per application.");
resultMap.put("Exception",
"Non AAF applications are allowed to have only one keyspace per application.");
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
index 3d5cf4e5..73a6ee55 100644
--- a/src/main/java/org/onap/music/main/MusicCore.java
+++ b/src/main/java/org/onap/music/main/MusicCore.java
@@ -31,7 +31,9 @@ import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonKeySpace;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
-// import org.onap.music.eelf.logging.EELFLoggerDelegate;
+import org.onap.music.eelf.logging.format.AppMessages;
+import org.onap.music.eelf.logging.format.ErrorSeverity;
+import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicLockingException;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
@@ -66,7 +68,7 @@ public class MusicCore {
this.selectQueryForTheRow = selectQueryForTheRow;
}
- public boolean testCondition() {
+ public boolean testCondition() throws Exception {
// first generate the row
ResultSet results = quorumGet(selectQueryForTheRow);
Row row = results.one();
@@ -83,7 +85,7 @@ public class MusicCore {
try {
mLockHandle = new MusicLockingService();
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to aquire Locl store handle" + e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKHANDLE,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
throw new MusicLockingException("Failed to aquire Locl store handle " + e);
}
}
@@ -111,12 +113,24 @@ public class MusicCore {
/**
*
* @return
+ * @throws MusicServiceException
*/
- public static MusicDataStore getDSHandle() {
+ public static MusicDataStore getDSHandle() throws MusicServiceException {
logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
long start = System.currentTimeMillis();
if (mDstoreHandle == null) {
- mDstoreHandle = new MusicDataStore();
+ // Quick Fix - Best to put this into every call to getDSHandle?
+ if (! MusicUtil.getMyCassaHost().equals("localhost") ) {
+ mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
+ } else {
+ mDstoreHandle = new MusicDataStore();
+ }
+ }
+ if(mDstoreHandle.getSession() == null) {
+ String message = "Connection to Cassandra has not been enstablished."
+ + " Please check connection properites and reboot.";
+ logger.info(EELFLoggerDelegate.applicationLogger, message);
+ throw new MusicServiceException(message);
}
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
@@ -130,7 +144,8 @@ public class MusicCore {
try {
lockId = getLockingServiceHandle().createLockId("/" + lockName);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to create Lock Reference " + lockName);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.CREATELOCK+lockName,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+
}
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to create lock reference:" + (end - start) + " ms");
@@ -169,7 +184,7 @@ public class MusicCore {
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to get lock state:" + (end - start) + " ms");
return mls;
} catch (NullPointerException | MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"No lock object exists as of now.." + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
return null;
}
@@ -194,14 +209,18 @@ public class MusicCore {
}
}
} else
- logger.debug("There is no lock state object for " + key);
-
+ logger.error(EELFLoggerDelegate.errorLogger,key, AppMessages.INVALIDLOCK,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+
/*
* call the traditional acquire lock now and if the result returned is true, set the
* begin time-stamp and lease period
*/
if (acquireLock(key, lockId).getResult() == ResultType.SUCCESS) {
mls = getMusicLockState(key);// get latest state
+ if ( mls == null ) {
+ logger.info(EELFLoggerDelegate.applicationLogger,"Music Lock State is null");
+ return new ReturnType(ResultType.FAILURE, "Could not acquire lock, Lock State is null");
+ }
if (mls.getLeaseStartTime() == -1) {// set it again only if it is not set already
mls.setLeaseStartTime(System.currentTimeMillis());
mls.setLeasePeriod(leasePeriod);
@@ -217,7 +236,8 @@ public class MusicCore {
}
} catch (Exception e) {
StringWriter sw = new StringWriter();
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR506E] Failed to aquire lock ",ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+
String exceptionAsString = sw.toString();
return new ReturnType(ResultType.FAILURE,
"Exception thrown in acquireLockWithLease:\n" + exceptionAsString);
@@ -234,9 +254,9 @@ public class MusicCore {
try {
result = getLockingServiceHandle().isMyTurn(lockId);
} catch (MusicLockingException e2) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to aquireLock lockId " + lockId + " " + e2);
+ logger.error(EELFLoggerDelegate.errorLogger,AppMessages.INVALIDLOCK + lockId + " " + e2);
}
- if (result == false) {
+ if (!result) {
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Not your turn, someone else has the lock");
try {
if (!getLockingServiceHandle().lockIdExists(lockId)) {
@@ -244,7 +264,7 @@ public class MusicCore {
return new ReturnType(ResultType.FAILURE, "Lockid doesn't exist");
}
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to check if lockid exists - lockId " + lockId + " " + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK+lockId,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: returning failure");
return new ReturnType(ResultType.FAILURE, "Not your turn, someone else has the lock");
@@ -253,7 +273,7 @@ public class MusicCore {
// this is for backward compatibility where locks could also be acquired on just
// keyspaces or tables.
- if (isTableOrKeySpaceLock(key) == true) {
+ if (isTableOrKeySpaceLock(key)) {
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: A table or keyspace lock so no need to perform sync...so returning true");
return new ReturnType(ResultType.SUCCESS, "A table or keyspace lock so no need to perform sync...so returning true");
}
@@ -270,7 +290,7 @@ public class MusicCore {
return new ReturnType(ResultType.SUCCESS, "You already have the lock!");
}
} catch (NullPointerException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"In acquire lock:No one has tried to acquire the lock yet..");
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK+lockId,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
// change status to "being locked". This state transition is necessary to ensure syncing
@@ -286,14 +306,18 @@ public class MusicCore {
try {
getLockingServiceHandle().setLockState(key, newMls);
} catch (MusicLockingException e1) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to set Lock state " + key + " " + e1);
+ logger.error(EELFLoggerDelegate.errorLogger,e1.getMessage(), AppMessages.LOCKSTATE+key,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Set lock state to being_locked");
// do syncing if this was a forced lock release
if (needToSyncQuorum) {
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Since there was a forcible release, need to sync quorum!");
- syncQuorum(key);
+ try {
+ syncQuorum(key);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,"Failed to set Lock state " + e);
+ }
}
// change status to locked
@@ -303,7 +327,7 @@ public class MusicCore {
try {
getLockingServiceHandle().setLockState(key, newMls);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to set Lock state " + key + " " + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKSTATE+key,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Set lock state to locked and assigned current lock ref "
+ lockId + " as holder");
@@ -325,7 +349,7 @@ public class MusicCore {
}
- private static void syncQuorum(String key) {
+ private static void syncQuorum(String key) throws Exception {
logger.info(EELFLoggerDelegate.applicationLogger,"Performing sync operation---");
String[] splitString = key.split("\\.");
String keyspaceName = splitString[0];
@@ -346,8 +370,6 @@ public class MusicCore {
selectQuery.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName + " WHERE "
+ primaryKeyName + "= ?" + ";");
selectQuery.addValue(cqlFormattedPrimaryKeyValue);
- // String selectQuery = "SELECT * FROM "+keyspaceName+"."+tableName+ " WHERE
- // "+primaryKeyName+"="+cqlFormattedPrimaryKeyValue+";";
ResultSet results = null;
try {
results = getDSHandle().executeCriticalGet(selectQuery);
@@ -356,7 +378,6 @@ public class MusicCore {
ColumnDefinitions colInfo = row.getColumnDefinitions();
int totalColumns = colInfo.size();
int counter = 1;
- // String fieldValueString="";
StringBuilder fieldValueString = new StringBuilder("");
for (Definition definition : colInfo) {
String colName = definition.getName();
@@ -365,7 +386,6 @@ public class MusicCore {
DataType colType = definition.getType();
Object valueObj = getDSHandle().getColValue(row, colName, colType);
Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- // fieldValueString = fieldValueString+ colName+"="+valueString;
fieldValueString.append(colName + " = ?");
updateQuery.addValue(valueString);
if (counter != (totalColumns - 1))
@@ -375,12 +395,10 @@ public class MusicCore {
updateQuery.appendQueryString("UPDATE " + keyspaceName + "." + tableName + " SET "
+ fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
updateQuery.addValue(cqlFormattedPrimaryKeyValue);
- // String updateQuery = "UPDATE "+keyspaceName+"."+tableName+" SET "+fieldValueString+"
- // WHERE "+primaryKeyName+"="+cqlFormattedPrimaryKeyValue+";";
getDSHandle().executePut(updateQuery, "critical");
} catch (MusicServiceException | MusicQueryException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to execute update query " + updateQuery + " " + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery ,ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR);
}
}
@@ -397,7 +415,8 @@ public class MusicCore {
try {
results = getDSHandle().executeCriticalGet(query);
} catch (MusicServiceException | MusicQueryException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.MAJOR, ErrorTypes.GENERALSERVICEERROR);
+
}
return results;
@@ -407,8 +426,9 @@ public class MusicCore {
*
* @param results
* @return
+ * @throws MusicServiceException
*/
- public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) {
+ public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) throws MusicServiceException {
return getDSHandle().marshalData(results);
}
@@ -422,7 +442,7 @@ public class MusicCore {
try {
return getLockingServiceHandle().whoseTurnIsIt("/" + lockName) + "";
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed whoseTurnIsIt " + lockName + " " + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKINGERROR+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
return null;
@@ -444,7 +464,7 @@ public class MusicCore {
try {
getLockingServiceHandle().unlockAndDeleteId(lockId);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to Destroy Lock Ref " + lockId + " " + 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");
@@ -455,7 +475,7 @@ public class MusicCore {
try {
getLockingServiceHandle().unlockAndDeleteId(lockId);
} catch (MusicLockingException e1) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to release Lock " + lockId + " " + e1);
+ logger.error(EELFLoggerDelegate.errorLogger,e1.getMessage(), AppMessages.RELEASELOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
String lockName = getLockNameFromId(lockId);
MusicLockState mls;
@@ -472,7 +492,7 @@ public class MusicCore {
try {
getLockingServiceHandle().setLockState(lockName, mls);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to release Lock " + lockName + " " + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.RELEASELOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to release lock:" + (end - start) + " ms");
@@ -493,7 +513,7 @@ public class MusicCore {
try {
getLockingServiceHandle().deleteLock("/" + lockName);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to Delete Lock " + lockName + " " + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DELTELOCK+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to delete lock:" + (end - start) + " ms");
@@ -506,8 +526,9 @@ public class MusicCore {
* @param keyspace
* @param tablename
* @return
+ * @throws MusicServiceException
*/
- public static TableMetadata returnColumnMetadata(String keyspace, String tablename) {
+ public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException {
return getDSHandle().returnColumnMetadata(keyspace, tablename);
}
@@ -520,7 +541,7 @@ public class MusicCore {
try {
getLockingServiceHandle().getzkLockHandle().createNode(nodeName);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to get ZK Lock Handle " + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
}
@@ -535,7 +556,7 @@ public class MusicCore {
try {
getLockingServiceHandle().getzkLockHandle().setNodeData(nodeName, data);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to get ZK Lock Handle " + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
logger.info(EELFLoggerDelegate.applicationLogger,"Performed zookeeper write to " + nodeName);
long end = System.currentTimeMillis();
@@ -553,7 +574,7 @@ public class MusicCore {
try {
data = getLockingServiceHandle().getzkLockHandle().getNodeData(nodeName);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to get ZK Lock Handle " + e);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the actual zk put:" + (end - start) + " ms");
@@ -578,6 +599,7 @@ public class MusicCore {
try {
result = getDSHandle().executePut(queryObject, MusicUtil.EVENTUAL);
} 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);
}
if (result) {
@@ -604,10 +626,16 @@ public class MusicCore {
MusicLockState mls = getLockingServiceHandle()
.getLockState(keyspaceName + "." + tableName + "." + primaryKey);
if (mls.getLockHolder().equals(lockId) == true) {
- if (conditionInfo != null)// check if condition is true
+ if (conditionInfo != null)
+ try {
if (conditionInfo.testCondition() == false)
return new ReturnType(ResultType.FAILURE,
"Lock acquired but the condition is not true");
+ } catch (Exception e) {
+ return new ReturnType(ResultType.FAILURE,
+ "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
+ + e.getMessage());
+ }
getDSHandle().executePut(queryObject, MusicUtil.CRITICAL);
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the critical put:" + (end - start) + " ms");
@@ -642,7 +670,7 @@ public class MusicCore {
try {
result = getDSHandle().executePut(queryObject, consistency);
} catch (MusicQueryException | MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
throw new MusicServiceException(ex.getMessage());
}
return result;
@@ -688,7 +716,7 @@ public class MusicCore {
} else
throw new MusicServiceException("YOU DO NOT HAVE THE LOCK");
} catch (MusicQueryException | MusicServiceException | MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
}
return results;
}
@@ -866,6 +894,7 @@ public class MusicCore {
return resultMap;
}
if (aid == null && (userId == null || password == null)) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
logger.error(EELFLoggerDelegate.errorLogger,"One or more required headers is missing. userId: " + userId
+ " :: password: " + password);
resultMap.put("Exception",
@@ -878,11 +907,12 @@ public class MusicCore {
try {
isValid = CachingUtil.authenticateAAFUser(nameSpace, userId, password, keyspace);
} catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
logger.error(EELFLoggerDelegate.errorLogger,"Got exception while AAF authentication for namespace " + nameSpace);
resultMap.put("Exception", e.getMessage());
}
if (!isValid) {
- logger.error(EELFLoggerDelegate.errorLogger,"User not authenticated with AAF.");
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
resultMap.put("Exception", "User not authenticated...");
}
if (!resultMap.isEmpty())
@@ -921,7 +951,7 @@ public class MusicCore {
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(uuid, keyspace);
+ //CachingUtil.updateMusicCache(uuid, keyspace);
MusicCore.eventualPut(pQuery);
resultMap.put("aid", uuid);
}
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
index a31e33f9..0f77614e 100755
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/src/main/java/org/onap/music/main/MusicUtil.java
@@ -45,436 +45,444 @@ import com.datastax.driver.core.DataType;
*
*/
public class MusicUtil {
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
-
- private static int myId = 0;
- private static ArrayList<String> allIds = new ArrayList<String>();
- private static String publicIp = "";
- private static ArrayList<String> allPublicIps = new ArrayList<String>();
- private static String myZkHost = "localhost";
- private static String myCassaHost = "localhost";
- private static String defaultMusicIp = "localhost";
- private static boolean debug = true;
- private static String version = "2.3.0";
- private static String musicRestIp = "localhost";
- private static String musicPropertiesFilePath = "/opt/app/music/etc/music.properties";
- private static long defaultLockLeasePeriod = 6000;
- private static final String[] propKeys = new String[] { "zookeeper.host", "cassandra.host", "music.ip", "debug",
- "version", "music.rest.ip", "music.properties", "lock.lease.period", "id", "all.ids", "public.ip",
- "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url" };
-
- public static final String ATOMIC = "atomic";
- public static final String EVENTUAL = "eventual";
- public static final String CRITICAL = "critical";
- public static final String ATOMICDELETELOCK = "atomic_delete_lock";
-
- public static final String DEFAULTKEYSPACENAME = "TBD";
- private static String cassName = "cassandra";
- private static String cassPwd;
- private static String aafEndpointUrl = null;
-
- /**
- * @return the cassName
- */
- public static String getCassName() {
- return cassName;
- }
-
- /**
- * @return the cassPwd
- */
- public static String getCassPwd() {
- return cassPwd;
- }
-
- /**
- * @return the aafEndpointUrl
- */
- public static String getAafEndpointUrl() {
- return aafEndpointUrl;
- }
-
- /**
- *
- * @param aafEndpointUrl
- */
- public static void setAafEndpointUrl(String aafEndpointUrl) {
- MusicUtil.aafEndpointUrl = aafEndpointUrl;
- }
-
- /**
- *
- * @return
- */
- public static int getMyId() {
- return myId;
- }
-
- /**
- *
- * @param myId
- */
- public static void setMyId(int myId) {
- MusicUtil.myId = myId;
- }
-
- /**
- *
- * @return
- */
- public static ArrayList<String> getAllIds() {
- return allIds;
- }
-
- /**
- *
- * @param allIds
- */
- public static void setAllIds(List<String> allIds) {
- MusicUtil.allIds = (ArrayList<String>) allIds;
- }
-
- /**
- *
- * @return
- */
- public static String getPublicIp() {
- return publicIp;
- }
-
- /**
- *
- * @param publicIp
- */
- public static void setPublicIp(String publicIp) {
- MusicUtil.publicIp = publicIp;
- }
-
- /**
- *
- * @return
- */
- public static ArrayList<String> getAllPublicIps() {
- return allPublicIps;
- }
-
- /**
- *
- * @param allPublicIps
- */
- public static void setAllPublicIps(List<String> allPublicIps) {
- MusicUtil.allPublicIps = (ArrayList<String>) allPublicIps;
- }
-
- /**
- * Returns An array of property names that should be in the Properties
- * files.
- *
- * @return
- */
- public static String[] getPropkeys() {
- return propKeys;
- }
-
- /**
- * Get MusicRestIp - default = localhost property file value - music.rest.ip
- *
- * @return
- */
- public static String getMusicRestIp() {
- return musicRestIp;
- }
-
- /**
- * Set MusicRestIp
- *
- * @param musicRestIp
- */
- public static void setMusicRestIp(String musicRestIp) {
- MusicUtil.musicRestIp = musicRestIp;
- }
-
- /**
- * Get MusicPropertiesFilePath - Default = /opt/music/music.properties
- * property file value - music.properties
- *
- * @return
- */
- public static String getMusicPropertiesFilePath() {
- return musicPropertiesFilePath;
- }
-
- /**
- * Set MusicPropertiesFilePath
- *
- * @param musicPropertiesFilePath
- */
- public static void setMusicPropertiesFilePath(String musicPropertiesFilePath) {
- MusicUtil.musicPropertiesFilePath = musicPropertiesFilePath;
- }
-
- /**
- * Get DefaultLockLeasePeriod - Default = 6000 property file value -
- * lock.lease.period
- *
- * @return
- */
- public static long getDefaultLockLeasePeriod() {
- return defaultLockLeasePeriod;
- }
-
- /**
- * Set DefaultLockLeasePeriod
- *
- * @param defaultLockLeasePeriod
- */
- public static void setDefaultLockLeasePeriod(long defaultLockLeasePeriod) {
- MusicUtil.defaultLockLeasePeriod = defaultLockLeasePeriod;
- }
-
- /**
- * Set Debug
- *
- * @param debug
- */
- public static void setDebug(boolean debug) {
- MusicUtil.debug = debug;
- }
-
- /**
- * Is Debug - Default = true property file value - debug
- *
- * @return
- */
- public static boolean isDebug() {
- return debug;
- }
-
- /**
- * Set Version
- *
- * @param version
- */
- public static void setVersion(String version) {
- MusicUtil.version = version;
- }
-
- /**
- * Return the version property file value - version
- *
- * @return
- */
- public static String getVersion() {
- return version;
- }
-
- /**
- * Get MyZkHost - Zookeeper Hostname - Default = localhost property file
- * value - zookeeper.host
- *
- * @return
- */
- public static String getMyZkHost() {
- return myZkHost;
- }
-
- /**
- * Set MyZkHost - Zookeeper Hostname
- *
- * @param myZkHost
- */
- public static void setMyZkHost(String myZkHost) {
- MusicUtil.myZkHost = myZkHost;
- }
-
- /**
- * Get MyCassHost - Cassandra Hostname - Default = localhost property file
- * value - cassandra.host
- *
- * @return
- */
- public static String getMyCassaHost() {
- return myCassaHost;
- }
-
- /**
- * Set MyCassHost - Cassandra Hostname
- *
- * @param myCassaHost
- */
- public static void setMyCassaHost(String myCassaHost) {
- MusicUtil.myCassaHost = myCassaHost;
- }
-
- /**
- * Get DefaultMusicIp - Default = localhost property file value - music.ip
- *
- * @return
- */
- public static String getDefaultMusicIp() {
- return defaultMusicIp;
- }
-
- /**
- * Set DefaultMusicIp
- *
- * @param defaultMusicIp
- */
- public static void setDefaultMusicIp(String defaultMusicIp) {
- MusicUtil.defaultMusicIp = defaultMusicIp;
- }
-
- /**
- *
- * @return
- */
- public static String getTestType() {
- String testType = "";
- try {
- Scanner fileScanner = new Scanner(new File(""));
- testType = fileScanner.next();// ignore the my id line
- String batchSize = fileScanner.next();// ignore the my public ip
- // line
- fileScanner.close();
- } catch (FileNotFoundException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
- return testType;
-
- }
-
- /**
- *
- * @param time
- */
- public static void sleep(long time) {
- try {
- Thread.sleep(time);
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
- }
-
- /**
- * Utility function to check if the query object is valid.
- *
- * @param withparams
- * @param queryObject
- * @return
- */
- public static boolean isValidQueryObject(boolean withparams, PreparedQueryObject queryObject) {
- if (withparams) {
- int noOfValues = queryObject.getValues().size();
- int noOfParams = 0;
- char[] temp = queryObject.getQuery().toCharArray();
- for (int i = 0; i < temp.length; i++) {
- if (temp[i] == '?')
- noOfParams++;
- }
- return (noOfValues == noOfParams);
- } else {
- return !queryObject.getQuery().isEmpty();
- }
-
- }
-
- public static void setCassName(String cassName) {
- MusicUtil.cassName = cassName;
- }
-
- public static void setCassPwd(String cassPwd) {
- MusicUtil.cassPwd = cassPwd;
- }
-
- public static String convertToCQLDataType(DataType type, Object valueObj) {
-
- String value = "";
- switch (type.getName()) {
- case UUID:
- value = valueObj + "";
- break;
- case TEXT:
- case VARCHAR:
- String valueString = valueObj + "";
- valueString = valueString.replace("'", "''");
- value = "'" + valueString + "'";
- break;
- case MAP: {
- Map<String, Object> otMap = (Map<String, Object>) valueObj;
- value = "{" + jsonMaptoSqlString(otMap, ",") + "}";
- break;
- }
- default:
- value = valueObj + "";
- break;
- }
- return value;
- }
-
- /**
- *
- * @param colType
- * @param valueObj
- * @return
- * @throws Exception
- */
- public static Object convertToActualDataType(DataType colType, Object valueObj) {
- String valueObjString = valueObj + "";
- switch (colType.getName()) {
- case UUID:
- return UUID.fromString(valueObjString);
- case VARINT:
- return BigInteger.valueOf(Long.parseLong(valueObjString));
- case BIGINT:
- return Long.parseLong(valueObjString);
- case INT:
- return Integer.parseInt(valueObjString);
- case FLOAT:
- return Float.parseFloat(valueObjString);
- case DOUBLE:
- return Double.parseDouble(valueObjString);
- case BOOLEAN:
- return Boolean.parseBoolean(valueObjString);
- case MAP:
- return (Map<String, Object>) valueObj;
- default:
- return valueObjString;
- }
- }
-
- /**
- *
- * Utility function to parse json map into sql like string
- *
- * @param jMap
- * @param lineDelimiter
- * @return
- */
-
- public static String jsonMaptoSqlString(Map<String, Object> jMap, String lineDelimiter) {
- StringBuilder sqlString = new StringBuilder();
- int counter = 0;
- for (Map.Entry<String, Object> entry : jMap.entrySet()) {
- Object ot = entry.getValue();
- String value = ot + "";
- if (ot instanceof String) {
- value = "'" + value.replace("'", "''") + "'";
- }
- sqlString.append("'" + entry.getKey() + "':" + value);
- if (counter != jMap.size() - 1)
- sqlString.append(lineDelimiter);
- counter = counter + 1;
- }
- 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;
- }
+ private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
+
+ public static final String ATOMIC = "atomic";
+ public static final String EVENTUAL = "eventual";
+ public static final String CRITICAL = "critical";
+ public static final String ATOMICDELETELOCK = "atomic_delete_lock";
+
+ public static final String DEFAULTKEYSPACENAME = "TBD";
+
+
+ private static int myId = 0;
+ private static ArrayList<String> allIds = new ArrayList<>();
+ private static String publicIp = "";
+ private static ArrayList<String> allPublicIps = new ArrayList<>();
+ private static String myZkHost = "localhost";
+ private static String myCassaHost = "localhost";
+ private static String defaultMusicIp = "localhost";
+ private static boolean debug = true;
+ private static String version = "2.3.0";
+ private static String musicRestIp = "localhost";
+ private static String musicPropertiesFilePath = "/opt/app/music/etc/music.properties";
+ private static long defaultLockLeasePeriod = 6000;
+ private static final String[] propKeys = new String[] { "zookeeper.host", "cassandra.host", "music.ip", "debug",
+ "version", "music.rest.ip", "music.properties", "lock.lease.period", "id", "all.ids", "public.ip",
+ "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url" };
+
+ private static String cassName = "cassandra";
+ private static String cassPwd;
+ private static String aafEndpointUrl = null;
+
+ private MusicUtil() {
+ throw new IllegalStateException("Utility Class");
+ }
+
+
+ /**
+ * @return the cassName
+ */
+ public static String getCassName() {
+ return cassName;
+ }
+
+ /**
+ * @return the cassPwd
+ */
+ public static String getCassPwd() {
+ return cassPwd;
+ }
+
+ /**
+ * @return the aafEndpointUrl
+ */
+ public static String getAafEndpointUrl() {
+ return aafEndpointUrl;
+ }
+
+ /**
+ *
+ * @param aafEndpointUrl
+ */
+ public static void setAafEndpointUrl(String aafEndpointUrl) {
+ MusicUtil.aafEndpointUrl = aafEndpointUrl;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static int getMyId() {
+ return myId;
+ }
+
+ /**
+ *
+ * @param myId
+ */
+ public static void setMyId(int myId) {
+ MusicUtil.myId = myId;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static List<String> getAllIds() {
+ return allIds;
+ }
+
+ /**
+ *
+ * @param allIds
+ */
+ public static void setAllIds(List<String> allIds) {
+ MusicUtil.allIds = (ArrayList<String>) allIds;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static String getPublicIp() {
+ return publicIp;
+ }
+
+ /**
+ *
+ * @param publicIp
+ */
+ public static void setPublicIp(String publicIp) {
+ MusicUtil.publicIp = publicIp;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static List<String> getAllPublicIps() {
+ return allPublicIps;
+ }
+
+ /**
+ *
+ * @param allPublicIps
+ */
+ public static void setAllPublicIps(List<String> allPublicIps) {
+ MusicUtil.allPublicIps = (ArrayList<String>) allPublicIps;
+ }
+
+ /**
+ * Returns An array of property names that should be in the Properties
+ * files.
+ *
+ * @return
+ */
+ public static String[] getPropkeys() {
+ return propKeys;
+ }
+
+ /**
+ * Get MusicRestIp - default = localhost property file value - music.rest.ip
+ *
+ * @return
+ */
+ public static String getMusicRestIp() {
+ return musicRestIp;
+ }
+
+ /**
+ * Set MusicRestIp
+ *
+ * @param musicRestIp
+ */
+ public static void setMusicRestIp(String musicRestIp) {
+ MusicUtil.musicRestIp = musicRestIp;
+ }
+
+ /**
+ * Get MusicPropertiesFilePath - Default = /opt/music/music.properties
+ * property file value - music.properties
+ *
+ * @return
+ */
+ public static String getMusicPropertiesFilePath() {
+ return musicPropertiesFilePath;
+ }
+
+ /**
+ * Set MusicPropertiesFilePath
+ *
+ * @param musicPropertiesFilePath
+ */
+ public static void setMusicPropertiesFilePath(String musicPropertiesFilePath) {
+ MusicUtil.musicPropertiesFilePath = musicPropertiesFilePath;
+ }
+
+ /**
+ * Get DefaultLockLeasePeriod - Default = 6000 property file value -
+ * lock.lease.period
+ *
+ * @return
+ */
+ public static long getDefaultLockLeasePeriod() {
+ return defaultLockLeasePeriod;
+ }
+
+ /**
+ * Set DefaultLockLeasePeriod
+ *
+ * @param defaultLockLeasePeriod
+ */
+ public static void setDefaultLockLeasePeriod(long defaultLockLeasePeriod) {
+ MusicUtil.defaultLockLeasePeriod = defaultLockLeasePeriod;
+ }
+
+ /**
+ * Set Debug
+ *
+ * @param debug
+ */
+ public static void setDebug(boolean debug) {
+ MusicUtil.debug = debug;
+ }
+
+ /**
+ * Is Debug - Default = true property file value - debug
+ *
+ * @return
+ */
+ public static boolean isDebug() {
+ return debug;
+ }
+
+ /**
+ * Set Version
+ *
+ * @param version
+ */
+ public static void setVersion(String version) {
+ MusicUtil.version = version;
+ }
+
+ /**
+ * Return the version property file value - version
+ *
+ * @return
+ */
+ public static String getVersion() {
+ return version;
+ }
+
+ /**
+ * Get MyZkHost - Zookeeper Hostname - Default = localhost property file
+ * value - zookeeper.host
+ *
+ * @return
+ */
+ public static String getMyZkHost() {
+ return myZkHost;
+ }
+
+ /**
+ * Set MyZkHost - Zookeeper Hostname
+ *
+ * @param myZkHost
+ */
+ public static void setMyZkHost(String myZkHost) {
+ MusicUtil.myZkHost = myZkHost;
+ }
+
+ /**
+ * Get MyCassHost - Cassandra Hostname - Default = localhost property file
+ * value - cassandra.host
+ *
+ * @return
+ */
+ public static String getMyCassaHost() {
+ return myCassaHost;
+ }
+
+ /**
+ * Set MyCassHost - Cassandra Hostname
+ *
+ * @param myCassaHost
+ */
+ public static void setMyCassaHost(String myCassaHost) {
+ MusicUtil.myCassaHost = myCassaHost;
+ }
+
+ /**
+ * Get DefaultMusicIp - Default = localhost property file value - music.ip
+ *
+ * @return
+ */
+ public static String getDefaultMusicIp() {
+ return defaultMusicIp;
+ }
+
+ /**
+ * Set DefaultMusicIp
+ *
+ * @param defaultMusicIp
+ */
+ public static void setDefaultMusicIp(String defaultMusicIp) {
+ MusicUtil.defaultMusicIp = defaultMusicIp;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public static String getTestType() {
+ String testType = "";
+ try {
+ Scanner fileScanner = new Scanner(new File(""));
+ testType = fileScanner.next();// ignore the my id line
+ String batchSize = fileScanner.next();// ignore the my public ip
+ // line
+ fileScanner.close();
+ } catch (FileNotFoundException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ }
+ return testType;
+
+ }
+
+ /**
+ *
+ * @param time
+ */
+ public static void sleep(long time) {
+ try {
+ Thread.sleep(time);
+ } catch (InterruptedException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ /**
+ * Utility function to check if the query object is valid.
+ *
+ * @param withparams
+ * @param queryObject
+ * @return
+ */
+ public static boolean isValidQueryObject(boolean withparams, PreparedQueryObject queryObject) {
+ if (withparams) {
+ int noOfValues = queryObject.getValues().size();
+ int noOfParams = 0;
+ char[] temp = queryObject.getQuery().toCharArray();
+ for (int i = 0; i < temp.length; i++) {
+ if (temp[i] == '?')
+ noOfParams++;
+ }
+ return (noOfValues == noOfParams);
+ } else {
+ return !queryObject.getQuery().isEmpty();
+ }
+
+ }
+
+ public static void setCassName(String cassName) {
+ MusicUtil.cassName = cassName;
+ }
+
+ public static void setCassPwd(String cassPwd) {
+ MusicUtil.cassPwd = cassPwd;
+ }
+
+ public static String convertToCQLDataType(DataType type, Object valueObj) throws Exception {
+
+ String value = "";
+ switch (type.getName()) {
+ case UUID:
+ value = valueObj + "";
+ break;
+ case TEXT:
+ case VARCHAR:
+ String valueString = valueObj + "";
+ valueString = valueString.replace("'", "''");
+ value = "'" + valueString + "'";
+ break;
+ case MAP: {
+ Map<String, Object> otMap = (Map<String, Object>) valueObj;
+ value = "{" + jsonMaptoSqlString(otMap, ",") + "}";
+ break;
+ }
+ default:
+ value = valueObj + "";
+ break;
+ }
+ return value;
+ }
+
+ /**
+ *
+ * @param colType
+ * @param valueObj
+ * @return
+ * @throws Exception
+ */
+ public static Object convertToActualDataType(DataType colType, Object valueObj) throws Exception{
+ String valueObjString = valueObj + "";
+ switch (colType.getName()) {
+ case UUID:
+ return UUID.fromString(valueObjString);
+ case VARINT:
+ return BigInteger.valueOf(Long.parseLong(valueObjString));
+ case BIGINT:
+ return Long.parseLong(valueObjString);
+ case INT:
+ return Integer.parseInt(valueObjString);
+ case FLOAT:
+ return Float.parseFloat(valueObjString);
+ case DOUBLE:
+ return Double.parseDouble(valueObjString);
+ case BOOLEAN:
+ return Boolean.parseBoolean(valueObjString);
+ case MAP:
+ return (Map<String, Object>) valueObj;
+ default:
+ return valueObjString;
+ }
+ }
+
+ /**
+ *
+ * Utility function to parse json map into sql like string
+ *
+ * @param jMap
+ * @param lineDelimiter
+ * @return
+ */
+
+ public static String jsonMaptoSqlString(Map<String, Object> jMap, String lineDelimiter) throws Exception{
+ StringBuilder sqlString = new StringBuilder();
+ int counter = 0;
+ for (Map.Entry<String, Object> entry : jMap.entrySet()) {
+ Object ot = entry.getValue();
+ String value = ot + "";
+ if (ot instanceof String) {
+ value = "'" + value.replace("'", "''") + "'";
+ }
+ sqlString.append("'" + entry.getKey() + "':" + value);
+ if (counter != jMap.size() - 1)
+ sqlString.append(lineDelimiter);
+ counter = counter + 1;
+ }
+ 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/PropertiesListener.java b/src/main/java/org/onap/music/main/PropertiesListener.java
index de231542..afd35387 100755
--- a/src/main/java/org/onap/music/main/PropertiesListener.java
+++ b/src/main/java/org/onap/music/main/PropertiesListener.java
@@ -32,6 +32,9 @@ import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
+import org.onap.music.eelf.logging.format.AppMessages;
+import org.onap.music.eelf.logging.format.ErrorSeverity;
+import org.onap.music.eelf.logging.format.ErrorTypes;
@WebListener
public class PropertiesListener implements ServletContextListener {
@@ -127,6 +130,7 @@ public class PropertiesListener implements ServletContextListener {
}
}
} catch (IOException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.IOERROR ,ErrorSeverity.CRITICAL, ErrorTypes.CONNECTIONERROR);
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
}
diff --git a/src/main/java/org/onap/music/main/ResultType.java b/src/main/java/org/onap/music/main/ResultType.java
index f19ada4a..6b0c5252 100644
--- a/src/main/java/org/onap/music/main/ResultType.java
+++ b/src/main/java/org/onap/music/main/ResultType.java
@@ -22,7 +22,8 @@
package org.onap.music.main;
public enum ResultType {
- SUCCESS("Success"), FAILURE("Failure");
+ SUCCESS("Success"), FAILURE("Failure"),
+ SYNTAXERROR("SyntaxError"), EXCEPTION("Exception");
private String result;