Default action of AID(AuthID) was to allow only one keyspace.
HAS required the ability to create more than one.
Also included are some Logging and response fixes.
Change-Id: I30b7d0f5a5c6e535ff2b737dc58b8d4fbd427d02
Issue-ID: MUSIC-64, OPTFRA-191
Signed-off-by: Thomas Nelson Jr (arthurdent3) tn1381@att.com <tn1381@att.com>
<groupId>org.onap.music</groupId>
<artifactId>MUSIC</artifactId>
<packaging>war</packaging>
- <version>2.4.20</version>
+ <version>2.4.22</version>
<description>
This is the MUSIC REST interface, packaged as a war file.
</description>
private static CacheAccess<String, String> musicCache = JCS.getInstance("musicCache");
private static CacheAccess<String, Map<String, String>> aafCache = JCS.getInstance("aafCache");
private static CacheAccess<String, String> appNameCache = JCS.getInstance("appNameCache");
+ private static CacheAccess<String, Map<String, String>> musicValidateCache = JCS.getInstance("musicValidateCache");
private static Map<String, Number> userAttempts = new HashMap<>();
private static Map<String, Calendar> lastFailedTime = new HashMap<>();
map = new HashMap<>();
map.put(userId, password);
aafCache.put(nameSpace, map);
- musicCache.put(nameSpace, keySpace);
+ musicCache.put(keySpace, nameSpace);
logger.debug("Cronjob: Cache Updated with AAF response for namespace "
+ nameSpace);
}
String keySpace) throws Exception {
if (aafCache.get(nameSpace) != null) {
- if (keySpace != null && !musicCache.get(nameSpace).equals(keySpace)) {
+ 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)) {
logger.info(EELFLoggerDelegate.applicationLogger,"Authenticated with cache value..");
return responseObj;
}
- public static Map<String, Object> authenticateAIDUser(String aid, String keyspace)
- throws Exception {
- Map<String, Object> resultMap = new HashMap<>();
- String uuid = null;
- /*
- * if(aid == null || aid.length() == 0) { resultMap.put("Exception Message",
- * "AID is missing for the keyspace requested."); //create a new AID ?? } else
- */
- if (musicCache.get(keyspace) == null) {
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "SELECT uuid from admin.keyspace_master where keyspace_name = '"
- + keyspace + "' allow filtering");
- Row rs = MusicCore.get(pQuery).one();
- try {
- uuid = rs.getUUID("uuid").toString();
- musicCache.put(keyspace, uuid);
- } catch (Exception e) {
- String msg = 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."
- : msg));
- return resultMap;
- }
- if (!musicCache.get(keyspace).toString().equals(aid)) {
- resultMap.put("Exception",
- "Unauthorized operation. Invalid AID for the keyspace");
- return resultMap;
- }
- } else if (musicCache.get(keyspace) != null
- && !musicCache.get(keyspace).toString().equals(aid)) {
- resultMap.put("Exception Message",
- "Unauthorized operation. Invalid AID for the keyspace");
- return resultMap;
- }
- resultMap.put("aid", uuid);
- return resultMap;
+ public static void updateMusicCache(String keyspace, String nameSpace) {
+ logger.info(EELFLoggerDelegate.applicationLogger,"Updating musicCache for keyspace " + keyspace + " with nameSpace " + nameSpace);
+ musicCache.put(keyspace, nameSpace);
}
- public static void updateMusicCache(String aid, String keyspace) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Updating musicCache for keyspace " + keyspace + " with aid " + aid);
- musicCache.put(keyspace, aid);
+ public static void updateMusicValidateCache(String nameSpace, String userId, String password) {
+ logger.info(EELFLoggerDelegate.applicationLogger,"Updating musicCache for nameSpacce " + nameSpace + " with userId " + userId);
+ Map<String, String> map = new HashMap<>();
+ map.put(userId, password);
+ musicValidateCache.put(nameSpace, map);
}
-
+
public static void updateisAAFCache(String namespace, String isAAF) {
appNameCache.put(namespace, isAAF);
}
}
public static String getUuidFromMusicCache(String keyspace) throws MusicServiceException {
- String uuid = musicCache.get(keyspace);
+ String uuid = null;
if (uuid == null) {
PreparedQueryObject pQuery = new PreparedQueryObject();
pQuery.appendQueryString(
Row rs = MusicCore.get(pQuery).one();
try {
uuid = rs.getUUID("uuid").toString();
- musicCache.put(keyspace, uuid);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,"Exception occured during uuid retrieval from DB."+e.getMessage());
e.printStackTrace();
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"))) {
+ 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.");
- }
+ }
+ return resultMap;
+ }
+
+ public static Map<String, Object> authenticateAIDUser(String nameSpace, String userId, String password,
+ String keyspace) {
+ Map<String, Object> resultMap = new HashMap<>();
+ if((musicCache.get(keyspace) != null) && (musicValidateCache.get(nameSpace) != null)
+ && (musicValidateCache.get(nameSpace).containsKey(userId))) {
+ if(!musicCache.get(keyspace).equals(nameSpace)) {
+ resultMap.put("Exception", "Namespace and keyspace doesn't match");
+ return resultMap;
+ }
+ if(!musicValidateCache.get(nameSpace).get(userId).equals(password)) {
+ resultMap.put("Exception", "Namespace, userId and password doesn't match");
+ return resultMap;
+ }
+ return resultMap;
+ }
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "select * from admin.keyspace_master where keyspace_name = ? allow filtering");
+ try {
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspace));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ Row rs = null;
+ try {
+ rs = MusicCore.get(queryObject).one();
+ } catch (MusicServiceException e) {
+ e.printStackTrace();
+ resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
+ return resultMap;
+ }
+ if(rs == null) {
+ resultMap.put("Exception", "Please make sure keyspace:"+keyspace+" exists.");
+ return resultMap;
+ }
+ else {
+ String user = rs.getString("username");
+ String pwd = rs.getString("password");
+ String ns = rs.getString("application_name");
+ if(!ns.equals(nameSpace)) {
+ resultMap.put("Exception", "Namespace and keyspace doesn't match");
+ return resultMap;
+ }
+ if(!user.equals(userId)) {
+ resultMap.put("Exception", "Invalid userId :"+userId);
+ return resultMap;
+ }
+ if(!pwd.equals(password)) {
+ resultMap.put("Exception", "Invalid password");
+ return resultMap;
}
}
+ CachingUtil.updateMusicCache(keyspace, nameSpace);
+ CachingUtil.updateMusicValidateCache(nameSpace, userId, password);
return resultMap;
}
}
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 {
if (!rs.all().isEmpty()) {
resultMap.put("Exception", "Application " + appName
+ " has already been onboarded. Please contact admin.");
+ response.setStatus(400);
return resultMap;
}
if (returnStr.contains("Failure")) {
resultMap.put("Exception",
"Oops. Something wrong with onboarding process. Please retry later or contact admin.");
+ response.setStatus(400);
return resultMap;
}
CachingUtil.updateisAAFCache(appName, isAAF);
resultMap.put( row.getUUID("uuid").toString(),row.getString("keyspace_name"));
}
if (resultMap.isEmpty()) {
- if(uuid != null)
+ if(uuid != null) {
resultMap.put("Exception", "Please make sure Aid is correct and application is onboarded.");
- else {
+ response.setStatus(400);
+ return resultMap;
+ }else {
resultMap.put("Exception",
"Application is not onboarded. Please make sure all the information is correct.");
+ response.setStatus(400);
+ return resultMap;
}
}
return resultMap;
if (result==ResultType.SUCCESS) {
resultMap.put("Success", "Your application has been deleted successfully");
} else {
- resultMap.put("Exception","Oops. Spomething went wrong. Please make sure Aid is correct or Application is onboarded");
+ resultMap.put("Exception","Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded");
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
response.setStatus(400);
return resultMap;
resultMap.put("Failure", "More than one Aid exists for this application, so please provide Aid.");
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MULTIPLERECORDS ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
response.setStatus(400);
+ return resultMap;
}
-
- return resultMap;
}
resultMap.put("Success", "Your application has been updated successfully");
} else {
resultMap.put("Exception",
- "Oops. Spomething went wrong. Please make sure Aid is correct and application is onboarded");
+ "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded");
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
response.setStatus(400);
+ return resultMap;
}
return resultMap;
Map<String, Object> authMap = CachingUtil.verifyOnboarding(ns, userId, password);
response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (!authMap.isEmpty()) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
}
if(kspObject == null || kspObject.getReplicationInfo() == null) {
authMap.put(ResultType.EXCEPTION.getResult(), ResultType.BODYMISSING.getResult());
+ response.setStatus(401);
return authMap;
}
authMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
"createKeySpace");
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.applicationLogger,
- "Exception while authenting the user.");
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("Unable to authenticate.").toMap();
}
String newAid = null;
if (authMap.containsKey("aid")) {
newAid = (String) authMap.get("aid");
} else {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
}
}
try {
repString = "{" + MusicUtil.jsonMaptoSqlString(replicationInfo, ",") + "}";
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+
}
queryObject.appendQueryString(
"CREATE KEYSPACE " + keyspaceName + " WITH replication = " + repString);
ResultType result = ResultType.FAILURE;
try {
result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
- logger.error(EELFLoggerDelegate.errorLogger, "result = " + result);
+ logger.info(EELFLoggerDelegate.applicationLogger, "result = " + result);
} catch ( MusicServiceException ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(newAid, keyspaceName);
+ CachingUtil.updateMusicCache(keyspaceName, ns);
+ CachingUtil.updateMusicValidateCache(ns, userId, password);
MusicCore.eventualPut(queryObject);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
}
@DELETE
@Path("/{name}")
@ApiOperation(value = "Delete Keyspace", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> dropKeySpace(
@ApiParam(value = "Major Version",
required = true) @HeaderParam("userId") String userId,
@ApiParam(value = "Password",
required = true) @HeaderParam("password") String password,
- JsonKeySpace kspObject,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("name") String keyspaceName,
@Context HttpServletResponse response) throws Exception {
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
+ response.setStatus(401);
return authMap;
}
long count = row.getLong(0);
if (count == 0) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("Keyspace not found. Please make sure keyspace exists.").toMap();
} else if (count == 1) {
pQuery = new PreparedQueryObject();
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
}
String consistency = MusicUtil.EVENTUAL;
try {
result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
} catch (MusicServiceException ex) {
- response.setStatus(400);
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.MUSICSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
authMap.remove("aid");
- if (!authMap.isEmpty())
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ if (!authMap.isEmpty()) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
+ return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ }
MultivaluedMap<String, String> rowParams = info.getQueryParameters();
String indexName = "";
if (rowParams.getFirst("index_name") != null)
try {
result = MusicCore.nonKeyRelatedPut(query, "eventual");
} catch (MusicServiceException ex) {
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "insertIntoTable");
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
}
response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
+ return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
}
Map<String, Object> valuesMap = insObj.getValues();
.setError("Table name doesn't exists. Please check the table name.").toMap();
}
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
}
String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();
try {
colType = tableInfo.getColumn(entry.getKey()).getType();
} catch(NullPointerException ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "Invalid column name : "+entry.getKey());
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() +" Invalid column name : "+entry.getKey(), AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap();
}
if(primaryKey == null || primaryKey.length() <= 0) {
logger.error(EELFLoggerDelegate.errorLogger, "Some required partition key parts are missing: "+primaryKeyName );
+ response.setStatus(400);
return new JsonResponse(ResultType.SYNTAXERROR).setError("Some required partition key parts are missing: "+primaryKeyName).toMap();
}
}
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
if (result==null) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap();
}
return new JsonResponse(result.getResult()).toMap();
authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "updateTable");
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
}
response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
}
long startTime = System.currentTimeMillis();
try {
tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
}
if (tableInfo == null) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE)
.setError("Table information not found. Please check input for table name= "
+ keyspace + "." + tablename).toMap();
colType = tableInfo.getColumn(entry.getKey()).getType();
} catch(NullPointerException ex) {
logger.error(EELFLoggerDelegate.errorLogger, "Invalid column name : "+entry.getKey());
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap();
}
Object valueString = null;
.setError("Mandatory WHERE clause is missing. Please check the input request.").toMap();
}
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
if(lockId == null) {
logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+ " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
}
operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
rowId.primarKeyValue, queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
}
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
}
}
logger.info(EELFLoggerDelegate.applicationLogger, timingString);
if (operationResult==null) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap();
}
return new JsonResponse(operationResult.getResult()).toMap();
authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "deleteFromTable");
} catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
}
response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
}
if(delObj == null) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("Required HTTP Request body is missing.").toMap();
}
PreparedQueryObject queryObject = new PreparedQueryObject();
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
String rowSpec = rowId.rowIdString.toString();
if(lockId == null) {
logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+ " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
}
queryObject, conditionInfo);
}
} catch (MusicLockingException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE)
.setError("Unable to perform Delete operation. Exception from music").toMap();
}
if (operationResult.getResult().equals(ResultType.FAILURE)) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(operationResult.getMessage()).toMap();
}
return new JsonResponse(operationResult.getResult()).toMap();
@DELETE
@Path("/{keyspace}/tables/{tablename}")
@ApiOperation(value = "Drop Table", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> dropTable(
@ApiParam(value = "Major Version",
required = true) @HeaderParam("userId") String userId,
@ApiParam(value = "Password",
required = true) @HeaderParam("password") String password,
- JsonTable tabObj,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
}
String consistency = "eventual";// for now this needs only eventual
try {
return new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency)).toMap();
} catch (MusicServiceException ex) {
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error("Error while authentication... ");
+ logger.error(EELFLoggerDelegate.errorLogger,"Error while authentication... ", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
}
String lockId = selObj.getConsistencyInfo().get("lockId");
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
queryObject.appendQueryString(
if(lockId == null) {
logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+ " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
}
authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
}
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject = selectSpecificQuery(version, minorVersion, patchVersion, aid, ns,
userId, password, keyspace, tablename, info, limit);
} catch (MusicServiceException ex) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
}
return new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap();
} catch (MusicServiceException ex) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
+ response.setStatus(400);
return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
}
response.addHeader(xLatestVersion,MusicUtil.getVersion());
Map<String, Object> resultMap = MusicCore.validateLock(lockName);
if (resultMap.containsKey("Exception")) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return resultMap;
}
String keyspaceName = (String) resultMap.get("keyspace");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.setStatus(401);
+ return resultMap;
}
ResultType status = ResultType.SUCCESS;
String lockId = MusicCore.createLockReference(lockName);
if (lockId == null) {
status = ResultType.FAILURE;
- response.setStatus(400);
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.LOCKINGERROR ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ response.setStatus(400);
+ return new JsonResponse(status).setError("Lock Id is null").toMap();
}
return new JsonResponse(status).setLock(lockId).toMap();
}
response.addHeader(xLatestVersion,MusicUtil.getVersion());
Map<String, Object> resultMap = MusicCore.validateLock(lockId);
if (resultMap.containsKey("Exception")) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return resultMap;
}
String keyspaceName = (String) resultMap.get("keyspace");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
+ return resultMap;
}
try {
String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
response.addHeader(xLatestVersion,MusicUtil.getVersion());
Map<String, Object> resultMap = MusicCore.validateLock(lockId);
if (resultMap.containsKey("Exception")) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return resultMap;
}
String keyspaceName = (String) resultMap.get("keyspace");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
response.setStatus(400);
return resultMap;
}
response.addHeader(xLatestVersion,MusicUtil.getVersion());
Map<String, Object> resultMap = MusicCore.validateLock(lockName);
if (resultMap.containsKey("Exception")) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return resultMap;
}
String keyspaceName = (String) resultMap.get("keyspace");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
+ return resultMap;
}
String who = MusicCore.whoseTurnIsIt(lockName);
ResultType status = ResultType.SUCCESS;
if ( who == null ) {
status = ResultType.FAILURE;
error = "There was a problem getting the lock holder";
- response.setStatus(400);
+ logger.error(EELFLoggerDelegate.errorLogger,"There was a problem getting the lock holder", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
+ return new JsonResponse(status).setError(error)
+ .setLock(lockName).setLockHolder(who).toMap();
}
return new JsonResponse(status).setError(error)
.setLock(lockName).setLockHolder(who).toMap();
response.addHeader(xLatestVersion,MusicUtil.getVersion());
Map<String, Object> resultMap = MusicCore.validateLock(lockName);
if (resultMap.containsKey("Exception")) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return resultMap;
}
String keyspaceName = (String) resultMap.get("keyspace");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
+ return resultMap;
}
MusicLockState mls = MusicCore.getMusicLockState(lockName);
if(mls == null) {
jsonResponse.setError("");
jsonResponse.setMessage("No lock object created yet..");
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
+ return jsonResponse.toMap();
} else {
jsonResponse.setStatus(ResultType.SUCCESS);
jsonResponse.setLockStatus(mls.getLockStatus());
jsonResponse.setLockHolder(mls.getLockHolder());
+ return jsonResponse.toMap();
}
- return jsonResponse.toMap();
}
/**
response.addHeader(xLatestVersion,MusicUtil.getVersion());
Map<String, Object> resultMap = MusicCore.validateLock(lockId);
if (resultMap.containsKey("Exception")) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return resultMap;
}
String keyspaceName = (String) resultMap.get("keyspace");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- response.setStatus(400);
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return resultMap;
}
boolean voluntaryRelease = true;
MusicLockState mls = MusicCore.releaseLock(lockId,voluntaryRelease);
if(mls.getErrorMessage() != null) {
resultMap.put(ResultType.EXCEPTION.getResult(), mls.getErrorMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return resultMap;
}
Map<String,Object> returnMap = null;
.setLockStatus(mls.getLockStatus()).toMap();
}
if (mls.getLockStatus() == MusicLockState.LockStatus.LOCKED) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.LOCKINGERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
returnMap = new JsonResponse(ResultType.FAILURE).setLock(lockId)
.setLockStatus(mls.getLockStatus()).toMap();
}
response.addHeader(xLatestVersion,MusicUtil.getVersion());
Map<String, Object> resultMap = MusicCore.validateLock(lockName);
if (resultMap.containsKey("Exception")) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
return resultMap;
}
String keyspaceName = (String) resultMap.get("keyspace");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.setStatus(400);
+ return resultMap;
}
MusicCore.deleteLock(lockName);
return new JsonResponse(ResultType.SUCCESS).toMap();
@ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
@ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
@Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().dropTable(version,minorVersion,patchVersion,aid, ns, userId, password, tabObj, keyspace, tablename,response);
+ return new RestMusicDataAPI().dropTable(version,minorVersion,patchVersion,aid, ns, userId, password, keyspace, tablename,response);
}
}
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Map<String, Object> resultMap = data.dropTable("1", "1", "1",
"abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- jsonTable, keyspaceName, tableName, http);
+ keyspaceName, tableName, http);
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
jsonKeyspace.setReplicationInfo(replicationInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Map<String, Object> resultMap = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, userId, password, jsonKeyspace, keyspaceName, http);
+ appName, userId, password, keyspaceName, http);
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
@Test
public void Test3_createLockReference() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = lock.createLockReference(lockName, uuid.toString(), appName, null, null, http);
+ Map<String, Object> resultMap = lock.createLockReference(lockName, null, appName, userId, password, http);
@SuppressWarnings("unchecked")
Map<String, Object> resultMap1 = (Map<String, Object>) resultMap.get("lock");
lockId = (String) resultMap1.get("lock");
@Test
public void Test4_accquireLock() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = lock.accquireLock(lockId, uuid.toString(), appName, null, null, http);
+ Map<String, Object> resultMap = lock.accquireLock(lockId, null, appName, userId, password, http);
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
@Test
public void Test5_currentLockHolder() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = lock.currentLockHolder(lockName, uuid.toString(), appName, null, null, http);
+ Map<String, Object> resultMap = lock.currentLockHolder(lockName, null, appName, userId, password, http);
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
@Test
public void Test7_unLock() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = lock.unLock(lockId, uuid.toString(), appName, null, null, http);
+ Map<String, Object> resultMap = lock.unLock(lockId, null, appName, userId, password, http);
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
@Test
public void Test8_delete() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = lock.deleteLock(lockName, uuid.toString(), appName, null, null, http);
+ Map<String, Object> resultMap = lock.deleteLock(lockName, null, appName, userId, password, http);
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
}
\ No newline at end of file
major=2
minor=4
-patch=20
+patch=22
base_version=${major}.${minor}.${patch}