Add retry to Music get calls 82/90482/2
authorArthur Martella <arthur.martella.1@att.com>
Tue, 25 Jun 2019 20:27:00 +0000 (16:27 -0400)
committerTschaen, Brendan <ctschaen@att.com>
Tue, 25 Jun 2019 20:57:17 +0000 (16:57 -0400)
Add 3 retries to Music get calls.
Ideally, should allow configuration of number of retries.

Issue-ID: MUSIC-416
Signed-off-by: Martella, Arthur <arthur.martella.1@att.com>
Change-Id: Ibdbc8c91da103b8058e46f8995f54e349a41afbd

mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java

index 71302dd..1bdb022 100644 (file)
@@ -2270,25 +2270,29 @@ public class MusicMixin implements MusicInterface {
     private static Row executeMusicLockedGet(String keyspace, String table, PreparedQueryObject cqlObject, String primaryKey,
                                              String lock)
         throws MDBCServiceException{
-        ResultSet result;
-        if(lock != null && !lock.isEmpty()) {
-            try {
-                result = MusicCore.criticalGet(keyspace, table, primaryKey, cqlObject, lock);
-            } catch (MusicServiceException e) {
-                e.printStackTrace();
-                throw new MDBCServiceException("Error executing critical get", e);
+        ResultSet result = null;
+        int triesRemaining = 3;
+        while (result==null && triesRemaining>0) {
+            if(lock != null && !lock.isEmpty()) {
+                try {
+                    result = MusicCore.criticalGet(keyspace, table, primaryKey, cqlObject, lock);
+                } catch (MusicServiceException e) {
+                    e.printStackTrace();
+                    throw new MDBCServiceException("Error executing critical get", e);
+                }
             }
-        }
-        else{
-            try {
-                result = MusicCore.atomicGet(keyspace,table,primaryKey,cqlObject);
-            } catch (MusicServiceException|MusicLockingException|MusicQueryException e) {
-                e.printStackTrace();
-                throw new MDBCServiceException("Error executing atomic get", e);
+            else{
+                try {
+                    result = MusicCore.atomicGet(keyspace,table,primaryKey,cqlObject);
+                } catch (MusicServiceException|MusicLockingException|MusicQueryException e) {
+                    e.printStackTrace();
+                    throw new MDBCServiceException("Error executing atomic get", e);
+                }
             }
+            triesRemaining--;
         }
         if(result==null){
-            throw new MDBCServiceException("Error executing atomic get for primary key: "+primaryKey);
+            throw new MDBCServiceException("Error executing atomic get for primary key: " + primaryKey + " and lock: " + lock);
         }
         if(result.isExhausted()){
             return null;