diff options
author | Bharath Balasubramanian <bharathb@research.att.com> | 2018-03-18 15:05:59 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-03-18 15:05:59 +0000 |
commit | c3b32d4f9e681115e061b5d3a907363a346b1f40 (patch) | |
tree | 5b9b51dd326232cade075483e042271bc88264ce | |
parent | 8609757625321ee22372d7b918f9fc145ef8ef3e (diff) | |
parent | 67da04ebd086a4e79c9f9acf4d1084729306b2d6 (diff) |
Merge "CLM Changes"
14 files changed, 114 insertions, 77 deletions
@@ -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> @@ -40,9 +40,10 @@ <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> @@ -313,7 +314,7 @@ <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> diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java index 87c000b2..a5db4be5 100644 --- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java @@ -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; diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java index b7a9ec23..a58552c6 100644 --- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java @@ -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; diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java index 01b72672..54de02fd 100644 --- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java @@ -22,10 +22,14 @@ 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; diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java index 85895baf..497e17d1 100644 --- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java @@ -21,10 +21,13 @@ */ 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; diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java index 11311733..0bac1e31 100755 --- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java @@ -21,10 +21,13 @@ */ 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; diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java index 0c2d012c..64bc3887 100644 --- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java @@ -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; diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java index c0d8521d..5d508adb 100644 --- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java @@ -22,10 +22,14 @@ 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; diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java index fae7720d..3ab5ea0d 100644 --- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java @@ -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; diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java index 16a02862..2c46efbc 100755 --- a/src/main/java/org/onap/music/main/CachingUtil.java +++ b/src/main/java/org/onap/music/main/CachingUtil.java @@ -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 { diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java index 6ce6b0d3..4929edd8 100644 --- a/src/main/java/org/onap/music/main/MusicCore.java +++ b/src/main/java/org/onap/music/main/MusicCore.java @@ -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); } diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java index bcdb8dd2..4c8de434 100755 --- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java @@ -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)) { diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java index 435b196c..c5dc69f6 100644 --- a/src/test/java/org/onap/music/unittests/TestRestMusicData.java +++ b/src/test/java/org/onap/music/unittests/TestRestMusicData.java @@ -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 diff --git a/version.properties b/version.properties index e1384772..b6a0bf9a 100644 --- a/version.properties +++ b/version.properties @@ -4,7 +4,7 @@ major=2 minor=4 -patch=18 +patch=20 base_version=${major}.${minor}.${patch} |