aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/music/lockingservice/MusicLockingService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/music/lockingservice/MusicLockingService.java')
-rw-r--r--src/main/java/org/onap/music/lockingservice/MusicLockingService.java39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java
index 9b21f596..2fc8a151 100644
--- a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java
+++ b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java
@@ -28,6 +28,9 @@ import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
+import org.onap.music.eelf.logging.format.AppMessages;
+import org.onap.music.eelf.logging.format.ErrorSeverity;
+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;
@@ -35,7 +38,7 @@ import org.onap.music.main.MusicUtil;
public class MusicLockingService implements Watcher {
-
+
private static final int SESSION_TIMEOUT = 180000;
ZkStatelessLockService zkLockHandle = null;
private CountDownLatch connectedSignal = new CountDownLatch(1);
@@ -48,10 +51,10 @@ public class MusicLockingService implements Watcher {
connectedSignal.await();
zkLockHandle = new ZkStatelessLockService(zk);
} catch (IOException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ 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());
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
throw new MusicServiceException("Exception Occured " + e.getMessage());
}
}
@@ -65,13 +68,17 @@ public class MusicLockingService implements Watcher {
ZooKeeper zk = new ZooKeeper(lockServer, SESSION_TIMEOUT, this);
connectedSignal.await();
zkLockHandle = new ZkStatelessLockService(zk);
- } catch (IOException | InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
+ } catch (IOException 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);
+ }
}
public void createLockaIfItDoesNotExist(String lockName) {
- if (zkLockHandle.checkIfLockExists(lockName) == false) {
+ if (!zkLockHandle.checkIfLockExists(lockName)) {
String lockHolder = null;
MusicLockState ml = new MusicLockState(MusicLockState.LockStatus.UNLOCKED, lockHolder);
byte[] data = ml.serialize();
@@ -90,12 +97,14 @@ public class MusicLockingService implements Watcher {
try{
data = zkLockHandle.getNodeData(lockName);
}catch (Exception ex){
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
}
if(data !=null)
return MusicLockState.deSerialize(data);
- else
- throw new MusicLockingException("Invalid lock or acquire failed");
+ else {
+ logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.INVALIDLOCK, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
+ throw new MusicLockingException("Invalid lock or acquire failed");
+ }
}
public String createLockId(String lockName) {
@@ -109,9 +118,13 @@ public class MusicLockingService implements Watcher {
String lockName = "/" + st.nextToken("/");
try {
return zkLockHandle.lock(lockName, lockId);
- } catch (KeeperException | InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
+ } catch (KeeperException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.LOCKINGERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
+ }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);
+ }
return false;
}