From 3acbae6bf3be04f352bfaac340b8303064a2f7c4 Mon Sep 17 00:00:00 2001 From: "Thomas Nelson Jr (arthurdent3)" Date: Tue, 20 Feb 2018 16:50:44 -0500 Subject: Applying bug fixes To many overlapping changes so including all of them. When pushing individually build was breaking. Issue-ID: MUSIC-33,MUSIC-34,MUSIC-35,MUSIC-36,MUSIC-37 Change-Id: I15b6f7c683d0d2eeadd99c2376dedd6c43a67a8c Signed-off-by: Thomas Nelson Jr (arthurdent3) --- .../onap/music/lockingservice/MusicLockState.java | 10 ++- .../music/lockingservice/MusicLockingService.java | 67 ++++++++++-------- .../onap/music/lockingservice/ProtocolSupport.java | 11 +-- .../org/onap/music/lockingservice/ZNodeName.java | 11 ++- .../lockingservice/ZkStatelessLockService.java | 82 ++++++++++------------ 5 files changed, 88 insertions(+), 93 deletions(-) (limited to 'src/main/java/org/onap/music/lockingservice') diff --git a/src/main/java/org/onap/music/lockingservice/MusicLockState.java b/src/main/java/org/onap/music/lockingservice/MusicLockState.java index 23661ad4..10cdc0e7 100644 --- a/src/main/java/org/onap/music/lockingservice/MusicLockState.java +++ b/src/main/java/org/onap/music/lockingservice/MusicLockState.java @@ -29,9 +29,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.Serializable; -import org.onap.music.main.MusicCore; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.onap.music.eelf.logging.EELFLoggerDelegate; // the state variable that will be stored in zookeeper, capturing the transitions of public class MusicLockState implements Serializable { @@ -39,7 +37,7 @@ public class MusicLockState implements Serializable { UNLOCKED, BEING_LOCKED, LOCKED };// captures the state of the lock - private static EELFLogger logger = EELFManager.getInstance().getLogger(MusicLockState.class); + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicLockState.class); LockStatus lockStatus; boolean needToSyncQuorum = false; String lockHolder; @@ -106,7 +104,7 @@ public class MusicLockState implements Serializable { out = new ObjectOutputStream(bos); out.writeObject(this); } catch (IOException e) { - logger.error(e.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger,e.getMessage()); } return bos.toByteArray(); } @@ -119,7 +117,7 @@ public class MusicLockState implements Serializable { in = new ObjectInputStream(bis); o = in.readObject(); } catch (ClassNotFoundException | IOException e) { - logger.error(e.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger,e.getMessage()); } return (MusicLockState) o; } diff --git a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java index 59b502ca..9b21f596 100644 --- a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java +++ b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java @@ -1,20 +1,16 @@ /* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * 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 + * ============LICENSE_START========================================== org.onap.music + * =================================================================== Copyright (c) 2017 AT&T + * Intellectual Property =================================================================== + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. * * ============LICENSE_END============================================= * ==================================================================== @@ -25,28 +21,26 @@ package org.onap.music.lockingservice; import java.io.IOException; import java.util.StringTokenizer; import java.util.concurrent.CountDownLatch; + import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.Watcher.Event.KeeperState; -import org.onap.music.exceptions.MusicServiceException; -import org.onap.music.main.MusicCore; -import org.onap.music.main.MusicUtil; import org.apache.zookeeper.ZooKeeper; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.music.datastore.MusicDataStore; import org.onap.music.eelf.logging.EELFLoggerDelegate; +import org.onap.music.exceptions.MusicLockingException; +import org.onap.music.exceptions.MusicServiceException; +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); - private static EELFLogger logger = - EELFManager.getInstance().getLogger(MusicLockingService.class); - // private static EELFLoggerDelegate logger = - // EELFLoggerDelegate.getLogger(MusicLockingService.class); + private static EELFLoggerDelegate logger = + EELFLoggerDelegate.getLogger(MusicLockingService.class); public MusicLockingService() throws MusicServiceException { try { @@ -54,10 +48,10 @@ public class MusicLockingService implements Watcher { connectedSignal.await(); zkLockHandle = new ZkStatelessLockService(zk); } catch (IOException e) { - logger.error(e.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); throw new MusicServiceException("IO Error has occured" + e.getMessage()); } catch (InterruptedException e) { - logger.error(e.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); throw new MusicServiceException("Exception Occured " + e.getMessage()); } } @@ -72,7 +66,7 @@ public class MusicLockingService implements Watcher { connectedSignal.await(); zkLockHandle = new ZkStatelessLockService(zk); } catch (IOException | InterruptedException e) { - logger.error(e.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); } } @@ -90,10 +84,18 @@ public class MusicLockingService implements Watcher { zkLockHandle.setNodeData(lockName, data); } - public MusicLockState getLockState(String lockName) { + public MusicLockState getLockState(String lockName) throws MusicLockingException { - byte[] data = zkLockHandle.getNodeData(lockName); + byte[] data = null; + try{ + data = zkLockHandle.getNodeData(lockName); + }catch (Exception ex){ + logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage()); + } + if(data !=null) return MusicLockState.deSerialize(data); + else + throw new MusicLockingException("Invalid lock or acquire failed"); } public String createLockId(String lockName) { @@ -108,7 +110,7 @@ public class MusicLockingService implements Watcher { try { return zkLockHandle.lock(lockName, lockId); } catch (KeeperException | InterruptedException e) { - logger.error(e.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger, e.getMessage()); } return false; } @@ -139,4 +141,9 @@ public class MusicLockingService implements Watcher { zkLockHandle.close(); } + public boolean lockIdExists(String lockIdWithDollar) { + String lockId = lockIdWithDollar.replace('$', '/'); + return zkLockHandle.checkIfLockExists(lockId); + } + } diff --git a/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java b/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java index 37ae9e96..df4d6ad6 100644 --- a/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java +++ b/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java @@ -29,6 +29,7 @@ import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; +import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.lockingservice.ZooKeeperOperation; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -40,7 +41,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * */ class ProtocolSupport { - private static final Logger LOG = LoggerFactory.getLogger(ProtocolSupport.class); + private EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ProtocolSupport.class); protected ZooKeeper zookeeper; private AtomicBoolean closed = new AtomicBoolean(false); @@ -128,7 +129,7 @@ class ProtocolSupport { try { return operation.execute(); } catch (KeeperException.SessionExpiredException e) { - LOG.warn("Session expired for: " + zookeeper + " so reconnecting due to: " + e, e); + LOG.debug("Session expired for: " + zookeeper + " so reconnecting due to: " + e, e); throw e; } catch (KeeperException.ConnectionLossException e) { if (exception == null) { @@ -173,9 +174,9 @@ class ProtocolSupport { } }); } catch (KeeperException e) { - LOG.warn("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger,"Caught: " + e, e); } catch (InterruptedException e) { - LOG.warn("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger,"Caught: " + e, e); } } @@ -198,7 +199,7 @@ class ProtocolSupport { try { Thread.sleep(attemptCount * retryDelay); } catch (InterruptedException e) { - LOG.debug("Failed to sleep: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger,"Failed to sleep: " + e, e); } } } diff --git a/src/main/java/org/onap/music/lockingservice/ZNodeName.java b/src/main/java/org/onap/music/lockingservice/ZNodeName.java index c8d14cba..eefc81a9 100644 --- a/src/main/java/org/onap/music/lockingservice/ZNodeName.java +++ b/src/main/java/org/onap/music/lockingservice/ZNodeName.java @@ -21,8 +21,7 @@ */ package org.onap.music.lockingservice; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.onap.music.eelf.logging.EELFLoggerDelegate; /** * Represents an ephemeral znode name which has an ordered sequence number and can be sorted in @@ -33,8 +32,8 @@ class ZNodeName implements Comparable { private final String name; private String prefix; private int sequence = -1; - private static EELFLogger LOG = EELFManager.getInstance().getLogger(ZNodeName.class); - + private EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ZNodeName.class); + public ZNodeName(String name) { if (name == null) { throw new NullPointerException("id cannot be null"); @@ -49,9 +48,9 @@ class ZNodeName implements Comparable { // If an exception occurred we misdetected a sequence suffix, // so return -1. } catch (NumberFormatException e) { - LOG.info("Number format exception for " + idx, e); + LOG.error(EELFLoggerDelegate.errorLogger,"Number format exception for " + idx, e); } catch (ArrayIndexOutOfBoundsException e) { - LOG.info("Array out of bounds for " + idx, e); + LOG.error(EELFLoggerDelegate.errorLogger,"Array out of bounds for " + idx, e); } } } diff --git a/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java b/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java index 99ccd4db..bd8ddfe3 100644 --- a/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java +++ b/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java @@ -1,26 +1,23 @@ /* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * 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 + * ============LICENSE_START========================================== org.onap.music + * =================================================================== Copyright (c) 2017 AT&T + * Intellectual Property =================================================================== + * 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 * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. * * ============LICENSE_END============================================= * ==================================================================== */ package org.onap.music.lockingservice; + import java.util.List; import java.util.SortedSet; import java.util.TreeSet; @@ -30,8 +27,7 @@ import org.apache.zookeeper.ZooDefs; import org.apache.zookeeper.ZooKeeper; import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.onap.music.eelf.logging.EELFLoggerDelegate; /** * A protocol to implement an exclusive write lock or to elect a leader. @@ -48,8 +44,8 @@ public class ZkStatelessLockService extends ProtocolSupport { zookeeper = zk; } - private static EELFLogger LOG = - EELFManager.getInstance().getLogger(ZkStatelessLockService.class); + private static EELFLoggerDelegate LOG = + EELFLoggerDelegate.getLogger(ZkStatelessLockService.class); protected void createLock(final String path, final byte[] data) { final List acl = ZooDefs.Ids.OPEN_ACL_UNSAFE; @@ -61,9 +57,9 @@ public class ZkStatelessLockService extends ProtocolSupport { } }); } catch (KeeperException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); } catch (InterruptedException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); } } @@ -71,7 +67,7 @@ public class ZkStatelessLockService extends ProtocolSupport { try { zookeeper.close(); } catch (InterruptedException e) { - LOG.info(e.getMessage()); + LOG.error(EELFLoggerDelegate.errorLogger, e.getMessage()); } } @@ -85,9 +81,9 @@ public class ZkStatelessLockService extends ProtocolSupport { } }); } catch (KeeperException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); } catch (InterruptedException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); } } @@ -99,10 +95,8 @@ public class ZkStatelessLockService extends ProtocolSupport { else return null; - } catch (KeeperException e) { - LOG.info("Caught: " + e, e); - } catch (InterruptedException e) { - LOG.info("Caught: " + e, e); + } catch (KeeperException | InterruptedException e) { + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); } return null; } @@ -114,10 +108,8 @@ public class ZkStatelessLockService extends ProtocolSupport { if (stat != null) { result = true; } - } catch (KeeperException e) { - LOG.info(e.getMessage()); - } catch (InterruptedException e) { - LOG.info(e.getMessage()); + } catch (KeeperException | InterruptedException e) { + LOG.error(EELFLoggerDelegate.errorLogger, e.getMessage()); } return result; } @@ -129,13 +121,10 @@ public class ZkStatelessLockService extends ProtocolSupport { public String createLockId(String dir) { ensurePathExists(dir); LockZooKeeperOperation zop = new LockZooKeeperOperation(dir); - try { retryOperation(zop); - } catch (KeeperException e) { - LOG.info(e.getMessage()); - } catch (InterruptedException e) { - LOG.info(e.getMessage()); + } catch (KeeperException | InterruptedException e) { + LOG.error(EELFLoggerDelegate.errorLogger, e.getMessage()); } return zop.getId(); } @@ -172,13 +161,13 @@ public class ZkStatelessLockService extends ProtocolSupport { }; zopdel.execute(); } catch (InterruptedException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); // set that we have been interrupted. Thread.currentThread().interrupt(); } catch (KeeperException.NoNodeException e) { // do nothing } catch (KeeperException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); throw (RuntimeException) new RuntimeException(e.getMessage()).initCause(e); } } @@ -198,13 +187,13 @@ public class ZkStatelessLockService extends ProtocolSupport { } return sortedNames.first().getName(); } catch (InterruptedException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); // set that we have been interrupted. Thread.currentThread().interrupt(); } catch (KeeperException.NoNodeException e) { // do nothing } catch (KeeperException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); throw (RuntimeException) new RuntimeException(e.getMessage()).initCause(e); } } @@ -227,13 +216,13 @@ public class ZkStatelessLockService extends ProtocolSupport { }; zopdel.execute(); } catch (InterruptedException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); // set that we have been interrupted. Thread.currentThread().interrupt(); } catch (KeeperException.NoNodeException e) { // do nothing } catch (KeeperException e) { - LOG.info("Caught: " + e, e); + LOG.error(EELFLoggerDelegate.errorLogger, "Caught: " + e, e); throw (RuntimeException) new RuntimeException(e.getMessage()).initCause(e); } } @@ -292,8 +281,8 @@ public class ZkStatelessLockService extends ProtocolSupport { if (id != null) { List names = zookeeper.getChildren(dir, false); if (names.isEmpty()) { - LOG.info("No children in: " + dir + " when we've just " - + "created one! Lets recreate it..."); + LOG.info(EELFLoggerDelegate.applicationLogger, "No children in: " + dir + + " when we've just " + "created one! Lets recreate it..."); // lets force the recreation of the id id = null; } else { @@ -318,8 +307,9 @@ public class ZkStatelessLockService extends ProtocolSupport { if (stat != null) { return Boolean.FALSE; } else { - LOG.info("Could not find the" + " stats for less than me: " - + lastChildName.getName()); + LOG.info(EELFLoggerDelegate.applicationLogger, + "Could not find the" + " stats for less than me: " + + lastChildName.getName()); } } else return Boolean.TRUE; -- cgit 1.2.3-korg