Changes Listed below:
[music.git] / src / main / java / org / onap / music / conductor / conditionals / MusicConditional.java
index ff77bfd..29740d8 100644 (file)
@@ -3,7 +3,9 @@
  * org.onap.music
  * ===================================================================
  *  Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
  *  Modifications Copyright (C) 2019 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.
@@ -90,7 +92,12 @@ public class MusicConditional {
         
         
         String key = keyspace + "." + tablename + "." + primaryKey;
-        String lockId = MusicCore.createLockReference(key);
+        String lockId;
+        try {
+               lockId = MusicCore.createLockReference(key);
+        } catch (MusicLockingException e) {
+               return new ReturnType(ResultType.FAILURE, e.getMessage());
+        }
         long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
         ReturnType lockAcqResult = MusicCore.acquireLockWithLease(key, lockId, leasePeriod);
 
@@ -112,6 +119,7 @@ public class MusicConditional {
                 return lockAcqResult;
             }
         } catch (Exception e) {
+            logger.error(EELFLoggerDelegate.applicationLogger, e);
             MusicCore.destroyLockRef(lockId);
             return new ReturnType(ResultType.FAILURE, e.getMessage());
         }
@@ -130,6 +138,7 @@ public class MusicConditional {
                 try {
                     results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(queryBank.get(MusicUtil.SELECT));
                 } catch (Exception e) {
+                    logger.error(EELFLoggerDelegate.applicationLogger, e);
                     return new ReturnType(ResultType.FAILURE, e.getMessage());
                 }
                 if (results.all().isEmpty()) {
@@ -148,6 +157,7 @@ public class MusicConditional {
             StringWriter sw = new StringWriter();
             e.printStackTrace(new PrintWriter(sw));
             String exceptionAsString = sw.toString();
+            logger.error(EELFLoggerDelegate.applicationLogger, e);
             return new ReturnType(ResultType.FAILURE,
                     "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
                             + exceptionAsString);
@@ -155,7 +165,10 @@ public class MusicConditional {
 
     }
 
-    public static ReturnType update(Map<String,PreparedQueryObject> queryBank, String keyspace, String tableName, String primaryKey,String primaryKeyValue,String planId,String cascadeColumnName,Map<String,String> cascadeColumnValues) throws MusicLockingException, MusicQueryException, MusicServiceException {
+       public static ReturnType update(Map<String, PreparedQueryObject> queryBank, String keyspace, String tableName,
+                       String primaryKey, String primaryKeyValue, String planId, String cascadeColumnName,
+                       Map<String, String> cascadeColumnValues)
+                       throws MusicLockingException, MusicQueryException, MusicServiceException {
 
         String key = keyspace + "." + tableName + "." + primaryKeyValue;
         String lockId = MusicCore.createLockReference(key);
@@ -175,6 +188,7 @@ public class MusicConditional {
 
         } catch (Exception e) {
             MusicCore.destroyLockRef(lockId);
+            logger.error(EELFLoggerDelegate.applicationLogger, e);
             return new ReturnType(ResultType.FAILURE, e.getMessage());
 
         }
@@ -202,6 +216,7 @@ public class MusicConditional {
                     try {
                         MusicDataStoreHandle.getDSHandle().executePut(update, "critical");
                     } catch (Exception ex) {
+                        logger.error(EELFLoggerDelegate.applicationLogger, ex);
                         return new ReturnType(ResultType.FAILURE, ex.getMessage());
                     }
                 }else {
@@ -219,6 +234,7 @@ public class MusicConditional {
             StringWriter sw = new StringWriter();
             e.printStackTrace(new PrintWriter(sw));
             String exceptionAsString = sw.toString();
+            logger.error(EELFLoggerDelegate.applicationLogger, e);
             return new ReturnType(ResultType.FAILURE,
                     "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
                             + exceptionAsString);
@@ -254,11 +270,12 @@ public class MusicConditional {
         StringBuilder fieldsString = new StringBuilder("(vector_ts"+",");
         StringBuilder valueString = new StringBuilder("(" + "?" + ",");
         String vector = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
+        String localPrimaryKey;
         queryObject.addValue(vector);
         if(casscadeColumn!=null && casscadeColumnValues!=null) {
             fieldsString.append(casscadeColumn).append(" ,");
-          valueString.append("?,");
-          queryObject.addValue(casscadeColumnValues);
+            valueString.append("?,");
+            queryObject.addValue(casscadeColumnValues);
         }
         
         int counter = 0;
@@ -267,23 +284,23 @@ public class MusicConditional {
             fieldsString.append(entry.getKey());
             Object valueObj = entry.getValue();
             if (primaryKeyName.equals(entry.getKey())) {
-                primaryKey = entry.getValue() + "";
-                primaryKey = primaryKey.replace("'", "''");
+                localPrimaryKey = entry.getValue() + "";
+                localPrimaryKey = localPrimaryKey.replace("'", "''");
             }
             DataType colType = null;
             try {
                 colType = tableInfo.getColumn(entry.getKey()).getType();
             } catch(NullPointerException ex) {
-                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() +" Invalid column name : "+entry.getKey(), AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
-               
+                logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() +" Invalid column name : "+entry.getKey(), 
+                    AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR, ex);
             }
 
             Object formattedValue = null;
             try {
-              formattedValue = MusicUtil.convertToActualDataType(colType, valueObj);
+                formattedValue = MusicUtil.convertToActualDataType(colType, valueObj);
             } catch (Exception e) {
-              logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
-          }
+                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), e);
+            }
             
             valueString.append("?");
             queryObject.addValue(formattedValue);