From b1dc42528a3e7e89187fac220a2f9be3e4151caf Mon Sep 17 00:00:00 2001 From: "Vikram Potturi(apotturi)" Date: Mon, 21 May 2018 20:06:08 -0400 Subject: Added changes for Zookeeper node healthcheck Change-Id: Ib25342cebfc95a217dedc2588f2fb1284b1ef03f Issue-ID: MUSIC-73 Signed-off-by: Vikram Potturi(apotturi) --- jar/pom.xml | 2 +- .../onap/music/lockingservice/MusicLockingService.java | 18 ++++++++++++++++++ jar/src/main/webapp/WEB-INF/classes/project.properties | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/jar/pom.xml b/jar/pom.xml index d2d74523..6627b002 100644 --- a/jar/pom.xml +++ b/jar/pom.xml @@ -25,7 +25,7 @@ org.onap.music MUSIC jar - 2.5.5 + 2.5.6 This is the MUSIC interface, packaged as a jar file. diff --git a/jar/src/main/java/org/onap/music/lockingservice/MusicLockingService.java b/jar/src/main/java/org/onap/music/lockingservice/MusicLockingService.java index ae026903..29f23158 100644 --- a/jar/src/main/java/org/onap/music/lockingservice/MusicLockingService.java +++ b/jar/src/main/java/org/onap/music/lockingservice/MusicLockingService.java @@ -34,6 +34,7 @@ import org.onap.music.eelf.logging.format.ErrorTypes; import org.onap.music.exceptions.MusicLockingException; import org.onap.music.exceptions.MusicServiceException; import org.onap.music.main.MusicUtil; +import java.util.concurrent.TimeUnit; public class MusicLockingService implements Watcher { @@ -76,6 +77,23 @@ public class MusicLockingService implements Watcher { logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); } } + + public MusicLockingService(int timeout) throws MusicServiceException { + CountDownLatch connectedSignal1 = new CountDownLatch(1); + try { + ZooKeeper zk1 = new ZooKeeper(MusicUtil.getMyZkHost(), SESSION_TIMEOUT, this); + connectedSignal1.await(timeout, TimeUnit.SECONDS); + if(!zk1.getState().isConnected()) { + throw new MusicServiceException("Unable to Connect. Some nodes are down."); + } + } catch (IOException 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(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR); + throw new MusicServiceException("Exception Occured " + e.getMessage()); + } + } public void createLockaIfItDoesNotExist(String lockName) { if (!zkLockHandle.checkIfLockExists(lockName)) { diff --git a/jar/src/main/webapp/WEB-INF/classes/project.properties b/jar/src/main/webapp/WEB-INF/classes/project.properties index 3b6d2283..cb51134a 100644 --- a/jar/src/main/webapp/WEB-INF/classes/project.properties +++ b/jar/src/main/webapp/WEB-INF/classes/project.properties @@ -1,4 +1,4 @@ -version=2.5.3 +version=2.5.5 artifactId=MUSIC music.properties=/opt/app/music/etc/music.properties -- cgit 1.2.3-korg