diff options
author | Thomas Nelson <nelson24@att.com> | 2019-02-14 17:14:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-02-14 17:14:51 +0000 |
commit | 4771ff0c0b5b68209e29bec88a0b2e566ef50834 (patch) | |
tree | 58161acbcfdd12401a5dbc505e8ae5cbbb48f079 | |
parent | c91215965fa4d6f19441fa96fd5c3b5910795057 (diff) | |
parent | 8b580939e18d541c89b32256d99dc08aecae7809 (diff) |
Merge "Fixed Sonar issues in ZkStatelessLockService"
-rw-r--r-- | src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java | 38 |
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; } |