aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/music/datastore/MusicDataStore.java22
-rw-r--r--src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java6
-rwxr-xr-xsrc/main/java/org/onap/music/main/CachingUtil.java25
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java33
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java2
-rw-r--r--src/main/java/org/onap/music/main/ResultType.java3
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicAdminAPI.java2
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicDataAPI.java212
8 files changed, 234 insertions, 71 deletions
diff --git a/src/main/java/org/onap/music/datastore/MusicDataStore.java b/src/main/java/org/onap/music/datastore/MusicDataStore.java
index e1ae5b08..09bdc8a7 100644
--- a/src/main/java/org/onap/music/datastore/MusicDataStore.java
+++ b/src/main/java/org/onap/music/datastore/MusicDataStore.java
@@ -33,6 +33,8 @@ import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.main.MusicUtil;
+import org.onap.music.main.ResultType;
+
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.ColumnDefinitions.Definition;
@@ -46,6 +48,7 @@ import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.TableMetadata;
import com.datastax.driver.core.exceptions.AlreadyExistsException;
+import com.datastax.driver.core.exceptions.InvalidQueryException;
import com.datastax.driver.core.exceptions.NoHostAvailableException;
/**
@@ -65,6 +68,13 @@ public class MusicDataStore {
public void setSession(Session session) {
this.session = session;
}
+
+ /**
+ * @param session
+ */
+ public Session getSession() {
+ return session;
+ }
/**
* @param cluster
@@ -245,7 +255,7 @@ public class MusicDataStore {
}
}
- public boolean doesRowSatisfyCondition(Row row, Map<String, Object> condition) {
+ public boolean doesRowSatisfyCondition(Row row, Map<String, Object> condition) throws Exception {
ColumnDefinitions colInfo = row.getColumnDefinitions();
for (Map.Entry<String, Object> entry : condition.entrySet()) {
@@ -310,7 +320,14 @@ public class MusicDataStore {
"In preprared Execute Put: the actual insert query:"
+ queryObject.getQuery() + "; the values"
+ queryObject.getValues());
- PreparedStatement preparedInsert = session.prepare(queryObject.getQuery());
+ PreparedStatement preparedInsert = null;
+ try {
+ preparedInsert = session.prepare(queryObject.getQuery());
+ } catch(InvalidQueryException iqe) {
+ logger.error(EELFLoggerDelegate.errorLogger, iqe.getMessage());
+ throw new MusicQueryException(iqe.getMessage());
+ }
+
try {
if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
logger.info(EELFLoggerDelegate.applicationLogger, "Executing critical put query");
@@ -327,6 +344,7 @@ public class MusicDataStore {
catch (AlreadyExistsException ae) {
logger.error(EELFLoggerDelegate.errorLogger, "Executing Session Failure for Request = "
+ "[" + queryObject.getQuery() + "]" + " Reason = " + ae.getMessage());
+ throw new MusicServiceException(ae.getMessage());
}
catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "Executing Session Failure for Request = "
diff --git a/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java b/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java
index bd8ddfe3..f7464ec0 100644
--- a/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java
+++ b/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java
@@ -281,10 +281,8 @@ public class ZkStatelessLockService extends ProtocolSupport {
if (id != null) {
List<String> names = zookeeper.getChildren(dir, false);
if (names.isEmpty()) {
- LOG.info(EELFLoggerDelegate.applicationLogger, "No children in: " + dir
- + " when we've just " + "created one! Lets recreate it...");
- // lets force the recreation of the id
- id = null;
+ LOG.info(EELFLoggerDelegate.applicationLogger, "No children in: " + dir);
+ return Boolean.FALSE;
} else {
// lets sort them explicitly (though they do seem to come back in order
// ususally :)
diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java
index 4b2b4824..aef261f0 100755
--- a/src/main/java/org/onap/music/main/CachingUtil.java
+++ b/src/main/java/org/onap/music/main/CachingUtil.java
@@ -378,8 +378,7 @@ public class CachingUtil implements Runnable {
}
- public static Map<String, Object> verifyOnboarding(String ns, String userId, String password)
- throws Exception {
+ public static Map<String, Object> verifyOnboarding(String ns, String userId, String password) {
Map<String, Object> resultMap = new HashMap<>();
if (ns == null || userId == null || password == null) {
logger.error(EELFLoggerDelegate.errorLogger,"One or more required headers is missing. userId: "+userId+" :: password: "+password);
@@ -390,10 +389,24 @@ public class CachingUtil implements Runnable {
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString(
"select * from admin.keyspace_master where application_name = ? and username = ? and password = ? allow filtering");
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
- Row rs = MusicCore.get(queryObject).one();
+ try {
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
+ } catch(Exception e) {
+ resultMap.put("Exception",
+ "Unable to process input data. Invalid input data type. Please check ns, userId and password values. "+e.getMessage());
+ return resultMap;
+ }
+ Row rs = null;
+ try {
+ rs = MusicCore.get(queryObject).one();
+ } catch (MusicServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
+ return resultMap;
+ }
if (rs == null) {
logger.error(EELFLoggerDelegate.errorLogger,"Namespace, UserId and password doesn't match. namespace: "+ns+" and userId: "+userId);
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
index 3d5cf4e5..04aa60ce 100644
--- a/src/main/java/org/onap/music/main/MusicCore.java
+++ b/src/main/java/org/onap/music/main/MusicCore.java
@@ -66,7 +66,7 @@ public class MusicCore {
this.selectQueryForTheRow = selectQueryForTheRow;
}
- public boolean testCondition() {
+ public boolean testCondition() throws Exception {
// first generate the row
ResultSet results = quorumGet(selectQueryForTheRow);
Row row = results.one();
@@ -111,13 +111,20 @@ public class MusicCore {
/**
*
* @return
+ * @throws MusicServiceException
*/
- public static MusicDataStore getDSHandle() {
+ public static MusicDataStore getDSHandle() throws MusicServiceException {
logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
long start = System.currentTimeMillis();
if (mDstoreHandle == null) {
mDstoreHandle = new MusicDataStore();
}
+ if(mDstoreHandle.getSession() == null) {
+ String message = "Connection to Cassandra has not been enstablished."
+ + " Please check connection properites and reboot.";
+ logger.info(EELFLoggerDelegate.applicationLogger, message);
+ throw new MusicServiceException(message);
+ }
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
return mDstoreHandle;
@@ -293,7 +300,11 @@ public class MusicCore {
// do syncing if this was a forced lock release
if (needToSyncQuorum) {
logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Since there was a forcible release, need to sync quorum!");
- syncQuorum(key);
+ try {
+ syncQuorum(key);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,"Failed to set Lock state " + e);
+ }
}
// change status to locked
@@ -325,7 +336,7 @@ public class MusicCore {
}
- private static void syncQuorum(String key) {
+ private static void syncQuorum(String key) throws Exception {
logger.info(EELFLoggerDelegate.applicationLogger,"Performing sync operation---");
String[] splitString = key.split("\\.");
String keyspaceName = splitString[0];
@@ -407,8 +418,9 @@ public class MusicCore {
*
* @param results
* @return
+ * @throws MusicServiceException
*/
- public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) {
+ public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) throws MusicServiceException {
return getDSHandle().marshalData(results);
}
@@ -506,8 +518,9 @@ public class MusicCore {
* @param keyspace
* @param tablename
* @return
+ * @throws MusicServiceException
*/
- public static TableMetadata returnColumnMetadata(String keyspace, String tablename) {
+ public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException {
return getDSHandle().returnColumnMetadata(keyspace, tablename);
}
@@ -604,10 +617,16 @@ public class MusicCore {
MusicLockState mls = getLockingServiceHandle()
.getLockState(keyspaceName + "." + tableName + "." + primaryKey);
if (mls.getLockHolder().equals(lockId) == true) {
- if (conditionInfo != null)// check if condition is true
+ if (conditionInfo != null)
+ try {
if (conditionInfo.testCondition() == false)
return new ReturnType(ResultType.FAILURE,
"Lock acquired but the condition is not true");
+ } catch (Exception e) {
+ return new ReturnType(ResultType.FAILURE,
+ "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
+ + e.getMessage());
+ }
getDSHandle().executePut(queryObject, MusicUtil.CRITICAL);
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the critical put:" + (end - start) + " ms");
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
index a31e33f9..3c0d4c9d 100755
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/src/main/java/org/onap/music/main/MusicUtil.java
@@ -418,7 +418,7 @@ public class MusicUtil {
* @return
* @throws Exception
*/
- public static Object convertToActualDataType(DataType colType, Object valueObj) {
+ public static Object convertToActualDataType(DataType colType, Object valueObj) throws Exception{
String valueObjString = valueObj + "";
switch (colType.getName()) {
case UUID:
diff --git a/src/main/java/org/onap/music/main/ResultType.java b/src/main/java/org/onap/music/main/ResultType.java
index f19ada4a..6b0c5252 100644
--- a/src/main/java/org/onap/music/main/ResultType.java
+++ b/src/main/java/org/onap/music/main/ResultType.java
@@ -22,7 +22,8 @@
package org.onap.music.main;
public enum ResultType {
- SUCCESS("Success"), FAILURE("Failure");
+ SUCCESS("Success"), FAILURE("Failure"),
+ SYNTAXERROR("SyntaxError"), EXCEPTION("Exception");
private String result;
diff --git a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
index 0265d039..6d8ac088 100755
--- a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
@@ -195,7 +195,7 @@ public class RestMusicAdminAPI {
String ks = row.getString("keyspace_name");
if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
PreparedQueryObject queryObject = new PreparedQueryObject();
- queryObject.appendQueryString("DROP KEYSPACE " + ks + ";");
+ queryObject.appendQueryString("DROP KEYSPACE IF EXISTS " + ks + ";");
MusicCore.nonKeyRelatedPut(queryObject, consistency);
}
}
diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
index f1d88efa..0eedbaa0 100755
--- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
@@ -43,6 +43,7 @@ import org.onap.music.datastore.jsonobjects.JsonKeySpace;
import org.onap.music.datastore.jsonobjects.JsonTable;
import org.onap.music.datastore.jsonobjects.JsonUpdate;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
+import org.onap.music.exceptions.MusicLockingException;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicCore;
@@ -51,6 +52,8 @@ import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
import org.onap.music.main.ReturnType;
import org.onap.music.response.jsonobjects.JsonResponse;
+
+import com.att.eelf.configuration.EELFLogger;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
@@ -144,15 +147,21 @@ public class RestMusicDataAPI {
JsonKeySpace kspObject,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("name") String keyspaceName,
- @Context HttpServletResponse response) throws Exception {
+ @Context HttpServletResponse response) {
Map<String, Object> resultMap = CachingUtil.verifyOnboarding(ns, userId, password);
response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (!resultMap.isEmpty()) {
return resultMap;
}
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "createKeySpace");
+ try {
+ resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ "createKeySpace");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.applicationLogger,
+ "Exception while authenting the user.");
+ return resultMap;
+ }
String newAid = null;
if (!resultMap.isEmpty()) {
if (resultMap.containsKey("aid")) {
@@ -200,7 +209,12 @@ public class RestMusicDataAPI {
queryObject.appendQueryString(
"DELETE FROM admin.keyspace_master where uuid = " + newAid);
queryObject.appendQueryString(";");
- result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ try {
+ result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ } catch (MusicServiceException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ resultMap.put("Exception", e.getMessage());
+ }
resultMap.remove("aid");
resultMap.remove("uuid");
return resultMap;
@@ -209,10 +223,23 @@ public class RestMusicDataAPI {
queryObject = new PreparedQueryObject();
queryObject.appendQueryString(
"UPDATE admin.keyspace_master SET keyspace_name=? where uuid = ?;");
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
+ try {
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
MusicUtil.DEFAULTKEYSPACENAME));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid));
- result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid));
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ resultMap.put("Exception", "Unable to process input data. Invalid input data type. "
+ + "Please check keyspace_name and aid.. ");
+ }
+ try {
+ result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ } catch (MusicServiceException e) {
+ e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger, "Unable to process operation. Error: "+e.getMessage());
+ resultMap.put("Exception", "Unable to process operation. Error: "+e.getMessage());
+ return resultMap;
+ }
resultMap.remove("aid");
resultMap.remove("uuid");
return resultMap;
@@ -233,8 +260,15 @@ public class RestMusicDataAPI {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
}
resultMap.remove("uuid");
- if (CachingUtil.isAAFApplication(ns))
- resultMap.remove("aid");
+ try {
+ if (CachingUtil.isAAFApplication(ns))
+ resultMap.remove("aid");
+ } catch (MusicServiceException e) {
+ e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ resultMap.put("Exception", e.getMessage());
+ return resultMap;
+ }
resultMap.put("Status", String.valueOf(result));
return resultMap;
@@ -366,11 +400,17 @@ public class RestMusicDataAPI {
int counter = 0;
String primaryKey;
for (Map.Entry<String, String> entry : fields.entrySet()) {
- fieldsString.append("" + entry.getKey() + " " + entry.getValue() + "");
+
if (entry.getKey().equals("PRIMARY KEY")) {
- primaryKey = entry.getValue().substring(entry.getValue().indexOf('(') + 1);
- primaryKey = primaryKey.substring(0, primaryKey.indexOf(')'));
- }
+ if(! entry.getValue().contains("("))
+ primaryKey = entry.getValue();
+ else {
+ primaryKey = entry.getValue().substring(entry.getValue().indexOf('(') + 1);
+ primaryKey = primaryKey.substring(0, primaryKey.indexOf(')'));
+ }
+ fieldsString.append("" + entry.getKey() + " (" + primaryKey + ")");
+ } else
+ fieldsString.append("" + entry.getKey() + " " + entry.getValue() + "");
if (counter == fields.size() - 1)
fieldsString.append(")");
else
@@ -500,9 +540,15 @@ public class RestMusicDataAPI {
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception {
- Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "insertIntoTable");
+ @Context HttpServletResponse response) {
+ Map<String, Object> resultMap = null;
+ try {
+ resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ aid, "insertIntoTable");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+ }
response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
@@ -512,7 +558,17 @@ public class RestMusicDataAPI {
ReturnType result = null;
Map<String, Object> valuesMap = insObj.getValues();
PreparedQueryObject queryObject = new PreparedQueryObject();
- TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+ TableMetadata tableInfo = null;
+ try {
+ tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+ if(tableInfo == null)
+ throw new MusicServiceException("Table name doesn't exists. Please check the table name.");
+ } catch (MusicServiceException e) {
+ e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ resultMap.put(ResultType.SYNTAXERROR.getResult(), e.getMessage());
+ return resultMap;
+ }
String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();
StringBuilder fieldsString = new StringBuilder("(vector_ts,");
String vectorTs =
@@ -532,7 +588,13 @@ public class RestMusicDataAPI {
DataType colType = tableInfo.getColumn(entry.getKey()).getType();
- Object formattedValue = MusicUtil.convertToActualDataType(colType, valueObj);
+ Object formattedValue = null;
+ try {
+ formattedValue = MusicUtil.convertToActualDataType(colType, valueObj);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ //return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+ }
valueString.append("?");
queryObject.addValue(formattedValue);
@@ -593,7 +655,7 @@ public class RestMusicDataAPI {
: new ReturnType(ResultType.FAILURE,
"Null result - Please Contact admin").toMap();
} catch (Exception ex) {
- logger.info(EELFLoggerDelegate.applicationLogger, ex.getMessage());
+ logger.error(EELFLoggerDelegate.applicationLogger, ex.getMessage());
return new ReturnType(ResultType.FAILURE, ex.getMessage()).toMap();
}
}
@@ -631,9 +693,15 @@ public class RestMusicDataAPI {
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context UriInfo info, @Context HttpServletResponse response) throws Exception {
- Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "updateTable");
+ @Context UriInfo info, @Context HttpServletResponse response) {
+ Map<String, Object> resultMap;
+ try {
+ resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ aid, "updateTable");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+ }
response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
@@ -651,7 +719,15 @@ public class RestMusicDataAPI {
PreparedQueryObject queryObject = new PreparedQueryObject();
Map<String, Object> valuesMap = updateObj.getValues();
- TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+ TableMetadata tableInfo;
+ try {
+ tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+ } catch (MusicServiceException e) {
+ e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
+ resultMap.put("Exception", e.getMessage());
+ return resultMap;
+ }
if (tableInfo == null) {
return new ReturnType(ResultType.FAILURE,
"Table information not found. Please check input for table name= "
@@ -665,7 +741,13 @@ public class RestMusicDataAPI {
for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
Object valueObj = entry.getValue();
DataType colType = tableInfo.getColumn(entry.getKey()).getType();
- Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
+ Object valueString = null;
+ try {
+ valueString = MusicUtil.convertToActualDataType(colType, valueObj);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ //return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+ }
fieldValueString.append(entry.getKey() + "= ?");
queryObject.addValue(valueString);
if (counter != valuesMap.size() - 1)
@@ -699,7 +781,12 @@ public class RestMusicDataAPI {
RowIdentifier rowId = null;
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
+ if(rowId == null || rowId.primarKeyValue.isEmpty()) {
+ resultMap.put(ResultType.SYNTAXERROR.getResult(), "Mandatory WHERE clause is missing. Please check the input request.");
+ return resultMap;
+ }
} catch (MusicServiceException ex) {
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage());
return new ReturnType(ResultType.FAILURE, ex.getMessage()).toMap();
}
@@ -730,11 +817,21 @@ public class RestMusicDataAPI {
queryObject, lockId, conditionInfo);
} else if (consistency.equalsIgnoreCase("atomic_delete_lock")) {
// this function is mainly for the benchmarks
- operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
- rowId.primarKeyValue, queryObject, conditionInfo);
+ try {
+ operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
+ rowId.primarKeyValue, queryObject, conditionInfo);
+ } catch (MusicLockingException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+ }
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
- operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
- queryObject, conditionInfo);
+ try {
+ operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
+ queryObject, conditionInfo);
+ } catch (MusicLockingException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ return new ReturnType(ResultType.FAILURE, e.getMessage()).toMap();
+ }
}
long actualUpdateCompletionTime = System.currentTimeMillis();
@@ -788,15 +885,25 @@ public class RestMusicDataAPI {
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context UriInfo info, @Context HttpServletResponse response) throws Exception {
- Map<String, Object> resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "deleteFromTable");
+ @Context UriInfo info, @Context HttpServletResponse response) {
+ Map<String, Object> resultMap = null;
+ try {
+ resultMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ aid, "deleteFromTable");
+ } catch (Exception e) {
+ resultMap.put("Exception", e.getMessage());
+ return resultMap;
+ }
response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
return resultMap;
}
+ if(delObj == null) {
+ resultMap.put("Exception", "Request body is missing. Please check your input data and retry.");
+ return resultMap;
+ }
PreparedQueryObject queryObject = new PreparedQueryObject();
StringBuilder columnString = new StringBuilder();
@@ -851,21 +958,25 @@ public class RestMusicDataAPI {
String consistency = delObj.getConsistencyInfo().get("type");
ReturnType operationResult = null;
-
- if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL))
- operationResult = MusicCore.eventualPut(queryObject);
- else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
- String lockId = delObj.getConsistencyInfo().get("lockId");
- operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
- queryObject, lockId, conditionInfo);
- } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
- operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
- queryObject, conditionInfo);
- }
- else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
- operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, rowId.primarKeyValue,
- queryObject, conditionInfo);
- }
+ try {
+ if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL))
+ operationResult = MusicCore.eventualPut(queryObject);
+ else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
+ String lockId = delObj.getConsistencyInfo().get("lockId");
+ operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
+ queryObject, lockId, conditionInfo);
+ } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
+ operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
+ queryObject, conditionInfo);
+ }
+ else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
+ operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, rowId.primarKeyValue,
+ queryObject, conditionInfo);
+ }
+ } catch (MusicLockingException e) {
+ resultMap.put("Exception", "Unable to perform Delete operation. Exception from music: "+e.getMessage());
+ return resultMap;
+ }
try {
return operationResult.toMap();
} catch (NullPointerException e) {
@@ -1077,7 +1188,6 @@ public class RestMusicDataAPI {
* @param limit
* @return
* @throws MusicServiceException
- * @throws Exception
*/
public PreparedQueryObject selectSpecificQuery(String version, String minorVersion,
String patchVersion, String aid, String ns, String userId, String password,
@@ -1108,7 +1218,6 @@ public class RestMusicDataAPI {
* @param queryObject
* @return
* @throws MusicServiceException
- * @throws Exception
*/
private RowIdentifier getRowIdentifier(String keyspace, String tablename,
MultivaluedMap<String, String> rowParams, PreparedQueryObject queryObject)
@@ -1130,7 +1239,12 @@ public class RestMusicDataAPI {
List<String> valueList = entry.getValue();
String indValue = valueList.get(0);
DataType colType = tableInfo.getColumn(entry.getKey()).getType();
- Object formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
+ Object formattedValue = null;
+ try {
+ formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ }
primaryKey.append(indValue);
rowSpec.append(keyName + "= ?");
queryObject.addValue(formattedValue);