summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java4
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java4
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java4
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java3
-rwxr-xr-xsrc/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java3
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java3
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java4
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java4
-rwxr-xr-xsrc/main/java/org/onap/music/main/CachingUtil.java11
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java22
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicDataAPI.java114
11 files changed, 106 insertions, 70 deletions
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)) {