summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/authentication.rst170
-rwxr-xr-xdocs/index.rst21
-rw-r--r--docs/multi.rst181
-rw-r--r--docs/setup.rst50
-rw-r--r--docs/single.rst85
-rwxr-xr-xpom.xml4
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java52
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicDataAPI.java66
-rw-r--r--src/main/java/org/onap/music/rest/RestMusicLocksAPI.java483
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicData.java28
-rw-r--r--version.properties2
11 files changed, 810 insertions, 332 deletions
diff --git a/docs/authentication.rst b/docs/authentication.rst
new file mode 100644
index 00000000..3c6f48a4
--- /dev/null
+++ b/docs/authentication.rst
@@ -0,0 +1,170 @@
+ `For Single install:`_
+
+ `Multi-Site Install:`_
+
+ `Headers:`_
+
+ `AAF Authentication`_
+
+ `AID Authentication Non-AAF`_
+
+`Onboarding API`_
+
+`Add Application`_
+
+`Get Application`_
+
+`Edit Application`_
+
+`Delete Application`_
+
+
+Steps to test AAF MUSIC has been enhanced to support applications which are already authenticated using AAF and applications which are not authenticated using AAF.
+
+If an application has already been using AAF, it should have required namespace, userId and password.
+
+**Non AAF applications (AID)** Works just like AAF but Namespace is an app name and MUSIC manages the User instead of AAF
+
+All the required params should be sent as headers.
+
+Changed in Cassandra: Admin needs to create the following keyspace and table.
+
+In the cassandra bin dir run ./cqlsh and log in to db then:
+
+If you want to save the following in a file you can then run ./cqlsh -f <file.cql>
+
+For Single install:
+^^^^^^^^^^^^^^^^^^^
+::
+
+ //Create Admin Keyspace
+
+ CREATE KEYSPACE admin
+ WITH REPLICATION = {
+ 'class' : 'SimpleStrategy',
+ 'replication_factor': 1
+ }
+ AND DURABLE_WRITES = true;
+
+ CREATE TABLE admin.keyspace_master (
+ uuid uuid,
+ keyspace_name text,
+ application_name text,
+ is_api boolean,
+ password text,
+ username text,
+ is_aaf boolean,
+ PRIMARY KEY (uuid)
+ );
+
+
+Multi-Site Install:
+^^^^^^^^^^^^^^^^^^^
+
+::
+
+ //Create Admin Keyspace
+
+ CREATE KEYSPACE admin
+ WITH REPLICATION = {
+ 'class' : 'NetworkTopologyStrategy',
+ 'DC1':2
+ }
+ AND DURABLE_WRITES = true;
+
+ CREATE TABLE admin.keyspace_master (
+ uuid uuid,
+ keyspace_name text,
+ application_name text,
+ is_api boolean,
+ password text,
+ username text,
+ is_aaf boolean,
+ PRIMARY KEY (uuid)
+ );
+
+Headers:
+^^^^^^^^
+
+For AAF applications all the 3 headers ns, userId and password are mandatory.
+
+For Non AAF applications if aid is not provided MUSIC creates new random unique UUID and returns to caller.
+
+Caller application then need to save the UUID and need to pass the UUID to further modify/access the keyspace.
+
+Required Headers
+
+AAF Authentication
+^^^^^^^^^^^^^^^^^^
+::
+
+ Key : Value : Description
+ ns : org.onap.aaf : AAF Namespace
+ userId : username : USer Id
+ password: password : Password of User
+
+AID Authentication Non-AAF
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+::
+
+ Key : Value : Description
+ ns : App Name : App Name
+ userId : username : Username for this user (Required during Create keyspace Only)
+ password: password : Password for this user (Required during Create keyspace Only)
+
+Onboarding API
+^^^^^^^^^^^^^^
+
+Add Application
+^^^^^^^^^^^^^^^
+
+::
+
+ POST URL: /MUSIC/rest/v2/admin/onboardAppWithMusic with JSON as follows:
+
+ {
+ "appname": "<the Namespace for aaf or the Identifier for the specific app using AID access",
+ "userId" : "<userid>",
+ "isAAF" : true/false,
+ "password" : ""
+ }
+
+Get Application
+^^^^^^^^^^^^^^^
+
+::
+
+ POST URL: /MUSIC/rest/v2/admin/search with JSON as follows:
+
+ {
+ "appname": "<the Namespace for aaf or the Identifier for the specific app using AID access",
+ "isAAF" : true/false,
+ "aid" : "Unique ID for this user"
+ }
+
+Edit Application
+^^^^^^^^^^^^^^^^
+
+::
+
+ PUT URL: /MUSIC/rest/v2/admin/onboardAppWithMusic with JSON as follows:
+
+ {
+ "aid" : "Unique ID for this user",
+ "appname": "<the Namespace for aaf or the Identifier for the specific app using AID access",
+ "userId" : "<userid>",
+ "isAAF" : true/false,
+ "password" : ""
+ }
+
+Delete Application
+^^^^^^^^^^^^^^^^^^
+
+::
+
+ DELETE URL: /MUSIC/rest/v2/admin/onboardAppWithMusic with JSON as follows:
+
+ {
+ "aid" : "Unique ID for this app"
+ }
diff --git a/docs/index.rst b/docs/index.rst
index 417b6052..3ef97755 100755
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -8,12 +8,17 @@ Music Developer Documentation
.. toctree::
:maxdepth: 1
- architecture
- configuration
- consumedapis
- delivery
- index
- installation
- logging
- offeredapis
+ Single-SIte Install <single>
+ Muili-Site Install <multi>
+ setup
release-notes
+
+
+.. architecture
+.. configuration
+.. consumedapis
+.. delivery
+.. index
+.. installation
+.. logging
+.. offeredapis
diff --git a/docs/multi.rst b/docs/multi.rst
new file mode 100644
index 00000000..bc26465f
--- /dev/null
+++ b/docs/multi.rst
@@ -0,0 +1,181 @@
+===========================
+Multi-site or Local Cluster
+===========================
+Follow the instructions for local MUSIC installation on all the machines/VMs/hosts (referred to as a node) on which you want MUSIC installed. However, Cassandra and Zookeeper needs to be configured to run as multi-node installations (instructions below) before running them.
+
+Cassandra:
+----------
+In the cassandra.yaml file which is present in the cassa_install/conf directory in each node, set the following parameters:
+cassandra.yaml::
+
+ cluster_name: ‘name of cluster’
+ #...
+ num_tokens: 256
+ #...
+ seed_provider:
+ - class_name: org.apache.cassandra.locator.SimpleSeedProvider
+ parameters:
+ - seeds: "<public ip of first seed>, <public ip of second seed>, etc"
+ #...
+ listen_address: private ip of VM
+ #...
+ broadcast_address: public ip of VM
+ #...
+ endpoint_snitch: GossipingPropertyFileSnitch
+ #...
+ rpc_address: <private ip>
+ #...
+ phi_convict_threshold: 12
+
+- In the cassandra-rackdc.properties file, assign data center and rack names as needed if required ( This is for multi data center install).
+- Once this is done on all three nodes, you can run cassandra on each of the nodes through the cassandra bin folder with this command::
+
+ ./cassandra
+
+- In the cassandra bin folder, if you run the following it will tell you the state of the cluster::
+
+ ./nodetool status
+
+- To access cassandra, one any of the nodes you can run the following and then perform CQL queries.::
+
+ ./cqlsh <private ip>
+
+Extra Cassandra information for Authentication:
+-----------------------------------------------
+To create first user in Cassandra
+
+1. Edit conf/Cassandra.yaml file::
+
+ authenticator: PasswordAuthenticator
+ authorizer: CassandraAuthorizer
+
+
+2. Restart Cassandra
+3. Login to cqlsh with default credentials::
+
+ cqlsh -u cassandra -p cassandra
+
+4. To change default user create new user with the following command.::
+
+ CREATE USER new_user WITH PASSWORD ‘new_password’ SUPERUSER;
+
+5. Change password for default user ‘Cassandra’ so that no one will be able to login::
+
+ ALTER USER cassandra WITH PASSWORD ‘SomeLongRandomStringNoonewillthinkof’;
+
+6. Provide the new user credentials to Music. Update music.properties file and uncomment or add the following::
+
+ cassandra.user=<new_user>
+ cassandra.password=<new_password>
+
+To access keyspace through cqlsh, login with credentials that are passed to MUSIC while creating the keyspace.
+
+
+
+Zookeeper:
+----------
+Once zookeeper has been installed on all the nodes, modify the **zk_install_location/conf/zoo.cfg** on all the nodes with the following lines:
+
+::
+
+ tickTime=2000
+ dataDir=/opt/app/music/var/zookeeper
+ clientPort=2181
+ initLimit=5
+ syncLimit=2
+ quorumListenOnAllIPs=true
+ server.1=public IP of node 1:2888:3888
+ server.2=public IP of node 2:2888:3888
+ server.3=public IP of node 3:2888:3888
+
+Create the directory /var/zookeeper in all the machines and within that create a file called myid that contains the id of the machine. The machine running node.i will contain just the number i in the file myid.
+
+Start each of the nodes one by one from the zk_install_location/bin folder using the command:
+
+
+
+ ./zkServer.sh start
+
+On each node check the file zookeeper.out in the zk_install_location/ bin to make sure all the machines are talking to each other and there are no errors. Note that while the machines are yet to come up there maybe error messages saying that connection has not yet been established. Clearly, this is ok.
+
+
+If there are no errors, then from zk_install_location/bin simply run the following to get command line access to zookeeper. ./zkCli.sh
+
+
+Run these commands on different machines to make sure the zk nodes are syncing.
+
+::
+
+ [zkshell] ls /
+ [zookeeper]
+
+Next, create a new znode by running
+
+::
+
+ create /zk_test my_data.
+
+This creates a new znode and associates the string "my_data" with the node. You should see:
+
+::
+
+ [zkshell] create /zk_test my_data
+ Created /zk_test
+
+Issue another ls / command to see what the directory looks like:
+
+::
+
+ [zkshell] ls /
+ [zookeeper, zk_test]
+
+MUSIC
+Create a music.properties file and place it in /opt/app/music/etc at each node. Here is a sample of the file:
+cassandra.yaml::
+
+ my.id=0
+ all.ids=0
+ my.public.ip=localhost
+ all.public.ips=localhost
+ #######################################
+ # Optional current values are defaults
+ #######################################
+ # If using docker this would point to the specific docker name.
+ #zookeeper.host=localhost
+ #cassandra.host=localhost
+ #music.ip=localhost
+ #debug=true
+ #music.rest.ip=localhost
+ #lock.lease.period=6000
+ # Cassandra Login - Do not user cassandra/cassandra
+ cassandra.user=cassandra1
+ cassandra.password=cassandra1
+ # AAF Endpoint
+ #aaf.endpoint.url=<aaf url>
+
+- Build the MUSIC.war (see `Build Music`_) and place it within the webapps folder of the tomcat installation.
+- Start tomcat and you should now have MUSIC running.
+
+For Logging create a dir /opt/app/music/logs. When MUSIC/Tomcat starts a MUSIC dir with various logs will be created.
+
+Build Music
+^^^^^^^^^^^
+Documentation will be updated to show that. Code can be downloaded from Music Gerrit.
+To build you will need to ensure you update your settings with the ONAP settings.xml
+(Workspace and Development Tools)
+
+Once you have done that run the following:
+
+::
+
+ # If you installed settings.xml in your ./m2 folder
+ mvn clean package
+ # If you placed the settings.xml elsewhere:
+ mvn clean package -s /path/to/settings.xml
+
+After it is built you will find the MUSIC.war in the ./target folder.
+
+There is a folder called postman that contains a postman collection for testing with postman.
+
+Continue with `Authentication <./automation.rst>`_
+ \ No newline at end of file
diff --git a/docs/setup.rst b/docs/setup.rst
new file mode 100644
index 00000000..208c779b
--- /dev/null
+++ b/docs/setup.rst
@@ -0,0 +1,50 @@
+Setup for Developing MUSIC
+==========================
+
+.. toctree::
+ :maxdepth: 1
+
+ Single-Site Install <single>
+ Muili-Site Install <multi>
+ Authentication
+
+MUSIC is to be installed in a single Dir on a vm.
+
+
+The main MUSIC dir should be::
+
+ /opt/app/music
+ # These also need to be set up
+ /opt/app/music/etc
+ /opt/app/music/logs
+ /opt/app/music/lib/zookeeper
+
+When installing Tomcat, Cassandra and Zookeeper they should also be installed here.::
+
+ /opt/app/music/apache-cassandra-n.n.n
+ /opt/app/music/zookeeper-n.n.n
+ /opt/app/music/apache-tomcat-n.n.n
+
+
+You could also create links from install dirs to a common name ie\:::
+
+ ln -s /opt/app/music/apache-cassandra-n.n.n cassandra
+ ln -s /opt/app/music/zookeeper-n.n.n zookeeper
+ ln -s /opt/app/music/apache-tomcat-n.n.n tomcat
+
+Cassandra and Zookeeper have data dirs.::
+
+ # For cassandra it should be (This is the default)
+ /opt/app/music/cassandra/data
+ # For Zookeeper it should be
+ /opt/app/music/zookeeper/
+
+
+Continue by selecting the link to the setup you are doing.
+
+.. toctree::
+ :maxdepth: 1
+
+ Single-Site Install <single>
+ Muili-Site Install <multi>
+ Authentication
diff --git a/docs/single.rst b/docs/single.rst
new file mode 100644
index 00000000..08c5e315
--- /dev/null
+++ b/docs/single.rst
@@ -0,0 +1,85 @@
+======================
+Single VM/Site install
+======================
+Local Installation
+------------------
+Prerequisites
+
+If you are using a VM make sure it has at least 8 GB of RAM (It may work with 4 GB, but with 2 GB it
+does give issues).
+
+Instructions
+
+- Create MUSIC Install dir /opt/app/music
+- Open /etc/hosts as sudo and enter the name of the vm alongside localhost in the line for 127.0.0.1. E.g. 127.0.0.1 localhost music-1. Some of the apt-get installation seem to require this.
+- Ensure you have OpenJDK 8 on your machine.
+- Download Apache Cassandra 3.0, install into /opt/app/music and follow these instructions http://cassandra.apache.org/doc/latest/getting_started/installing.html till and including Step
+- By the end of this you should have Cassandra working.
+- Download Apache Zookeeper 3.4.6, install into /opt/app/music and follow these instructions https://zookeeper.apache.org/doc/trunk/zookeeperStarted.html pertaining to the standalone operation. By the end of this you should have Zookeeper working.
+- Download the Version 8.5 Apache Tomcat and install it using these instructions https://tomcat.apache.org/download-80.cgi (this is for version 8.5).
+- Create a music.properties file and place it in /opt/app/music/etc/. Here is a sample of the file:
+
+music.properties::
+
+ music.properties
+ my.id=0
+ all.ids=0
+ my.public.ip=localhost
+ all.public.ips=localhost
+ ########################
+ # Optional current values are defaults
+ ######################################
+ # If using docker this would point to the specific docker name.
+ #zookeeper.host=localhost
+ #cassandra.host=localhost
+ #music.ip=localhost
+
+ #debug=true
+ #music.rest.ip=localhost
+ #lock.lease.period=6000
+ # Cassandra Login - Do not user cassandra/cassandra
+ cassandra.user=cassandra1
+ cassandra.password=cassandra1
+ # AAF Endpoint
+ #aaf.endpoint.url=<aaf url>
+
+- Make a dir /opt/app/music/logs MUSIC dir with MUSIC logs will be created in this dir after MUSIC starts.
+- Build the MUSIC.war and place in tomcat webapps dir.
+- Authentications/AAF Setup For Authentication setup.
+- Start tomcat and you should now have MUSIC running.
+
+Extra Cassandra information for Authentication:
+
+To create first user in Cassandra
+
+1. Edit conf/Cassandra.yaml file::
+
+ authenticator: PasswordAuthenticator
+ authorizer: CassandraAuthorizer
+
+
+2. Restart Cassandra
+3. Login to cqlsh with default credentials::
+
+ cqlsh -u cassandra -p cassandra
+
+4. To change default user create new user with the following command.::
+
+ CREATE USER new_user WITH PASSWORD ‘new_password’ SUPERUSER;
+
+5. Change password for default user ‘Cassandra’ so that no one will be able to login::
+
+ ALTER USER cassandra WITH PASSWORD ‘SomeLongRandomStringNoonewillthinkof’;
+
+6. Provide the new user credentials to Music. Update music.properties file and uncomment or add the following::
+
+ cassandra.user=<new_user>
+ cassandra.password=<new_password>
+
+To access keyspace through cqlsh, login with credentials that are passed to MUSIC while creating the keyspace.
+
+Continue with `Authentication <./automation.rst>`_
+
+
+
+ \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 59ce19a8..76505ad5 100755
--- a/pom.xml
+++ b/pom.xml
@@ -18,14 +18,14 @@
============LICENSE_END=============================================
====================================================================
--->
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.onap.music</groupId>
<artifactId>MUSIC</artifactId>
<packaging>war</packaging>
- <version>2.5.2</version>
+ <version>2.5.3</version>
<description>
This is the MUSIC REST interface, packaged as a war file.
</description>
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
index b6cc1902..5b442a79 100755
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/src/main/java/org/onap/music/main/MusicUtil.java
@@ -29,6 +29,8 @@ import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.UUID;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import com.datastax.driver.core.DataType;
@@ -49,6 +51,9 @@ public class MusicUtil {
public static final String CRITICAL = "critical";
public static final String ATOMICDELETELOCK = "atomic_delete_lock";
public static final String DEFAULTKEYSPACENAME = "TBD";
+ 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 LOCALHOST = "localhost";
private static final String PROPERTIES_FILE = "/opt/app/music/etc/music.properties";
@@ -474,4 +479,51 @@ public class MusicUtil {
}
return sqlString.toString();
}
+
+ @SuppressWarnings("unused")
+ public static String buildVersion(String major, String minor, String patch) {
+ if (minor != null) {
+ major += "." + minor;
+ if (patch != null) {
+ major += "." + patch;
+ }
+ }
+ 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
+ */
+ public static 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);
+ logger.info(EELFLoggerDelegate.applicationLogger,"Version In:" + versionIn);
+ return response;
+ }
+
+
+
+
}
diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
index 53ed9e5b..93b8f82a 100755
--- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
@@ -99,12 +99,12 @@ public class RestMusicDataAPI {
*/
private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
- 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 static final String VERSION = "v2";
private class RowIdentifier {
public String primarKeyValue;
@@ -121,47 +121,6 @@ public class RestMusicDataAPI {
}
}
- @SuppressWarnings("unused")
- private String buildVersion(String major, String minor, String patch) {
- if (minor != null) {
- major += "." + minor;
- if (patch != null) {
- major += "." + patch;
- }
- }
- 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
@@ -187,7 +146,7 @@ public class RestMusicDataAPI {
@ApiParam(value = "Password",required = true) @HeaderParam(PASSWORD) String password,
JsonKeySpace kspObject,
@ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) {
- ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> authMap = CachingUtil.verifyOnboarding(ns, userId, password);
if (!authMap.isEmpty()) {
@@ -313,7 +272,7 @@ public class RestMusicDataAPI {
@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);
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password,keyspaceName, aid, "dropKeySpace");
if (authMap.containsKey("aid"))
@@ -389,7 +348,7 @@ public class RestMusicDataAPI {
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);
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
aid, "createTable");
if (authMap.containsKey("aid"))
@@ -494,10 +453,9 @@ public class RestMusicDataAPI {
@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);
+ ResponseBuilder response = MusicUtil.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");
if (!authMap.isEmpty()) {
@@ -554,7 +512,7 @@ public class RestMusicDataAPI {
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename) {
- ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> authMap = null;
@@ -727,7 +685,7 @@ public class RestMusicDataAPI {
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
@Context UriInfo info) {
- ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> authMap;
try {
@@ -940,7 +898,7 @@ public class RestMusicDataAPI {
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
@Context UriInfo info) {
- ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> authMap = null;
try {
@@ -1081,7 +1039,7 @@ public class RestMusicDataAPI {
required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename) throws Exception {
- ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> authMap =
MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "dropTable");
@@ -1137,7 +1095,7 @@ public class RestMusicDataAPI {
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
@Context UriInfo info) throws Exception {
- ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,aid, "selectCritical");
if (authMap.containsKey("aid"))
@@ -1215,7 +1173,7 @@ public class RestMusicDataAPI {
@ApiParam(value = "Table Name",
required = true) @PathParam("tablename") String tablename,
@Context UriInfo info) throws Exception {
- ResponseBuilder response = buildVersionResponse(version, minorVersion, patchVersion);
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> authMap =
MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "select");
@@ -1232,7 +1190,7 @@ public class RestMusicDataAPI {
else {
int limit = -1; // do not limit the number of results
try {
- queryObject = selectSpecificQuery(version, minorVersion, patchVersion, aid, ns,
+ 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);
diff --git a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java
index da94f9d2..9189fbb3 100644
--- a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java
@@ -23,7 +23,6 @@ package org.onap.music.rest;
import java.util.Map;
-import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -32,9 +31,10 @@ import javax.ws.rs.POST;
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.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.jsonobjects.JsonLeasedLock;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
@@ -52,47 +52,47 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
-@Path("/v{version: [0-9]+}/locks/")
+@Path("/v2/locks/")
@Api(value="Lock Api")
public class RestMusicLocksAPI {
- @SuppressWarnings("unused")
private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicLocksAPI.class);
- private static String xLatestVersion = "X-latestVersion";
-
- /**
- * Puts the requesting process in the q for this lock. The corresponding
- * node will be created in zookeeper if it did not already exist
- *
- * @param lockName
- * @return
- * @throws Exception
- */
+ private static final String XMINORVERSION = "X-minorVersion";
+ private static final String XPATCHVERSION = "X-patchVersion";
+ private static final String VERSION = "v2";
- @POST
- @Path("/create/{lockname}")
- @ApiOperation(value = "Create Lock",
- notes = "Puts the requesting process in the q for this lock." +
- " The corresponding node will be created in zookeeper if it did not already exist." +
- " Lock Name is the \"key\" of the form keyspaceName.tableName.rowId",
- response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> createLockReference(
- @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
- @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ /**
+ * Puts the requesting process in the q for this lock. The corresponding
+ * node will be created in zookeeper if it did not already exist
+ *
+ * @param lockName
+ * @return
+ * @throws Exception
+ */
+ @POST
+ @Path("/create/{lockname}")
+ @ApiOperation(value = "Create Lock",
+ notes = "Puts the requesting process in the q for this lock." +
+ " The corresponding node will be created in zookeeper if it did not already exist." +
+ " Lock Name is the \"key\" of the form keyspaceName.tableName.rowId",
+ response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response createLockReference(
+ @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
+ @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,
- @Context HttpServletResponse response) throws Exception{
- response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ required = true) @HeaderParam("password") String password) throws Exception{
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> resultMap = MusicCore.validateLock(lockName);
if (resultMap.containsKey("Exception")) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
@@ -101,52 +101,50 @@ public class RestMusicLocksAPI {
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.setStatus(401);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED).entity(resultMap).build();
+ }
+ ResultType status = ResultType.SUCCESS;
+ String lockId = MusicCore.createLockReference(lockName);
+
+ if (lockId == null) {
+ status = ResultType.FAILURE;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.LOCKINGERROR ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(status).setError("Lock Id is null").toMap()).build();
}
- ResultType status = ResultType.SUCCESS;
- String lockId = MusicCore.createLockReference(lockName);
-
- if (lockId == null) {
- status = ResultType.FAILURE;
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.LOCKINGERROR ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- response.setStatus(400);
- return new JsonResponse(status).setError("Lock Id is null").toMap();
- }
- return new JsonResponse(status).setLock(lockId).toMap();
- }
+ return response.status(Status.OK).entity(new JsonResponse(status).setLock(lockId).toMap()).build();
+ }
- /**
- *
- * Checks if the node is in the top of the queue and hence acquires the lock
- *
- * @param lockId
- * @return
- * @throws Exception
- */
- @GET
- @Path("/acquire/{lockreference}")
- @ApiOperation(value = "Aquire Lock",
- notes = "Checks if the node is in the top of the queue and hence acquires the lock",
- response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> accquireLock(
- @ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId,
- @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ /**
+ *
+ * Checks if the node is in the top of the queue and hence acquires the lock
+ *
+ * @param lockId
+ * @return
+ * @throws Exception
+ */
+ @GET
+ @Path("/acquire/{lockreference}")
+ @ApiOperation(value = "Aquire Lock",
+ notes = "Checks if the node is in the top of the queue and hence acquires the lock",
+ response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response accquireLock(
+ @ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId,
+ @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,
- @Context HttpServletResponse response) throws Exception{
- response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ required = true) @HeaderParam("password") String password) throws Exception{
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> resultMap = MusicCore.validateLock(lockId);
if (resultMap.containsKey("Exception")) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
@@ -155,47 +153,48 @@ public class RestMusicLocksAPI {
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
+ }
+ try {
+ String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
+ ReturnType lockStatus = MusicCore.acquireLock(lockName,lockId);
+ if ( lockStatus.getResult().equals(ResultType.SUCCESS)) {
+ response.status(Status.OK);
+ } else {
+ response.status(Status.BAD_REQUEST);
+ }
+ return response.entity(new JsonResponse(lockStatus.getResult()).setLock(lockId).setMessage(lockStatus.getMessage()).toMap()).build();
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,AppMessages.INVALIDLOCK + lockId, ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Unable to aquire lock").toMap()).build();
}
- try {
- String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
- ReturnType lockStatus = MusicCore.acquireLock(lockName,lockId);
- return new JsonResponse(lockStatus.getResult()).setLock(lockId)
- .setMessage(lockStatus.getMessage()).toMap();
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,AppMessages.INVALIDLOCK + lockId, ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- resultMap.put("Exception","Unable to aquire lock");
- response.setStatus(400);
- return new JsonResponse(ResultType.FAILURE).setError("Unable to aquire lock").toMap();
- }
- }
-
+ }
+
-
- @POST
- @Path("/acquire-with-lease/{lockreference}")
- @ApiOperation(value = "Aquire Lock with Lease", response = Map.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> accquireLockWithLease(JsonLeasedLock lockObj,
- @ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId,
- @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+
+ @POST
+ @Path("/acquire-with-lease/{lockreference}")
+ @ApiOperation(value = "Aquire Lock with Lease", response = Map.class)
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response accquireLockWithLease(JsonLeasedLock lockObj,
+ @ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId,
+ @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,
- @Context HttpServletResponse response) throws Exception{
- response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ required = true) @HeaderParam("password") String password) throws Exception{
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> resultMap = MusicCore.validateLock(lockId);
if (resultMap.containsKey("Exception")) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
@@ -205,40 +204,44 @@ public class RestMusicLocksAPI {
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
+ }
+ String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
+ ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, lockObj.getLeasePeriod());
+ if ( lockLeaseStatus.getResult().equals(ResultType.SUCCESS)) {
+ response.status(Status.OK);
+ } else {
+ response.status(Status.BAD_REQUEST);
}
- String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
- ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, lockObj.getLeasePeriod());
- return new JsonResponse(lockLeaseStatus.getResult()).setLock(lockName)
- .setMessage(lockLeaseStatus.getMessage())
- .setLockLease(String.valueOf(lockObj.getLeasePeriod())).toMap();
- }
-
+ return response.entity(new JsonResponse(lockLeaseStatus.getResult()).setLock(lockName)
+ .setMessage(lockLeaseStatus.getMessage())
+ .setLockLease(String.valueOf(lockObj.getLeasePeriod())).toMap()).build();
+ }
+
- @GET
- @Path("/enquire/{lockname}")
- @ApiOperation(value = "Get Lock Holder",
- notes = "Gets the current Lock Holder",
- response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> currentLockHolder(
- @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
- @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ @GET
+ @Path("/enquire/{lockname}")
+ @ApiOperation(value = "Get Lock Holder",
+ notes = "Gets the current Lock Holder",
+ response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response currentLockHolder(
+ @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
+ @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,
- @Context HttpServletResponse response) throws Exception{
- response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ required = true) @HeaderParam("password") String password) throws Exception{
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> resultMap = MusicCore.validateLock(lockName);
if (resultMap.containsKey("Exception")) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
@@ -247,47 +250,43 @@ public class RestMusicLocksAPI {
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
- String who = MusicCore.whoseTurnIsIt(lockName);
- ResultType status = ResultType.SUCCESS;
- String error = "";
- if ( who == null ) {
- status = ResultType.FAILURE;
- error = "There was a problem getting the lock holder";
- logger.error(EELFLoggerDelegate.errorLogger,"There was a problem getting the lock holder", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return new JsonResponse(status).setError(error)
- .setLock(lockName).setLockHolder(who).toMap();
- }
- return new JsonResponse(status).setError(error)
- .setLock(lockName).setLockHolder(who).toMap();
- }
+ String who = MusicCore.whoseTurnIsIt(lockName);
+ ResultType status = ResultType.SUCCESS;
+ String error = "";
+ if ( who == null ) {
+ status = ResultType.FAILURE;
+ error = "There was a problem getting the lock holder";
+ logger.error(EELFLoggerDelegate.errorLogger,"There was a problem getting the lock holder", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(status).setError(error).setLock(lockName).setLockHolder(who).toMap()).build();
+ }
+ return response.status(Status.OK).entity(new JsonResponse(status).setError(error).setLock(lockName).setLockHolder(who).toMap()).build();
+ }
- @GET
- @Path("/{lockname}")
- @ApiOperation(value = "Lock State",
- notes = "Returns current Lock State and Holder.",
- response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> currentLockState(
- @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
- @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ @GET
+ @Path("/{lockname}")
+ @ApiOperation(value = "Lock State",
+ notes = "Returns current Lock State and Holder.",
+ response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response currentLockState(
+ @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
+ @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,
- @Context HttpServletResponse response) throws Exception{
- response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ required = true) @HeaderParam("password") String password) throws Exception{
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> resultMap = MusicCore.validateLock(lockName);
if (resultMap.containsKey("Exception")) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
@@ -297,56 +296,54 @@ public class RestMusicLocksAPI {
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
-
+
MusicLockState mls = MusicCore.getMusicLockState(lockName);
- Map<String,Object> returnMap = null;
- JsonResponse jsonResponse = new JsonResponse(ResultType.FAILURE).setLock(lockName);
- if(mls == null) {
- jsonResponse.setError("");
- jsonResponse.setMessage("No lock object created yet..");
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return jsonResponse.toMap();
- } else {
- jsonResponse.setStatus(ResultType.SUCCESS);
- jsonResponse.setLockStatus(mls.getLockStatus());
- jsonResponse.setLockHolder(mls.getLockHolder());
- return jsonResponse.toMap();
- }
- }
+ Map<String,Object> returnMap = null;
+ JsonResponse jsonResponse = new JsonResponse(ResultType.FAILURE).setLock(lockName);
+ if(mls == null) {
+ jsonResponse.setError("");
+ jsonResponse.setMessage("No lock object created yet..");
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(jsonResponse.toMap()).build();
+ } else {
+ jsonResponse.setStatus(ResultType.SUCCESS);
+ jsonResponse.setLockStatus(mls.getLockStatus());
+ jsonResponse.setLockHolder(mls.getLockHolder());
+ return response.status(Status.OK).entity(jsonResponse.toMap()).build();
+ }
+ }
- /**
- *
- * deletes the process from the zk queue
- *
- * @param lockId
- * @throws Exception
- */
- @DELETE
- @Path("/release/{lockreference}")
- @ApiOperation(value = "Release Lock",
- notes = "deletes the process from the zk queue",
- response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> unLock(@PathParam("lockreference") String lockId,
- @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ /**
+ *
+ * deletes the process from the zk queue
+ *
+ * @param lockId
+ * @throws Exception
+ */
+ @DELETE
+ @Path("/release/{lockreference}")
+ @ApiOperation(value = "Release Lock",
+ notes = "deletes the process from the zk queue",
+ response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response unLock(@PathParam("lockreference") String lockId,
+ @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,
- @Context HttpServletResponse response) throws Exception{
- response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ required = true) @HeaderParam("password") String password) throws Exception{
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> resultMap = MusicCore.validateLock(lockId);
if (resultMap.containsKey("Exception")) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
@@ -355,56 +352,55 @@ public class RestMusicLocksAPI {
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
+ }
+ boolean voluntaryRelease = true;
+ MusicLockState mls = MusicCore.releaseLock(lockId,voluntaryRelease);
+ if(mls.getErrorMessage() != null) {
+ resultMap.put(ResultType.EXCEPTION.getResult(), mls.getErrorMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
+ }
+ Map<String,Object> returnMap = null;
+ if (mls.getLockStatus() == MusicLockState.LockStatus.UNLOCKED) {
+ returnMap = new JsonResponse(ResultType.SUCCESS).setLock(lockId)
+ .setLockStatus(mls.getLockStatus()).toMap();
+ response.status(Status.OK);
+ }
+ if (mls.getLockStatus() == MusicLockState.LockStatus.LOCKED) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.LOCKINGERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ returnMap = new JsonResponse(ResultType.FAILURE).setLock(lockId)
+ .setLockStatus(mls.getLockStatus()).toMap();
+ response.status(Status.BAD_REQUEST);
}
- boolean voluntaryRelease = true;
- MusicLockState mls = MusicCore.releaseLock(lockId,voluntaryRelease);
- if(mls.getErrorMessage() != null) {
- resultMap.put(ResultType.EXCEPTION.getResult(), mls.getErrorMessage());
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
- }
- Map<String,Object> returnMap = null;
- if (mls.getLockStatus() == MusicLockState.LockStatus.UNLOCKED) {
- returnMap = new JsonResponse(ResultType.SUCCESS).setLock(lockId)
- .setLockStatus(mls.getLockStatus()).toMap();
- }
- if (mls.getLockStatus() == MusicLockState.LockStatus.LOCKED) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.LOCKINGERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- returnMap = new JsonResponse(ResultType.FAILURE).setLock(lockId)
- .setLockStatus(mls.getLockStatus()).toMap();
- }
- return returnMap;
- }
+ return response.entity(returnMap).build();
+ }
- /**
- *
- * @param lockName
- * @throws Exception
- */
- @DELETE
- @Path("/delete/{lockname}")
- @ApiOperation(value = "Delete Lock", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> deleteLock(@PathParam("lockname") String lockName,
- @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
+ /**
+ *
+ * @param lockName
+ * @throws Exception
+ */
+ @DELETE
+ @Path("/delete/{lockname}")
+ @ApiOperation(value = "Delete Lock", response = Map.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response deleteLock(@PathParam("lockname") String lockName,
+ @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,
- @Context HttpServletResponse response) throws Exception{
- response.addHeader(xLatestVersion,MusicUtil.getVersion());
+ required = true) @HeaderParam("password") String password) throws Exception{
+ ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
Map<String, Object> resultMap = MusicCore.validateLock(lockName);
if (resultMap.containsKey("Exception")) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
@@ -413,12 +409,11 @@ public class RestMusicLocksAPI {
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
if (!resultMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- response.setStatus(400);
- return resultMap;
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
- MusicCore.deleteLock(lockName);
- return new JsonResponse(ResultType.SUCCESS).toMap();
- }
+ MusicCore.deleteLock(lockName);
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).toMap()).build();
+ }
}
diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
index e82280f8..b9fd058a 100644
--- a/src/test/java/org/onap/music/unittests/TestRestMusicData.java
+++ b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
@@ -470,7 +470,6 @@ public class TestRestMusicData {
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());
@@ -552,13 +551,6 @@ public class TestRestMusicData {
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);
@@ -583,14 +575,12 @@ public class TestRestMusicData {
@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"));
}
@@ -611,7 +601,6 @@ public class TestRestMusicData {
@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();
@@ -641,7 +630,6 @@ public class TestRestMusicData {
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");
@@ -667,10 +655,6 @@ public class TestRestMusicData {
@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") );
@@ -689,8 +673,6 @@ public class TestRestMusicData {
@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"));
}
@@ -698,7 +680,7 @@ public class TestRestMusicData {
@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);
+ Map<String, Object> resultMap = (Map<String, Object>) lock.createLockReference(lockName,"1","1", null, appName, userId, password).getEntity();
@SuppressWarnings("unchecked")
Map<String, Object> resultMap1 = (Map<String, Object>) resultMap.get("lock");
lockId = (String) resultMap1.get("lock");
@@ -708,28 +690,28 @@ public class TestRestMusicData {
@Test
public void Test4_accquireLock() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = lock.accquireLock(lockId, null, appName, userId, password, http);
+ Map<String, Object> resultMap = (Map<String, Object>) lock.accquireLock(lockId,"1","1", null, appName, userId, password).getEntity();
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
@Test
public void Test5_currentLockHolder() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = lock.currentLockHolder(lockName, null, appName, userId, password, http);
+ Map<String, Object> resultMap = (Map<String, Object>) lock.currentLockHolder(lockName,"1","1", null, appName, userId, password).getEntity();
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
@Test
public void Test7_unLock() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = lock.unLock(lockId, null, appName, userId, password, http);
+ Map<String, Object> resultMap = (Map<String, Object>) lock.unLock(lockId,"1","1", null, appName, userId, password).getEntity();
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
@Test
public void Test8_delete() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = lock.deleteLock(lockName, null, appName, userId, password, http);
+ Map<String, Object> resultMap = (Map<String, Object>) lock.deleteLock(lockName,"1","1", null, appName, userId, password).getEntity();
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
} \ No newline at end of file
diff --git a/version.properties b/version.properties
index ecf57f41..8cfb5921 100644
--- a/version.properties
+++ b/version.properties
@@ -4,7 +4,7 @@
major=2
minor=5
-patch=2
+patch=3
base_version=${major}.${minor}.${patch}