From 458f4be403cea7ae9091cd4ba9bd432c2c941ed8 Mon Sep 17 00:00:00 2001 From: Arundathi Patil Date: Tue, 13 Nov 2018 17:45:43 +0530 Subject: Sonar Fix: MusicLockingService Fixed sonar issues/code-smells across this file Issue-ID: MUSIC-178 Change-Id: Iea3dd8daef36ed0ac2f368671e3530cc5962d870 Signed-off-by: Arundathi Patil --- .../music/lockingservice/MusicLockingService.java | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java index f9c09338..097055ba 100644 --- a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java +++ b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java @@ -52,30 +52,35 @@ public class MusicLockingService implements Watcher { connectedSignal.await(); zkLockHandle = new ZkStatelessLockService(zk); } catch (IOException e) { + logger.error("Error", e); logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR); throw new MusicServiceException("IO Error has occured" + e.getMessage()); } catch (InterruptedException e) { + logger.error("Error", e); logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); throw new MusicServiceException("Exception Occured " + e.getMessage()); } } - public ZkStatelessLockService getzkLockHandle() { - return zkLockHandle; - } - public MusicLockingService(String lockServer) { try { ZooKeeper zk = new ZooKeeper(lockServer, SESSION_TIMEOUT, this); connectedSignal.await(); zkLockHandle = new ZkStatelessLockService(zk); } catch (IOException e) { - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR); + logger.error("Error", e); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR); }catch( InterruptedException e) { - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); - }catch(Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); - } + logger.error("Error", e); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); + }catch(Exception e) { + logger.error("Error", e); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); + } + } + + public ZkStatelessLockService getzkLockHandle() { + return zkLockHandle; } public void createLockaIfItDoesNotExist(String lockName) { @@ -98,6 +103,7 @@ public class MusicLockingService implements Watcher { try{ data = zkLockHandle.getNodeData(lockName); }catch (Exception ex){ + logger.error("Error", ex); logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); } if(data !=null) @@ -120,10 +126,13 @@ public class MusicLockingService implements Watcher { try { return zkLockHandle.lock(lockName, lockId); } catch (KeeperException e) { + logger.error("Error", e); logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.LOCKINGERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); }catch( InterruptedException e) { + logger.error("Error", e); logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); }catch(Exception e) { + logger.error("Error", e); logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); } return false; -- cgit 1.2.3-korg