From 587e3d75c651f97b6e11cc61d7159e607c3f0f90 Mon Sep 17 00:00:00 2001 From: "Vikram Potturi(apotturi)" Date: Mon, 9 Apr 2018 16:47:50 -0400 Subject: Adding HEAT map information. Change-Id: I676137f72ab3cf451532c8f8fcfd032f83c31d5b Issue-ID: MUSIC-63 Signed-off-by: Vikram Potturi(apotturi) --- .../java/org/onap/music/lockingservice/MusicLockingService.java | 8 ++++++-- src/main/java/org/onap/music/main/MusicCore.java | 4 +++- src/main/java/org/onap/music/rest/RestMusicLocksAPI.java | 6 +++++- src/test/java/org/onap/music/unittests/TestMusicCore.java | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java index 44a00bcf..ae026903 100644 --- a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java +++ b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java @@ -133,8 +133,12 @@ public class MusicLockingService implements Watcher { zkLockHandle.unlock(lockId); } - public void deleteLock(String lockName) { - zkLockHandle.deleteLock(lockName); + public void deleteLock(String lockName) throws MusicLockingException { + if(lockIdExists(lockName)) + zkLockHandle.deleteLock(lockName); + else{ + throw new MusicLockingException("Lock does not exist.Please check the lock: " + lockName + " and try again"); + } } public String whoseTurnIsIt(String lockName) { diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java index d38a4d6a..dfc93ccc 100644 --- a/src/main/java/org/onap/music/main/MusicCore.java +++ b/src/main/java/org/onap/music/main/MusicCore.java @@ -518,14 +518,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"); diff --git a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java index 9189fbb3..22112ddf 100644 --- a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java @@ -412,7 +412,11 @@ public class RestMusicLocksAPI { logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR); return response.status(Status.BAD_REQUEST).entity(resultMap).build(); } - MusicCore.deleteLock(lockName); + try{ + MusicCore.deleteLock(lockName); + }catch (Exception e) { + return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build(); + } return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).toMap()).build(); } diff --git a/src/test/java/org/onap/music/unittests/TestMusicCore.java b/src/test/java/org/onap/music/unittests/TestMusicCore.java index 876c78b1..e798aaf1 100644 --- a/src/test/java/org/onap/music/unittests/TestMusicCore.java +++ b/src/test/java/org/onap/music/unittests/TestMusicCore.java @@ -257,7 +257,7 @@ public class TestMusicCore { } @Test - public void testDeleteLock() { + public void testDeleteLock() throws MusicLockingException { Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1"); MusicCore.deleteLock("id1"); Mockito.verify(mLockHandle).deleteLock("/" + "id1"); -- cgit 1.2.3-korg