public boolean testCondition() throws Exception {
// first generate the row
ResultSet results = quorumGet(selectQueryForTheRow);
- Row row = results.one();
+ Row row = null;
+ if(results != null) {
+ row = results.one();
+ }
return getDSHandle().doesRowSatisfyCondition(row, conditions);
}
}
long start = System.currentTimeMillis();
if (mDstoreHandle == null) {
// Quick Fix - Best to put this into every call to getDSHandle?
- if (! MusicUtil.getMyCassaHost().equals("localhost") ) {
+ if (! "localhost".equals(MusicUtil.getMyCassaHost())) {
mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
} else {
mDstoreHandle = new MusicDataStore();
MusicLockState newMls = null;
try {
currentMls = getMusicLockState(key);
- String currentLockHolder = currentMls.getLockHolder();
+ String currentLockHolder = null;
+ if(currentMls != null) { currentLockHolder = currentMls.getLockHolder(); };
if (lockId.equals(currentLockHolder)) {
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: You already have the lock!");
return new ReturnType(ResultType.SUCCESS, "You already have the lock!");
/**
*
* @param lockName
+ * @throws MusicLockingException
*/
- public static void deleteLock(String lockName) {
+ public static void deleteLock(String lockName) throws MusicLockingException {
long start = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Deleting lock for " + lockName);
try {
getLockingServiceHandle().deleteLock("/" + lockName);
} catch (MusicLockingException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DELTELOCK+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ throw new MusicLockingException(e.getMessage());
}
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to delete lock:" + (end - start) + " ms");
}
return results;
}
+
+ public static String getMyHostId() {
+ PreparedQueryObject pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString("SELECT HOST_ID FROM SYSTEM.LOCAL");
+ ResultSet rs = null;
+ try {
+ rs = getDSHandle().executeEventualGet(pQuery);
+ Row row = rs.one();
+ return (row == null) ? "UNKNOWN" : row.getUUID("HOST_ID").toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ }
+ logger.error(EELFLoggerDelegate.errorLogger, "Some issue during MusicCore.getMyHostId");
+ return "UNKNOW";
+ }
/**
* This method performs DDL operations on cassandra, if the the resource is available. Lock ID
operation);
if (!resultMap.isEmpty())
return resultMap;
- boolean isAAF = CachingUtil.isAAFApplication(nameSpace);
- 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;
+ String isAAFApp = null;
+ try {
+ isAAFApp= CachingUtil.isAAFApplication(nameSpace);
+ } catch(MusicServiceException e) {
+ resultMap.put("Exception", e.getMessage());
+ return resultMap;
+ }
+ if(isAAFApp == null) {
+ resultMap.put("Exception", "Namespace: "+nameSpace+" doesn't exist. Please make sure ns(appName)"
+ + " is correct and Application is onboarded.");
+ return resultMap;
}
- if (aid == null && (userId == null || password == null)) {
+ boolean isAAF = Boolean.valueOf(isAAFApp);
+ 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 {
uuid = CachingUtil.generateUUID();
resultMap.put("uuid", "new");
}
-
- pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspace));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), nameSpace));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- 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);
- MusicCore.eventualPut(pQuery);
resultMap.put("aid", uuid);
}