summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorr.bogacki <r.bogacki@samsung.com>2019-02-12 10:19:11 +0100
committerRobert Bogacki <r.bogacki@samsung.com>2019-02-13 14:09:49 +0000
commit8b580939e18d541c89b32256d99dc08aecae7809 (patch)
tree4c8c5977ae451ad8f7d068a0f8db957298ab5df5
parent3b8e0a333bb754117f41e7206a6706bad66829fb (diff)
Fixed Sonar issues in ZkStatelessLockService
Fixed potential NullPointerException. Added restoring of the interrupted state. Removed unnecessary imports. Added missing loggers. Change-Id: I62bb8ef2b4893c60c1cea7dcd4ba29f2908b4d05 Issue-ID: MUSIC-329 Signed-off-by: Robert Bogacki <r.bogacki@samsung.com>
-rw-r--r--src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java b/src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java
index 38c4726f..e8ed257a 100644
--- a/src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java
+++ b/src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java
@@ -3,7 +3,8 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
- * Modifications Copyright (c) 2018 IBM.
+ * Modifications Copyright (c) 2018 IBM.
+ * Modifications Copyright (c) 2019 Samsung.
* ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
@@ -39,7 +40,6 @@ import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
-import org.onap.music.service.impl.MusicZKCore;
import com.datastax.driver.core.DataType;
@@ -127,6 +127,7 @@ public class ZkStatelessLockService extends ProtocolSupport {
}
}catch (InterruptedException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
+ Thread.currentThread().interrupt();
}catch (KeeperException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
}
@@ -144,6 +145,7 @@ public class ZkStatelessLockService extends ProtocolSupport {
retryOperation(zop);
}catch (InterruptedException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
+ Thread.currentThread().interrupt();
}catch (KeeperException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
}
@@ -303,20 +305,26 @@ public class ZkStatelessLockService extends ProtocolSupport {
Stat stat = null;
try {
stat = zookeeper.exists(id, false);
- } catch (KeeperException | InterruptedException e1) {
- e1.printStackTrace();
+ } catch (InterruptedException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
+ Thread.currentThread().interrupt();
+ } catch (KeeperException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
}
- Long ctime = stat.getCtime();
- MusicUtil.zkNodeMap.put(id, ctime);
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "INSERT INTO admin.locks(lock_id, ctime) VALUES (?,?)");
- try {
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), id));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), ctime));
- MusicCore.eventualPut(pQuery);
- } catch (Exception e) {
- e.printStackTrace();
+
+ if (stat != null){
+ Long ctime = stat.getCtime();
+ MusicUtil.zkNodeMap.put(id, ctime);
+ PreparedQueryObject pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString(
+ "INSERT INTO admin.locks(lock_id, ctime) VALUES (?,?)");
+ try {
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), id));
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), ctime));
+ MusicCore.eventualPut(pQuery);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.UNKNOWN);
+ }
}
break;
}