summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitmodules5
-rw-r--r--WebContent/WEB-INF/web.xml3
m---------distributed-kv-store0
-rw-r--r--distribution/cassandra/docker-entrypoint.sh103
-rwxr-xr-xpom.xml4
-rw-r--r--src/main/java/org/onap/music/datastore/MusicDataStore.java7
-rw-r--r--src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java53
-rwxr-xr-xsrc/main/java/org/onap/music/main/CachingUtil.java15
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java8
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java19
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicAdminAPI.java317
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicDataAPI.java725
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicQAPI.java389
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicData.java368
-rw-r--r--version.properties4
15 files changed, 1179 insertions, 841 deletions
diff --git a/.gitmodules b/.gitmodules
index 4495accf..e69de29b 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,5 +0,0 @@
-[submodule "distributed-kv-store"]
- path = distributed-kv-store
- url = ../music/distributed-kv-store
- branch = .
- ignore = dirty
diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml
index 6d8e67c9..59fe1251 100644
--- a/WebContent/WEB-INF/web.xml
+++ b/WebContent/WEB-INF/web.xml
@@ -17,7 +17,8 @@
<param-value>
io.swagger.jaxrs.json,
io.swagger.jaxrs.listing,
- org.onap.music.rest
+ org.onap.music.rest,
+ org.onap.music.exceptions
</param-value>
</init-param>
<init-param>
diff --git a/distributed-kv-store b/distributed-kv-store
deleted file mode 160000
-Subproject 749870b8ce9dddd09e98a65fc4c57b295880c8b
diff --git a/distribution/cassandra/docker-entrypoint.sh b/distribution/cassandra/docker-entrypoint.sh
index 2e2c657e..f05daed2 100644
--- a/distribution/cassandra/docker-entrypoint.sh
+++ b/distribution/cassandra/docker-entrypoint.sh
@@ -9,64 +9,65 @@ done
# first arg is `-f` or `--some-option`
# or there are no args
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
- set -- cassandra -f "$@"
+ set -- cassandra -f "$@"
fi
# allow the container to be started with `--user`
if [ "$1" = 'cassandra' -a "$(id -u)" = '0' ]; then
- chown -R cassandra /var/lib/cassandra /var/log/cassandra "$CASSANDRA_CONFIG"
- exec gosu cassandra "$BASH_SOURCE" "$@"
+ chown -R cassandra /var/lib/cassandra /var/log/cassandra "$CASSANDRA_CONFIG"
+ exec gosu cassandra "$BASH_SOURCE" "$@"
fi
if [ "$1" = 'cassandra' ]; then
- : ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}
-
- : ${CASSANDRA_LISTEN_ADDRESS='auto'}
- if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
- CASSANDRA_LISTEN_ADDRESS="$(hostname --ip-address)"
- fi
-
- : ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}
-
- if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
- CASSANDRA_BROADCAST_ADDRESS="$(hostname --ip-address)"
- fi
- : ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}
-
- if [ -n "${CASSANDRA_NAME:+1}" ]; then
- : ${CASSANDRA_SEEDS:="cassandra"}
- fi
- : ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}
-
- sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONFIG/cassandra.yaml"
-
- for yaml in \
- broadcast_address \
- broadcast_rpc_address \
- cluster_name \
- endpoint_snitch \
- listen_address \
- num_tokens \
- rpc_address \
- start_rpc \
- ; do
- var="CASSANDRA_${yaml^^}"
- val="${!var}"
- if [ "$val" ]; then
- sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONFIG/cassandra.yaml"
- fi
- done
-
- for rackdc in dc rack; do
- var="CASSANDRA_${rackdc^^}"
- val="${!var}"
- if [ "$val" ]; then
- sed -ri 's/^('"$rackdc"'=).*/\1 '"$val"'/' "$CASSANDRA_CONFIG/cassandra-rackdc.properties"
- fi
- done
+ : ${CASSANDRA_RPC_ADDRESS='0.0.0.0'}
+
+ : ${CASSANDRA_LISTEN_ADDRESS='auto'}
+ if [ "$CASSANDRA_LISTEN_ADDRESS" = 'auto' ]; then
+ CASSANDRA_LISTEN_ADDRESS="$(hostname --ip-address)"
+ fi
+
+ : ${CASSANDRA_BROADCAST_ADDRESS="$CASSANDRA_LISTEN_ADDRESS"}
+
+ if [ "$CASSANDRA_BROADCAST_ADDRESS" = 'auto' ]; then
+ CASSANDRA_BROADCAST_ADDRESS="$(hostname --ip-address)"
+ fi
+ : ${CASSANDRA_BROADCAST_RPC_ADDRESS:=$CASSANDRA_BROADCAST_ADDRESS}
+
+ if [ -n "${CASSANDRA_NAME:+1}" ]; then
+ : ${CASSANDRA_SEEDS:="cassandra"}
+ fi
+ : ${CASSANDRA_SEEDS:="$CASSANDRA_BROADCAST_ADDRESS"}
+
+ sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONFIG/cassandra.yaml"
+
+ for yaml in \
+ broadcast_address \
+ broadcast_rpc_address \
+ cluster_name \
+ endpoint_snitch \
+ listen_address \
+ num_tokens \
+ rpc_address \
+ start_rpc \
+ ; do
+ var="CASSANDRA_${yaml^^}"
+ val="${!var}"
+ if [ "$val" ]; then
+ sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONFIG/cassandra.yaml"
+ fi
+ done
+
+ for rackdc in dc rack; do
+ var="CASSANDRA_${rackdc^^}"
+ val="${!var}"
+ if [ "$val" ]; then
+ sed -ri 's/^('"$rackdc"'=).*/\1 '"$val"'/' "$CASSANDRA_CONFIG/cassandra-rackdc.properties"
+ fi
+ done
fi
-for f in /docker-entrypoint-initdb.d/*.cql; do
+echo "Updating username and password"
+for f in /docker-entrypoint-initdb.d/music*.cql; do
if [ "${CASSUSER}" ]; then
sed -ri 's/CASSUSER/'${CASSUSER}'/' "$f"
fi
@@ -74,11 +75,12 @@ for f in /docker-entrypoint-initdb.d/*.cql; do
sed -ri 's/CASSPASS/'${CASSPASS}'/' "$f"
fi
done
+echo "Updating username and password - Complete"
-echo "################################ Let run Scripts ##############################"
+echo "################################ Let run cql's ##############################"
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
@@ -88,6 +90,5 @@ for f in /docker-entrypoint-initdb.d/*; do
esac
echo
done
-echo "################################ Let run Scripts End ##############################"
exec "$@"
diff --git a/pom.xml b/pom.xml
index 60880b1e..59ce19a8 100755
--- a/pom.xml
+++ b/pom.xml
@@ -25,7 +25,7 @@
<groupId>org.onap.music</groupId>
<artifactId>MUSIC</artifactId>
<packaging>war</packaging>
- <version>2.4.22</version>
+ <version>2.5.2</version>
<description>
This is the MUSIC REST interface, packaged as a war file.
</description>
@@ -33,7 +33,7 @@
<parent>
<groupId>org.onap.oparent</groupId>
<artifactId>oparent</artifactId>
- <version>1.1.0</version>
+ <version>0.1.1</version>
<relativePath />
</parent>
diff --git a/src/main/java/org/onap/music/datastore/MusicDataStore.java b/src/main/java/org/onap/music/datastore/MusicDataStore.java
index c64a96b3..278cf768 100644
--- a/src/main/java/org/onap/music/datastore/MusicDataStore.java
+++ b/src/main/java/org/onap/music/datastore/MusicDataStore.java
@@ -375,11 +375,12 @@ public class MusicDataStore {
}
logger.info(EELFLoggerDelegate.applicationLogger,
"Executing Eventual get query:" + queryObject.getQuery());
- PreparedStatement preparedEventualGet = session.prepare(queryObject.getQuery());
- preparedEventualGet.setConsistencyLevel(ConsistencyLevel.ONE);
+
ResultSet results = null;
try {
- results = session.execute(preparedEventualGet.bind(queryObject.getValues().toArray()));
+ PreparedStatement preparedEventualGet = session.prepare(queryObject.getQuery());
+ preparedEventualGet.setConsistencyLevel(ConsistencyLevel.ONE);
+ results = session.execute(preparedEventualGet.bind(queryObject.getValues().toArray()));
} catch (Exception ex) {
logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.UNKNOWNERROR+ "[" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
diff --git a/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java b/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java
new file mode 100644
index 00000000..14a23d1f
--- /dev/null
+++ b/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java
@@ -0,0 +1,53 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=============================================
+ * ====================================================================
+ */
+package org.onap.music.exceptions;
+
+import java.io.EOFException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+import org.codehaus.jackson.map.exc.UnrecognizedPropertyException;
+import org.onap.music.main.ResultType;
+import org.onap.music.response.jsonobjects.JsonResponse;
+
+@Provider
+public class MusicExceptionMapper implements ExceptionMapper<Exception> {
+ @Override
+ public Response toResponse(Exception exception) {
+ if(exception instanceof UnrecognizedPropertyException) {
+ return Response.status(Response.Status.BAD_REQUEST).
+ entity(new JsonResponse(ResultType.FAILURE).setError("Unknown field :"+((UnrecognizedPropertyException) exception).getUnrecognizedPropertyName()).toMap()).
+ build();
+ }
+ else if(exception instanceof EOFException) {
+ return Response.status(Response.Status.BAD_REQUEST).
+ entity(new JsonResponse(ResultType.FAILURE).setError("Request body cannot be empty").toMap()).
+ build();
+ }
+ else {
+ return Response.status(Response.Status.BAD_REQUEST).
+ entity(new JsonResponse(ResultType.FAILURE).setError(exception.getMessage()).toMap()).
+ build();
+ }
+ }
+}
diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java
index 2a105c24..b59e81b3 100755
--- a/src/main/java/org/onap/music/main/CachingUtil.java
+++ b/src/main/java/org/onap/music/main/CachingUtil.java
@@ -45,6 +45,7 @@ import com.att.eelf.configuration.EELFLogger;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
+import com.datastax.driver.core.exceptions.InvalidQueryException;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
@@ -241,7 +242,13 @@ public class CachingUtil implements Runnable {
pQuery.appendQueryString(
"SELECT is_aaf from admin.keyspace_master where application_name = '"
+ namespace + "' allow filtering");
- Row rs = MusicCore.get(pQuery).one();
+ Row rs = null;
+ try {
+ rs = MusicCore.get(pQuery).one();
+ } catch(InvalidQueryException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+e.getMessage());
+ throw new MusicServiceException("Please make sure admin.keyspace_master table is configured.");
+ }
try {
isAAF = String.valueOf(rs.getBool("is_aaf"));
if(isAAF != null)
@@ -333,7 +340,11 @@ public class CachingUtil implements Runnable {
e.printStackTrace();
resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
return resultMap;
- }
+ } catch (InvalidQueryException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+e.getMessage());
+ resultMap.put("Exception", "Please make sure admin.keyspace_master table is configured.");
+ return resultMap;
+ }
if (rs == null) {
logger.error(EELFLoggerDelegate.errorLogger,"Application is not onboarded. Please contact admin.");
resultMap.put("Exception", "Application is not onboarded. Please contact admin.");
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
index abeedf6f..d38a4d6a 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;
- String isAAFApp = CachingUtil.isAAFApplication(nameSpace);
+ String isAAFApp = null;
+ try {
+ isAAFApp= CachingUtil.isAAFApplication(nameSpace);
+ } catch(MusicServiceException e) {
+ resultMap.put("Exception", e.getMessage());
+ return resultMap;
+ }
if(isAAFApp == null) {
resultMap.put("Exception", "Namespace: "+nameSpace+" doesn't exist. Please make sure ns(appName)"
+ " is correct and Application is onboarded.");
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
index c0b968be..b6cc1902 100755
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/src/main/java/org/onap/music/main/MusicUtil.java
@@ -25,15 +25,12 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.UUID;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.exceptions.MusicServiceException;
-
import com.datastax.driver.core.DataType;
/**
@@ -51,21 +48,22 @@ public class MusicUtil {
public static final String EVENTUAL = "eventual";
public static final String CRITICAL = "critical";
public static final String ATOMICDELETELOCK = "atomic_delete_lock";
-
public static final String DEFAULTKEYSPACENAME = "TBD";
+ private static final String LOCALHOST = "localhost";
+ private static final String PROPERTIES_FILE = "/opt/app/music/etc/music.properties";
private static int myId = 0;
private static ArrayList<String> allIds = new ArrayList<>();
private static String publicIp = "";
private static ArrayList<String> allPublicIps = new ArrayList<>();
- private static String myZkHost = "localhost";
- private static String myCassaHost = "localhost";
- private static String defaultMusicIp = "localhost";
+ private static String myZkHost = LOCALHOST;
+ private static String myCassaHost = LOCALHOST;
+ private static String defaultMusicIp = LOCALHOST;
private static boolean debug = true;
private static String version = "2.3.0";
- private static String musicRestIp = "localhost";
- private static String musicPropertiesFilePath = "/opt/app/music/etc/music.properties";
+ private static String musicRestIp = LOCALHOST;
+ private static String musicPropertiesFilePath = PROPERTIES_FILE;
private static long defaultLockLeasePeriod = 6000;
private static final String[] propKeys = new String[] { "zookeeper.host", "cassandra.host", "music.ip", "debug",
"version", "music.rest.ip", "music.properties", "lock.lease.period", "id", "all.ids", "public.ip",
@@ -424,9 +422,10 @@ public class MusicUtil {
* @param colType
* @param valueObj
* @return
+ * @throws MusicTypeConversionException
* @throws Exception
*/
- public static Object convertToActualDataType(DataType colType, Object valueObj) throws Exception{
+ 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/rest/RestMusicAdminAPI.java b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
index 2d7aa833..c66944cb 100755
--- a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
@@ -27,15 +27,16 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonOnboard;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
@@ -46,18 +47,19 @@ import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
-
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
-@Path("/v{version: [0-9]+}/admin")
+@Path("/v2/admin")
+// @Path("/v{version: [0-9]+}/admin")
// @Path("/admin")
@Api(value = "Admin Api", hidden = true)
public class RestMusicAdminAPI {
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class);
+ private static EELFLoggerDelegate logger =
+ EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class);
/*
* API to onboard an application with MUSIC. This is the mandatory first step.
@@ -68,20 +70,20 @@ public class RestMusicAdminAPI {
@ApiOperation(value = "Onboard application", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> onboardAppWithMusic(JsonOnboard jsonObj,
- @Context HttpServletResponse response) throws Exception {
+ public Response onboardAppWithMusic(JsonOnboard jsonObj) throws Exception {
+ ResponseBuilder response =
+ Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
Map<String, Object> resultMap = new HashMap<>();
String appName = jsonObj.getAppname();
String userId = jsonObj.getUserId();
String isAAF = jsonObj.getIsAAF();
String password = jsonObj.getPassword();
- response.addHeader("X-latestVersion", MusicUtil.getVersion());
if (appName == null || userId == null || isAAF == null || password == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO,
+ ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
resultMap.put("Exception",
"Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.");
- response.setStatus(401);
- return resultMap;
+ return Response.status(Status.UNAUTHORIZED).entity(resultMap).build();
}
PreparedQueryObject pQuery = new PreparedQueryObject();
@@ -92,8 +94,7 @@ public class RestMusicAdminAPI {
if (!rs.all().isEmpty()) {
resultMap.put("Exception", "Application " + appName
+ " has already been onboarded. Please contact admin.");
- response.setStatus(400);
- return resultMap;
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
pQuery = new PreparedQueryObject();
@@ -114,37 +115,34 @@ public class RestMusicAdminAPI {
if (returnStr.contains("Failure")) {
resultMap.put("Exception",
"Oops. Something wrong with onboarding process. Please retry later or contact admin.");
- response.setStatus(400);
- return resultMap;
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
CachingUtil.updateisAAFCache(appName, isAAF);
resultMap.put("Success", "Your application " + appName + " has been onboarded with MUSIC.");
resultMap.put("Generated AID", uuid);
- return resultMap;
+ return Response.status(Status.OK).entity(resultMap).build();
}
-
-
+
+
@POST
@Path("/search")
@ApiOperation(value = "Search Onboard application", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> getOnboardedInfoSearch(
- JsonOnboard jsonObj,
- @Context HttpServletResponse response) throws Exception {
+ public Response getOnboardedInfoSearch(JsonOnboard jsonObj) throws Exception {
Map<String, Object> resultMap = new HashMap<>();
-
- response.addHeader("X-latestVersion", MusicUtil.getVersion());
+ ResponseBuilder response =
+ Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
String appName = jsonObj.getAppname();
String uuid = jsonObj.getAid();
String isAAF = jsonObj.getIsAAF();
-
+
if (appName == null && uuid == null && isAAF == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO,
+ ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
resultMap.put("Exception",
"Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.");
- response.setStatus(401);
- return resultMap;
+ return Response.status(Status.UNAUTHORIZED).entity(resultMap).build();
}
PreparedQueryObject pQuery = new PreparedQueryObject();
@@ -153,12 +151,12 @@ public class RestMusicAdminAPI {
cql = cql + "application_name = ? AND ";
if (uuid != null)
cql = cql + "uuid = ? AND ";
- if(isAAF != null)
- cql = cql + "is_aaf = ?";
-
- if(cql.endsWith("AND "))
- cql = cql.trim().substring(0, cql.length()-4);
- System.out.println("Query is: "+cql);
+ if (isAAF != null)
+ cql = cql + "is_aaf = ?";
+
+ if (cql.endsWith("AND "))
+ cql = cql.trim().substring(0, cql.length() - 4);
+ System.out.println("Query is: " + cql);
cql = cql + " allow filtering";
System.out.println("Get OnboardingInfo CQL: " + cql);
pQuery.appendQueryString(cql);
@@ -167,26 +165,26 @@ public class RestMusicAdminAPI {
if (uuid != null)
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
if (isAAF != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), Boolean.parseBoolean(isAAF)));
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(),
+ Boolean.parseBoolean(isAAF)));
ResultSet rs = MusicCore.get(pQuery);
Iterator<Row> it = rs.iterator();
while (it.hasNext()) {
Row row = (Row) it.next();
- resultMap.put( row.getUUID("uuid").toString(),row.getString("keyspace_name"));
+ resultMap.put(row.getUUID("uuid").toString(), row.getString("keyspace_name"));
}
if (resultMap.isEmpty()) {
- if(uuid != null) {
- resultMap.put("Exception", "Please make sure Aid is correct and application is onboarded.");
- response.setStatus(400);
- return resultMap;
- }else {
+ if (uuid != null) {
resultMap.put("Exception",
- "Application is not onboarded. Please make sure all the information is correct.");
- response.setStatus(400);
- return resultMap;
+ "Please make sure Aid is correct and application is onboarded.");
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
+ } else {
+ resultMap.put("Exception",
+ "Application is not onboarded. Please make sure all the information is correct.");
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
}
- return resultMap;
+ return Response.status(Status.OK).entity(resultMap).build();
}
@@ -195,53 +193,52 @@ public class RestMusicAdminAPI {
@ApiOperation(value = "Delete Onboard application", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> deleteOnboardApp(JsonOnboard jsonObj,
- @Context HttpServletResponse response) throws Exception {
+ public Response deleteOnboardApp(JsonOnboard jsonObj) throws Exception {
Map<String, Object> resultMap = new HashMap<>();
- response.addHeader("X-latestVersion", MusicUtil.getVersion());
+ ResponseBuilder response =
+ Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
String appName = jsonObj.getAppname();
String aid = jsonObj.getAid();
PreparedQueryObject pQuery = new PreparedQueryObject();
String consistency = MusicUtil.EVENTUAL;;
if (appName == null && aid == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
resultMap.put("Exception", "Please make sure either appName(ns) or Aid is present");
- response.setStatus(400);
- return resultMap;
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
if (aid != null) {
- pQuery.appendQueryString("SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString(aid)));
- Row row = MusicCore.get(pQuery).one();
- if(row!=null) {
- String ks = row.getString("keyspace_name");
- if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
- PreparedQueryObject queryObject = new PreparedQueryObject();
- queryObject.appendQueryString("DROP KEYSPACE IF EXISTS " + ks + ";");
- MusicCore.nonKeyRelatedPut(queryObject, consistency);
- }
- }
- pQuery = new PreparedQueryObject();
- pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ? IF EXISTS");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString(aid)));
- ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
- if (result==ResultType.SUCCESS) {
- resultMap.put("Success", "Your application has been deleted successfully");
- } else {
- resultMap.put("Exception","Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ pQuery.appendQueryString(
+ "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
+ UUID.fromString(aid)));
+ Row row = MusicCore.get(pQuery).one();
+ if (row != null) {
+ String ks = row.getString("keyspace_name");
+ if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("DROP KEYSPACE IF EXISTS " + ks + ";");
+ MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ }
+ }
+ pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ? IF EXISTS");
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
+ UUID.fromString(aid)));
+ ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
+ if (result == ResultType.SUCCESS) {
+ resultMap.put("Success", "Your application has been deleted successfully");
+ } else {
+ resultMap.put("Exception",
+ "Oops. Something went wrong. Please make sure Aid is correct or Application is onboarded");
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- return resultMap;
+ }
+ return Response.status(Status.OK).entity(resultMap).build();
}
-
-
-
-
+
pQuery.appendQueryString(
"select uuid from admin.keyspace_master where application_name = ? allow filtering");
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
@@ -251,35 +248,37 @@ public class RestMusicAdminAPI {
if (rows.size() == 0) {
resultMap.put("Exception",
"Application not found. Please make sure Application exists.");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
} else if (rows.size() == 1) {
uuid = rows.get(0).getUUID("uuid").toString();
pQuery = new PreparedQueryObject();
- pQuery.appendQueryString("SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString(uuid)));
- Row row = MusicCore.get(pQuery).one();
- String ks = row.getString("keyspace_name");
- if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
- PreparedQueryObject queryObject = new PreparedQueryObject();
- queryObject.appendQueryString("DROP KEYSPACE " + ks + ";");
- MusicCore.nonKeyRelatedPut(queryObject, consistency);
- }
-
+ pQuery.appendQueryString(
+ "SELECT keyspace_name FROM admin.keyspace_master WHERE uuid = ?");
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
+ UUID.fromString(uuid)));
+ Row row = MusicCore.get(pQuery).one();
+ String ks = row.getString("keyspace_name");
+ if (!ks.equals(MusicUtil.DEFAULTKEYSPACENAME)) {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("DROP KEYSPACE " + ks + ";");
+ MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ }
+
pQuery = new PreparedQueryObject();
pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ?");
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
UUID.fromString(uuid)));
MusicCore.eventualPut(pQuery);
resultMap.put("Success", "Your application " + appName + " has been deleted.");
- return resultMap;
+ return Response.status(Status.OK).entity(resultMap).build();
} else {
- resultMap.put("Failure", "More than one Aid exists for this application, so please provide Aid.");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MULTIPLERECORDS ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ resultMap.put("Failure",
+ "More than one Aid exists for this application, so please provide Aid.");
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MULTIPLERECORDS,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
}
@@ -289,10 +288,10 @@ public class RestMusicAdminAPI {
@ApiOperation(value = "Update Onboard application", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> updateOnboardApp(JsonOnboard jsonObj,
- @Context HttpServletResponse response) throws Exception {
+ public Response updateOnboardApp(JsonOnboard jsonObj) throws Exception {
Map<String, Object> resultMap = new HashMap<>();
- response.addHeader("X-latestVersion", MusicUtil.getVersion());
+ ResponseBuilder response =
+ Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
String aid = jsonObj.getAid();
String appName = jsonObj.getAppname();
String userId = jsonObj.getUserId();
@@ -303,69 +302,69 @@ public class RestMusicAdminAPI {
if (aid == null) {
resultMap.put("Exception", "Please make sure Aid is present");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
if (appName == null && userId == null && password == null && isAAF == null) {
resultMap.put("Exception",
"No parameters found to update. Please update atleast one parameter.");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
-
- if(appName!=null) {
- pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "select uuid from admin.keyspace_master where application_name = ? allow filtering");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- ResultSet rs = MusicCore.get(pQuery);
- if (!rs.all().isEmpty()) {
- resultMap.put("Exception", "Application " + appName
- + " has already been onboarded. Please contact admin.");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.ALREADYEXIST ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
- }
+
+ if (appName != null) {
+ pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString(
+ "select uuid from admin.keyspace_master where application_name = ? allow filtering");
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ ResultSet rs = MusicCore.get(pQuery);
+ if (!rs.all().isEmpty()) {
+ resultMap.put("Exception", "Application " + appName
+ + " has already been onboarded. Please contact admin.");
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.ALREADYEXIST,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
+ }
+ }
+
+ pQuery = new PreparedQueryObject();
+ StringBuilder preCql = new StringBuilder("UPDATE admin.keyspace_master SET ");
+ if (appName != null)
+ preCql.append(" application_name = ?,");
+ if (userId != null)
+ preCql.append(" username = ?,");
+ if (password != null)
+ preCql.append(" password = ?,");
+ if (isAAF != null)
+ preCql.append(" is_aaf = ?,");
+ preCql.deleteCharAt(preCql.length() - 1);
+ preCql.append(" WHERE uuid = ? IF EXISTS");
+ pQuery.appendQueryString(preCql.toString());
+ if (appName != null)
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ if (userId != null)
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ if (password != null)
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
+ if (isAAF != null)
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
+
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid)));
+ ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
+
+ if (result == ResultType.SUCCESS) {
+ resultMap.put("Success", "Your application has been updated successfully");
+ } else {
+ resultMap.put("Exception",
+ "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded");
+ logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA,
+ ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
-
- pQuery = new PreparedQueryObject();
- StringBuilder preCql = new StringBuilder("UPDATE admin.keyspace_master SET ");
- if (appName != null)
- preCql.append(" application_name = ?,");
- if (userId != null)
- preCql.append(" username = ?,");
- if (password != null)
- preCql.append(" password = ?,");
- if (isAAF != null)
- preCql.append(" is_aaf = ?,");
- preCql.deleteCharAt(preCql.length() - 1);
- preCql.append(" WHERE uuid = ? IF EXISTS");
- pQuery.appendQueryString(preCql.toString());
- if (appName != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- if (userId != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- if (password != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
- if (isAAF != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
-
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), UUID.fromString(aid)));
- ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
-
- if (result==ResultType.SUCCESS) {
- resultMap.put("Success", "Your application has been updated successfully");
- } else {
- resultMap.put("Exception",
- "Oops. Something went wrong. Please make sure Aid is correct and application is onboarded");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return resultMap;
- }
-
- return resultMap;
+
+ return Response.status(Status.OK).entity(resultMap).build();
}
}
diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
index 2d095949..53ed9e5b 100755
--- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
@@ -1,16 +1,20 @@
/*
- * ============LICENSE_START========================================== org.onap.music
- * =================================================================== Copyright (c) 2017 AT&T
- * Intellectual Property ===================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*
* ============LICENSE_END=============================================
* ====================================================================
@@ -18,11 +22,9 @@
package org.onap.music.rest;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -33,8 +35,12 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
@@ -56,7 +62,6 @@ 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;
@@ -65,7 +70,9 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
-@Path("/v{version: [0-9]+}/keyspaces")
+/* Version 2 Class */
+//@Path("/v{version: [0-9]+}/keyspaces")
+@Path("/v2/keyspaces")
@Api(value = "Data Api")
public class RestMusicDataAPI {
/*
@@ -82,18 +89,23 @@ public class RestMusicDataAPI {
* be the latest PATCH version of the MINOR requested by the client, or the latest PATCH version
* of the MAJOR (if not specified by the client on the request) - Contains a single position
* value (e.g. if the full version is 1.24.5, X-patchVersion = "5") - Is mandatory for the
- * server on response
+ * server on response (CURRENTLY NOT USED)
*
*** X-latestVersion *** - Used only to communicate an API's latest version - Is mandatory for the
* server on response, and shall include the entire version of the API (e.g. if the full version
* is 1.24.5, X-latestVersion = "1.24.5") - Used in the response to inform clients that they are
- * not using the latest version of the API
+ * not using the latest version of the API (CURRENTLY NOT USED)
*
*/
private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
- private static String xLatestVersion = "X-latestVersion";
-
+ private static final String XLATESTVERSION = "X-latestVersion";
+ private static final String XMINORVERSION = "X-minorVersion";
+ private static final String XPATCHVERSION = "X-patchVersion";
+ private static final String NS = "ns";
+ private static final String USERID = "userId";
+ private static final String PASSWORD = "password";
+
private class RowIdentifier {
public String primarKeyValue;
public StringBuilder rowIdString;
@@ -119,6 +131,37 @@ public class RestMusicDataAPI {
}
return major;
}
+
+ /**
+ * Currently this will build a header with X-latestVersion, X-minorVersion and X-pathcVersion
+ * X-latestVerstion will be equal to the latest full version.
+ * X-minorVersion - will be equal to the latest minor version.
+ * X-pathVersion - will be equal to the latest patch version.
+ * Future plans will change this.
+ * @param response
+ * @param major
+ * @param minor
+ * @param patch
+ * @return
+ */
+ private ResponseBuilder buildVersionResponse(String major, String minor, String patch) {
+ ResponseBuilder response = Response.noContent();
+ String versionIn = buildVersion(major,minor,patch);
+ String version = MusicUtil.getVersion();
+ String[] verArray = version.split("\\.",3);
+ if ( minor != null ) {
+ response.header(XMINORVERSION,minor);
+ } else {
+ response.header(XMINORVERSION,verArray[1]);
+ }
+ if ( patch != null ) {
+ response.header(XPATCHVERSION,patch);
+ } else {
+ response.header(XPATCHVERSION,verArray[2]);
+ }
+ response.header(XLATESTVERSION,version);
+ return response;
+ }
/**
* Create Keyspace REST
@@ -133,53 +176,47 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Create Keyspace", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> createKeySpace(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ //public Map<String, Object> createKeySpace(
+ public Response createKeySpace(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
JsonKeySpace kspObject,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("name") String keyspaceName,
- @Context HttpServletResponse response) {
+ @ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap = CachingUtil.verifyOnboarding(ns, userId, password);
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.status(Status.UNAUTHORIZED);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
if(kspObject == null || kspObject.getReplicationInfo() == null) {
- authMap.put(ResultType.EXCEPTION.getResult(), ResultType.BODYMISSING.getResult());
- response.setStatus(401);
- return authMap;
- }
+ authMap.put(ResultType.EXCEPTION.getResult(), ResultType.BODYMISSING.getResult());
+ response.status(Status.BAD_REQUEST);
+ return response.entity(authMap).build();
+ }
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "createKeySpace");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Unable to authenticate.").toMap();
- }
+ authMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ "createKeySpace");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ response.status(Status.BAD_REQUEST);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError("Unable to authenticate.").toMap()).build();
+ }
String newAid = null;
if (!authMap.isEmpty()) {
if (authMap.containsKey("aid")) {
newAid = (String) authMap.get("aid");
} else {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.status(Status.UNAUTHORIZED);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
}
@@ -214,8 +251,7 @@ public class RestMusicDataAPI {
logger.info(EELFLoggerDelegate.applicationLogger, "result = " + result);
} catch ( MusicServiceException ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("err:" + ex.getMessage()).toMap()).build();
}
try {
@@ -229,7 +265,7 @@ public class RestMusicDataAPI {
queryObject.appendQueryString(";");
MusicCore.nonKeyRelatedPut(queryObject, consistency);
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
}
try {
@@ -250,11 +286,10 @@ public class RestMusicDataAPI {
MusicCore.eventualPut(queryObject);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ return response.status(Response.Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
- return new JsonResponse(ResultType.SUCCESS).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Keyspace " + keyspaceName + " Created").toMap()).build();
}
/**
@@ -268,31 +303,23 @@ public class RestMusicDataAPI {
@Path("/{name}")
@ApiOperation(value = "Delete Keyspace", response = String.class)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> dropKeySpace(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ //public Map<String, Object> dropKeySpace(
+ public Response dropKeySpace(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("name") String keyspaceName,
- @Context HttpServletResponse response) throws Exception {
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password,
- keyspaceName, aid, "dropKeySpace");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
+ @ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
+ Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password,keyspaceName, aid, "dropKeySpace");
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- response.setStatus(401);
- return authMap;
+ return response.status(Status.UNAUTHORIZED).entity(authMap).build();
}
String consistency = MusicUtil.EVENTUAL;// for now this needs only
@@ -308,9 +335,9 @@ public class RestMusicDataAPI {
long count = row.getLong(0);
if (count == 0) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Keyspace not found. Please make sure keyspace exists.").toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Keyspace not found. Please make sure keyspace exists.").toMap()).build();
+ // Admin Functions:
} else if (count == 1) {
pQuery = new PreparedQueryObject();
pQuery.appendQueryString(
@@ -328,14 +355,20 @@ public class RestMusicDataAPI {
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString("DROP KEYSPACE " + keyspaceName + ";");
- return new JsonResponse(MusicCore.nonKeyRelatedPut(queryObject, consistency)).toMap();
+ ResultType result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ if ( result.equals(ResultType.FAILURE) ) {
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(result).setError("Error Deleteing Keyspace " + keyspaceName).toMap()).build();
+ }
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Keyspace " + keyspaceName + " Deleted").toMap()).build();
}
/**
*
* @param tableObj
+ * @param version
* @param keyspace
* @param tablename
+ * @param headers
* @return
* @throws Exception
*/
@@ -344,36 +377,26 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Create Table", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> createTable(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ //public Map<String, Object> createTable(
+ public Response createTable(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
- JsonTable tableObj,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("keyspace") String keyspace,
- @ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception {
-
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
+ JsonTable tableObj,
+ @ApiParam(value = "Keyspace Name",required = true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "createTable");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
String consistency = MusicUtil.EVENTUAL;
// for now this needs only eventual consistency
@@ -386,15 +409,15 @@ public class RestMusicDataAPI {
for (Map.Entry<String, String> entry : fields.entrySet()) {
if (entry.getKey().equals("PRIMARY KEY")) {
- 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 + ")");
+ 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() + "");
+ fieldsString.append("" + entry.getKey() + " " + entry.getValue() + "");
if (counter == fields.size() - 1)
fieldsString.append(")");
else
@@ -437,12 +460,14 @@ public class RestMusicDataAPI {
try {
result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.MUSICSERVICEERROR);
+ response.status(Status.BAD_REQUEST);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
-
- return new JsonResponse(result).toMap();
+ if ( result.equals(ResultType.FAILURE) ) {
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(result).setError("Error Creating Table " + tablename).toMap()).build();
+ }
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("TableName " + tablename + " Created under keyspace " + keyspace).toMap()).build();
}
/**
@@ -457,36 +482,28 @@ public class RestMusicDataAPI {
@Path("/{keyspace}/tables/{tablename}/index/{field}")
@ApiOperation(value = "Create Index", response = String.class)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> createIndex(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ public Response createIndex(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("keyspace") String keyspace,
- @ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename,
- @ApiParam(value = "Field Name",
- required = true) @PathParam("field") String fieldName,
- @Context UriInfo info, @Context HttpServletResponse response) throws Exception {
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "createIndex");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
+ @ApiParam(value = "Keyspace Name",required = true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename,
+ @ApiParam(value = "Field Name",required = true) @PathParam("field") String fieldName,
+ @Context UriInfo info) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
+ Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,aid, "createIndex");
+ response.header(XLATESTVERSION, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ response.status(Status.UNAUTHORIZED);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
MultivaluedMap<String, String> rowParams = info.getQueryParameters();
String indexName = "";
@@ -500,12 +517,15 @@ public class RestMusicDataAPI {
try {
result = MusicCore.nonKeyRelatedPut(query, "eventual");
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ response.status(Status.BAD_REQUEST);
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
+ }
+ if ( result.equals(ResultType.SUCCESS) ) {
+ return response.entity(new JsonResponse(result).setMessage("Index Created on " + keyspace+"."+tablename+"."+fieldName).toMap()).build();
+ } else {
+ return response.entity(new JsonResponse(result).setError("Unknown Error in create index.").toMap()).build();
}
-
- return new JsonResponse(result).toMap();
}
/**
@@ -521,58 +541,49 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Insert Into Table", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> insertIntoTable(
- @ApiParam(value = "Major Version",
- required = true) @PathParam("version") String version,
- @ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ public Response insertIntoTable(
+ @ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
+ @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
+ @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
- @ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
- @ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
- @ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ @ApiParam(value = "Application namespace",required = true) @HeaderParam(NS) String ns,
+ @ApiParam(value = "userId",required = true) @HeaderParam(USERID) String userId,
+ @ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
JsonInsert insObj,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) {
+ required = true) @PathParam("tablename") String tablename) {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap = null;
+
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "insertIntoTable");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
Map<String, Object> valuesMap = insObj.getValues();
PreparedQueryObject queryObject = new PreparedQueryObject();
TableMetadata tableInfo = null;
- try {
- tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
- if(tableInfo == null) {
- return new JsonResponse(ResultType.FAILURE)
- .setError("Table name doesn't exists. Please check the table name.").toMap();
- }
- } catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
- }
+ try {
+ tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+ if(tableInfo == null) {
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Table name doesn't exists. Please check the table name.").toMap()).build();
+ }
+ } catch (MusicServiceException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
+ }
String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();
StringBuilder fieldsString = new StringBuilder("(vector_ts,");
String vectorTs =
@@ -594,8 +605,7 @@ public class RestMusicDataAPI {
colType = tableInfo.getColumn(entry.getKey()).getType();
} catch(NullPointerException ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() +" Invalid column name : "+entry.getKey(), AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap()).build();
}
Object formattedValue = null;
@@ -618,9 +628,8 @@ public class RestMusicDataAPI {
}
if(primaryKey == null || primaryKey.length() <= 0) {
- logger.error(EELFLoggerDelegate.errorLogger, "Some required partition key parts are missing: "+primaryKeyName );
- response.setStatus(400);
- return new JsonResponse(ResultType.SYNTAXERROR).setError("Some required partition key parts are missing: "+primaryKeyName).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger, "Some required partition key parts are missing: "+primaryKeyName );
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.SYNTAXERROR).setError("Some required partition key parts are missing: "+primaryKeyName).toMap()).build();
}
queryObject.appendQueryString("INSERT INTO " + keyspace + "." + tablename + " "
@@ -660,11 +669,10 @@ public class RestMusicDataAPI {
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();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
}
- result = MusicCore.criticalPut(keyspace, tablename, primaryKey, queryObject, lockId,
- null);
+ result = MusicCore.criticalPut(keyspace, tablename, primaryKey, queryObject, lockId,null);
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
result = MusicCore.atomicPut(keyspace, tablename, primaryKey, queryObject, null);
@@ -674,17 +682,15 @@ public class RestMusicDataAPI {
}
} catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
if (result==null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
}
- return new JsonResponse(result.getResult()).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(result.getResult()).setMessage("Insert Successful").toMap()).build();
}
/**
@@ -701,42 +707,41 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Update Table", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> updateTable(
+ public Response updateTable(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
JsonUpdate updateObj,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context UriInfo info, @Context HttpServletResponse response) {
+ @Context UriInfo info) {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap;
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "updateTable");
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
long startTime = System.currentTimeMillis();
String operationId = UUID.randomUUID().toString();// just for infoging
@@ -750,19 +755,17 @@ public class RestMusicDataAPI {
Map<String, Object> valuesMap = updateObj.getValues();
TableMetadata tableInfo;
- try {
- tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
- } catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
- }
+ try {
+ tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
+ } catch (MusicServiceException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
+ }
if (tableInfo == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE)
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
.setError("Table information not found. Please check input for table name= "
- + keyspace + "." + tablename).toMap();
+ + keyspace + "." + tablename).toMap()).build();
}
String vectorTs =
String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
@@ -776,8 +779,7 @@ public class RestMusicDataAPI {
colType = tableInfo.getColumn(entry.getKey()).getType();
} catch(NullPointerException ex) {
logger.error(EELFLoggerDelegate.errorLogger, "Invalid column name : "+entry.getKey());
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap()).build();
}
Object valueString = null;
try {
@@ -819,14 +821,12 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
if(rowId == null || rowId.primarKeyValue.isEmpty()) {
-
- return new JsonResponse(ResultType.FAILURE)
- .setError("Mandatory WHERE clause is missing. Please check the input request.").toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Mandatory WHERE clause is missing. Please check the input request.").toMap()).build();
}
} catch (MusicServiceException ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
queryObject.appendQueryString(
@@ -855,9 +855,8 @@ public class RestMusicDataAPI {
if(lockId == null) {
logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+ " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
- + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
}
operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, lockId, conditionInfo);
@@ -867,18 +866,16 @@ public class RestMusicDataAPI {
operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
rowId.primarKeyValue, queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
try {
operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
}
long actualUpdateCompletionTime = System.currentTimeMillis();
@@ -897,11 +894,16 @@ public class RestMusicDataAPI {
logger.info(EELFLoggerDelegate.applicationLogger, timingString);
if (operationResult==null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"Null result - Please Contact admin", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
+ }
+ if ( operationResult.getResult() == ResultType.SUCCESS ) {
+ return response.status(Status.OK).entity(new JsonResponse(operationResult.getResult()).setMessage(operationResult.getMessage()).toMap()).build();
+ } else {
+ logger.error(EELFLoggerDelegate.errorLogger,operationResult.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(operationResult.getResult()).setError(operationResult.getMessage()).toMap()).build();
}
- return new JsonResponse(operationResult.getResult()).toMap();
+
}
/**
@@ -918,48 +920,46 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Delete From table", response = String.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> deleteFromTable(
+ public Response deleteFromTable(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
JsonDelete delObj,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context UriInfo info, @Context HttpServletResponse response) {
+ @Context UriInfo info) {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap = null;
- try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "deleteFromTable");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap();
- }
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
+ try {
+ authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ aid, "deleteFromTable");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
+ }
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
if(delObj == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Required HTTP Request body is missing.").toMap();
- }
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Required HTTP Request body is missing.").toMap()).build();
+ }
PreparedQueryObject queryObject = new PreparedQueryObject();
StringBuilder columnString = new StringBuilder();
@@ -979,9 +979,8 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
String rowSpec = rowId.rowIdString.toString();
@@ -1016,39 +1015,41 @@ public class RestMusicDataAPI {
ReturnType operationResult = null;
try {
- if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL))
- operationResult = MusicCore.eventualPut(queryObject);
- else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
- String lockId = delObj.getConsistencyInfo().get("lockId");
- if(lockId == null) {
+ if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL))
+ 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);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
- + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
}
- 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);
- }
+ 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) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE)
- .setError("Unable to perform Delete operation. Exception from music").toMap();
- }
- if (operationResult.getResult().equals(ResultType.FAILURE)) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(operationResult.getMessage()).toMap();
- }
- return new JsonResponse(operationResult.getResult()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unable to perform Delete operation. Exception from music").toMap()).build();
+ }
+ if (operationResult==null) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
+ }
+ if (operationResult.getResult().equals(ResultType.SUCCESS)) {
+ return response.status(Status.OK).entity(new JsonResponse(operationResult.getResult()).setMessage(operationResult.getMessage()).toMap()).build();
+ } else {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(operationResult.getMessage()).toMap()).build();
+ }
}
/**
@@ -1062,45 +1063,43 @@ public class RestMusicDataAPI {
@Path("/{keyspace}/tables/{tablename}")
@ApiOperation(value = "Drop Table", response = String.class)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> dropTable(
+ public Response dropTable(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception {
+ required = true) @PathParam("tablename") String tablename) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap =
MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "dropTable");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
String consistency = "eventual";// for now this needs only eventual
// consistency
PreparedQueryObject query = new PreparedQueryObject();
query.appendQueryString("DROP TABLE " + keyspace + "." + tablename + ";");
try {
- return new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency)).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency)).toMap()).build();
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
}
@@ -1118,35 +1117,34 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Select Critical", response = Map.class)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> selectCritical(
+ public Response selectCritical(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
JsonInsert selObj,
@ApiParam(value = "Keyspace Name",
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> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "selectCritical");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
+ @Context UriInfo info) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
+ Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,aid, "selectCritical");
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"Error while authentication... ", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
String lockId = selObj.getConsistencyInfo().get("lockId");
@@ -1156,9 +1154,8 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
queryObject.appendQueryString(
"SELECT * FROM " + keyspace + "." + tablename + " WHERE " + rowId.rowIdString + ";");
@@ -1168,12 +1165,11 @@ public class RestMusicDataAPI {
String consistency = selObj.getConsistencyInfo().get("type");
if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
- if(lockId == null) {
+ if(lockId == null) {
logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
+ " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
- + "and acquire lock or use ATOMIC instead of CRITICAL").toMap();
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("LockId cannot be null. Create lock "
+ + "and acquire lock or use ATOMIC instead of CRITICAL").toMap()).build();
}
results = MusicCore.criticalGet(keyspace, tablename, rowId.primarKeyValue, queryObject,
lockId);
@@ -1185,7 +1181,7 @@ public class RestMusicDataAPI {
results = MusicCore.atomicGetWithDeleteLock(keyspace, tablename, rowId.primarKeyValue, queryObject);
}
- return new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap()).build();
}
/**
@@ -1200,34 +1196,34 @@ public class RestMusicDataAPI {
@Path("/{keyspace}/tables/{tablename}/rows")
@ApiOperation(value = "Select All or Select Specific", response = Map.class)
@Produces(MediaType.APPLICATION_JSON)
- public Map<String, Object> select(
+ public Response select(
@ApiParam(value = "Major Version",
required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",
- required = false) @HeaderParam("X-minorVersion") String minorVersion,
+ required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@ApiParam(value = "Patch Version",
- required = false) @HeaderParam("X-patchVersion") String patchVersion,
+ required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace",
- required = true) @HeaderParam("ns") String ns,
+ required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "userId",
- required = true) @HeaderParam("userId") String userId,
+ required = true) @HeaderParam(USERID) String userId,
@ApiParam(value = "Password",
- required = true) @HeaderParam("password") String password,
+ required = true) @HeaderParam(PASSWORD) String password,
@ApiParam(value = "Keyspace Name",
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
- @Context UriInfo info, @Context HttpServletResponse response) throws Exception {
+ @Context UriInfo info) throws Exception {
+ ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+
Map<String, Object> authMap =
MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "select");
- response.addHeader(xLatestVersion, MusicUtil.getVersion());
if (authMap.containsKey("aid"))
- authMap.remove("aid");
+ authMap.remove("aid");
if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
PreparedQueryObject queryObject = new PreparedQueryObject();
@@ -1239,19 +1235,17 @@ public class RestMusicDataAPI {
queryObject = selectSpecificQuery(version, minorVersion, patchVersion, aid, ns,
userId, password, keyspace, tablename, info, limit);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
}
try {
ResultSet results = MusicCore.get(queryObject);
- return new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap();
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap()).build();
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap();
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
}
@@ -1314,9 +1308,10 @@ public class RestMusicDataAPI {
String keyName = entry.getKey();
List<String> valueList = entry.getValue();
String indValue = valueList.get(0);
- DataType colType = tableInfo.getColumn(entry.getKey()).getType();
+ DataType colType = null;
Object formattedValue = null;
try {
+ colType = tableInfo.getColumn(entry.getKey()).getType();
formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
diff --git a/src/main/java/org/onap/music/rest/RestMusicQAPI.java b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
index 39233dc5..e08adaf7 100755
--- a/src/main/java/org/onap/music/rest/RestMusicQAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
@@ -26,7 +26,6 @@ package org.onap.music.rest;
import java.util.HashMap;
import java.util.Map;
-import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -38,6 +37,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.onap.music.datastore.jsonobjects.JsonDelete;
@@ -47,8 +47,6 @@ import org.onap.music.datastore.jsonobjects.JsonUpdate;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.main.MusicCore;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import org.onap.music.datastore.PreparedQueryObject;
import com.datastax.driver.core.ResultSet;
@@ -60,199 +58,194 @@ import io.swagger.annotations.ApiParam;
@Path("/priorityq/")
@Api(value="Q Api")
public class RestMusicQAPI {
-
- private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
-
-
- /**
- *
- * @param tableObj
- * @param keyspace
- * @param tablename
- * @throws Exception
- */
-
- @POST
- @Path("/keyspaces/{keyspace}/{qname}")
- @ApiOperation(value = "", response = Void.class)
- @Consumes(MediaType.APPLICATION_JSON)
- public Map<String,Object> createQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tableObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().createTable(version,minorVersion,patchVersion,aid, ns, userId, password, tableObj, keyspace, tablename,response);
- }
-
- /**
- *
- * @param insObj
- * @param keyspace
- * @param tablename
- * @throws Exception
- */
- @POST
- @Path("/keyspaces/{keyspace}/{qname}/rows")
- @ApiOperation(value = "", response = Void.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> insertIntoQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonInsert insObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().insertIntoTable(version,minorVersion,patchVersion,aid, ns, userId, password, insObj, keyspace, tablename,response);
- }
-
- /**
- *
- * @param updateObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @PUT
- @Path("/keyspaces/{keyspace}/{qname}/rows")
- @ApiOperation(value = "", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> updateQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonUpdate updateObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context UriInfo info,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().updateTable(version,minorVersion,patchVersion,aid, ns, userId, password, updateObj, keyspace, tablename, info,response);
- }
-
- /**
- *
- * @param delObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @DELETE
- @Path("/keyspaces/{keyspace}/{qname}/rows")
- @ApiOperation(value = "", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> deleteFromQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonDelete delObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context UriInfo info,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().deleteFromTable(version,minorVersion,patchVersion,aid, ns, userId, password, delObj, keyspace, tablename, info,response);
- }
-
- /**
- *
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @GET
- @Path("/keyspaces/{keyspace}/{qname}/peek")
- @ApiOperation(value = "", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String, HashMap<String, Object>> peek(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context UriInfo info) throws Exception{
- int limit =1; //peek must return just the top row
- PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
- ResultSet results = MusicCore.get(query);
- return MusicCore.marshallResults(results);
-
- }
-
- /**
- *
- *
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @GET
- @Path("/keyspaces/{keyspace}/{qname}/filter")
- @ApiOperation(value = "", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String, HashMap<String, Object>> filter(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context UriInfo info) throws Exception{
- int limit =-1;
- PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
- ResultSet results = MusicCore.get(query);
- return MusicCore.marshallResults(results);
- }
-
- /**
- *
- * @param tabObj
- * @param keyspace
- * @param tablename
- * @throws Exception
- */
- @DELETE
- @ApiOperation(value = "", response = Void.class)
- @Path("/keyspaces/{keyspace}/{qname}")
- public Map<String,Object> dropQ(
- @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
- @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
- @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
- @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
- @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
- @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
- @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tabObj,
- @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
- @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
- @Context HttpServletResponse response) throws Exception{
- return new RestMusicDataAPI().dropTable(version,minorVersion,patchVersion,aid, ns, userId, password, keyspace, tablename,response);
- }
+
+ private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
+
+
+ /**
+ *
+ * @param tableObj
+ * @param keyspace
+ * @param tablename
+ * @throws Exception
+ */
+
+ @POST
+ @Path("/keyspaces/{keyspace}/{qname}")
+ @ApiOperation(value = "", response = Void.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response createQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tableObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{
+ return new RestMusicDataAPI().createTable(version,minorVersion,patchVersion,aid, ns, userId, password, tableObj, keyspace, tablename);
+ }
+
+ /**
+ *
+ * @param insObj
+ * @param keyspace
+ * @param tablename
+ * @throws Exception
+ */
+ @POST
+ @Path("/keyspaces/{keyspace}/{qname}/rows")
+ @ApiOperation(value = "", response = Void.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response insertIntoQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonInsert insObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{
+ return new RestMusicDataAPI().insertIntoTable(version,minorVersion,patchVersion,aid, ns, userId, password, insObj, keyspace, tablename);
+ }
+
+ /**
+ *
+ * @param updateObj
+ * @param keyspace
+ * @param tablename
+ * @param info
+ * @return
+ * @throws Exception
+ */
+ @PUT
+ @Path("/keyspaces/{keyspace}/{qname}/rows")
+ @ApiOperation(value = "", response = String.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response updateQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns, @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonUpdate updateObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
+ @Context UriInfo info) throws Exception{
+ return new RestMusicDataAPI().updateTable(version,minorVersion,patchVersion,aid, ns, userId, password, updateObj, keyspace, tablename, info);
+ }
+
+ /**
+ *
+ * @param delObj
+ * @param keyspace
+ * @param tablename
+ * @param info
+ * @return
+ * @throws Exception
+ */
+ @DELETE
+ @Path("/keyspaces/{keyspace}/{qname}/rows")
+ @ApiOperation(value = "", response = String.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deleteFromQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonDelete delObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
+ @Context UriInfo info) throws Exception{
+ return new RestMusicDataAPI().deleteFromTable(version,minorVersion,patchVersion,aid, ns, userId, password, delObj, keyspace, tablename, info);
+ }
+
+ /**
+ *
+ * @param keyspace
+ * @param tablename
+ * @param info
+ * @return
+ * @throws Exception
+ */
+ @GET
+ @Path("/keyspaces/{keyspace}/{qname}/peek")
+ @ApiOperation(value = "", response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Map<String, HashMap<String, Object>> peek(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
+ @Context UriInfo info) throws Exception{
+ int limit =1; //peek must return just the top row
+ PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
+ ResultSet results = MusicCore.get(query);
+ return MusicCore.marshallResults(results);
+
+ }
+
+ /**
+ *
+ *
+ * @param keyspace
+ * @param tablename
+ * @param info
+ * @return
+ * @throws Exception
+ */
+ @GET
+ @Path("/keyspaces/{keyspace}/{qname}/filter")
+ @ApiOperation(value = "", response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Map<String, HashMap<String, Object>> filter(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename,
+ @Context UriInfo info) throws Exception{
+ int limit =-1;
+ PreparedQueryObject query = new RestMusicDataAPI().selectSpecificQuery(version,minorVersion,patchVersion,aid, ns, userId, password,keyspace,tablename,info,limit);
+ ResultSet results = MusicCore.get(query);
+ return MusicCore.marshallResults(results);
+ }
+
+ /**
+ *
+ * @param tabObj
+ * @param keyspace
+ * @param tablename
+ * @throws Exception
+ */
+ @DELETE
+ @ApiOperation(value = "", response = Void.class)
+ @Path("/keyspaces/{keyspace}/{qname}")
+ public Response dropQ(
+ @ApiParam(value="Major Version",required=true) @PathParam("version") String version,
+ @ApiParam(value="Minor Version",required=false) @HeaderParam("X-minorVersion") String minorVersion,
+ @ApiParam(value="Patch Version",required=false) @HeaderParam("X-patchVersion") String patchVersion,
+ @ApiParam(value="AID",required=true) @HeaderParam("aid") String aid,
+ @ApiParam(value="Application namespace",required=true) @HeaderParam("ns") String ns,
+ @ApiParam(value="userId",required=true) @HeaderParam("userId") String userId,
+ @ApiParam(value="Password",required=true) @HeaderParam("password") String password, JsonTable tabObj,
+ @ApiParam(value="Key Space",required=true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value="Table Name",required=true) @PathParam("tablename") String tablename) throws Exception{
+ return new RestMusicDataAPI().dropTable(version,minorVersion,patchVersion,aid, ns, userId, password, keyspace, tablename);
+ }
}
diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
index a8a8612a..e82280f8 100644
--- a/src/test/java/org/onap/music/unittests/TestRestMusicData.java
+++ b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
@@ -18,7 +18,8 @@
package org.onap.music.unittests;
import static org.junit.Assert.assertEquals;
-import static org.onap.music.main.MusicCore.mLockHandle;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.HashMap;
import java.util.List;
@@ -26,6 +27,7 @@ import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.apache.curator.test.TestingServer;
import org.junit.AfterClass;
@@ -46,7 +48,6 @@ import org.onap.music.datastore.jsonobjects.JsonSelect;
import org.onap.music.datastore.jsonobjects.JsonTable;
import org.onap.music.datastore.jsonobjects.JsonUpdate;
import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
@@ -180,9 +181,38 @@ public class TestRestMusicData {
jsonKeyspace.setKeyspaceName(keyspaceName);
jsonKeyspace.setReplicationInfo(replicationInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = data.createKeySpace("1", "1", "1", null, appName, userId,
- password, jsonKeyspace, keyspaceName, http);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
+ Response response = data.createKeySpace("1", "1", "1", null, appName, userId,
+ password, jsonKeyspace, keyspaceName);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(200,response.getStatus());
+ }
+
+ @Test
+ public void Test2_createKeyspace0() throws Exception {
+ JsonKeySpace jsonKeyspace = new JsonKeySpace();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> replicationInfo = new HashMap<>();
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createKeySpace("1", "1", "1", null, appName, userId,
+ password, jsonKeyspace, keyspaceName);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(400,response.getStatus());
+ }
+//MusicCore.autheticateUser
+ @Test
+ public void Test2_createKeyspace01() throws Exception {
+ JsonKeySpace jsonKeyspace = new JsonKeySpace();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> replicationInfo = new HashMap<>();
+ String appName1 = "test";
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createKeySpace("1", "1", "1", null, appName1, userId,
+ password, jsonKeyspace, keyspaceName);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(401,response.getStatus());
}
@Test
@@ -198,11 +228,11 @@ public class TestRestMusicData {
jsonKeyspace.setKeyspaceName("TestApp1");
jsonKeyspace.setReplicationInfo(replicationInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- 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("Keyspace testcassa already exists",
- resultMap.get("error"));;
+ Response response = data.createKeySpace("1", "1", "1", null, "TestApp1",
+ "TestUser1", password, jsonKeyspace, keyspaceName);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(400,response.getStatus());
}
@Test
@@ -221,12 +251,66 @@ public class TestRestMusicData {
jsonTable.setTableName(tableName);
jsonTable.setFields(fields);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = data.createTable("1", "1", "1",
+ Response response = data.createTable("1", "1", "1",
"abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- jsonTable, keyspaceName, tableName, http);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
+ jsonTable, keyspaceName, tableName);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+ // Improper Auth
+ @Test
+ public void Test3_createTable1() throws Exception {
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, "wrong",
+ jsonTable, keyspaceName, tableName);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(401, response.getStatus());
}
+ // Improper keyspace
+ @Test
+ public void Test3_createTable2() throws Exception {
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
+ jsonTable, "wrong", tableName);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(401, response.getStatus());
+ }
+
+
+
@Test
public void Test4_insertIntoTable() throws Exception {
JsonInsert jsonInsert = new JsonInsert();
@@ -241,9 +325,9 @@ public class TestRestMusicData {
jsonInsert.setTableName(tableName);
jsonInsert.setValues(values);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, userId, password, jsonInsert, keyspaceName, tableName, http);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, userId, password, jsonInsert, keyspaceName, tableName);
+ assertEquals(200, response.getStatus());
}
@Test
@@ -260,12 +344,56 @@ public class TestRestMusicData {
jsonInsert.setTableName(tableName);
jsonInsert.setValues(values);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = data.insertIntoTable("1", "1", "1",
+ Response response = data.insertIntoTable("1", "1", "1",
"abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- jsonInsert, keyspaceName, tableName, http);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
+ jsonInsert, keyspaceName, tableName);
+ assertEquals(200, response.getStatus());
+ }
+
+ // Auth Error
+ @Test
+ public void Test4_insertIntoTable3() throws Exception {
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "test1");
+ values.put("emp_salary", 1500);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.insertIntoTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, "wrong",
+ jsonInsert, keyspaceName, tableName);
+ assertEquals(401, response.getStatus());
}
+ // Table wrong
+ @Test
+ public void Test4_insertIntoTable4() throws Exception {
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "test1");
+ values.put("emp_salary", 1500);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.insertIntoTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
+ jsonInsert, keyspaceName, "wrong");
+ assertEquals(400, response.getStatus());
+ }
+
+
+
@Test
public void Test5_updateTable() throws Exception {
JsonUpdate jsonUpdate = new JsonUpdate();
@@ -281,9 +409,9 @@ public class TestRestMusicData {
jsonUpdate.setValues(values);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Mockito.when(info.getQueryParameters()).thenReturn(row);
- Map<String, Object> resultMap = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- userId, password, jsonUpdate, keyspaceName, tableName, info, http);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
+ Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ userId, password, jsonUpdate, keyspaceName, tableName, info);
+ assertEquals(200, response.getStatus());
}
@Test
@@ -296,9 +424,11 @@ public class TestRestMusicData {
jsonSelect.setConsistencyInfo(consistencyInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Mockito.when(info.getQueryParameters()).thenReturn(row);
- Map<String, Object> resultMap = data.select("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, keyspaceName, tableName, info, http);
- assertEquals("2500", ((HashMap<String,HashMap<String,Object>>) resultMap.get("result")).get("row 0").get("emp_salary").toString());
+ Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, userId, password, keyspaceName, tableName, info);
+ HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
+ HashMap<String, Object> result = map.get("result");
+ assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
}
@Test
@@ -311,10 +441,11 @@ public class TestRestMusicData {
jsonInsert.setConsistencyInfo(consistencyInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Mockito.when(info.getQueryParameters()).thenReturn(row);
- Map<String, Object> resultMap = data.selectCritical("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonInsert, keyspaceName, tableName,
- info, http);
- assertEquals("2500", ((HashMap<String,HashMap<String,Object>>) resultMap.get("result")).get("row 0").get("emp_salary").toString());
+ Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, userId, password, jsonInsert, keyspaceName, tableName,info);
+ HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
+ HashMap<String, Object> result = map.get("result");
+ assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
}
@Test
@@ -327,10 +458,44 @@ public class TestRestMusicData {
jsonDelete.setConsistencyInfo(consistencyInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Mockito.when(info.getQueryParameters()).thenReturn(row);
- Map<String, Object> resultMap = data.deleteFromTable("1", "1", "1",
+ Response response = data.deleteFromTable("1", "1", "1",
"abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- jsonDelete, keyspaceName, tableName, info, http);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
+ jsonDelete, keyspaceName, tableName, info);
+ assertEquals(200, response.getStatus());
+ }
+
+ // Values
+ @Test
+ public void Test6_deleteFromTable1() throws Exception {
+ JsonDelete jsonDelete = new JsonDelete();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ //row.add("emp_name", "test1");
+ consistencyInfo.put("type", "atomic");
+ jsonDelete.setConsistencyInfo(consistencyInfo);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = data.deleteFromTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
+ jsonDelete, keyspaceName, tableName, info);
+ assertEquals(400, response.getStatus());
+ }
+
+ // delObj
+ @Test
+ public void Test6_deleteFromTable2() throws Exception {
+ JsonDelete jsonDelete = new JsonDelete();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ row.add("emp_name", "test1");
+ consistencyInfo.put("type", "atomic");
+ jsonDelete.setConsistencyInfo(consistencyInfo);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = data.deleteFromTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
+ null, keyspaceName, tableName, info);
+ assertEquals(400, response.getStatus());
}
@Test
@@ -340,10 +505,10 @@ public class TestRestMusicData {
consistencyInfo.put("type", "atomic");
jsonTable.setConsistencyInfo(consistencyInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = data.dropTable("1", "1", "1",
+ Response response = data.dropTable("1", "1", "1",
"abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- keyspaceName, tableName, http);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
+ keyspaceName, tableName);
+ assertEquals(200, response.getStatus());
}
@Test
@@ -359,31 +524,98 @@ public class TestRestMusicData {
jsonKeyspace.setKeyspaceName("TestApp1");
jsonKeyspace.setReplicationInfo(replicationInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, userId, password, keyspaceName, http);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
+ Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, userId, password, keyspaceName);
+ assertEquals(200, response.getStatus());
}
@Test
+ public void Test8_deleteKeyspace2() throws Exception {
+ JsonKeySpace jsonKeyspace = new JsonKeySpace();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> replicationInfo = new HashMap<>();
+ consistencyInfo.put("type", "eventual");
+ replicationInfo.put("class", "SimpleStrategy");
+ replicationInfo.put("replication_factor", 1);
+ jsonKeyspace.setConsistencyInfo(consistencyInfo);
+ jsonKeyspace.setDurabilityOfWrites("true");
+ jsonKeyspace.setKeyspaceName("TestApp1");
+ jsonKeyspace.setReplicationInfo(replicationInfo);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, userId, "wrong", keyspaceName);
+ assertEquals(401, response.getStatus());
+ }
+
+ @Test
+ public void Test8_deleteKeyspace3() throws Exception {
+ JsonKeySpace jsonKeyspace = new JsonKeySpace();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> replicationInfo = new HashMap<>();
+// consistencyInfo.put("type", "eventual");
+// replicationInfo.put("class", "SimpleStrategy");
+// replicationInfo.put("replication_factor", 1);
+// jsonKeyspace.setConsistencyInfo(consistencyInfo);
+// jsonKeyspace.setDurabilityOfWrites("true");
+ // jsonKeyspace.setKeyspaceName("TestApp1");
+// jsonKeyspace.setReplicationInfo(replicationInfo);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, userId, password, keyspaceName);
+ assertEquals(400, response.getStatus());
+ }
+
+
+
+ @Test
public void Test6_onboard() throws Exception {
JsonOnboard jsonOnboard = new JsonOnboard();
jsonOnboard.setAppname("TestApp2");
jsonOnboard.setIsAAF("false");
jsonOnboard.setUserId("TestUser2");
jsonOnboard.setPassword("TestPassword2");
- Map<String, Object> resultMap = admin.onboardAppWithMusic(jsonOnboard, http);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.onboardAppWithMusic(jsonOnboard).getEntity();
resultMap.containsKey("success");
onboardUUID = resultMap.get("Generated AID").toString();
assertEquals("Your application TestApp2 has been onboarded with MUSIC.", resultMap.get("Success"));
}
+ // Missing appname
+ @Test
+ public void Test6_onboard1() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+// jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setUserId("TestUser2");
+ jsonOnboard.setPassword("TestPassword2");
+ Map<String, Object> resultMap = (Map<String, Object>) admin.onboardAppWithMusic(jsonOnboard).getEntity();
+ resultMap.containsKey("success");
+ System.out.println("--->" + resultMap.toString());
+// onboardUUID = resultMap.get("Generated AID").toString();
+ assertEquals("Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", resultMap.get("Exception"));
+ }
+
@Test
public void Test7_onboardSearch() throws Exception {
JsonOnboard jsonOnboard = new JsonOnboard();
jsonOnboard.setAppname("TestApp2");
jsonOnboard.setIsAAF("false");
jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = admin.getOnboardedInfoSearch(jsonOnboard, http);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.getOnboardedInfoSearch(jsonOnboard).getEntity();
+ resultMap.containsKey("success");
+ assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID));
+
+ }
+
+ // Missing appname
+ @Test
+ public void Test7_onboardSearch1() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+// jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.getOnboardedInfoSearch(jsonOnboard).getEntity();
+ System.out.println("--->" + resultMap.toString());
resultMap.containsKey("success");
assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID));
@@ -396,22 +628,74 @@ public class TestRestMusicData {
jsonOnboard.setUserId("TestUser3");
jsonOnboard.setPassword("TestPassword3");
jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = admin.updateOnboardApp(jsonOnboard, http);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard).getEntity();
+ System.out.println("--->" + resultMap.toString());
resultMap.containsKey("success");
assertEquals("Your application has been updated successfully", resultMap.get("Success"));
}
+ // Aid null
+ @Test
+ public void Test8_onboardUpdate1() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setUserId("TestUser3");
+ jsonOnboard.setPassword("TestPassword3");
+// jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard).getEntity();
+ System.out.println("--->" + resultMap.toString());
+ resultMap.containsKey("success");
+ assertEquals("Please make sure Aid is present", resultMap.get("Exception"));
+ }
+
+ // Appname not null
+ @Test
+ public void Test8_onboardUpdate2() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setUserId("TestUser3");
+ jsonOnboard.setPassword("TestPassword3");
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard).getEntity();
+ resultMap.containsKey("success");
+ System.out.println("--->" + resultMap.toString());
+ assertEquals("Application TestApp2 has already been onboarded. Please contact admin.", resultMap.get("Exception"));
+ }
+
+ // All null
+ @Test
+ public void Test8_onboardUpdate3() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+// jsonOnboard.setAppname("TestApp2");
+// jsonOnboard.setIsAAF("false");
+// jsonOnboard.setUserId("TestUser3");
+// jsonOnboard.setPassword("TestPassword3");
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard).getEntity();
+ assertTrue(resultMap.containsKey("Exception") );
+ }
+
@Test
public void Test9_onboardDelete() throws Exception {
JsonOnboard jsonOnboard = new JsonOnboard();
jsonOnboard.setAppname("TestApp2");
jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = admin.deleteOnboardApp(jsonOnboard, http);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard).getEntity();
resultMap.containsKey("success");
assertEquals("Your application has been deleted successfully", resultMap.get("Success"));
}
@Test
+ public void Test9_onboardDelete1() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+// jsonOnboard.setAppname("TestApp2");
+// jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard).getEntity();
+ assertTrue(resultMap.containsKey("Exception"));
+ }
+
+ @Test
public void Test3_createLockReference() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Map<String, Object> resultMap = lock.createLockReference(lockName, null, appName, userId, password, http);
diff --git a/version.properties b/version.properties
index 24dfb134..ecf57f41 100644
--- a/version.properties
+++ b/version.properties
@@ -3,8 +3,8 @@
# because they are used in Jenkins, whose plug-in doesn't support
major=2
-minor=4
-patch=22
+minor=5
+patch=2
base_version=${major}.${minor}.${patch}