CLM Changes 53/36353/1
authorThomas Nelson Jr (arthurdent3) tn1381@att.com <tn1381@att.com>
Sun, 18 Mar 2018 05:48:08 +0000 (01:48 -0400)
committerThomas Nelson Jr (arthurdent3) tn1381@att.com <tn1381@att.com>
Sun, 18 Mar 2018 05:48:08 +0000 (01:48 -0400)
Change-Id: Id34c036653bf0816e5c67004e4dcf7da90e470e7
Issue-ID: MUSIC-47, MUSIC-48, MUSIC-49
Signed-off-by: Thomas Nelson Jr (arthurdent3) tn1381@att.com <tn1381@att.com>
14 files changed:
pom.xml
src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java
src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java
src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java
src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java
src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java
src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java
src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java
src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java
src/main/java/org/onap/music/main/CachingUtil.java
src/main/java/org/onap/music/main/MusicCore.java
src/main/java/org/onap/music/rest/RestMusicDataAPI.java
src/test/java/org/onap/music/unittests/TestRestMusicData.java
version.properties

diff --git a/pom.xml b/pom.xml
index b57733d..4bb5e21 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
     <groupId>org.onap.music</groupId>
     <artifactId>MUSIC</artifactId>
     <packaging>war</packaging>
-    <version>2.4.18</version>
+    <version>2.4.20</version>
     <description>
             This is the MUSIC REST interface, packaged as a war file.
     </description>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <jersey1.version>1.19</jersey1.version>
+        <jersey2.version>2.25.1</jersey2.version>
         <jaxrs.version>2.0.1</jaxrs.version>
-        <cassandra.version>3.2.0</cassandra.version>
-        <zookeeper.version>3.4.6</zookeeper.version>
+        <cassandra.version>3.4.0</cassandra.version>
+        <zookeeper.version>3.4.11</zookeeper.version>
 
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
         <dependency>
             <groupId>io.swagger</groupId>
             <artifactId>swagger-jersey-jaxrs</artifactId>
-            <version>1.5.8</version>
+            <version>1.5.18</version>
         </dependency>
         <dependency>
             <groupId>com.google.guava</groupId>
index 87c000b..a5db4be 100644 (file)
@@ -23,10 +23,14 @@ package org.onap.music.datastore.jsonobjects;
 
 import java.util.ArrayList;
 import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 @ApiModel(value = "JsonTable", description = "Json model for delete")
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class JsonDelete {
 
     private ArrayList<String> columns = null;
index b7a9ec2..a58552c 100644 (file)
@@ -27,10 +27,14 @@ import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 @ApiModel(value = "JsonTable", description = "Json model for table vlaues insert")
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class JsonInsert implements Serializable {
     private String keyspaceName;
     private String tableName;
index 01b7267..54de02f 100644 (file)
 package org.onap.music.datastore.jsonobjects;
 
 import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 @ApiModel(value = "JsonTable", description = "Json model creating new keyspace")
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class JsonKeySpace {
     private String keyspaceName;
     private Map<String, Object> replicationInfo;
index 85895ba..497e17d 100644 (file)
  */
 package org.onap.music.datastore.jsonobjects;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 @ApiModel(value = "JsonTable", description = "model for leased lock")
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class JsonLeasedLock {
     long leasePeriod;
     String notifyUrl;
index 1131173..0bac1e3 100755 (executable)
  */
 package org.onap.music.datastore.jsonobjects;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 @ApiModel(value = "JsonOnboard", description = "Defines the Json for Onboarding an application.")
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class JsonOnboard {
     private String appname;
     private String userId;
index 0c2d012..64bc388 100644 (file)
@@ -28,6 +28,9 @@ import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.Map;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class JsonSelect implements Serializable {
     private Map<String, String> consistencyInfo;
 
index c0d8521..5d508ad 100644 (file)
 package org.onap.music.datastore.jsonobjects;
 
 import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 @ApiModel(value = "JsonTable", description = "Defines the Json for Creating a new Table.")
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class JsonTable {
     private String keyspaceName;
     private String tableName;
index fae7720..3ab5ea0 100644 (file)
@@ -27,10 +27,14 @@ import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.Map;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
 @ApiModel(value = "JsonTable", description = "Json model for table update")
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class JsonUpdate implements Serializable {
     private String keyspaceName;
     private String tableName;
index 16a0286..2c46efb 100755 (executable)
@@ -244,7 +244,7 @@ public class CachingUtil implements Runnable {
                 return resultMap;
             }
             if (!musicCache.get(keyspace).toString().equals(aid)) {
-                resultMap.put("Exception Message",
+                resultMap.put("Exception",
                                 "Unauthorized operation. Invalid AID for the keyspace");
                 return resultMap;
             }
@@ -267,8 +267,7 @@ public class CachingUtil implements Runnable {
         appNameCache.put(namespace, isAAF);
     }
 
-    public static Boolean isAAFApplication(String namespace) throws MusicServiceException {
-
+    public static String isAAFApplication(String namespace) throws MusicServiceException {
         String isAAF = appNameCache.get(namespace);
         if (isAAF == null) {
             PreparedQueryObject pQuery = new PreparedQueryObject();
@@ -278,14 +277,14 @@ public class CachingUtil implements Runnable {
             Row rs = MusicCore.get(pQuery).one();
             try {
                 isAAF = String.valueOf(rs.getBool("is_aaf"));
-                appNameCache.put(namespace, isAAF);
+                if(isAAF != null)
+                    appNameCache.put(namespace, isAAF);
             } catch (Exception e) {
                logger.error(EELFLoggerDelegate.errorLogger,  e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
                e.printStackTrace();
             }
         }
-
-        return Boolean.valueOf(isAAF);
+        return isAAF;
     }
 
     public static String getUuidFromMusicCache(String keyspace) throws MusicServiceException {
index 6ce6b0d..4929edd 100644 (file)
@@ -890,7 +890,13 @@ public class MusicCore {
                         operation);
         if (!resultMap.isEmpty())
             return resultMap;
-        boolean isAAF = CachingUtil.isAAFApplication(nameSpace);
+        String isAAFApp = CachingUtil.isAAFApplication(nameSpace);
+        if(isAAFApp == null) {
+            resultMap.put("Exception", "Namespace: "+nameSpace+" doesn't exist. Please make sure ns(appName)"
+                    + " is correct and Application is onboarded.");
+            return resultMap;
+        }
+        boolean isAAF = Boolean.valueOf(isAAFApp);
         if (!isAAF && !(operation.equals("createKeySpace"))) {
                if(aid == null) {
                        resultMap.put("Exception", "Aid is mandatory for nonAAF applications ");
@@ -947,20 +953,6 @@ public class MusicCore {
                 uuid = CachingUtil.generateUUID();
                 resultMap.put("uuid", "new");
             }
-
-            pQuery = new PreparedQueryObject();
-            pQuery.appendQueryString(
-                            "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
-                                            + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
-            pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
-            pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspace));
-            pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), nameSpace));
-            pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
-            pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
-            pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
-            pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
-            //CachingUtil.updateMusicCache(uuid, keyspace);
-            MusicCore.eventualPut(pQuery);
             resultMap.put("aid", uuid);
         }
 
index bcdb8dd..4c8de43 100755 (executable)
@@ -205,48 +205,10 @@ public class RestMusicDataAPI {
         ResultType result = ResultType.FAILURE;
         try {
             result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
-            logger.error(EELFLoggerDelegate.errorLogger, "resulta = " + result);
-        } catch (Exception e) {
-            logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
-            return new JsonResponse(ResultType.FAILURE)
-                       .setError("Couldn't create keyspace. Please make sure all the information is correct.").toMap();
-        }
-
-        if (result==ResultType.FAILURE) {
-               logger.info(EELFLoggerDelegate.applicationLogger, "Cannot create keyspace, cleaning up");
-               JsonResponse resultJson = new JsonResponse(ResultType.FAILURE);
-            resultJson.setError("Keyspace already exists. Please contact admin.");
-            if (authMap.get("uuid").equals("new")) {
-                queryObject = new PreparedQueryObject();
-                queryObject.appendQueryString(
-                                "DELETE FROM admin.keyspace_master where uuid = " + newAid);
-                queryObject.appendQueryString(";");
-                try {
-                                       MusicCore.nonKeyRelatedPut(queryObject, consistency);
-                               } catch (MusicServiceException e) {
-                                       logger.error(EELFLoggerDelegate.errorLogger,
-                                                       "Error cleaning up createKeyspace. Cannot DELETE uuid. " + e.getMessage());
-                               }
-                return resultJson.toMap();
-            } else {
-                queryObject = new PreparedQueryObject();
-                queryObject.appendQueryString(
-                                "UPDATE admin.keyspace_master SET keyspace_name=? where uuid = ?;");
-                try {
-                       queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
-                                MusicUtil.DEFAULTKEYSPACENAME));
-                                       queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid));
-                               } catch (Exception e) {
-                                       logger.error(EELFLoggerDelegate.errorLogger,
-                                                       "Error cleaning up createKeyspace. Cannot get correct data types" + e.getMessage());
-                               }
-                try {
-                                        MusicCore.nonKeyRelatedPut(queryObject, consistency);
-                               } catch (MusicServiceException e) {
-                                       logger.error(EELFLoggerDelegate.errorLogger, "Unable to process operation. Error: "+e.getMessage());
-                               }
-                return resultJson.toMap();
-            }
+            logger.error(EELFLoggerDelegate.errorLogger, "result = " + result);
+        } catch ( MusicServiceException ex) {
+            logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR  ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+            return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
         }
         
         try {
@@ -263,6 +225,26 @@ public class RestMusicDataAPI {
                logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
         }
         
+        try {
+            boolean isAAF = Boolean.valueOf(CachingUtil.isAAFApplication(ns));
+            queryObject = new PreparedQueryObject();
+            queryObject.appendQueryString(
+                        "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+                                        + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
+            queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid));
+            queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
+            queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
+            queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
+            queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
+            queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+            queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
+            CachingUtil.updateMusicCache(newAid, keyspaceName);
+            MusicCore.eventualPut(queryObject);
+        } catch (Exception e) {
+            logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+            return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+        }
+        
         return new JsonResponse(ResultType.SUCCESS).toMap();
     }
 
@@ -444,7 +426,7 @@ public class RestMusicDataAPI {
             result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
         } catch (MusicServiceException ex) {
                response.setStatus(400);
-            return new JsonResponse(result).toMap();
+            return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
         }
 
         return new JsonResponse(result).toMap();
@@ -585,8 +567,13 @@ public class RestMusicDataAPI {
                 primaryKey = entry.getValue() + "";
                 primaryKey = primaryKey.replace("'", "''");
             }
-
-            DataType colType = tableInfo.getColumn(entry.getKey()).getType();
+            DataType colType = null;
+            try {
+                colType = tableInfo.getColumn(entry.getKey()).getType();
+            } catch(NullPointerException ex) {
+                logger.error(EELFLoggerDelegate.errorLogger, "Invalid column name : "+entry.getKey());
+                return new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap();
+            }
 
             Object formattedValue = null;
             try {
@@ -646,6 +633,12 @@ public class RestMusicDataAPI {
                 result = MusicCore.eventualPut(queryObject);
             } else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
                 String lockId = insObj.getConsistencyInfo().get("lockId");
+                if(lockId == null) {
+                    logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+                            + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
+                    return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+                            + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+                }
                 result = MusicCore.criticalPut(keyspace, tablename, primaryKey, queryObject, lockId,
                                 null);
             } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
@@ -745,7 +738,13 @@ public class RestMusicDataAPI {
         int counter = 0;
         for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
             Object valueObj = entry.getValue();
-            DataType colType = tableInfo.getColumn(entry.getKey()).getType();
+            DataType colType = null;
+            try {
+                colType = tableInfo.getColumn(entry.getKey()).getType();
+            } catch(NullPointerException ex) {
+                logger.error(EELFLoggerDelegate.errorLogger, "Invalid column name : "+entry.getKey());
+                return new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap();
+            }
             Object valueString = null;
             try {
               valueString = MusicUtil.convertToActualDataType(colType, valueObj);
@@ -818,6 +817,12 @@ public class RestMusicDataAPI {
             operationResult = MusicCore.eventualPut(queryObject);
         else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
             String lockId = updateObj.getConsistencyInfo().get("lockId");
+            if(lockId == null) {
+                logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+                        + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
+                return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+                        + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+            }
             operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
                             queryObject, lockId, conditionInfo);
         } else if (consistency.equalsIgnoreCase("atomic_delete_lock")) {
@@ -946,7 +951,6 @@ public class RestMusicDataAPI {
             queryObject.appendQueryString(
                             "DELETE " + columnString + " FROM " + keyspace + "." + rowSpec + ";");
         }
-
         // get the conditional, if any
         Condition conditionInfo;
         if (delObj.getConditions() == null)
@@ -968,6 +972,12 @@ public class RestMusicDataAPI {
                    operationResult = MusicCore.eventualPut(queryObject);
                else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
                    String lockId = delObj.getConsistencyInfo().get("lockId");
+                   if(lockId == null) {
+                    logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+                            + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
+                    return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+                            + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+                }
                    operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
                                    queryObject, lockId, conditionInfo);
                } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
@@ -982,8 +992,8 @@ public class RestMusicDataAPI {
                        return new JsonResponse(ResultType.FAILURE)
                                        .setError("Unable to perform Delete operation. Exception from music").toMap();
                }
-        if (operationResult==null) {
-               return new JsonResponse(ResultType.FAILURE).toMap();
+        if (operationResult.getResult().equals(ResultType.FAILURE)) {
+               return new JsonResponse(ResultType.FAILURE).setError(operationResult.getMessage()).toMap();
         }
         return new JsonResponse(operationResult.getResult()).toMap();
     }
@@ -1100,6 +1110,12 @@ public class RestMusicDataAPI {
         String consistency = selObj.getConsistencyInfo().get("type");
 
         if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
+               if(lockId == null) {
+                logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+                        + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
+                return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+                        + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+            }
             results = MusicCore.criticalGet(keyspace, tablename, rowId.primarKeyValue, queryObject,
                             lockId);
         } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
index 435b196..c5dc69f 100644 (file)
@@ -201,8 +201,8 @@ public class TestRestMusicData {
         Map<String, Object> resultMap = data.createKeySpace("1", "1", "1", null, "TestApp1",
                         "TestUser1", password, jsonKeyspace, keyspaceName, http);
         System.out.println("#######status is " + resultMap.get("Exception"));
-        assertEquals("Couldn't create keyspace. Please make sure all the information is correct.",
-                        resultMap.get("error"));
+        assertEquals("Keyspace testcassa already exists",
+                resultMap.get("error"));;
     }
 
     @Test
index e138477..b6a0bf9 100644 (file)
@@ -4,7 +4,7 @@
 
 major=2
 minor=4
-patch=18
+patch=20
 
 base_version=${major}.${minor}.${patch}