X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fmusic%2Fmain%2FMusicCore.java;h=98696babfdfb486858d58c9daea609aaa1046ab7;hb=c83eecde0e1caf1d25abb01960aab0b6dbe855bf;hp=abeedf6ff6f152ed912348e82cf1314e5e10c80d;hpb=de47cea9e656dabfbf3608287238041ab263f05e;p=music.git diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java index abeedf6f..98696bab 100644 --- a/src/main/java/org/onap/music/main/MusicCore.java +++ b/src/main/java/org/onap/music/main/MusicCore.java @@ -73,7 +73,10 @@ public class MusicCore { 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); } } @@ -122,7 +125,7 @@ public class MusicCore { 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(); @@ -186,7 +189,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,e.getMessage(), AppMessages.INVALIDLOCK,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR); + logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.INVALIDLOCK,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR); } return null; } @@ -210,9 +213,9 @@ public class MusicCore { mls = releaseLock(currentLockHolder, voluntaryRelease); } } - } else + } else { 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 @@ -288,7 +291,8 @@ public class MusicCore { 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!"); @@ -518,14 +522,16 @@ public class MusicCore { /** * * @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"); @@ -706,6 +712,22 @@ public class MusicCore { } 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 @@ -890,7 +912,13 @@ public class MusicCore { operation); if (!resultMap.isEmpty()) return resultMap; - String isAAFApp = CachingUtil.isAAFApplication(nameSpace); + 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.");