Merge "Remove the unused import"
[music.git] / src / main / java / org / onap / music / main / MusicCore.java
index cc147d5..9f7b060 100644 (file)
@@ -22,7 +22,6 @@
 package org.onap.music.main;
 
 
-import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.HashMap;
 import java.util.Map;
@@ -74,7 +73,10 @@ public class MusicCore {
         public boolean testCondition() throws Exception {
             // first generate the row
             ResultSet results = quorumGet(selectQueryForTheRow);
-            Row row = results.one();
+            Row row = null;
+            if(results != null) {
+                row = results.one();
+            }
             return getDSHandle().doesRowSatisfyCondition(row, conditions);
         }
     }
@@ -123,7 +125,7 @@ public class MusicCore {
         long start = System.currentTimeMillis();
         if (mDstoreHandle == null) {
             // Quick Fix - Best to put this into every call to getDSHandle?
-            if (! MusicUtil.getMyCassaHost().equals("localhost") ) {
+            if (! "localhost".equals(MusicUtil.getMyCassaHost())) {
                 mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
             } else {
                 mDstoreHandle = new MusicDataStore();
@@ -289,7 +291,8 @@ public class MusicCore {
         MusicLockState newMls = null;
         try {
             currentMls = getMusicLockState(key);
-            String currentLockHolder = currentMls.getLockHolder();
+            String currentLockHolder = null;
+            if(currentMls != null) { currentLockHolder = currentMls.getLockHolder(); };
             if (lockId.equals(currentLockHolder)) {
                 logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: You already have the lock!");
                 return new ReturnType(ResultType.SUCCESS, "You already have the lock!");
@@ -665,7 +668,6 @@ public class MusicCore {
                             "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
                                             + e.getMessage());
         }catch(MusicLockingException ex){
-                       logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage());
             return new ReturnType(ResultType.FAILURE,ex.getMessage());
         }
 
@@ -710,6 +712,22 @@ public class MusicCore {
         }
         return results;
     }
+    
+    public static String getMyHostId() {
+       PreparedQueryObject pQuery = new PreparedQueryObject();
+       pQuery.appendQueryString("SELECT HOST_ID FROM SYSTEM.LOCAL");
+               ResultSet rs = null;
+               try {
+                       rs = getDSHandle().executeEventualGet(pQuery);
+                       Row row = rs.one();
+                       return (row == null) ? "UNKNOWN" : row.getUUID("HOST_ID").toString();
+               } catch (Exception e) {
+                       e.printStackTrace();
+            logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+        }
+               logger.error(EELFLoggerDelegate.errorLogger, "Some issue during MusicCore.getMyHostId");
+               return "UNKNOW";
+       }
 
     /**
      * This method performs DDL operations on cassandra, if the the resource is available. Lock ID