aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--INFO.yaml0
-rw-r--r--README.md4
-rw-r--r--WebContent/WEB-INF/web.xml5
-rw-r--r--distribution/cassandra/Dockerfile7
-rw-r--r--distribution/cassandra/cassandra.yaml5
-rw-r--r--distribution/cassandra_job/Dockerfile9
-rw-r--r--distribution/cassandra_job/admin.cql17
-rw-r--r--distribution/cassandra_job/admin_pw.cql2
-rw-r--r--distribution/cassandra_job/runcql.sh71
-rw-r--r--distribution/cassandra_job/test.cql2
-rw-r--r--docs/architecture.rst10
-rw-r--r--docs/authentication.rst27
-rw-r--r--docs/configuration.rst27
-rwxr-xr-xdocs/index.rst12
-rw-r--r--docs/installation.rst20
-rw-r--r--docs/logging.rst13
-rw-r--r--docs/release-notes.rst53
-rw-r--r--docs/setup.rst8
-rw-r--r--docs/single.rst2
-rw-r--r--docs/swagger.json2118
-rw-r--r--example/VotingApp/README.md (renamed from examples/VotingApp/README.md)0
-rw-r--r--example/VotingApp/pom.xml (renamed from examples/VotingApp/pom.xml)58
-rw-r--r--example/VotingApp/src/main/java/main/JsonDelete.java (renamed from examples/VotingApp/src/main/java/main/JsonDelete.java)0
-rw-r--r--example/VotingApp/src/main/java/main/JsonInsert.java (renamed from examples/VotingApp/src/main/java/main/JsonInsert.java)0
-rw-r--r--example/VotingApp/src/main/java/main/JsonKeySpace.java (renamed from examples/VotingApp/src/main/java/main/JsonKeySpace.java)0
-rw-r--r--example/VotingApp/src/main/java/main/JsonTable.java (renamed from examples/VotingApp/src/main/java/main/JsonTable.java)0
-rw-r--r--example/VotingApp/src/main/java/main/MusicConnector.java (renamed from examples/VotingApp/src/main/java/main/MusicConnector.java)0
-rw-r--r--example/VotingApp/src/main/java/main/Util.java (renamed from examples/VotingApp/src/main/java/main/Util.java)0
-rw-r--r--example/VotingApp/src/main/java/main/VotingAppJar.java115
-rw-r--r--example/VotingApp/src/main/java/main/VotingAppREST.java (renamed from examples/VotingApp/src/main/java/main/VotingApp.java)6
-rw-r--r--example/VotingAppJar/VotingAppJar/pom.xml30
-rw-r--r--example/VotingAppJar/VotingAppJar/src/main/java/org/onap/music/VotingAppJar/VotingAppJar.java115
-rw-r--r--example/VotingAppJar/VotingAppJar/src/test/java/org/onap/music/VotingAppJar/AppTest.java38
-rw-r--r--examples/VotingApp/dependency-reduced-pom.xml38
-rw-r--r--jar/DO_NOT_EDIT_ANYTHING_IN_THIS_FOLDER.md1
-rw-r--r--jar/pom.xml29
-rw-r--r--jar/src/main/java/LICENSE.txt24
-rw-r--r--jar/src/main/java/org/onap/music/datastore/MusicDataStore.java469
-rw-r--r--jar/src/main/java/org/onap/music/datastore/PreparedQueryObject.java79
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/AAFResponse.java42
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/JSONObject.java37
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java87
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java122
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java77
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java52
-rwxr-xr-xjar/src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java83
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java59
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java117
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java132
-rw-r--r--jar/src/main/java/org/onap/music/datastore/jsonobjects/NameSpace.java47
-rw-r--r--jar/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java175
-rw-r--r--jar/src/main/java/org/onap/music/eelf/logging/EELFLoggerDelegate.java354
-rw-r--r--jar/src/main/java/org/onap/music/eelf/logging/format/AppMessages.java183
-rw-r--r--jar/src/main/java/org/onap/music/eelf/logging/format/ErrorCodes.java106
-rw-r--r--jar/src/main/java/org/onap/music/eelf/logging/format/ErrorSeverity.java37
-rw-r--r--jar/src/main/java/org/onap/music/eelf/logging/format/ErrorTypes.java44
-rw-r--r--jar/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java53
-rw-r--r--jar/src/main/java/org/onap/music/exceptions/MusicLockingException.java74
-rw-r--r--jar/src/main/java/org/onap/music/exceptions/MusicPolicyVoilationException.java79
-rw-r--r--jar/src/main/java/org/onap/music/exceptions/MusicQueryException.java89
-rw-r--r--jar/src/main/java/org/onap/music/exceptions/MusicServiceException.java84
-rw-r--r--jar/src/main/java/org/onap/music/lockingservice/LockListener.java39
-rw-r--r--jar/src/main/java/org/onap/music/lockingservice/MusicLockState.java137
-rw-r--r--jar/src/main/java/org/onap/music/lockingservice/MusicLockingService.java184
-rw-r--r--jar/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java208
-rw-r--r--jar/src/main/java/org/onap/music/lockingservice/ZNodeName.java118
-rw-r--r--jar/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java339
-rw-r--r--jar/src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java42
-rwxr-xr-xjar/src/main/java/org/onap/music/main/CachingUtil.java420
-rw-r--r--jar/src/main/java/org/onap/music/main/CipherUtil.java269
-rw-r--r--jar/src/main/java/org/onap/music/main/CronJobManager.java47
-rw-r--r--jar/src/main/java/org/onap/music/main/MusicCore.java992
-rw-r--r--jar/src/main/java/org/onap/music/main/MusicDigest.java78
-rwxr-xr-xjar/src/main/java/org/onap/music/main/MusicUtil.java572
-rwxr-xr-xjar/src/main/java/org/onap/music/main/PropertiesListener.java151
-rw-r--r--jar/src/main/java/org/onap/music/main/ResultType.java41
-rw-r--r--jar/src/main/java/org/onap/music/main/ReturnType.java74
-rw-r--r--jar/src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java265
-rwxr-xr-xjar/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java372
-rw-r--r--jar/src/main/java/org/onap/music/rest/RestMusicBmAPI.java307
-rwxr-xr-xjar/src/main/java/org/onap/music/rest/RestMusicDataAPI.java1289
-rw-r--r--jar/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java113
-rw-r--r--jar/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java423
-rwxr-xr-xjar/src/main/java/org/onap/music/rest/RestMusicQAPI.java251
-rw-r--r--jar/src/main/java/org/onap/music/rest/RestMusicTestAPI.java67
-rw-r--r--jar/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java63
-rw-r--r--jar/src/main/resources/LICENSE.txt24
-rw-r--r--jar/src/main/resources/Resources.properties50
-rw-r--r--jar/src/main/resources/cache.ccf56
-rw-r--r--jar/src/main/resources/logback.xml270
-rw-r--r--jar/src/main/resources/project.properties4
-rw-r--r--jar/src/test/java/LICENSE.txt24
-rw-r--r--jar/src/test/java/org/onap/music/unittests/CassandraCQL.java256
-rw-r--r--jar/src/test/java/org/onap/music/unittests/JsonResponseTest.java83
-rw-r--r--jar/src/test/java/org/onap/music/unittests/MusicUtilTest.java207
-rw-r--r--jar/src/test/java/org/onap/music/unittests/ResultTypeTest.java43
-rw-r--r--jar/src/test/java/org/onap/music/unittests/ReturnTypeTest.java83
-rw-r--r--jar/src/test/java/org/onap/music/unittests/TestLockStore.java53
-rw-r--r--jar/src/test/java/org/onap/music/unittests/TestMusicCore.java489
-rw-r--r--jar/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java176
-rw-r--r--jar/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java54
-rw-r--r--jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java86
-rw-r--r--jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java86
-rw-r--r--jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java72
-rw-r--r--jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java53
-rw-r--r--jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java78
-rw-r--r--jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java41
-rw-r--r--jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java99
-rw-r--r--jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java103
-rw-r--r--jar/version.properties13
-rw-r--r--musictrigger/pom.xml158
-rw-r--r--[-rwxr-xr-x]musictrigger/src/MusicTrigger.java129
-rwxr-xr-xpom.xml61
-rw-r--r--src/main/java/org/onap/music/conductor/conditionals/JsonConditional.java4
-rw-r--r--src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java47
-rw-r--r--src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java4
-rw-r--r--src/main/java/org/onap/music/datastore/CassaDataStore.java (renamed from src/main/java/org/onap/music/datastore/MusicDataStore.java)98
-rw-r--r--src/main/java/org/onap/music/datastore/CassaLockStore.java173
-rw-r--r--src/main/java/org/onap/music/datastore/MusicLockState.java41
-rw-r--r--src/main/java/org/onap/music/datastore/PreparedQueryObject.java5
-rwxr-xr-xsrc/main/java/org/onap/music/datastore/jsonobjects/JSONCallbackResponse.java89
-rwxr-xr-xsrc/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java135
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java4
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java5
-rwxr-xr-xsrc/main/java/org/onap/music/datastore/jsonobjects/JsonNotification.java119
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonNotifyClientResponse.java59
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java5
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java9
-rw-r--r--src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java31
-rw-r--r--src/main/java/org/onap/music/lockingservice/LockListener.java39
-rw-r--r--src/main/java/org/onap/music/lockingservice/MusicLockState.java140
-rw-r--r--src/main/java/org/onap/music/lockingservice/MusicLockingService.java168
-rw-r--r--src/main/java/org/onap/music/lockingservice/ProtocolSupport.java210
-rw-r--r--src/main/java/org/onap/music/lockingservice/ZNodeName.java118
-rw-r--r--src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java363
-rw-r--r--src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java42
-rwxr-xr-xsrc/main/java/org/onap/music/main/CachingUtil.java75
-rw-r--r--src/main/java/org/onap/music/main/CronJobManager.java94
-rw-r--r--src/main/java/org/onap/music/main/MusicCore.java776
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java83
-rwxr-xr-xsrc/main/java/org/onap/music/main/PropertiesListener.java9
-rw-r--r--src/main/java/org/onap/music/main/VotingAppJar.java115
-rw-r--r--src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java9
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicAdminAPI.java480
-rw-r--r--src/main/java/org/onap/music/rest/RestMusicBmAPI.java307
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicDataAPI.java76
-rw-r--r--src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java20
-rw-r--r--src/main/java/org/onap/music/rest/RestMusicLocksAPI.java23
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicQAPI.java35
-rw-r--r--src/main/java/org/onap/music/rest/RestMusicVersionAPI.java3
-rw-r--r--src/main/resources/logback.xml7
-rw-r--r--src/test/java/org/onap/music/unittests/CassandraCQL.java6
-rw-r--r--src/test/java/org/onap/music/unittests/MusicDataStoreTest.java4
-rw-r--r--src/test/java/org/onap/music/unittests/MusicLockStoreTest.java (renamed from jar/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java)22
-rw-r--r--src/test/java/org/onap/music/unittests/TestCassaLockStore.java71
-rw-r--r--src/test/java/org/onap/music/unittests/TestLockStore.java53
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCore.java711
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java53
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestAdminData.java2244
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicData.java (renamed from jar/src/test/java/org/onap/music/unittests/TestRestMusicData.java)534
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java10
-rw-r--r--src/test/java/org/onap/music/unittests/TestVotingApp.java115
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java44
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonNotifyClientResponseTest.java46
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java56
-rw-r--r--[-rwxr-xr-x]version.properties2
166 files changed, 2168 insertions, 21082 deletions
diff --git a/INFO.yaml b/INFO.yaml
deleted file mode 100644
index e69de29b..00000000
--- a/INFO.yaml
+++ /dev/null
diff --git a/README.md b/README.md
index 3f83f2da..b86ff4f5 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-## MUSIC - Multi-site State Coordination Service
-
+xxxtest## MUSIC - Multi-site State Coordination Service
+123
To achieve 5 9s of availability on 3 9s or lower software and infrastructure in a cost-effective manner, ONAP components need to work in a reliable, active-active manner across multiple sites (platform-maturity resiliency level 3). A fundamental aspect of this is state management across geo-distributed sites in a reliable, scalable, highly available and efficient manner. This is an important and challenging problem because of three fundamental reasons:
* Current solutions for state-management of ONAP components like MariaDB clustering, that work very effectively within a site, may not scale across geo-distributed sites (e.g., Beijing, Amsterdam and Irvine) or allow partitioned operation (thereby compromising availability). This is mainly because WAN latencies are much higher across sites and frequent network partitions can occur.
diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml
index 7b6caf4c..3bab5589 100644
--- a/WebContent/WEB-INF/web.xml
+++ b/WebContent/WEB-INF/web.xml
@@ -6,11 +6,6 @@
org.onap.music.main.PropertiesListener
</listener-class>
</listener>
- <listener>
- <listener-class>
- org.onap.music.main.CronJobManager
- </listener-class>
- </listener>
<servlet>
<servlet-name>music-servlet</servlet-name>
<servlet-class>
diff --git a/distribution/cassandra/Dockerfile b/distribution/cassandra/Dockerfile
index fe13322c..9405fcb3 100644
--- a/distribution/cassandra/Dockerfile
+++ b/distribution/cassandra/Dockerfile
@@ -1,4 +1,9 @@
#registry.hub.docker.com/
-FROM library/cassandra:3.11
+FROM library/cassandra:3.0
+RUN mkdir -p /docker-entrypoint-initdb.d && mkdir -p /home/cassandra/.cassandra && chown -R cassandra /home/cassandra
COPY cassandra.yaml /etc/cassandra/
+COPY music_single.cql /docker-entrypoint-initdb.d/
+COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
+RUN chmod 755 /usr/local/bin/docker-entrypoint.sh && chown -R cassandra /docker-entrypoint-initdb.d
+
ENTRYPOINT ["docker-entrypoint.sh"]
diff --git a/distribution/cassandra/cassandra.yaml b/distribution/cassandra/cassandra.yaml
index fa7c74a6..d4af64af 100644
--- a/distribution/cassandra/cassandra.yaml
+++ b/distribution/cassandra/cassandra.yaml
@@ -530,8 +530,7 @@ native_transport_port: 9042
# native_transport_max_concurrent_connections_per_ip: -1
# Whether to start the thrift rpc server.
-#start_rpc: false
-start_rpc: true
+start_rpc: false
# The address or interface to bind the Thrift RPC service and native transport
# server to.
@@ -721,7 +720,7 @@ sstable_preemptive_open_interval_in_mb: 50
# How long the coordinator should wait for read operations to complete
read_request_timeout_in_ms: 5000
# How long the coordinator should wait for seq or index scans to complete
-range_request_timeout_in_ms: 15000
+range_request_timeout_in_ms: 10000
# How long the coordinator should wait for writes to complete
write_request_timeout_in_ms: 2000
# How long the coordinator should wait for counter writes to complete
diff --git a/distribution/cassandra_job/Dockerfile b/distribution/cassandra_job/Dockerfile
deleted file mode 100644
index 528c3bf4..00000000
--- a/distribution/cassandra_job/Dockerfile
+++ /dev/null
@@ -1,9 +0,0 @@
-#registry.hub.docker.com/
-FROM library/cassandra:3.11
-ENV DEF_USER=cassandra
-ENV DEF_PASS=cassandra
-COPY runcql.sh /
-RUN mkdir -p cql/extra && \
- chmod 755 runcql.sh && \
- chown cassandra runcql.sh
-CMD ["/runcql.sh"]
diff --git a/distribution/cassandra_job/admin.cql b/distribution/cassandra_job/admin.cql
deleted file mode 100644
index 904a2bab..00000000
--- a/distribution/cassandra_job/admin.cql
+++ /dev/null
@@ -1,17 +0,0 @@
-CREATE KEYSPACE IF NOT EXISTS admin
- WITH REPLICATION = {
- 'class' : 'SimpleStrategy',
- 'replication_factor': 1
- }
- AND DURABLE_WRITES = true;
-
-CREATE TABLE IF NOT EXISTS admin.keyspace_master (
- uuid uuid,
- keyspace_name text,
- application_name text,
- is_api boolean,
- password text,
- username text,
- is_aaf boolean,
- PRIMARY KEY (uuid)
-);
diff --git a/distribution/cassandra_job/admin_pw.cql b/distribution/cassandra_job/admin_pw.cql
deleted file mode 100644
index bbad8d1d..00000000
--- a/distribution/cassandra_job/admin_pw.cql
+++ /dev/null
@@ -1,2 +0,0 @@
-CREATE ROLE IF NOT EXISTS <CASSUSER> WITH PASSWORD = '<CASSPASS>' AND SUPERUSER = True AND LOGIN = True;
-ALTER ROLE cassandra WITH PASSWORD = 'SomeLongRandomStringNoonewillthinkof';
diff --git a/distribution/cassandra_job/runcql.sh b/distribution/cassandra_job/runcql.sh
deleted file mode 100644
index 687e93b3..00000000
--- a/distribution/cassandra_job/runcql.sh
+++ /dev/null
@@ -1,71 +0,0 @@
-#! /bin/bash
-if [ $CASS_HOSTNAME ]; then
- echo "#############################################"
- echo "############## Let run cql's ################"
- echo "#############################################"
- echo "Current Variales in play"
- echo "Default User"
- echo "DEF_USER="$DEF_USER
- echo "DEF_PASS=***********"
- echo "New User"
- echo "USERNAME="$USERNAME
- echo "PASSWORD=***********"
- if cqlsh -u cassandra -p cassandra -e "describe keyspaces;";
- then
- >&2 echo "Cassandra user still avalable, will continue as usual";
- else
- if cqlsh -u $USERNAME -p $PASSWORD -e "describe keyspaces;";
- then
- >&2 echo "Password $USERNAME in play, update Variables"
- DEF_USER=$USERNAME
- DEF_PASS=$PASSWORD
- if cqlsh -u $USERNAME -p $PASSWORD -e "describe keyspaces;" | grep admin1;
- then
- >&2 echo "Admin table exists, everything looks good"
- exit 0;
- else
- >&2 echo "Admin does not exists but password has changed. Continue as usual with proper username set"
- >&2 echo "DEF_USER=" $DEF_USER
- fi
- else
- >&2 echo "Continue and as usual"
- fi
- fi
- echo "admin.cql file:"
- cat /cql/admin.cql
- >&2 echo "Running cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin.cql ${CASS_HOSTNAME} ${PORT}"
- sleep 1;
- if cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin.cql ${CASS_HOSTNAME} ${PORT};
- then
- >&2 echo "Success - admin.cql - Admin keyspace created";
- else
- >&2 echo "Failure - admin.cql";
- exit 0;
- fi
- echo "admin_pw.cql file:"
- cat /cql/admin_pw.cql
- >&2 echo "Running cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin_pw.cql ${CASS_HOSTNAME} ${PORT}"
- sleep 1;
- if cqlsh -u $DEF_USER -p $DEF_PASS -f /cql/admin_pw.cql ${CASS_HOSTNAME} ${PORT};
- then
- >&2 echo "Success - admin_pw.cql - Password Changed";
- else
- >&2 echo "Failure - admin_pw.cql";
- exit 0;
- fi
-
- for f in /cql/extra/*; do
- case "$f" in
- *.cql)
- echo "$0: running $f" && cqlsh -u ${USERNAME} -p ${PASSWORD} -f "$f" ${CASS_HOSTNAME} ${PORT};
- ;;
- *)
- echo "$0: ignoring $f"
- ;;
- esac
- done
-else
- >&2 echo "Missing CASS_HOSTNAME";
- exit 0;
-fi
-
diff --git a/distribution/cassandra_job/test.cql b/distribution/cassandra_job/test.cql
deleted file mode 100644
index 196fea22..00000000
--- a/distribution/cassandra_job/test.cql
+++ /dev/null
@@ -1,2 +0,0 @@
-DESCRIBE keyspaces;
-
diff --git a/docs/architecture.rst b/docs/architecture.rst
index ae29f9e0..8daa0d3b 100644
--- a/docs/architecture.rst
+++ b/docs/architecture.rst
@@ -4,7 +4,15 @@
Architecture
============
-` See ONAP Wiki <https://wiki.onap.org/display/DW/MUSIC-Multi-site+State+Coordination+Service>`_
+.. note::
+ * This section is used to describe a software component from a high level
+ view of capability, common usage scenarios, and interactions with other
+ components required in the usage scenarios.
+
+ * The architecture section is typically: provided in a platform-component
+ and sdk collections; and referenced from developer and user guides.
+
+ * This note must be removed after content has been added.
Capabilities
diff --git a/docs/authentication.rst b/docs/authentication.rst
index 87dbea05..3c6f48a4 100644
--- a/docs/authentication.rst
+++ b/docs/authentication.rst
@@ -1,25 +1,22 @@
-Authentication
-==============
+ `For Single install:`_
-`Single-Site Install`_
+ `Multi-Site Install:`_
-`Multi-Site Install`_
+ `Headers:`_
-`Headers`_
+ `AAF Authentication`_
-`AAF Authentication`_
-
-`AID Authentication Non-AAF`_
+ `AID Authentication Non-AAF`_
`Onboarding API`_
- `Add Application`_
+`Add Application`_
- `Get Application`_
+`Get Application`_
- `Edit Application`_
+`Edit Application`_
- `Delete 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.
@@ -36,7 +33,7 @@ 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>
-Single-Site Install
+For Single install:
^^^^^^^^^^^^^^^^^^^
::
@@ -61,7 +58,7 @@ Single-Site Install
);
-Multi-Site Install
+Multi-Site Install:
^^^^^^^^^^^^^^^^^^^
::
@@ -86,7 +83,7 @@ Multi-Site Install
PRIMARY KEY (uuid)
);
-Headers
+Headers:
^^^^^^^^
For AAF applications all the 3 headers ns, userId and password are mandatory.
diff --git a/docs/configuration.rst b/docs/configuration.rst
index 279e5bd6..085f9c66 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -4,25 +4,24 @@
Configuration
=============
-See the following pages for Configuration Information:
+.. note::
+ * This section is used to describe the options a software component offers for configuration.
-.. toctree::
- :maxdepth: 1
+ * Configuration is typically: provided for platform-component and sdk projects;
+ and referenced in developer and user guides.
+
+ * This note must be removed after content has been added.
- Single-Site Install <single>
- Multi-Site Install <multi>
- Authentication <authentication>
+Example ...
-.. Example ...
+You can provide the following in ``basic.conf``
-.. You can provide the following in ``basic.conf``
+``host=ADDRESS``
+ The address of the host
-.. ``host=ADDRESS``
-.. The address of the host
+``port=PORT``
+ The port used for signaling
-.. ``port=PORT``
-.. The port used for signaling
-
-.. Optional. Default: ``8080``
+ Optional. Default: ``8080``
diff --git a/docs/index.rst b/docs/index.rst
index 437a50d8..3ef97755 100755
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -8,17 +8,17 @@ Music Developer Documentation
.. toctree::
:maxdepth: 1
- installation
+ Single-SIte Install <single>
+ Muili-Site Install <multi>
setup
release-notes
- architecture
- logging
- configuration
-
+
.. architecture
+.. configuration
.. consumedapis
.. delivery
.. index
-..
+.. installation
+.. logging
.. offeredapis
diff --git a/docs/installation.rst b/docs/installation.rst
index 1b817114..be64a63b 100644
--- a/docs/installation.rst
+++ b/docs/installation.rst
@@ -4,17 +4,17 @@
Installation
============
+.. note::
+ * This section is used to describe how a software component is acquired and installed.
+
+ * This section is typically: provided for a platform-component and application; and
+ referenced in user guides.
-.. toctree::
- :maxdepth: 1
+ * This note must be removed after content has been added.
- Single-Site Install <single>
- Multi-Site Install <multi>
+Environment
+-----------
-.. Environment
-.. -----------
-
-
-.. Steps
-.. -----
+Steps
+-----
diff --git a/docs/logging.rst b/docs/logging.rst
index b1d3a186..39eabfba 100644
--- a/docs/logging.rst
+++ b/docs/logging.rst
@@ -4,8 +4,14 @@
Logging
=======
-Log file produced will be in /opt/app/music/logs/MUSIC/music.log,error.log,debug.log
-Log files are in EELF format.
+.. note::
+ * This section is used to describe the informational or diagnostic messages emitted from
+ a software component and the methods or collecting them.
+
+ * This section is typically: provided for a platform-component and sdk; and
+ referenced in developer and user guides
+
+ * This note must be removed after content has been added.
Where to Access Information
@@ -14,6 +20,3 @@ Where to Access Information
Error / Warning Messages
------------------------
-
-
-
diff --git a/docs/release-notes.rst b/docs/release-notes.rst
index 766fb123..9b6688c3 100644
--- a/docs/release-notes.rst
+++ b/docs/release-notes.rst
@@ -4,58 +4,47 @@
Release Notes
=============
-Initial Release for Beijing
-Version: 2.5.4
---------------
-
-:Release Date: 2018-06-07
-
-**New Features**
+.. note::
+ * This Release Notes must be updated each time the team decides to Release new artifacts.
+ * The scope of this Release Notes is for this particular component. In other words, each ONAP component has its Release Notes.
+ * This Release Notes is cumulative, the most recently Released artifact is made visible in the top of this Release Notes.
+ * Except the date and the version number, all the other sections are optional but there must be at least one section describing the purpose of this new release.
+ * This note must be removed after content has been added.
-MUSIC provides a service with recipes that individual ONAP components and microservice can use for
- - state replication across multiple geo-distributed sites
- - flexible fine-grained consistency management of state
- - policy driven state-ownership across replicas of the service
+Version: x.y.z
+--------------
-**Bug Fixes**
- - `MUSIC-33 <https://jira.onap.org/projects/MUSIC/issues/MUSIC-33>`_ CriticalPut is causing HTTP Status 500 – Internal Server Error
+:Release Date: yyyy-mm-dd
- - `MUSIC-34 <https://jira.onap.org/projects/MUSIC/issues/MUSIC-34>`_ CreateTable,InsertIntoTable,UpdateTable,DeleteFromTable,DropTable don't check resource existence
- - `MUSIC-35 <https://jira.onap.org/projects/MUSIC/issues/MUSIC-35>`_ Onboarding issues
- - `MUSIC-36 <https://jira.onap.org/projects/MUSIC/issues/MUSIC-36>`_ Test Case failing
+**New Features**
- - `MUSIC-37 <https://jira.onap.org/projects/MUSIC/issues/MUSIC-37>`_ Acquire lock to return more information
+One or two sentences explaining the purpose of this Release.
+**Bug Fixes**
+ - `CIMAN-65 <https://jira.onap.org/browse/CIMAN-65>`_ and a sentence explaining what this defect is addressing.
**Known Issues**
-N/A
-
-**Security Notes**
-
-MUSIC code has been formally scanned during build time using NexusIQ and all Critical vulnerabilities have been addressed, items that remain open have been assessed for risk and determined to be false positive. The MUSIC open Critical security vulnerabilities and their risk assessment have been documented as part of the `project <https://wiki.onap.org/pages/viewpage.action?pageId=25439359>`_.
+ - `CIMAN-65 <https://jira.onap.org/browse/CIMAN-65>`_ and two, three sentences.
+ One sentences explaining what is the issue.
+
+ Another sentence explaining the impact of the issue.
+
+ And an optional sentence providing a workaround.
-Quick Links:
+**Security Issues**
+ You may want to include a reference to CVE (Common Vulnerabilities and Exposures) `CVE <https://cve.mitre.org>`_
-- `MUSIC project page <https://wiki.onap.org/display/DW/MUSIC+Project>`_
-- `Passing Badge information for MUSIC <https://bestpractices.coreinfrastructure.org/en/projects/1722>`_
-- `Project Vulnerability Review Table for MUSIC <https://wiki.onap.org/pages/viewpage.action?pageId=25439359>`_
**Upgrade Notes**
- N/A
-
**Deprecation Notes**
- N/A
-
**Other**
- N/A
-
===========
End of Release Notes
diff --git a/docs/setup.rst b/docs/setup.rst
index b12acd04..208c779b 100644
--- a/docs/setup.rst
+++ b/docs/setup.rst
@@ -5,8 +5,8 @@ Setup for Developing MUSIC
:maxdepth: 1
Single-Site Install <single>
- Multi-Site Install <multi>
- Authentication <authentication>
+ Muili-Site Install <multi>
+ Authentication
MUSIC is to be installed in a single Dir on a vm.
@@ -46,5 +46,5 @@ Continue by selecting the link to the setup you are doing.
:maxdepth: 1
Single-Site Install <single>
- Multi-Site Install <multi>
- Authentication <authentication>
+ Muili-Site Install <multi>
+ Authentication
diff --git a/docs/single.rst b/docs/single.rst
index 060f02b4..08c5e315 100644
--- a/docs/single.rst
+++ b/docs/single.rst
@@ -15,7 +15,7 @@ Instructions
- 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/r3.4.6/zookeeperStarted.html pertaining to the standalone operation. By the end of this you should have Zookeeper 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:
diff --git a/docs/swagger.json b/docs/swagger.json
index 27db769f..c352537b 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -1,2117 +1 @@
-{
- "swagger": "2.0",
- "info": {
- "version": "1.0.0",
- "title": ""
- },
- "host": "localhost:8080",
- "basePath": "/MUSIC/rest",
- "tags": [
- {
- "name": "Data Api"
- },
- {
- "name": "Healthcheck Api"
- },
- {
- "name": "Lock Api"
- },
- {
- "name": "Q Api"
- },
- {
- "name": "Test Api"
- },
- {
- "name": "Version Api"
- }
- ],
- "schemes": [
- "http"
- ],
- "paths": {
- "/v2/keyspaces/{keyspace}/tables/{tablename}/rows": {
- "get": {
- "tags": [
- "Data Api"
- ],
- "summary": "Select All or Select Specific",
- "description": "",
- "operationId": "select",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "tablename",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- },
- "post": {
- "tags": [
- "Data Api"
- ],
- "summary": "Insert Into Table",
- "description": "",
- "operationId": "insertIntoTable",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "tablename",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- },
- "put": {
- "tags": [
- "Data Api"
- ],
- "summary": "Update Table",
- "description": "",
- "operationId": "updateTable",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "tablename",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- },
- "delete": {
- "tags": [
- "Data Api"
- ],
- "summary": "Delete From table",
- "description": "",
- "operationId": "deleteFromTable",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "tablename",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- }
- },
- "/v2/keyspaces/{name}": {
- "post": {
- "tags": [
- "Data Api"
- ],
- "summary": "Create Keyspace",
- "description": "",
- "operationId": "createKeySpace",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "name",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- },
- "delete": {
- "tags": [
- "Data Api"
- ],
- "summary": "Delete Keyspace",
- "description": "",
- "operationId": "dropKeySpace",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "name",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- }
- },
- "/v2/keyspaces/{keyspace}/tables/{tablename}/index/{field}": {
- "post": {
- "tags": [
- "Data Api"
- ],
- "summary": "Create Index",
- "description": "",
- "operationId": "createIndex",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "tablename",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "field",
- "in": "path",
- "description": "Field Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- }
- },
- "/v2/keyspaces/{keyspace}/tables/{tablename}/rows/criticalget": {
- "put": {
- "tags": [
- "Data Api"
- ],
- "summary": "Select Critical",
- "description": "",
- "operationId": "selectCritical",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "tablename",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v2/keyspaces/{keyspace}/tables/{tablename}": {
- "post": {
- "tags": [
- "Data Api"
- ],
- "summary": "Create Table",
- "description": "",
- "operationId": "createTable",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "tablename",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- },
- "delete": {
- "tags": [
- "Data Api"
- ],
- "summary": "Drop Table",
- "description": "",
- "operationId": "dropTable",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Keyspace Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "tablename",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- }
- },
- "/v{version}/service/pingCassandra/{consistency}": {
- "get": {
- "tags": [
- "Healthcheck Api"
- ],
- "summary": "Get Health Status",
- "description": "",
- "operationId": "cassandraStatus",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "consistency",
- "in": "path",
- "description": "Consistency level",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v{version}/service/pingZookeeper": {
- "get": {
- "tags": [
- "Healthcheck Api"
- ],
- "summary": "Get Health Status",
- "description": "",
- "operationId": "ZKStatus",
- "produces": [
- "application/json"
- ],
- "parameters": [],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v2/locks/create/{lockname}": {
- "post": {
- "tags": [
- "Lock Api"
- ],
- "summary": "Create Lock",
- "description": "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",
- "operationId": "createLockReference",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "lockname",
- "in": "path",
- "description": "Lock Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v2/locks/acquire/{lockreference}": {
- "get": {
- "tags": [
- "Lock Api"
- ],
- "summary": "Aquire Lock",
- "description": "Checks if the node is in the top of the queue and hence acquires the lock",
- "operationId": "accquireLock",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "lockreference",
- "in": "path",
- "description": "Lock Reference",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v2/locks/acquire-with-lease/{lockreference}": {
- "post": {
- "tags": [
- "Lock Api"
- ],
- "summary": "Aquire Lock with Lease",
- "description": "",
- "operationId": "accquireLockWithLease",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "lockreference",
- "in": "path",
- "description": "Lock Reference",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v2/locks/enquire/{lockname}": {
- "get": {
- "tags": [
- "Lock Api"
- ],
- "summary": "Get Lock Holder",
- "description": "Gets the current Lock Holder",
- "operationId": "currentLockHolder",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "lockname",
- "in": "path",
- "description": "Lock Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v2/locks/{lockname}": {
- "get": {
- "tags": [
- "Lock Api"
- ],
- "summary": "Lock State",
- "description": "Returns current Lock State and Holder.",
- "operationId": "currentLockState",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "lockname",
- "in": "path",
- "description": "Lock Name",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "userId",
- "in": "header",
- "description": "userId",
- "required": true,
- "type": "string"
- },
- {
- "name": "password",
- "in": "header",
- "description": "Password",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v2/locks/release/{lockreference}": {
- "delete": {
- "tags": [
- "Lock Api"
- ],
- "summary": "Release Lock",
- "description": "deletes the process from the zk queue",
- "operationId": "unLock",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "lockreference",
- "in": "path",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v2/locks/delete/{lockname}": {
- "delete": {
- "tags": [
- "Lock Api"
- ],
- "summary": "Delete Lock",
- "description": "",
- "operationId": "deleteLock",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "lockname",
- "in": "path",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/{version}/priorityq/keyspaces/{keyspace}/{qname}": {
- "post": {
- "tags": [
- "Q Api"
- ],
- "summary": "Create Q",
- "description": "",
- "operationId": "createQ",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Key Space",
- "required": true,
- "type": "string"
- },
- {
- "name": "qname",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- },
- "delete": {
- "tags": [
- "Q Api"
- ],
- "summary": "DropQ",
- "description": "",
- "operationId": "dropQ",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Key Space",
- "required": true,
- "type": "string"
- },
- {
- "name": "qname",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- }
- },
- "/{version}/priorityq/keyspaces/{keyspace}/{qname}/rows": {
- "post": {
- "tags": [
- "Q Api"
- ],
- "summary": "",
- "description": "",
- "operationId": "insertIntoQ",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Key Space",
- "required": true,
- "type": "string"
- },
- {
- "name": "qname",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "default": {
- "description": "successful operation"
- }
- }
- },
- "put": {
- "tags": [
- "Q Api"
- ],
- "summary": "updateQ",
- "description": "",
- "operationId": "updateQ",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Key Space",
- "required": true,
- "type": "string"
- },
- {
- "name": "qname",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- },
- "delete": {
- "tags": [
- "Q Api"
- ],
- "summary": "deleteQ",
- "description": "",
- "operationId": "deleteFromQ",
- "consumes": [
- "application/json"
- ],
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "in": "body",
- "name": "body",
- "required": false,
- "schema": {
- "$ref": "#/definitions/JsonTable"
- }
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Key Space",
- "required": true,
- "type": "string"
- },
- {
- "name": "qname",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "string"
- }
- }
- }
- }
- },
- "/{version}/priorityq/keyspaces/{keyspace}/{qname}/peek": {
- "get": {
- "tags": [
- "Q Api"
- ],
- "summary": "",
- "description": "",
- "operationId": "peek",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Key Space",
- "required": true,
- "type": "string"
- },
- {
- "name": "qname",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/{version}/priorityq/keyspaces/{keyspace}/{qname}/filter": {
- "get": {
- "tags": [
- "Q Api"
- ],
- "summary": "filter",
- "description": "",
- "operationId": "filter",
- "produces": [
- "application/json"
- ],
- "parameters": [
- {
- "name": "version",
- "in": "path",
- "description": "Major Version",
- "required": true,
- "type": "string"
- },
- {
- "name": "X-minorVersion",
- "in": "header",
- "description": "Minor Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "X-patchVersion",
- "in": "header",
- "description": "Patch Version",
- "required": false,
- "type": "string"
- },
- {
- "name": "aid",
- "in": "header",
- "description": "AID",
- "required": true,
- "type": "string"
- },
- {
- "name": "ns",
- "in": "header",
- "description": "Application namespace",
- "required": true,
- "type": "string"
- },
- {
- "name": "Authorization",
- "in": "header",
- "description": "Authorization",
- "required": true,
- "type": "string"
- },
- {
- "name": "keyspace",
- "in": "path",
- "description": "Key Space",
- "required": true,
- "type": "string"
- },
- {
- "name": "qname",
- "in": "path",
- "description": "Table Name",
- "required": true,
- "type": "string"
- }
- ],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v{version}/test": {
- "get": {
- "tags": [
- "Test Api"
- ],
- "summary": "Get Test",
- "description": "",
- "operationId": "simpleTests",
- "produces": [
- "application/json"
- ],
- "parameters": [],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- },
- "/v{version}/version": {
- "get": {
- "tags": [
- "Version Api"
- ],
- "summary": "Get Version",
- "description": "",
- "operationId": "version",
- "produces": [
- "application/json"
- ],
- "parameters": [],
- "responses": {
- "200": {
- "description": "successful operation",
- "schema": {
- "type": "object",
- "additionalProperties": {
- "type": "object"
- }
- }
- }
- }
- }
- }
- },
- "definitions": {
- "JsonTable": {
- "type": "object",
- "properties": {
- "columns": {
- "type": "array",
- "description": "Column values",
- "items": {
- "type": "string"
- }
- },
- "consistencyInfo": {
- "type": "object",
- "description": "Consistency level",
- "additionalProperties": {
- "type": "string"
- }
- },
- "conditions": {
- "type": "object",
- "description": "Conditions",
- "additionalProperties": {
- "type": "object"
- }
- },
- "ttl": {
- "type": "string",
- "description": "Time to live information"
- },
- "timestamp": {
- "type": "string",
- "description": "Time stamp"
- }
- },
- "description": "Json model for delete"
- }
- }
-}
+{"swagger":"2.0","info":{"version":"1.0.0","title":""},"host":"localhost:8080","basePath":"/MUSIC/rest","tags":[{"name":"Version Api"},{"name":"Test Api"},{"name":"Q Api"},{"name":"Data Api"},{"name":"Lock Api"}],"schemes":["http"],"paths":{"/priorityq/keyspaces/{keyspace}/{qname}":{"post":{"tags":["Q Api"],"summary":"","description":"","operationId":"createQ","consumes":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}},"delete":{"tags":["Q Api"],"summary":"","description":"","operationId":"dropQ","parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/priorityq/keyspaces/{keyspace}/{qname}/filter":{"get":{"tags":["Q Api"],"summary":"","description":"","operationId":"filter","produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/priorityq/keyspaces/{keyspace}/{qname}/peek":{"get":{"tags":["Q Api"],"summary":"","description":"","operationId":"peek","produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/priorityq/keyspaces/{keyspace}/{qname}/rows":{"post":{"tags":["Q Api"],"summary":"","description":"","operationId":"insertIntoQ","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}},"put":{"tags":["Q Api"],"summary":"","description":"","operationId":"updateQ","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"delete":{"tags":["Q Api"],"summary":"","description":"","operationId":"deleteFromQ","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/keyspaces/{keyspace}/tables/{tablename}":{"post":{"tags":["Data Api"],"summary":"Create Table","description":"","operationId":"createTable","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"delete":{"tags":["Data Api"],"summary":"Drop Table","description":"","operationId":"dropTable","parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/keyspaces/{keyspace}/tables/{tablename}/index/{field}":{"post":{"tags":["Data Api"],"summary":"Create Index","description":"","operationId":"createIndex","produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"},{"name":"field","in":"path","description":"Field Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/keyspaces/{keyspace}/tables/{tablename}/rows":{"get":{"tags":["Data Api"],"summary":"Select All or Select Specivic","description":"","operationId":"select","produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}},"post":{"tags":["Data Api"],"summary":"Insert Into Table","description":"","operationId":"insertIntoTable","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"put":{"tags":["Data Api"],"summary":"Update Table","description":"","operationId":"updateTable","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"delete":{"tags":["Data Api"],"summary":"Delete From table","description":"","operationId":"deleteFromTable","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/keyspaces/{keyspace}/tables/{tablename}/rows/criticalget":{"put":{"tags":["Data Api"],"summary":"Select Critical","description":"","operationId":"selectCritical","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/keyspaces/{name}":{"post":{"tags":["Data Api"],"summary":"Create Keyspace","description":"","operationId":"createKeySpace","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"name","in":"path","description":"Keyspace Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"delete":{"tags":["Data Api"],"summary":"Delete Keyspace","description":"","operationId":"dropKeySpace","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"name","in":"path","description":"Keyspace Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/locks/acquire-with-lease/{lockreference}":{"post":{"tags":["Lock Api"],"summary":"Aquire Lock with Lease","description":"","operationId":"accquireLockWithLease","consumes":["application/json"],"produces":["application/json"],"parameters":[{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"lockreference","in":"path","description":"Lock Reference","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/acquire/{lockreference}":{"get":{"tags":["Lock Api"],"summary":"Aquire Lock","description":"Checks if the node is in the top of the queue and hence acquires the lock","operationId":"accquireLock","produces":["application/json"],"parameters":[{"name":"lockreference","in":"path","description":"Lock Reference","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/create/{lockname}":{"post":{"tags":["Lock Api"],"summary":"Create Lock","description":"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","operationId":"createLockReference","produces":["application/json"],"parameters":[{"name":"lockname","in":"path","description":"Lock Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/delete/{lockname}":{"delete":{"tags":["Lock Api"],"summary":"Delete Lock","description":"","operationId":"deleteLock","produces":["application/json"],"parameters":[{"name":"lockname","in":"path","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/enquire/{lockname}":{"get":{"tags":["Lock Api"],"summary":"Get Lock Holder","description":"Gets the current Lock Holder","operationId":"currentLockHolder","produces":["application/json"],"parameters":[{"name":"lockname","in":"path","description":"Lock Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/release/{lockreference}":{"delete":{"tags":["Lock Api"],"summary":"Release Lock","description":"deletes the process from the zk queue","operationId":"unLock","produces":["application/json"],"parameters":[{"name":"lockreference","in":"path","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/{lockname}":{"get":{"tags":["Lock Api"],"summary":"Lock State","description":"Returns current Lock State and Holder.","operationId":"currentLockState","produces":["application/json"],"parameters":[{"name":"lockname","in":"path","description":"Lock Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/test":{"get":{"tags":["Test Api"],"summary":"Get Test","description":"","operationId":"simpleTests","produces":["application/json"],"parameters":[],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/version":{"get":{"tags":["Version Api"],"summary":"Get Version","description":"","operationId":"version","produces":["application/json"],"parameters":[],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}}},"definitions":{"JsonTable":{"type":"object","properties":{"leasePeriod":{"type":"integer","format":"int64","description":"Lease period"},"notifyUrl":{"type":"string","description":"URL to be notified"}},"description":"model for leased lock"},"PreparedQueryObject":{"type":"object","properties":{"values":{"type":"array","items":{"type":"object"}},"query":{"type":"string"}}}}} \ No newline at end of file
diff --git a/examples/VotingApp/README.md b/example/VotingApp/README.md
index bcd37b9b..bcd37b9b 100644
--- a/examples/VotingApp/README.md
+++ b/example/VotingApp/README.md
diff --git a/examples/VotingApp/pom.xml b/example/VotingApp/pom.xml
index 0c85e60b..87cac6c0 100644
--- a/examples/VotingApp/pom.xml
+++ b/example/VotingApp/pom.xml
@@ -24,7 +24,6 @@ stated inside of the file.
<modelVersion>4.0.0</modelVersion>
<groupId>com.att.reserarch.VoteAppForMUSIC</groupId>
<artifactId>VoteAppForMUSIC</artifactId>
- <packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
@@ -45,15 +44,15 @@ stated inside of the file.
<version>1.9</version>
</dependency>
<dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-json</artifactId>
- <version>1.18.1</version>
- </dependency>
- <dependency>
- <groupId>com.owlike</groupId>
- <artifactId>genson</artifactId>
- <version>0.99</version>
- </dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-json</artifactId>
+ <version>1.18.1</version>
+</dependency>
+<dependency>
+ <groupId>com.owlike</groupId>
+ <artifactId>genson</artifactId>
+ <version>0.99</version>
+</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
@@ -66,11 +65,11 @@ stated inside of the file.
<version>1.9</version>
</dependency>
- <!-- <dependency>
+ <dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.18</version>
- </dependency> -->
+ </dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
@@ -87,36 +86,7 @@ stated inside of the file.
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>
-
- <dependency>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>3.1.1</version>
- </dependency>
+
</dependencies>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <id>default-jar</id>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <transformers>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <mainClass>main.VotingApp</mainClass>
- </transformer>
- </transformers>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
-
+
+</project> \ No newline at end of file
diff --git a/examples/VotingApp/src/main/java/main/JsonDelete.java b/example/VotingApp/src/main/java/main/JsonDelete.java
index 9b75f875..9b75f875 100644
--- a/examples/VotingApp/src/main/java/main/JsonDelete.java
+++ b/example/VotingApp/src/main/java/main/JsonDelete.java
diff --git a/examples/VotingApp/src/main/java/main/JsonInsert.java b/example/VotingApp/src/main/java/main/JsonInsert.java
index a2099c16..a2099c16 100644
--- a/examples/VotingApp/src/main/java/main/JsonInsert.java
+++ b/example/VotingApp/src/main/java/main/JsonInsert.java
diff --git a/examples/VotingApp/src/main/java/main/JsonKeySpace.java b/example/VotingApp/src/main/java/main/JsonKeySpace.java
index ff7b6c67..ff7b6c67 100644
--- a/examples/VotingApp/src/main/java/main/JsonKeySpace.java
+++ b/example/VotingApp/src/main/java/main/JsonKeySpace.java
diff --git a/examples/VotingApp/src/main/java/main/JsonTable.java b/example/VotingApp/src/main/java/main/JsonTable.java
index 66171af2..66171af2 100644
--- a/examples/VotingApp/src/main/java/main/JsonTable.java
+++ b/example/VotingApp/src/main/java/main/JsonTable.java
diff --git a/examples/VotingApp/src/main/java/main/MusicConnector.java b/example/VotingApp/src/main/java/main/MusicConnector.java
index d6ed20ba..d6ed20ba 100644
--- a/examples/VotingApp/src/main/java/main/MusicConnector.java
+++ b/example/VotingApp/src/main/java/main/MusicConnector.java
diff --git a/examples/VotingApp/src/main/java/main/Util.java b/example/VotingApp/src/main/java/main/Util.java
index aefa9a36..aefa9a36 100644
--- a/examples/VotingApp/src/main/java/main/Util.java
+++ b/example/VotingApp/src/main/java/main/Util.java
diff --git a/example/VotingApp/src/main/java/main/VotingAppJar.java b/example/VotingApp/src/main/java/main/VotingAppJar.java
new file mode 100644
index 00000000..f73e9059
--- /dev/null
+++ b/example/VotingApp/src/main/java/main/VotingAppJar.java
@@ -0,0 +1,115 @@
+package main;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicLockingException;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.main.MusicCore;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+
+/**
+ *
+ */
+public class VotingAppJar
+{
+ String keyspaceName;
+ String tableName;
+
+ public VotingAppJar() throws MusicServiceException {
+ keyspaceName = "VotingAppForMusic";
+ tableName = "votevount";
+
+ createVotingKeyspace();
+ System.out.println("Created keyspaces");
+ createVotingTable();
+ System.out.println("Created tables");
+
+ createEntryForCandidate("Popeye");
+ createEntryForCandidate("Judy");
+ createEntryForCandidate("Flash");
+ createEntryForCandidate("Mickey");
+ System.out.println("Created candidates");
+ }
+
+ private void createVotingKeyspace() throws MusicServiceException {
+
+ Map<String,Object> replicationInfo = new HashMap<String, Object>();
+ replicationInfo.put("'class'", "'SimpleStrategy'");
+ replicationInfo.put("'replication_factor'", 1);
+
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE KEYSPACE " + keyspaceName + " WITH REPLICATION = " + replicationInfo.toString().replaceAll("=", ":"));
+
+ try {
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+ } catch (MusicServiceException e) {
+ if (e.getMessage().equals("Keyspace votingappformusic already exists")) {
+ // ignore
+ } else {
+ throw(e);
+ }
+ }
+ }
+
+ private void createVotingTable() throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE TABLE " + keyspaceName + "." + tableName + " (name text PRIMARY KEY, count varint);");
+
+ try {
+ MusicCore.createTable(keyspaceName, tableName, queryObject, "eventual");
+ } catch (MusicServiceException e) {
+ if (e.getMessage().equals("Table votingappformusic.votevount already exists")) {
+ //ignore
+ } else {
+ throw(e);
+ }
+ }
+ }
+
+ private void createEntryForCandidate(String candidateName) throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "INSERT INTO " + keyspaceName + "." + tableName + " (name, count) "
+ + "VALUES ('"+candidateName+"', 0);");
+
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+ }
+
+ public void vote() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ updateVoteCount("Popeye",5);
+ updateVoteCount("Judy",7);
+ updateVoteCount("Mickey",8);
+ updateVoteCount("Flash",2);
+ }
+
+ private void updateVoteCount(String candidateName, int numVotes) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "INSERT INTO " + keyspaceName + "." + tableName + " (name, count) "
+ + "VALUES ('"+candidateName+"', "+numVotes+");");
+ MusicCore.atomicPut(keyspaceName, tableName, candidateName, queryObject, null);
+ }
+
+ private void readAllVotes() throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName);
+ ResultSet rs = MusicCore.get(queryObject);
+ for(Row candidate : rs.all()) {
+ System.out.println(candidate.getString("name") + " - " + candidate.getVarint("count"));
+ }
+ }
+
+ public static void main( String[] args ) throws Exception {
+ VotingAppJar vHandle = new VotingAppJar();
+ vHandle.vote();
+ vHandle.readAllVotes();
+ }
+
+} \ No newline at end of file
diff --git a/examples/VotingApp/src/main/java/main/VotingApp.java b/example/VotingApp/src/main/java/main/VotingAppREST.java
index e58c324d..a7b08368 100644
--- a/examples/VotingApp/src/main/java/main/VotingApp.java
+++ b/example/VotingApp/src/main/java/main/VotingAppREST.java
@@ -39,7 +39,7 @@ import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.json.JSONConfiguration;
-public class VotingApp {
+public class VotingAppREST {
String keyspaceName;
ArrayList<String> lockNames;
MusicConnector musicHandle;
@@ -50,7 +50,7 @@ public class VotingApp {
String userId = "abc123d";
String password = "password";
- public VotingApp(String[] musicIps){
+ public VotingAppREST(String[] musicIps){
lockNames = new ArrayList<String>();
musicHandle = new MusicConnector(musicIps);
bootStrap();
@@ -499,7 +499,7 @@ public class VotingApp {
args = new String[]{"localhost"};
}
for(int i =0; i < 2;++i){
- VotingApp vHandle = new VotingApp(args);
+ VotingAppREST vHandle = new VotingAppREST(args);
vHandle.overAllTests();
System.out.println("=====================================");
diff --git a/example/VotingAppJar/VotingAppJar/pom.xml b/example/VotingAppJar/VotingAppJar/pom.xml
new file mode 100644
index 00000000..69b310d5
--- /dev/null
+++ b/example/VotingAppJar/VotingAppJar/pom.xml
@@ -0,0 +1,30 @@
+<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>VotingAppJar</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>VotingAppJar</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.music</groupId>
+ <artifactId>MUSIC</artifactId>
+ <version>3.0.2</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/example/VotingAppJar/VotingAppJar/src/main/java/org/onap/music/VotingAppJar/VotingAppJar.java b/example/VotingAppJar/VotingAppJar/src/main/java/org/onap/music/VotingAppJar/VotingAppJar.java
new file mode 100644
index 00000000..ad2661ec
--- /dev/null
+++ b/example/VotingAppJar/VotingAppJar/src/main/java/org/onap/music/VotingAppJar/VotingAppJar.java
@@ -0,0 +1,115 @@
+package org.onap.music.VotingAppJar;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicLockingException;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.main.MusicCore;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+
+/**
+ *
+ */
+public class VotingAppJar
+{
+ String keyspaceName;
+ String tableName;
+
+ public VotingAppJar() throws MusicServiceException {
+ keyspaceName = "VotingAppForMusic"+System.currentTimeMillis();
+ tableName = "votecount";
+
+ createVotingKeyspace();
+ System.out.println("Created keyspaces");
+ createVotingTable();
+ System.out.println("Created tables");
+
+ createEntryForCandidate("Popeye");
+ createEntryForCandidate("Judy");
+ createEntryForCandidate("Flash");
+ createEntryForCandidate("Mickey");
+ System.out.println("Created candidates");
+ }
+
+ private void createVotingKeyspace() throws MusicServiceException {
+
+ Map<String,Object> replicationInfo = new HashMap<String, Object>();
+ replicationInfo.put("'class'", "'SimpleStrategy'");
+ replicationInfo.put("'replication_factor'", 1);
+
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE KEYSPACE " + keyspaceName + " WITH REPLICATION = " + replicationInfo.toString().replaceAll("=", ":"));
+
+ try {
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+ } catch (MusicServiceException e) {
+ if (e.getMessage().equals("Keyspace votingappformusic already exists")) {
+ // ignore
+ } else {
+ throw(e);
+ }
+ }
+ }
+
+ private void createVotingTable() throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE TABLE " + keyspaceName + "." + tableName + " (name text PRIMARY KEY, count varint);");
+
+ try {
+ MusicCore.createTable(keyspaceName, tableName, queryObject, "eventual");
+ } catch (MusicServiceException e) {
+ if (e.getMessage().equals("Table votingappformusic.votevount already exists")) {
+ //ignore
+ } else {
+ throw(e);
+ }
+ }
+ }
+
+ private void createEntryForCandidate(String candidateName) throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "INSERT INTO " + keyspaceName + "." + tableName + " (name, count) "
+ + "VALUES ('"+candidateName+"', 0);");
+
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+ }
+
+ public void vote() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ updateVoteCount("Popeye",5);
+ updateVoteCount("Judy",7);
+ updateVoteCount("Mickey",8);
+ updateVoteCount("Flash",2);
+ }
+
+ private void updateVoteCount(String candidateName, int numVotes) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "INSERT INTO " + keyspaceName + "." + tableName + " (name, count) "
+ + "VALUES ('"+candidateName+"', "+numVotes+");");
+ MusicCore.atomicPut(keyspaceName, tableName, candidateName, queryObject, null);
+ }
+
+ private void readAllVotes() throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName);
+ ResultSet rs = MusicCore.get(queryObject);
+ for(Row candidate : rs.all()) {
+ System.out.println(candidate.getString("name") + " - " + candidate.getVarint("count"));
+ }
+ }
+
+ public static void main( String[] args ) throws Exception {
+ VotingAppJar vHandle = new VotingAppJar();
+ vHandle.vote();
+ vHandle.readAllVotes();
+ }
+
+} \ No newline at end of file
diff --git a/example/VotingAppJar/VotingAppJar/src/test/java/org/onap/music/VotingAppJar/AppTest.java b/example/VotingAppJar/VotingAppJar/src/test/java/org/onap/music/VotingAppJar/AppTest.java
new file mode 100644
index 00000000..536655c2
--- /dev/null
+++ b/example/VotingAppJar/VotingAppJar/src/test/java/org/onap/music/VotingAppJar/AppTest.java
@@ -0,0 +1,38 @@
+package org.onap.music.VotingAppJar;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/examples/VotingApp/dependency-reduced-pom.xml b/examples/VotingApp/dependency-reduced-pom.xml
deleted file mode 100644
index faf90967..00000000
--- a/examples/VotingApp/dependency-reduced-pom.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.att.reserarch.VoteAppForMUSIC</groupId>
- <artifactId>VoteAppForMUSIC</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <id>default-jar</id>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <transformers>
- <transformer />
- <transformer>
- <mainClass>main.VotingApp</mainClass>
- </transformer>
- </transformers>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- <repositories>
- <repository>
- <id>maven2-repository.java.net</id>
- <name>Java.net Repository for Maven</name>
- <url>http://download.java.net/maven/2/</url>
- </repository>
- </repositories>
-</project>
diff --git a/jar/DO_NOT_EDIT_ANYTHING_IN_THIS_FOLDER.md b/jar/DO_NOT_EDIT_ANYTHING_IN_THIS_FOLDER.md
deleted file mode 100644
index d0baf49b..00000000
--- a/jar/DO_NOT_EDIT_ANYTHING_IN_THIS_FOLDER.md
+++ /dev/null
@@ -1 +0,0 @@
-This folder (/jar) is not guaranteed to be around for Casablanca.
diff --git a/jar/pom.xml b/jar/pom.xml
index 9fc8ff30..0c983b2d 100644
--- a/jar/pom.xml
+++ b/jar/pom.xml
@@ -25,7 +25,7 @@
<groupId>org.onap.music</groupId>
<artifactId>MUSIC</artifactId>
<packaging>jar</packaging>
- <version>2.5.7</version>
+ <version>2.5.3</version>
<description>
This is the MUSIC REST interface, packaged as a war file.
</description>
@@ -81,14 +81,12 @@
<build>
<finalName>MUSIC</finalName>
- <sourceDirectory>src/main/java</sourceDirectory>
+ <sourceDirectory>../src/main/java</sourceDirectory>
<outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
- <testSourceDirectory>src/test/java</testSourceDirectory>
- <testOutputDirectory>target/test-classes</testOutputDirectory>
<defaultGoal>validate</defaultGoal>
<resources>
<resource>
- <directory>src/main/resources</directory>
+ <directory>../src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
@@ -114,9 +112,6 @@
<configuration>
<source>1.7</source>
<target>1.7</target>
- <excludes>
- <exclude>jar/**</exclude>
- </excludes>
</configuration>
</plugin>
<plugin>
@@ -333,24 +328,6 @@
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
- <dependency>
- <groupId>org.mindrot</groupId>
- <artifactId>jbcrypt</artifactId>
- <version>0.4</version>
- </dependency>
- <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.9</version>
- </dependency>
- <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.0</version>
- </dependency>
-
</dependencies>
<reporting>
diff --git a/jar/src/main/java/LICENSE.txt b/jar/src/main/java/LICENSE.txt
deleted file mode 100644
index cc6cdea5..00000000
--- a/jar/src/main/java/LICENSE.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-
-The following license applies to all files in this and sub-directories. Licenses
-are included in individual source files where appropriate, and if it differs
-from this text, it supersedes this. Any file that does not have license text
-defaults to being covered by this text; not all files support the addition of
-licenses.
-#
-# -------------------------------------------------------------------------
-# 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.
-#
-# -------------------------------------------------------------------------
-# \ No newline at end of file
diff --git a/jar/src/main/java/org/onap/music/datastore/MusicDataStore.java b/jar/src/main/java/org/onap/music/datastore/MusicDataStore.java
deleted file mode 100644
index 71006f73..00000000
--- a/jar/src/main/java/org/onap/music/datastore/MusicDataStore.java
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * ============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.datastore;
-
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.MusicUtil;
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.ColumnDefinitions.Definition;
-import com.datastax.driver.core.ConsistencyLevel;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.KeyspaceMetadata;
-import com.datastax.driver.core.Metadata;
-import com.datastax.driver.core.PreparedStatement;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.core.TableMetadata;
-import com.datastax.driver.core.exceptions.AlreadyExistsException;
-import com.datastax.driver.core.exceptions.InvalidQueryException;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
-import com.datastax.driver.core.policies.RoundRobinPolicy;
-import com.datastax.driver.core.HostDistance;
-import com.datastax.driver.core.PoolingOptions;
-
-
-/**
- * @author nelson24
- *
- */
-public class MusicDataStore {
-
- private Session session;
- private Cluster cluster;
-
-
-
- /**
- * @param session
- */
- public void setSession(Session session) {
- this.session = session;
- }
-
- /**
- * @param session
- */
- public Session getSession() {
- return session;
- }
-
- /**
- * @param cluster
- */
- public void setCluster(Cluster cluster) {
- this.cluster = cluster;
- }
-
-
-
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStore.class);
-
- /**
- *
- */
- public MusicDataStore() {
- connectToCassaCluster();
- }
-
-
- /**
- * @param cluster
- * @param session
- */
- public MusicDataStore(Cluster cluster, Session session) {
- this.session = session;
- this.cluster = cluster;
- }
-
- /**
- *
- * @param remoteIp
- * @throws MusicServiceException
- */
- public MusicDataStore(String remoteIp) {
- try {
- connectToCassaCluster(remoteIp);
- } catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
- }
-
- /**
- *
- * @return
- */
- private ArrayList<String> getAllPossibleLocalIps() {
- ArrayList<String> allPossibleIps = new ArrayList<String>();
- try {
- Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
- while (en.hasMoreElements()) {
- NetworkInterface ni = (NetworkInterface) en.nextElement();
- Enumeration<InetAddress> ee = ni.getInetAddresses();
- while (ee.hasMoreElements()) {
- InetAddress ia = (InetAddress) ee.nextElement();
- allPossibleIps.add(ia.getHostAddress());
- }
- }
- } catch (SocketException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.CONNCECTIVITYERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- }catch(Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), ErrorSeverity.ERROR, ErrorTypes.GENERALSERVICEERROR);
- }
- return allPossibleIps;
- }
-
- /**
- * This method iterates through all available IP addresses and connects to multiple cassandra
- * clusters.
- */
- private void connectToCassaCluster() {
- Iterator<String> it = getAllPossibleLocalIps().iterator();
- String address = "localhost";
- String[] addresses = null;
- address = MusicUtil.getMyCassaHost();
- addresses = address.split(",");
-
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Connecting to cassa cluster: Iterating through possible ips:"
- + getAllPossibleLocalIps());
- PoolingOptions poolingOptions = new PoolingOptions();
- poolingOptions
- .setConnectionsPerHost(HostDistance.LOCAL, 4, 10)
- .setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
- while (it.hasNext()) {
- try {
- if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) {
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd());
- cluster = Cluster.builder().withPort(9042)
- .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd())
- //.withLoadBalancingPolicy(new RoundRobinPolicy())
- .withPoolingOptions(poolingOptions)
- .addContactPoints(addresses).build();
- }
- else
- cluster = Cluster.builder().withPort(9042)
- //.withLoadBalancingPolicy(new RoundRobinPolicy())
- .addContactPoints(addresses).build();
-
- Metadata metadata = cluster.getMetadata();
- logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster "
- + metadata.getClusterName() + " at " + address);
- session = cluster.connect();
-
- break;
- } catch (NoHostAvailableException e) {
- address = it.next();
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.HOSTUNAVAILABLE, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- }
- }
- }
-
- /**
- *
- */
- public void close() {
- session.close();
- }
-
- /**
- * This method connects to cassandra cluster on specific address.
- *
- * @param address
- */
- private void connectToCassaCluster(String address) throws MusicServiceException {
- String[] addresses = null;
- addresses = address.split(",");
- PoolingOptions poolingOptions = new PoolingOptions();
- poolingOptions
- .setConnectionsPerHost(HostDistance.LOCAL, 4, 10)
- .setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
- if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) {
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd());
- cluster = Cluster.builder().withPort(9042)
- .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd())
- //.withLoadBalancingPolicy(new RoundRobinPolicy())
- .withPoolingOptions(poolingOptions)
- .addContactPoints(addresses).build();
- }
- else {
- cluster = Cluster.builder().withPort(9042)
- //.withLoadBalancingPolicy(new RoundRobinPolicy())
- .withPoolingOptions(poolingOptions)
- .addContactPoints(addresses).build();
- }
- Metadata metadata = cluster.getMetadata();
- logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster "
- + metadata.getClusterName() + " at " + address);
- try {
- session = cluster.connect();
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.CASSANDRACONNECTIVITY, ErrorSeverity.ERROR, ErrorTypes.SERVICEUNAVAILABLE);
- throw new MusicServiceException(
- "Error while connecting to Cassandra cluster.. " + ex.getMessage());
- }
- }
-
- /**
- *
- * @param keyspace
- * @param tableName
- * @param columnName
- * @return DataType
- */
- public DataType returnColumnDataType(String keyspace, String tableName, String columnName) {
- KeyspaceMetadata ks = cluster.getMetadata().getKeyspace(keyspace);
- TableMetadata table = ks.getTable(tableName);
- return table.getColumn(columnName).getType();
-
- }
-
- /**
- *
- * @param keyspace
- * @param tableName
- * @return TableMetadata
- */
- public TableMetadata returnColumnMetadata(String keyspace, String tableName) {
- KeyspaceMetadata ks = cluster.getMetadata().getKeyspace(keyspace);
- return ks.getTable(tableName);
- }
-
-
- /**
- * Utility function to return the Java specific object type.
- *
- * @param row
- * @param colName
- * @param colType
- * @return
- */
- public Object getColValue(Row row, String colName, DataType colType) {
-
- switch (colType.getName()) {
- case VARCHAR:
- return row.getString(colName);
- case UUID:
- return row.getUUID(colName);
- case VARINT:
- return row.getVarint(colName);
- case BIGINT:
- return row.getLong(colName);
- case INT:
- return row.getInt(colName);
- case FLOAT:
- return row.getFloat(colName);
- case DOUBLE:
- return row.getDouble(colName);
- case BOOLEAN:
- return row.getBool(colName);
- case MAP:
- return row.getMap(colName, String.class, String.class);
- default:
- return null;
- }
- }
-
- public boolean doesRowSatisfyCondition(Row row, Map<String, Object> condition) throws Exception {
- ColumnDefinitions colInfo = row.getColumnDefinitions();
-
- for (Map.Entry<String, Object> entry : condition.entrySet()) {
- String colName = entry.getKey();
- DataType colType = colInfo.getType(colName);
- Object columnValue = getColValue(row, colName, colType);
- Object conditionValue = MusicUtil.convertToActualDataType(colType, entry.getValue());
- if (columnValue.equals(conditionValue) == false)
- return false;
- }
- return true;
- }
-
- /**
- * Utility function to store ResultSet values in to a MAP for output.
- *
- * @param results
- * @return MAP
- */
- public Map<String, HashMap<String, Object>> marshalData(ResultSet results) {
- Map<String, HashMap<String, Object>> resultMap =
- new HashMap<String, HashMap<String, Object>>();
- int counter = 0;
- for (Row row : results) {
- ColumnDefinitions colInfo = row.getColumnDefinitions();
- HashMap<String, Object> resultOutput = new HashMap<String, Object>();
- for (Definition definition : colInfo) {
- if (!definition.getName().equals("vector_ts"))
- resultOutput.put(definition.getName(),
- getColValue(row, definition.getName(), definition.getType()));
- }
- resultMap.put("row " + counter, resultOutput);
- counter++;
- }
- return resultMap;
- }
-
-
- // Prepared Statements 1802 additions
- /**
- * This Method performs DDL and DML operations on Cassandra using specified consistency level
- *
- * @param queryObject Object containing cassandra prepared query and values.
- * @param consistency Specify consistency level for data synchronization across cassandra
- * replicas
- * @return Boolean Indicates operation success or failure
- * @throws MusicServiceException
- * @throws MusicQueryException
- */
- public boolean executePut(PreparedQueryObject queryObject, String consistency)
- throws MusicServiceException, MusicQueryException {
-
- boolean result = false;
-
- if (!MusicUtil.isValidQueryObject(!queryObject.getValues().isEmpty(), queryObject)) {
- logger.error(EELFLoggerDelegate.errorLogger, queryObject.getQuery(),AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- throw new MusicQueryException("Ill formed queryObject for the request = " + "["
- + queryObject.getQuery() + "]");
- }
- logger.info(EELFLoggerDelegate.applicationLogger,
- "In preprared Execute Put: the actual insert query:"
- + queryObject.getQuery() + "; the values"
- + queryObject.getValues());
- PreparedStatement preparedInsert = null;
- try {
-
- preparedInsert = session.prepare(queryObject.getQuery());
-
- } catch(InvalidQueryException iqe) {
- logger.error(EELFLoggerDelegate.errorLogger, iqe.getMessage(),AppMessages.QUERYERROR, ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR);
- throw new MusicQueryException(iqe.getMessage());
- }catch(Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.QUERYERROR, ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR);
- throw new MusicQueryException(e.getMessage());
- }
-
- try {
- if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "Executing critical put query");
- preparedInsert.setConsistencyLevel(ConsistencyLevel.QUORUM);
- } else if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "Executing simple put query");
- preparedInsert.setConsistencyLevel(ConsistencyLevel.ONE);
- }
-
- ResultSet rs = session.execute(preparedInsert.bind(queryObject.getValues().toArray()));
- result = rs.wasApplied();
-
- }
- catch (AlreadyExistsException ae) {
- logger.error(EELFLoggerDelegate.errorLogger, ae.getMessage(),AppMessages.SESSIONFAILED+ " [" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- throw new MusicServiceException(ae.getMessage());
- }
- catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.SESSIONFAILED+ " [" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- throw new MusicQueryException("Executing Session Failure for Request = " + "["
- + queryObject.getQuery() + "]" + " Reason = " + e.getMessage());
- }
-
-
- return result;
- }
-
- /**
- * This method performs DDL operations on Cassandra using consistency level ONE.
- *
- * @param queryObject Object containing cassandra prepared query and values.
- * @return ResultSet
- * @throws MusicServiceException
- * @throws MusicQueryException
- */
- public ResultSet executeEventualGet(PreparedQueryObject queryObject)
- throws MusicServiceException, MusicQueryException {
-
- if (!MusicUtil.isValidQueryObject(!queryObject.getValues().isEmpty(), queryObject)) {
- logger.error(EELFLoggerDelegate.errorLogger, "",AppMessages.QUERYERROR+ " [" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- throw new MusicQueryException("Ill formed queryObject for the request = " + "["
- + queryObject.getQuery() + "]");
- }
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Executing Eventual get query:" + queryObject.getQuery());
-
- ResultSet results = null;
- try {
- 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);
- throw new MusicServiceException(ex.getMessage());
- }
- return results;
- }
-
- /**
- *
- * This method performs DDL operation on Cassandra using consistency level QUORUM.
- *
- * @param queryObject Object containing cassandra prepared query and values.
- * @return ResultSet
- * @throws MusicServiceException
- * @throws MusicQueryException
- */
- public ResultSet executeCriticalGet(PreparedQueryObject queryObject)
- throws MusicServiceException, MusicQueryException {
- if (!MusicUtil.isValidQueryObject(!queryObject.getValues().isEmpty(), queryObject)) {
- logger.error(EELFLoggerDelegate.errorLogger, "",AppMessages.QUERYERROR+ " [" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- throw new MusicQueryException("Error processing Prepared Query Object for the request = " + "["
- + queryObject.getQuery() + "]");
- }
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Executing Critical get query:" + queryObject.getQuery());
- PreparedStatement preparedEventualGet = session.prepare(queryObject.getQuery());
- preparedEventualGet.setConsistencyLevel(ConsistencyLevel.QUORUM);
- ResultSet results = null;
- try {
- 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);
- throw new MusicServiceException(ex.getMessage());
- }
- return results;
-
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/PreparedQueryObject.java b/jar/src/main/java/org/onap/music/datastore/PreparedQueryObject.java
deleted file mode 100644
index 694d9acd..00000000
--- a/jar/src/main/java/org/onap/music/datastore/PreparedQueryObject.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ============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.datastore;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- *
- * @author srupane
- *
- */
-public class PreparedQueryObject {
-
-
- private List<Object> values;
- private StringBuilder query;
-
-
-
- /**
- *
- */
- public PreparedQueryObject() {
-
- this.values = new ArrayList<>();
- this.query = new StringBuilder();
- }
-
- /**
- * @return
- */
- public List<Object> getValues() {
- return values;
- }
-
- /**
- * @param o
- */
- public void addValue(Object o) {
- this.values.add(o);
- }
-
- /**
- * @param s
- */
- public void appendQueryString(String s) {
- this.query.append(s);
- }
-
- /**
- * @return
- */
- public String getQuery() {
- return this.query.toString();
- }
-
-
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/AAFResponse.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/AAFResponse.java
deleted file mode 100644
index df6089ee..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/AAFResponse.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.util.ArrayList;
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonTable", description = "Reponse class for AAF request")
-public class AAFResponse {
-
- private ArrayList<NameSpace> ns = null;
-
- @ApiModelProperty(value = "Namespace value")
- public ArrayList<NameSpace> getNs() {
- return ns;
- }
-
- public void setNs(ArrayList<NameSpace> ns) {
- this.ns = ns;
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JSONObject.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/JSONObject.java
deleted file mode 100644
index 8de0a2cd..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JSONObject.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.onap.music.datastore.jsonobjects;
-/*
- * ============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=============================================
- * ====================================================================
- */
-
-
-public class JSONObject {
-
- private String data;
-
- public String getData() {
- return data;
- }
-
- public void setData(String data) {
- this.data = data;
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java
deleted file mode 100644
index a5db4be5..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.util.ArrayList;
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonTable", description = "Json model for delete")
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonDelete {
-
- private ArrayList<String> columns = null;
- private Map<String, String> consistencyInfo;
- private Map<String, Object> conditions;
- String ttl, timestamp;
-
-
- @ApiModelProperty(value = "Conditions")
- public Map<String, Object> getConditions() {
- return conditions;
- }
-
- public void setConditions(Map<String, Object> conditions) {
- this.conditions = conditions;
- }
-
- @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic")
- public Map<String, String> getConsistencyInfo() {
- return consistencyInfo;
- }
-
- public void setConsistencyInfo(Map<String, String> consistencyInfo) {
- this.consistencyInfo = consistencyInfo;
- }
-
- @ApiModelProperty(value = "Column values")
- public ArrayList<String> getColumns() {
- return columns;
- }
-
- public void setColumns(ArrayList<String> columns) {
- this.columns = columns;
- }
-
-
- @ApiModelProperty(value = "Time to live information")
- public String getTtl() {
- return ttl;
- }
-
- public void setTtl(String ttl) {
- this.ttl = ttl;
- }
-
- @ApiModelProperty(value = "Time stamp")
- public String getTimestamp() {
- return timestamp;
- }
-
- public void setTimestamp(String timestamp) {
- this.timestamp = timestamp;
- }
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java
deleted file mode 100644
index a58552c6..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonTable", description = "Json model for table vlaues insert")
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonInsert implements Serializable {
- private String keyspaceName;
- private String tableName;
- private Map<String, Object> values;
- private String ttl;
- private String timestamp;
- private Map<String, Object> row_specification;
- private Map<String, String> consistencyInfo;
-
- @ApiModelProperty(value = "keyspace")
- public String getKeyspaceName() {
- return keyspaceName;
- }
-
- public void setKeyspaceName(String keyspaceName) {
- this.keyspaceName = keyspaceName;
- }
-
- @ApiModelProperty(value = "Table name")
- public String getTableName() {
- return tableName;
- }
-
- public void setTableName(String tableName) {
- this.tableName = tableName;
- }
-
- @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic")
- public Map<String, String> getConsistencyInfo() {
- return consistencyInfo;
- }
-
- public void setConsistencyInfo(Map<String, String> consistencyInfo) {
- this.consistencyInfo = consistencyInfo;
- }
-
- @ApiModelProperty(value = "Time to live information")
- public String getTtl() {
- return ttl;
- }
-
- public void setTtl(String ttl) {
- this.ttl = ttl;
- }
-
- @ApiModelProperty(value = "Time stamp")
- public String getTimestamp() {
- return timestamp;
- }
-
- public void setTimestamp(String timestamp) {
- this.timestamp = timestamp;
- }
-
- @ApiModelProperty(value = "values returned")
- public Map<String, Object> getValues() {
- return values;
- }
-
- public void setValues(Map<String, Object> values) {
- this.values = values;
- }
-
- @ApiModelProperty(value = "Information for selecting specific rows for insert")
- public Map<String, Object> getRow_specification() {
- return row_specification;
- }
-
- public void setRow_specification(Map<String, Object> row_specification) {
- this.row_specification = row_specification;
- }
-
- public byte[] serialize() {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutput out = null;
- try {
- out = new ObjectOutputStream(bos);
- out.writeObject(this);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return bos.toByteArray();
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java
deleted file mode 100644
index 54de02fd..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonTable", description = "Json model creating new keyspace")
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonKeySpace {
- private String keyspaceName;
- private Map<String, Object> replicationInfo;
- private String durabilityOfWrites;
- private Map<String, String> consistencyInfo;
-
- @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic")
- public Map<String, String> getConsistencyInfo() {
- return consistencyInfo;
- }
-
- public void setConsistencyInfo(Map<String, String> consistencyInfo) {
- this.consistencyInfo = consistencyInfo;
- }
-
- @ApiModelProperty(value = "Replication information")
- public Map<String, Object> getReplicationInfo() {
- return replicationInfo;
- }
-
- public void setReplicationInfo(Map<String, Object> replicationInfo) {
- this.replicationInfo = replicationInfo;
- }
-
- @ApiModelProperty(value = "Durability", allowableValues = "true,false")
- public String getDurabilityOfWrites() {
- return durabilityOfWrites;
- }
-
- public void setDurabilityOfWrites(String durabilityOfWrites) {
- this.durabilityOfWrites = durabilityOfWrites;
- }
-
- @ApiModelProperty(value = "Keyspace name")
- public String getKeyspaceName() {
- return keyspaceName;
- }
-
- public void setKeyspaceName(String keyspaceName) {
- this.keyspaceName = keyspaceName;
- }
-
-
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java
deleted file mode 100644
index 497e17d1..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonTable", description = "model for leased lock")
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonLeasedLock {
- long leasePeriod;
- String notifyUrl;
-
- @ApiModelProperty(value = "Lease period")
- public long getLeasePeriod() {
- return leasePeriod;
- }
-
- public void setLeasePeriod(long leasePeriod) {
- this.leasePeriod = leasePeriod;
- }
-
- @ApiModelProperty(value = "URL to be notified")
- public String getNotifyUrl() {
- return notifyUrl;
- }
-
- public void setNotifyUrl(String notifyUrl) {
- this.notifyUrl = notifyUrl;
- }
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java
deleted file mode 100755
index 0bac1e31..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonOnboard", description = "Defines the Json for Onboarding an application.")
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonOnboard {
- private String appname;
- private String userId;
- private String password;
- private String isAAF;
- private String aid;
-
- @ApiModelProperty(value = "Application Password")
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- @ApiModelProperty(value = "Application UUID")
- public String getAid() {
- return aid;
- }
-
- public void setAid(String aid) {
- this.aid = aid;
- }
-
- @ApiModelProperty(value = "Application name")
- public String getAppname() {
- return appname;
- }
-
- public void setAppname(String appname) {
- this.appname = appname;
- }
-
- @ApiModelProperty(value = "User Id")
- public String getUserId() {
- return userId;
- }
-
- public void setUserId(String userId) {
- this.userId = userId;
- }
-
- @ApiModelProperty(value = "Is AAF Application", allowableValues = "true, false")
- public String getIsAAF() {
- return isAAF;
- }
-
- public void setIsAAF(String isAAF) {
- this.isAAF = isAAF;
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java
deleted file mode 100644
index 64bc3887..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonSelect implements Serializable {
- private Map<String, String> consistencyInfo;
-
-
- public Map<String, String> getConsistencyInfo() {
- return consistencyInfo;
- }
-
- public void setConsistencyInfo(Map<String, String> consistencyInfo) {
- this.consistencyInfo = consistencyInfo;
- }
-
- public byte[] serialize() {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutput out = null;
- try {
- out = new ObjectOutputStream(bos);
- out.writeObject(this);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return bos.toByteArray();
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java
deleted file mode 100644
index 5d508adb..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonTable", description = "Defines the Json for Creating a new Table.")
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonTable {
- private String keyspaceName;
- private String tableName;
-
- private Map<String, String> fields;
- private Map<String, Object> properties;
- private String primaryKey;
- private String sortingKey;
- private String clusteringOrder;
- private Map<String, String> consistencyInfo;
-
- @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic")
- public Map<String, String> getConsistencyInfo() {
- return consistencyInfo;
- }
-
- public void setConsistencyInfo(Map<String, String> consistencyInfo) {
- this.consistencyInfo = consistencyInfo;
- }
-
- @ApiModelProperty(value = "Properties")
- public Map<String, Object> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, Object> properties) {
- this.properties = properties;
- }
-
- @ApiModelProperty(value = "Fields")
- public Map<String, String> getFields() {
- return fields;
- }
-
- public void setFields(Map<String, String> fields) {
- this.fields = fields;
- }
-
- @ApiModelProperty(value = "KeySpace Name")
- public String getKeyspaceName() {
- return keyspaceName;
- }
-
- public void setKeyspaceName(String keyspaceName) {
- this.keyspaceName = keyspaceName;
- }
-
- @ApiModelProperty(value = "Table Name")
- public String getTableName() {
- return tableName;
- }
-
- public void setTableName(String tableName) {
- this.tableName = tableName;
- }
-
- @ApiModelProperty(value = "Sorting Key")
- public String getSortingKey() {
- return sortingKey;
- }
-
- public void setSortingKey(String sortingKey) {
- this.sortingKey = sortingKey;
- }
-
- @ApiModelProperty(value = "Clustering Order", notes = "")
- public String getClusteringOrder() {
- return clusteringOrder;
- }
-
- public void setClusteringOrder(String clusteringOrder) {
- this.clusteringOrder = clusteringOrder;
- }
-
- @ApiModelProperty(value = "Primary Key")
- public String getPrimaryKey() {
- return primaryKey;
- }
-
- public void setPrimaryKey(String primaryKey) {
- this.primaryKey = primaryKey;
- }
-
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java
deleted file mode 100644
index 3ab5ea0d..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonTable", description = "Json model for table update")
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonUpdate implements Serializable {
- private String keyspaceName;
- private String tableName;
- private Map<String, Object> values;
- private String ttl, timestamp;
- private Map<String, String> consistencyInfo;
- private Map<String, Object> conditions;
- private Map<String, Object> row_specification;
-
- @ApiModelProperty(value = "Conditions")
- public Map<String, Object> getConditions() {
- return conditions;
- }
-
- public void setConditions(Map<String, Object> conditions) {
- this.conditions = conditions;
- }
-
- @ApiModelProperty(value = "Information for selecting sepcific rows")
- public Map<String, Object> getRow_specification() {
- return row_specification;
- }
-
- public void setRow_specification(Map<String, Object> row_specification) {
- this.row_specification = row_specification;
- }
-
-
- @ApiModelProperty(value = "Keyspace name")
- public String getKeyspaceName() {
- return keyspaceName;
- }
-
- public void setKeyspaceName(String keyspaceName) {
- this.keyspaceName = keyspaceName;
- }
-
- @ApiModelProperty(value = "Table name")
- public String getTableName() {
- return tableName;
- }
-
- public void setTableName(String tableName) {
- this.tableName = tableName;
- }
-
- @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic")
- public Map<String, String> getConsistencyInfo() {
- return consistencyInfo;
- }
-
- public void setConsistencyInfo(Map<String, String> consistencyInfo) {
- this.consistencyInfo = consistencyInfo;
- }
-
- @ApiModelProperty(value = "Time to live value")
- public String getTtl() {
- return ttl;
- }
-
- public void setTtl(String ttl) {
- this.ttl = ttl;
- }
-
- @ApiModelProperty(value = "Time stamp")
- public String getTimestamp() {
- return timestamp;
- }
-
- public void setTimestamp(String timestamp) {
- this.timestamp = timestamp;
- }
-
- @ApiModelProperty(value = "Column values")
- public Map<String, Object> getValues() {
- return values;
- }
-
- public void setValues(Map<String, Object> values) {
- this.values = values;
- }
-
- public byte[] serialize() {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutput out = null;
- try {
- out = new ObjectOutputStream(bos);
- out.writeObject(this);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return bos.toByteArray();
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/datastore/jsonobjects/NameSpace.java b/jar/src/main/java/org/onap/music/datastore/jsonobjects/NameSpace.java
deleted file mode 100644
index 232353c1..00000000
--- a/jar/src/main/java/org/onap/music/datastore/jsonobjects/NameSpace.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.util.List;
-
-
-public class NameSpace {
- private String name;
- private List<String> admin;
-
- public List<String> getAdmin() {
- return admin;
- }
-
- public String getName() {
- return name;
- }
-
- public void setAdmin(List<String> admin) {
- this.admin = admin;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java b/jar/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java
deleted file mode 100644
index 1f4abea1..00000000
--- a/jar/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * ============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.eelf.healthcheck;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.util.Iterator;
-
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.mindrot.jbcrypt.BCrypt;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.exceptions.MusicLockingException;
-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;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-
-
-
-
-/**
- * @author inam
- *
- */
-public class MusicHealthCheck {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
-
- private String cassandrHost;
- private String zookeeperHost;
-
-
-
-
-
-
-
-
- public String getCassandraStatus() {
- logger.info(EELFLoggerDelegate.applicationLogger,"Getting Status for Cassandra");
- if(this.getAdminKeySpace()) {
- return "ACTIVE";
- }else {
- logger.info(EELFLoggerDelegate.applicationLogger,"Cassandra Service is not responding");
- return "INACTIVE";
- }
- }
-
-
- private Boolean getAdminKeySpace() {
-
- String appName = "";
-
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "select * from admin.keyspace_master");
- //pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- try {
- ResultSet rs = MusicCore.get(pQuery);
-
- if(rs != null) {
- return Boolean.TRUE;
- }else {
- return Boolean.FALSE;
- }
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(),AppMessages.CASSANDRACONNECTIVITY, ErrorTypes.CONNECTIONERROR, ErrorSeverity.CRITICAL);
- }
-
- return Boolean.FALSE;
-
-
- }
-
- public String getZookeeperStatus() {
-
-
- String host = MusicUtil.getMyZkHost();
- logger.info(EELFLoggerDelegate.applicationLogger,"Getting Status for Zookeeper Host: "+host);
- try {
- MusicLockingService lockingService = MusicCore.getLockingServiceHandle();
- //additionally need to call the ZK to create,aquire and delete lock
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(),AppMessages.LOCKINGERROR, ErrorTypes.CONNECTIONERROR, ErrorSeverity.CRITICAL);
- return "INACTIVE";
- }
-
- logger.info(EELFLoggerDelegate.applicationLogger,"Zookeeper is Active and Running");
- return "ACTIVE";
-
- //return "Zookeeper is not responding";
-
- }
-
-
-
-
- public String getCassandrHost() {
- return cassandrHost;
- }
-
-
-
-
- public void setCassandrHost(String cassandrHost) {
- this.cassandrHost = cassandrHost;
- }
-
-
-
-
- public String getZookeeperHost() {
- return zookeeperHost;
- }
-
-
-
-
- public void setZookeeperHost(String zookeeperHost) {
- this.zookeeperHost = zookeeperHost;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-}
diff --git a/jar/src/main/java/org/onap/music/eelf/logging/EELFLoggerDelegate.java b/jar/src/main/java/org/onap/music/eelf/logging/EELFLoggerDelegate.java
deleted file mode 100644
index 0c290b6f..00000000
--- a/jar/src/main/java/org/onap/music/eelf/logging/EELFLoggerDelegate.java
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * ============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.eelf.logging;
-
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
-import java.net.InetAddress;
-import java.text.MessageFormat;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import javax.servlet.http.HttpServletRequest;
-import org.slf4j.MDC;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.att.eelf.configuration.SLF4jWrapper;
-
-public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
-
- public static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();
- public static final EELFLogger applicationLogger =
- EELFManager.getInstance().getApplicationLogger();
- public static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
- public static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- public static final EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger();
-
- private String className;
- private static ConcurrentMap<String, EELFLoggerDelegate> classMap = new ConcurrentHashMap<>();
-
- public EELFLoggerDelegate(final String className) {
- super(className);
- this.className = className;
- }
-
- /**
- * Convenience method that gets a logger for the specified class.
- *
- * @see #getLogger(String)
- *
- * @param clazz
- * @return Instance of EELFLoggerDelegate
- */
- public static EELFLoggerDelegate getLogger(Class<?> clazz) {
- return getLogger(clazz.getName());
- }
-
- /**
- * Gets a logger for the specified class name. If the logger does not already exist in the map,
- * this creates a new logger.
- *
- * @param className If null or empty, uses EELFLoggerDelegate as the class name.
- * @return Instance of EELFLoggerDelegate
- */
- public static EELFLoggerDelegate getLogger(final String className) {
- String classNameNeverNull = className == null || "".equals(className)
- ? EELFLoggerDelegate.class.getName()
- : className;
- EELFLoggerDelegate delegate = classMap.get(classNameNeverNull);
- if (delegate == null) {
- delegate = new EELFLoggerDelegate(className);
- classMap.put(className, delegate);
- }
- return delegate;
- }
-
- /**
- * Logs a message at the lowest level: trace.
- *
- * @param logger
- * @param msg
- */
- public void trace(EELFLogger logger, String msg) {
- if (logger.isTraceEnabled()) {
- logger.trace(msg);
- }
- }
-
- /**
- * Logs a message with parameters at the lowest level: trace.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void trace(EELFLogger logger, String msg, Object... arguments) {
- if (logger.isTraceEnabled()) {
- logger.trace(msg, arguments);
- }
- }
-
- /**
- * Logs a message and throwable at the lowest level: trace.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void trace(EELFLogger logger, String msg, Throwable th) {
- if (logger.isTraceEnabled()) {
- logger.trace(msg, th);
- }
- }
-
- /**
- * Logs a message at the second-lowest level: debug.
- *
- * @param logger
- * @param msg
- */
- public void debug(EELFLogger logger, String msg) {
- if (logger.isDebugEnabled()) {
- logger.debug(msg);
- }
- }
-
- /**
- * Logs a message with parameters at the second-lowest level: debug.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void debug(EELFLogger logger, String msg, Object... arguments) {
- if (logger.isDebugEnabled()) {
- logger.debug(msg, arguments);
- }
- }
-
- /**
- * Logs a message and throwable at the second-lowest level: debug.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void debug(EELFLogger logger, String msg, Throwable th) {
- if (logger.isDebugEnabled()) {
- logger.debug(msg, th);
- }
- }
-
- /**
- * Logs a message at info level.
- *
- * @param logger
- * @param msg
- */
- public void info(EELFLogger logger, String msg) {
- logger.info(className + " - "+msg);
- }
-
- /**
- * Logs a message with parameters at info level.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void info(EELFLogger logger, String msg, Object... arguments) {
- logger.info(msg, arguments);
- }
-
- /**
- * Logs a message and throwable at info level.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void info(EELFLogger logger, String msg, Throwable th) {
- logger.info(msg, th);
- }
-
- /**
- * Logs a message at warn level.
- *
- * @param logger
- * @param msg
- */
- public void warn(EELFLogger logger, String msg) {
- logger.warn(msg);
- }
-
- /**
- * Logs a message with parameters at warn level.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void warn(EELFLogger logger, String msg, Object... arguments) {
- logger.warn(msg, arguments);
- }
-
- /**
- * Logs a message and throwable at warn level.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void warn(EELFLogger logger, String msg, Throwable th) {
- logger.warn(msg, th);
- }
-
- /**
- * Logs a message at error level.
- *
- * @param logger
- * @param msg
- */
- public void error(EELFLogger logger, String msg) {
- logger.error(className+ " - " + msg);
- }
-
- /**
- * Logs a message with parameters at error level.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void error(EELFLogger logger, String msg, Object... arguments) {
- logger.warn(msg, arguments);
- }
-
- /**
- * Logs a message and throwable at error level.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void error(EELFLogger logger, String msg, Throwable th) {
- logger.warn(msg, th);
- }
-
- /**
- * Logs a message with the associated alarm severity at error level.
- *
- * @param logger
- * @param msg
- * @param severtiy
- */
- public void error(EELFLogger logger, String msg, Object /* AlarmSeverityEnum */ severtiy) {
- logger.error(msg);
- }
-
- /**
- * Initializes the logger context.
- */
- public void init() {
- setGlobalLoggingContext();
- final String msg =
- "############################ Logging is started. ############################";
- // These loggers emit the current date-time without being told.
- info(applicationLogger, msg);
- error(errorLogger, msg);
- debug(debugLogger, msg);
- info(auditLogger, msg);
- info(metricsLogger, msg);
- }
-
- /**
- * Builds a message using a template string and the arguments.
- *
- * @param message
- * @param args
- * @return
- */
- private String formatMessage(String message, Object... args) {
- StringBuilder sbFormattedMessage = new StringBuilder();
- if (args != null && args.length > 0 && message != null && message != "") {
- MessageFormat mf = new MessageFormat(message);
- sbFormattedMessage.append(mf.format(args));
- } else {
- sbFormattedMessage.append(message);
- }
-
- return sbFormattedMessage.toString();
- }
-
- /**
- * Loads all the default logging fields into the MDC context.
- */
- private void setGlobalLoggingContext() {
- MDC.put(MDC_SERVICE_INSTANCE_ID, "");
- try {
- MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
- MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
- } catch (Exception e) {
- errorLogger.error("setGlobalLoggingContext failed", e);
- }
- }
-
- public static void mdcPut(String key, String value) {
- MDC.put(key, value);
- }
-
- public static String mdcGet(String key) {
- return MDC.get(key);
- }
-
- public static void mdcRemove(String key) {
- MDC.remove(key);
- }
-
- /**
- * Loads the RequestId/TransactionId into the MDC which it should be receiving with an each
- * incoming REST API request. Also, configures few other request based logging fields into the
- * MDC context.
- *
- * @param req
- * @param appName
- */
- public void setRequestBasedDefaultsIntoGlobalLoggingContext(HttpServletRequest req,
- String appName) {
- // Load the default fields
- setGlobalLoggingContext();
-
- // Load the request based fields
- if (req != null) {
- // Rest Path
- MDC.put(MDC_SERVICE_NAME, req.getServletPath());
-
- // Client IPAddress i.e. IPAddress of the remote host who is making
- // this request.
- String clientIPAddress = req.getHeader("X-FORWARDED-FOR");
- if (clientIPAddress == null) {
- clientIPAddress = req.getRemoteAddr();
- }
- }
- }
-}
diff --git a/jar/src/main/java/org/onap/music/eelf/logging/format/AppMessages.java b/jar/src/main/java/org/onap/music/eelf/logging/format/AppMessages.java
deleted file mode 100644
index 2c7952b2..00000000
--- a/jar/src/main/java/org/onap/music/eelf/logging/format/AppMessages.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * ============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.eelf.logging.format;
-
-/**
- * @author inam
- *
- */
-public enum AppMessages {
-
-
-
- /*
- * 100-199 Security/Permission Related - Authentication problems
- * [ERR100E] Missing Information
- * [ERR101E] Authentication error occured
- *
- * 200-299 Availability/Timeout Related/IO - connectivity error - connection timeout
- * [ERR200E] Connectivity
- * [ERR201E] Host not available
- * [ERR202E] Error while connecting to Cassandra cluster
- * [ERR203E] IO Error has occured
- * [ERR204E] Execution Interrupted
- * [ERR205E] Session Expired
- * [ERR206E] Cache not authenticated
- *
- *
- * 300-399 Data Access/Integrity Related
- * [ERR300E] Incorrect data
- *
- * 400-499 - Cassandra Query Related
- * [ERR400E] Error while processing prepared query object
- * [ERR401E] Executing Session Failure for Request
- * [ERR402E] Ill formed queryObject for the request
- * [ERR403E] Error processing Prepared Query Object
- *
- * 500-599 - Zookeepr/Locking Related
- * [ERR500E] Invalid lock
- * [ERR501E] Locking Error has occured
- * [ERR502E] Zookeeper error has occured
- * [ERR503E] Failed to aquire lock store handle
- * [ERR504E] Failed to create Lock Reference
- * [ERR505E] Lock does not exist
- * [ERR506E] Failed to aquire lock
- * [ERR507E] Lock not aquired
- * [ERR508E] Lock state not set
- * [ERR509E] Lock not destroyed
- * [ERR510E] Lock not released
- * [ERR511E] Lock not deleted
- * [ERR512E] Failed to get ZK Lock Handle
- *
- *
- * 600 - 699 - Music Service Errors
- * [ERR600E] Error initializing the cache
- *
- * 700-799 Schema Interface Type/Validation - received Pay-load checksum is
- * invalid - received JSON is not valid
- *
- * 800-899 Business/Flow Processing Related - check out to service is not
- * allowed - Roll-back is done - failed to generate heat file
- *
- *
- * 900-999 Unknown Errors - Unexpected exception
- * [ERR900E] Unexpected error occured
- * [ERR901E] Number format exception
- *
- *
- * 1000-1099 Reserved - do not use
- *
- */
-
-
-
-
- MISSINGINFO("[ERR100E]", "Missing Information ","Details: NA", "Please check application credentials and/or headers"),
- AUTHENTICATIONERROR("[ERR101E]", "Authentication error occured ","Details: NA", "Please verify application credentials"),
- CONNCECTIVITYERROR("[ERR200E]"," Connectivity error","Details: NA ","Please check connectivity to external resources"),
- HOSTUNAVAILABLE("[ERR201E]","Host not available","Details: NA","Please verify the host details"),
- CASSANDRACONNECTIVITY("[ERR202E]","Error while connecting to Cassandra cluster",""," Please check cassandra cluster details"),
- IOERROR("[ERR203E]","IO Error has occured","","Please check IO"),
- EXECUTIONINTERRUPTED("[ERR204E]"," Execution Interrupted","",""),
- SESSIONEXPIRED("[ERR205E]"," Session Expired","","Session has expired."),
- CACHEAUTHENTICATION("[ERR206E]","Cache not authenticated",""," Cache not authenticated"),
-
- INCORRECTDATA("[ERR300E]"," Incorrect data",""," Please verify the request payload and try again"),
- MULTIPLERECORDS("[ERR301E]"," Multiple records found",""," Please verify the request payload and try again"),
- ALREADYEXIST("[ERR302E]"," Record already exist",""," Please verify the request payload and try again"),
- MISSINGDATA("[ERR300E]"," Incorrect data",""," Please verify the request payload and try again"),
-
- QUERYERROR("[ERR400E]","Error while processing prepared query object",""," Please verify the query"),
- SESSIONFAILED("[ERR401E]","Executing Session Failure for Request","","Please verify the session and request"),
-
- INVALIDLOCK("[ERR500E]"," Invalid lock or acquire failed",""," Lock is not valid to aquire"),
- LOCKINGERROR("[ERR501E]"," Locking Error has occured",""," Locking Error has occured"),
- KEEPERERROR("[ERR502E]"," Zookeeper error has occured","","Please check zookeeper details"),
- LOCKHANDLE("[ERR503E]","Failed to aquire lock store handle",""," Failed to aquire lock store handle"),
- CREATELOCK("[ERR504E]","Failed to aquire lock store handle ","","Failed to aquire lock store handle "),
- LOCKSTATE("[ERR508E]"," Lock state not set",""," Lock state not set"),
- DESTROYLOCK("[ERR509E]"," Lock not destroyed",""," Lock not destroyed"),
- RELEASELOCK("[ERR510E]"," Lock not released",""," Lock not released"),
- DELTELOCK("[ERR511E]",""," Lock not deleted "," Lock not deleted "),
- CACHEERROR("[ERR600E]"," Error initializing the cache",""," Error initializing the cache"),
-
- UNKNOWNERROR("[ERR900E]"," Unexpected error occured",""," Please check logs for details");
-
-
-
- ErrorTypes eType;
- ErrorSeverity alarmSeverity;
- ErrorSeverity errorSeverity;
- String errorCode;
- String errorDescription;
- String details;
- String resolution;
-
-
- AppMessages(String errorCode, String errorDescription, String details,String resolution) {
-
- this.errorCode = errorCode;
- this.errorDescription = errorDescription;
- this.details = details;
- this.resolution = resolution;
- }
-
-
-
-
- AppMessages(ErrorTypes eType, ErrorSeverity alarmSeverity,
- ErrorSeverity errorSeverity, String errorCode, String errorDescription, String details,
- String resolution) {
-
- this.eType = eType;
- this.alarmSeverity = alarmSeverity;
- this.errorSeverity = errorSeverity;
- this.errorCode = errorCode;
- this.errorDescription = errorDescription;
- this.details = details;
- this.resolution = resolution;
- }
-
- public String getDetails() {
- return this.details;
- }
-
- public String getResolution() {
- return this.resolution;
- }
-
- public String getErrorCode() {
- return this.errorCode;
- }
-
- public String getErrorDescription() {
- return this.errorDescription;
- }
-
-
-
-
-
-
-
-}
diff --git a/jar/src/main/java/org/onap/music/eelf/logging/format/ErrorCodes.java b/jar/src/main/java/org/onap/music/eelf/logging/format/ErrorCodes.java
deleted file mode 100644
index b18c1771..00000000
--- a/jar/src/main/java/org/onap/music/eelf/logging/format/ErrorCodes.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * ============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.eelf.logging.format;
-
-
-
-/**
- * @author inam
- *
- */
-public enum ErrorCodes {
-
-
- /*
- * 100-199 Security/Permission Related - Authentication problems
- * [ERR100E] Missing Information
- * [ERR101E] Authentication error occured
- *
- * 200-299 Availability/Timeout Related/IO - connectivity error - connection timeout
- * [ERR200E] Connectivity
- * [ERR201E] Host not available
- * [ERR202E] Error while connecting to Cassandra cluster
- * [ERR203E] IO Error has occured
- * [ERR204E] Execution Interrupted
- * [ERR205E] Session Expired
- * [ERR206E] Cache not authenticated
- *
- *
- * 300-399 Data Access/Integrity Related
- *
- * 400-499 - Cassandra Query Related
- * [ERR400E] Error while processing prepared query object
- * [ERR401E] Executing Session Failure for Request
- * [ERR402E] Ill formed queryObject for the request
- * [ERR403E] Error processing Prepared Query Object
- *
- * 500-599 - Zookeepr/Locking Related
- * [ERR500E] Invalid lock
- * [ERR501E] Locking Error has occured
- * [ERR502E] Zookeeper error has occured
- * [ERR503E] Failed to aquire lock store handle
- * [ERR504E] Failed to create Lock Reference
- * [ERR505E] Lock does not exist
- * [ERR506E] Failed to aquire lock
- * [ERR507E] Lock not aquired
- * [ERR508E] Lock state not set
- * [ERR509E] Lock not destroyed
- * [ERR510E] Lock not released
- * [ERR511E] Lock not deleted
- * [ERR512E] Failed to get ZK Lock Handle
- *
- *
- * 600 - 699 - Music Service Errors
- * [ERR600E] Error initializing the cache
- *
- * 700-799 Schema Interface Type/Validation - received Pay-load checksum is
- * invalid - received JSON is not valid
- *
- * 800-899 Business/Flow Processing Related - check out to service is not
- * allowed - Roll-back is done - failed to generate heat file
- *
- *
- * 900-999 Unknown Errors - Unexpected exception
- * [ERR900E] Unexpected error occured
- * [ERR901E] Number format exception
- *
- *
- * 1000-1099 Reserved - do not use
- *
- */
-
- /*SUCCESS("Success"), FAILURE("Failure");
-
- private String result;
-
- ResultType(String result) {
- this.result = result;
- }
-
- public String getResult() {
- return result;
- }
-*/
-
-
-
-}
diff --git a/jar/src/main/java/org/onap/music/eelf/logging/format/ErrorSeverity.java b/jar/src/main/java/org/onap/music/eelf/logging/format/ErrorSeverity.java
deleted file mode 100644
index cda5dd31..00000000
--- a/jar/src/main/java/org/onap/music/eelf/logging/format/ErrorSeverity.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * ============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.eelf.logging.format;
-
-/**
- * @author inam
- *
- */
-public enum ErrorSeverity {
- INFO,
- WARN,
- ERROR,
- FATAL,
- CRITICAL,
- MAJOR,
- MINOR,
- NONE,
-}
diff --git a/jar/src/main/java/org/onap/music/eelf/logging/format/ErrorTypes.java b/jar/src/main/java/org/onap/music/eelf/logging/format/ErrorTypes.java
deleted file mode 100644
index 2536f4a4..00000000
--- a/jar/src/main/java/org/onap/music/eelf/logging/format/ErrorTypes.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * ============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.eelf.logging.format;
-
-import com.att.eelf.i18n.EELFResolvableErrorEnum;
-
-/**
- * @author inam
- *
- */
-public enum ErrorTypes implements EELFResolvableErrorEnum {
-
-
- CONNECTIONERROR,
- SESSIONEXPIRED,
- AUTHENTICATIONERROR,
- SERVICEUNAVAILABLE,
- QUERYERROR,
- DATAERROR,
- GENERALSERVICEERROR,
- MUSICSERVICEERROR,
- LOCKINGERROR,
- UNKNOWN,
-
-}
diff --git a/jar/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java b/jar/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java
deleted file mode 100644
index 14a23d1f..00000000
--- a/jar/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ============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/jar/src/main/java/org/onap/music/exceptions/MusicLockingException.java b/jar/src/main/java/org/onap/music/exceptions/MusicLockingException.java
deleted file mode 100644
index 1a9e45d9..00000000
--- a/jar/src/main/java/org/onap/music/exceptions/MusicLockingException.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * ============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;
-
-/**
- * @author inam
- *
- */
-public class MusicLockingException extends Exception {
-
- /**
- *
- */
- public MusicLockingException() {
-
- }
-
- /**
- * @param message
- */
- public MusicLockingException(String message) {
- super(message);
-
- }
-
- /**
- * @param cause
- */
- public MusicLockingException(Throwable cause) {
- super(cause);
-
- }
-
- /**
- * @param message
- * @param cause
- */
- public MusicLockingException(String message, Throwable cause) {
- super(message, cause);
-
- }
-
- /**
- * @param message
- * @param cause
- * @param enableSuppression
- * @param writableStackTrace
- */
- public MusicLockingException(String message, Throwable cause, boolean enableSuppression,
- boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
-
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/exceptions/MusicPolicyVoilationException.java b/jar/src/main/java/org/onap/music/exceptions/MusicPolicyVoilationException.java
deleted file mode 100644
index bade21a4..00000000
--- a/jar/src/main/java/org/onap/music/exceptions/MusicPolicyVoilationException.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ============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;
-
-/**
- * @author inam
- *
- */
-public class MusicPolicyVoilationException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- /**
- *
- */
- public MusicPolicyVoilationException() {
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- */
- public MusicPolicyVoilationException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param cause
- */
- public MusicPolicyVoilationException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- * @param cause
- */
- public MusicPolicyVoilationException(String message, Throwable cause) {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
-
- /**
- * @param message
- * @param cause
- * @param enableSuppression
- * @param writableStackTrace
- */
- public MusicPolicyVoilationException(String message, Throwable cause, boolean enableSuppression,
- boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- // TODO Auto-generated constructor stub
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/exceptions/MusicQueryException.java b/jar/src/main/java/org/onap/music/exceptions/MusicQueryException.java
deleted file mode 100644
index 24b8568b..00000000
--- a/jar/src/main/java/org/onap/music/exceptions/MusicQueryException.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * ============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;
-
-
-
-/**
- * @author inam
- *
- */
-public class MusicQueryException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- private int errorCode;
-
-
- /**
- *
- */
- public MusicQueryException() {
- super();
- }
-
- /**
- * @param message
- */
- public MusicQueryException(String message) {
- super(message);
- }
-
-
-
- /**
- * @param message
- */
- public MusicQueryException(String message, int errorCode) {
- super(message);
- this.errorCode = errorCode;
- }
-
- /**
- * @param cause
- */
- public MusicQueryException(Throwable cause) {
- super(cause);
- }
-
- /**
- * @param message
- * @param cause
- */
- public MusicQueryException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * @param message
- * @param cause
- * @param enableSuppression
- * @param writableStackTrace
- */
- public MusicQueryException(String message, Throwable cause, boolean enableSuppression,
- boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/exceptions/MusicServiceException.java b/jar/src/main/java/org/onap/music/exceptions/MusicServiceException.java
deleted file mode 100644
index a3b1fc56..00000000
--- a/jar/src/main/java/org/onap/music/exceptions/MusicServiceException.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * ============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;
-
-/**
- * @author inam
- *
- */
-public class MusicServiceException extends Exception {
-
-
- private int errorCode;
- private String errorMessage;
-
- public int getErrorCode() {
- return errorCode;
- }
-
-
- public void setErrorCode(int errorCode) {
- this.errorCode = errorCode;
- }
-
-
- public String getErrorMessage() {
- return errorMessage;
- }
-
-
- public void setErrorMessage(String errorMessage) {
- this.errorMessage = errorMessage;
- }
-
-
- public MusicServiceException() {
- super();
- }
-
-
- public MusicServiceException(String message) {
- super(message);
-
- }
-
-
- public MusicServiceException(Throwable cause) {
- super(cause);
-
- }
-
-
- public MusicServiceException(String message, Throwable cause) {
- super(message, cause);
-
- }
-
-
- public MusicServiceException(String message, Throwable cause, boolean enableSuppression,
- boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
-
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/lockingservice/LockListener.java b/jar/src/main/java/org/onap/music/lockingservice/LockListener.java
deleted file mode 100644
index 33188e60..00000000
--- a/jar/src/main/java/org/onap/music/lockingservice/LockListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * ============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.lockingservice;
-
-/**
- * This class has two methods which are call back methods when a lock is acquired and when the lock
- * is released.
- *
- */
-public interface LockListener {
- /**
- * call back called when the lock is acquired
- */
- public void lockAcquired();
-
- /**
- * call back called when the lock is released.
- */
- public void lockReleased();
-}
diff --git a/jar/src/main/java/org/onap/music/lockingservice/MusicLockState.java b/jar/src/main/java/org/onap/music/lockingservice/MusicLockState.java
deleted file mode 100644
index 6c31410f..00000000
--- a/jar/src/main/java/org/onap/music/lockingservice/MusicLockState.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * ============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.lockingservice;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-
-// the state variable that will be stored in zookeeper, capturing the transitions of
-public class MusicLockState implements Serializable {
- public enum LockStatus {
- UNLOCKED, BEING_LOCKED, LOCKED
- };// captures the state of the lock
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicLockState.class);
- LockStatus lockStatus;
- boolean needToSyncQuorum = false;
- String lockHolder;
- long leasePeriod = Long.MAX_VALUE, leaseStartTime = -1;
-
- private String errorMessage = null;
-
- public MusicLockState(String errorMessage) {
- this.errorMessage = errorMessage;
- }
-
- public MusicLockState(LockStatus lockStatus, String lockHolder) {
- this.lockStatus = lockStatus;
- this.lockHolder = lockHolder;
- }
-
- public MusicLockState(LockStatus lockStatus, String lockHolder, boolean needToSyncQuorum) {
- this.lockStatus = lockStatus;
- this.lockHolder = lockHolder;
- this.needToSyncQuorum = needToSyncQuorum;
- }
-
-
- public long getLeasePeriod() {
- return leasePeriod;
- }
-
- public boolean isNeedToSyncQuorum() {
- return needToSyncQuorum;
- }
-
-
-
- public void setLeasePeriod(long leasePeriod) {
- this.leasePeriod = leasePeriod;
- }
-
-
- public long getLeaseStartTime() {
- return leaseStartTime;
- }
-
-
- public void setLeaseStartTime(long leaseStartTime) {
- this.leaseStartTime = leaseStartTime;
- }
-
-
-
- public LockStatus getLockStatus() {
- return lockStatus;
- }
-
- public void setLockStatus(LockStatus lockStatus) {
- this.lockStatus = lockStatus;
- }
-
- public String getLockHolder() {
- return lockHolder;
- }
-
- public void setLockHolder(String lockHolder) {
- this.lockHolder = lockHolder;
- }
-
- public String getErrorMessage() {
- return errorMessage;
- }
-
- public byte[] serialize() {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutput out = null;
- try {
- out = new ObjectOutputStream(bos);
- out.writeObject(this);
- } catch (IOException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- }
- return bos.toByteArray();
- }
-
- public static MusicLockState deSerialize(byte[] data) {
- ByteArrayInputStream bis = new ByteArrayInputStream(data);
- Object o = null;
- ObjectInput in = null;
- try {
- in = new ObjectInputStream(bis);
- o = in.readObject();
- } catch (ClassNotFoundException | IOException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.UNKNOWN);
- }
- return (MusicLockState) o;
- }
-}
diff --git a/jar/src/main/java/org/onap/music/lockingservice/MusicLockingService.java b/jar/src/main/java/org/onap/music/lockingservice/MusicLockingService.java
deleted file mode 100644
index 4070238a..00000000
--- a/jar/src/main/java/org/onap/music/lockingservice/MusicLockingService.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * ============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.lockingservice;
-
-
-import java.io.IOException;
-import java.util.StringTokenizer;
-import java.util.concurrent.CountDownLatch;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
-import org.apache.zookeeper.ZooKeeper;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.exceptions.MusicLockingException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.MusicUtil;
-import java.util.concurrent.TimeUnit;
-
-
-public class MusicLockingService implements Watcher {
-
-
- private static final int SESSION_TIMEOUT = 180000;
- ZkStatelessLockService zkLockHandle = null;
- private CountDownLatch connectedSignal = new CountDownLatch(1);
- private static EELFLoggerDelegate logger =
- EELFLoggerDelegate.getLogger(MusicLockingService.class);
-
- public MusicLockingService() throws MusicServiceException {
- try {
- ZooKeeper zk = new ZooKeeper(MusicUtil.getMyZkHost(), SESSION_TIMEOUT, this);
- connectedSignal.await();
- zkLockHandle = new ZkStatelessLockService(zk);
- } catch (IOException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- throw new MusicServiceException("IO Error has occured" + e.getMessage());
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw new MusicServiceException("Exception Occured " + e.getMessage());
- }
- }
-
- public MusicLockingService(int timeout) throws MusicServiceException {
- CountDownLatch connectedSignal1 = new CountDownLatch(1);
- try {
- ZooKeeper zk1 = new ZooKeeper(MusicUtil.getMyZkHost(), SESSION_TIMEOUT, this);
- connectedSignal1.await(timeout, TimeUnit.SECONDS);
- if(!zk1.getState().isConnected()) {
- throw new MusicServiceException("Unable to Connect. Some nodes are down.");
- }
- } catch (IOException e ) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- throw new MusicServiceException("IO Error has occured" + e.getMessage());
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw new MusicServiceException("Exception Occured " + e.getMessage());
- }
- }
-
- public ZkStatelessLockService getzkLockHandle() {
- return zkLockHandle;
- }
-
- public MusicLockingService(String lockServer) {
- try {
- ZooKeeper zk = new ZooKeeper(lockServer, SESSION_TIMEOUT, this);
- connectedSignal.await();
- zkLockHandle = new ZkStatelessLockService(zk);
- } catch (IOException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- }catch( InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch(Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- }
-
- public void createLockaIfItDoesNotExist(String lockName) {
- if (!zkLockHandle.checkIfLockExists(lockName)) {
- String lockHolder = null;
- MusicLockState ml = new MusicLockState(MusicLockState.LockStatus.UNLOCKED, lockHolder);
- byte[] data = ml.serialize();
- zkLockHandle.createLock(lockName, data);
- }
- }
-
- public void setLockState(String lockName, MusicLockState mls) {
- byte[] data = mls.serialize();
- zkLockHandle.setNodeData(lockName, data);
- }
-
- public MusicLockState getLockState(String lockName) throws MusicLockingException {
-
- byte[] data = null;
- try{
- data = zkLockHandle.getNodeData(lockName);
- }catch (Exception ex){
- logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- if(data !=null)
- return MusicLockState.deSerialize(data);
- else {
- logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.INVALIDLOCK, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw new MusicLockingException("Invalid lock or acquire failed");
- }
- }
-
- public String createLockId(String lockName) {
- String lockIdWithSlash = zkLockHandle.createLockId(lockName);
- return lockIdWithSlash.replace('/', '$');
- }
-
- public boolean isMyTurn(String lockIdWithDollar) {
- String lockId = lockIdWithDollar.replace('$', '/');
- StringTokenizer st = new StringTokenizer(lockId);
- String lockName = "/" + st.nextToken("/");
- try {
- return zkLockHandle.lock(lockName, lockId);
- } catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.LOCKINGERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch( InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch(Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- return false;
- }
-
- public void unlockAndDeleteId(String lockIdWithDollar) throws KeeperException.NoNodeException {
- String lockId = lockIdWithDollar.replace('$', '/');
- zkLockHandle.unlock(lockId);
- }
-
- public void deleteLock(String lockName) throws MusicLockingException {
- if(lockIdExists(lockName))
- zkLockHandle.deleteLock(lockName);
- else{
- throw new MusicLockingException("Lock does not exist.Please check the lock: " + lockName + " and try again");
- }
- }
-
- public String whoseTurnIsIt(String lockName) {
- String lockHolder = zkLockHandle.currentLockHolder(lockName);
- return lockHolder.replace('/', '$');
-
- }
-
- public void process(WatchedEvent event) { // Watcher interface
- if (event.getState() == KeeperState.SyncConnected) {
- connectedSignal.countDown();
- }
- }
-
-
- public void close() {
- zkLockHandle.close();
- }
-
- public boolean lockIdExists(String lockIdWithDollar) {
- String lockId = lockIdWithDollar.replace('$', '/');
- return zkLockHandle.checkIfLockExists(lockId);
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java b/jar/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java
deleted file mode 100644
index 4082b3b8..00000000
--- a/jar/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * ============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.lockingservice;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.data.ACL;
-import org.apache.zookeeper.data.Stat;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.lockingservice.ZooKeeperOperation;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * A base class for protocol implementations which provides a number of higher level helper methods
- * for working with ZooKeeper along with retrying synchronous operations if the connection to
- * ZooKeeper closes such as {@link #retryOperation(ZooKeeperOperation)}
- *
- */
-class ProtocolSupport {
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ProtocolSupport.class);
-
- protected ZooKeeper zookeeper;
- private AtomicBoolean closed = new AtomicBoolean(false);
- private long retryDelay = 500L;
- private int retryCount = 10;
- private List<ACL> acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
-
- /**
- * Closes this strategy and releases any ZooKeeper resources; but keeps the ZooKeeper instance
- * open
- */
- public void close() {
- if (closed.compareAndSet(false, true)) {
- doClose();
- }
- }
-
- /**
- * return zookeeper client instance
- *
- * @return zookeeper client instance
- */
- public ZooKeeper getZookeeper() {
- return zookeeper;
- }
-
- /**
- * return the acl its using
- *
- * @return the acl.
- */
- public List<ACL> getAcl() {
- return acl;
- }
-
- /**
- * set the acl
- *
- * @param acl the acl to set to
- */
- public void setAcl(List<ACL> acl) {
- this.acl = acl;
- }
-
- /**
- * get the retry delay in milliseconds
- *
- * @return the retry delay
- */
- public long getRetryDelay() {
- return retryDelay;
- }
-
- /**
- * Sets the time waited between retry delays
- *
- * @param retryDelay the retry delay
- */
- public void setRetryDelay(long retryDelay) {
- this.retryDelay = retryDelay;
- }
-
- /**
- * Allow derived classes to perform some custom closing operations to release resources
- */
- protected void doClose() {
- throw new UnsupportedOperationException();
- }
-
-
- /**
- * Perform the given operation, retrying if the connection fails
- *
- * @return object. it needs to be cast to the callee's expected return type.
- * @param operation FILL IN
- * @throws KeeperException FILL IN
- * @throws InterruptedException FILL IN
- */
- protected Object retryOperation(ZooKeeperOperation operation)
- throws KeeperException, InterruptedException {
- KeeperException exception = null;
- for (int i = 0; i < retryCount; i++) {
- try {
- return operation.execute();
- } catch (KeeperException.SessionExpiredException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.SESSIONEXPIRED+" for: " + zookeeper + " so reconnecting due to: " + e, ErrorSeverity.ERROR, ErrorTypes.SESSIONEXPIRED);
- throw e;
- } catch (KeeperException.ConnectionLossException e) {
- if (exception == null) {
- exception = e;
- }
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.CONNCECTIVITYERROR, ErrorSeverity.ERROR, ErrorTypes.SESSIONEXPIRED);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Attempt " + i + " failed with connection loss so attempting to reconnect: " + e);
-
- retryDelay(i);
- }
- }
- throw exception;
- }
-
- /**
- * Ensures that the given path exists with no data, the current ACL and no flags
- *
- * @param path the lock path
- */
- protected void ensurePathExists(String path) {
- ensureExists(path, null, acl, CreateMode.PERSISTENT);
- }
-
- /**
- * Ensures that the given path exists with the given data, ACL and flags
- *
- * @param path the lock path
- * @param data the data
- * @param acl list of ACLs applying to the path
- * @param flags create mode flags
- */
- protected void ensureExists(final String path, final byte[] data, final List<ACL> acl,
- final CreateMode flags) {
- try {
- retryOperation(new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- Stat stat = zookeeper.exists(path, false);
- if (stat != null) {
- return true;
- }
- zookeeper.create(path, data, acl, flags);
- return true;
- }
- });
- } catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- }
-
- /**
- * Returns true if this protocol has been closed
- *
- * @return true if this protocol is closed
- */
- protected boolean isClosed() {
- return closed.get();
- }
-
- /**
- * Performs a retry delay if this is not the first attempt
- *
- * @param attemptCount the number of the attempts performed so far
- */
- protected void retryDelay(int attemptCount) {
- if (attemptCount > 0) {
- try {
- Thread.sleep(attemptCount * retryDelay);
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.GENERALSERVICEERROR);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Thread failed to sleep: " + e);
- Thread.currentThread().interrupt();
- }
- }
- }
-}
diff --git a/jar/src/main/java/org/onap/music/lockingservice/ZNodeName.java b/jar/src/main/java/org/onap/music/lockingservice/ZNodeName.java
deleted file mode 100644
index 0c190f14..00000000
--- a/jar/src/main/java/org/onap/music/lockingservice/ZNodeName.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * ============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.lockingservice;
-
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-
-/**
- * Represents an ephemeral znode name which has an ordered sequence number and can be sorted in
- * order
- *
- */
-class ZNodeName implements Comparable<ZNodeName> {
- private final String name;
- private String prefix;
- private int sequence = -1;
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ZNodeName.class);
-
- public ZNodeName(String name) {
- if (name == null) {
- throw new NullPointerException("id cannot be null");
- }
- this.name = name;
- this.prefix = name;
- int idx = name.lastIndexOf('-');
- if (idx >= 0) {
- this.prefix = name.substring(0, idx);
- try {
- this.sequence = Integer.parseInt(name.substring(idx + 1));
- // If an exception occurred we misdetected a sequence suffix,
- // so return -1.
- } catch (NumberFormatException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Number format exception "+idx, ErrorSeverity.ERROR, ErrorTypes.GENERALSERVICEERROR);
- } catch (ArrayIndexOutOfBoundsException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Array out of bounds for "+idx, ErrorSeverity.ERROR, ErrorTypes.GENERALSERVICEERROR);
- }
- }
- }
-
- @Override
- public String toString() {
- return name.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (o == null || getClass() != o.getClass())
- return false;
-
- ZNodeName sequence = (ZNodeName) o;
-
- if (!name.equals(sequence.name))
- return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- return name.hashCode() + 37;
- }
-
- public int compareTo(ZNodeName that) {
- int answer = this.prefix.compareTo(that.prefix);
- if (answer == 0) {
- int s1 = this.sequence;
- int s2 = that.sequence;
- if (s1 == -1 && s2 == -1) {
- return this.name.compareTo(that.name);
- }
- answer = s1 == -1 ? 1 : s2 == -1 ? -1 : s1 - s2;
- }
- return answer;
- }
-
- /**
- * Returns the name of the znode
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the sequence number
- */
- public int getZNodeName() {
- return sequence;
- }
-
- /**
- * Returns the text prefix before the sequence number
- */
- public String getPrefix() {
- return prefix;
- }
-}
diff --git a/jar/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java b/jar/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java
deleted file mode 100644
index e99df255..00000000
--- a/jar/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * ============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.lockingservice;
-
-
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.data.ACL;
-import org.apache.zookeeper.data.Stat;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-
-/**
- * A <a href="package.html">protocol to implement an exclusive write lock or to elect a leader</a>.
- * <p/>
- * You invoke {@link #lock()} to start the process of grabbing the lock; you may get the lock then
- * or it may be some time later.
- * <p/>
- * You can register a listener so that you are invoked when you get the lock; otherwise you can ask
- * if you have the lock by calling {@link #isOwner()}
- *
- */
-public class ZkStatelessLockService extends ProtocolSupport {
- public ZkStatelessLockService(ZooKeeper zk) {
- zookeeper = zk;
- }
-
- private static EELFLoggerDelegate logger =
- EELFLoggerDelegate.getLogger(ZkStatelessLockService.class);
-
- protected void createLock(final String path, final byte[] data) {
- final List<ACL> acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
- try {
- retryOperation(new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- zookeeper.create(path, data, acl, CreateMode.PERSISTENT);
- return true;
- }
- });
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- }
-
- public void close() {
- try {
- zookeeper.close();
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- }
-
- public void setNodeData(final String lockName, final byte[] data) {
- try {
- retryOperation(new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- zookeeper.getSessionId();
- zookeeper.setData("/" + lockName, data, -1);
- return true;
- }
- });
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
-
- }
-
- public byte[] getNodeData(final String lockName) {
- try {
- if (zookeeper.exists("/" + lockName, null) != null)
- return zookeeper.getData("/" + lockName, false, null);
- else
- return null;
-
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- return null;
- }
-
- public boolean checkIfLockExists(String lockName) {
- boolean result = false;
- try {
- Stat stat = zookeeper.exists(lockName, false);
- if (stat != null) {
- result = true;
- }
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- return result;
- }
-
- public void createNode(String nodeName) {
- ensurePathExists(nodeName);
- }
-
- public String createLockId(String dir) {
- ensurePathExists(dir);
- LockZooKeeperOperation zop = new LockZooKeeperOperation(dir);
- try {
- retryOperation(zop);
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- return zop.getId();
- }
-
- /**
- * Attempts to acquire the exclusive write lock returning whether or not it was acquired. Note
- * that the exclusive lock may be acquired some time later after this method has been invoked
- * due to the current lock owner going away.
- */
- public synchronized boolean lock(String dir, String lockId)
- throws KeeperException, InterruptedException {
- if (isClosed()) {
- return false;
- }
- LockZooKeeperOperation zop = new LockZooKeeperOperation(dir, lockId);
- return (Boolean) retryOperation(zop);
- }
-
- /**
- * Removes the lock or associated znode if you no longer require the lock. this also removes
- * your request in the queue for locking in case you do not already hold the lock.
- *
- * @throws RuntimeException throws a runtime exception if it cannot connect to zookeeper.
- * @throws NoNodeException
- */
- public synchronized void unlock(String lockId) throws RuntimeException, KeeperException.NoNodeException {
- final String id = lockId;
- if (!isClosed() && id != null) {
- try {
- ZooKeeperOperation zopdel = new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- zookeeper.delete(id, -1);
- return Boolean.TRUE;
- }
- };
- zopdel.execute();
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- // set that we have been interrupted.
- Thread.currentThread().interrupt();
- } catch (KeeperException.NoNodeException e) {
- // do nothing
- throw new KeeperException.NoNodeException("Lock doesn't exists. Release lock operation failed.");
- } catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw (RuntimeException) new RuntimeException(e.getMessage()).initCause(e);
- }
- }
- }
-
- public synchronized String currentLockHolder(String mainLock) {
- final String id = mainLock;
- if (!isClosed() && id != null) {
- List<String> names;
- try {
- names = zookeeper.getChildren(id, false);
- if (names.isEmpty())
- return "";
- SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
- for (String name : names) {
- sortedNames.add(new ZNodeName(id + "/" + name));
- }
- return sortedNames.first().getName();
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- // set that we have been interrupted.
- Thread.currentThread().interrupt();
- } catch (KeeperException.NoNodeException e) {
- // do nothing
- } catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw (RuntimeException) new RuntimeException(e.getMessage()).initCause(e);
- }
- }
- return "No lock holder!";
- }
-
- public synchronized void deleteLock(String mainLock) {
- final String id = mainLock;
- if (!isClosed() && id != null) {
- try {
- ZooKeeperOperation zopdel = new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- List<String> names = zookeeper.getChildren(id, false);
- for (String name : names) {
- zookeeper.delete(id + "/" + name, -1);
- }
- zookeeper.delete(id, -1);
- return Boolean.TRUE;
- }
- };
- zopdel.execute();
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- // set that we have been interrupted.
- Thread.currentThread().interrupt();
- } catch (KeeperException.NoNodeException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- // do nothing
- } catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw (RuntimeException) new RuntimeException(e.getMessage()).initCause(e);
- }
- }
-
- }
-
- /**
- * a zoookeeper operation that is mainly responsible for all the magic required for locking.
- */
- private class LockZooKeeperOperation implements ZooKeeperOperation {
-
- /**
- * find if we have been created earlier if not create our node
- *
- * @param prefix the prefix node
- * @param zookeeper the zookeeper client
- * @param dir the dir parent
- * @throws KeeperException
- * @throws InterruptedException
- */
- private String dir;
- private String id = null;
-
- public String getId() {
- return id;
- }
-
- public LockZooKeeperOperation(String dir) {
- this.dir = dir;
- }
-
- public LockZooKeeperOperation(String dir, String id) {
- this.dir = dir;
- this.id = id;
- }
-
- /**
- * the command that is run and retried for actually obtaining the lock
- *
- * @return if the command was successful or not
- */
- public boolean execute() throws KeeperException, InterruptedException {
- do {
- if (id == null) {
- String prefix = "x-";
- byte[] data = {0x12, 0x34};
- id = zookeeper.create(dir + "/" + prefix, data, getAcl(),
- CreateMode.PERSISTENT_SEQUENTIAL);
-
- if (logger.isDebugEnabled()) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Created id: " + id);
- }
- if (id != null)
- break;
- }
- if (id != null) {
- List<String> names = zookeeper.getChildren(dir, false);
- if (names.isEmpty()) {
- logger.info(EELFLoggerDelegate.applicationLogger, "No children in: " + dir
- + " when we've just " + "created one! Lets recreate it...");
- // lets force the recreation of the id
- id = null;
- return Boolean.FALSE;
-
- } else {
- // lets sort them explicitly (though they do seem to come back in order
- // ususally :)
- ZNodeName idName = new ZNodeName(id);
- SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
- for (String name : names) {
- sortedNames.add(new ZNodeName(dir + "/" + name));
- }
- if (!sortedNames.contains(idName))
- return Boolean.FALSE;
-
- SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
- if (!lessThanMe.isEmpty()) {
- ZNodeName lastChildName = lessThanMe.last();
- String lastChildId = lastChildName.getName();
- if (logger.isDebugEnabled()) {
- logger.debug(EELFLoggerDelegate.debugLogger, "watching less than me node: " + lastChildId);
- }
- Stat stat = zookeeper.exists(lastChildId, false);
- if (stat != null) {
- return Boolean.FALSE;
- } else {
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Could not find the" + " stats for less than me: "
- + lastChildName.getName());
- }
- } else
- return Boolean.TRUE;
- }
- }
- } while (id == null);
- return Boolean.FALSE;
- }
- }
-
-}
-
diff --git a/jar/src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java b/jar/src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java
deleted file mode 100644
index 7020d14d..00000000
--- a/jar/src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ============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.lockingservice;
-
-import org.apache.zookeeper.KeeperException;
-
-/**
- * A callback object which can be used for implementing retry-able operations in the
- * {@link org.onap.music.lockingservice.ProtocolSupport} class
- *
- */
-public interface ZooKeeperOperation {
-
- /**
- * Performs the operation - which may be involved multiple times if the connection
- * to ZooKeeper closes during this operation
- *
- * @return the result of the operation or null
- * @throws KeeperException FILL IN
- * @throws InterruptedException FILL IN
- */
- public boolean execute() throws KeeperException, InterruptedException;
-}
diff --git a/jar/src/main/java/org/onap/music/main/CachingUtil.java b/jar/src/main/java/org/onap/music/main/CachingUtil.java
deleted file mode 100755
index aa06aae2..00000000
--- a/jar/src/main/java/org/onap/music/main/CachingUtil.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
- * ============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.main;
-
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.UUID;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.jcs.JCS;
-import org.apache.commons.jcs.access.CacheAccess;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.mindrot.jbcrypt.BCrypt;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.AAFResponse;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.exceptions.MusicServiceException;
-
-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;
-
-/**
- * All Caching related logic is handled by this class and a schedule cron runs to update cache.
- *
- * @author Vikram
- *
- */
-public class CachingUtil implements Runnable {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CachingUtil.class);
-
- private static CacheAccess<String, String> musicCache = JCS.getInstance("musicCache");
- private static CacheAccess<String, Map<String, String>> aafCache = JCS.getInstance("aafCache");
- private static CacheAccess<String, String> appNameCache = JCS.getInstance("appNameCache");
- private static CacheAccess<String, Map<String, String>> musicValidateCache = JCS.getInstance("musicValidateCache");
- private static Map<String, Number> userAttempts = new HashMap<>();
- private static Map<String, Calendar> lastFailedTime = new HashMap<>();
-
- public boolean isCacheRefreshNeeded() {
- if (aafCache.get("initBlankMap") == null)
- return true;
- return false;
- }
-
- public void initializeMusicCache() {
- logger.info(EELFLoggerDelegate.applicationLogger,"Initializing Music Cache...");
- musicCache.put("isInitialized", "true");
- }
-
- public void initializeAafCache() throws MusicServiceException {
- logger.info(EELFLoggerDelegate.applicationLogger,"Resetting and initializing AAF Cache...");
-
- String query = "SELECT uuid, application_name, keyspace_name, username, password FROM admin.keyspace_master WHERE is_api = ? allow filtering";
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(query);
- try {
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), false));
- } catch (Exception e1) {
- logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.CACHEERROR, ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- e1.printStackTrace();
- }
- ResultSet rs = MusicCore.get(pQuery);
- Iterator<Row> it = rs.iterator();
- Map<String, String> map = null;
- while (it.hasNext()) {
- Row row = it.next();
- String nameSpace = row.getString("keyspace_name");
- String userId = row.getString("username");
- String password = row.getString("password");
- String keySpace = row.getString("application_name");
- try {
- userAttempts.put(nameSpace, 0);
- AAFResponse responseObj = triggerAAF(nameSpace, userId, password);
- if (responseObj.getNs().size() > 0) {
- map = new HashMap<>();
- map.put(userId, password);
- aafCache.put(nameSpace, map);
- musicCache.put(keySpace, nameSpace);
- logger.debug("Cronjob: Cache Updated with AAF response for namespace "
- + nameSpace);
- }
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Something at AAF was changed for ns: " + nameSpace+" So not updating Cache for the namespace. ");
- e.printStackTrace();
- }
- }
-
- }
-
- @Override
- public void run() {
- logger.info(EELFLoggerDelegate.applicationLogger,"Scheduled task invoked. Refreshing Cache...");
- try {
- initializeAafCache();
- } catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR);
- }
- }
-
- public static boolean authenticateAAFUser(String nameSpace, String userId, String password,
- String keySpace) throws Exception {
-
- if (aafCache.get(nameSpace) != null) {
- if (keySpace != null && !musicCache.get(keySpace).equals(nameSpace)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Create new application for the same namespace.");
- } else if (aafCache.get(nameSpace).get(userId).equals(password)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Authenticated with cache value..");
- // reset invalid attempts to 0
- userAttempts.put(nameSpace, 0);
- return true;
- } else {
- // call AAF update cache with new password
- if (userAttempts.get(nameSpace) == null)
- userAttempts.put(nameSpace, 0);
- if ((Integer) userAttempts.get(nameSpace) >= 3) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Reached max attempts. Checking if time out..");
- logger.info(EELFLoggerDelegate.applicationLogger,"Failed time: "+lastFailedTime.get(nameSpace).getTime());
- Calendar calendar = Calendar.getInstance();
- long delayTime = (calendar.getTimeInMillis()-lastFailedTime.get(nameSpace).getTimeInMillis());
- logger.info(EELFLoggerDelegate.applicationLogger,"Delayed time: "+delayTime);
- if( delayTime > 120000) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Resetting failed attempt.");
- userAttempts.put(nameSpace, 0);
- } else {
- logger.info(EELFLoggerDelegate.applicationLogger,"No more attempts allowed. Please wait for atleast 2 min.");
- throw new Exception("No more attempts allowed. Please wait for atleast 2 min.");
- }
- }
- logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.CACHEAUTHENTICATION,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- logger.info(EELFLoggerDelegate.applicationLogger,"Check AAF again...");
- }
- }
-
- AAFResponse responseObj = triggerAAF(nameSpace, userId, password);
- if (responseObj.getNs().size() > 0) {
- if (responseObj.getNs().get(0).getAdmin().contains(userId)) {
- //Map<String, String> map = new HashMap<>();
- //map.put(userId, password);
- //aafCache.put(nameSpace, map);
- return true;
- }
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"Invalid user. Cache not updated");
- return false;
- }
-
- private static AAFResponse triggerAAF(String nameSpace, String userId, String password)
- throws Exception {
- if (MusicUtil.getAafEndpointUrl() == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
- throw new Exception("AAF endpoint is not set. Please specify in the properties file.");
- }
- Client client = Client.create();
- // WebResource webResource =
- // client.resource("https://aaftest.test.att.com:8095/proxy/authz/nss/"+nameSpace);
- WebResource webResource = client.resource(MusicUtil.getAafEndpointUrl().concat(nameSpace));
- String plainCreds = userId + ":" + password;
- byte[] plainCredsBytes = plainCreds.getBytes();
- byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
- String base64Creds = new String(base64CredsBytes);
-
- ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON)
- .header("Authorization", "Basic " + base64Creds)
- .header("content-type", "application/json").get(ClientResponse.class);
- if (response.getStatus() != 200) {
- if (userAttempts.get(nameSpace) == null)
- userAttempts.put(nameSpace, 0);
- if ((Integer) userAttempts.get(nameSpace) >= 2) {
- lastFailedTime.put(nameSpace, Calendar.getInstance());
- userAttempts.put(nameSpace, ((Integer) userAttempts.get(nameSpace) + 1));
- throw new Exception(
- "Reached max invalid attempts. Please contact admin and retry with valid credentials.");
- }
- userAttempts.put(nameSpace, ((Integer) userAttempts.get(nameSpace) + 1));
- throw new Exception(
- "Unable to authenticate. Please check the AAF credentials against namespace.");
- // TODO Allow for 2-3 times and forbid any attempt to trigger AAF with invalid values
- // for specific time.
- }
- response.getHeaders().put(HttpHeaders.CONTENT_TYPE,
- Arrays.asList(MediaType.APPLICATION_JSON));
- // AAFResponse output = response.getEntity(AAFResponse.class);
- response.bufferEntity();
- String x = response.getEntity(String.class);
- AAFResponse responseObj = new ObjectMapper().readValue(x, AAFResponse.class);
-
- return responseObj;
- }
-
- public static void updateMusicCache(String keyspace, String nameSpace) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Updating musicCache for keyspace " + keyspace + " with nameSpace " + nameSpace);
- musicCache.put(keyspace, nameSpace);
- }
-
- public static void updateMusicValidateCache(String nameSpace, String userId, String password) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Updating musicCache for nameSpacce " + nameSpace + " with userId " + userId);
- Map<String, String> map = new HashMap<>();
- map.put(userId, password);
- musicValidateCache.put(nameSpace, map);
- }
-
- public static void updateisAAFCache(String namespace, String isAAF) {
- appNameCache.put(namespace, isAAF);
- }
-
- public static String isAAFApplication(String namespace) throws MusicServiceException {
- String isAAF = appNameCache.get(namespace);
- if (isAAF == null) {
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "SELECT is_aaf from admin.keyspace_master where application_name = '"
- + namespace + "' allow filtering");
- 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)
- appNameCache.put(namespace, isAAF);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- e.printStackTrace();
- }
- }
- return isAAF;
- }
-
- public static String getUuidFromMusicCache(String keyspace) throws MusicServiceException {
- String uuid = null;
- if (uuid == null) {
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "SELECT uuid from admin.keyspace_master where keyspace_name = '"
- + keyspace + "' allow filtering");
- Row rs = MusicCore.get(pQuery).one();
- try {
- uuid = rs.getUUID("uuid").toString();
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Exception occured during uuid retrieval from DB."+e.getMessage());
- e.printStackTrace();
- }
- }
- return uuid;
- }
-
- public static String getAppName(String keyspace) throws MusicServiceException {
- String appName = null;
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "SELECT application_name from admin.keyspace_master where keyspace_name = '"
- + keyspace + "' allow filtering");
- Row rs = MusicCore.get(pQuery).one();
- try {
- appName = rs.getString("application_name");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- e.printStackTrace();
- }
- return appName;
- }
-
- public static String generateUUID() {
- String uuid = UUID.randomUUID().toString();
- logger.info(EELFLoggerDelegate.applicationLogger,"New AID generated: "+uuid);
- return uuid;
- }
-
- public static Map<String, Object> validateRequest(String nameSpace, String userId,
- String password, String keyspace, String aid, String operation) {
- Map<String, Object> resultMap = new HashMap<>();
- if (!"createKeySpace".equals(operation)) {
- if (nameSpace == null) {
- resultMap.put("Exception", "Application namespace is mandatory.");
- }
- }
- return resultMap;
-
- }
-
- public static Map<String, Object> verifyOnboarding(String ns, String userId, String password) {
- Map<String, Object> resultMap = new HashMap<>();
- if (ns == null || userId == null || password == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- logger.error(EELFLoggerDelegate.errorLogger,"One or more required headers is missing. userId: "+userId+" :: password: "+password);
- resultMap.put("Exception",
- "One or more required headers appName(ns), userId, password is missing. Please check.");
- return resultMap;
- }
- PreparedQueryObject queryObject = new PreparedQueryObject();
- queryObject.appendQueryString(
- "select * from admin.keyspace_master where application_name = ? allow filtering");
- try {
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
- } catch(Exception e) {
- resultMap.put("Exception",
- "Unable to process input data. Invalid input data type. Please check ns, userId and password values. "+e.getMessage());
- return resultMap;
- }
- Row rs = null;
- try {
- rs = MusicCore.get(queryObject).one();
- } catch (MusicServiceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
- return resultMap;
- } 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.");
- } else {
- if(!(rs.getString("username").equals(userId)) || !(BCrypt.checkpw(password, rs.getString("password")))) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- logger.error(EELFLoggerDelegate.errorLogger,"Namespace, UserId and password doesn't match. namespace: "+ns+" and userId: "+userId);
- resultMap.put("Exception", "Namespace, UserId and password doesn't match. namespace: "+ns+" and userId: "+userId);
- return resultMap;
- }
- }
- return resultMap;
- }
-
- public static Map<String, Object> authenticateAIDUser(String nameSpace, String userId, String password,
- String keyspace) {
- Map<String, Object> resultMap = new HashMap<>();
- String pwd = null;
- if((musicCache.get(keyspace) != null) && (musicValidateCache.get(nameSpace) != null)
- && (musicValidateCache.get(nameSpace).containsKey(userId))) {
- if(!musicCache.get(keyspace).equals(nameSpace)) {
- resultMap.put("Exception", "Namespace and keyspace doesn't match");
- return resultMap;
- }
- if(!BCrypt.checkpw(password,musicValidateCache.get(nameSpace).get(userId))) {
- resultMap.put("Exception", "Namespace, userId and password doesn't match");
- return resultMap;
- }
- return resultMap;
- }
- PreparedQueryObject queryObject = new PreparedQueryObject();
- queryObject.appendQueryString(
- "select * from admin.keyspace_master where keyspace_name = ? allow filtering");
- try {
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspace));
- } catch (Exception e) {
- e.printStackTrace();
- }
- Row rs = null;
- try {
- rs = MusicCore.get(queryObject).one();
- } catch (MusicServiceException e) {
- e.printStackTrace();
- resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
- return resultMap;
- }
- if(rs == null) {
- resultMap.put("Exception", "Please make sure keyspace:"+keyspace+" exists.");
- return resultMap;
- }
- else {
- String user = rs.getString("username");
- pwd = rs.getString("password");
- String ns = rs.getString("application_name");
- if(!ns.equals(nameSpace)) {
- resultMap.put("Exception", "Namespace and keyspace doesn't match");
- return resultMap;
- }
- if(!user.equals(userId)) {
- resultMap.put("Exception", "Invalid userId :"+userId);
- return resultMap;
- }
- if(!BCrypt.checkpw(password, pwd)) {
- resultMap.put("Exception", "Invalid password");
- return resultMap;
- }
- }
- CachingUtil.updateMusicCache(keyspace, nameSpace);
- CachingUtil.updateMusicValidateCache(nameSpace, userId, pwd);
- return resultMap;
- }
-}
diff --git a/jar/src/main/java/org/onap/music/main/CipherUtil.java b/jar/src/main/java/org/onap/music/main/CipherUtil.java
deleted file mode 100644
index 1c7a687b..00000000
--- a/jar/src/main/java/org/onap/music/main/CipherUtil.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * ============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.main;
-
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.UnsupportedEncodingException;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.util.Scanner;
-
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang3.ArrayUtils;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-
-public class CipherUtil {
-
-
- /**
- * Default key.
- */
- private static String keyString = null;
-
- private static final String ALGORITHM = "AES";
- private static final String ALGORYTHM_DETAILS = ALGORITHM + "/CBC/PKCS5PADDING";
- private static final int BLOCK_SIZE = 128;
- @SuppressWarnings("unused")
- private static SecretKeySpec secretKeySpec;
- private static IvParameterSpec ivspec;
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CipherUtil.class);
- /**
- * @deprecated Please use {@link #encryptPKC(String)} to encrypt the text.
- *
- * Encrypts the text using the specified secret key.
- *
- * @param plainText
- * Text to encrypt
- * @param secretKey
- * Key to use for encryption
- * @return encrypted version of plain text.
- * @
- * if any encryption step fails
- *
- */
- @Deprecated
- public static String encrypt(String plainText, String secretKey) {
- String encryptedString = null;
- try {
- byte[] encryptText = plainText.getBytes("UTF-8");
- byte[] rawKey = Base64.decodeBase64(secretKey);
- SecretKeySpec sKeySpec = new SecretKeySpec(rawKey, "AES");
- Cipher cipher = Cipher.getInstance("AES");
- cipher.init(Cipher.ENCRYPT_MODE, sKeySpec);
- encryptedString = Base64.encodeBase64String(cipher.doFinal(encryptText));
- } catch (BadPaddingException | IllegalBlockSizeException | InvalidKeyException | NoSuchAlgorithmException
- | NoSuchPaddingException | UnsupportedEncodingException ex) {
- }
- return encryptedString;
- }
-
- /**
- * @deprecated Please use {@link #encryptPKC(String)} to encrypt the text.
- * Encrypts the text using the secret key in key.properties file.
- *
- * @param plainText
- * Text to encrypt
- * @return Encrypted Text
- * @
- * if any decryption step fails
- */
- @Deprecated
- public static String encrypt(String plainText) {
- return CipherUtil.encrypt(plainText, keyString);
- }
-
- /**
- * Encrypts the text using a secret key.
- *
- * @param plainText
- * Text to encrypt
- * @return Encrypted Text
- * @
- * if any decryption step fails
- */
- public static String encryptPKC(String plainText) {
- return CipherUtil.encryptPKC(plainText, keyString);
- }
-
- /**
- *
- * @deprecated Please use {@link #decryptPKC(String)} to Decryption the text.
- *
- * Decrypts the text using the specified secret key.
- *
- * @param encryptedText
- * Text to decrypt
- * @param secretKey
- * Key to use for decryption
- * @return plain text version of encrypted text
- * @
- * if any decryption step fails
- *
- */
- @Deprecated
- public static String decrypt(String encryptedText, String secretKey) {
- String encryptedString = null;
- try {
- byte[] rawKey = Base64.decodeBase64(secretKey);
- SecretKeySpec sKeySpec = new SecretKeySpec(rawKey, "AES");
- byte[] encryptText = Base64.decodeBase64(encryptedText.getBytes("UTF-8"));
- Cipher cipher = Cipher.getInstance("AES");
- cipher.init(Cipher.DECRYPT_MODE, sKeySpec);
- encryptedString = new String(cipher.doFinal(encryptText));
- } catch (BadPaddingException | IllegalBlockSizeException | InvalidKeyException | NoSuchAlgorithmException
- | NoSuchPaddingException | UnsupportedEncodingException ex) {
- }
- return encryptedString;
- }
-
- private static SecretKeySpec getSecretKeySpec() {
- byte[] key = Base64.decodeBase64(keyString);
- return new SecretKeySpec(key, ALGORITHM);
- }
-
- private static SecretKeySpec getSecretKeySpec(String keyString) {
- byte[] key = Base64.decodeBase64(keyString);
- return new SecretKeySpec(key, ALGORITHM);
- }
-
- /**
- * Encrypt the text using the secret key in key.properties file
- *
- * @param value
- * @return The encrypted string
- * @throws BadPaddingException
- * @
- * In case of issue with the encryption
- */
- public static String encryptPKC(String value, String skey) {
- Cipher cipher = null;
- byte[] iv = null, finalByte = null;
-
- try {
- cipher = Cipher.getInstance(ALGORYTHM_DETAILS, "SunJCE");
-
- SecureRandom r = SecureRandom.getInstance("SHA1PRNG");
- iv = new byte[BLOCK_SIZE / 8];
- r.nextBytes(iv);
- ivspec = new IvParameterSpec(iv);
- cipher.init(Cipher.ENCRYPT_MODE, getSecretKeySpec(skey), ivspec);
- finalByte = cipher.doFinal(value.getBytes());
-
- } catch (Exception ex) {
-
- }
- return Base64.encodeBase64String(ArrayUtils.addAll(iv, finalByte));
- }
-
- /**
- * Decrypts the text using the secret key in key.properties file.
- *
- * @param message
- * The encrypted string that must be decrypted using the ecomp
- * Encryption Key
- * @return The String decrypted
- * @
- * if any decryption step fails
- */
- public static String decryptPKC(String message, String skey) {
- byte[] encryptedMessage = Base64.decodeBase64(message);
- Cipher cipher;
- byte[] decrypted = null;
- try {
- cipher = Cipher.getInstance(ALGORYTHM_DETAILS, "SunJCE");
- ivspec = new IvParameterSpec(ArrayUtils.subarray(encryptedMessage, 0, BLOCK_SIZE / 8));
- byte[] realData = ArrayUtils.subarray(encryptedMessage, BLOCK_SIZE / 8, encryptedMessage.length);
- cipher.init(Cipher.DECRYPT_MODE, getSecretKeySpec(skey), ivspec);
- decrypted = cipher.doFinal(realData);
-
- } catch (Exception ex) {
-
-
- }
-
- return new String(decrypted);
- }
-
- /**
- * @deprecated Please use {@link #decryptPKC(String)} to Decrypt the text.
- *
- * Decrypts the text using the secret key in key.properties file.
- *
- * @param encryptedText
- * Text to decrypt
- * @return Decrypted text
- * @
- * if any decryption step fails
- */
- @Deprecated
- public static String decrypt(String encryptedText) {
- return CipherUtil.decrypt(encryptedText, keyString);
- }
-
- /**
- *
- * Decrypts the text using the secret key in key.properties file.
- *
- * @param encryptedText
- * Text to decrypt
- * @return Decrypted text
- * @
- * if any decryption step fails
- */
- public static String decryptPKC(String encryptedText) {
- return CipherUtil.decryptPKC(encryptedText, keyString);
- }
-
-
- public static void readAndSetKeyString() {
- try {
- Scanner in = new Scanner(new FileReader("/opt/app/music/etc/properties.txt"));
- StringBuilder sb = new StringBuilder();
- while(in.hasNext()) {
- sb.append(in.next());
- }
- in.close();
- keyString = sb.toString();
- } catch (FileNotFoundException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
- }
-
- /*public static void main(String[] args) {
-
- System.out.println("Encrypted password: "+encryptPKC("cassandra"));
-
- System.out.println("Decrypted password: "+decryptPKC("dDhqAp5/RwZbl9yRSZg15fN7Qul9eiE/JFkKemtTib0="));
- System.out.println("Decrypted password: "+decryptPKC("I/dOtD/YYzBStbtOYhKuUUyPHSW2G9ZzdSyB8bJp4vk="));
- System.out.println("Decrypted password: "+decryptPKC("g7zJqg74dLsH/fyL7I75b4eySy3pbMS2xVqkrB5lDl8="));
- }*/
-
-}
diff --git a/jar/src/main/java/org/onap/music/main/CronJobManager.java b/jar/src/main/java/org/onap/music/main/CronJobManager.java
deleted file mode 100644
index fb4a2ac3..00000000
--- a/jar/src/main/java/org/onap/music/main/CronJobManager.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * ============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.main;
-
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.annotation.WebListener;
-
-@WebListener
-public class CronJobManager implements ServletContextListener {
-
- private ScheduledExecutorService scheduler;
-
- @Override
- public void contextInitialized(ServletContextEvent event) {
- scheduler = Executors.newSingleThreadScheduledExecutor();
- scheduler.scheduleAtFixedRate(new CachingUtil(), 0, 24, TimeUnit.HOURS);
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent event) {
- scheduler.shutdownNow();
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/main/MusicCore.java b/jar/src/main/java/org/onap/music/main/MusicCore.java
deleted file mode 100644
index cad384a3..00000000
--- a/jar/src/main/java/org/onap/music/main/MusicCore.java
+++ /dev/null
@@ -1,992 +0,0 @@
-/*
- * ============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.main;
-
-
-import java.io.StringWriter;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.exceptions.MusicLockingException;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
-import org.onap.music.lockingservice.MusicLockingService;
-
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.ColumnDefinitions.Definition;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.TableMetadata;
-
-/**
- * This class .....
- *
- *
- */
-public class MusicCore {
-
- public static MusicLockingService mLockHandle = null;
- public static MusicDataStore mDstoreHandle = null;
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
-
- public static class Condition {
- Map<String, Object> conditions;
- PreparedQueryObject selectQueryForTheRow;
-
- public Condition(Map<String, Object> conditions, PreparedQueryObject selectQueryForTheRow) {
- this.conditions = conditions;
- this.selectQueryForTheRow = selectQueryForTheRow;
- }
-
- public boolean testCondition() throws Exception {
- // first generate the row
- ResultSet results = quorumGet(selectQueryForTheRow);
- Row row = results.one();
- return getDSHandle().doesRowSatisfyCondition(row, conditions);
- }
- }
-
-
- public static MusicLockingService getLockingServiceHandle() throws MusicLockingException {
- logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring lock store handle");
- long start = System.currentTimeMillis();
-
- if (mLockHandle == null) {
- try {
- mLockHandle = new MusicLockingService();
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKHANDLE,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- throw new MusicLockingException("Failed to aquire Locl store handle " + e);
- }
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to acquire lock store handle:" + (end - start) + " ms");
- return mLockHandle;
- }
-
- /**
- *
- * @param remoteIp
- * @return
- */
- public static MusicDataStore getDSHandle(String remoteIp) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
- long start = System.currentTimeMillis();
- if (mDstoreHandle == null) {
- try {
- MusicUtil.loadProperties();
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "No properties file defined. Falling back to default.");
- }
- mDstoreHandle = new MusicDataStore(remoteIp);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
- return mDstoreHandle;
- }
-
- /**
- *
- * @return
- * @throws MusicServiceException
- */
- public static MusicDataStore getDSHandle() throws MusicServiceException {
- logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
- long start = System.currentTimeMillis();
- if (mDstoreHandle == null) {
- try {
- MusicUtil.loadProperties();
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "No properties file defined. Falling back to default.");
- }
- // Quick Fix - Best to put this into every call to getDSHandle?
- if (! MusicUtil.getMyCassaHost().equals("localhost") ) {
- mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
- } else {
- mDstoreHandle = new MusicDataStore();
- }
- }
- if(mDstoreHandle.getSession() == null) {
- String message = "Connection to Cassandra has not been enstablished."
- + " Please check connection properites and reboot.";
- logger.info(EELFLoggerDelegate.applicationLogger, message);
- throw new MusicServiceException(message);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
- return mDstoreHandle;
- }
-
- public static String createLockReference(String lockName) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Creating lock reference for lock name:" + lockName);
- long start = System.currentTimeMillis();
- String lockId = null;
- try {
- lockId = getLockingServiceHandle().createLockId("/" + lockName);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.CREATELOCK+lockName,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
-
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to create lock reference:" + (end - start) + " ms");
- return lockId;
- }
-
- /**
- *
- * @param key
- * @return
- */
- public static boolean isTableOrKeySpaceLock(String key) {
- String[] splitString = key.split("\\.");
- if (splitString.length > 2)
- return false;
- else
- return true;
- }
-
- /**
- *
- * @param key
- * @return
- */
- public static MusicLockState getMusicLockState(String key) {
- long start = System.currentTimeMillis();
- try {
- String[] splitString = key.split("\\.");
- String keyspaceName = splitString[0];
- String tableName = splitString[1];
- String primaryKey = splitString[2];
- MusicLockState mls;
- String lockName = keyspaceName + "." + tableName + "." + primaryKey;
- mls = getLockingServiceHandle().getLockState(lockName);
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to get lock state:" + (end - start) + " ms");
- return mls;
- } catch (NullPointerException | MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- return null;
- }
-
- public static ReturnType acquireLockWithLease(String key, String lockId, long leasePeriod) {
- try {
- long start = System.currentTimeMillis();
- /* check if the current lock has exceeded its lease and if yes, release that lock */
- MusicLockState mls = getMusicLockState(key);
- if (mls != null) {
- if (mls.getLockStatus().equals(LockStatus.LOCKED)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"The current lock holder for " + key + " is " + mls.getLockHolder()
- + ". Checking if it has exceeded lease");
- long currentLockPeriod = System.currentTimeMillis() - mls.getLeaseStartTime();
- long currentLeasePeriod = mls.getLeasePeriod();
- if (currentLockPeriod > currentLeasePeriod) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Lock period " + currentLockPeriod
- + " has exceeded lease period " + currentLeasePeriod);
- boolean voluntaryRelease = false;
- String currentLockHolder = mls.getLockHolder();
- mls = releaseLock(currentLockHolder, voluntaryRelease);
- }
- }
- } else
- logger.error(EELFLoggerDelegate.errorLogger,key, AppMessages.INVALIDLOCK,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
-
- /*
- * call the traditional acquire lock now and if the result returned is true, set the
- * begin time-stamp and lease period
- */
- if (acquireLock(key, lockId).getResult() == ResultType.SUCCESS) {
- mls = getMusicLockState(key);// get latest state
- if ( mls == null ) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Music Lock State is null");
- return new ReturnType(ResultType.FAILURE, "Could not acquire lock, Lock State is null");
- }
- if (mls.getLeaseStartTime() == -1) {// set it again only if it is not set already
- mls.setLeaseStartTime(System.currentTimeMillis());
- mls.setLeasePeriod(leasePeriod);
- getLockingServiceHandle().setLockState(key, mls);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to acquire leased lock:" + (end - start) + " ms");
- return new ReturnType(ResultType.SUCCESS, "Accquired lock");
- } else {
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to fail to acquire leased lock:" + (end - start) + " ms");
- return new ReturnType(ResultType.FAILURE, "Could not acquire lock");
- }
- } catch (Exception e) {
- StringWriter sw = new StringWriter();
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR506E] Failed to aquire lock ",ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
-
- String exceptionAsString = sw.toString();
- return new ReturnType(ResultType.FAILURE,
- "Exception thrown in acquireLockWithLease:\n" + exceptionAsString);
- }
- }
-
- public static ReturnType acquireLock(String key, String lockId) throws MusicLockingException {
- /*
- * first check if I am on top. Since ids are not reusable there is no need to check
- * lockStatus If the status is unlocked, then the above call will automatically return
- * false.
- */
- Boolean result = false;
- try {
- result = getLockingServiceHandle().isMyTurn(lockId);
- } catch (MusicLockingException e2) {
- logger.error(EELFLoggerDelegate.errorLogger,AppMessages.INVALIDLOCK + lockId + " " + e2);
- throw new MusicLockingException();
- }
- if (!result) {
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Not your turn, someone else has the lock");
- try {
- if (!getLockingServiceHandle().lockIdExists(lockId)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "In acquire lock: this lockId doesn't exist");
- return new ReturnType(ResultType.FAILURE, "Lockid doesn't exist");
- }
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK+lockId,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- throw new MusicLockingException();
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: returning failure");
- return new ReturnType(ResultType.FAILURE, "Not your turn, someone else has the lock");
- }
-
-
- // this is for backward compatibility where locks could also be acquired on just
- // keyspaces or tables.
- if (isTableOrKeySpaceLock(key)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: A table or keyspace lock so no need to perform sync...so returning true");
- return new ReturnType(ResultType.SUCCESS, "A table or keyspace lock so no need to perform sync...so returning true");
- }
-
- // read the lock name corresponding to the key and if the status is locked or being locked,
- // then return false
- MusicLockState currentMls = null;
- MusicLockState newMls = null;
- try {
- currentMls = getMusicLockState(key);
- String currentLockHolder = currentMls.getLockHolder();
- if (lockId.equals(currentLockHolder)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: You already have the lock!");
- return new ReturnType(ResultType.SUCCESS, "You already have the lock!");
- }
- } catch (NullPointerException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK+lockId,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
-
- // change status to "being locked". This state transition is necessary to ensure syncing
- // before granting the lock
- String lockHolder = null;
- boolean needToSyncQuorum = false;
- if (currentMls != null)
- needToSyncQuorum = currentMls.isNeedToSyncQuorum();
-
-
- newMls = new MusicLockState(MusicLockState.LockStatus.BEING_LOCKED, lockHolder,
- needToSyncQuorum);
- try {
- getLockingServiceHandle().setLockState(key, newMls);
- } catch (MusicLockingException e1) {
- logger.error(EELFLoggerDelegate.errorLogger,e1.getMessage(), AppMessages.LOCKSTATE+key,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Set lock state to being_locked");
-
- // do syncing if this was a forced lock release
- if (needToSyncQuorum) {
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Since there was a forcible release, need to sync quorum!");
- try {
- syncQuorum(key);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to set Lock state " + e);
- }
- }
-
- // change status to locked
- lockHolder = lockId;
- needToSyncQuorum = false;
- newMls = new MusicLockState(MusicLockState.LockStatus.LOCKED, lockHolder, needToSyncQuorum);
- try {
- getLockingServiceHandle().setLockState(key, newMls);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKSTATE+key,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Set lock state to locked and assigned current lock ref "
- + lockId + " as holder");
-
- return new ReturnType(result?ResultType.SUCCESS:ResultType.FAILURE, "Set lock state to locked and assigned a lock holder");
- }
-
-
-
- /**
- *
- * @param keyspaceName
- * @param kspObject
- * @return
- * @throws Exception
- */
- public boolean createKeyspace(String keyspaceName, JsonKeySpace kspObject) throws Exception {
- return true;
- }
-
-
- private static void syncQuorum(String key) throws Exception {
- logger.info(EELFLoggerDelegate.applicationLogger,"Performing sync operation---");
- String[] splitString = key.split("\\.");
- String keyspaceName = splitString[0];
- String tableName = splitString[1];
- String primaryKeyValue = splitString[2];
- PreparedQueryObject selectQuery = new PreparedQueryObject();
- PreparedQueryObject updateQuery = new PreparedQueryObject();
-
- // get the primary key d
- TableMetadata tableInfo = returnColumnMetadata(keyspaceName, tableName);
- String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();// we only support single
- // primary key
- DataType primaryKeyType = tableInfo.getPrimaryKey().get(0).getType();
- Object cqlFormattedPrimaryKeyValue =
- MusicUtil.convertToActualDataType(primaryKeyType, primaryKeyValue);
-
- // get the row of data from a quorum
- selectQuery.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName + " WHERE "
- + primaryKeyName + "= ?" + ";");
- selectQuery.addValue(cqlFormattedPrimaryKeyValue);
- ResultSet results = null;
- try {
- results = getDSHandle().executeCriticalGet(selectQuery);
- // write it back to a quorum
- Row row = results.one();
- ColumnDefinitions colInfo = row.getColumnDefinitions();
- int totalColumns = colInfo.size();
- int counter = 1;
- StringBuilder fieldValueString = new StringBuilder("");
- for (Definition definition : colInfo) {
- String colName = definition.getName();
- if (colName.equals(primaryKeyName))
- continue;
- DataType colType = definition.getType();
- Object valueObj = getDSHandle().getColValue(row, colName, colType);
- Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- fieldValueString.append(colName + " = ?");
- updateQuery.addValue(valueString);
- if (counter != (totalColumns - 1))
- fieldValueString.append(",");
- counter = counter + 1;
- }
- updateQuery.appendQueryString("UPDATE " + keyspaceName + "." + tableName + " SET "
- + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
- updateQuery.addValue(cqlFormattedPrimaryKeyValue);
-
- getDSHandle().executePut(updateQuery, "critical");
- } catch (MusicServiceException | MusicQueryException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery ,ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR);
- }
- }
-
-
-
-
- /**
- *
- * @param query
- * @return ResultSet
- */
- public static ResultSet quorumGet(PreparedQueryObject query) {
- ResultSet results = null;
- try {
- results = getDSHandle().executeCriticalGet(query);
- } catch (MusicServiceException | MusicQueryException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.MAJOR, ErrorTypes.GENERALSERVICEERROR);
-
- }
- return results;
-
- }
-
- /**
- *
- * @param results
- * @return
- * @throws MusicServiceException
- */
- public static Map<String, HashMap<String, Object>> marshallResults(ResultSet results) throws MusicServiceException {
- return getDSHandle().marshalData(results);
- }
-
- /**
- *
- * @param lockName
- * @return
- */
- public static String whoseTurnIsIt(String lockName) {
-
- try {
- return getLockingServiceHandle().whoseTurnIsIt("/" + lockName) + "";
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKINGERROR+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- return null;
-
-
- }
-
- /**
- *
- * @param lockId
- * @return
- */
- public static String getLockNameFromId(String lockId) {
- StringTokenizer st = new StringTokenizer(lockId);
- return st.nextToken("$");
- }
-
- public static void destroyLockRef(String lockId) {
- long start = System.currentTimeMillis();
- try {
- getLockingServiceHandle().unlockAndDeleteId(lockId);
- } catch (MusicLockingException | NoNodeException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DESTROYLOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to destroy lock reference:" + (end - start) + " ms");
- }
-
- public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) {
- long start = System.currentTimeMillis();
- try {
- getLockingServiceHandle().unlockAndDeleteId(lockId);
- } catch (MusicLockingException e1) {
- logger.error(EELFLoggerDelegate.errorLogger,e1.getMessage(), AppMessages.RELEASELOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- } catch (KeeperException.NoNodeException nne) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to release Lock " + lockId + " " + nne);
- MusicLockState mls = new MusicLockState("Lock doesn't exists. Release lock operation failed.");
- return mls;
- }
- String lockName = getLockNameFromId(lockId);
- MusicLockState mls;
- String lockHolder = null;
- if (voluntaryRelease) {
- mls = new MusicLockState(MusicLockState.LockStatus.UNLOCKED, lockHolder);
- logger.info(EELFLoggerDelegate.applicationLogger,"In unlock: lock voluntarily released for " + lockId);
- } else {
- boolean needToSyncQuorum = true;
- mls = new MusicLockState(MusicLockState.LockStatus.UNLOCKED, lockHolder,
- needToSyncQuorum);
- logger.info(EELFLoggerDelegate.applicationLogger,"In unlock: lock forcibly released for " + lockId);
- }
- try {
- getLockingServiceHandle().setLockState(lockName, mls);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.RELEASELOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to release lock:" + (end - start) + " ms");
- return mls;
- }
-
- public static void voluntaryReleaseLock(String lockId) throws MusicLockingException{
- try {
- getLockingServiceHandle().unlockAndDeleteId(lockId);
- } catch (KeeperException.NoNodeException e) {
- // ??? No way
- }
- }
-
- /**
- *
- * @param lockName
- * @throws MusicLockingException
- */
- public static void deleteLock(String lockName) throws MusicLockingException {
- long start = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Deleting lock for " + lockName);
- try {
- getLockingServiceHandle().deleteLock("/" + lockName);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DELTELOCK+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- throw new MusicLockingException(e.getMessage());
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to delete lock:" + (end - start) + " ms");
- }
-
-
-
- /**
- *
- * @param keyspace
- * @param tablename
- * @return
- * @throws MusicServiceException
- */
- public static TableMetadata returnColumnMetadata(String keyspace, String tablename) throws MusicServiceException {
- return getDSHandle().returnColumnMetadata(keyspace, tablename);
- }
-
-
- /**
- *
- * @param nodeName
- */
- public static void pureZkCreate(String nodeName) {
- try {
- getLockingServiceHandle().getzkLockHandle().createNode(nodeName);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- }
-
- /**
- *
- * @param nodeName
- * @param data
- */
- public static void pureZkWrite(String nodeName, byte[] data) {
- long start = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Performing zookeeper write to " + nodeName);
- try {
- getLockingServiceHandle().getzkLockHandle().setNodeData(nodeName, data);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"Performed zookeeper write to " + nodeName);
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the actual zk put:" + (end - start) + " ms");
- }
-
- /**
- *
- * @param nodeName
- * @return
- */
- public static byte[] pureZkRead(String nodeName) {
- long start = System.currentTimeMillis();
- byte[] data = null;
- try {
- data = getLockingServiceHandle().getzkLockHandle().getNodeData(nodeName);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the actual zk put:" + (end - start) + " ms");
- return data;
- }
-
-
-
- // Prepared Query Additions.
-
- /**
- *
- * @param keyspaceName
- * @param tableName
- * @param primaryKey
- * @param queryObject
- * @return ReturnType
- * @throws MusicServiceException
- */
- public static ReturnType eventualPut(PreparedQueryObject queryObject) {
- boolean result = false;
- try {
- result = getDSHandle().executePut(queryObject, MusicUtil.EVENTUAL);
- } catch (MusicServiceException | MusicQueryException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage() + " " + ex.getCause() + " " + ex);
- return new ReturnType(ResultType.FAILURE, ex.getMessage());
- }
- if (result) {
- return new ReturnType(ResultType.SUCCESS, "Success");
- } else {
- return new ReturnType(ResultType.FAILURE, "Failure");
- }
- }
-
- /**
- *
- * @param keyspaceName
- * @param tableName
- * @param primaryKey
- * @param queryObject
- * @param lockId
- * @return
- */
- public static ReturnType criticalPut(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject, String lockId, Condition conditionInfo) {
- long start = System.currentTimeMillis();
-
- try {
- MusicLockState mls = getLockingServiceHandle()
- .getLockState(keyspaceName + "." + tableName + "." + primaryKey);
- if (mls.getLockHolder().equals(lockId) == true) {
- if (conditionInfo != null)
- try {
- if (conditionInfo.testCondition() == false)
- return new ReturnType(ResultType.FAILURE,
- "Lock acquired but the condition is not true");
- } catch (Exception e) {
- return new ReturnType(ResultType.FAILURE,
- "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
- + e.getMessage());
- }
- getDSHandle().executePut(queryObject, MusicUtil.CRITICAL);
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the critical put:" + (end - start) + " ms");
- return new ReturnType(ResultType.SUCCESS, "Update performed");
- } else
- return new ReturnType(ResultType.FAILURE,
- "Cannot perform operation since you are the not the lock holder");
- } catch (MusicQueryException | MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
- return new ReturnType(ResultType.FAILURE,
- "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
- + e.getMessage());
- }catch(MusicLockingException ex){
- return new ReturnType(ResultType.FAILURE,ex.getMessage());
- }
-
- }
-
- /**
- *
- * @param queryObject
- * @param consistency
- * @return Boolean Indicates success or failure
- * @throws MusicServiceException
- *
- *
- */
- public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency) throws MusicServiceException {
- // this is mainly for some functions like keyspace creation etc which does not
- // really need the bells and whistles of Music locking.
- boolean result = false;
- try {
- result = getDSHandle().executePut(queryObject, consistency);
- } catch (MusicQueryException | MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- throw new MusicServiceException(ex.getMessage());
- }
- return result?ResultType.SUCCESS:ResultType.FAILURE;
- }
-
- /**
- * This method performs DDL operation on cassandra.
- *
- * @param queryObject query object containing prepared query and values
- * @return ResultSet
- * @throws MusicServiceException
- */
- public static ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException {
- ResultSet results = null;
- try {
- results = getDSHandle().executeEventualGet(queryObject);
- } catch (MusicQueryException | MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
- throw new MusicServiceException(e.getMessage());
- }
- return results;
- }
-
- /**
- * This method performs DDL operations on cassandra, if the the resource is available. Lock ID
- * is used to check if the resource is free.
- *
- * @param keyspaceName name of the keyspace
- * @param tableName name of the table
- * @param primaryKey primary key value
- * @param queryObject query object containing prepared query and values
- * @param lockId lock ID to check if the resource is free to perform the operation.
- * @return ResultSet
- */
- public static ResultSet criticalGet(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject, String lockId) throws MusicServiceException {
- ResultSet results = null;
- try {
- MusicLockState mls = getLockingServiceHandle()
- .getLockState(keyspaceName + "." + tableName + "." + primaryKey);
- if (mls.getLockHolder().equals(lockId)) {
- results = getDSHandle().executeCriticalGet(queryObject);
- } else
- throw new MusicServiceException("YOU DO NOT HAVE THE LOCK");
- } catch (MusicQueryException | MusicServiceException | MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- }
- return results;
- }
-
- /**
- * This method performs DML operation on cassandra, when the lock of the dd is acquired.
- *
- * @param keyspaceName name of the keyspace
- * @param tableName name of the table
- * @param primaryKey primary key value
- * @param queryObject query object containing prepared query and values
- * @return ReturnType
- * @throws MusicLockingException
- */
- public static ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
-
- long start = System.currentTimeMillis();
- String key = keyspaceName + "." + tableName + "." + primaryKey;
- String lockId = createLockReference(key);
- long lockCreationTime = System.currentTimeMillis();
- ReturnType lockAcqResult = acquireLock(key, lockId);
- long lockAcqTime = System.currentTimeMillis();
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
- ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
- queryObject, lockId, conditionInfo);
- long criticalPutTime = System.currentTimeMillis();
- voluntaryReleaseLock(lockId);
- long lockDeleteTime = System.currentTimeMillis();
- String timingInfo = "|lock creation time:" + (lockCreationTime - start)
- + "|lock accquire time:" + (lockAcqTime - lockCreationTime)
- + "|critical put time:" + (criticalPutTime - lockAcqTime)
- + "|lock delete time:" + (lockDeleteTime - criticalPutTime) + "|";
- criticalPutResult.setTimingInfo(timingInfo);
- return criticalPutResult;
- } else {
- logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
- destroyLockRef(lockId);
- return lockAcqResult;
- }
- }
-
- /**
- * this function is mainly for the benchmarks to see the effect of lock deletion.
- *
- * @param keyspaceName
- * @param tableName
- * @param primaryKey
- * @param queryObject
- * @param conditionInfo
- * @return
- * @throws MusicLockingException
- */
- public static ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName,
- String primaryKey, PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
-
- long start = System.currentTimeMillis();
- String key = keyspaceName + "." + tableName + "." + primaryKey;
- String lockId = createLockReference(key);
- long lockCreationTime = System.currentTimeMillis();
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = acquireLock(key, lockId);
- long lockAcqTime = System.currentTimeMillis();
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
- ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
- queryObject, lockId, conditionInfo);
- long criticalPutTime = System.currentTimeMillis();
- deleteLock(key);
- long lockDeleteTime = System.currentTimeMillis();
- String timingInfo = "|lock creation time:" + (lockCreationTime - start)
- + "|lock accquire time:" + (lockAcqTime - lockCreationTime)
- + "|critical put time:" + (criticalPutTime - lockAcqTime)
- + "|lock delete time:" + (lockDeleteTime - criticalPutTime) + "|";
- criticalPutResult.setTimingInfo(timingInfo);
- return criticalPutResult;
- } else {
- logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
- deleteLock(key);
- return lockAcqResult;
- }
- }
-
-
-
-
- /**
- * This method performs DDL operation on cassasndra, when the lock for the resource is acquired.
- *
- * @param keyspaceName name of the keyspace
- * @param tableName name of the table
- * @param primaryKey primary key value
- * @param queryObject query object containing prepared query and values
- * @return ResultSet
- * @throws MusicServiceException
- * @throws MusicLockingException
- */
- public static ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
- String key = keyspaceName + "." + tableName + "." + primaryKey;
- String lockId = createLockReference(key);
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = acquireLock(key, lockId);
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
- ResultSet result =
- criticalGet(keyspaceName, tableName, primaryKey, queryObject, lockId);
- voluntaryReleaseLock(lockId);
- return result;
- } else {
- destroyLockRef(lockId);
- logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
- return null;
- }
- }
-
- public static ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
- String key = keyspaceName + "." + tableName + "." + primaryKey;
- String lockId = createLockReference(key);
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
-
- ReturnType lockAcqResult = acquireLock(key, lockId);
-
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "acquired lock with id " + lockId);
- ResultSet result = criticalGet(keyspaceName, tableName, primaryKey, queryObject, lockId);
- deleteLock(key);
- return result;
- } else {
- deleteLock(key);
- logger.info(EELFLoggerDelegate.applicationLogger, "unable to acquire lock, id " + lockId);
- return null;
- }
- }
-
-
-
- /**
- * authenticate user logic
- *
- * @param nameSpace
- * @param userId
- * @param password
- * @param keyspace
- * @param aid
- * @param operation
- * @return
- * @throws Exception
- */
- public static Map<String, Object> autheticateUser(String nameSpace, String userId,
- String password, String keyspace, String aid, String operation)
- throws Exception {
- Map<String, Object> resultMap = new HashMap<>();
- String uuid = null;
- resultMap = CachingUtil.validateRequest(nameSpace, userId, password, keyspace, aid,
- operation);
- if (!resultMap.isEmpty())
- return resultMap;
- 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.");
- return resultMap;
- }
- boolean isAAF = Boolean.valueOf(isAAFApp);
- if (userId == null || password == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- logger.error(EELFLoggerDelegate.errorLogger,"One or more required headers is missing. userId: " + userId
- + " :: password: " + password);
- resultMap.put("Exception",
- "UserId and Password are mandatory for the operation " + operation);
- return resultMap;
- }
- if(!isAAF && !(operation.equals("createKeySpace"))) {
- resultMap = CachingUtil.authenticateAIDUser(nameSpace, userId, password, keyspace);
- if (!resultMap.isEmpty())
- return resultMap;
-
- }
- if (isAAF && nameSpace != null && userId != null && password != null) {
- boolean isValid = true;
- try {
- isValid = CachingUtil.authenticateAAFUser(nameSpace, userId, password, keyspace);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- logger.error(EELFLoggerDelegate.errorLogger,"Got exception while AAF authentication for namespace " + nameSpace);
- resultMap.put("Exception", e.getMessage());
- }
- if (!isValid) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- resultMap.put("Exception", "User not authenticated...");
- }
- if (!resultMap.isEmpty())
- return resultMap;
-
- }
-
- if (operation.equals("createKeySpace")) {
- logger.info(EELFLoggerDelegate.applicationLogger,"AID is not provided. Creating new UUID for keyspace.");
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "select uuid from admin.keyspace_master where application_name=? and username=? and keyspace_name=? allow filtering");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), nameSpace));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
-
- try {
- Row rs = MusicCore.get(pQuery).one();
- uuid = rs.getUUID("uuid").toString();
- resultMap.put("uuid", "existing");
- } catch (Exception e) {
- logger.info(EELFLoggerDelegate.applicationLogger,"No UUID found in DB. So creating new UUID.");
- uuid = CachingUtil.generateUUID();
- resultMap.put("uuid", "new");
- }
- resultMap.put("aid", uuid);
- }
-
- return resultMap;
- }
-
- /**
- * @param lockName
- * @return
- */
- public static Map<String, Object> validateLock(String lockName) {
- Map<String, Object> resultMap = new HashMap<>();
- String[] locks = lockName.split("\\.");
- if(locks.length < 3) {
- resultMap.put("Exception", "Invalid lock. Please make sure lock is of the type keyspaceName.tableName.primaryKey");
- return resultMap;
- }
- String keyspace= locks[0];
- if(keyspace.startsWith("$"))
- keyspace = keyspace.substring(1);
- resultMap.put("keyspace",keyspace);
- return resultMap;
- }
-}
diff --git a/jar/src/main/java/org/onap/music/main/MusicDigest.java b/jar/src/main/java/org/onap/music/main/MusicDigest.java
deleted file mode 100644
index 893cb51f..00000000
--- a/jar/src/main/java/org/onap/music/main/MusicDigest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * ============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.main;
-
-/**
- *
- *
- */
-public class MusicDigest {
- private String evPutStatus;
- private String vectorTs;
-
- /**
- * @param evPutStatus
- * @param vectorTs
- */
- public MusicDigest(String evPutStatus, String vectorTs) {
- this.evPutStatus = evPutStatus;
- this.vectorTs = vectorTs;
- }
-
- /**
- * @return
- */
- public String getEvPutStatus() {
- return evPutStatus;
- }
-
- /**
- * @param evPutStatus
- */
- public void setEvPutStatus(String evPutStatus) {
- this.evPutStatus = evPutStatus;
- }
-
- /**
- * @return
- */
- public String getVectorTs() {
- return vectorTs;
- }
-
- /**
- * @param vectorTs
- */
- public void setVectorTs(String vectorTs) {
- this.vectorTs = vectorTs;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return vectorTs + "|" + evPutStatus;
- }
-}
-
diff --git a/jar/src/main/java/org/onap/music/main/MusicUtil.java b/jar/src/main/java/org/onap/music/main/MusicUtil.java
deleted file mode 100755
index 77afb57e..00000000
--- a/jar/src/main/java/org/onap/music/main/MusicUtil.java
+++ /dev/null
@@ -1,572 +0,0 @@
-/*
- * ============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.main;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.math.BigInteger;
-import java.util.ArrayList;
-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;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-
-/**
- * @author nelson24
- *
- * Properties This will take Properties and load them into MusicUtil.
- * This is a hack for now. Eventually it would bebest to do this in
- * another way.
- *
- */
-public class MusicUtil {
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
-
- public static final String ATOMIC = "atomic";
- 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 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";
-
- 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 boolean debug = true;
- private static String version = "2.3.0";
- 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",
- "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url" };
-
- private static String cassName = "cassandra";
- private static String cassPwd = "cassandra";
- private static String aafEndpointUrl = null;
-
- private MusicUtil() {
- throw new IllegalStateException("Utility Class");
- }
-
-
- /**
- * @return the cassName
- */
- public static String getCassName() {
- return cassName;
- }
-
- /**
- * @return the cassPwd
- */
- public static String getCassPwd() {
- return cassPwd;
- }
-
- /**
- * @return the aafEndpointUrl
- */
- public static String getAafEndpointUrl() {
- return aafEndpointUrl;
- }
-
- /**
- *
- * @param aafEndpointUrl
- */
- public static void setAafEndpointUrl(String aafEndpointUrl) {
- MusicUtil.aafEndpointUrl = aafEndpointUrl;
- }
-
- /**
- *
- * @return
- */
- public static int getMyId() {
- return myId;
- }
-
- /**
- *
- * @param myId
- */
- public static void setMyId(int myId) {
- MusicUtil.myId = myId;
- }
-
- /**
- *
- * @return
- */
- public static List<String> getAllIds() {
- return allIds;
- }
-
- /**
- *
- * @param allIds
- */
- public static void setAllIds(List<String> allIds) {
- MusicUtil.allIds = (ArrayList<String>) allIds;
- }
-
- /**
- *
- * @return
- */
- public static String getPublicIp() {
- return publicIp;
- }
-
- /**
- *
- * @param publicIp
- */
- public static void setPublicIp(String publicIp) {
- MusicUtil.publicIp = publicIp;
- }
-
- /**
- *
- * @return
- */
- public static List<String> getAllPublicIps() {
- return allPublicIps;
- }
-
- /**
- *
- * @param allPublicIps
- */
- public static void setAllPublicIps(List<String> allPublicIps) {
- MusicUtil.allPublicIps = (ArrayList<String>) allPublicIps;
- }
-
- /**
- * Returns An array of property names that should be in the Properties
- * files.
- *
- * @return
- */
- public static String[] getPropkeys() {
- return propKeys;
- }
-
- /**
- * Get MusicRestIp - default = localhost property file value - music.rest.ip
- *
- * @return
- */
- public static String getMusicRestIp() {
- return musicRestIp;
- }
-
- /**
- * Set MusicRestIp
- *
- * @param musicRestIp
- */
- public static void setMusicRestIp(String musicRestIp) {
- MusicUtil.musicRestIp = musicRestIp;
- }
-
- /**
- * Get MusicPropertiesFilePath - Default = /opt/music/music.properties
- * property file value - music.properties
- *
- * @return
- */
- public static String getMusicPropertiesFilePath() {
- return musicPropertiesFilePath;
- }
-
- /**
- * Set MusicPropertiesFilePath
- *
- * @param musicPropertiesFilePath
- */
- public static void setMusicPropertiesFilePath(String musicPropertiesFilePath) {
- MusicUtil.musicPropertiesFilePath = musicPropertiesFilePath;
- }
-
- /**
- * Get DefaultLockLeasePeriod - Default = 6000 property file value -
- * lock.lease.period
- *
- * @return
- */
- public static long getDefaultLockLeasePeriod() {
- return defaultLockLeasePeriod;
- }
-
- /**
- * Set DefaultLockLeasePeriod
- *
- * @param defaultLockLeasePeriod
- */
- public static void setDefaultLockLeasePeriod(long defaultLockLeasePeriod) {
- MusicUtil.defaultLockLeasePeriod = defaultLockLeasePeriod;
- }
-
- /**
- * Set Debug
- *
- * @param debug
- */
- public static void setDebug(boolean debug) {
- MusicUtil.debug = debug;
- }
-
- /**
- * Is Debug - Default = true property file value - debug
- *
- * @return
- */
- public static boolean isDebug() {
- return debug;
- }
-
- /**
- * Set Version
- *
- * @param version
- */
- public static void setVersion(String version) {
- MusicUtil.version = version;
- }
-
- /**
- * Return the version property file value - version
- *
- * @return
- */
- public static String getVersion() {
- return version;
- }
-
- /**
- * Get MyZkHost - Zookeeper Hostname - Default = localhost property file
- * value - zookeeper.host
- *
- * @return
- */
- public static String getMyZkHost() {
- return myZkHost;
- }
-
- /**
- * Set MyZkHost - Zookeeper Hostname
- *
- * @param myZkHost
- */
- public static void setMyZkHost(String myZkHost) {
- MusicUtil.myZkHost = myZkHost;
- }
-
- /**
- * Get MyCassHost - Cassandra Hostname - Default = localhost property file
- * value - cassandra.host
- *
- * @return
- */
- public static String getMyCassaHost() {
- return myCassaHost;
- }
-
- /**
- * Set MyCassHost - Cassandra Hostname
- *
- * @param myCassaHost
- */
- public static void setMyCassaHost(String myCassaHost) {
- MusicUtil.myCassaHost = myCassaHost;
- }
-
- /**
- * Get DefaultMusicIp - Default = localhost property file value - music.ip
- *
- * @return
- */
- public static String getDefaultMusicIp() {
- return defaultMusicIp;
- }
-
- /**
- * Set DefaultMusicIp
- *
- * @param defaultMusicIp
- */
- public static void setDefaultMusicIp(String defaultMusicIp) {
- MusicUtil.defaultMusicIp = defaultMusicIp;
- }
-
- /**
- *
- * @return
- */
- public static String getTestType() {
- String testType = "";
- try {
- Scanner fileScanner = new Scanner(new File(""));
- testType = fileScanner.next();// ignore the my id line
- String batchSize = fileScanner.next();// ignore the my public ip
- // line
- fileScanner.close();
- } catch (FileNotFoundException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
- return testType;
-
- }
-
- /**
- *
- * @param time
- */
- public static void sleep(long time) {
- try {
- Thread.sleep(time);
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- Thread.currentThread().interrupt();
- }
- }
-
- /**
- * Utility function to check if the query object is valid.
- *
- * @param withparams
- * @param queryObject
- * @return
- */
- public static boolean isValidQueryObject(boolean withparams, PreparedQueryObject queryObject) {
- if (withparams) {
- int noOfValues = queryObject.getValues().size();
- int noOfParams = 0;
- char[] temp = queryObject.getQuery().toCharArray();
- for (int i = 0; i < temp.length; i++) {
- if (temp[i] == '?')
- noOfParams++;
- }
- return (noOfValues == noOfParams);
- } else {
- return !queryObject.getQuery().isEmpty();
- }
-
- }
-
- public static void setCassName(String cassName) {
- MusicUtil.cassName = cassName;
- }
-
- public static void setCassPwd(String cassPwd) {
- MusicUtil.cassPwd = cassPwd;
- }
-
- public static String convertToCQLDataType(DataType type, Object valueObj) throws Exception {
-
- String value = "";
- switch (type.getName()) {
- case UUID:
- value = valueObj + "";
- break;
- case TEXT:
- case VARCHAR:
- String valueString = valueObj + "";
- valueString = valueString.replace("'", "''");
- value = "'" + valueString + "'";
- break;
- case MAP: {
- Map<String, Object> otMap = (Map<String, Object>) valueObj;
- value = "{" + jsonMaptoSqlString(otMap, ",") + "}";
- break;
- }
- default:
- value = valueObj + "";
- break;
- }
- return value;
- }
-
- /**
- *
- * @param colType
- * @param valueObj
- * @return
- * @throws MusicTypeConversionException
- * @throws Exception
- */
- public static Object convertToActualDataType(DataType colType, Object valueObj) throws Exception {
- String valueObjString = valueObj + "";
- switch (colType.getName()) {
- case UUID:
- return UUID.fromString(valueObjString);
- case VARINT:
- return BigInteger.valueOf(Long.parseLong(valueObjString));
- case BIGINT:
- return Long.parseLong(valueObjString);
- case INT:
- return Integer.parseInt(valueObjString);
- case FLOAT:
- return Float.parseFloat(valueObjString);
- case DOUBLE:
- return Double.parseDouble(valueObjString);
- case BOOLEAN:
- return Boolean.parseBoolean(valueObjString);
- case MAP:
- return (Map<String, Object>) valueObj;
- default:
- return valueObjString;
- }
- }
-
- /**
- *
- * Utility function to parse json map into sql like string
- *
- * @param jMap
- * @param lineDelimiter
- * @return
- */
-
- public static String jsonMaptoSqlString(Map<String, Object> jMap, String lineDelimiter) throws Exception{
- StringBuilder sqlString = new StringBuilder();
- int counter = 0;
- for (Map.Entry<String, Object> entry : jMap.entrySet()) {
- Object ot = entry.getValue();
- String value = ot + "";
- if (ot instanceof String) {
- value = "'" + value.replace("'", "''") + "'";
- }
- sqlString.append("'" + entry.getKey() + "':" + value);
- if (counter != jMap.size() - 1)
- sqlString.append(lineDelimiter);
- counter = counter + 1;
- }
- 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;
- }
-
-
- public static void loadProperties() throws Exception {
- CipherUtil.readAndSetKeyString();
- Properties prop = new Properties();
- InputStream input = null;
- try {
- // load the properties file
- input = MusicUtil.class.getClassLoader().getResourceAsStream("music.properties");
- prop.load(input);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "Unable to find properties file.");
- throw new Exception();
- } finally {
- if (input != null) {
- try {
- input.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- String cassPwd = prop.getProperty("cassandra.password");
- String isEncrypted = prop.getProperty("cassandra.password.isencrypted");
- logger.info(EELFLoggerDelegate.applicationLogger,"cassandra.password:" + cassPwd);
- logger.info(EELFLoggerDelegate.applicationLogger,"cassandra.password.isencrypted:" + isEncrypted);
- if("true".equals(isEncrypted)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Decrypting....");
- cassPwd = CipherUtil.decryptPKC(cassPwd);
- logger.info(EELFLoggerDelegate.applicationLogger,"Decrypted password: "+cassPwd);
- MusicUtil.setCassPwd(cassPwd);
- } else
- MusicUtil.setCassPwd(cassPwd);
- // get the property value and return it
- MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host"));
- String zkHosts = prop.getProperty("zookeeper.host");
- MusicUtil.setMyZkHost(zkHosts);
- MusicUtil.setCassName(prop.getProperty("cassandra.user"));
- }
-
-
-}
diff --git a/jar/src/main/java/org/onap/music/main/PropertiesListener.java b/jar/src/main/java/org/onap/music/main/PropertiesListener.java
deleted file mode 100755
index afd35387..00000000
--- a/jar/src/main/java/org/onap/music/main/PropertiesListener.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * ============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.main;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Properties;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.annotation.WebListener;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-
-@WebListener
-public class PropertiesListener implements ServletContextListener {
- private Properties prop;
-
- private static EELFLoggerDelegate logger =
- EELFLoggerDelegate.getLogger(PropertiesListener.class);
-
- @Override
- public void contextInitialized(ServletContextEvent servletContextEvent) {
- prop = new Properties();
- Properties projectProp = new Properties();
- URL resource = getClass().getResource("/");
- String musicPropertiesFilePath = resource.getPath().replace("WEB-INF/classes/",
- "WEB-INF/classes/project.properties");
-
- // Open the file
- try {
- InputStream musicProps = null;
- projectProp.load(new FileInputStream(musicPropertiesFilePath));
- if (projectProp.containsKey("music.properties")) {
- musicProps = new FileInputStream(projectProp.getProperty("music.properties"));
- } else {
- musicProps = new FileInputStream(MusicUtil.getMusicPropertiesFilePath());
- }
- prop.load(musicProps);
- musicProps.close();
- prop.putAll(projectProp);
- String[] propKeys = MusicUtil.getPropkeys();
- for (int k = 0; k < propKeys.length; k++) {
- String key = propKeys[k];
- if (prop.containsKey(key) && prop.get(key) != null) {
- logger.info(key + " : " + prop.getProperty(key));
- switch (key) {
- case "zookeeper.host":
- MusicUtil.setMyZkHost(prop.getProperty(key));
- break;
- case "cassandra.host":
- MusicUtil.setMyCassaHost(prop.getProperty(key));
- break;
- case "music.ip":
- MusicUtil.setDefaultMusicIp(prop.getProperty(key));
- break;
- case "debug":
- MusicUtil.setDebug(Boolean
- .getBoolean(prop.getProperty(key).toLowerCase()));
- break;
- case "version":
- MusicUtil.setVersion(prop.getProperty(key));
- break;
- case "music.rest.ip":
- MusicUtil.setMusicRestIp(prop.getProperty(key));
- break;
- case "music.properties":
- MusicUtil.setMusicPropertiesFilePath(prop.getProperty(key));
- break;
- case "lock.lease.period":
- MusicUtil.setDefaultLockLeasePeriod(
- Long.parseLong(prop.getProperty(key)));
- break;
- case "my.id":
- MusicUtil.setMyId(Integer.parseInt(prop.getProperty(key)));
- break;
- case "all.ids":
- String[] ids = prop.getProperty(key).split(":");
- MusicUtil.setAllIds(new ArrayList<String>(Arrays.asList(ids)));
- break;
- case "public.ip":
- MusicUtil.setPublicIp(prop.getProperty(key));
- break;
- case "all.public.ips":
- String[] ips = prop.getProperty(key).split(":");
- if (ips.length == 1) {
- // Future use
- } else if (ips.length > 1) {
- MusicUtil.setAllPublicIps(
- new ArrayList<String>(Arrays.asList(ips)));
- }
- break;
- case "cassandra.user":
- MusicUtil.setCassName(prop.getProperty(key));
- break;
- case "cassandra.password":
- MusicUtil.setCassPwd(prop.getProperty(key));
- break;
- case "aaf.endpoint.url":
- MusicUtil.setAafEndpointUrl(prop.getProperty(key));
- break;
- default:
- logger.error(EELFLoggerDelegate.errorLogger,
- "No case found for " + key);
- }
- }
- }
- } catch (IOException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.IOERROR ,ErrorSeverity.CRITICAL, ErrorTypes.CONNECTIONERROR);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
- }
-
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Starting MUSIC " + MusicUtil.getVersion() + " on node with id "
- + MusicUtil.getMyId() + " and public ip "
- + MusicUtil.getPublicIp() + "...");
- logger.info(EELFLoggerDelegate.applicationLogger,
- "List of all MUSIC ids:" + MusicUtil.getAllIds().toString());
- logger.info(EELFLoggerDelegate.applicationLogger,
- "List of all MUSIC public ips:" + MusicUtil.getAllPublicIps().toString());
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
- prop = null;
- }
-}
diff --git a/jar/src/main/java/org/onap/music/main/ResultType.java b/jar/src/main/java/org/onap/music/main/ResultType.java
deleted file mode 100644
index 61ba0295..00000000
--- a/jar/src/main/java/org/onap/music/main/ResultType.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ============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.main;
-
-public enum ResultType {
- SUCCESS("Success"), FAILURE("Failure"),
- SYNTAXERROR("SyntaxError"), EXCEPTION("Exception"),
- BODYMISSING("Incomplete Request body. Please correct your input request and retry.");
-
- private String result;
-
- ResultType(String result) {
- this.result = result;
- }
-
- public String getResult() {
- return result;
- }
-
-}
-
-
diff --git a/jar/src/main/java/org/onap/music/main/ReturnType.java b/jar/src/main/java/org/onap/music/main/ReturnType.java
deleted file mode 100644
index 1453a1bf..00000000
--- a/jar/src/main/java/org/onap/music/main/ReturnType.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * ============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.main;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class ReturnType {
- private ResultType result;
- private String message;
-
- public ReturnType(ResultType result, String message) {
- super();
- this.result = result;
- this.message = message;
- }
-
- public String getTimingInfo() {
- return timingInfo;
- }
-
- public void setTimingInfo(String timingInfo) {
- this.timingInfo = timingInfo;
- }
-
- private String timingInfo;
-
- public ResultType getResult() {
- return result;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public String toJson() {
- return "{ \"result\":\"" + result.getResult() + "\", \"message\":\"" + message + "\"}";
- }
-
- public String toString() {
- return result + " | " + message;
- }
-
- public Map<String, Object> toMap() {
- Map<String, Object> newMap = new HashMap<>();
- newMap.put("result", result.getResult());
- newMap.put("message", message);
- return newMap;
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java b/jar/src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java
deleted file mode 100644
index a406afce..00000000
--- a/jar/src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * ============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.response.jsonobjects;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
-import org.onap.music.main.ResultType;
-import org.powermock.core.spi.testresult.Result;
-
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.ColumnDefinitions.Definition;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonResponse", description = "General Response JSON")
-public class JsonResponse {
-
- /* Status is required */
- private ResultType status;
-
- /* Standard informational fields */
- private String error;
- private String message;
-
- /* versioning */
- private String musicVersion;
-
- /* Data Fields */
- private Map<String, HashMap<String, Object>> dataResult;
-
- /* Locking fields */
- private String lock;
- private LockStatus lockStatus;
- private String lockHolder;
- private String lockLease;
-
-
- /**
- * Create a JSONLock Response
- * Use setters to provide more information as in
- * JsonLockResponse(ResultType.SUCCESS).setMessage("We did it").setLock(mylockname)
- * @param status
- */
- public JsonResponse(ResultType status) {
- this.status = status;
- }
-
- /**
- *
- * @return
- */
- @ApiModelProperty(value = "Overall status of the response.",
- allowableValues = "Success,Failure")
- public ResultType getStatus() {
- return status;
- }
-
- /**
- *
- * @param status
- */
- public JsonResponse setStatus(ResultType status) {
- this.status = status;
- return this;
- }
-
- /**
- *
- * @return the error
- */
- @ApiModelProperty(value = "Error value")
- public String getError() {
- return error;
- }
-
- /**
- *
- * @param error
- */
- public JsonResponse setError(String error) {
- this.error = error;
- return this;
- }
-
- /**
- *
- * @return the message
- */
- @ApiModelProperty(value = "Message value")
- public String getMessage() {
- return message;
- }
-
- /**
- *
- * @param message
- */
- public JsonResponse setMessage(String message) {
- this.message = message;
- return this;
- }
-
-
- /**
- *
- * @return the music version
- */
- public String getMusicVersion() {
- return this.musicVersion;
- }
-
- /**
- *
- * @param version of music
- * @return
- */
- public JsonResponse setMusicVersion(String version) {
- this.musicVersion = version;
- return this;
- }
-
- public Map<String, HashMap<String, Object>> getDataResult() {
- return this.dataResult;
- }
-
- public JsonResponse setDataResult(Map<String, HashMap<String, Object>> map) {
- this.dataResult = map;
- return this;
- }
-
- /**
- *
- * @return
- */
- public String getLock() {
- return lock;
- }
-
- /**
- *
- * @param lock
- */
- public JsonResponse setLock(String lock) {
- this.lock = lock;
- return this;
- }
-
- /**
- *
- * @return the lockStatus
- */
- @ApiModelProperty(value = "Status of the lock")
- public LockStatus getLockStatus() {
- return lockStatus;
- }
-
- /**
- *
- * @param lockStatus
- */
- public JsonResponse setLockStatus(LockStatus lockStatus) {
- this.lockStatus = lockStatus;
- return this;
- }
-
- /**
- *
- *
- * @return the lockHolder
- */
- @ApiModelProperty(value = "Holder of the Lock")
- public String getLockHolder() {
- return lockHolder;
- }
-
- /**
- *
- * @param lockHolder
- */
- public JsonResponse setLockHolder(String lockHolder) {
- this.lockHolder = lockHolder;
- return this;
- }
-
-
-
- /**
- * @return the lockLease
- */
- public String getLockLease() {
- return lockLease;
- }
-
- /**
- * @param lockLease the lockLease to set
- */
- public JsonResponse setLockLease(String lockLease) {
- this.lockLease = lockLease;
- return this;
- }
-
- /**
- * Convert to Map
- *
- * @return
- */
- public Map<String, Object> toMap() {
- Map<String, Object> fullMap = new HashMap<>();
- fullMap.put("status", status);
- if (error!=null) {fullMap.put("error", error);}
- if (message!=null) {fullMap.put("message", message);}
-
- if (musicVersion!=null) {fullMap.put("version", musicVersion);}
-
- if (dataResult!=null) {
- fullMap.put("result", dataResult);
- }
-
- if (lock!=null) {
- Map<String, Object> lockMap = new HashMap<>();
- if (lock!=null) {lockMap.put("lock", lock);}
- if (lockStatus!=null) {lockMap.put("lock-status", lockStatus);}
- if (lockHolder!=null) {lockMap.put("lock-holder", lockHolder);}
- if (lockLease!=null) {lockMap.put("lock-lease", lockLease);}
- fullMap.put("lock", lockMap);
- }
-
- return fullMap;
- }
-
- /**
- * Convert to String
- */
- @Override
- public String toString() {
- return "JsonLockResponse [status=" + status + ", error=" + error + ", message=" + message
- + ", lock=" + lock + ", lockStatus=" + lockStatus + ", lockHolder="
- + lockHolder + "]";
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java b/jar/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
deleted file mode 100755
index e7c7fb6c..00000000
--- a/jar/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
+++ /dev/null
@@ -1,372 +0,0 @@
-/*
- * ============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.rest;
-
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-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.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.Response.Status;
-
-import org.mindrot.jbcrypt.BCrypt;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-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("/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);
-
- /*
- * API to onboard an application with MUSIC. This is the mandatory first step.
- *
- */
- @POST
- @Path("/onboardAppWithMusic")
- @ApiOperation(value = "Onboard application", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- 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();
- if (appName == null || userId == null || isAAF == null || password == null) {
- 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.");
- return Response.status(Status.UNAUTHORIZED).entity(resultMap).build();
- }
-
- PreparedQueryObject 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.");
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
-
- pQuery = new PreparedQueryObject();
- String uuid = CachingUtil.generateUUID();
- pQuery.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
-
- String returnStr = MusicCore.eventualPut(pQuery).toString();
- if (returnStr.contains("Failure")) {
- resultMap.put("Exception",
- "Oops. Something wrong with onboarding process. Please retry later or contact admin.");
- 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 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 Response getOnboardedInfoSearch(JsonOnboard jsonObj) throws Exception {
- Map<String, Object> resultMap = new HashMap<>();
- 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);
- resultMap.put("Exception",
- "Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.");
- return Response.status(Status.UNAUTHORIZED).entity(resultMap).build();
- }
-
- PreparedQueryObject pQuery = new PreparedQueryObject();
- String cql = "select uuid, keyspace_name from admin.keyspace_master where ";
- if (appName != null)
- 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);
- cql = cql + " allow filtering";
- System.out.println("Get OnboardingInfo CQL: " + cql);
- pQuery.appendQueryString(cql);
- if (appName != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- if (uuid != null)
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- if (isAAF != null)
- 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"));
- }
- if (resultMap.isEmpty()) {
- if (uuid != null) {
- resultMap.put("Exception",
- "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 Response.status(Status.OK).entity(resultMap).build();
- }
-
-
- @DELETE
- @Path("/onboardAppWithMusic")
- @ApiOperation(value = "Delete Onboard application", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response deleteOnboardApp(JsonOnboard jsonObj) throws Exception {
- Map<String, Object> resultMap = new HashMap<>();
- 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);
- resultMap.put("Exception", "Please make sure either appName(ns) or Aid is present");
- 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);
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
-
- }
- 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));
- ResultSet rs = MusicCore.get(pQuery);
- List<Row> rows = rs.all();
- String uuid = null;
- 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);
- 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 = 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 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);
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- }
-
-
- @PUT
- @Path("/onboardAppWithMusic")
- @ApiOperation(value = "Update Onboard application", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response updateOnboardApp(JsonOnboard jsonObj) throws Exception {
- Map<String, Object> resultMap = new HashMap<>();
- ResponseBuilder response =
- Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
- String aid = jsonObj.getAid();
- String appName = jsonObj.getAppname();
- String userId = jsonObj.getUserId();
- String isAAF = jsonObj.getIsAAF();
- String password = jsonObj.getPassword();
- String consistency = "eventual";
- PreparedQueryObject pQuery;
-
- if (aid == null) {
- resultMap.put("Exception", "Please make sure Aid is present");
- 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);
- 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);
- 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(), BCrypt.hashpw(password, BCrypt.gensalt())));
- 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();
- }
-
- return Response.status(Status.OK).entity(resultMap).build();
- }
-}
diff --git a/jar/src/main/java/org/onap/music/rest/RestMusicBmAPI.java b/jar/src/main/java/org/onap/music/rest/RestMusicBmAPI.java
deleted file mode 100644
index 55eb47f2..00000000
--- a/jar/src/main/java/org/onap/music/rest/RestMusicBmAPI.java
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * ============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.rest;
-
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-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.MultivaluedMap;
-import javax.ws.rs.core.UriInfo;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.datastore.PreparedQueryObject;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.TableMetadata;
-import io.swagger.annotations.Api;
-//import io.swagger.annotations.ApiOperation;
-//import io.swagger.annotations.ApiParam;
-
-/*
- * These are functions created purely for benchmarking purposes. Commented out Swagger - This should
- * be undocumented API
- *
- */
-@Path("/v{version: [0-9]+}/benchmarks/")
-@Api(value = "Benchmark API", hidden = true)
-public class RestMusicBmAPI {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicBmAPI.class);
-
- // pure zk calls...
-
- /**
- *
- * @param nodeName
- * @throws Exception
- */
- @POST
- @Path("/purezk/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkCreate(@PathParam("name") String nodeName) throws Exception {
- MusicCore.pureZkCreate("/" + nodeName);
- }
-
-
- /**
- *
- * @param insObj
- * @param nodeName
- * @throws Exception
- */
- @PUT
- @Path("/purezk/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkUpdate(JsonInsert insObj, @PathParam("name") String nodeName)
- throws Exception {
- logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zk normal update-------------------------");
- long start = System.currentTimeMillis();
- MusicCore.pureZkWrite(nodeName, insObj.serialize());
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Total time taken for Zk normal update:" + (end - start) + " ms");
- }
-
- /**
- *
- * @param nodeName
- * @return
- * @throws Exception
- */
- @GET
- @Path("/purezk/{name}")
- @Consumes(MediaType.TEXT_PLAIN)
- public byte[] pureZkGet(@PathParam("name") String nodeName) throws Exception {
- return MusicCore.pureZkRead(nodeName);
- }
-
- /**
- *
- * @param insObj
- * @param lockName
- * @param nodeName
- * @throws Exception
- */
- @PUT
- @Path("/purezk/atomic/{lockname}/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkAtomicPut(JsonInsert updateObj, @PathParam("lockname") String lockname,
- @PathParam("name") String nodeName) throws Exception {
- long startTime = System.currentTimeMillis();
- String operationId = UUID.randomUUID().toString();// just for debugging purposes.
- String consistency = updateObj.getConsistencyInfo().get("type");
-
- logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zookeeper " + consistency + " update-" + operationId
- + "-------------------------");
-
- byte[] data = updateObj.serialize();
- long jsonParseCompletionTime = System.currentTimeMillis();
-
- String lockId = MusicCore.createLockReference(lockname);
-
- long lockCreationTime = System.currentTimeMillis();
-
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = MusicCore.acquireLockWithLease(lockname, lockId, leasePeriod);
- long lockAcqTime = System.currentTimeMillis();
- long zkPutTime = 0, lockReleaseTime = 0;
-
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
- MusicCore.pureZkWrite(lockname, data);
- zkPutTime = System.currentTimeMillis();
- boolean voluntaryRelease = true;
- if (consistency.equals("atomic"))
- MusicCore.releaseLock(lockId, voluntaryRelease);
- else if (consistency.equals("atomic_delete_lock"))
- MusicCore.deleteLock(lockname);
- lockReleaseTime = System.currentTimeMillis();
- } else {
- MusicCore.destroyLockRef(lockId);
- }
-
- long actualUpdateCompletionTime = System.currentTimeMillis();
-
-
- long endTime = System.currentTimeMillis();
-
- String lockingInfo = "|lock creation time:" + (lockCreationTime - jsonParseCompletionTime)
- + "|lock accquire time:" + (lockAcqTime - lockCreationTime)
- + "|zk put time:" + (zkPutTime - lockAcqTime);
-
- if (consistency.equals("atomic"))
- lockingInfo = lockingInfo + "|lock release time:" + (lockReleaseTime - zkPutTime) + "|";
- else if (consistency.equals("atomic_delete_lock"))
- lockingInfo = lockingInfo + "|lock delete time:" + (lockReleaseTime - zkPutTime) + "|";
-
- String timingString = "Time taken in ms for Zookeeper " + consistency + " update-"
- + operationId + ":" + "|total operation time:" + (endTime - startTime)
- + "|json parsing time:" + (jsonParseCompletionTime - startTime)
- + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)
- + lockingInfo;
-
- logger.info(EELFLoggerDelegate.applicationLogger,timingString);
- }
-
- /**
- *
- * @param insObj
- * @param lockName
- * @param nodeName
- * @throws Exception
- */
- @GET
- @Path("/purezk/atomic/{lockname}/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkAtomicGet(JsonInsert insObj, @PathParam("lockname") String lockName,
- @PathParam("name") String nodeName) throws Exception {
- logger.info("--------------Zk atomic read-------------------------");
- long start = System.currentTimeMillis();
- String lockId = MusicCore.createLockReference(lockName);
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = MusicCore.acquireLockWithLease(lockName, lockId, leasePeriod);
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info("acquired lock with id " + lockId);
- MusicCore.pureZkRead(nodeName);
- boolean voluntaryRelease = true;
- MusicCore.releaseLock(lockId, voluntaryRelease);
- } else {
- MusicCore.destroyLockRef(lockId);
- }
-
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Total time taken for Zk atomic read:" + (end - start) + " ms");
- }
-
- /**
- *
- * doing an update directly to cassa but through the rest api
- *
- * @param insObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @PUT
- @Path("/cassa/keyspaces/{keyspace}/tables/{tablename}/rows")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public boolean updateTableCassa(JsonInsert insObj, @PathParam("keyspace") String keyspace,
- @PathParam("tablename") String tablename, @Context UriInfo info)
- throws Exception {
- long startTime = System.currentTimeMillis();
- String operationId = UUID.randomUUID().toString();// just for debugging purposes.
- String consistency = insObj.getConsistencyInfo().get("type");
- logger.info(EELFLoggerDelegate.applicationLogger,"--------------Cassandra " + consistency + " update-" + operationId
- + "-------------------------");
- PreparedQueryObject queryObject = new PreparedQueryObject();
- Map<String, Object> valuesMap = insObj.getValues();
- TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
- String vectorTs = "'" + Thread.currentThread().getId() + System.currentTimeMillis() + "'";
- String fieldValueString = "vector_ts= ? ,";
- queryObject.addValue(vectorTs);
-
- int counter = 0;
- for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
- Object valueObj = entry.getValue();
- DataType colType = tableInfo.getColumn(entry.getKey()).getType();
- Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- fieldValueString = fieldValueString + entry.getKey() + "= ?";
- queryObject.addValue(valueString);
- if (counter != valuesMap.size() - 1)
- fieldValueString = fieldValueString + ",";
- counter = counter + 1;
- }
-
- // get the row specifier
- String rowSpec = "";
- counter = 0;
- queryObject.appendQueryString("UPDATE " + keyspace + "." + tablename + " ");
- MultivaluedMap<String, String> rowParams = info.getQueryParameters();
- String primaryKey = "";
- for (MultivaluedMap.Entry<String, List<String>> entry : rowParams.entrySet()) {
- String keyName = entry.getKey();
- List<String> valueList = entry.getValue();
- String indValue = valueList.get(0);
- DataType colType = tableInfo.getColumn(entry.getKey()).getType();
- Object formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
- primaryKey = primaryKey + indValue;
- rowSpec = rowSpec + keyName + "= ? ";
- queryObject.addValue(formattedValue);
- if (counter != rowParams.size() - 1)
- rowSpec = rowSpec + " AND ";
- counter = counter + 1;
- }
-
-
- String ttl = insObj.getTtl();
- String timestamp = insObj.getTimestamp();
-
- if ((ttl != null) && (timestamp != null)) {
-
- logger.info(EELFLoggerDelegate.applicationLogger,"both there");
- queryObject.appendQueryString(" USING TTL ? AND TIMESTAMP ?");
- queryObject.addValue(Integer.parseInt(ttl));
- queryObject.addValue(Long.parseLong(timestamp));
- }
-
- if ((ttl != null) && (timestamp == null)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"ONLY TTL there");
- queryObject.appendQueryString(" USING TTL ?");
- queryObject.addValue(Integer.parseInt(ttl));
- }
-
- if ((ttl == null) && (timestamp != null)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"ONLY timestamp there");
- queryObject.appendQueryString(" USING TIMESTAMP ?");
- queryObject.addValue(Long.parseLong(timestamp));
- }
- queryObject.appendQueryString(" SET " + fieldValueString + " WHERE " + rowSpec + ";");
-
- long jsonParseCompletionTime = System.currentTimeMillis();
-
- boolean operationResult = true;
- MusicCore.getDSHandle().executePut(queryObject, insObj.getConsistencyInfo().get("type"));
-
- long actualUpdateCompletionTime = System.currentTimeMillis();
-
- long endTime = System.currentTimeMillis();
-
- String timingString = "Time taken in ms for Cassandra " + consistency + " update-"
- + operationId + ":" + "|total operation time:" + (endTime - startTime)
- + "|json parsing time:" + (jsonParseCompletionTime - startTime)
- + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)
- + "|";
- logger.info(EELFLoggerDelegate.applicationLogger,timingString);
-
- return operationResult;
- }
-}
diff --git a/jar/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/jar/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
deleted file mode 100755
index 47d1eae7..00000000
--- a/jar/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
+++ /dev/null
@@ -1,1289 +0,0 @@
-/*
- * ============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.rest;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-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.mindrot.jbcrypt.BCrypt;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.exceptions.MusicLockingException;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.CachingUtil;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicCore.Condition;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.response.jsonobjects.JsonResponse;
-
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.TableMetadata;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-
-/* Version 2 Class */
-//@Path("/v{version: [0-9]+}/keyspaces")
-@Path("/v2/keyspaces")
-@Api(value = "Data Api")
-public class RestMusicDataAPI {
- /*
- * Header values for Versioning X-minorVersion *** - Used to request or communicate a MINOR
- * version back from the client to the server, and from the server back to the client - This
- * will be the MINOR version requested by the client, or the MINOR version of the last MAJOR
- * version (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-minorVersion = "24") - Is optional for the client on
- * request; however, this header should be provided if the client needs to take advantage of
- * MINOR incremented version functionality - Is mandatory for the server on response
- *
- *** X-patchVersion *** - Used only to communicate a PATCH version in a response for
- * troubleshooting purposes only, and will not be provided by the client on request - This will
- * 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 (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 (CURRENTLY NOT USED)
- *
- */
-
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
- 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;
- public StringBuilder rowIdString;
- @SuppressWarnings("unused")
- public PreparedQueryObject queryObject;// the string with all the row
- // identifiers separated by AND
-
- public RowIdentifier(String primaryKeyValue, StringBuilder rowIdString,
- PreparedQueryObject queryObject) {
- this.primarKeyValue = primaryKeyValue;
- this.rowIdString = rowIdString;
- this.queryObject = queryObject;
- }
- }
-
-
- /**
- * Create Keyspace REST
- *
- * @param kspObject
- * @param keyspaceName
- * @return
- * @throws Exception
- */
- @POST
- @Path("/{name}")
- @ApiOperation(value = "Create Keyspace", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- //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,
- JsonKeySpace kspObject,
- @ApiParam(value = "Keyspace Name",required = true) @PathParam("name") String keyspaceName) {
- ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
-
- Map<String, Object> authMap = CachingUtil.verifyOnboarding(ns, userId, password);
- if (!authMap.isEmpty()) {
- 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.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.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.status(Status.UNAUTHORIZED);
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
- }
- }
-
- String consistency = MusicUtil.EVENTUAL;// for now this needs only
- // eventual consistency
-
- PreparedQueryObject queryObject = new PreparedQueryObject();
- long start = System.currentTimeMillis();
- Map<String, Object> replicationInfo = kspObject.getReplicationInfo();
- String repString = null;
- try {
- repString = "{" + MusicUtil.jsonMaptoSqlString(replicationInfo, ",") + "}";
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
-
- }
- queryObject.appendQueryString(
- "CREATE KEYSPACE " + keyspaceName + " WITH replication = " + repString);
- if (kspObject.getDurabilityOfWrites() != null) {
- queryObject.appendQueryString(
- " AND durable_writes = " + kspObject.getDurabilityOfWrites());
- }
-
- queryObject.appendQueryString(";");
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Time taken for setting up query in create keyspace:" + (end - start));
-
- ResultType result = ResultType.FAILURE;
- try {
- result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
- logger.info(EELFLoggerDelegate.applicationLogger, "result = " + result);
- } catch ( MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("err:" + ex.getMessage()).toMap()).build();
- }
-
- try {
- queryObject = new PreparedQueryObject();
- queryObject.appendQueryString("CREATE ROLE IF NOT EXISTS '" + userId
- + "' WITH PASSWORD = '" + password + "' AND LOGIN = true;");
- MusicCore.nonKeyRelatedPut(queryObject, consistency);
- queryObject = new PreparedQueryObject();
- queryObject.appendQueryString("GRANT ALL PERMISSIONS on KEYSPACE " + keyspaceName
- + " to '" + userId + "'");
- queryObject.appendQueryString(";");
- MusicCore.nonKeyRelatedPut(queryObject, consistency);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- }
-
- try {
- boolean isAAF = Boolean.valueOf(CachingUtil.isAAFApplication(ns));
- String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
- queryObject = new PreparedQueryObject();
- queryObject.appendQueryString(
- "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), newAid));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), ns));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- queryObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, ns);
- CachingUtil.updateMusicValidateCache(ns, userId, hashedpwd);
- MusicCore.eventualPut(queryObject);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
- return response.status(Response.Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
-
- return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Keyspace " + keyspaceName + " Created").toMap()).build();
- }
-
- /**
- *
- * @param kspObject
- * @param keyspaceName
- * @return
- * @throws Exception
- */
- @DELETE
- @Path("/{name}")
- @ApiOperation(value = "Delete Keyspace", response = String.class)
- @Produces(MediaType.APPLICATION_JSON)
- //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) throws Exception {
- ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
-
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password,keyspaceName, aid, "dropKeySpace");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- return response.status(Status.UNAUTHORIZED).entity(authMap).build();
- }
-
- String consistency = MusicUtil.EVENTUAL;// for now this needs only
- // eventual
- // consistency
- String appName = CachingUtil.getAppName(keyspaceName);
- String uuid = CachingUtil.getUuidFromMusicCache(keyspaceName);
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "select count(*) as count from admin.keyspace_master where application_name=? allow filtering;");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- Row row = MusicCore.get(pQuery).one();
- long count = row.getLong(0);
-
- if (count == 0) {
- 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(
- "UPDATE admin.keyspace_master SET keyspace_name=? where uuid = ?;");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- MusicCore.nonKeyRelatedPut(pQuery, consistency);
- } else {
- pQuery = new PreparedQueryObject();
- pQuery.appendQueryString("delete from admin.keyspace_master where uuid = ?");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- MusicCore.nonKeyRelatedPut(pQuery, consistency);
- }
-
- PreparedQueryObject queryObject = new PreparedQueryObject();
- queryObject.appendQueryString("DROP KEYSPACE " + keyspaceName + ";");
- 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
- */
- @POST
- @Path("/{keyspace}/tables/{tablename}")
- @ApiOperation(value = "Create Table", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- //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) throws Exception {
- ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "createTable");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- 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
- PreparedQueryObject queryObject = new PreparedQueryObject();
- // first read the information about the table fields
- Map<String, String> fields = tableObj.getFields();
- StringBuilder fieldsString = new StringBuilder("(vector_ts text,");
- int counter = 0;
- String primaryKey;
- 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 + ")");
- } else
- fieldsString.append("" + entry.getKey() + " " + entry.getValue() + "");
- if (counter == fields.size() - 1)
- fieldsString.append(")");
- else
- fieldsString.append(",");
- counter = counter + 1;
- }
- // information about the name-value style properties
- Map<String, Object> propertiesMap = tableObj.getProperties();
- StringBuilder propertiesString = new StringBuilder();
- if (propertiesMap != null) {
- counter = 0;
- for (Map.Entry<String, Object> entry : propertiesMap.entrySet()) {
- Object ot = entry.getValue();
- String value = ot + "";
- if (ot instanceof String) {
- value = "'" + value + "'";
- } else if (ot instanceof Map) {
- @SuppressWarnings("unchecked")
- Map<String, Object> otMap = (Map<String, Object>) ot;
- value = "{" + MusicUtil.jsonMaptoSqlString(otMap, ",") + "}";
- }
-
- propertiesString.append(entry.getKey() + "=" + value + "");
- if (counter != propertiesMap.size() - 1)
- propertiesString.append(" AND ");
-
- counter = counter + 1;
- }
- }
-
- queryObject.appendQueryString(
- "CREATE TABLE " + keyspace + "." + tablename + " " + fieldsString);
-
- if (propertiesMap != null)
- queryObject.appendQueryString(" WITH " + propertiesString);
-
- queryObject.appendQueryString(";");
- ResultType result = ResultType.FAILURE;
-
- try {
- result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
- } catch (MusicServiceException ex) {
- 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();
- }
- 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();
- }
-
- /**
- *
- * @param keyspace
- * @param tablename
- * @param fieldName
- * @param info
- * @throws Exception
- */
- @POST
- @Path("/{keyspace}/tables/{tablename}/index/{field}")
- @ApiOperation(value = "Create Index", response = String.class)
- @Produces(MediaType.APPLICATION_JSON)
- 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) throws Exception {
- ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
-
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,aid, "createIndex");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- 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 = "";
- if (rowParams.getFirst("index_name") != null)
- indexName = rowParams.getFirst("index_name");
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString("Create index " + indexName + " if not exists on " + keyspace + "."
- + tablename + " (" + fieldName + ");");
-
- ResultType result = ResultType.FAILURE;
- try {
- result = MusicCore.nonKeyRelatedPut(query, "eventual");
- } catch (MusicServiceException ex) {
- 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();
- }
- }
-
- /**
- *
- * @param insObj
- * @param keyspace
- * @param tablename
- * @return
- * @throws Exception
- */
- @POST
- @Path("/{keyspace}/tables/{tablename}/rows")
- @ApiOperation(value = "Insert Into Table", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- 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,
- JsonInsert insObj,
- @ApiParam(value = "Keyspace Name",
- required = true) @PathParam("keyspace") String keyspace,
- @ApiParam(value = "Table Name",
- required = true) @PathParam("tablename") String tablename) {
- ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
-
- Map<String, Object> authMap = null;
-
- try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "insertIntoTable");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- 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 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 =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- StringBuilder valueString = new StringBuilder("(" + "?" + ",");
- queryObject.addValue(vectorTs);
- int counter = 0;
- String primaryKey = "";
-
- for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
- fieldsString.append("" + entry.getKey());
- Object valueObj = entry.getValue();
- if (primaryKeyName.equals(entry.getKey())) {
- primaryKey = entry.getValue() + "";
- primaryKey = primaryKey.replace("'", "''");
- }
- DataType colType = null;
- try {
- 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);
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap()).build();
- }
-
- Object formattedValue = null;
- try {
- formattedValue = MusicUtil.convertToActualDataType(colType, valueObj);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
- }
- valueString.append("?");
- queryObject.addValue(formattedValue);
-
- if (counter == valuesMap.size() - 1) {
- fieldsString.append(")");
- valueString.append(")");
- } else {
- fieldsString.append(",");
- valueString.append(",");
- }
- counter = counter + 1;
- }
-
- if(primaryKey == null || primaryKey.length() <= 0) {
- 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 + " "
- + fieldsString + " VALUES " + valueString);
-
- String ttl = insObj.getTtl();
- String timestamp = insObj.getTimestamp();
-
- if ((ttl != null) && (timestamp != null)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "both there");
- queryObject.appendQueryString(" USING TTL ? AND TIMESTAMP ?");
- queryObject.addValue(Integer.parseInt(ttl));
- queryObject.addValue(Long.parseLong(timestamp));
- }
-
- if ((ttl != null) && (timestamp == null)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "ONLY TTL there");
- queryObject.appendQueryString(" USING TTL ?");
- queryObject.addValue(Integer.parseInt(ttl));
- }
-
- if ((ttl == null) && (timestamp != null)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "ONLY timestamp there");
- queryObject.appendQueryString(" USING TIMESTAMP ?");
- queryObject.addValue(Long.parseLong(timestamp));
- }
-
- queryObject.appendQueryString(";");
-
- ReturnType result = null;
- String consistency = insObj.getConsistencyInfo().get("type");
- try {
- if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL)) {
- result = MusicCore.eventualPut(queryObject);
- } else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
- String lockId = insObj.getConsistencyInfo().get("lockId");
- if(lockId == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
- + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- return 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);
- } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
- result = MusicCore.atomicPut(keyspace, tablename, primaryKey, queryObject, null);
-
- }
- else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
- result = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, primaryKey, queryObject, null);
-
- }
- } catch (Exception ex) {
- 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);
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Null result - Please Contact admin").toMap()).build();
- }
- return response.status(Status.OK).entity(new JsonResponse(result.getResult()).setMessage("Insert Successful").toMap()).build();
- }
-
- /**
- *
- * @param insObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @PUT
- @Path("/{keyspace}/tables/{tablename}/rows")
- @ApiOperation(value = "Update Table", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response updateTable(
- @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,
- 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) {
- ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
-
- Map<String, Object> authMap;
- try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
- aid, "updateTable");
- } 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");
- if (!authMap.isEmpty()) {
- 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
- // purposes.
- String consistency = updateObj.getConsistencyInfo().get("type");
- logger.info(EELFLoggerDelegate.applicationLogger, "--------------Music " + consistency
- + " update-" + operationId + "-------------------------");
- // obtain the field value pairs of the update
-
- PreparedQueryObject queryObject = new PreparedQueryObject();
- 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);
- 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);
- 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()).build();
- }
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- StringBuilder fieldValueString = new StringBuilder("vector_ts=?,");
- queryObject.addValue(vectorTs);
- int counter = 0;
- for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
- Object valueObj = entry.getValue();
- DataType colType = null;
- try {
- colType = tableInfo.getColumn(entry.getKey()).getType();
- } catch(NullPointerException ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "Invalid column name : "+entry.getKey());
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap()).build();
- }
- Object valueString = null;
- try {
- valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
- }
- fieldValueString.append(entry.getKey() + "= ?");
- queryObject.addValue(valueString);
- if (counter != valuesMap.size() - 1)
- fieldValueString.append(",");
- counter = counter + 1;
- }
- String ttl = updateObj.getTtl();
- String timestamp = updateObj.getTimestamp();
-
- queryObject.appendQueryString("UPDATE " + keyspace + "." + tablename + " ");
- if ((ttl != null) && (timestamp != null)) {
-
- logger.info("both there");
- queryObject.appendQueryString(" USING TTL ? AND TIMESTAMP ?");
- queryObject.addValue(Integer.parseInt(ttl));
- queryObject.addValue(Long.parseLong(timestamp));
- }
-
- if ((ttl != null) && (timestamp == null)) {
- logger.info("ONLY TTL there");
- queryObject.appendQueryString(" USING TTL ?");
- queryObject.addValue(Integer.parseInt(ttl));
- }
-
- if ((ttl == null) && (timestamp != null)) {
- logger.info("ONLY timestamp there");
- queryObject.appendQueryString(" USING TIMESTAMP ?");
- queryObject.addValue(Long.parseLong(timestamp));
- }
- // get the row specifier
- RowIdentifier rowId = null;
- try {
- rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
- if(rowId == null || rowId.primarKeyValue.isEmpty()) {
- 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);
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
- }
-
- queryObject.appendQueryString(
- " SET " + fieldValueString + " WHERE " + rowId.rowIdString + ";");
-
- // get the conditional, if any
- Condition conditionInfo;
- if (updateObj.getConditions() == null)
- conditionInfo = null;
- else {// to avoid parsing repeatedly, just send the select query to
- // obtain row
- PreparedQueryObject selectQuery = new PreparedQueryObject();
- selectQuery.appendQueryString("SELECT * FROM " + keyspace + "." + tablename + " WHERE "
- + rowId.rowIdString + ";");
- selectQuery.addValue(rowId.primarKeyValue);
- conditionInfo = new MusicCore.Condition(updateObj.getConditions(), selectQuery);
- }
-
- ReturnType operationResult = null;
- long jsonParseCompletionTime = System.currentTimeMillis();
-
- if (consistency.equalsIgnoreCase(MusicUtil.EVENTUAL))
- operationResult = MusicCore.eventualPut(queryObject);
- else if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
- String lockId = updateObj.getConsistencyInfo().get("lockId");
- if(lockId == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
- + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- return 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("atomic_delete_lock")) {
- // this function is mainly for the benchmarks
- try {
- operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
- rowId.primarKeyValue, queryObject, conditionInfo);
- } catch (MusicLockingException 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();
- }
- } 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);
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
- }
- long actualUpdateCompletionTime = System.currentTimeMillis();
-
- long endTime = System.currentTimeMillis();
- String timingString = "Time taken in ms for Music " + consistency + " update-" + operationId
- + ":" + "|total operation time:" + (endTime - startTime)
- + "|json parsing time:" + (jsonParseCompletionTime - startTime)
- + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)
- + "|";
-
- if (operationResult != null && operationResult.getTimingInfo() != null) {
- String lockManagementTime = operationResult.getTimingInfo();
- timingString = timingString + lockManagementTime;
- }
- logger.info(EELFLoggerDelegate.applicationLogger, timingString);
-
- if (operationResult==null) {
- 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();
- }
-
- }
-
- /**
- *
- * @param delObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @DELETE
- @Path("/{keyspace}/tables/{tablename}/rows")
- @ApiOperation(value = "Delete From table", response = String.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response deleteFromTable(
- @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,
- 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) {
- ResponseBuilder response = MusicUtil.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);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- 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);
- 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();
-
- int counter = 0;
- ArrayList<String> columnList = delObj.getColumns();
- if (columnList != null) {
- for (String column : columnList) {
- columnString.append(column);
- if (counter != columnList.size() - 1)
- columnString.append(",");
- counter = counter + 1;
- }
- }
-
- // get the row specifier
- RowIdentifier rowId = null;
- try {
- rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
- } catch (MusicServiceException ex) {
- 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();
-
- if ((columnList != null) && (!rowSpec.isEmpty())) {
- queryObject.appendQueryString("DELETE " + columnString + " FROM " + keyspace + "."
- + tablename + " WHERE " + rowSpec + ";");
- }
-
- if ((columnList == null) && (!rowSpec.isEmpty())) {
- queryObject.appendQueryString("DELETE FROM " + keyspace + "." + tablename + " WHERE "
- + rowSpec + ";");
- }
-
- if ((columnList != null) && (rowSpec.isEmpty())) {
- queryObject.appendQueryString(
- "DELETE " + columnString + " FROM " + keyspace + "." + rowSpec + ";");
- }
- // get the conditional, if any
- Condition conditionInfo;
- if (delObj.getConditions() == null)
- conditionInfo = null;
- else {// to avoid parsing repeatedly, just send the select query to
- // obtain row
- PreparedQueryObject selectQuery = new PreparedQueryObject();
- selectQuery.appendQueryString("SELECT * FROM " + keyspace + "." + tablename + " WHERE "
- + rowId.rowIdString + ";");
- selectQuery.addValue(rowId.primarKeyValue);
- conditionInfo = new MusicCore.Condition(delObj.getConditions(), selectQuery);
- }
-
- String consistency = delObj.getConsistencyInfo().get("type");
-
- 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) {
- logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
- + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- 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);
- }
- } catch (MusicLockingException 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("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();
- }
- }
-
- /**
- *
- * @param tabObj
- * @param keyspace
- * @param tablename
- * @throws Exception
- */
- @DELETE
- @Path("/{keyspace}/tables/{tablename}")
- @ApiOperation(value = "Drop Table", response = String.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Response dropTable(
- @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) throws Exception {
- ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
-
- Map<String, Object> authMap =
- MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "dropTable");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- 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 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);
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
- }
-
- }
-
- /**
- *
- * @param selObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- */
- @PUT
- @Path("/{keyspace}/tables/{tablename}/rows/criticalget")
- @ApiOperation(value = "Select Critical", response = Map.class)
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response selectCritical(
- @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,
- 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) throws Exception {
- ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
-
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,aid, "selectCritical");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"Error while authentication... ", 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 lockId = selObj.getConsistencyInfo().get("lockId");
-
- PreparedQueryObject queryObject = new PreparedQueryObject();
-
- RowIdentifier rowId = null;
- try {
- rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
- } catch (MusicServiceException ex) {
- 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 + ";");
-
- ResultSet results = null;
-
- String consistency = selObj.getConsistencyInfo().get("type");
-
- if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) {
- if(lockId == null) {
- logger.error(EELFLoggerDelegate.errorLogger,"LockId cannot be null. Create lock reference or"
- + " use ATOMIC instead of CRITICAL", ErrorSeverity.FATAL, ErrorTypes.MUSICSERVICEERROR);
- return 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);
- } else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
- results = MusicCore.atomicGet(keyspace, tablename, rowId.primarKeyValue, queryObject);
- }
-
- else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
- results = MusicCore.atomicGetWithDeleteLock(keyspace, tablename, rowId.primarKeyValue, queryObject);
- }
-
- return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap()).build();
- }
-
- /**
- *
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @GET
- @Path("/{keyspace}/tables/{tablename}/rows")
- @ApiOperation(value = "Select All or Select Specific", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Response select(
- @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,
- @Context UriInfo info) throws Exception {
- ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
-
- Map<String, Object> authMap =
- MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "select");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- 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();
-
- if (info.getQueryParameters().isEmpty())// select all
- queryObject.appendQueryString("SELECT * FROM " + keyspace + "." + tablename + ";");
- else {
- int limit = -1; // do not limit the number of results
- try {
- 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);
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
- }
- }
-
- try {
- ResultSet results = MusicCore.get(queryObject);
- 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);
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
- }
-
- }
-
- /**
- *
- * @param keyspace
- * @param tablename
- * @param info
- * @param limit
- * @return
- * @throws MusicServiceException
- */
- public PreparedQueryObject selectSpecificQuery(String version, String minorVersion,
- String patchVersion, String aid, String ns, String userId, String password,
- String keyspace, String tablename, UriInfo info, int limit)
- throws MusicServiceException {
-
- PreparedQueryObject queryObject = new PreparedQueryObject();
- StringBuilder rowIdString = getRowIdentifier(keyspace, tablename, info.getQueryParameters(),
- queryObject).rowIdString;
-
- queryObject.appendQueryString(
- "SELECT * FROM " + keyspace + "." + tablename + " WHERE " + rowIdString);
-
- if (limit != -1) {
- queryObject.appendQueryString(" LIMIT " + limit);
- }
-
- queryObject.appendQueryString(";");
- return queryObject;
-
- }
-
- /**
- *
- * @param keyspace
- * @param tablename
- * @param rowParams
- * @param queryObject
- * @return
- * @throws MusicServiceException
- */
- private RowIdentifier getRowIdentifier(String keyspace, String tablename,
- MultivaluedMap<String, String> rowParams, PreparedQueryObject queryObject)
- throws MusicServiceException {
- StringBuilder rowSpec = new StringBuilder();
- int counter = 0;
- TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
- if (tableInfo == null) {
- logger.error(EELFLoggerDelegate.errorLogger,
- "Table information not found. Please check input for table name= "
- + keyspace + "." + tablename);
- throw new MusicServiceException(
- "Table information not found. Please check input for table name= "
- + keyspace + "." + tablename);
- }
- StringBuilder primaryKey = new StringBuilder();
- for (MultivaluedMap.Entry<String, List<String>> entry : rowParams.entrySet()) {
- String keyName = entry.getKey();
- List<String> valueList = entry.getValue();
- String indValue = valueList.get(0);
- 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());
- }
- primaryKey.append(indValue);
- rowSpec.append(keyName + "= ?");
- queryObject.addValue(formattedValue);
- if (counter != rowParams.size() - 1)
- rowSpec.append(" AND ");
- counter = counter + 1;
- }
- return new RowIdentifier(primaryKey.toString(), rowSpec, queryObject);
- }
-}
diff --git a/jar/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java b/jar/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java
deleted file mode 100644
index 752a538b..00000000
--- a/jar/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * ============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.rest;
-
-import java.util.HashMap;
-/**
- * @author inam
- *
- */
-import java.util.Map;
-
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.GET;
-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.Consumes;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.Response.Status;
-
-
-import org.onap.music.response.jsonobjects.JsonResponse;
-import org.onap.music.eelf.healthcheck.MusicHealthCheck;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-
-
-
-
-@Path("/v{version: [0-9]+}/service")
-@Api(value="Healthcheck Api")
-public class RestMusicHealthCheckAPI {
-
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicUtil.class);
-
-
- @GET
- @Path("/cs")
- @ApiOperation(value = "Get Health Status", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Response cassandraStatus(@Context HttpServletResponse response) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Replying to request for MUSIC Health Check status for Cassandra");
-
- Map<String, Object> resultMap = new HashMap<>();
-
- MusicHealthCheck cassHealthCheck = new MusicHealthCheck();
- String status = cassHealthCheck.getCassandraStatus();
- if(status.equals("ACTIVE")) {
- resultMap.put("ACTIVE", "Cassandra Running and Listening to requests");
- return Response.status(Status.OK).entity(resultMap).build();
- }else {
- resultMap.put("INACTIVE", "Cassandra Service is not responding");
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
-
-
-
- }
-
- @GET
- @Path("/zk")
- @ApiOperation(value = "Get Health Status", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Response ZKStatus(@Context HttpServletResponse response) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Replying to request for MUSIC Health Check status for Zookeeper");
- Map<String, Object> resultMap = new HashMap<>();
- MusicHealthCheck ZKHealthCheck = new MusicHealthCheck();
- String status = ZKHealthCheck.getZookeeperStatus();
- if(status.equals("ACTIVE")) {
- resultMap.put("ACTIVE", "Zookeeper is Active and Running");
- return Response.status(Status.OK).entity(resultMap).build();
- }else {
- resultMap.put("INACTIVE", "Zookeeper is not responding");
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- }
-
-
-
-
-
-
-
-}
diff --git a/jar/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java b/jar/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java
deleted file mode 100644
index 22112ddf..00000000
--- a/jar/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * ============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.rest;
-
-import java.util.Map;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-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.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;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.response.jsonobjects.JsonResponse;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-
-
-@Path("/v2/locks/")
-@Api(value="Lock Api")
-public class RestMusicLocksAPI {
-
- private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicLocksAPI.class);
- private static final String XMINORVERSION = "X-minorVersion";
- private static final String XPATCHVERSION = "X-patchVersion";
- private static final String VERSION = "v2";
-
- /**
- * 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) 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);
- return response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- String keyspaceName = (String) resultMap.get("keyspace");
- resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "createLockReference");
- if (resultMap.containsKey("aid"))
- resultMap.remove("aid");
- if (!resultMap.isEmpty()) {
- 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();
- }
- 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 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) 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);
- return response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- String keyspaceName = (String) resultMap.get("keyspace");
- resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "accquireLock");
- if (resultMap.containsKey("aid"))
- resultMap.remove("aid");
- if (!resultMap.isEmpty()) {
- 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();
- }
- }
-
-
-
-
- @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) 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);
- return response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- String keyspaceName = (String) resultMap.get("keyspace");
- resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "accquireLockWithLease");
-
- if (resultMap.containsKey("aid"))
- resultMap.remove("aid");
- if (!resultMap.isEmpty()) {
- 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);
- }
- 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 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) 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);
- return response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- String keyspaceName = (String) resultMap.get("keyspace");
- resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "currentLockHolder");
- if (resultMap.containsKey("aid"))
- resultMap.remove("aid");
- if (!resultMap.isEmpty()) {
- 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);
- 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 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) 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);
- return response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- String keyspaceName = (String) resultMap.get("keyspace");
- resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "currentLockState");
-
- if (resultMap.containsKey("aid"))
- resultMap.remove("aid");
- if (!resultMap.isEmpty()) {
- 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);
- 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 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) 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);
- return response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- String keyspaceName = (String) resultMap.get("keyspace");
- resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "unLock");
- if (resultMap.containsKey("aid"))
- resultMap.remove("aid");
- if (!resultMap.isEmpty()) {
- 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);
- }
- 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 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) 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);
- return response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- String keyspaceName = (String) resultMap.get("keyspace");
- resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
- "deleteLock");
- if (resultMap.containsKey("aid"))
- resultMap.remove("aid");
- if (!resultMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- return response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- try{
- MusicCore.deleteLock(lockName);
- }catch (Exception e) {
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
- return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).toMap()).build();
- }
-
-}
diff --git a/jar/src/main/java/org/onap/music/rest/RestMusicQAPI.java b/jar/src/main/java/org/onap/music/rest/RestMusicQAPI.java
deleted file mode 100755
index e08adaf7..00000000
--- a/jar/src/main/java/org/onap/music/rest/RestMusicQAPI.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * ============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.rest;
-
-
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-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.UriInfo;
-
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.main.MusicCore;
-
-import org.onap.music.datastore.PreparedQueryObject;
-import com.datastax.driver.core.ResultSet;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-
-//@Path("/v{version: [0-9]+}/priorityq/")
-@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 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/jar/src/main/java/org/onap/music/rest/RestMusicTestAPI.java b/jar/src/main/java/org/onap/music/rest/RestMusicTestAPI.java
deleted file mode 100644
index 287fa176..00000000
--- a/jar/src/main/java/org/onap/music/rest/RestMusicTestAPI.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * ============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.rest;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.main.MusicUtil;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-
-
-@Path("/v{version: [0-9]+}/test")
-@Api(value="Test Api")
-public class RestMusicTestAPI {
-
- @SuppressWarnings("unused")
- private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicTestAPI.class);
-
- /**
- * Returns a test JSON. This will confirm that REST is working.
- * @return
- */
- @GET
- @ApiOperation(value = "Get Test", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String, HashMap<String, String>> simpleTests(
- @Context HttpServletResponse response) {
- response.addHeader("X-latestVersion",MusicUtil.getVersion());
- Map<String, HashMap<String, String>> testMap = new HashMap<>();
- for(int i=0; i < 3; i++){
- HashMap<String, String> innerMap = new HashMap<>();
- innerMap.put(i+"", i+1+"");
- innerMap.put(i+1+"", i+2+"");
- testMap.put(i+"", innerMap);
- }
- return testMap;
- }
-}
diff --git a/jar/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java b/jar/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java
deleted file mode 100644
index a5f2ac49..00000000
--- a/jar/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * ============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.rest;
-
-import java.util.Map;
-
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-
-import org.onap.music.response.jsonobjects.JsonResponse;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-
-
-@Path("/v{version: [0-9]+}/version")
-@Api(value="Version Api")
-public class RestMusicVersionAPI {
-
- private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicVersionAPI.class);
-
- /**
- * Get the version of MUSIC
- * @return
- */
- @GET
- @ApiOperation(value = "Get Version", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Map<String,Object> version(@Context HttpServletResponse response) {
- logger.info("Replying to request for MUSIC version with MUSIC:" + MusicUtil.getVersion());
- response.addHeader("X-latestVersion",MusicUtil.getVersion());
- return new JsonResponse(ResultType.SUCCESS).setMusicVersion("MUSIC:" + MusicUtil.getVersion()).toMap();
- }
-} \ No newline at end of file
diff --git a/jar/src/main/resources/LICENSE.txt b/jar/src/main/resources/LICENSE.txt
deleted file mode 100644
index cc6cdea5..00000000
--- a/jar/src/main/resources/LICENSE.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-
-The following license applies to all files in this and sub-directories. Licenses
-are included in individual source files where appropriate, and if it differs
-from this text, it supersedes this. Any file that does not have license text
-defaults to being covered by this text; not all files support the addition of
-licenses.
-#
-# -------------------------------------------------------------------------
-# 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.
-#
-# -------------------------------------------------------------------------
-# \ No newline at end of file
diff --git a/jar/src/main/resources/Resources.properties b/jar/src/main/resources/Resources.properties
deleted file mode 100644
index 72269cb8..00000000
--- a/jar/src/main/resources/Resources.properties
+++ /dev/null
@@ -1,50 +0,0 @@
-#============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=============================================
-#====================================================================
-#Resource key=Error Code|Message text|Resolution text |Description text
-LOADING_DEFAULT_LOG_CONFIGURATION=\
- EELF0001I|\
- Loading default logging configuration from system resource file "{0}"|\
- No external logging configurations were defined or found, So verify the default logging configuration from system resource file (../logback.xml). |\
- Loading default logging configuration from system resource file
-LOADING_LOG_CONFIGURATION=EELF0002I|\
- Loading logging configuration from file "{0}"|\
- Verify the correct logging configuration file is loaded. |\
- Loading logging configuration for specific file
-LOGGING_ALREADY_INITIALIZED=\
- EELF0003W|\
- Logging has already been initialized, check the container logging definitions to ensure they represent your desired logging configuration.|\
- Verify the container logging definitions to ensure they represent your desired logging configuration. |\
- Logging has already been initialized, check the container logging definitions to ensure they represent your desired logging configuration.
-NO_LOG_CONFIGURATION=\
- EELF0004E|\
- No log configuration could be found or defaulted!|\
- No external and default logging configuration file. |\
- No log configuration could be found or defaulted!
-SEARCHING_LOG_CONFIGURATION=\
- EELF0005I|\
- Searching path "{0}" for log configuration file "{1}"|\
- Verify the correct Path({user.home};etc;../etc) and filename (eelf.logging.file).|\
- Searching path for specific log configuration file.
-UNSUPPORTED_LOGGING_FRAMEWORK=\
- EELF0006E|\
- An unsupported logging framework is bound to SLF4J. |\
- Verify your logging frameworks.|\
- An unsupported logging framework is bound to SLF4J.
-
diff --git a/jar/src/main/resources/cache.ccf b/jar/src/main/resources/cache.ccf
deleted file mode 100644
index acc6831c..00000000
--- a/jar/src/main/resources/cache.ccf
+++ /dev/null
@@ -1,56 +0,0 @@
-# DEFAULT CACHE REGION
-jcs.default=
-jcs.default.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
-jcs.default.cacheattributes.MaxObjects=1000
-jcs.default.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
-jcs.default.cacheattributes.UseMemoryShrinker=false
-jcs.default.cacheattributes.MaxMemoryIdleTime=3600
-jcs.default.cacheattributes.ShrinkerInterval=60
-jcs.default.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
-jcs.default.elementattributes.IsEternal=false
-jcs.default.elementattributes.MaxLife=21600
-jcs.default.elementattributes.IdleTime=1800
-jcs.default.elementattributes.IsSpool=true
-jcs.default.elementattributes.IsRemote=true
-jcs.default.elementattributes.IsLateral=true
-
-# PRE-DEFINED CACHE REGIONS
-jcs.region.musicCache=
-jcs.region.musicCache.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
-jcs.region.musicCache.cacheattributes.MaxObjects=1000
-jcs.region.musicCache.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
-jcs.region.musicCache.cacheattributes.UseMemoryShrinker=false
-jcs.region.musicCache.cacheattributes.MaxMemoryIdleTime=3600
-jcs.region.musicCache.cacheattributes.ShrinkerInterval=60
-jcs.region.musicCache.cacheattributes.MaxSpoolPerRun=500
-jcs.region.musicCache.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
-jcs.region.musicCache.elementattributes.IsEternal=false
-
-
-# PRE-DEFINED CACHE REGIONS
-jcs.region.aafCache=
-jcs.region.aafCache.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
-jcs.region.aafCache.cacheattributes.MaxObjects=1000
-jcs.region.aafCache.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
-jcs.region.aafCache.cacheattributes.UseMemoryShrinker=false
-jcs.region.aafCache.cacheattributes.MaxMemoryIdleTime=3600
-jcs.region.aafCache.cacheattributes.ShrinkerInterval=60
-jcs.region.aafCache.cacheattributes.MaxSpoolPerRun=500
-jcs.region.aafCache.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
-jcs.region.aafCache.elementattributes.IsEternal=false
-
-# PRE-DEFINED CACHE REGIONS
-jcs.region.appNameCache=
-jcs.region.appNameCache.cacheattributes=org.apache.commons.jcs.engine.CompositeCacheAttributes
-jcs.region.appNameCache.cacheattributes.MaxObjects=1000
-jcs.region.appNameCache.cacheattributes.MemoryCacheName=org.apache.commons.jcs.engine.memory.lru.LRUMemoryCache
-jcs.region.appNameCache.cacheattributes.UseMemoryShrinker=false
-jcs.region.appNameCache.cacheattributes.MaxMemoryIdleTime=3600
-jcs.region.appNameCache.cacheattributes.ShrinkerInterval=60
-jcs.region.appNameCache.cacheattributes.MaxSpoolPerRun=500
-jcs.region.appNameCache.elementattributes=org.apache.commons.jcs.engine.ElementAttributes
-jcs.region.appNameCache.elementattributes.IsEternal=false
-
-
-
-
diff --git a/jar/src/main/resources/logback.xml b/jar/src/main/resources/logback.xml
deleted file mode 100644
index fe7f54ae..00000000
--- a/jar/src/main/resources/logback.xml
+++ /dev/null
@@ -1,270 +0,0 @@
-<!--
- ============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=============================================
- ====================================================================
--->
-<configuration scan="true" scanPeriod="3 seconds">
- <!--<jmxConfigurator /> -->
- <!-- directory path for all other type logs -->
- <property name="logDir" value="/opt/app/music/logs" />
-
- <!-- directory path for debugging type logs -->
- <property name="debugDir" value="debug-logs" />
-
- <!-- specify the component name -->
- <!-- <property name="componentName" value="EELF"></property> -->
- <property name="componentName" value="MUSIC"></property>
-
- <!-- log file names -->
- <property name="generalLogName" value="music" />
- <property name="securityLogName" value="security" />
- <property name="errorLogName" value="error" />
- <property name="metricsLogName" value="metrics" />
- <property name="auditLogName" value="audit" />
- <property name="debugLogName" value="debug" />
- <property name="defaultPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" />
- <property name="applicationLoggerPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %msg%n" />
- <property name="auditLoggerPattern" value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}|%X{Unused}|%X{ProcessKey}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}| %msg%n" />
- <property name="metricsLoggerPattern" value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}|%X{Unused}|%X{ProcessKey}|%X{TargetVirtualEntity}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}| %msg%n" />
- <property name="errorLoggerPattern" value= "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %msg%n " />
- <property name="debugLoggerPattern" value="%date{ISO8601,UTC}|%X{RequestId}| %msg%n" ></property>
- <property name="logDirectory" value="${logDir}/${componentName}" />
- <property name="debugLogDirectory" value="${debugDir}/${componentName}" />
- <!-- Example evaluator filter applied against console appender -->
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <!-- <encoder>
- <pattern>${defaultPattern}</pattern>
- </encoder> -->
- <layout class="">
- <pattern>
- %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
- </pattern>
- </layout>
- </appender>
-
- <!-- ============================================================================ -->
- <!-- EELF Appenders -->
- <!-- ============================================================================ -->
- <appender name="EELF"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${logDirectory}/${generalLogName}.log</file>
- <rollingPolicy
- class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${logDirectory}/${generalLogName}.%i.log.zip
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>9</maxIndex>
- </rollingPolicy>
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>5MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${applicationLoggerPattern}</pattern>
- </encoder>
- </appender>
-
- <appender name="asyncEELF" class="ch.qos.logback.classic.AsyncAppender">
- <queueSize>256</queueSize>
- <includeCallerData>true</includeCallerData>
- <appender-ref ref="EELF" />
- </appender>
-
- <!-- EELF Security Appender. This appender is used to record security events
- to the security log file. Security events are separate from other loggers
- in EELF so that security log records can be captured and managed in a secure
- way separate from the other logs. This appender is set to never discard any
- events. -->
- <appender name="EELFSecurity"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${logDirectory}/${securityLogName}.log</file>
- <rollingPolicy
- class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${logDirectory}/${securityLogName}.%i.log.zip
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>9</maxIndex>
- </rollingPolicy>
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>5MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n </pattern>
- </encoder>
- </appender>
-
- <appender name="asyncEELFSecurity" class="ch.qos.logback.classic.AsyncAppender">
- <queueSize>256</queueSize>
- <discardingThreshold>0</discardingThreshold>
- <appender-ref ref="EELFSecurity" />
- </appender>
-
-
-
-
- <!-- EELF Audit Appender. This appender is used to record audit engine
- related logging events. The audit logger and appender are specializations
- of the EELF application root logger and appender. This can be used to segregate
- Policy engine events from other components, or it can be eliminated to record
- these events as part of the application root log. -->
-
- <appender name="EELFAudit"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${logDirectory}/${auditLogName}.log</file>
- <rollingPolicy
- class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${logDirectory}/${auditLogName}.%i.log.zip
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>9</maxIndex>
- </rollingPolicy>
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>5MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${auditLoggerPattern}</pattern>
- </encoder>
- </appender>
- <appender name="asyncEELFAudit" class="ch.qos.logback.classic.AsyncAppender">
- <queueSize>256</queueSize>
- <appender-ref ref="EELFAudit" />
- </appender>
-
-<appender name="EELFMetrics"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${logDirectory}/${metricsLogName}.log</file>
- <rollingPolicy
- class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${logDirectory}/${metricsLogName}.%i.log.zip
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>9</maxIndex>
- </rollingPolicy>
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>5MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <!-- <pattern>"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} -
- %msg%n"</pattern> -->
- <pattern>${metricsLoggerPattern}</pattern>
- </encoder>
- </appender>
-
-
- <appender name="asyncEELFMetrics" class="ch.qos.logback.classic.AsyncAppender">
- <queueSize>256</queueSize>
- <appender-ref ref="EELFMetrics"/>
- </appender>
-
- <appender name="EELFError"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${logDirectory}/${errorLogName}.log</file>
- <rollingPolicy
- class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${logDirectory}/${errorLogName}.%i.log.zip
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>9</maxIndex>
- </rollingPolicy>
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>5MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${errorLoggerPattern}</pattern>
- </encoder>
- </appender>
-
- <appender name="asyncEELFError" class="ch.qos.logback.classic.AsyncAppender">
- <queueSize>256</queueSize>
- <appender-ref ref="EELFError"/>
- </appender>
-
- <appender name="EELFDebug"
- class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${debugLogDirectory}/${debugLogName}.log</file>
- <rollingPolicy
- class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${debugLogDirectory}/${debugLogName}.%i.log.zip
- </fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>9</maxIndex>
- </rollingPolicy>
- <triggeringPolicy
- class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>5MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>${debugLoggerPattern}</pattern>
- </encoder>
- </appender>
-
- <appender name="asyncEELFDebug" class="ch.qos.logback.classic.AsyncAppender">
- <queueSize>256</queueSize>
- <appender-ref ref="EELFDebug" />
- <includeCallerData>true</includeCallerData>
- </appender>
-
-
- <!-- ============================================================================ -->
- <!-- EELF loggers -->
- <!-- ============================================================================ -->
- <logger name="com.att.eelf" level="info" additivity="false">
- <appender-ref ref="asyncEELF" />
-
- </logger>
- <logger name="com.att.eelf.security" level="info" additivity="false">
- <appender-ref ref="asyncEELFSecurity" />
-
- </logger>
-
-
- <logger name="com.att.eelf.audit" level="info" additivity="false">
- <appender-ref ref="asyncEELFAudit" />
-
- </logger>
-
- <logger name="com.att.eelf.metrics" level="info" additivity="false">
- <appender-ref ref="asyncEELFMetrics" />
-
- </logger>
-
-
- <logger name="com.att.eelf.error" level="error" additivity="false">
- <appender-ref ref="asyncEELFError" />
-
- </logger>
-
- <logger name="com.att.eelf.debug" level="debug" additivity="false">
- <appender-ref ref="asyncEELFDebug" />
-
- </logger>
-
-
-
-
- <root level="INFO">
- <appender-ref ref="asyncEELF" />
- <appender-ref ref="STDOUT" />
- </root>
-
-</configuration>
diff --git a/jar/src/main/resources/project.properties b/jar/src/main/resources/project.properties
deleted file mode 100644
index 199afa33..00000000
--- a/jar/src/main/resources/project.properties
+++ /dev/null
@@ -1,4 +0,0 @@
-version=${project.version}
-artifactId=${project.artifactId}
-music.properties=/opt/app/music/etc/music.properties
-
diff --git a/jar/src/test/java/LICENSE.txt b/jar/src/test/java/LICENSE.txt
deleted file mode 100644
index cc6cdea5..00000000
--- a/jar/src/test/java/LICENSE.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-
-The following license applies to all files in this and sub-directories. Licenses
-are included in individual source files where appropriate, and if it differs
-from this text, it supersedes this. Any file that does not have license text
-defaults to being covered by this text; not all files support the addition of
-licenses.
-#
-# -------------------------------------------------------------------------
-# 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.
-#
-# -------------------------------------------------------------------------
-# \ No newline at end of file
diff --git a/jar/src/test/java/org/onap/music/unittests/CassandraCQL.java b/jar/src/test/java/org/onap/music/unittests/CassandraCQL.java
deleted file mode 100644
index a4c250c2..00000000
--- a/jar/src/test/java/org/onap/music/unittests/CassandraCQL.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * ============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.unittests;
-
-/**
- * @author srupane
- *
- */
-
-import java.io.IOException;
-import java.math.BigInteger;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
-import org.apache.cassandra.exceptions.ConfigurationException;
-import org.apache.thrift.transport.TTransportException;
-import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-
-public class CassandraCQL {
-
- public static final String createKeySpace =
- "CREATE KEYSPACE IF NOT EXISTS testCassa WITH replication = "
- +"{'class':'SimpleStrategy','replication_factor':1} AND durable_writes = true;";
-
- public static final String dropKeyspace = "DROP KEYSPACE IF EXISTS testCassa";
-
- public static final String createTableEmployees =
- "CREATE TABLE IF NOT EXISTS testCassa.employees "
- + "(vector_ts text,empId uuid,empName text,empSalary varint,address Map<text,text>,PRIMARY KEY (empName)) "
- + "WITH comment='Financial Info of employees' "
- + "AND compression={'sstable_compression':'DeflateCompressor','chunk_length_kb':64} "
- + "AND compaction={'class':'SizeTieredCompactionStrategy','min_threshold':6};";
-
- public static final String insertIntoTablePrepared1 =
- "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary) VALUES (?,?,?,?); ";
-
- public static final String insertIntoTablePrepared2 =
- "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary,address) VALUES (?,?,?,?,?);";
-
- public static final String selectALL = "SELECT * FROM testCassa.employees;";
-
- public static final String selectSpecific =
- "SELECT * FROM testCassa.employees WHERE empName= ?;";
-
- public static final String updatePreparedQuery =
- "UPDATE testCassa.employees SET vector_ts=?,address= ? WHERE empName= ?;";
-
- public static final String deleteFromTable = " ";
-
- public static final String deleteFromTablePrepared = " ";
-
- // Set Values for Prepared Query
-
- public static List<Object> setPreparedInsertValues1() {
-
- List<Object> preppreparedInsertValues1 = new ArrayList<>();
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- UUID empId = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40cd6");
- BigInteger empSalary = BigInteger.valueOf(23443);
- String empName = "Mr Test one";
- preppreparedInsertValues1.add(vectorTs);
- preppreparedInsertValues1.add(empId);
- preppreparedInsertValues1.add(empName);
- preppreparedInsertValues1.add(empSalary);
- return preppreparedInsertValues1;
- }
-
- public static List<Object> setPreparedInsertValues2() {
-
- List<Object> preparedInsertValues2 = new ArrayList<>();
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- UUID empId = UUID.fromString("abc434cc-d657-4e90-b4e5-df4223d40cd6");
- BigInteger empSalary = BigInteger.valueOf(45655);
- String empName = "Mr Test two";
- Map<String, String> address = new HashMap<>();
- preparedInsertValues2.add(vectorTs);
- preparedInsertValues2.add(empId);
- preparedInsertValues2.add(empName);
- preparedInsertValues2.add(empSalary);
- address.put("Street", "1 some way");
- address.put("City", "Some town");
- preparedInsertValues2.add(address);
- return preparedInsertValues2;
- }
-
- public static List<Object> setPreparedUpdateValues() {
-
- List<Object> preparedUpdateValues = new ArrayList<>();
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- Map<String, String> address = new HashMap<>();
- preparedUpdateValues.add(vectorTs);
- String empName = "Mr Test one";
- address.put("Street", "101 Some Way");
- address.put("City", "New York");
- preparedUpdateValues.add(address);
- preparedUpdateValues.add(empName);
- return preparedUpdateValues;
- }
-
- // Generate Different Prepared Query Objects
- /**
- * Query Object for Get.
- *
- * @return
- */
- public static PreparedQueryObject setPreparedGetQuery() {
-
- PreparedQueryObject queryObject = new PreparedQueryObject();
- String empName1 = "Mr Test one";
- queryObject.appendQueryString(selectSpecific);
- queryObject.addValue(empName1);
- return queryObject;
- }
-
- /**
- * Query Object 1 for Insert.
- *
- * @return {@link PreparedQueryObject}
- */
- public static PreparedQueryObject setPreparedInsertQueryObject1() {
-
- PreparedQueryObject queryobject = new PreparedQueryObject();
- queryobject.appendQueryString(insertIntoTablePrepared1);
- List<Object> values = setPreparedInsertValues1();
- if (!values.isEmpty() || values != null) {
- for (Object o : values) {
- queryobject.addValue(o);
- }
- }
- return queryobject;
-
- }
-
- /**
- * Query Object 2 for Insert.
- *
- * @return {@link PreparedQueryObject}
- */
- public static PreparedQueryObject setPreparedInsertQueryObject2() {
-
- PreparedQueryObject queryobject = new PreparedQueryObject();
- queryobject.appendQueryString(insertIntoTablePrepared2);
- List<Object> values = setPreparedInsertValues2();
- if (!values.isEmpty() || values != null) {
- for (Object o : values) {
- queryobject.addValue(o);
- }
- }
- return queryobject;
-
- }
-
- /**
- * Query Object for Update.
- *
- * @return {@link PreparedQueryObject}
- */
- public static PreparedQueryObject setPreparedUpdateQueryObject() {
-
- PreparedQueryObject queryobject = new PreparedQueryObject();
- queryobject.appendQueryString(updatePreparedQuery);
- List<Object> values = setPreparedUpdateValues();
- if (!values.isEmpty() || values != null) {
- for (Object o : values) {
- queryobject.addValue(o);
- }
- }
- return queryobject;
-
- }
-
- private static ArrayList<String> getAllPossibleLocalIps() {
- ArrayList<String> allPossibleIps = new ArrayList<String>();
- try {
- Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
- while (en.hasMoreElements()) {
- NetworkInterface ni = (NetworkInterface) en.nextElement();
- Enumeration<InetAddress> ee = ni.getInetAddresses();
- while (ee.hasMoreElements()) {
- InetAddress ia = (InetAddress) ee.nextElement();
- allPossibleIps.add(ia.getHostAddress());
- }
- }
- } catch (SocketException e) {
- System.out.println(e.getMessage());
- }
- return allPossibleIps;
- }
-
- public static MusicDataStore connectToEmbeddedCassandra() {
- Iterator<String> it = getAllPossibleLocalIps().iterator();
- String address = "localhost";
-
- Cluster cluster = null;
- Session session = null;
- while (it.hasNext()) {
- try {
-
- try {
- EmbeddedCassandraServerHelper.startEmbeddedCassandra(80000);
- } catch (ConfigurationException | TTransportException | IOException e) {
-
- System.out.println(e.getMessage());
- }
-
- cluster = new Cluster.Builder().addContactPoint(address).withPort(9142).build();
- cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(20000);
- session = cluster.connect();
-
- break;
- } catch (NoHostAvailableException e) {
- address = it.next();
- System.out.println(e.getMessage());
-
- }
- }
- return new MusicDataStore(cluster, session);
-
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/JsonResponseTest.java b/jar/src/test/java/org/onap/music/unittests/JsonResponseTest.java
deleted file mode 100644
index 9da10638..00000000
--- a/jar/src/test/java/org/onap/music/unittests/JsonResponseTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.music.main.ResultType;
-import org.onap.music.response.jsonobjects.JsonResponse;
-
-public class JsonResponseTest {
-
- JsonResponse result = null;
-
- @Test
- public void testJsonResponseBooleanStringString() {
- result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("version");
- assertEquals("error",result.getError());
- }
-
- @Test
- public void testStatus() {
- result = new JsonResponse(ResultType.SUCCESS);
- result.setStatus(ResultType.SUCCESS);
- assertEquals(ResultType.SUCCESS, result.getStatus());
- result = new JsonResponse(ResultType.FAILURE).setError("error").setMusicVersion("version");
- assertEquals(ResultType.FAILURE, result.getStatus());
- }
-
- @Test
- public void testError() {
- result = new JsonResponse(ResultType.FAILURE);
- result.setError("error");
- assertTrue(result.getError().equals("error"));
- result.setError("");
- assertFalse(result.getError().equals("error"));
- }
-
- @Test
- public void testVersion() {
- result = new JsonResponse(ResultType.SUCCESS);
- result.setMusicVersion("version");
- assertTrue(result.getMusicVersion().equals("version"));
- result.setMusicVersion("");
- assertFalse(result.getMusicVersion().equals("version"));
- }
-
- @Test
- public void testToMap() {
- result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("1.0");
- Map<String,Object> myMap = result.toMap();
- assertTrue(myMap.containsKey("status"));
- assertEquals(ResultType.SUCCESS, myMap.get("status"));
- assertEquals("error", myMap.get("error"));
- assertEquals("1.0", myMap.get("version"));
-
- result = new JsonResponse(ResultType.FAILURE);
- myMap = result.toMap();
- assertTrue(myMap.containsKey("status"));
- assertEquals(ResultType.FAILURE, myMap.get("status"));
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/jar/src/test/java/org/onap/music/unittests/MusicUtilTest.java
deleted file mode 100644
index b117c330..00000000
--- a/jar/src/test/java/org/onap/music/unittests/MusicUtilTest.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import org.apache.cassandra.exceptions.PreparedQueryNotFoundException;
-import org.junit.Test;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.MusicUtil;
-import com.datastax.driver.core.DataType;
-import javassist.CodeConverter.ArrayAccessReplacementMethodNames;
-
-public class MusicUtilTest {
-
- @Test
- public void testGetCassName() {
- MusicUtil.setCassName("Cassandra");
- assertTrue(MusicUtil.getCassName().equals("Cassandra"));
- }
-
- @Test
- public void testGetCassPwd() {
- MusicUtil.setCassPwd("Cassandra");
- assertTrue(MusicUtil.getCassPwd().equals("Cassandra"));
- }
-
- @Test
- public void testGetAafEndpointUrl() {
- MusicUtil.setAafEndpointUrl("url");
- assertEquals(MusicUtil.getAafEndpointUrl(),"url");
- }
-
- @Test
- public void testGetMyId() {
- MusicUtil.setMyId(1);
- assertEquals(MusicUtil.getMyId(),1);
- }
-
- @Test
- public void testGetAllIds() {
- List<String> ids = new ArrayList<String>();
- ids.add("1");
- ids.add("2");
- ids.add("3");
- MusicUtil.setAllIds(ids);
- assertEquals(MusicUtil.getAllIds().get(0),"1");
- }
-
-// @Test
-// public void testGetPublicIp() {
-// MusicUtil.setPublicIp("10.0.0.1");
-// assertEquals(MusicUtil.getPublicIp(),"10.0.0.1");
-// }
-
- @Test
- public void testGetAllPublicIps() {
- List<String> ips = new ArrayList<String>();
- ips.add("10.0.0.1");
- ips.add("10.0.0.2");
- ips.add("10.0.0.3");
- MusicUtil.setAllPublicIps(ips);
- assertEquals(MusicUtil.getAllPublicIps().get(1),"10.0.0.2");
- }
-
- @Test
- public void testGetPropkeys() {
- assertEquals(MusicUtil.getPropkeys()[2],"music.ip");
- }
-
- @Test
- public void testGetMusicRestIp() {
- MusicUtil.setMusicRestIp("localhost");
- assertEquals(MusicUtil.getMusicRestIp(),"localhost");
- }
-
- @Test
- public void testGetMusicPropertiesFilePath() {
- MusicUtil.setMusicPropertiesFilePath("filepath");
- assertEquals(MusicUtil.getMusicPropertiesFilePath(),"filepath");
- }
-
- @Test
- public void testGetDefaultLockLeasePeriod() {
- MusicUtil.setDefaultLockLeasePeriod(5000);
- assertEquals(MusicUtil.getDefaultLockLeasePeriod(),5000);
- }
-
- @Test
- public void testIsDebug() {
- MusicUtil.setDebug(true);
- assertTrue(MusicUtil.isDebug());
- }
-
- @Test
- public void testGetVersion() {
- MusicUtil.setVersion("1.0.0");
- assertEquals(MusicUtil.getVersion(),"1.0.0");
- }
-
- /*@Test
- public void testGetMyZkHost() {
- MusicUtil.setMyZkHost("10.0.0.2");
- assertEquals(MusicUtil.getMyZkHost(),"10.0.0.2");
- }*/
-
- @Test
- public void testGetMyCassaHost() {
- MusicUtil.setMyCassaHost("10.0.0.2");
- assertEquals(MusicUtil.getMyCassaHost(),"10.0.0.2");
- }
-
- @Test
- public void testGetDefaultMusicIp() {
- MusicUtil.setDefaultMusicIp("10.0.0.2");
- assertEquals(MusicUtil.getDefaultMusicIp(),"10.0.0.2");
- }
-
-// @Test
-// public void testGetTestType() {
-// fail("Not yet implemented"); // TODO
-// }
-
- @Test
- public void testIsValidQueryObject() {
- PreparedQueryObject myQueryObject = new PreparedQueryObject();
- myQueryObject.appendQueryString("select * from apple where type = ?");
- myQueryObject.addValue("macintosh");
- assertTrue(MusicUtil.isValidQueryObject(true,myQueryObject));
-
- myQueryObject.appendQueryString("select * from apple");
- assertTrue(MusicUtil.isValidQueryObject(false,myQueryObject));
-
- myQueryObject.appendQueryString("select * from apple where type = ?");
- assertFalse(MusicUtil.isValidQueryObject(true,myQueryObject));
-
- myQueryObject = new PreparedQueryObject();
- myQueryObject.appendQueryString("");
- System.out.println("#######" + myQueryObject.getQuery().isEmpty());
- assertFalse(MusicUtil.isValidQueryObject(false,myQueryObject));
-
-
- }
-
- @Test
- public void testConvertToCQLDataType() throws Exception {
- Map<String,Object> myMap = new HashMap<String,Object>();
- myMap.put("name","tom");
- assertEquals(MusicUtil.convertToCQLDataType(DataType.varchar(),"Happy People"),"'Happy People'");
- assertEquals(MusicUtil.convertToCQLDataType(DataType.uuid(),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab")),"29dc2afa-c2c0-47ae-afae-e72a645308ab");
- assertEquals(MusicUtil.convertToCQLDataType(DataType.blob(),"Hi"),"Hi");
- assertEquals(MusicUtil.convertToCQLDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),"{'name':'tom'}");
- }
-
- @Test
- public void testConvertToActualDataType() throws Exception {
- assertEquals(MusicUtil.convertToActualDataType(DataType.varchar(),"Happy People"),"Happy People");
- assertEquals(MusicUtil.convertToActualDataType(DataType.uuid(),"29dc2afa-c2c0-47ae-afae-e72a645308ab"),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.varint(),"1234"),BigInteger.valueOf(Long.parseLong("1234")));
- assertEquals(MusicUtil.convertToActualDataType(DataType.bigint(),"123"),Long.parseLong("123"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.cint(),"123"),Integer.parseInt("123"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.cfloat(),"123.01"),Float.parseFloat("123.01"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.cdouble(),"123.02"),Double.parseDouble("123.02"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.cboolean(),"true"),Boolean.parseBoolean("true"));
- Map<String,Object> myMap = new HashMap<String,Object>();
- myMap.put("name","tom");
- assertEquals(MusicUtil.convertToActualDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),myMap);
-
- }
-
- @Test
- public void testJsonMaptoSqlString() throws Exception {
- Map<String,Object> myMap = new HashMap<>();
- myMap.put("name","tom");
- myMap.put("value",5);
- String result = MusicUtil.jsonMaptoSqlString(myMap,",");
- assertTrue(result.contains("name"));
- assertTrue(result.contains("value"));
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/ResultTypeTest.java b/jar/src/test/java/org/onap/music/unittests/ResultTypeTest.java
deleted file mode 100644
index 012629e0..00000000
--- a/jar/src/test/java/org/onap/music/unittests/ResultTypeTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import org.junit.Test;
-import org.onap.music.main.ResultType;
-
-public class ResultTypeTest {
-
- @Test
- public void testResultType() {
- assertEquals("SUCCESS",ResultType.SUCCESS.name());
- assertEquals("FAILURE",ResultType.FAILURE.name());
- }
-
- @Test
- public void testGetResult() {
- assertEquals("Success",ResultType.SUCCESS.getResult());
- assertEquals("Failure",ResultType.FAILURE.getResult());
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/ReturnTypeTest.java b/jar/src/test/java/org/onap/music/unittests/ReturnTypeTest.java
deleted file mode 100644
index c22b0155..00000000
--- a/jar/src/test/java/org/onap/music/unittests/ReturnTypeTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import java.util.Map;
-import org.apache.tools.ant.filters.TokenFilter.ContainsString;
-import org.hamcrest.core.AnyOf;
-import org.junit.Test;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-
-public class ReturnTypeTest {
-
- @Test
- public void testReturnType() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- assertEquals(result.getMessage(),"message");
- assertEquals(result.getResult(),ResultType.SUCCESS);
- }
-
- @Test
- public void testTimingInfo() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- result.setTimingInfo("123");
- assertEquals(result.getTimingInfo(),"123");
- }
-
- @Test
- public void testGetResult() {
- ReturnType result = new ReturnType(ResultType.FAILURE,"message");
- assertEquals(result.getResult(),ResultType.FAILURE);
- }
-
- @Test
- public void testGetMessage() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- result.setMessage("NewMessage");
- assertEquals(result.getMessage(),"NewMessage");
- }
-
- @Test
- public void testToJson() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- String myJson = result.toJson();
- assertTrue(myJson.contains("message"));
- }
-
- @Test
- public void testToString() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- String test = result.toString();
- assertTrue(test.contains("message"));
- }
-
- @Test
- public void testToMap() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- Map<String, Object> myMap = result.toMap();
- assertTrue(myMap.containsKey("message"));
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/TestLockStore.java b/jar/src/test/java/org/onap/music/unittests/TestLockStore.java
deleted file mode 100644
index 4dbc7b4f..00000000
--- a/jar/src/test/java/org/onap/music/unittests/TestLockStore.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ============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.unittests;
-
-import org.apache.log4j.Logger;
-import org.onap.music.lockingservice.MusicLockingService;
-
-public class TestLockStore {
- final static Logger logger = Logger.getLogger(TestLockStore.class);
-
- public static void main(String[] args) throws Exception {
- String lockName = "/achristmkllas";
- MusicLockingService ml = new MusicLockingService();
- ml.deleteLock(lockName);
-
-
- logger.info("lockname:" + lockName);
-
- String lockId1 = ml.createLockId(lockName);
- logger.info("lockId1 " + lockId1);
- logger.info(ml.isMyTurn(lockId1));
-
- String lockId2 = ml.createLockId(lockName);
- logger.info("lockId2 " + lockId2);
- logger.info("check " + ml.isMyTurn("$bank$x-94608776321630264-0000000000"));
- logger.info(ml.isMyTurn(lockId2));
-
- // zkClient.unlock(lockId1);
- // logger.info(ml.lock(lockId2));
- // zkClient.unlock(lockId2);
- }
-
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/TestMusicCore.java b/jar/src/test/java/org/onap/music/unittests/TestMusicCore.java
deleted file mode 100644
index e798aaf1..00000000
--- a/jar/src/test/java/org/onap/music/unittests/TestMusicCore.java
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import static org.onap.music.main.MusicCore.mDstoreHandle;
-import static org.onap.music.main.MusicCore.mLockHandle;
-
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.music.exceptions.MusicLockingException;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.main.MusicCore.Condition;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Session;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TestMusicCore {
-
- @Mock
- private Condition condition;
-
- @Mock
- private ResultSet rs;
-
- @Mock
- private PreparedQueryObject preparedQueryObject;
-
- @Mock
- private Session session;
-
- @Before
- public void setUp() {
- mLockHandle = Mockito.mock(MusicLockingService.class);
-
- }
-
- @Test
- public void testCreateLockReferenceforvalidlock() {
- Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
- String lockId = MusicCore.createLockReference("test");
- assertEquals("lock", lockId);
- Mockito.verify(mLockHandle).createLockId("/" + "test");
- }
-
- @Test
- public void testIsTableOrKeySpaceLock() {
- Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1");
- assertTrue(result);
- }
-
- @Test
- public void testIsTableOrKeySpaceLockwithPrimarykey() {
- Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1.pk1");
- assertFalse(result);
- }
-
- @Test
- public void testGetMusicLockState() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(mLockHandle.getLockState("ks1.tb1.pk1")).thenReturn(musicLockState);
- MusicLockState mls = MusicCore.getMusicLockState("ks1.tb1.pk1");
- assertEquals(musicLockState, mls);
- Mockito.verify(mLockHandle).getLockState("ks1.tb1.pk1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrue() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnFalse() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType lock = MusicCore.acquireLock("ks1.ts1", "id1");
- assertEquals(lock.getResult(), ResultType.FAILURE);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandHaveLock() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandDontHaveLock() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id2");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockifLockRefDoesntExist() throws MusicLockingException {
- Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false);
- ReturnType lock = MusicCore.acquireLock("ks1.ts1", "bs1");
- assertEquals(lock.getResult(), ResultType.FAILURE);
- assertEquals(lock.getMessage(), "Lockid doesn't exist");
- Mockito.verify(mLockHandle).lockIdExists("bs1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLease() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- musicLockState.setLeasePeriod(0);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithException() throws MusicLockingException {
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "failure");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenThrow(new MusicLockingException());
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLockStatusLOCKED() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLockStatusUNLOCKED() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
-
- }
-
- @Test
- public void testAcquireLockWithLeaseIfNotMyTurn() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testQuorumGet() throws MusicServiceException, MusicQueryException {
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.quorumGet(preparedQueryObject);
- assertNotNull(rs1);
- }
-
- @Test
- public void testGetLockNameFromId() {
- String lockname = MusicCore.getLockNameFromId("lockName$id");
- assertEquals("lockName", lockname);
- }
-
- @Test
- public void testDestroyLockRef() throws NoNodeException {
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicCore.destroyLockRef("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testreleaseLockwithvoluntaryReleaseTrue() throws NoNodeException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicLockState musicLockState1 = MusicCore.releaseLock("id1", true);
- assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testreleaseLockwithvoluntaryReleaseFalse() throws NoNodeException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicLockState musicLockState1 = MusicCore.releaseLock("id1", false);
- assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testDeleteLock() throws MusicLockingException {
- Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1");
- MusicCore.deleteLock("id1");
- Mockito.verify(mLockHandle).deleteLock("/" + "id1");
- }
-
- /*
- * @Test public void testNonKeyRelatedPut() throws Exception { mDstoreHandle =
- * Mockito.mock(MusicDataStore.class); Mockito.when(mDstoreHandle.executePut("qu1",
- * "consistency")).thenReturn(true); Boolean result = MusicCore.nonKeyRelatedPut("qu1",
- * "consistency"); assertTrue(result); Mockito.verify(mDstoreHandle).executePut("qu1",
- * "consistency"); }
- */
-
- @Test
- public void testEventualPutPreparedQuery() throws MusicServiceException, MusicQueryException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true);
- ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
- }
-
- @Test
- public void testEventualPutPreparedQuerywithResultFalse()
- throws MusicServiceException, MusicQueryException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false);
- ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
- //Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, MusicUtil.EVENTUAL);
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithValidLockId()
- throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(condition.testCondition()).thenReturn(true);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
- ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithInvalidLockId() throws MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(condition.testCondition()).thenReturn(false);
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testNonKeyRelatedPutPreparedQuery() throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true);
- ResultType result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency");
- assertEquals(ResultType.SUCCESS, result);
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "consistency");
- }
-
- @Test
- public void testAtomicPutPreparedQuery() throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(condition.testCondition()).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
- ReturnType returnType =
- MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
- }
-
- @Test
- public void testAtomicPutPreparedQuerywithAcquireLockWithLeaseFalse() throws MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType returnType =
- MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- }
-
- @Test
- public void testAtomicGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNotNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
- }
-
- @Test
- public void testAtomicGetPreparedQuerywithAcquireLockWithLeaseFalse()
- throws MusicServiceException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testGetPreparedQuery() throws MusicServiceException, MusicQueryException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- rs = Mockito.mock(ResultSet.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executeEventualGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.get(preparedQueryObject);
- assertNotNull(rs1);
- Mockito.verify(mDstoreHandle).executeEventualGet(preparedQueryObject);
-
- }
-
- @Test
- public void testcriticalGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
- assertNotNull(rs1);
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
- }
-
- @Test
- public void testcriticalGetPreparedQuerywithInvalidLockId() throws MusicServiceException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
- assertNull(rs1);
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java b/jar/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
deleted file mode 100644
index d327d0f0..00000000
--- a/jar/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.util.List;
-import org.apache.curator.test.TestingServer;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestMusicCoreIntegration {
-
- static TestingServer zkServer;
- static PreparedQueryObject testObject;
- static String lockId = null;
- static String lockName = "ks1.tb1.pk1";
-
- @BeforeClass
- public static void init() throws Exception {
- try {
- MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- MusicCore.mLockHandle = new MusicLockingService();
- } catch (Exception e) {
- e.printStackTrace();
- }
- System.out.println("####Port:" + zkServer.getPort());
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- System.out.println("After class");
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.dropKeyspace);
- MusicCore.eventualPut(testObject);
- MusicCore.deleteLock(lockName);
- MusicCore.mDstoreHandle.close();
- MusicCore.mLockHandle.getzkLockHandle().close();
- MusicCore.mLockHandle.close();
- zkServer.stop();
-
- }
-
- @Test
- public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
- MusicCore.mLockHandle = new MusicLockingService();
- ResultType result = ResultType.FAILURE;
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createKeySpace);
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createTableEmployees);
- result = MusicCore.nonKeyRelatedPut(testObject, MusicUtil.EVENTUAL);
- assertEquals(ResultType.SUCCESS, result);
- }
-
- @Test
- public void Test2_atomicPut() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedInsertQueryObject1();
- ReturnType returnType = MusicCore.atomicPut("testCassa", "employees", "Mr Test one",
- testObject, null);
- assertEquals(ResultType.SUCCESS, returnType.getResult());
- }
-
- @Test
- public void Test3_atomicPutWithDeleteLock() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedInsertQueryObject2();
- ReturnType returnType = MusicCore.atomicPutWithDeleteLock("testCassa", "employees",
- "Mr Test two", testObject, null);
- assertEquals(ResultType.SUCCESS, returnType.getResult());
- }
-
- @Test
- public void Test4_atomicGetWithDeleteLock() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedGetQuery();
- ResultSet resultSet = MusicCore.atomicGetWithDeleteLock("testCassa", "employees",
- "Mr Test one", testObject);
- List<Row> rows = resultSet.all();
- assertEquals(1, rows.size());
- }
-
- @Test
- public void Test5_atomicGet() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedGetQuery();
- ResultSet resultSet =
- MusicCore.atomicGet("testCassa", "employees", "Mr Test two", testObject);
- List<Row> rows = resultSet.all();
- assertEquals(1, rows.size());
- }
-
- @Test
- public void Test6_createLockReference() throws Exception {
- lockId = MusicCore.createLockReference(lockName);
- assertNotNull(lockId);
- }
-
- @Test
- public void Test7_acquireLockwithLease() throws Exception {
- ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, 1000);
- assertEquals(ResultType.SUCCESS, lockLeaseStatus.getResult());
- }
-
- @Test
- public void Test8_acquireLock() throws Exception {
- ReturnType lockStatus = MusicCore.acquireLock(lockName, lockId);
- assertEquals(ResultType.SUCCESS, lockStatus.getResult());
- }
-
- @Test
- public void Test9_release() throws Exception {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- MusicLockState musicLockState1 = new MusicLockState(LockStatus.UNLOCKED, "id1");
- MusicCore.whoseTurnIsIt(lockName);
- MusicLockState mls = MusicCore.getMusicLockState(lockName);
- boolean voluntaryRelease = true;
- MusicLockState mls1 = MusicCore.releaseLock(lockId, voluntaryRelease);
- assertEquals(musicLockState.getLockStatus(), mls.getLockStatus());
- assertEquals(musicLockState1.getLockStatus(), mls1.getLockStatus());
- }
-
- @Test
- public void Test10_create() {
- MusicCore.pureZkCreate("/nodeName");
- }
-
- @Test
- public void Test11_write() {
- MusicCore.pureZkWrite("nodeName", "I'm Test".getBytes());
- }
-
- @Test
- public void Test12_read() {
- byte[] data = MusicCore.pureZkRead("nodeName");
- String data1 = new String(data);
- assertEquals("I'm Test", data1);
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java b/jar/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java
deleted file mode 100644
index 354668c7..00000000
--- a/jar/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.ArrayList;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.AAFResponse;
-import org.onap.music.datastore.jsonobjects.NameSpace;
-
-public class AAFResponseTest {
-
- @Test
- public void testGetNs() {
- NameSpace ns = new NameSpace();
- AAFResponse ar = new AAFResponse();
- ArrayList<NameSpace> nsArray = new ArrayList<>();
- ns.setName("tom");
- ArrayList<String> admin = new ArrayList<>();
- admin.add("admin1");
- ns.setAdmin(admin);
- nsArray.add(ns);
- ar.setNs(nsArray);
- assertEquals("tom",ar.getNs().get(0).getName());
- assertEquals("admin1",ar.getNs().get(0).getAdmin().get(0));
-
- }
-
-// @Test
-// public void testSetNs() {
-// fail("Not yet implemented");
-// }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java b/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
deleted file mode 100644
index 885694bd..00000000
--- a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-
-public class JsonDeleteTest {
-
- JsonDelete jd = null;
-
- @Before
- public void init() {
- jd = new JsonDelete();
- }
-
-
- @Test
- public void testGetConditions() {
- Map<String,Object> mapSo = new HashMap<>();
- mapSo = new HashMap<>();
- mapSo.put("key1","one");
- mapSo.put("key2","two");
- jd.setConditions(mapSo);
- assertEquals("one",jd.getConditions().get("key1"));
- }
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String,String> mapSs = new HashMap<>();
- mapSs = new HashMap<>();
- mapSs.put("key3","three");
- mapSs.put("key4","four");
- jd.setConsistencyInfo(mapSs);
- assertEquals("three",jd.getConsistencyInfo().get("key3"));
- }
-
- @Test
- public void testGetColumns() {
- ArrayList<String> ary = new ArrayList<>();
- ary = new ArrayList<>();
- ary.add("e1");
- ary.add("e2");
- ary.add("e3");
- jd.setColumns(ary);
- assertEquals("e1",jd.getColumns().get(0));
- }
-
- @Test
- public void testGetTtl() {
- jd.setTtl("2000");
- assertEquals("2000",jd.getTtl());
- }
-
- @Test
- public void testGetTimestamp() {
- jd.setTimestamp("20:00");
- assertEquals("20:00",jd.getTimestamp());
-
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java b/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java
deleted file mode 100644
index 69403cc7..00000000
--- a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-
-public class JsonInsertTest {
-
- JsonInsert ji = new JsonInsert();
-
- @Test
- public void testGetKeyspaceName() {
- ji.setKeyspaceName("keyspace");
- assertEquals("keyspace",ji.getKeyspaceName());
- }
-
- @Test
- public void testGetTableName() {
- ji.setTableName("table");
- assertEquals("table",ji.getTableName());
- }
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String,String> cons = new HashMap<>();
- cons.put("test","true");
- ji.setConsistencyInfo(cons);
- assertEquals("true",ji.getConsistencyInfo().get("test"));
- }
-
- @Test
- public void testGetTtl() {
- ji.setTtl("ttl");
- assertEquals("ttl",ji.getTtl());
- }
-
- @Test
- public void testGetTimestamp() {
- ji.setTimestamp("10:30");
- assertEquals("10:30",ji.getTimestamp());
- }
-
- @Test
- public void testGetValues() {
- Map<String,Object> cons = new HashMap<>();
- cons.put("val1","one");
- cons.put("val2","two");
- ji.setValues(cons);
- assertEquals("one",ji.getValues().get("val1"));
- }
-
- @Test
- public void testGetRow_specification() {
- Map<String,Object> cons = new HashMap<>();
- cons.put("val1","one");
- cons.put("val2","two");
- ji.setRow_specification(cons);
- assertEquals("two",ji.getRow_specification().get("val2"));
- }
-
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java b/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java
deleted file mode 100644
index 882d5d5e..00000000
--- a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-
-public class JsonKeySpaceTest {
-
- JsonKeySpace jk = null;
-
-
- @Before
- public void init() {
- jk = new JsonKeySpace();
- }
-
-
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("k1", "one");
- jk.setConsistencyInfo(mapSs);
- assertEquals("one",jk.getConsistencyInfo().get("k1"));
- }
-
- @Test
- public void testGetReplicationInfo() {
- Map<String,Object> mapSo = new HashMap<>();
- mapSo.put("k1", "one");
- jk.setReplicationInfo(mapSo);
- assertEquals("one",jk.getReplicationInfo().get("k1"));
-
- }
-
- @Test
- public void testGetDurabilityOfWrites() {
- jk.setDurabilityOfWrites("1");
- assertEquals("1",jk.getDurabilityOfWrites());
- }
-
- @Test
- public void testGetKeyspaceName() {
- jk.setKeyspaceName("Keyspace");
- assertEquals("Keyspace",jk.getKeyspaceName());
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java b/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
deleted file mode 100644
index 63f901c6..00000000
--- a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
-
-public class JsonLeasedLockTest {
-
- JsonLeasedLock jl = null;
-
- @Before
- public void init() {
- jl = new JsonLeasedLock();
- }
-
-
- @Test
- public void testGetLeasePeriod() {
- long lease = 20000;
- jl.setLeasePeriod(lease);
- assertEquals(lease,jl.getLeasePeriod());
- }
-
- @Test
- public void testGetNotifyUrl() {
- String url = "http://somewhere.com";
- jl.setNotifyUrl(url);
- assertEquals(url,jl.getNotifyUrl());
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java b/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java
deleted file mode 100644
index 82f1748a..00000000
--- a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-
-public class JsonOnboardTest {
-
- JsonOnboard jo = null;
-
- @Before
- public void init() {
- jo = new JsonOnboard();
- }
-
-
- @Test
- public void testGetPassword() {
- String password = "password";
- jo.setPassword(password);
- assertEquals(password,jo.getPassword());
- }
-
- @Test
- public void testGetAid() {
- String aid = "aid";
- jo.setAid(aid);
- assertEquals(aid,jo.getAid());
-
- }
-
- @Test
- public void testGetAppname() {
- String appName = "appName";
- jo.setAppname(appName);
- assertEquals(appName,jo.getAppname());
-
- }
-
- @Test
- public void testGetUserId() {
- String userId = "userId";
- jo.setUserId(userId);
- assertEquals(userId,jo.getUserId());
-
- }
-
- @Test
- public void testGetIsAAF() {
- String aaf = "true";
- jo.setIsAAF(aaf);
- assertEquals(aaf,jo.getIsAAF());
-
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java b/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java
deleted file mode 100644
index 0243232f..00000000
--- a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonSelect;
-
-public class JsonSelectTest {
-
- @Test
- public void testGetConsistencyInfo() {
- JsonSelect js = new JsonSelect();
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("k1", "one");
- js.setConsistencyInfo(mapSs);
- assertEquals("one",js.getConsistencyInfo().get("k1"));
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java b/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
deleted file mode 100644
index e4c800fc..00000000
--- a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-
-public class JsonTableTest {
-
- JsonTable jt = null;
-
- @Before
- public void init() {
- jt = new JsonTable();
- }
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("k1", "one");
- jt.setConsistencyInfo(mapSs);
- assertEquals("one",jt.getConsistencyInfo().get("k1"));
- }
-
- @Test
- public void testGetProperties() {
- Map<String, Object> properties = new HashMap<>();
- properties.put("k1", "one");
- jt.setProperties(properties);
- }
-
- @Test
- public void testGetFields() {
- Map<String, String> fields = new HashMap<>();
- fields.put("k1", "one");
- jt.setFields(fields);
- assertEquals("one",jt.getFields().get("k1"));
- }
-
- @Test
- public void testGetKeyspaceName() {
- String keyspace = "keyspace";
- jt.setKeyspaceName(keyspace);
- assertEquals(keyspace,jt.getKeyspaceName());
- }
-
- @Test
- public void testGetTableName() {
- String table = "table";
- jt.setTableName(table);
- assertEquals(table,jt.getTableName());
- }
-
- @Test
- public void testGetSortingKey() {
- String sortKey = "sortkey";
- jt.setSortingKey(sortKey);
- assertEquals(sortKey,jt.getSortingKey());
- }
-
- @Test
- public void testGetClusteringOrder() {
- String clusteringOrder = "clusteringOrder";
- jt.setClusteringOrder(clusteringOrder);
- assertEquals(clusteringOrder,jt.getClusteringOrder());
- }
-
- @Test
- public void testGetPrimaryKey() {
- String primaryKey = "primaryKey";
- jt.setPrimaryKey(primaryKey);
- assertEquals(primaryKey,jt.getPrimaryKey());
- }
-
-}
diff --git a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java b/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java
deleted file mode 100644
index 54db0540..00000000
--- a/jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2018 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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
-
-public class JsonUpdateTest {
-
- JsonUpdate ju = null;
-
- @Before
- public void init() {
- ju = new JsonUpdate();
- }
-
-
- @Test
- public void testGetConditions() {
- Map<String,Object> mapSo = new HashMap<>();
- mapSo.put("key1","one");
- mapSo.put("key2","two");
- ju.setConditions(mapSo);
- assertEquals("one",ju.getConditions().get("key1"));
- }
-
- @Test
- public void testGetRow_specification() {
- Map<String,Object> mapSo = new HashMap<>();
- mapSo.put("key1","one");
- mapSo.put("key2","two");
- ju.setRow_specification(mapSo);
- assertEquals("one",ju.getRow_specification().get("key1"));
- }
-
- @Test
- public void testGetKeyspaceName() {
- String keyspace = "keyspace";
- ju.setKeyspaceName(keyspace);
- assertEquals(keyspace,ju.getKeyspaceName());
- }
-
- @Test
- public void testGetTableName() {
- String table = "table";
- ju.setTableName(table);
- assertEquals(table,ju.getTableName());
- }
-
- @Test
- public void testGetConsistencyInfo() {
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("k1", "one");
- ju.setConsistencyInfo(mapSs);
- assertEquals("one",ju.getConsistencyInfo().get("k1"));
- }
-
- @Test
- public void testGetTtl() {
- ju.setTtl("2000");
- assertEquals("2000",ju.getTtl());
- }
-
- @Test
- public void testGetTimestamp() {
- ju.setTimestamp("20:00");
- assertEquals("20:00",ju.getTimestamp());
-
- }
-
- @Test
- public void testGetValues() {
- Map<String,Object> cons = new HashMap<>();
- cons.put("val1","one");
- cons.put("val2","two");
- ju.setValues(cons);
- assertEquals("one",ju.getValues().get("val1"));
- }
-
-}
diff --git a/jar/version.properties b/jar/version.properties
deleted file mode 100644
index 2ffa6347..00000000
--- a/jar/version.properties
+++ /dev/null
@@ -1,13 +0,0 @@
-# Versioning variables
-# Note that these variables cannot be structured (e.g. : version.release or version.snapshot etc... )
-# because they are used in Jenkins, whose plug-in doesn't support
-
-major=2
-minor=5
-patch=6
-
-base_version=${major}.${minor}.${patch}
-
-# Release must be completed with git revision # in Jenkins
-release_version=${base_version}
-snapshot_version=${base_version}-SNAPSHOT
diff --git a/musictrigger/pom.xml b/musictrigger/pom.xml
index f1d700a9..a0a156a9 100644
--- a/musictrigger/pom.xml
+++ b/musictrigger/pom.xml
@@ -1,100 +1,62 @@
<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>musictrigger</artifactId>
- <packaging>jar</packaging>
- <version>0.1.0</version>
- <parent>
- <groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>1.2.0</version>
- <relativePath/>
- </parent>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <!--nexus -->
- <nexusproxy>https://nexus.onap.org</nexusproxy>
- <snapshotNexusPath>/content/repositories/snapshots/</snapshotNexusPath>
- <releaseNexusPath>/content/repositories/releases/</releaseNexusPath>
- <stagingNexusPath>/content/repositories/staging/</stagingNexusPath>
- <sitePath>/content/sites/site/org/onap/music/${project.version}</sitePath>
- <!--maven -->
- <timestamp>${maven.build.timestamp}</timestamp>
- <maven.build.timestamp.format>yyyy.MM.dd.HH.mm</maven.build.timestamp.format>
- <!--docker -->
- <docker.tag>${project.version}-${timestamp}</docker.tag>
- <docker.latest.tag>${project.version}-latest</docker.latest.tag>
- </properties>
- <build>
- <sourceDirectory>src</sourceDirectory>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.6.1</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <mainClass>fully.qualified.MainClass</mainClass>
- </manifest>
- </archive>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ 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>MusicTrigger</groupId>
+ <artifactId>MusicTrigger</artifactId>
+ <packaging>jar</packaging>
+ <version>0.1</version>
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.6.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>fully.qualified.MainClass</mainClass>
+ </manifest>
+ </archive>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
- <dependencies>
- <dependency>
- <groupId>com.owlike</groupId>
- <artifactId>genson</artifactId>
- <version>0.99</version>
- </dependency>
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-client</artifactId>
- <version>1.17</version>
- </dependency>
- <dependency>
- <groupId>com.datastax.cassandra</groupId>
- <artifactId>cassandra-driver-core</artifactId>
- <version>3.0.0</version>
- </dependency>
- <dependency>
- <groupId>org.cassandraunit</groupId>
- <artifactId>cassandra-unit</artifactId>
- <version>3.3.0.1</version>
- </dependency>
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.11</version>
- </dependency>
- </dependencies>
- <distributionManagement>
- <repository>
- <id>ecomp-releases</id>
- <name>Release Repository</name>
- <url>${nexusproxy}/${releaseNexusPath}</url>
- </repository>
- <snapshotRepository>
- <id>ecomp-snapshots</id>
- <name>Snapshot Repository</name>
- <url>${nexusproxy}/${snapshotNexusPath}</url>
- </snapshotRepository>
- <!-- added for javadoc -->
- <site>
- <id>ecomp-site</id>
- <url>dav:${nexusproxy}${sitePath}</url>
- </site>
- </distributionManagement>
-</project>
+ <dependencies>
+ <dependency>
+ <groupId>com.owlike</groupId>
+ <artifactId>genson</artifactId>
+ <version>0.99</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>1.17</version>
+ </dependency>
+ <dependency>
+ <groupId>com.datastax.cassandra</groupId>
+ <artifactId>cassandra-driver-core</artifactId>
+ <version>3.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.cassandraunit</groupId>
+ <artifactId>cassandra-unit</artifactId>
+ <version>3.3.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.11</version>
+ </dependency>
+ </dependencies>
+</project> \ No newline at end of file
diff --git a/musictrigger/src/MusicTrigger.java b/musictrigger/src/MusicTrigger.java
index b5894da1..a27a6c40 100755..100644
--- a/musictrigger/src/MusicTrigger.java
+++ b/musictrigger/src/MusicTrigger.java
@@ -23,14 +23,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Map;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
@@ -40,7 +33,6 @@ import org.apache.cassandra.db.Clustering;
import org.apache.cassandra.db.Mutation;
import org.apache.cassandra.db.partitions.Partition;
import org.apache.cassandra.db.rows.Cell;
-import org.apache.cassandra.db.rows.Row;
import org.apache.cassandra.db.rows.Unfiltered;
import org.apache.cassandra.db.rows.UnfilteredRowIterator;
import org.apache.cassandra.triggers.ITrigger;
@@ -55,109 +47,38 @@ public class MusicTrigger implements ITrigger {
private static final Logger logger = LoggerFactory.getLogger(MusicTrigger.class);
-
public Collection<Mutation> augment(Partition partition)
{
- boolean isDelete = false;
- logger.info("Step 1: "+partition.partitionLevelDeletion().isLive());
- if(partition.partitionLevelDeletion().isLive()) {
-
- } else {
- // Partition Level Deletion
- isDelete = true;
- }
- logger.info("MusicTrigger isDelete: " + isDelete);
- String ksName = partition.metadata().ksName;
String tableName = partition.metadata().cfName;
logger.info("MusicTrigger Table: " + tableName);
- boolean isInsert = checkQueryType(partition);
+
org.json.simple.JSONObject obj = new org.json.simple.JSONObject();
-
- String operation = null;
- if(isDelete)
- operation = "delete";
- else if(isInsert)
- operation = "insert";
- else
- operation = "update";
- Map<String, Object> changeMap = new HashMap<>();
-
- obj.put("operation", operation);
- obj.put("keyspace", ksName);
- obj.put("table_name", tableName);
- obj.put("full_table", ksName+"."+tableName);
- obj.put("primary_key", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey()));
- List<String> updateList = new ArrayList<>();
- //obj.put("message_id", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey()));
- if("update".equals(operation)) {
- try {
- UnfilteredRowIterator it = partition.unfilteredIterator();
- while (it.hasNext()) {
- Unfiltered un = it.next();
- Clustering clt = (Clustering) un.clustering();
- Iterator<Cell> cells = partition.getRow(clt).cells().iterator();
- Iterator<ColumnDefinition> columns = partition.getRow(clt).columns().iterator();
-
- while(columns.hasNext()){
- ColumnDefinition columnDef = columns.next();
- Cell cell = cells.next();
-
- String data = null;
- if(cell.column().type.toString().equals("org.apache.cassandra.db.marshal.UTF8Type")) {
- logger.info(">> type is String");
- data = new String(cell.value().array()); // If cell type is text
- } else if(cell.column().type.toString().equals("org.apache.cassandra.db.marshal.Int32Type")) {
- //ByteBuffer wrapped = ByteBuffer.wrap(cell.value()); // big-endian by default
- int num = fromByteArray(cell.value().array());
- logger.info(">> type is Integer1 :: "+num);
- data = String.valueOf(num);
- }
-
- logger.info("Inside triggers loop: "+columnDef.name+" : "+data);
- //changeMap.put(ksName+"."+tableName+"."+columnDef.name,data);
- updateList.add(ksName+"."+tableName+":"+columnDef.name+":"+data);
- changeMap.put("field_value",ksName+"."+tableName+":"+columnDef.name+":"+data);
-
- }
- }
- } catch (Exception e) {
-
- }
- obj.put("updateList", updateList);
- } else {
- changeMap.put("field_value", ksName+"."+tableName);
- }
-
- obj.put("changeValue", changeMap);
- logger.info("Sending response: "+obj.toString());
+ obj.put("message_id", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey()));
+
try {
- notifyMusic(obj.toString());
- } catch(Exception e) {
- e.printStackTrace();
- logger.error("Notification failed..."+e.getMessage());
- }
- return Collections.emptyList();
- }
-
- private int fromByteArray(byte[] bytes) {
- return bytes[0] << 24 | (bytes[1] & 0xFF) << 16 | (bytes[2] & 0xFF) << 8 | (bytes[3] & 0xFF);
- }
-
- private boolean checkQueryType(Partition partition) {
- UnfilteredRowIterator it = partition.unfilteredIterator();
- while (it.hasNext()) {
- Unfiltered unfiltered = it.next();
- Row row = (Row) unfiltered;
- if (isInsert(row)) {
- return true;
+ UnfilteredRowIterator it = partition.unfilteredIterator();
+ while (it.hasNext()) {
+ Unfiltered un = it.next();
+ Clustering clt = (Clustering) un.clustering();
+ Iterator<Cell> cells = partition.getRow(clt).cells().iterator();
+ Iterator<ColumnDefinition> columns = partition.getRow(clt).columns().iterator();
+
+ while(columns.hasNext()){
+ ColumnDefinition columnDef = columns.next();
+ Cell cell = cells.next();
+ String data = new String(cell.value().array()); // If cell type is text
+ obj.put(columnDef.toString(), data);
+ }
}
+ } catch (Exception e) {
+
}
- return false;
+ logger.info("What is this? "+obj.toString());
+
+ notifyMusic(obj.toString());
+ return Collections.emptyList();
}
- private boolean isInsert(Row row) {
- return row.primaryKeyLivenessInfo().timestamp() != Long.MIN_VALUE;
- }
private void notifyMusic(String request) {
System.out.println("notifyMusic...");
@@ -171,12 +92,12 @@ public class MusicTrigger implements ITrigger {
.post(ClientResponse.class, data);
if(response.getStatus() != 200){
- System.out.println("Exception while notifying MUSIC...");
+ System.out.println("Exception...");
}
- /*response.getHeaders().put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON));
+ response.getHeaders().put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON));
response.bufferEntity();
String x = response.getEntity(String.class);
- System.out.println("Response: "+x);*/
+ System.out.println("Response: "+x);
}
diff --git a/pom.xml b/pom.xml
index 22a17245..dff48dcf 100755
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,3 @@
-<?xml version="1.0"?>
<!--
============LICENSE_START==========================================
org.onap.music
@@ -8,9 +7,9 @@
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.
@@ -19,30 +18,24 @@
============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">
+-->
+<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>3.0.22</version>
+ <version>3.0.2</version>
<description>
This is the MUSIC REST interface, packaged as a war file.
</description>
- <parent>
- <groupId>org.onap.oparent</groupId>
- <artifactId>oparent</artifactId>
- <version>1.2.0</version>
- <relativePath/>
- </parent>
-
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jersey1.version>1.19</jersey1.version>
<jersey2.version>2.25.1</jersey2.version>
<jaxrs.version>2.0.1</jaxrs.version>
- <cassandra.version>3.6.0</cassandra.version>
+ <cassandra.version>3.4.0</cassandra.version>
<zookeeper.version>3.4.11</zookeeper.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -185,11 +178,7 @@
<scope>provided</scope>
</dependency>
<!-- /Development -->
- <!-- <dependency>
- <groupId>com.hazelcast</groupId>
- <artifactId>hazelcast-client</artifactId>
- <version>3.7.1</version>
- </dependency> -->
+
<!-- Logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
@@ -219,6 +208,7 @@
<version>1.0.1-oss</version>
</dependency>
<!-- End Logging -->
+
<!-- Cassandra -->
<dependency>
<groupId>com.datastax.cassandra</groupId>
@@ -226,6 +216,7 @@
<version>${cassandra.version}</version>
</dependency>
<!-- /Cassandra -->
+
<!-- Zookeeper -->
<dependency>
<groupId>org.apache.zookeeper</groupId>
@@ -239,6 +230,7 @@
</exclusions>
</dependency>
<!-- /Zookeeper -->
+
<!-- Jersey -->
<dependency>
<groupId>com.sun.jersey</groupId>
@@ -286,6 +278,7 @@
<version>3.3.0.2</version>
<scope>test</scope>
</dependency>
+ <!-- https://mvnrepository.com/artifact/it.unimi.dsi/fastutil -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
@@ -312,7 +305,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
- <version>4.1.30.Final</version>
+ <version>4.0.56.Final</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
@@ -332,18 +325,13 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
+ <version>19.0</version>
</dependency>
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.4</version>
</dependency>
- <dependency>
- <groupId>com.owlike</groupId>
- <artifactId>genson</artifactId>
- <version>1.3</version>
- </dependency>
-
</dependencies>
<reporting>
@@ -398,30 +386,17 @@
</image>
<!-- Cassandra -->
<image>
- <name>onap/music/cassandra_3_11</name>
- <alias>docker_cassandra_sec</alias>
+ <name>onap/music/cassandra_music</name>
+ <alias>docker_cassandra</alias>
<build>
<cleanup>true</cleanup>
<tags>
- <tag>${docker.tag}</tag>
- <tag>${docker.latest.tag}</tag>
+ <tag>3.0-${timestamp}</tag>
+ <tag>3.0-latest</tag>
</tags>
<dockerFileDir>${project.basedir}/distribution/cassandra</dockerFileDir>
</build>
</image>
- <!-- Cassandra Job -->
- <image>
- <name>onap/music/cassandra_job</name>
- <alias>docker_cassandra_job</alias>
- <build>
- <cleanup>true</cleanup>
- <tags>
- <tag>${docker.tag}</tag>
- <tag>${docker.latest.tag}</tag>
- </tags>
- <dockerFileDir>${project.basedir}/distribution/cassandra_job</dockerFileDir>
- </build>
- </image>
<!-- Zookeeper -->
<!-- <image> <name>onap/music/zookeeper_music</name>
<alias>docker_zookeeper</alias> <build> <cleanup>true</cleanup> <tags> <tag>3.4-${timestamp}</tag>
diff --git a/src/main/java/org/onap/music/conductor/conditionals/JsonConditional.java b/src/main/java/org/onap/music/conductor/conditionals/JsonConditional.java
index 8cacc369..33a14bef 100644
--- a/src/main/java/org/onap/music/conductor/conditionals/JsonConditional.java
+++ b/src/main/java/org/onap/music/conductor/conditionals/JsonConditional.java
@@ -35,8 +35,8 @@ public class JsonConditional implements Serializable {
private String primaryKey;
private String primaryKeyValue;
private String casscadeColumnName;
- private transient Map<String,Object> tableValues;
- private transient Map<String,Object> casscadeColumnData;
+ private Map<String,Object> tableValues;
+ private Map<String,Object> casscadeColumnData;
private Map<String,Map<String,String>> conditions;
public Map<String, Object> getTableValues() {
diff --git a/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java b/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
index d5e9e4d5..8aadcba3 100644
--- a/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
+++ b/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
@@ -32,7 +32,6 @@ import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.lockingservice.MusicLockState;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
@@ -47,7 +46,6 @@ import com.datastax.driver.core.TableMetadata;
public class MusicConditional {
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
- private static final String CRITICAL = "critical";
public static ReturnType conditionalInsert(String keyspace, String tablename, String casscadeColumnName,
Map<String, Object> casscadeColumnData, String primaryKey, Map<String, Object> valuesMap,
@@ -94,7 +92,7 @@ public class MusicConditional {
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
ReturnType criticalPutResult = conditionalInsertAtomic(lockId, keyspace, tablename, primaryKey,
queryBank);
- MusicCore.destroyLockRef(lockId);
+ MusicCore.destroyLockRef(key,lockId);
if (criticalPutResult.getMessage().contains("insert"))
criticalPutResult
.setMessage("Insert values: ");
@@ -104,12 +102,11 @@ public class MusicConditional {
return criticalPutResult;
} else {
- MusicCore.destroyLockRef(lockId);
+ MusicCore.destroyLockRef(key,lockId);
return lockAcqResult;
}
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED);
- MusicCore.destroyLockRef(lockId);
+ MusicCore.destroyLockRef(key,lockId);
return new ReturnType(ResultType.FAILURE, e.getMessage());
}
@@ -121,20 +118,19 @@ public class MusicConditional {
ResultSet results = null;
try {
-
- MusicLockState mls = MusicCore.getLockingServiceHandle()
- .getLockState(keyspace + "." + tableName + "." + primaryKey);
- if (mls.getLockHolder().equals(lockId)) {
+ String fullyQualifiedKey = keyspace + "." + tableName + "." + primaryKey;
+ ReturnType lockAcqResult = MusicCore.acquireLock(fullyQualifiedKey, lockId);
+ if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
try {
results = MusicCore.getDSHandle().executeCriticalGet(queryBank.get(MusicUtil.SELECT));
} catch (Exception e) {
return new ReturnType(ResultType.FAILURE, e.getMessage());
}
if (results.all().isEmpty()) {
- MusicCore.getDSHandle().executePut(queryBank.get(MusicUtil.INSERT), CRITICAL);
+ MusicCore.getDSHandle().executePut(queryBank.get(MusicUtil.INSERT), "critical");
return new ReturnType(ResultType.SUCCESS, "insert");
} else {
- MusicCore.getDSHandle().executePut(queryBank.get(MusicUtil.UPDATE), CRITICAL);
+ MusicCore.getDSHandle().executePut(queryBank.get(MusicUtil.UPDATE), "critical");
return new ReturnType(ResultType.SUCCESS, "update");
}
} else {
@@ -145,7 +141,6 @@ public class MusicConditional {
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
String exceptionAsString = sw.toString();
return new ReturnType(ResultType.FAILURE,
"Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
@@ -159,21 +154,18 @@ public class MusicConditional {
String key = keyspace + "." + tableName + "." + primaryKeyValue;
String lockId = MusicCore.createLockReference(key);
long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = MusicCore.acquireLockWithLease(key, lockId, leasePeriod);
-
try {
-
+ ReturnType lockAcqResult = MusicCore.acquireLockWithLease(key, lockId, leasePeriod);
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
return updateAtomic(lockId, keyspace, tableName, primaryKey,primaryKeyValue, queryBank,planId,cascadeColumnValues,cascadeColumnName);
} else {
- MusicCore.destroyLockRef(lockId);
+ MusicCore.destroyLockRef(key,lockId);
return lockAcqResult;
}
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- MusicCore.destroyLockRef(lockId);
+ MusicCore.destroyLockRef(key,lockId);
return new ReturnType(ResultType.FAILURE, e.getMessage());
}
@@ -181,11 +173,11 @@ public class MusicConditional {
public static ReturnType updateAtomic(String lockId, String keyspace, String tableName, String primaryKey,String primaryKeyValue,
Map<String,PreparedQueryObject> queryBank,String planId,Map<String,String> cascadeColumnValues,String casscadeColumnName) {
+ String key = keyspace + "." + tableName + "." + primaryKeyValue;
+ long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
try {
-
- MusicLockState mls = MusicCore.getLockingServiceHandle()
- .getLockState(keyspace + "." + tableName + "." + primaryKeyValue);
- if (mls.getLockHolder().equals(lockId)) {
+ ReturnType lockAcqResult = MusicCore.acquireLockWithLease(key, lockId, leasePeriod);
+ if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
Row row = MusicCore.getDSHandle().executeCriticalGet(queryBank.get(MusicUtil.SELECT)).one();
if(row != null) {
@@ -199,14 +191,14 @@ public class MusicConditional {
update.addValue(MusicUtil.convertToActualDataType(DataType.text(), vector_ts));
update.addValue(MusicUtil.convertToActualDataType(DataType.text(), primaryKeyValue));
try {
- MusicCore.getDSHandle().executePut(update, CRITICAL);
+ MusicCore.getDSHandle().executePut(update, "critical");
} catch (Exception ex) {
return new ReturnType(ResultType.FAILURE, ex.getMessage());
}
}else {
return new ReturnType(ResultType.FAILURE,"Cannot find data related to key: "+primaryKey);
}
- MusicCore.getDSHandle().executePut(queryBank.get(MusicUtil.UPSERT), CRITICAL);
+ MusicCore.getDSHandle().executePut(queryBank.get(MusicUtil.UPSERT), "critical");
return new ReturnType(ResultType.SUCCESS, "update success");
} else {
@@ -215,7 +207,6 @@ public class MusicConditional {
}
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsString = sw.toString();
@@ -340,7 +331,7 @@ public class MusicConditional {
Map<String, String> finalValues = new HashMap<>();
values = (Map<String, String>) columnValue;
- if (values != null && values.keySet().contains(planId)) {
+ if (values.keySet().contains(planId)) {
String valueString = values.get(planId);
String tempValueString = valueString.replaceAll("\\{", "").replaceAll("\"", "").replaceAll("\\}", "");
String[] elements = tempValueString.split(",");
@@ -355,4 +346,4 @@ public class MusicConditional {
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java b/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java
index eb466754..4292749c 100644
--- a/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java
+++ b/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java
@@ -103,7 +103,7 @@ public class RestMusicConditionalAPI {
Map<String, Object> authMap = null;
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "insertIntoTable");
+ authMap = MusicCore.authenticate(ns, userId, password, keyspace, aid, "insertIntoTable");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO, ErrorSeverity.CRITICAL,
ErrorTypes.AUTHENTICATIONERROR);
@@ -174,7 +174,7 @@ public class RestMusicConditionalAPI {
Map<String, Object> authMap = null;
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "updateTable");
+ authMap = MusicCore.authenticate(ns, userId, password, keyspace, aid, "updateTable");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO, ErrorSeverity.CRITICAL,
ErrorTypes.AUTHENTICATIONERROR);
diff --git a/src/main/java/org/onap/music/datastore/MusicDataStore.java b/src/main/java/org/onap/music/datastore/CassaDataStore.java
index 0154ad28..14934f6e 100644
--- a/src/main/java/org/onap/music/datastore/MusicDataStore.java
+++ b/src/main/java/org/onap/music/datastore/CassaDataStore.java
@@ -30,6 +30,8 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.UUID;
+
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
@@ -42,10 +44,8 @@ import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.ColumnDefinitions.Definition;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.HostDistance;
import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.Metadata;
-import com.datastax.driver.core.PoolingOptions;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
@@ -54,13 +54,42 @@ import com.datastax.driver.core.TableMetadata;
import com.datastax.driver.core.exceptions.AlreadyExistsException;
import com.datastax.driver.core.exceptions.InvalidQueryException;
import com.datastax.driver.core.exceptions.NoHostAvailableException;
+import com.datastax.driver.core.utils.UUIDs;
import com.sun.jersey.core.util.Base64;
/**
* @author nelson24
*
*/
-public class MusicDataStore {
+/**
+ * @author bharathb
+ *
+ */
+/**
+ * @author bharathb
+ *
+ */
+/**
+ * @author bharathb
+ *
+ */
+/**
+ * @author bharathb
+ *
+ */
+/**
+ * @author bharathb
+ *
+ */
+/**
+ * @author bharathb
+ *
+ */
+/**
+ * @author bharathb
+ *
+ */
+public class CassaDataStore {
private Session session;
private Cluster cluster;
@@ -90,12 +119,12 @@ public class MusicDataStore {
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStore.class);
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CassaDataStore.class);
/**
*
*/
- public MusicDataStore() {
+ public CassaDataStore() {
connectToCassaCluster();
}
@@ -104,7 +133,7 @@ public class MusicDataStore {
* @param cluster
* @param session
*/
- public MusicDataStore(Cluster cluster, Session session) {
+ public CassaDataStore(Cluster cluster, Session session) {
this.session = session;
this.cluster = cluster;
}
@@ -114,7 +143,7 @@ public class MusicDataStore {
* @param remoteIp
* @throws MusicServiceException
*/
- public MusicDataStore(String remoteIp) {
+ public CassaDataStore(String remoteIp) {
try {
connectToCassaCluster(remoteIp);
} catch (MusicServiceException e) {
@@ -151,35 +180,16 @@ public class MusicDataStore {
* clusters.
*/
private void connectToCassaCluster() {
- Iterator<String> it = getAllPossibleLocalIps().iterator();
+ Iterator<String> it = getAllPossibleLocalIps().iterator();
String address = "localhost";
- String[] addresses = null;
- address = MusicUtil.getMyCassaHost();
- addresses = address.split(",");
-
logger.info(EELFLoggerDelegate.applicationLogger,
"Connecting to cassa cluster: Iterating through possible ips:"
+ getAllPossibleLocalIps());
- PoolingOptions poolingOptions = new PoolingOptions();
- poolingOptions
- .setConnectionsPerHost(HostDistance.LOCAL, 4, 10)
- .setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
while (it.hasNext()) {
try {
- if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) {
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd());
- cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort())
- .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd())
- //.withLoadBalancingPolicy(new RoundRobinPolicy())
- .withPoolingOptions(poolingOptions)
- .addContactPoints(addresses).build();
- }
- else
- cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort())
- //.withLoadBalancingPolicy(new RoundRobinPolicy())
- .addContactPoints(addresses).build();
-
+ cluster = Cluster.builder().withPort(9042)
+ .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd())
+ .addContactPoint(address).build();
Metadata metadata = cluster.getMetadata();
logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster "
+ metadata.getClusterName() + " at " + address);
@@ -206,27 +216,9 @@ public class MusicDataStore {
* @param address
*/
private void connectToCassaCluster(String address) throws MusicServiceException {
- String[] addresses = null;
- addresses = address.split(",");
- PoolingOptions poolingOptions = new PoolingOptions();
- poolingOptions
- .setConnectionsPerHost(HostDistance.LOCAL, 4, 10)
- .setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
- if(MusicUtil.getCassName() != null && MusicUtil.getCassPwd() != null) {
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Building with credentials "+MusicUtil.getCassName()+" & "+MusicUtil.getCassPwd());
- cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort())
- .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd())
- //.withLoadBalancingPolicy(new RoundRobinPolicy())
- .withPoolingOptions(poolingOptions)
- .addContactPoints(addresses).build();
- }
- else {
- cluster = Cluster.builder().withPort(MusicUtil.getCassandraPort())
- //.withLoadBalancingPolicy(new RoundRobinPolicy())
- .withPoolingOptions(poolingOptions)
- .addContactPoints(addresses).build();
- }
+ cluster = Cluster.builder().withPort(9042)
+ .withCredentials(MusicUtil.getCassName(), MusicUtil.getCassPwd())
+ .addContactPoint(address).build();
Metadata metadata = cluster.getMetadata();
logger.info(EELFLoggerDelegate.applicationLogger, "Connected to cassa cluster "
+ metadata.getClusterName() + " at " + address);
@@ -315,7 +307,7 @@ public class MusicDataStore {
DataType colType = colInfo.getType(colName);
Object columnValue = getColValue(row, colName, colType);
Object conditionValue = MusicUtil.convertToActualDataType(colType, entry.getValue());
- if (!columnValue.equals(conditionValue))
+ if (columnValue.equals(conditionValue) == false)
return false;
}
return true;
@@ -479,5 +471,5 @@ public class MusicDataStore {
return results;
}
-
}
+
diff --git a/src/main/java/org/onap/music/datastore/CassaLockStore.java b/src/main/java/org/onap/music/datastore/CassaLockStore.java
new file mode 100644
index 00000000..e03a1c07
--- /dev/null
+++ b/src/main/java/org/onap/music/datastore/CassaLockStore.java
@@ -0,0 +1,173 @@
+package org.onap.music.datastore;
+
+import java.util.UUID;
+
+import org.onap.music.eelf.logging.EELFLoggerDelegate;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.main.MusicUtil;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.datastax.driver.core.utils.UUIDs;
+
+/*
+ * This is the lock store that is built on top of Cassandra that is used by MUSIC to maintain lock state.
+ */
+
+public class CassaLockStore {
+
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CassaLockStore.class);
+
+ public class LockObject{
+ public String lockRef;
+ public String createTime;
+ public String acquireTime;
+ public LockObject(String lockRef, String createTime, String acquireTime) {
+ this.lockRef = lockRef;
+ this.acquireTime = acquireTime;
+ this.createTime = createTime;
+
+ }
+ }
+ CassaDataStore dsHandle;
+ public CassaLockStore() {
+ dsHandle = new CassaDataStore();
+ }
+
+ public CassaLockStore(CassaDataStore dsHandle) {
+ this.dsHandle=dsHandle;
+ }
+
+
+ /**
+ *
+ * This method creates a shadow locking table for every main table in Cassandra. This table tracks all information regarding locks.
+ * @param keyspace of the application.
+ * @param table of the application.
+ * @return true if the operation was successful.
+ * @throws MusicServiceException
+ * @throws MusicQueryException
+ */
+ public boolean createLockQueue(String keyspace, String table) throws MusicServiceException, MusicQueryException {
+ logger.info(EELFLoggerDelegate.applicationLogger,
+ "Create lock queue/table for " + keyspace+"."+table);
+ table = "lockQ_"+table;
+ String tabQuery = "CREATE TABLE IF NOT EXISTS "+keyspace+"."+table
+ + " ( key text, lockReference bigint, createTime text, acquireTime text, guard bigint static, PRIMARY KEY ((key), lockReference) ) "
+ + "WITH CLUSTERING ORDER BY (lockReference ASC);";
+ System.out.println(tabQuery);
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+
+ queryObject.appendQueryString(tabQuery);
+ boolean result;
+ result = dsHandle.executePut(queryObject, "eventual");
+ return result;
+ }
+
+ /**
+ * This method creates a lock reference for each invocation. The lock references are monotonically increasing timestamps.
+ * @param keyspace of the locks.
+ * @param table of the locks.
+ * @param lockName is the primary key of the lock table
+ * @return the UUID lock reference.
+ * @throws MusicServiceException
+ * @throws MusicQueryException
+ */
+ public String genLockRefandEnQueue(String keyspace, String table, String lockName) throws MusicServiceException, MusicQueryException {
+ logger.info(EELFLoggerDelegate.applicationLogger,
+ "Create lock reference for " + keyspace + "." + table + "." + lockName);
+ table = "lockQ_" + table;
+ long lockEpochMillis = System.currentTimeMillis();
+ long lockRef = lockEpochMillis;
+
+ logger.info(EELFLoggerDelegate.applicationLogger,
+ "Created lock reference for " + keyspace + "." + table + "." + lockName + ":" + lockRef);
+
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ String defaultQuery = " UPDATE " + keyspace + "." + table + " SET guard=-1 WHERE key=? IF guard = NULL;";
+
+ queryObject.addValue(lockName);
+ queryObject.appendQueryString(defaultQuery);
+ boolean dqResult = dsHandle.executePut(queryObject, "critical");
+// System.out.println("dqResult: " + dqResult);
+
+
+ queryObject = new PreparedQueryObject();
+ String insQuery = "BEGIN BATCH" +
+ " UPDATE " + keyspace + "." + table + " SET guard=? WHERE key=? IF guard < ?;" +
+ " INSERT INTO " + keyspace + "." + table +
+ "(key, lockReference, createTime, acquireTime) VALUES (?,?,?,?) IF NOT EXISTS; APPLY BATCH;";
+
+ queryObject.addValue(lockRef);
+ queryObject.addValue(lockName);
+ queryObject.addValue(lockRef);
+
+ queryObject.addValue(lockName);
+ queryObject.addValue(lockRef);
+ queryObject.addValue(String.valueOf(lockEpochMillis));
+ queryObject.addValue("0");
+ queryObject.appendQueryString(insQuery);
+ boolean pResult = dsHandle.executePut(queryObject, "critical");
+// System.out.println("pResult: " + pResult);
+ return String.valueOf(lockRef);
+ }
+
+
+ /**
+ * This method returns the top of lock table/queue for the key.
+ * @param keyspace of the application.
+ * @param table of the application.
+ * @param key is the primary key of the application table
+ * @return the UUID lock reference.
+ * @throws MusicServiceException
+ * @throws MusicQueryException
+ */
+ public LockObject peekLockQueue(String keyspace, String table, String key) throws MusicServiceException, MusicQueryException{
+ logger.info(EELFLoggerDelegate.applicationLogger,
+ "Peek in lock table for " + keyspace+"."+table+"."+key);
+ table = "lockQ_"+table;
+ String selectQuery = "select * from "+keyspace+"."+table+" where key='"+key+"' LIMIT 1;";
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(selectQuery);
+ ResultSet results = dsHandle.executeEventualGet(queryObject);
+ Row row = results.one();
+ String lockReference = "" + row.getLong("lockReference");
+ String createTime = row.getString("createTime");
+ String acquireTime = row.getString("acquireTime");
+
+ return new LockObject(lockReference, createTime,acquireTime);
+ }
+
+
+ /**
+ * This method removes the lock ref from the lock table/queue for the key.
+ * @param keyspace of the application.
+ * @param table of the application.
+ * @param key is the primary key of the application table
+ * @param lockReference the lock reference that needs to be dequeued.
+ * @throws MusicServiceException
+ * @throws MusicQueryException
+ */
+ public void deQueueLockRef(String keyspace, String table, String key, String lockReference) throws MusicServiceException, MusicQueryException{
+ table = "lockQ_"+table;
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ Long lockReferenceL = Long.parseLong(lockReference);
+ String deleteQuery = "delete from "+keyspace+"."+table+" where key='"+key+"' AND lockReference ="+lockReferenceL+" IF EXISTS;";
+ queryObject.appendQueryString(deleteQuery);
+ dsHandle.executePut(queryObject, "critical");
+ }
+
+
+ public void updateLockAcquireTime(String keyspace, String table, String key, String lockReference) throws MusicServiceException, MusicQueryException{
+ table = "lockQ_"+table;
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ Long lockReferenceL = Long.parseLong(lockReference);
+ String updateQuery = "update "+keyspace+"."+table+" set acquireTime='"+ System.currentTimeMillis()+"' where key='"+key+"' AND lockReference = "+lockReferenceL+" IF EXISTS;";
+ queryObject.appendQueryString(updateQuery);
+ dsHandle.executePut(queryObject, "eventual");
+
+ }
+
+
+}
diff --git a/src/main/java/org/onap/music/datastore/MusicLockState.java b/src/main/java/org/onap/music/datastore/MusicLockState.java
new file mode 100644
index 00000000..60a15b13
--- /dev/null
+++ b/src/main/java/org/onap/music/datastore/MusicLockState.java
@@ -0,0 +1,41 @@
+package org.onap.music.datastore;
+public class MusicLockState {
+ public enum LockStatus {
+ UNLOCKED, BEING_LOCKED, LOCKED
+ };// captures the state of the lock
+
+ private LockStatus lockStatus;
+ private String lockHolder;
+ private String errorMessage = null;
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ public MusicLockState(LockStatus lockStatus, String lockHolder) {
+ super();
+ this.lockStatus = lockStatus;
+ this.lockHolder = lockHolder;
+ }
+
+ public LockStatus getLockStatus() {
+ return lockStatus;
+ }
+
+ public void setLockStatus(LockStatus lockStatus) {
+ this.lockStatus = lockStatus;
+ }
+
+ public String getLockHolder() {
+ return lockHolder;
+ }
+
+ public void setLockHolder(String lockHolder) {
+ this.lockHolder = lockHolder;
+ }
+
+}
diff --git a/src/main/java/org/onap/music/datastore/PreparedQueryObject.java b/src/main/java/org/onap/music/datastore/PreparedQueryObject.java
index 694d9acd..534f7d65 100644
--- a/src/main/java/org/onap/music/datastore/PreparedQueryObject.java
+++ b/src/main/java/org/onap/music/datastore/PreparedQueryObject.java
@@ -34,6 +34,7 @@ public class PreparedQueryObject {
private List<Object> values;
private StringBuilder query;
+
@@ -67,6 +68,10 @@ public class PreparedQueryObject {
this.query.append(s);
}
+ public void replaceQueryString(String s) {
+ this.query.replace(0, query.length(), s);
+ }
+
/**
* @return
*/
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JSONCallbackResponse.java b/src/main/java/org/onap/music/datastore/jsonobjects/JSONCallbackResponse.java
deleted file mode 100755
index f869c342..00000000
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JSONCallbackResponse.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.util.List;
-import java.util.Map;
-
-public class JSONCallbackResponse {
-
- private String full_table;
- private String keyspace;
- private Map<String, String> changeValue;
- private String operation;
- private String table_name;
- private String primary_key;
- private Object miscObjects;
- private List<String> updateList;
-
- public String getFull_table() {
- return full_table;
- }
- public void setFull_table(String full_table) {
- this.full_table = full_table;
- }
- public String getKeyspace() {
- return keyspace;
- }
- public void setKeyspace(String keyspace) {
- this.keyspace = keyspace;
- }
- public String getOperation() {
- return operation;
- }
- public void setOperation(String operation) {
- this.operation = operation;
- }
- public String getTable_name() {
- return table_name;
- }
- public void setTable_name(String table_name) {
- this.table_name = table_name;
- }
- public String getPrimary_key() {
- return primary_key;
- }
- public void setPrimary_key(String primary_key) {
- this.primary_key = primary_key;
- }
- public Object getMiscObjects() {
- return miscObjects;
- }
- public void setMiscObjects(Object miscObjects) {
- this.miscObjects = miscObjects;
- }
- public void setChangeValue(Map<String, String> changeValue) {
- this.changeValue = changeValue;
- }
- public Map<String, String> getChangeValue() {
- return changeValue;
- }
- public List<String> getUpdateList() {
- return updateList;
- }
- public void setUpdateList(List<String> updateList) {
- this.updateList = updateList;
- }
-
-
-}
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java
deleted file mode 100755
index 4a865320..00000000
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-@ApiModel(value = "JsonCallback", description = "Json model for callback")
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonCallback implements Serializable {
- private String applicationName;
- private String applicationUsername;
- private String applicationPassword;
- private String applicationNotificationEndpoint;
- private String notifyOn;
- private String notifyWhenChangeIn;
- private String notifyWhenInsertsIn;
- private String notifyWhenDeletesIn;
- private Map<String, String> responseBody;
-
- private String uuid;
-
- public String getUuid() {
- return uuid;
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- @ApiModelProperty(value = "application name")
- public String getApplicationName() {
- return applicationName;
- }
-
- public void setApplicationName(String applicationName) {
- this.applicationName = applicationName;
- }
-
- @ApiModelProperty(value = "notify On")
- public String getNotifyOn() {
- return notifyOn;
- }
-
- public void setNotifyOn(String notifyOn) {
- this.notifyOn = notifyOn;
- }
-
- @ApiModelProperty(value = "application User name")
- public String getApplicationUsername() {
- return applicationUsername;
- }
-
- public void setApplicationUsername(String applicationUsername) {
- this.applicationUsername = applicationUsername;
- }
-
- @ApiModelProperty(value = "application password")
- public String getApplicationPassword() {
- return applicationPassword;
- }
-
- public void setApplicationPassword(String applicationPassword) {
- this.applicationPassword = applicationPassword;
- }
-
- @ApiModelProperty(value = "application notification endpoint")
- public String getApplicationNotificationEndpoint() {
- return applicationNotificationEndpoint;
- }
-
- public void setApplicationNotificationEndpoint(String applicationNotificationEndpoint) {
- this.applicationNotificationEndpoint = applicationNotificationEndpoint;
- }
-
- @ApiModelProperty(value = "notify when updates")
- public String getNotifyWhenChangeIn() {
- return notifyWhenChangeIn;
- }
-
- public void setNotifyWhenChangeIn(String notifyWhenChangeIn) {
- this.notifyWhenChangeIn = notifyWhenChangeIn;
- }
-
- @ApiModelProperty(value = "notify when inserts")
- public String getNotifyWhenInsertsIn() {
- return notifyWhenInsertsIn;
- }
-
- public void setNotifyWhenInsertsIn(String notifyWhenInsertsIn) {
- this.notifyWhenInsertsIn = notifyWhenInsertsIn;
- }
-
- @ApiModelProperty(value = "notify when deletes")
- public String getNotifyWhenDeletesIn() {
- return notifyWhenDeletesIn;
- }
-
- public void setNotifyWhenDeletesIn(String notifyWhenDeletesIn) {
- this.notifyWhenDeletesIn = notifyWhenDeletesIn;
- }
-
- public Map<String, String> getResponseBody() {
- return responseBody;
- }
-
- public void setResponseBody(Map<String, String> responseBody) {
- this.responseBody = responseBody;
- }
-
-}
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java
index ce7f509b..a5db4be5 100644
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java
+++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java
@@ -36,8 +36,7 @@ public class JsonDelete {
private ArrayList<String> columns = null;
private Map<String, String> consistencyInfo;
private Map<String, Object> conditions;
- String ttl;
- String timestamp;
+ String ttl, timestamp;
@ApiModelProperty(value = "Conditions")
@@ -86,4 +85,3 @@ public class JsonDelete {
this.timestamp = timestamp;
}
}
-
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java
index c79ba9b7..9630abe0 100644
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java
+++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java
@@ -38,11 +38,12 @@ import io.swagger.annotations.ApiModelProperty;
public class JsonInsert implements Serializable {
private String keyspaceName;
private String tableName;
- private transient Map<String, Object> values;
+ private Map<String, Object> values;
private String ttl;
private String timestamp;
- private transient Map<String, Object> row_specification;
+ private Map<String, Object> row_specification;
private Map<String, String> consistencyInfo;
+ private byte[] data;
private Map<String, byte[]> objectMap;
@ApiModelProperty(value = "objectMap")
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonNotification.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonNotification.java
deleted file mode 100755
index ce244e2c..00000000
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonNotification.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.io.Serializable;
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-
-import io.swagger.annotations.ApiModel;
-
-@ApiModel(value = "JsonNotification", description = "Json model for callback")
-@JsonIgnoreProperties(ignoreUnknown = true)
-@JsonInclude(Include.NON_NULL)
-public class JsonNotification implements Serializable {
-
- private String notify_field;
- private String endpoint;
- private String username;
- private String password;
- private String notify_change;
- private String notify_insert;
- private String notify_delete;
- private String operation_type;
- private String triggerName;
- private Map<String, String> response_body;
-
- public String getNotify_field() {
- return notify_field;
- }
- public void setNotify_field(String notify_field) {
- this.notify_field = notify_field;
- }
- public String getEndpoint() {
- return endpoint;
- }
- public void setEndpoint(String endpoint) {
- this.endpoint = endpoint;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public Map<String, String> getResponse_body() {
- return response_body;
- }
- public void setResponse_body(Map<String, String> response_body) {
- this.response_body = response_body;
- }
- public String getNotify_change() {
- return notify_change;
- }
- public void setNotify_change(String notify_change) {
- this.notify_change = notify_change;
- }
- public String getNotify_insert() {
- return notify_insert;
- }
- public void setNotify_insert(String notify_insert) {
- this.notify_insert = notify_insert;
- }
- public String getNotify_delete() {
- return notify_delete;
- }
- public void setNotify_delete(String notify_delete) {
- this.notify_delete = notify_delete;
- }
- public String getOperation_type() {
- return operation_type;
- }
- public void setOperation_type(String operation_type) {
- this.operation_type = operation_type;
- }
- public String getTriggerName() {
- return triggerName;
- }
- public void setTriggerName(String triggerName) {
- this.triggerName = triggerName;
- }
- @Override
- public String toString() {
- try {
- return new com.fasterxml.jackson.databind.ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this);
- } catch (com.fasterxml.jackson.core.JsonProcessingException e) {
- return notify_field+ " : "+endpoint+ " : "+username+ " : "+password+ " : "+response_body;
- }
-
- }
-
-}
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonNotifyClientResponse.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonNotifyClientResponse.java
deleted file mode 100644
index 963352d0..00000000
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonNotifyClientResponse.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ============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.datastore.jsonobjects;
-
-import java.io.Serializable;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-import io.swagger.annotations.ApiModel;
-
-@ApiModel(value = "JsonNotifyClientResponse", description = "Json model for callback")
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class JsonNotifyClientResponse implements Serializable {
- private String message;
- private String status;
-
- public String getMessage() {
- return message;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- public String getStatus() {
- return status;
- }
- public void setStatus(String status) {
- this.status = status;
- }
-
- @Override
- public String toString() {
- try {
- return new com.fasterxml.jackson.databind.ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this);
- } catch (com.fasterxml.jackson.core.JsonProcessingException e) {
- return message+ " : "+status;
- }
-
- }
-
-}
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java
index ef56c5de..64bc3887 100644
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java
+++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java
@@ -27,13 +27,13 @@ import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Map;
-import org.apache.log4j.Logger;
+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class JsonSelect implements Serializable {
private Map<String, String> consistencyInfo;
- static Logger logger = Logger.getLogger(JsonSelect.class.getName());
+
public Map<String, String> getConsistencyInfo() {
return consistencyInfo;
@@ -51,7 +51,6 @@ public class JsonSelect implements Serializable {
out.writeObject(this);
} catch (IOException e) {
// TODO Auto-generated catch block
- logger.error("Error", e);
e.printStackTrace();
}
return bos.toByteArray();
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java
index c1a56819..3ab5ea0d 100644
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java
+++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java
@@ -38,12 +38,11 @@ import io.swagger.annotations.ApiModelProperty;
public class JsonUpdate implements Serializable {
private String keyspaceName;
private String tableName;
- private transient Map<String, Object> values;
- private String ttl;
- private String timestamp;
+ private Map<String, Object> values;
+ private String ttl, timestamp;
private Map<String, String> consistencyInfo;
- private transient Map<String, Object> conditions;
- private transient Map<String, Object> row_specification;
+ private Map<String, Object> conditions;
+ private Map<String, Object> row_specification;
@ApiModelProperty(value = "Conditions")
public Map<String, Object> getConditions() {
diff --git a/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java b/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java
index af6e6151..5f6329a1 100644
--- a/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java
+++ b/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java
@@ -25,12 +25,7 @@ import java.util.UUID;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.exceptions.MusicLockingException;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockingService;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
@@ -56,19 +51,16 @@ public class MusicHealthCheck {
result = getAdminKeySpace(consistency);
} catch(Exception e) {
if(e.getMessage().toLowerCase().contains("unconfigured table healthcheck")) {
- logger.error("Error", e);
- logger.debug("Creating table....");
+ System.out.println("Creating table....");
boolean ksresult = createKeyspace();
if(ksresult)
try {
result = getAdminKeySpace(consistency);
} catch (MusicServiceException e1) {
// TODO Auto-generated catch block
- logger.error("Error", e);
e1.printStackTrace();
}
} else {
- logger.error("Error", e);
return "One or more nodes are down or not responding.";
}
}
@@ -106,32 +98,13 @@ public class MusicHealthCheck {
} catch (MusicServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- logger.error("Error", e);
}
- if(rs != null && rs.getResult().toLowerCase().contains("success"))
+ if(rs.getResult().toLowerCase().contains("success"))
return true;
else
return false;
}
- public String getZookeeperStatus() {
-
- String host = MusicUtil.getMyZkHost();
- logger.info(EELFLoggerDelegate.applicationLogger, "Getting Status for Zookeeper Host: " + host);
- try {
- MusicLockingService lockingService = MusicCore.getLockingServiceHandle();
- // additionally need to call the ZK to create,aquire and delete lock
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.LOCKINGERROR,
- ErrorTypes.CONNECTIONERROR, ErrorSeverity.CRITICAL);
- return "INACTIVE";
- }
-
- logger.info(EELFLoggerDelegate.applicationLogger, "Zookeeper is Active and Running");
- return "ACTIVE";
-
- }
-
public String getCassandrHost() {
return cassandrHost;
}
diff --git a/src/main/java/org/onap/music/lockingservice/LockListener.java b/src/main/java/org/onap/music/lockingservice/LockListener.java
deleted file mode 100644
index 33188e60..00000000
--- a/src/main/java/org/onap/music/lockingservice/LockListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * ============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.lockingservice;
-
-/**
- * This class has two methods which are call back methods when a lock is acquired and when the lock
- * is released.
- *
- */
-public interface LockListener {
- /**
- * call back called when the lock is acquired
- */
- public void lockAcquired();
-
- /**
- * call back called when the lock is released.
- */
- public void lockReleased();
-}
diff --git a/src/main/java/org/onap/music/lockingservice/MusicLockState.java b/src/main/java/org/onap/music/lockingservice/MusicLockState.java
deleted file mode 100644
index 04a1e6b2..00000000
--- a/src/main/java/org/onap/music/lockingservice/MusicLockState.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * ============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.lockingservice;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-
-// the state variable that will be stored in zookeeper, capturing the transitions of
-public class MusicLockState implements Serializable {
- public enum LockStatus {
- UNLOCKED, BEING_LOCKED, LOCKED
- };// captures the state of the lock
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicLockState.class);
- LockStatus lockStatus;
- boolean needToSyncQuorum = false;
- String lockHolder;
- long leasePeriod = Long.MAX_VALUE;
- long leaseStartTime = -1;
-
- private String errorMessage = null;
-
- public MusicLockState(String errorMessage) {
- this.errorMessage = errorMessage;
- }
-
- public MusicLockState(LockStatus lockStatus, String lockHolder) {
- this.lockStatus = lockStatus;
- this.lockHolder = lockHolder;
- }
-
- public MusicLockState(LockStatus lockStatus, String lockHolder, boolean needToSyncQuorum) {
- this.lockStatus = lockStatus;
- this.lockHolder = lockHolder;
- this.needToSyncQuorum = needToSyncQuorum;
- }
-
-
- public long getLeasePeriod() {
- return leasePeriod;
- }
-
- public boolean isNeedToSyncQuorum() {
- return needToSyncQuorum;
- }
-
-
-
- public void setLeasePeriod(long leasePeriod) {
- this.leasePeriod = leasePeriod;
- }
-
-
- public long getLeaseStartTime() {
- return leaseStartTime;
- }
-
-
- public void setLeaseStartTime(long leaseStartTime) {
- this.leaseStartTime = leaseStartTime;
- }
-
-
-
- public LockStatus getLockStatus() {
- return lockStatus;
- }
-
- public void setLockStatus(LockStatus lockStatus) {
- this.lockStatus = lockStatus;
- }
-
- public String getLockHolder() {
- return lockHolder;
- }
-
- public void setLockHolder(String lockHolder) {
- this.lockHolder = lockHolder;
- }
-
- public String getErrorMessage() {
- return errorMessage;
- }
-
- public byte[] serialize() {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutput out = null;
- try {
- out = new ObjectOutputStream(bos);
- out.writeObject(this);
- } catch (IOException e) {
- logger.error("Error", e);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- }
- return bos.toByteArray();
- }
-
- public static MusicLockState deSerialize(byte[] data) {
- ByteArrayInputStream bis = new ByteArrayInputStream(data);
- Object o = null;
- ObjectInput in = null;
- try {
- in = new ObjectInputStream(bis);
- o = in.readObject();
- } catch (ClassNotFoundException | IOException e) {
- logger.error("Error", e);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.UNKNOWN);
- }
- return (MusicLockState) o;
- }
-}
diff --git a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java
deleted file mode 100644
index f9c09338..00000000
--- a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * ============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.lockingservice;
-
-
-import java.io.IOException;
-import java.util.StringTokenizer;
-import java.util.concurrent.CountDownLatch;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.Watcher.Event.KeeperState;
-import org.apache.zookeeper.ZooKeeper;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.exceptions.MusicLockingException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.CachingUtil;
-import org.onap.music.main.MusicUtil;
-
-
-public class MusicLockingService implements Watcher {
-
-
- private static final int SESSION_TIMEOUT = 180000;
- ZkStatelessLockService zkLockHandle = null;
- private CountDownLatch connectedSignal = new CountDownLatch(1);
- private static EELFLoggerDelegate logger =
- EELFLoggerDelegate.getLogger(MusicLockingService.class);
-
- public MusicLockingService() throws MusicServiceException {
- try {
- ZooKeeper zk = new ZooKeeper(MusicUtil.getMyZkHost(), SESSION_TIMEOUT, this);
- connectedSignal.await();
- zkLockHandle = new ZkStatelessLockService(zk);
- } catch (IOException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- throw new MusicServiceException("IO Error has occured" + e.getMessage());
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw new MusicServiceException("Exception Occured " + e.getMessage());
- }
- }
-
- public ZkStatelessLockService getzkLockHandle() {
- return zkLockHandle;
- }
-
- public MusicLockingService(String lockServer) {
- try {
- ZooKeeper zk = new ZooKeeper(lockServer, SESSION_TIMEOUT, this);
- connectedSignal.await();
- zkLockHandle = new ZkStatelessLockService(zk);
- } catch (IOException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.IOERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
- }catch( InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch(Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- }
-
- public void createLockaIfItDoesNotExist(String lockName) {
- if (!zkLockHandle.checkIfLockExists(lockName)) {
- String lockHolder = null;
- MusicLockState ml = new MusicLockState(MusicLockState.LockStatus.UNLOCKED, lockHolder);
- byte[] data = ml.serialize();
- zkLockHandle.createLock(lockName, data);
- }
- }
-
- public void setLockState(String lockName, MusicLockState mls) {
- byte[] data = mls.serialize();
- zkLockHandle.setNodeData(lockName, data);
- }
-
- public MusicLockState getLockState(String lockName) throws MusicLockingException {
-
- byte[] data = null;
- try{
- data = zkLockHandle.getNodeData(lockName);
- }catch (Exception ex){
- logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- if(data !=null)
- return MusicLockState.deSerialize(data);
- else {
- logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.INVALIDLOCK, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw new MusicLockingException("Invalid lock or acquire failed");
- }
- }
-
- public String createLockId(String lockName) {
- String lockIdWithSlash = zkLockHandle.createLockId(lockName);
- return lockIdWithSlash.replace('/', '$');
- }
-
- public boolean isMyTurn(String lockIdWithDollar) {
- String lockId = lockIdWithDollar.replace('$', '/');
- StringTokenizer st = new StringTokenizer(lockId);
- String lockName = "/" + st.nextToken("/");
- try {
- return zkLockHandle.lock(lockName, lockId);
- } catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.LOCKINGERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch( InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch(Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- return false;
- }
-
- public void unlockAndDeleteId(String lockIdWithDollar) throws KeeperException.NoNodeException {
- String lockId = lockIdWithDollar.replace('$', '/');
- zkLockHandle.unlock(lockId);
- CachingUtil.deleteKeysFromDB("'"+lockId+"'");
- }
-
- public void deleteLock(String lockName) throws MusicLockingException {
- if(lockIdExists(lockName))
- zkLockHandle.deleteLock(lockName);
- else{
- throw new MusicLockingException("Lock does not exist.Please check the lock: " + lockName + " and try again");
- }
- }
-
- public String whoseTurnIsIt(String lockName) {
- String lockHolder = zkLockHandle.currentLockHolder(lockName);
- return lockHolder.replace('/', '$');
-
- }
-
- public void process(WatchedEvent event) { // Watcher interface
- if (event.getState() == KeeperState.SyncConnected) {
- connectedSignal.countDown();
- }
- }
-
-
- public void close() {
- zkLockHandle.close();
- }
-
- public boolean lockIdExists(String lockIdWithDollar) {
- String lockId = lockIdWithDollar.replace('$', '/');
- return zkLockHandle.checkIfLockExists(lockId);
- }
-
-}
diff --git a/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java b/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java
deleted file mode 100644
index 19f49beb..00000000
--- a/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * ============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.lockingservice;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.data.ACL;
-import org.apache.zookeeper.data.Stat;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.lockingservice.ZooKeeperOperation;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * A base class for protocol implementations which provides a number of higher level helper methods
- * for working with ZooKeeper along with retrying synchronous operations if the connection to
- * ZooKeeper closes such as {@link #retryOperation(ZooKeeperOperation)}
- *
- */
-class ProtocolSupport {
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ProtocolSupport.class);
-
- protected ZooKeeper zookeeper;
- private AtomicBoolean closed = new AtomicBoolean(false);
- private long retryDelay = 500L;
- private int retryCount = 10;
- private List<ACL> acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
-
- /**
- * Closes this strategy and releases any ZooKeeper resources; but keeps the ZooKeeper instance
- * open
- */
- public void close() {
- if (closed.compareAndSet(false, true)) {
- doClose();
- }
- }
-
- /**
- * return zookeeper client instance
- *
- * @return zookeeper client instance
- */
- public ZooKeeper getZookeeper() {
- return zookeeper;
- }
-
- /**
- * return the acl its using
- *
- * @return the acl.
- */
- public List<ACL> getAcl() {
- return acl;
- }
-
- /**
- * set the acl
- *
- * @param acl the acl to set to
- */
- public void setAcl(List<ACL> acl) {
- this.acl = acl;
- }
-
- /**
- * get the retry delay in milliseconds
- *
- * @return the retry delay
- */
- public long getRetryDelay() {
- return retryDelay;
- }
-
- /**
- * Sets the time waited between retry delays
- *
- * @param retryDelay the retry delay
- */
- public void setRetryDelay(long retryDelay) {
- this.retryDelay = retryDelay;
- }
-
- /**
- * Allow derived classes to perform some custom closing operations to release resources
- */
- protected void doClose() {
- throw new UnsupportedOperationException();
- }
-
-
- /**
- * Perform the given operation, retrying if the connection fails
- *
- * @return object. it needs to be cast to the callee's expected return type.
- * @param operation FILL IN
- * @throws KeeperException FILL IN
- * @throws InterruptedException FILL IN
- */
- protected Object retryOperation(ZooKeeperOperation operation)
- throws KeeperException, InterruptedException {
- KeeperException exception = null;
- for (int i = 0; i < retryCount; i++) {
- try {
- return operation.execute();
- } catch (KeeperException.SessionExpiredException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.SESSIONEXPIRED+" for: " + zookeeper + " so reconnecting due to: " + e, ErrorSeverity.ERROR, ErrorTypes.SESSIONEXPIRED);
- throw e;
- } catch (KeeperException.ConnectionLossException e) {
- if (exception == null) {
- exception = e;
- }
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.CONNCECTIVITYERROR, ErrorSeverity.ERROR, ErrorTypes.SESSIONEXPIRED);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Attempt " + i + " failed with connection loss so attempting to reconnect: " + e);
-
- retryDelay(i);
- }
- }
- throw exception;
- }
-
- /**
- * Ensures that the given path exists with no data, the current ACL and no flags
- *
- * @param path the lock path
- */
- protected void ensurePathExists(String path) {
- ensureExists(path, null, acl, CreateMode.PERSISTENT);
- }
-
- /**
- * Ensures that the given path exists with the given data, ACL and flags
- *
- * @param path the lock path
- * @param data the data
- * @param acl list of ACLs applying to the path
- * @param flags create mode flags
- */
- protected void ensureExists(final String path, final byte[] data, final List<ACL> acl,
- final CreateMode flags) {
- try {
- retryOperation(new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- Stat stat = zookeeper.exists(path, false);
- if (stat != null) {
- return true;
- }
- zookeeper.create(path, data, acl, flags);
- return true;
- }
- });
- } catch (KeeperException e) {
- logger.error("Error", e);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- } catch (InterruptedException e) {
- logger.error("Error", e);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- }
-
- /**
- * Returns true if this protocol has been closed
- *
- * @return true if this protocol is closed
- */
- protected boolean isClosed() {
- return closed.get();
- }
-
- /**
- * Performs a retry delay if this is not the first attempt
- *
- * @param attemptCount the number of the attempts performed so far
- */
- protected void retryDelay(int attemptCount) {
- if (attemptCount > 0) {
- try {
- Thread.sleep(attemptCount * retryDelay);
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.GENERALSERVICEERROR);
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Thread failed to sleep: " + e);
- Thread.currentThread().interrupt();
- }
- }
- }
-}
diff --git a/src/main/java/org/onap/music/lockingservice/ZNodeName.java b/src/main/java/org/onap/music/lockingservice/ZNodeName.java
deleted file mode 100644
index 0c190f14..00000000
--- a/src/main/java/org/onap/music/lockingservice/ZNodeName.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * ============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.lockingservice;
-
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-
-/**
- * Represents an ephemeral znode name which has an ordered sequence number and can be sorted in
- * order
- *
- */
-class ZNodeName implements Comparable<ZNodeName> {
- private final String name;
- private String prefix;
- private int sequence = -1;
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ZNodeName.class);
-
- public ZNodeName(String name) {
- if (name == null) {
- throw new NullPointerException("id cannot be null");
- }
- this.name = name;
- this.prefix = name;
- int idx = name.lastIndexOf('-');
- if (idx >= 0) {
- this.prefix = name.substring(0, idx);
- try {
- this.sequence = Integer.parseInt(name.substring(idx + 1));
- // If an exception occurred we misdetected a sequence suffix,
- // so return -1.
- } catch (NumberFormatException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Number format exception "+idx, ErrorSeverity.ERROR, ErrorTypes.GENERALSERVICEERROR);
- } catch (ArrayIndexOutOfBoundsException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Array out of bounds for "+idx, ErrorSeverity.ERROR, ErrorTypes.GENERALSERVICEERROR);
- }
- }
- }
-
- @Override
- public String toString() {
- return name.toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (o == null || getClass() != o.getClass())
- return false;
-
- ZNodeName sequence = (ZNodeName) o;
-
- if (!name.equals(sequence.name))
- return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- return name.hashCode() + 37;
- }
-
- public int compareTo(ZNodeName that) {
- int answer = this.prefix.compareTo(that.prefix);
- if (answer == 0) {
- int s1 = this.sequence;
- int s2 = that.sequence;
- if (s1 == -1 && s2 == -1) {
- return this.name.compareTo(that.name);
- }
- answer = s1 == -1 ? 1 : s2 == -1 ? -1 : s1 - s2;
- }
- return answer;
- }
-
- /**
- * Returns the name of the znode
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the sequence number
- */
- public int getZNodeName() {
- return sequence;
- }
-
- /**
- * Returns the text prefix before the sequence number
- */
- public String getPrefix() {
- return prefix;
- }
-}
diff --git a/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java b/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java
deleted file mode 100644
index b09668b7..00000000
--- a/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * ============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.lockingservice;
-
-
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.data.ACL;
-import org.apache.zookeeper.data.Stat;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-
-import com.datastax.driver.core.DataType;
-
-/**
- * A <a href="package.html">protocol to implement an exclusive write lock or to elect a leader</a>.
- * <p/>
- * You invoke {@link #lock()} to start the process of grabbing the lock; you may get the lock then
- * or it may be some time later.
- * <p/>
- * You can register a listener so that you are invoked when you get the lock; otherwise you can ask
- * if you have the lock by calling {@link #isOwner()}
- *
- */
-public class ZkStatelessLockService extends ProtocolSupport {
- public ZkStatelessLockService(ZooKeeper zk) {
- zookeeper = zk;
- }
-
- private static EELFLoggerDelegate logger =
- EELFLoggerDelegate.getLogger(ZkStatelessLockService.class);
-
- protected void createLock(final String path, final byte[] data) {
- final List<ACL> acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
- try {
- retryOperation(new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- zookeeper.create(path, data, acl, CreateMode.PERSISTENT);
- return true;
- }
- });
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- }
-
- public void close() {
- try {
- zookeeper.close();
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- }
-
- public void setNodeData(final String lockName, final byte[] data) {
- try {
- retryOperation(new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- zookeeper.getSessionId();
- zookeeper.setData("/" + lockName, data, -1);
- return true;
- }
- });
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
-
- }
-
- public byte[] getNodeData(final String lockName) {
- try {
- if (zookeeper.exists("/" + lockName, null) != null)
- return zookeeper.getData("/" + lockName, false, null);
- else
- return null;
-
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- return null;
- }
-
- public boolean checkIfLockExists(String lockName) {
- boolean result = false;
- try {
- Stat stat = zookeeper.exists(lockName, false);
- if (stat != null) {
- result = true;
- }
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- return result;
- }
-
- public void createNode(String nodeName) {
- ensurePathExists(nodeName);
- }
-
- public String createLockId(String dir) {
- ensurePathExists(dir);
- LockZooKeeperOperation zop = new LockZooKeeperOperation(dir);
- try {
- retryOperation(zop);
- }catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- }
- return zop.getId();
- }
-
- /**
- * Attempts to acquire the exclusive write lock returning whether or not it was acquired. Note
- * that the exclusive lock may be acquired some time later after this method has been invoked
- * due to the current lock owner going away.
- */
- public synchronized boolean lock(String dir, String lockId)
- throws KeeperException, InterruptedException {
- if (isClosed()) {
- return false;
- }
- LockZooKeeperOperation zop = new LockZooKeeperOperation(dir, lockId);
- return (Boolean) retryOperation(zop);
- }
-
- /**
- * Removes the lock or associated znode if you no longer require the lock. this also removes
- * your request in the queue for locking in case you do not already hold the lock.
- *
- * @throws RuntimeException throws a runtime exception if it cannot connect to zookeeper.
- * @throws NoNodeException
- */
- public synchronized void unlock(String lockId) throws RuntimeException, KeeperException.NoNodeException {
- final String id = lockId;
- if (!isClosed() && id != null) {
- try {
- ZooKeeperOperation zopdel = new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- zookeeper.delete(id, -1);
- return Boolean.TRUE;
- }
- };
- zopdel.execute();
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- // set that we have been interrupted.
- Thread.currentThread().interrupt();
- } catch (KeeperException.NoNodeException e) {
- // do nothing
- throw new KeeperException.NoNodeException("Lock doesn't exists. Release lock operation failed.");
- } catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw (RuntimeException) new RuntimeException(e.getMessage()).initCause(e);
- }
- }
- }
-
- public synchronized String currentLockHolder(String mainLock) {
- final String id = mainLock;
- if (!isClosed() && id != null) {
- List<String> names;
- try {
- names = zookeeper.getChildren(id, false);
- if (names.isEmpty())
- return "";
- SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
- for (String name : names) {
- sortedNames.add(new ZNodeName(id + "/" + name));
- }
- return sortedNames.first().getName();
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- // set that we have been interrupted.
- Thread.currentThread().interrupt();
- } catch (KeeperException.NoNodeException e) {
- // do nothing
- } catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw (RuntimeException) new RuntimeException(e.getMessage()).initCause(e);
- }
- }
- return "No lock holder!";
- }
-
- public synchronized void deleteLock(String mainLock) {
- final String id = mainLock;
- if (!isClosed() && id != null) {
- try {
- ZooKeeperOperation zopdel = new ZooKeeperOperation() {
- public boolean execute() throws KeeperException, InterruptedException {
- List<String> names = zookeeper.getChildren(id, false);
- for (String name : names) {
- zookeeper.delete(id + "/" + name, -1);
- }
- zookeeper.delete(id, -1);
- return Boolean.TRUE;
- }
- };
- zopdel.execute();
- } catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- // set that we have been interrupted.
- Thread.currentThread().interrupt();
- } catch (KeeperException.NoNodeException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- // do nothing
- } catch (KeeperException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
- throw (RuntimeException) new RuntimeException(e.getMessage()).initCause(e);
- }
- }
-
- }
-
- /**
- * a zoookeeper operation that is mainly responsible for all the magic required for locking.
- */
- private class LockZooKeeperOperation implements ZooKeeperOperation {
-
- /**
- * find if we have been created earlier if not create our node
- *
- * @param prefix the prefix node
- * @param zookeeper the zookeeper client
- * @param dir the dir parent
- * @throws KeeperException
- * @throws InterruptedException
- */
- private String dir;
- private String id = null;
-
- public String getId() {
- return id;
- }
-
- public LockZooKeeperOperation(String dir) {
- this.dir = dir;
- }
-
- public LockZooKeeperOperation(String dir, String id) {
- this.dir = dir;
- this.id = id;
- }
-
- /**
- * the command that is run and retried for actually obtaining the lock
- *
- * @return if the command was successful or not
- */
- public boolean execute() throws KeeperException, InterruptedException {
- do {
- if (id == null) {
- String prefix = "x-";
- byte[] data = {0x12, 0x34};
- id = zookeeper.create(dir + "/" + prefix, data, getAcl(),
- CreateMode.PERSISTENT_SEQUENTIAL);
-
- if (logger.isDebugEnabled()) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Created id: " + id);
- }
- if (id != null) {
- Stat stat = null;
- try {
- stat = zookeeper.exists(id, false);
- } catch (KeeperException | InterruptedException e1) {
- logger.error(EELFLoggerDelegate.errorLogger, "Error in execute: " + e1);
- }
- Long ctime = stat.getCtime();
- MusicUtil.zkNodeMap.put(id, ctime);
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "INSERT INTO admin.locks(lock_id, ctime) VALUES (?,?)");
- try {
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), id));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), ctime));
- MusicCore.eventualPut(pQuery);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "Error in execute: " + e);
- }
- break;
- }
- }
- if (id != null) {
- List<String> names = zookeeper.getChildren(dir, false);
- if (names.isEmpty()) {
- logger.info(EELFLoggerDelegate.applicationLogger, "No children in: " + dir
- + " when we've just " + "created one! Lets recreate it...");
- // lets force the recreation of the id
- id = null;
- return Boolean.FALSE;
-
- } else {
- // lets sort them explicitly (though they do seem to come back in order
- // ususally :)
- ZNodeName idName = new ZNodeName(id);
- SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
- for (String name : names) {
- sortedNames.add(new ZNodeName(dir + "/" + name));
- }
- if (!sortedNames.contains(idName))
- return Boolean.FALSE;
-
- SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
- if (!lessThanMe.isEmpty()) {
- ZNodeName lastChildName = lessThanMe.last();
- String lastChildId = lastChildName.getName();
- if (logger.isDebugEnabled()) {
- logger.debug(EELFLoggerDelegate.debugLogger, "watching less than me node: " + lastChildId);
- }
- Stat stat = zookeeper.exists(lastChildId, false);
- if (stat != null) {
- return Boolean.FALSE;
- } else {
- logger.info(EELFLoggerDelegate.applicationLogger,
- "Could not find the" + " stats for less than me: "
- + lastChildName.getName());
- }
- } else
- return Boolean.TRUE;
- }
- }
- } while (id == null);
- return Boolean.FALSE;
- }
- }
-
-}
-
diff --git a/src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java b/src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java
deleted file mode 100644
index 7020d14d..00000000
--- a/src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ============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.lockingservice;
-
-import org.apache.zookeeper.KeeperException;
-
-/**
- * A callback object which can be used for implementing retry-able operations in the
- * {@link org.onap.music.lockingservice.ProtocolSupport} class
- *
- */
-public interface ZooKeeperOperation {
-
- /**
- * Performs the operation - which may be involved multiple times if the connection
- * to ZooKeeper closes during this operation
- *
- * @return the result of the operation or null
- * @throws KeeperException FILL IN
- * @throws InterruptedException FILL IN
- */
- public boolean execute() throws KeeperException, InterruptedException;
-}
diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java
index a81887a0..d3654118 100755
--- a/src/main/java/org/onap/music/main/CachingUtil.java
+++ b/src/main/java/org/onap/music/main/CachingUtil.java
@@ -21,24 +21,28 @@
*/
package org.onap.music.main;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.CacheAccess;
+import org.codehaus.jackson.map.ObjectMapper;
import org.mindrot.jbcrypt.BCrypt;
import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.datastore.jsonobjects.AAFResponse;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.datastore.jsonobjects.JsonCallback;
+
+import com.att.eelf.configuration.EELFLogger;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
@@ -61,8 +65,6 @@ public class CachingUtil implements Runnable {
private static CacheAccess<String, Map<String, String>> aafCache = JCS.getInstance("aafCache");
private static CacheAccess<String, String> appNameCache = JCS.getInstance("appNameCache");
private static CacheAccess<String, Map<String, String>> musicValidateCache = JCS.getInstance("musicValidateCache");
- private static CacheAccess<String, JsonCallback> callBackCache = JCS.getInstance("callBackCache");
- private static CacheAccess<String, List<String>> callbackNotifyList = JCS.getInstance("callbackNotifyList");
private static Map<String, Number> userAttempts = new HashMap<>();
private static Map<String, Calendar> lastFailedTime = new HashMap<>();
@@ -71,25 +73,7 @@ public class CachingUtil implements Runnable {
return true;
return false;
}
-
- public static void updateCallBackCache(String appName, JsonCallback jsonCallBack) {
- logger.info("updateCallBackCache: updating cache.....");
- callBackCache.put(appName, jsonCallBack);
- }
-
- public static JsonCallback getCallBackCache(String appName) {
- return callBackCache.get(appName);
- }
- public static void updateCallbackNotifyList(List<String> notifyList) {
- logger.info("callbackNotifyList: updating cache.....");
- callbackNotifyList.put("callbackNotify", notifyList);
- }
-
- public static List<String> getCallbackNotifyList() {
- return callbackNotifyList.get("callbackNotify");
- }
-
public void initializeMusicCache() {
logger.info(EELFLoggerDelegate.applicationLogger,"Initializing Music Cache...");
musicCache.put("isInitialized", "true");
@@ -105,6 +89,7 @@ public class CachingUtil implements Runnable {
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), false));
} catch (Exception e1) {
logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.CACHEERROR, ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ e1.printStackTrace();
}
ResultSet rs = MusicCore.get(pQuery);
Iterator<Row> it = rs.iterator();
@@ -117,8 +102,8 @@ public class CachingUtil implements Runnable {
String keySpace = row.getString("application_name");
try {
userAttempts.put(nameSpace, 0);
- boolean responseObj = triggerAAF(nameSpace, userId, password);
- if (responseObj) {
+ AAFResponse responseObj = triggerAAF(nameSpace, userId, password);
+ if (responseObj.getNs().size() > 0) {
map = new HashMap<>();
map.put(userId, password);
aafCache.put(nameSpace, map);
@@ -129,6 +114,7 @@ public class CachingUtil implements Runnable {
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR);
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Something at AAF was changed for ns: " + nameSpace+" So not updating Cache for the namespace. ");
+ e.printStackTrace();
}
}
@@ -147,7 +133,7 @@ public class CachingUtil implements Runnable {
public static boolean authenticateAAFUser(String nameSpace, String userId, String password,
String keySpace) throws Exception {
- if (aafCache.get(nameSpace) != null && musicCache.get(keySpace)!=null) {
+ if (aafCache.get(nameSpace) != null) {
if (keySpace != null && !musicCache.get(keySpace).equals(nameSpace)) {
logger.info(EELFLoggerDelegate.applicationLogger,"Create new application for the same namespace.");
} else if (aafCache.get(nameSpace).get(userId).equals(password)) {
@@ -178,13 +164,12 @@ public class CachingUtil implements Runnable {
}
}
- boolean responseObj = triggerAAF(nameSpace, userId, password);
- if (responseObj) {
+ AAFResponse responseObj = triggerAAF(nameSpace, userId, password);
+ if (responseObj.getNs().size() > 0) {
//if (responseObj.getNs().get(0).getAdmin().contains(userId)) {
- Map<String, String> map = new HashMap<>();
- map.put(userId, password);
- aafCache.put(nameSpace, map);
- CachingUtil.updateMusicCache(keySpace, nameSpace);
+ //Map<String, String> map = new HashMap<>();
+ //map.put(userId, password);
+ //aafCache.put(nameSpace, map);
return true;
//}
}
@@ -192,7 +177,7 @@ public class CachingUtil implements Runnable {
return false;
}
- private static boolean triggerAAF(String nameSpace, String userId, String password)
+ private static AAFResponse triggerAAF(String nameSpace, String userId, String password)
throws Exception {
if (MusicUtil.getAafEndpointUrl() == null) {
logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
@@ -225,14 +210,14 @@ public class CachingUtil implements Runnable {
// TODO Allow for 2-3 times and forbid any attempt to trigger AAF with invalid values
// for specific time.
}
- /*response.getHeaders().put(HttpHeaders.CONTENT_TYPE,
+ response.getHeaders().put(HttpHeaders.CONTENT_TYPE,
Arrays.asList(MediaType.APPLICATION_JSON));
// AAFResponse output = response.getEntity(AAFResponse.class);
response.bufferEntity();
String x = response.getEntity(String.class);
- AAFResponse responseObj = new ObjectMapper().readValue(x, AAFResponse.class);*/
+ AAFResponse responseObj = new ObjectMapper().readValue(x, AAFResponse.class);
- return true;
+ return responseObj;
}
public static void updateMusicCache(String keyspace, String nameSpace) {
@@ -271,6 +256,7 @@ public class CachingUtil implements Runnable {
appNameCache.put(namespace, isAAF);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
+ e.printStackTrace();
}
}
return isAAF;
@@ -288,6 +274,7 @@ public class CachingUtil implements Runnable {
uuid = rs.getUUID("uuid").toString();
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,"Exception occured during uuid retrieval from DB."+e.getMessage());
+ e.printStackTrace();
}
}
return uuid;
@@ -304,6 +291,7 @@ public class CachingUtil implements Runnable {
appName = rs.getString("application_name");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
+ e.printStackTrace();
}
return appName;
}
@@ -350,6 +338,7 @@ public class CachingUtil implements Runnable {
rs = MusicCore.get(queryObject).one();
} catch (MusicServiceException e) {
// TODO Auto-generated catch block
+ e.printStackTrace();
resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
return resultMap;
} catch (InvalidQueryException e) {
@@ -393,13 +382,14 @@ public class CachingUtil implements Runnable {
try {
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspace));
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ e.printStackTrace();
}
Row rs = null;
try {
rs = MusicCore.get(queryObject).one();
} catch (MusicServiceException e) {
- resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
+ e.printStackTrace();
+ resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
return resultMap;
}
if(rs == null) {
@@ -427,15 +417,4 @@ public class CachingUtil implements Runnable {
CachingUtil.updateMusicValidateCache(nameSpace, userId, pwd);
return resultMap;
}
-
- public static void deleteKeysFromDB(String deleteKeys) {
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "DELETE FROM admin.locks WHERE lock_id IN ("+deleteKeys+")");
- try {
- MusicCore.nonKeyRelatedPut(pQuery, "eventual");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.AUTHENTICATIONERROR, "Error in deleteKeysFromDB");
- }
- }
}
diff --git a/src/main/java/org/onap/music/main/CronJobManager.java b/src/main/java/org/onap/music/main/CronJobManager.java
index 4928044e..5b7a8de4 100644
--- a/src/main/java/org/onap/music/main/CronJobManager.java
+++ b/src/main/java/org/onap/music/main/CronJobManager.java
@@ -32,21 +32,16 @@ import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicLockingException;
import org.onap.music.exceptions.MusicServiceException;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
-//@WebListener
+@WebListener
public class CronJobManager implements ServletContextListener {
private ScheduledExecutorService scheduler;
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CronJobManager.class);
@Override
public void contextInitialized(ServletContextEvent event) {
@@ -58,25 +53,10 @@ public class CronJobManager implements ServletContextListener {
try {
ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
} catch (MusicServiceException e1) {
- logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),ErrorSeverity.ERROR);
+ e1.printStackTrace();
}
-
- //Zookeeper cleanup
- scheduler.scheduleAtFixedRate(new Runnable() {
- @Override
- public void run() {
- deleteLocksFromDB();
- }
- } , 0, 24, TimeUnit.HOURS);
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent event) {
- scheduler.shutdownNow();
- }
-
- public void deleteLocksFromDB() {
- PreparedQueryObject pQuery = new PreparedQueryObject();
+
+ pQuery = new PreparedQueryObject();
pQuery.appendQueryString(
"select * from admin.locks");
try {
@@ -91,22 +71,68 @@ public class CronJobManager implements ServletContextListener {
if(System.currentTimeMillis() >= ctime + 24 * 60 * 60 * 1000) {
expiredKeys = true;
String new_id = id.substring(1);
- try {
- MusicCore.deleteLock(new_id);
- } catch (MusicLockingException e) {
- logger.info(EELFLoggerDelegate.applicationLogger,
- e.getMessage());
- }
- deleteKeys.append("'").append(id).append("'").append(",");
+ MusicCore.deleteLock(new_id);
+ deleteKeys.append(id).append(",");
}
- }
+ else {
+ MusicUtil.zkNodeMap.put(id, ctime);
+ }
+ };
if(expiredKeys) {
deleteKeys.deleteCharAt(deleteKeys.length()-1);
- CachingUtil.deleteKeysFromDB(deleteKeys.toString());
+ deleteKeysFromDB(deleteKeys);
}
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),ErrorSeverity.ERROR);
+ e.printStackTrace();
+ } catch (MusicLockingException e) {
+ e.printStackTrace();
+ }
+
+ //Zookeeper cleanup
+ scheduler.scheduleAtFixedRate(new Runnable() {
+ @Override
+ public void run() {
+ Iterator<Entry<String, Long>> it = MusicUtil.zkNodeMap.entrySet().iterator();
+ StringBuilder deleteKeys = new StringBuilder();
+ Boolean expiredKeys = false;
+ while (it.hasNext()) {
+ Map.Entry<String, Long> pair = (Map.Entry<String, Long>)it.next();
+ long ctime = pair.getValue();
+ if (System.currentTimeMillis() >= ctime + 24 * 60 * 60 * 1000) {
+ try {
+ expiredKeys = true;
+ String id = pair.getKey();
+ deleteKeys.append("'").append(id).append("'").append(",");
+ MusicCore.deleteLock(id.substring(1));
+ MusicUtil.zkNodeMap.remove(id);
+
+ } catch (MusicLockingException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ if(expiredKeys) {
+ deleteKeys.deleteCharAt(deleteKeys.length()-1);
+ deleteKeysFromDB(deleteKeys);
+ }
}
+ } , 0, 24, TimeUnit.HOURS);
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent event) {
+ scheduler.shutdownNow();
+ }
+
+ public void deleteKeysFromDB(StringBuilder deleteKeys) {
+ PreparedQueryObject pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString(
+ "DELETE FROM admin.locks WHERE lock_id IN ("+deleteKeys+")");
+ try {
+ MusicCore.nonKeyRelatedPut(pQuery, "eventual");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java
index 9f7b060b..6b32fc53 100644
--- a/src/main/java/org/onap/music/main/MusicCore.java
+++ b/src/main/java/org/onap/music/main/MusicCore.java
@@ -26,12 +26,13 @@ import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.UUID;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.onap.music.datastore.MusicDataStore;
+import org.onap.music.datastore.CassaDataStore;
+import org.onap.music.datastore.CassaLockStore;
+import org.onap.music.datastore.CassaLockStore.LockObject;
+import org.onap.music.datastore.MusicLockState;
import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
@@ -39,9 +40,6 @@ import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicLockingException;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
-import org.onap.music.lockingservice.MusicLockingService;
import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.ColumnDefinitions.Definition;
@@ -50,6 +48,7 @@ import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.TableMetadata;
+
/**
* This class .....
*
@@ -57,10 +56,11 @@ import com.datastax.driver.core.TableMetadata;
*/
public class MusicCore {
- public static MusicLockingService mLockHandle = null;
- public static MusicDataStore mDstoreHandle = null;
+ public static CassaLockStore mLockHandle = null;
+ public static CassaDataStore mDstoreHandle = null;
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
-
+ private static boolean unitTestRun=true;
+
public static class Condition {
Map<String, Object> conditions;
PreparedQueryObject selectQueryForTheRow;
@@ -73,22 +73,19 @@ public class MusicCore {
public boolean testCondition() throws Exception {
// first generate the row
ResultSet results = quorumGet(selectQueryForTheRow);
- Row row = null;
- if(results != null) {
- row = results.one();
- }
+ Row row = results.one();
return getDSHandle().doesRowSatisfyCondition(row, conditions);
}
}
- public static MusicLockingService getLockingServiceHandle() throws MusicLockingException {
+ public static CassaLockStore getLockingServiceHandle() throws MusicLockingException {
logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring lock store handle");
long start = System.currentTimeMillis();
if (mLockHandle == null) {
try {
- mLockHandle = new MusicLockingService();
+ mLockHandle = new CassaLockStore(getDSHandle());
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKHANDLE,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
throw new MusicLockingException("Failed to aquire Locl store handle " + e);
@@ -104,11 +101,11 @@ public class MusicCore {
* @param remoteIp
* @return
*/
- public static MusicDataStore getDSHandle(String remoteIp) {
+ public static CassaDataStore getDSHandle(String remoteIp) {
logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
long start = System.currentTimeMillis();
if (mDstoreHandle == null) {
- mDstoreHandle = new MusicDataStore(remoteIp);
+ mDstoreHandle = new CassaDataStore(remoteIp);
}
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to acquire data store handle:" + (end - start) + " ms");
@@ -120,15 +117,16 @@ public class MusicCore {
* @return
* @throws MusicServiceException
*/
- public static MusicDataStore getDSHandle() throws MusicServiceException {
+ public static CassaDataStore getDSHandle() throws MusicServiceException {
+
logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring data store handle");
long start = System.currentTimeMillis();
if (mDstoreHandle == null) {
// Quick Fix - Best to put this into every call to getDSHandle?
- if (! "localhost".equals(MusicUtil.getMyCassaHost())) {
- mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
+ if (! MusicUtil.getMyCassaHost().equals("localhost") ) {
+ mDstoreHandle = new CassaDataStore(MusicUtil.getMyCassaHost());
} else {
- mDstoreHandle = new MusicDataStore();
+ mDstoreHandle = new CassaDataStore();
}
}
if(mDstoreHandle.getSession() == null) {
@@ -142,232 +140,160 @@ public class MusicCore {
return mDstoreHandle;
}
- public static String createLockReference(String lockName) {
+ public static String createLockReference(String fullyQualifiedKey) {
+ String[] splitString = fullyQualifiedKey.split("\\.");
+ String keyspace = splitString[0];
+ String table = splitString[1];
+ String lockName = splitString[2];
+
logger.info(EELFLoggerDelegate.applicationLogger,"Creating lock reference for lock name:" + lockName);
long start = System.currentTimeMillis();
- String lockId = null;
+ String lockReference = null;
try {
- lockId = getLockingServiceHandle().createLockId("/" + lockName);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.CREATELOCK+lockName,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
-
- }
+ lockReference = "" + getLockingServiceHandle().genLockRefandEnQueue(keyspace, table, lockName);
+ } catch (MusicLockingException | MusicServiceException | MusicQueryException e) {
+ e.printStackTrace();
+ }
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to create lock reference:" + (end - start) + " ms");
- return lockId;
- }
-
- /**
- *
- * @param key
- * @return
- */
- public static boolean isTableOrKeySpaceLock(String key) {
- String[] splitString = key.split("\\.");
- if (splitString.length > 2)
- return false;
- else
- return true;
+ return lockReference;
}
- /**
- *
- * @param key
- * @return
- */
- public static MusicLockState getMusicLockState(String key) {
- long start = System.currentTimeMillis();
- try {
- String[] splitString = key.split("\\.");
- String keyspaceName = splitString[0];
- String tableName = splitString[1];
- String primaryKey = splitString[2];
- MusicLockState mls;
- String lockName = keyspaceName + "." + tableName + "." + primaryKey;
- mls = getLockingServiceHandle().getLockState(lockName);
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to get lock state:" + (end - start) + " ms");
- return mls;
- } catch (NullPointerException | MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- return null;
- }
- public static ReturnType acquireLockWithLease(String key, String lockId, long leasePeriod) {
- try {
- long start = System.currentTimeMillis();
- /* check if the current lock has exceeded its lease and if yes, release that lock */
- MusicLockState mls = getMusicLockState(key);
- if (mls != null) {
- if (mls.getLockStatus().equals(LockStatus.LOCKED)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"The current lock holder for " + key + " is " + mls.getLockHolder()
- + ". Checking if it has exceeded lease");
- long currentLockPeriod = System.currentTimeMillis() - mls.getLeaseStartTime();
- long currentLeasePeriod = mls.getLeasePeriod();
- if (currentLockPeriod > currentLeasePeriod) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Lock period " + currentLockPeriod
- + " has exceeded lease period " + currentLeasePeriod);
- boolean voluntaryRelease = false;
- String currentLockHolder = mls.getLockHolder();
- mls = releaseLock(currentLockHolder, voluntaryRelease);
- }
- }
- } else
- logger.error(EELFLoggerDelegate.errorLogger,key, AppMessages.INVALIDLOCK,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
-
- /*
- * call the traditional acquire lock now and if the result returned is true, set the
- * begin time-stamp and lease period
- */
- if (acquireLock(key, lockId).getResult() == ResultType.SUCCESS) {
- mls = getMusicLockState(key);// get latest state
- if ( mls == null ) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Music Lock State is null");
- return new ReturnType(ResultType.FAILURE, "Could not acquire lock, Lock State is null");
- }
- if (mls.getLeaseStartTime() == -1) {// set it again only if it is not set already
- mls.setLeaseStartTime(System.currentTimeMillis());
- mls.setLeasePeriod(leasePeriod);
- getLockingServiceHandle().setLockState(key, mls);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to acquire leased lock:" + (end - start) + " ms");
- return new ReturnType(ResultType.SUCCESS, "Accquired lock");
- } else {
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to fail to acquire leased lock:" + (end - start) + " ms");
- return new ReturnType(ResultType.FAILURE, "Could not acquire lock");
- }
- } catch (Exception e) {
- StringWriter sw = new StringWriter();
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR506E] Failed to aquire lock ",ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
-
- String exceptionAsString = sw.toString();
- return new ReturnType(ResultType.FAILURE,
- "Exception thrown in acquireLockWithLease:\n" + exceptionAsString);
- }
+ public static ReturnType acquireLockWithLease(String fullyQualifiedKey, String lockReference, long leasePeriod) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ evictExpiredLockHolder(fullyQualifiedKey,leasePeriod);
+ return acquireLock(fullyQualifiedKey, lockReference);
}
- public static ReturnType acquireLock(String key, String lockId) throws MusicLockingException {
- /*
- * first check if I am on top. Since ids are not reusable there is no need to check
- * lockStatus If the status is unlocked, then the above call will automatically return
- * false.
- */
- Boolean result = false;
- try {
- result = getLockingServiceHandle().isMyTurn(lockId);
- } catch (MusicLockingException e2) {
- logger.error(EELFLoggerDelegate.errorLogger,AppMessages.INVALIDLOCK + lockId + " " + e2);
- throw new MusicLockingException();
- }
- if (!result) {
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Not your turn, someone else has the lock");
- try {
- if (!getLockingServiceHandle().lockIdExists(lockId)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "In acquire lock: this lockId doesn't exist");
- return new ReturnType(ResultType.FAILURE, "Lockid doesn't exist");
- }
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK+lockId,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- throw new MusicLockingException();
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: returning failure");
- return new ReturnType(ResultType.FAILURE, "Not your turn, someone else has the lock");
- }
-
-
- // this is for backward compatibility where locks could also be acquired on just
- // keyspaces or tables.
- if (isTableOrKeySpaceLock(key)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: A table or keyspace lock so no need to perform sync...so returning true");
- return new ReturnType(ResultType.SUCCESS, "A table or keyspace lock so no need to perform sync...so returning true");
- }
+ private static void evictExpiredLockHolder(String fullyQualifiedKey, long leasePeriod) throws MusicLockingException, MusicQueryException, MusicServiceException {
- // read the lock name corresponding to the key and if the status is locked or being locked,
- // then return false
- MusicLockState currentMls = null;
- MusicLockState newMls = null;
- try {
- currentMls = getMusicLockState(key);
- String currentLockHolder = null;
- if(currentMls != null) { currentLockHolder = currentMls.getLockHolder(); };
- if (lockId.equals(currentLockHolder)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: You already have the lock!");
- return new ReturnType(ResultType.SUCCESS, "You already have the lock!");
- }
- } catch (NullPointerException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.INVALIDLOCK+lockId,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
-
- // change status to "being locked". This state transition is necessary to ensure syncing
- // before granting the lock
- String lockHolder = null;
- boolean needToSyncQuorum = false;
- if (currentMls != null)
- needToSyncQuorum = currentMls.isNeedToSyncQuorum();
+ String[] splitString = fullyQualifiedKey.split("\\.");
+ String keyspace = splitString[0];
+ String table = splitString[1];
+ String primaryKeyValue = splitString[2];
+ LockObject currentLockHolderObject = getLockingServiceHandle().peekLockQueue(keyspace, table, primaryKeyValue);
+
+ /* Release the lock of the previous holder if it has expired. if the update to the acquire time has not reached due to network delays, simply use the create time as the
+ * reference*/
+
+ long referenceTime = Math.max(Long.parseLong(currentLockHolderObject.acquireTime), Long.parseLong(currentLockHolderObject.createTime));
+ if((System.currentTimeMillis() - referenceTime) > leasePeriod) {
+ forciblyReleaseLock(fullyQualifiedKey, currentLockHolderObject.lockRef+"");
+ logger.info(EELFLoggerDelegate.applicationLogger, currentLockHolderObject.lockRef+" forcibly released");
+ }
+ }
+
+ private static ReturnType isTopOfLockStore(String keyspace, String table, String primaryKeyValue, String lockReference) throws MusicLockingException, MusicQueryException, MusicServiceException {
+
+ //return failure to lock holders too early or already evicted from the lock store
+ String topOfLockStoreS = getLockingServiceHandle().peekLockQueue(keyspace, table, primaryKeyValue).lockRef;
+ long topOfLockStoreL = Long.parseLong(topOfLockStoreS);
+ long lockReferenceL = Long.parseLong(lockReference);
- newMls = new MusicLockState(MusicLockState.LockStatus.BEING_LOCKED, lockHolder,
- needToSyncQuorum);
- try {
- getLockingServiceHandle().setLockState(key, newMls);
- } catch (MusicLockingException e1) {
- logger.error(EELFLoggerDelegate.errorLogger,e1.getMessage(), AppMessages.LOCKSTATE+key,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ if(lockReferenceL > topOfLockStoreL) {
+ logger.info(EELFLoggerDelegate.applicationLogger, lockReference+" is not the lock holder yet");
+ return new ReturnType(ResultType.FAILURE, lockReference+" is not the lock holder yet");
}
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Set lock state to being_locked");
+
- // do syncing if this was a forced lock release
- if (needToSyncQuorum) {
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Since there was a forcible release, need to sync quorum!");
- try {
- syncQuorum(key);
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to set Lock state " + e);
- }
- }
+ if(lockReferenceL < topOfLockStoreL) {
+ logger.info(EELFLoggerDelegate.applicationLogger, lockReference+" is no longer/or was never in the lock store queue");
+ return new ReturnType(ResultType.FAILURE, lockReference+" is no longer/or was never in the lock store queue");
+ }
+
+ return new ReturnType(ResultType.SUCCESS, lockReference+" is top of lock store");
+ }
+
+ public static ReturnType acquireLock(String fullyQualifiedKey, String lockReference) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ String[] splitString = fullyQualifiedKey.split("\\.");
+ String keyspace = splitString[0];
+ String table = splitString[1];
+ String primaryKeyValue = splitString[2];
- // change status to locked
- lockHolder = lockId;
- needToSyncQuorum = false;
- newMls = new MusicLockState(MusicLockState.LockStatus.LOCKED, lockHolder, needToSyncQuorum);
- try {
- getLockingServiceHandle().setLockState(key, newMls);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKSTATE+key,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"In acquire lock: Set lock state to locked and assigned current lock ref "
- + lockId + " as holder");
+ ReturnType result = isTopOfLockStore(keyspace, table, primaryKeyValue, lockReference);
- return new ReturnType(result?ResultType.SUCCESS:ResultType.FAILURE, "Set lock state to locked and assigned a lock holder");
+ if(result.getResult().equals(ResultType.FAILURE))
+ return result;//not top of the lock store q
+
+ //check to see if the value of the key has to be synced in case there was a forceful release
+ String syncTable = keyspace+".unsyncedKeys_"+table;
+ String query = "select * from "+syncTable+" where key='"+fullyQualifiedKey+"';";
+ PreparedQueryObject readQueryObject = new PreparedQueryObject();
+ readQueryObject.appendQueryString(query);
+ ResultSet results = getDSHandle().executeCriticalGet(readQueryObject);
+ if (results.all().size() != 0) {
+ logger.info("In acquire lock: Since there was a forcible release, need to sync quorum!");
+ try {
+ syncQuorum(keyspace, table, primaryKeyValue);
+ } catch (Exception e) {
+ StringWriter sw = new StringWriter();
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR506E] Failed to aquire lock ",ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ String exceptionAsString = sw.toString();
+ return new ReturnType(ResultType.FAILURE, "Exception thrown while syncing key:\n" + exceptionAsString);
+ }
+ String cleanQuery = "delete * from music_internal.unsynced_keys where key='"+fullyQualifiedKey+"';";
+ PreparedQueryObject deleteQueryObject = new PreparedQueryObject();
+ deleteQueryObject.appendQueryString(cleanQuery);
+ getDSHandle().executePut(deleteQueryObject, "critical");
+ }
+
+ getLockingServiceHandle().updateLockAcquireTime(keyspace, table, primaryKeyValue, lockReference);
+
+ return new ReturnType(ResultType.SUCCESS, lockReference+" is the lock holder for the key");
}
/**
*
- * @param keyspaceName
- * @param kspObject
- * @return
- * @throws Exception
+ * @param tableQueryObject
+ * @param consistency
+ * @return Boolean Indicates success or failure
+ * @throws MusicServiceException
+ *
+ *
*/
- public boolean createKeyspace(String keyspaceName, JsonKeySpace kspObject) throws Exception {
- return true;
- }
-
-
- private static void syncQuorum(String key) throws Exception {
+ public static ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject, String consistency) throws MusicServiceException {
+ boolean result = false;
+
+ try {
+ //create shadow locking table
+ result = getLockingServiceHandle().createLockQueue(keyspace, table);
+ if(result == false)
+ return ResultType.FAILURE;
+
+ result = false;
+
+ //create table to track unsynced_keys
+ table = "unsyncedKeys_"+table;
+
+ String tabQuery = "CREATE TABLE IF NOT EXISTS "+keyspace+"."+table
+ + " ( key text,PRIMARY KEY (key) );";
+ System.out.println(tabQuery);
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+
+ queryObject.appendQueryString(tabQuery);
+ result = false;
+ result = getDSHandle().executePut(queryObject, "eventual");
+
+
+ //create actual table
+ result = getDSHandle().executePut(tableQueryObject, consistency);
+ } catch (MusicQueryException | MusicServiceException | MusicLockingException ex) {
+ logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ throw new MusicServiceException(ex.getMessage());
+ }
+ return result?ResultType.SUCCESS:ResultType.FAILURE;
+ }
+
+ private static void syncQuorum(String keyspace, String table, String primaryKeyValue) throws Exception {
logger.info(EELFLoggerDelegate.applicationLogger,"Performing sync operation---");
- String[] splitString = key.split("\\.");
- String keyspaceName = splitString[0];
- String tableName = splitString[1];
- String primaryKeyValue = splitString[2];
PreparedQueryObject selectQuery = new PreparedQueryObject();
PreparedQueryObject updateQuery = new PreparedQueryObject();
// get the primary key d
- TableMetadata tableInfo = returnColumnMetadata(keyspaceName, tableName);
+ TableMetadata tableInfo = returnColumnMetadata(keyspace, table);
String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();// we only support single
// primary key
DataType primaryKeyType = tableInfo.getPrimaryKey().get(0).getType();
@@ -375,7 +301,7 @@ public class MusicCore {
MusicUtil.convertToActualDataType(primaryKeyType, primaryKeyValue);
// get the row of data from a quorum
- selectQuery.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName + " WHERE "
+ selectQuery.appendQueryString("SELECT * FROM " + keyspace + "." + table + " WHERE "
+ primaryKeyName + "= ?" + ";");
selectQuery.addValue(cqlFormattedPrimaryKeyValue);
ResultSet results = null;
@@ -400,7 +326,7 @@ public class MusicCore {
fieldValueString.append(",");
counter = counter + 1;
}
- updateQuery.appendQueryString("UPDATE " + keyspaceName + "." + tableName + " SET "
+ updateQuery.appendQueryString("UPDATE " + keyspace + "." + table + " SET "
+ fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
updateQuery.addValue(cqlFormattedPrimaryKeyValue);
@@ -442,81 +368,68 @@ public class MusicCore {
/**
*
- * @param lockName
+ * @param fullyQualifiedKey lockName
* @return
*/
- public static String whoseTurnIsIt(String lockName) {
-
+ public static String whoseTurnIsIt(String fullyQualifiedKey) {
+ String[] splitString = fullyQualifiedKey.split("\\.");
+ String keyspace = splitString[0];
+ String table = splitString[1];
+ String primaryKeyValue = splitString[2];
try {
- return getLockingServiceHandle().whoseTurnIsIt("/" + lockName) + "";
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKINGERROR+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ return getLockingServiceHandle().peekLockQueue(keyspace, table, primaryKeyValue)+"";
+ } catch (MusicLockingException | MusicServiceException | MusicQueryException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKINGERROR+fullyQualifiedKey ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
return null;
-
-
}
/**
*
- * @param lockId
+ * @param lockReference
* @return
*/
- public static String getLockNameFromId(String lockId) {
- StringTokenizer st = new StringTokenizer(lockId);
+ public static String getLockNameFromId(String lockReference) {
+ StringTokenizer st = new StringTokenizer(lockReference);
return st.nextToken("$");
}
- public static void destroyLockRef(String lockId) {
+ public static MusicLockState destroyLockRef(String fullyQualifiedKey, String lockReference) {
long start = System.currentTimeMillis();
+ String[] splitString = fullyQualifiedKey.split("\\.");
+ String keyspace = splitString[0];
+ String table = splitString[1];
+ String primaryKeyValue = splitString[2];
try {
- getLockingServiceHandle().unlockAndDeleteId(lockId);
- } catch (MusicLockingException | NoNodeException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DESTROYLOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
+ getLockingServiceHandle().deQueueLockRef(keyspace, table, primaryKeyValue, lockReference);
+ } catch (MusicLockingException | MusicServiceException | MusicQueryException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DESTROYLOCK+lockReference ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
}
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to destroy lock reference:" + (end - start) + " ms");
+ return getMusicLockState(fullyQualifiedKey);
}
- public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) {
- long start = System.currentTimeMillis();
- try {
- getLockingServiceHandle().unlockAndDeleteId(lockId);
- } catch (MusicLockingException e1) {
- logger.error(EELFLoggerDelegate.errorLogger,e1.getMessage(), AppMessages.RELEASELOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- } catch (KeeperException.NoNodeException nne) {
- logger.error(EELFLoggerDelegate.errorLogger,"Failed to release Lock " + lockId + " " + nne);
- MusicLockState mls = new MusicLockState("Lock doesn't exists. Release lock operation failed.");
- return mls;
- }
- String lockName = getLockNameFromId(lockId);
- MusicLockState mls;
- String lockHolder = null;
- if (voluntaryRelease) {
- mls = new MusicLockState(MusicLockState.LockStatus.UNLOCKED, lockHolder);
- logger.info(EELFLoggerDelegate.applicationLogger,"In unlock: lock voluntarily released for " + lockId);
- } else {
- boolean needToSyncQuorum = true;
- mls = new MusicLockState(MusicLockState.LockStatus.UNLOCKED, lockHolder,
- needToSyncQuorum);
- logger.info(EELFLoggerDelegate.applicationLogger,"In unlock: lock forcibly released for " + lockId);
- }
- try {
- getLockingServiceHandle().setLockState(lockName, mls);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.RELEASELOCK+lockId ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to release lock:" + (end - start) + " ms");
- return mls;
- }
-
- public static void voluntaryReleaseLock(String lockId) throws MusicLockingException{
- try {
- getLockingServiceHandle().unlockAndDeleteId(lockId);
- } catch (KeeperException.NoNodeException e) {
- // ??? No way
- }
+ public static MusicLockState voluntaryReleaseLock(String fullyQualifiedKey, String lockReference) throws MusicLockingException{
+ return destroyLockRef(fullyQualifiedKey, lockReference);
+ }
+
+ public static MusicLockState forciblyReleaseLock(String fullyQualifiedKey, String lockReference) throws MusicLockingException, MusicServiceException, MusicQueryException{
+ String[] splitString = fullyQualifiedKey.split("\\.");
+ String keyspace = splitString[0];
+ String table = splitString[1];
+
+ //leave a signal that this key could potentially be unsynchronized
+ String syncTable = keyspace+".unsyncedKeys_"+table;
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ String values = "(?)";
+ queryObject.addValue(fullyQualifiedKey);
+ String insQuery = "insert into "+syncTable+" (key) values "+values+"';";
+ queryObject.appendQueryString(insQuery);
+ getDSHandle().executePut(queryObject, "critical");
+
+ //now release the lock
+ return destroyLockRef(fullyQualifiedKey, lockReference);
}
/**
@@ -525,17 +438,8 @@ public class MusicCore {
* @throws MusicLockingException
*/
public static void deleteLock(String lockName) throws MusicLockingException {
- long start = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Deleting lock for " + lockName);
- try {
- getLockingServiceHandle().deleteLock("/" + lockName);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DELTELOCK+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- throw new MusicLockingException(e.getMessage());
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to delete lock:" + (end - start) + " ms");
- }
+ //deprecated
+ }
@@ -551,63 +455,12 @@ public class MusicCore {
}
- /**
- *
- * @param nodeName
- */
- public static void pureZkCreate(String nodeName) {
- try {
- getLockingServiceHandle().getzkLockHandle().createNode(nodeName);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- }
-
- /**
- *
- * @param nodeName
- * @param data
- */
- public static void pureZkWrite(String nodeName, byte[] data) {
- long start = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Performing zookeeper write to " + nodeName);
- try {
- getLockingServiceHandle().getzkLockHandle().setNodeData(nodeName, data);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"Performed zookeeper write to " + nodeName);
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the actual zk put:" + (end - start) + " ms");
- }
-
- /**
- *
- * @param nodeName
- * @return
- */
- public static byte[] pureZkRead(String nodeName) {
- long start = System.currentTimeMillis();
- byte[] data = null;
- try {
- data = getLockingServiceHandle().getzkLockHandle().getNodeData(nodeName);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the actual zk put:" + (end - start) + " ms");
- return data;
- }
-
// Prepared Query Additions.
/**
*
- * @param keyspaceName
- * @param tableName
- * @param primaryKey
* @param queryObject
* @return ReturnType
* @throws MusicServiceException
@@ -627,52 +480,51 @@ public class MusicCore {
return new ReturnType(ResultType.FAILURE, "Failure");
}
}
-
+
/**
*
- * @param keyspaceName
- * @param tableName
- * @param primaryKey
+ * @param keyspace
+ * @param table
+ * @param primaryKeyValue
* @param queryObject
- * @param lockId
+ * @param lockReference
* @return
*/
- public static ReturnType criticalPut(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject, String lockId, Condition conditionInfo) {
+ public static ReturnType criticalPut(String keyspace, String table, String primaryKeyValue,
+ PreparedQueryObject queryObject, String lockReference, Condition conditionInfo) {
long start = System.currentTimeMillis();
-
try {
- MusicLockState mls = getLockingServiceHandle()
- .getLockState(keyspaceName + "." + tableName + "." + primaryKey);
- if (mls.getLockHolder().equals(lockId) == true) {
- if (conditionInfo != null)
- try {
- if (conditionInfo.testCondition() == false)
- return new ReturnType(ResultType.FAILURE,
- "Lock acquired but the condition is not true");
- } catch (Exception e) {
- return new ReturnType(ResultType.FAILURE,
- "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
- + e.getMessage());
- }
- getDSHandle().executePut(queryObject, MusicUtil.CRITICAL);
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the critical put:" + (end - start) + " ms");
- return new ReturnType(ResultType.SUCCESS, "Update performed");
- } else
- return new ReturnType(ResultType.FAILURE,
- "Cannot perform operation since you are the not the lock holder");
- } catch (MusicQueryException | MusicServiceException e) {
+ ReturnType result = isTopOfLockStore(keyspace, table, primaryKeyValue, lockReference);
+ if(result.getResult().equals(ResultType.FAILURE))
+ return result;//not top of the lock store q
+
+ if (conditionInfo != null)
+ try {
+ if (conditionInfo.testCondition() == false)
+ return new ReturnType(ResultType.FAILURE,
+ "Lock acquired but the condition is not true");
+ } catch (Exception e) {
+ return new ReturnType(ResultType.FAILURE,
+ "Exception thrown while checking the condition, check its sanctity:\n"
+ + e.getMessage());
+ }
+
+ String query = queryObject.getQuery();
+ query = query.replaceFirst("SET", "using TIMESTAMP "+ v2sTimeStampInMicroseconds(lockReference, System.currentTimeMillis())+ " SET");
+ queryObject.replaceQueryString(query);
+ getDSHandle().executePut(queryObject, MusicUtil.CRITICAL);
+ long end = System.currentTimeMillis();
+ logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the critical put:" + (end - start) + " ms");
+ }catch (MusicQueryException | MusicServiceException | MusicLockingException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
return new ReturnType(ResultType.FAILURE,
- "Exception thrown while doing the critical put, check sanctity of the row/conditions:\n"
+ "Exception thrown while doing the critical put\n"
+ e.getMessage());
- }catch(MusicLockingException ex){
- return new ReturnType(ResultType.FAILURE,ex.getMessage());
}
-
+ return new ReturnType(ResultType.SUCCESS, "Update performed");
}
+
/**
*
* @param queryObject
@@ -689,10 +541,11 @@ public class MusicCore {
try {
result = getDSHandle().executePut(queryObject, consistency);
} catch (MusicQueryException | MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(), AppMessages.UNKNOWNERROR,
+ ErrorSeverity.WARN, ErrorTypes.MUSICSERVICEERROR);
throw new MusicServiceException(ex.getMessage());
}
- return result?ResultType.SUCCESS:ResultType.FAILURE;
+ return result ? ResultType.SUCCESS : ResultType.FAILURE;
}
/**
@@ -712,46 +565,29 @@ public class MusicCore {
}
return results;
}
-
- public static String getMyHostId() {
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString("SELECT HOST_ID FROM SYSTEM.LOCAL");
- ResultSet rs = null;
- try {
- rs = getDSHandle().executeEventualGet(pQuery);
- Row row = rs.one();
- return (row == null) ? "UNKNOWN" : row.getUUID("HOST_ID").toString();
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
- }
- logger.error(EELFLoggerDelegate.errorLogger, "Some issue during MusicCore.getMyHostId");
- return "UNKNOW";
- }
/**
* This method performs DDL operations on cassandra, if the the resource is available. Lock ID
* is used to check if the resource is free.
*
- * @param keyspaceName name of the keyspace
- * @param tableName name of the table
- * @param primaryKey primary key value
+ * @param keyspace name of the keyspace
+ * @param table name of the table
+ * @param primaryKeyValue primary key value
* @param queryObject query object containing prepared query and values
- * @param lockId lock ID to check if the resource is free to perform the operation.
+ * @param lockReference lock ID to check if the resource is free to perform the operation.
* @return ResultSet
*/
- public static ResultSet criticalGet(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject, String lockId) throws MusicServiceException {
+ public static ResultSet criticalGet(String keyspace, String table, String primaryKeyValue,
+ PreparedQueryObject queryObject, String lockReference) throws MusicServiceException {
ResultSet results = null;
+
try {
- MusicLockState mls = getLockingServiceHandle()
- .getLockState(keyspaceName + "." + tableName + "." + primaryKey);
- if (mls.getLockHolder().equals(lockId)) {
+ ReturnType result = isTopOfLockStore(keyspace, table, primaryKeyValue, lockReference);
+ if(result.getResult().equals(ResultType.FAILURE))
+ return null;//not top of the lock store q
results = getDSHandle().executeCriticalGet(queryObject);
- } else
- throw new MusicServiceException("YOU DO NOT HAVE THE LOCK");
} catch (MusicQueryException | MusicServiceException | MusicLockingException 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);
}
return results;
}
@@ -765,22 +601,23 @@ public class MusicCore {
* @param queryObject query object containing prepared query and values
* @return ReturnType
* @throws MusicLockingException
+ * @throws MusicServiceException
+ * @throws MusicQueryException
*/
public static ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
-
+ PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException, MusicQueryException, MusicServiceException {
long start = System.currentTimeMillis();
- String key = keyspaceName + "." + tableName + "." + primaryKey;
- String lockId = createLockReference(key);
+ String fullyQualifiedKey = keyspaceName + "." + tableName + "." + primaryKey;
+ String lockReference = createLockReference(fullyQualifiedKey);
long lockCreationTime = System.currentTimeMillis();
- ReturnType lockAcqResult = acquireLock(key, lockId);
+ ReturnType lockAcqResult = acquireLock(fullyQualifiedKey, lockReference);
long lockAcqTime = System.currentTimeMillis();
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
+ logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockReference);
ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
- queryObject, lockId, conditionInfo);
+ queryObject, lockReference, conditionInfo);
long criticalPutTime = System.currentTimeMillis();
- voluntaryReleaseLock(lockId);
+ voluntaryReleaseLock(fullyQualifiedKey,lockReference);
long lockDeleteTime = System.currentTimeMillis();
String timingInfo = "|lock creation time:" + (lockCreationTime - start)
+ "|lock accquire time:" + (lockAcqTime - lockCreationTime)
@@ -789,49 +626,8 @@ public class MusicCore {
criticalPutResult.setTimingInfo(timingInfo);
return criticalPutResult;
} else {
- logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
- destroyLockRef(lockId);
- return lockAcqResult;
- }
- }
-
- /**
- * this function is mainly for the benchmarks to see the effect of lock deletion.
- *
- * @param keyspaceName
- * @param tableName
- * @param primaryKey
- * @param queryObject
- * @param conditionInfo
- * @return
- * @throws MusicLockingException
- */
- public static ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName,
- String primaryKey, PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
-
- long start = System.currentTimeMillis();
- String key = keyspaceName + "." + tableName + "." + primaryKey;
- String lockId = createLockReference(key);
- long lockCreationTime = System.currentTimeMillis();
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = acquireLock(key, lockId);
- long lockAcqTime = System.currentTimeMillis();
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
- ReturnType criticalPutResult = criticalPut(keyspaceName, tableName, primaryKey,
- queryObject, lockId, conditionInfo);
- long criticalPutTime = System.currentTimeMillis();
- deleteLock(key);
- long lockDeleteTime = System.currentTimeMillis();
- String timingInfo = "|lock creation time:" + (lockCreationTime - start)
- + "|lock accquire time:" + (lockAcqTime - lockCreationTime)
- + "|critical put time:" + (criticalPutTime - lockAcqTime)
- + "|lock delete time:" + (lockDeleteTime - criticalPutTime) + "|";
- criticalPutResult.setTimingInfo(timingInfo);
- return criticalPutResult;
- } else {
- logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
- deleteLock(key);
+ logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockReference);
+ voluntaryReleaseLock(fullyQualifiedKey,lockReference);
return lockAcqResult;
}
}
@@ -849,47 +645,31 @@ public class MusicCore {
* @return ResultSet
* @throws MusicServiceException
* @throws MusicLockingException
+ * @throws MusicQueryException
*/
public static ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
- String key = keyspaceName + "." + tableName + "." + primaryKey;
- String lockId = createLockReference(key);
+ PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException {
+ String fullyQualifiedKey = keyspaceName + "." + tableName + "." + primaryKey;
+ String lockReference = createLockReference(fullyQualifiedKey);
long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = acquireLock(key, lockId);
+ ReturnType lockAcqResult = acquireLock(fullyQualifiedKey, lockReference);
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
+ logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockReference);
ResultSet result =
- criticalGet(keyspaceName, tableName, primaryKey, queryObject, lockId);
- voluntaryReleaseLock(lockId);
+ criticalGet(keyspaceName, tableName, primaryKey, queryObject, lockReference);
+ voluntaryReleaseLock(fullyQualifiedKey,lockReference);
return result;
} else {
- destroyLockRef(lockId);
- logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockId);
+ voluntaryReleaseLock(fullyQualifiedKey,lockReference);
+ logger.info(EELFLoggerDelegate.applicationLogger,"unable to acquire lock, id " + lockReference);
return null;
}
}
- public static ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
- PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
- String key = keyspaceName + "." + tableName + "." + primaryKey;
- String lockId = createLockReference(key);
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
-
- ReturnType lockAcqResult = acquireLock(key, lockId);
-
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "acquired lock with id " + lockId);
- ResultSet result = criticalGet(keyspaceName, tableName, primaryKey, queryObject, lockId);
- deleteLock(key);
- return result;
- } else {
- deleteLock(key);
- logger.info(EELFLoggerDelegate.applicationLogger, "unable to acquire lock, id " + lockId);
- return null;
- }
- }
-
+ public static MusicLockState getMusicLockState(String fullyQualifiedKey) {
+ return null;
+ }
/**
* authenticate user logic
@@ -903,7 +683,7 @@ public class MusicCore {
* @return
* @throws Exception
*/
- public static Map<String, Object> autheticateUser(String nameSpace, String userId,
+ public static Map<String, Object> authenticate(String nameSpace, String userId,
String password, String keyspace, String aid, String operation)
throws Exception {
Map<String, Object> resultMap = new HashMap<>();
@@ -999,4 +779,38 @@ public class MusicCore {
resultMap.put("keyspace",keyspace);
return resultMap;
}
+
+
+ /**
+ * Given the time of write for an update in a critical section, this method provides a transformed timestamp
+ * that ensures that a previous lock holder who is still alive can never corrupt a later critical section.
+ * The main idea is to us the lock reference to clearly demarcate the timestamps across critical sections.
+ * @param the UUID lock reference associated with the write.
+ * @param the long timeOfWrite which is the actual time at which the write took place
+ * @throws MusicServiceException
+ * @throws MusicQueryException
+ */
+ private static long v2sTimeStampInMicroseconds(String lockReference, long timeOfWrite) throws MusicServiceException, MusicQueryException{
+ long lockEpochMillis = Long.parseLong(lockReference);
+
+ long lockEternityMillis = lockEpochMillis - MusicUtil.MusicEternityEpochMillis;
+
+ long ts = lockEternityMillis * MusicUtil.MaxCriticalSectionDurationMillis
+ + (timeOfWrite - lockEpochMillis);
+
+ return ts;
+
+// long test = (lockReferenceUUID.timestamp()-MusicUtil.MusicEternityEpochMillis);
+// long timeStamp = (lockReferenceUUID.timestamp()-MusicUtil.MusicEternityEpochMillis)*MusicUtil.MaxCriticalSectionDurationMillis
+// +timeOfWrite;
+// return timeStamp;
+
+// return timeOfWrite*1000;
+ }
+
+ public static void main(String[] args) {
+ String x = "axe top";
+ x = x.replaceFirst("top", "sword");
+ System.out.print(x); //returns sword pickaxe
+ }
}
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
index cfad845d..c11b4c7e 100755
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/src/main/java/org/onap/music/main/MusicUtil.java
@@ -23,15 +23,12 @@ package org.onap.music.main;
import java.io.File;
import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.UUID;
@@ -72,8 +69,7 @@ public class MusicUtil {
public static final String UPSERT = "upsert";
public static final String USERID = "userId";
public static final String PASSWORD = "password";
-
- public static final String AUTHORIZATION = "Authorization";
+ public static final String AUTHORIZATION = "Authorization";
private static final String LOCALHOST = "localhost";
private static final String PROPERTIES_FILE = "/opt/app/music/etc/music.properties";
@@ -85,10 +81,6 @@ public class MusicUtil {
private static String myZkHost = LOCALHOST;
private static String myCassaHost = LOCALHOST;
private static String defaultMusicIp = LOCALHOST;
- private static int cassandraPort = 9042;
- private static int notifytimeout = 30000;
- private static int notifyinterval = 5000;
-
private static boolean debug = true;
private static String version = "2.3.0";
private static String musicRestIp = LOCALHOST;
@@ -96,31 +88,22 @@ public class MusicUtil {
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",
- "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url","cassandra.port", "notify.timeout", "notify.interval" };
+ "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url" };
private static String cassName = "cassandra";
private static String cassPwd;
private static String aafEndpointUrl = null;
- public static final ConcurrentMap<String, Long> zkNodeMap = new ConcurrentHashMap<>();
+ public static ConcurrentMap<String, Long> zkNodeMap = new ConcurrentHashMap<>();
+
+ public static final long MusicEternityEpochMillis = 1533081600000L; // Wednesday, August 1, 2018 12:00:00 AM
+
+ public static final long MaxCriticalSectionDurationMillis = 1L * 24 * 60 * 60 * 1000; // 1 day
private MusicUtil() {
throw new IllegalStateException("Utility Class");
}
- /**
- *
- * @return cassandra port
- */
- public static int getCassandraPort() {
- return cassandraPort;
- }
-
- /**
- * set cassandra port
- * @param cassandraPort
- */
- public static void setCassandraPort(int cassandraPort) {
- MusicUtil.cassandraPort = cassandraPort;
- }
+
+
/**
* @return the cassName
*/
@@ -583,51 +566,5 @@ public class MusicUtil {
return authValues;
}
-
- public static void loadProperties() throws Exception {
- Properties prop = new Properties();
- InputStream input = null;
- try {
- // load the properties file
- input = MusicUtil.class.getClassLoader().getResourceAsStream("music.properties");
- prop.load(input);
- } catch (Exception ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "Unable to find properties file.");
- throw new Exception();
- } finally {
- if (input != null) {
- try {
- input.close();
- } catch (IOException e) {
- logger.error(EELFLoggerDelegate.applicationLogger,"Load properties failed "+e.getMessage(),e);
- }
- }
- }
- // get the property value and return it
- MusicUtil.setMyCassaHost(prop.getProperty("cassandra.host"));
- String zkHosts = prop.getProperty("zookeeper.host");
- MusicUtil.setMyZkHost(zkHosts);
- MusicUtil.setCassName(prop.getProperty("cassandra.user"));
- MusicUtil.setCassPwd(prop.getProperty("cassandra.password"));
- MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty("cassandra.port")));
- MusicUtil.setNotifyTimeOut(Integer.parseInt(prop.getProperty("notify.timeout")));
- MusicUtil.setNotifyInterval(Integer.parseInt(prop.getProperty("notify.interval")));
-
- }
-
- public static void setNotifyInterval(int notifyinterval) {
- MusicUtil.notifyinterval = notifyinterval;
- }
- public static void setNotifyTimeOut(int notifytimeout) {
- MusicUtil.notifytimeout = notifytimeout;
- }
-
- public static int getNotifyInterval() {
- return MusicUtil.notifyinterval;
- }
-
- public static int getNotifyTimeout() {
- return MusicUtil.notifytimeout;
-
- }
+
}
diff --git a/src/main/java/org/onap/music/main/PropertiesListener.java b/src/main/java/org/onap/music/main/PropertiesListener.java
index 0ed18be2..8b00e473 100755
--- a/src/main/java/org/onap/music/main/PropertiesListener.java
+++ b/src/main/java/org/onap/music/main/PropertiesListener.java
@@ -119,15 +119,6 @@ public class PropertiesListener implements ServletContextListener {
case "aaf.endpoint.url":
MusicUtil.setAafEndpointUrl(prop.getProperty(key));
break;
- case "cassandra.port":
- MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty(key)));
- break;
- case "notify.interval":
- MusicUtil.setNotifyInterval(Integer.parseInt(prop.getProperty(key)));
- break;
- case "notify.timeout":
- MusicUtil.setNotifyTimeOut(Integer.parseInt(prop.getProperty(key)));
- break;
default:
logger.error(EELFLoggerDelegate.errorLogger,
"No case found for " + key);
diff --git a/src/main/java/org/onap/music/main/VotingAppJar.java b/src/main/java/org/onap/music/main/VotingAppJar.java
new file mode 100644
index 00000000..1c475639
--- /dev/null
+++ b/src/main/java/org/onap/music/main/VotingAppJar.java
@@ -0,0 +1,115 @@
+package org.onap.music.main;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicLockingException;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.main.MusicCore;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+
+/**
+ *
+ */
+public class VotingAppJar
+{
+ String keyspaceName;
+ String tableName;
+
+ public VotingAppJar() throws MusicServiceException {
+ keyspaceName = "VotingAppForMusic";
+ tableName = "votevount";
+
+ createVotingKeyspace();
+ System.out.println("Created keyspaces");
+ createVotingTable();
+ System.out.println("Created tables");
+
+ createEntryForCandidate("Popeye");
+ createEntryForCandidate("Judy");
+ createEntryForCandidate("Flash");
+ createEntryForCandidate("Mickey");
+ System.out.println("Created candidates");
+ }
+
+ private void createVotingKeyspace() throws MusicServiceException {
+
+ Map<String,Object> replicationInfo = new HashMap<String, Object>();
+ replicationInfo.put("'class'", "'SimpleStrategy'");
+ replicationInfo.put("'replication_factor'", 1);
+
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE KEYSPACE " + keyspaceName + " WITH REPLICATION = " + replicationInfo.toString().replaceAll("=", ":"));
+
+ try {
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+ } catch (MusicServiceException e) {
+ if (e.getMessage().equals("Keyspace votingappformusic already exists")) {
+ // ignore
+ } else {
+ throw(e);
+ }
+ }
+ }
+
+ private void createVotingTable() throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE TABLE " + keyspaceName + "." + tableName + " (name text PRIMARY KEY, count varint);");
+
+ try {
+ MusicCore.createTable(keyspaceName, tableName, queryObject, "eventual");
+ } catch (MusicServiceException e) {
+ if (e.getMessage().equals("Table votingappformusic.votevount already exists")) {
+ //ignore
+ } else {
+ throw(e);
+ }
+ }
+ }
+
+ private void createEntryForCandidate(String candidateName) throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "INSERT INTO " + keyspaceName + "." + tableName + " (name, count) "
+ + "VALUES ('"+candidateName+"', 0);");
+
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+ }
+
+ public void vote() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ updateVoteCount("Popeye",5);
+ updateVoteCount("Judy",7);
+ updateVoteCount("Mickey",8);
+ updateVoteCount("Flash",2);
+ }
+
+ private void updateVoteCount(String candidateName, int numVotes) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "INSERT INTO " + keyspaceName + "." + tableName + " (name, count) "
+ + "VALUES ('"+candidateName+"', "+numVotes+");");
+ MusicCore.atomicPut(keyspaceName, tableName, candidateName, queryObject, null);
+ }
+
+ private void readAllVotes() throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName);
+ ResultSet rs = MusicCore.get(queryObject);
+ for(Row candidate : rs.all()) {
+ System.out.println(candidate.getString("name") + " - " + candidate.getVarint("count"));
+ }
+ }
+
+ public static void main( String[] args ) throws Exception {
+ VotingAppJar vHandle = new VotingAppJar();
+ vHandle.vote();
+ vHandle.readAllVotes();
+ }
+
+}
diff --git a/src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java b/src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java
index a406afce..6a843607 100644
--- a/src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java
+++ b/src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java
@@ -24,15 +24,8 @@ package org.onap.music.response.jsonobjects;
import java.util.HashMap;
import java.util.Map;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
+import org.onap.music.datastore.MusicLockState.LockStatus;
import org.onap.music.main.ResultType;
-import org.powermock.core.spi.testresult.Result;
-
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.ColumnDefinitions.Definition;
-
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
diff --git a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
index 0e365650..90436499 100755
--- a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
@@ -23,17 +23,10 @@ package org.onap.music.rest;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
import java.util.UUID;
-
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
@@ -45,47 +38,23 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
-import org.codehaus.jackson.map.ObjectMapper;
import org.mindrot.jbcrypt.BCrypt;
import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JSONCallbackResponse;
import org.onap.music.datastore.jsonobjects.JSONObject;
-import org.onap.music.datastore.jsonobjects.JsonCallback;
-import org.onap.music.datastore.jsonobjects.JsonNotification;
-import org.onap.music.datastore.jsonobjects.JsonNotifyClientResponse;
import org.onap.music.datastore.jsonobjects.JsonOnboard;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
-//import org.onap.music.main.CacheAccess;
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 org.onap.music.main.ReturnType;
-import org.onap.music.response.jsonobjects.JsonResponse;
-
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;
-import com.sun.jersey.core.util.Base64;
-
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
-import com.datastax.driver.core.TableMetadata;
-
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.ColumnDefinitions.Definition;
-import com.datastax.driver.core.TableMetadata;
-//import java.util.Base64.Encoder;
-//import java.util.Base64.Decoder;
@Path("/v2/admin")
// @Path("/v{version: [0-9]+}/admin")
@@ -94,6 +63,7 @@ import com.datastax.driver.core.TableMetadata;
public class RestMusicAdminAPI {
private static EELFLoggerDelegate logger =
EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class);
+
/*
* API to onboard an application with MUSIC. This is the mandatory first step.
*
@@ -175,7 +145,7 @@ public class RestMusicAdminAPI {
ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
resultMap.put("Exception",
"Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.");
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
+ return Response.status(Status.UNAUTHORIZED).entity(resultMap).build();
}
PreparedQueryObject pQuery = new PreparedQueryObject();
@@ -189,8 +159,9 @@ public class RestMusicAdminAPI {
if (cql.endsWith("AND "))
cql = cql.trim().substring(0, cql.length() - 4);
- logger.info("Query in callback is: " + cql);
+ System.out.println("Query is: " + cql);
cql = cql + " allow filtering";
+ System.out.println("Get OnboardingInfo CQL: " + cql);
pQuery.appendQueryString(cql);
if (appName != null)
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
@@ -399,447 +370,14 @@ public class RestMusicAdminAPI {
return Response.status(Status.OK).entity(resultMap).build();
}
-
- Client client = Client.create();
- ObjectMapper mapper = new ObjectMapper();
-
- @POST
- @Path("/callbackOps")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public Response callbackOps(final JSONObject inputJsonObj) {
- // {"keyspace":"conductor","full_table":"conductor.plans","changeValue":{"conductor.plans.status":"Who??","position":"3"},"operation":"update","table_name":"plans","primary_key":"3"}
- Map<String, Object> resultMap = new HashMap<>();
- new Thread(new Runnable() {
- public void run() {
- makeAsyncCall(inputJsonObj);
- }
- }).start();
-
- return Response.status(Status.OK).entity(resultMap).build();
- }
-
- private Response makeAsyncCall(JSONObject inputJsonObj) {
-
- Map<String, Object> resultMap = new HashMap<>();
- try {
- logger.info(EELFLoggerDelegate.applicationLogger, "Got notification: " + inputJsonObj.getData());
- String dataStr = inputJsonObj.getData();
- JSONCallbackResponse jsonResponse = mapper.readValue(dataStr, JSONCallbackResponse.class);
- String operation = jsonResponse.getOperation();
- Map<String, String> changeValueMap = jsonResponse.getChangeValue();
- String primaryKey = jsonResponse.getPrimary_key();
- String ksTableName = jsonResponse.getFull_table(); //conductor.plans
- if(ksTableName.equals("admin.notification_master")) {
- CachingUtil.updateCallbackNotifyList(new ArrayList<String>());
- return Response.status(Status.OK).entity(resultMap).build();
- }
- List<String> inputUpdateList = jsonResponse.getUpdateList();
- /*String field_value = changeValueMap.get("field_value");
- if(field_value == null)
- field_value = jsonResponse.getFull_table();*/
- String field_value = null;
- List<String> notifiyList = CachingUtil.getCallbackNotifyList();
- if(notifiyList == null || notifiyList.isEmpty()) {
- logger.info("Is cache empty? reconstructing Object from cache..");
- constructJsonCallbackFromCache();
- /*notifiyList = CachingUtil.getCallbackNotifyList();
- if("update".equals(operation)) {
- List<String> updateList = jsonResponse.getUpdateList();
- //logger.info("update list from trigger: "+updateList);
- for(String element : updateList) {
- logger.info("element: "+element);
- logger.info("notifiyList: "+notifiyList);
- if(notifiyList.contains(element)) {
- logger.info("Found the notifyOn property: "+element);
- field_value = element;
- }
- }
- }
-
- baseRequestObj = CachingUtil.getCallBackCache(field_value);
- logger.info("Reconstructing Object from cache is Successful.."+baseRequestObj);*/
- }
- notifiyList = CachingUtil.getCallbackNotifyList();
- JsonCallback baseRequestObj = null;
-
- if("update".equals(operation)) {
- for(String element: inputUpdateList) {
- baseRequestObj = CachingUtil.getCallBackCache(element);
- if(baseRequestObj != null) {
- logger.info("Found the element that was changed... "+element);
- break;
- }
- }
-
- List<String> updateList = jsonResponse.getUpdateList();
- //logger.info("update list from trigger: "+updateList);
- for(String element : updateList) {
- if(notifiyList.contains(element)) {
- logger.info("Found the notifyOn property: "+element);
- field_value = element;
- break;
- }
- }
- if(baseRequestObj == null || field_value == null) {
- for(String element: inputUpdateList) {
- String[] elementArr = element.split(":");
- String newElement = null;
- if(elementArr.length >= 2) {
- newElement = elementArr[0]+":"+elementArr[1];
- }
- baseRequestObj = CachingUtil.getCallBackCache(newElement);
- if(baseRequestObj != null) {
- logger.info("Found the element that was changed... "+newElement);
- break;
- }
- }
- for(String element : updateList) {
- String[] elementArr = element.split(":");
- String newElement = null;
- if(elementArr.length >= 2) {
- newElement = elementArr[0]+":"+elementArr[1];
- }
- if(notifiyList.contains(newElement)) {
- logger.info("Found the notifyOn property: "+newElement);
- field_value = newElement;
- break;
- }
- }
- }
- } else {
- field_value = jsonResponse.getFull_table();
- baseRequestObj = CachingUtil.getCallBackCache(field_value);
- }
-
- if(baseRequestObj == null) {
- resultMap.put("Exception",
- "Oops. Something went wrong. Please make sure Callback properties are onboarded.");
- logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA,
- ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- logger.info("Going through list: "+operation+ " && List: "+jsonResponse.getUpdateList());
-
- String key = "admin" + "." + "notification_master" + "." + baseRequestObj.getUuid();
- String lockId = MusicCore.createLockReference(key);
- ReturnType lockAcqResult = MusicCore.acquireLock(key, lockId);
- if(! lockAcqResult.getResult().toString().equals("SUCCESS")) {
- logger.error(EELFLoggerDelegate.errorLogger, "Some other node is notifying the caller..: ");
- }
-
- logger.info(operation+ ": Operation :: changeValue: "+changeValueMap);
- if(operation.equals("update")) {
- String notifyWhenChangeIn = baseRequestObj.getNotifyWhenChangeIn(); // conductor.plans.status
- if(null!=field_value) {
- if(field_value.equals(notifyWhenChangeIn)) {
- notifyCallBackAppl(jsonResponse, baseRequestObj);
- }
- }
- } else if(operation.equals("delete")) {
- String notifyWhenDeletesIn = baseRequestObj.getNotifyWhenDeletesIn(); // conductor.plans.status
- if(null!=field_value) {
- if(field_value.equals(notifyWhenDeletesIn)) {
- notifyCallBackAppl(jsonResponse, baseRequestObj);
- }
- }
- } else if(operation.equals("insert")) {
- String notifyWhenInsertsIn = baseRequestObj.getNotifyWhenInsertsIn(); // conductor.plans.status
- if(null!=field_value) {
- if(field_value.equals(notifyWhenInsertsIn)) {
- notifyCallBackAppl(jsonResponse, baseRequestObj);
- }
- }
- }
- MusicCore.releaseLock(lockId, true);
- } catch(Exception e) {
- e.printStackTrace();
- logger.info("Exception...");
- }
- logger.info(EELFLoggerDelegate.applicationLogger, "callback is completed. Notification was sent from Music...");
- return Response.status(Status.OK).entity(resultMap).build();
- }
-
- private void notifyCallBackAppl(JSONCallbackResponse jsonResponse, JsonCallback baseRequestObj) {
- int notifytimeout = MusicUtil.getNotifyTimeout();
- int notifyinterval = MusicUtil.getNotifyInterval();
- String endpoint = baseRequestObj.getApplicationNotificationEndpoint();
- String username = baseRequestObj.getApplicationUsername();
- String password = baseRequestObj.getApplicationPassword();
- JsonNotification jsonNotification = constructJsonNotification(jsonResponse, baseRequestObj);
- jsonNotification.setOperation_type(jsonResponse.getOperation());
- logger.info(EELFLoggerDelegate.applicationLogger, "Notification Response sent is: "+jsonNotification);
- WebResource webResource = client.resource(endpoint);
- String authData = username+":"+password;
- byte[] plainCredsBytes = authData.getBytes();
- byte[] base64CredsBytes = Base64.encode(plainCredsBytes);
- String base64Creds = new String(base64CredsBytes);
- Map<String, String> response_body = baseRequestObj.getResponseBody();
- ClientResponse response = null;
- try {
- response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json").type("application/json")
- .post(ClientResponse.class, jsonNotification);
- } catch (com.sun.jersey.api.client.ClientHandlerException chf) {
- boolean ok = false;
- logger.info(EELFLoggerDelegate.applicationLogger, "Is Service down?");
- long now= System.currentTimeMillis();
- long end = now+notifytimeout;
- while(! ok) {
- logger.info(EELFLoggerDelegate.applicationLogger, "retrying since error in notifying callback..");
- try {
- response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json").type("application/json")
- .post(ClientResponse.class, jsonNotification);
- if(response.getStatus() == 200) ok = true;
- }catch (Exception e) {
- logger.info(EELFLoggerDelegate.applicationLogger, "Retry until "+(end-System.currentTimeMillis()));
- if(response == null && System.currentTimeMillis() < end) ok = false;
- else ok = true;
- try{ Thread.sleep(notifyinterval); } catch(Exception e1) {}
- }
- }
- }
- if(response == null) {
- logger.error(EELFLoggerDelegate.errorLogger, "Can NOT notify the caller as caller failed to respond..");
- return;
- }
- JsonNotifyClientResponse responseStr = response.getEntity(JsonNotifyClientResponse.class);
- logger.info(EELFLoggerDelegate.applicationLogger, "Response from Notified client: "+responseStr);
-
- if(response.getStatus() != 200){
- long now= System.currentTimeMillis();
- long end = now+30000;
- while(response.getStatus() != 200 && System.currentTimeMillis() < end) {
- logger.info(EELFLoggerDelegate.applicationLogger, "retrying since error in notifying callback..");
- response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json").type("application/json")
- .post(ClientResponse.class, jsonNotification);
- }
- logger.info(EELFLoggerDelegate.applicationLogger, "Exception while notifying.. "+response.getStatus());
- }
- }
-
- private JsonNotification constructJsonNotification(JSONCallbackResponse jsonResponse, JsonCallback baseRequestObj) {
-
- JsonNotification jsonNotification = new JsonNotification();
- try {
- jsonNotification.setNotify_field(baseRequestObj.getNotifyOn());
- jsonNotification.setEndpoint(baseRequestObj.getApplicationNotificationEndpoint());
- jsonNotification.setUsername(baseRequestObj.getApplicationUsername());
- jsonNotification.setPassword(baseRequestObj.getApplicationPassword());
- String pkValue = jsonResponse.getPrimary_key();
-
- String[] fullNotifyArr = baseRequestObj.getNotifyOn().split(":");
-
- String[] tableArr = fullNotifyArr[0].split("\\.");
- TableMetadata tableInfo = MusicCore.returnColumnMetadata(tableArr[0], tableArr[1]);
- DataType primaryIdType = tableInfo.getPrimaryKey().get(0).getType();
- String primaryId = tableInfo.getPrimaryKey().get(0).getName();
-
- Map<String, String> responseBodyMap = baseRequestObj.getResponseBody();
- Map<String, String> newMap = new HashMap<>();
- if(responseBodyMap.size() == 1 && responseBodyMap.containsKey("")) {
- jsonNotification.setResponse_body(newMap);
- } else {
- for (Entry<String, String> entry : new HashSet<>(responseBodyMap.entrySet())) {
- String trimmed = entry.getKey().trim();
- if (!trimmed.equals(entry.getKey())) {
- responseBodyMap.remove(entry.getKey());
- responseBodyMap.put(trimmed, entry.getValue());
- }
- }
-
- Set<String> keySet = responseBodyMap.keySet();
- String cql = "select *";
- /*for(String keys: keySet) {
- cql = cql + keys + ",";
- }*/
- //cql = cql.substring(0, cql.length()-1);
- cql = cql + " FROM "+fullNotifyArr[0]+" WHERE "+primaryId+" = ?";
- logger.info("CQL in constructJsonNotification: "+cql);
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(cql);
- pQuery.addValue(MusicUtil.convertToActualDataType(primaryIdType, pkValue));
- Row row = MusicCore.get(pQuery).one();
- if(row != null) {
- ColumnDefinitions colInfo = row.getColumnDefinitions();
- for (Definition definition : colInfo) {
- String colName = definition.getName();
- if(keySet.contains(colName)) {
- DataType colType = definition.getType();
- Object valueObj = MusicCore.getDSHandle().getColValue(row, colName, colType);
- Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- logger.info(colName+" : "+valueString);
- newMap.put(colName, valueString.toString());
- keySet.remove(colName);
- }
- }
- }
- if(! keySet.isEmpty()) {
- Iterator<String> iterator = keySet.iterator();
- while (iterator.hasNext()) {
- String element = iterator.next();
- if(element != null && element.length() > 0)
- newMap.put(element,"COLUMN_NOT_FOUND");
- }
- }
-
- if("delete".equals(jsonResponse.getOperation()) || newMap.isEmpty()) {
- newMap.put(primaryId, pkValue);
- }
- jsonNotification.setResponse_body(newMap);
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
- return jsonNotification;
- }
-
- private void constructJsonCallbackFromCache() throws Exception{
- PreparedQueryObject pQuery = new PreparedQueryObject();
- JsonCallback jsonCallback = null;
- List<String> notifyList = new java.util.ArrayList<>();
- String cql =
- "select id, endpoint_userid, endpoint_password, notify_to_endpoint, notify_insert_on,"
- + " notify_delete_on, notify_update_on, request, notifyon from admin.notification_master allow filtering";
- pQuery.appendQueryString(cql);
- //pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), fullTable));
- logger.info("Query: "+pQuery.getQuery());
-
- ResultSet rs = MusicCore.get(pQuery);
- Iterator<Row> it = rs.iterator();
- while (it.hasNext()) {
- Row row = (Row) it.next();
- String endpoint = row.getString("notify_to_endpoint");
- String username = row.getString("endpoint_userid");
- ByteBuffer passwordBytes = row.getBytes("endpoint_password");
- String insert = row.getString("notify_insert_on");
- String delete = row.getString("notify_delete_on");
- String update = row.getString("notify_update_on");
- String request = row.getString("request");
- String notifyon = row.getString("notifyon");
- String uuid = row.getUUID("id").toString();
- notifyList.add(notifyon);
- jsonCallback = new JsonCallback();
- jsonCallback.setApplicationNotificationEndpoint(endpoint);
-
- Charset charset = Charset.forName("ISO-8859-1");
- String decodedPwd = charset.decode(passwordBytes).toString();
- jsonCallback.setApplicationPassword(decodedPwd);
- jsonCallback.setApplicationUsername(username);
- jsonCallback.setNotifyOn(notifyon);
- jsonCallback.setNotifyWhenInsertsIn(insert);
- jsonCallback.setNotifyWhenDeletesIn(delete);
- jsonCallback.setNotifyWhenChangeIn(update);
- jsonCallback.setUuid(uuid);
- logger.info("From DB. Saved request_body: "+request);
- request = request.substring(1, request.length()-1);
- String[] keyValuePairs = request.split(",");
- Map<String,String> responseBody = new HashMap<>();
-
- for(String pair : keyValuePairs) {
- String[] entry = pair.split("=");
- String val = "";
- if(entry.length == 2)
- val = entry[1];
- responseBody.put(entry[0], val);
- }
- logger.info("After parsing. Saved request_body: "+responseBody);
- jsonCallback.setResponseBody(responseBody);
- logger.info("Updating Cache with updateCallBackCache: "+notifyon+ " :::: "+jsonCallback);
- CachingUtil.updateCallBackCache(notifyon, jsonCallback);
- }
- CachingUtil.updateCallbackNotifyList(notifyList);
- }
@POST
- @Path("/onboardCallback")
+ @Path("/callbackOps")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
- public Response addCallback(JsonNotification jsonNotification) {
- Map<String, Object> resultMap = new HashMap<>();
- ResponseBuilder response =
- Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
- String username = jsonNotification.getUsername();
- String password = jsonNotification.getPassword();
- String endpoint = jsonNotification.getEndpoint();
- String notify_field = jsonNotification.getNotify_field();
- Map<String, String> responseBody = jsonNotification.getResponse_body();
- String triggerName = jsonNotification.getTriggerName();
- if(triggerName == null || triggerName.length() == 0)
- triggerName = "MusicTrigger";
-
- /*JsonCallback callBackCache = CachingUtil.getCallBackCache(notify_field);
- if(callBackCache != null) {
- resultMap.put("Exception", "The notification property has already been onboarded.");
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }*/
-
- String[] allFields = notify_field.split(":");
- String inserts = null;
- String updates = null;
- String deletes = null;
- String tableName = null;
- if(allFields.length >= 2) {
- inserts = updates = notify_field;
- } else if(allFields.length == 1) {
- inserts = deletes = notify_field;;
- }
- tableName = allFields[0];
- String cql = "CREATE TRIGGER IF NOT EXISTS musictrigger ON "+tableName+" Using '"+triggerName+"'";
- PreparedQueryObject pQuery = new PreparedQueryObject();
-
- String uuid = CachingUtil.generateUUID();
- try {
- pQuery.appendQueryString(
- "INSERT INTO admin.notification_master (id, endpoint_userid, endpoint_password, notify_to_endpoint, "
- + "notifyon, notify_insert_on, notify_delete_on, notify_update_on, request, current_notifier) VALUES (?,?,?,?,?,?,?,?,?,?)");
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), username));
- Charset charset = Charset.forName("ISO-8859-1");
- ByteBuffer decodedPwd = charset.encode(password);
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.blob(), decodedPwd.array()));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), endpoint));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), notify_field));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), inserts));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), deletes));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), updates));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), responseBody));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), MusicCore.getMyHostId()));
- MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.EVENTUAL);
- JsonCallback jsonCallback = new JsonCallback();
- jsonCallback.setUuid(uuid);
- jsonCallback.setApplicationNotificationEndpoint(endpoint);
- jsonCallback.setApplicationPassword(password);
- jsonCallback.setApplicationUsername(username);
- jsonCallback.setNotifyOn(notify_field);
- jsonCallback.setNotifyWhenChangeIn(updates);
- jsonCallback.setNotifyWhenDeletesIn(deletes);
- jsonCallback.setNotifyWhenInsertsIn(inserts);
- jsonCallback.setResponseBody(responseBody);
- CachingUtil.updateCallBackCache(notify_field, jsonCallback);
- logger.info("Cache updated ");
- pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(cql);
- ResultType nonKeyRelatedPut = MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.EVENTUAL);
- logger.info(EELFLoggerDelegate.applicationLogger, "Created trigger");
- //callBackCache.put(jsonCallback.getApplicationName(), jsonMap);
- } catch (InvalidQueryException e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Exception callback_api table not configured."+e.getMessage());
- resultMap.put("Exception", "Please make sure admin.notification_master table is configured.");
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- } catch(Exception e) {
- e.printStackTrace();
- resultMap.put("Exception", "Exception Occured.");
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Callback api successfully registered").toMap()).build();
+ public String callbackOps(JSONObject inputJsonObj) throws Exception {
+
+ System.out.println("Input JSON: "+inputJsonObj.getData());
+ return "Success";
}
-
- /*public String encodePwd(String password) {
- return Base64.getEncoder().encodeToString(password.getBytes());
- }
-
- public String decodePwd(String password) {
- byte[] bytes = Base64.getDecoder().decode(password);
- return new String(bytes);
- }*/
}
diff --git a/src/main/java/org/onap/music/rest/RestMusicBmAPI.java b/src/main/java/org/onap/music/rest/RestMusicBmAPI.java
deleted file mode 100644
index 55eb47f2..00000000
--- a/src/main/java/org/onap/music/rest/RestMusicBmAPI.java
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * ============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.rest;
-
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-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.MultivaluedMap;
-import javax.ws.rs.core.UriInfo;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.datastore.PreparedQueryObject;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.TableMetadata;
-import io.swagger.annotations.Api;
-//import io.swagger.annotations.ApiOperation;
-//import io.swagger.annotations.ApiParam;
-
-/*
- * These are functions created purely for benchmarking purposes. Commented out Swagger - This should
- * be undocumented API
- *
- */
-@Path("/v{version: [0-9]+}/benchmarks/")
-@Api(value = "Benchmark API", hidden = true)
-public class RestMusicBmAPI {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicBmAPI.class);
-
- // pure zk calls...
-
- /**
- *
- * @param nodeName
- * @throws Exception
- */
- @POST
- @Path("/purezk/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkCreate(@PathParam("name") String nodeName) throws Exception {
- MusicCore.pureZkCreate("/" + nodeName);
- }
-
-
- /**
- *
- * @param insObj
- * @param nodeName
- * @throws Exception
- */
- @PUT
- @Path("/purezk/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkUpdate(JsonInsert insObj, @PathParam("name") String nodeName)
- throws Exception {
- logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zk normal update-------------------------");
- long start = System.currentTimeMillis();
- MusicCore.pureZkWrite(nodeName, insObj.serialize());
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Total time taken for Zk normal update:" + (end - start) + " ms");
- }
-
- /**
- *
- * @param nodeName
- * @return
- * @throws Exception
- */
- @GET
- @Path("/purezk/{name}")
- @Consumes(MediaType.TEXT_PLAIN)
- public byte[] pureZkGet(@PathParam("name") String nodeName) throws Exception {
- return MusicCore.pureZkRead(nodeName);
- }
-
- /**
- *
- * @param insObj
- * @param lockName
- * @param nodeName
- * @throws Exception
- */
- @PUT
- @Path("/purezk/atomic/{lockname}/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkAtomicPut(JsonInsert updateObj, @PathParam("lockname") String lockname,
- @PathParam("name") String nodeName) throws Exception {
- long startTime = System.currentTimeMillis();
- String operationId = UUID.randomUUID().toString();// just for debugging purposes.
- String consistency = updateObj.getConsistencyInfo().get("type");
-
- logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zookeeper " + consistency + " update-" + operationId
- + "-------------------------");
-
- byte[] data = updateObj.serialize();
- long jsonParseCompletionTime = System.currentTimeMillis();
-
- String lockId = MusicCore.createLockReference(lockname);
-
- long lockCreationTime = System.currentTimeMillis();
-
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = MusicCore.acquireLockWithLease(lockname, lockId, leasePeriod);
- long lockAcqTime = System.currentTimeMillis();
- long zkPutTime = 0, lockReleaseTime = 0;
-
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
- MusicCore.pureZkWrite(lockname, data);
- zkPutTime = System.currentTimeMillis();
- boolean voluntaryRelease = true;
- if (consistency.equals("atomic"))
- MusicCore.releaseLock(lockId, voluntaryRelease);
- else if (consistency.equals("atomic_delete_lock"))
- MusicCore.deleteLock(lockname);
- lockReleaseTime = System.currentTimeMillis();
- } else {
- MusicCore.destroyLockRef(lockId);
- }
-
- long actualUpdateCompletionTime = System.currentTimeMillis();
-
-
- long endTime = System.currentTimeMillis();
-
- String lockingInfo = "|lock creation time:" + (lockCreationTime - jsonParseCompletionTime)
- + "|lock accquire time:" + (lockAcqTime - lockCreationTime)
- + "|zk put time:" + (zkPutTime - lockAcqTime);
-
- if (consistency.equals("atomic"))
- lockingInfo = lockingInfo + "|lock release time:" + (lockReleaseTime - zkPutTime) + "|";
- else if (consistency.equals("atomic_delete_lock"))
- lockingInfo = lockingInfo + "|lock delete time:" + (lockReleaseTime - zkPutTime) + "|";
-
- String timingString = "Time taken in ms for Zookeeper " + consistency + " update-"
- + operationId + ":" + "|total operation time:" + (endTime - startTime)
- + "|json parsing time:" + (jsonParseCompletionTime - startTime)
- + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)
- + lockingInfo;
-
- logger.info(EELFLoggerDelegate.applicationLogger,timingString);
- }
-
- /**
- *
- * @param insObj
- * @param lockName
- * @param nodeName
- * @throws Exception
- */
- @GET
- @Path("/purezk/atomic/{lockname}/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkAtomicGet(JsonInsert insObj, @PathParam("lockname") String lockName,
- @PathParam("name") String nodeName) throws Exception {
- logger.info("--------------Zk atomic read-------------------------");
- long start = System.currentTimeMillis();
- String lockId = MusicCore.createLockReference(lockName);
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = MusicCore.acquireLockWithLease(lockName, lockId, leasePeriod);
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info("acquired lock with id " + lockId);
- MusicCore.pureZkRead(nodeName);
- boolean voluntaryRelease = true;
- MusicCore.releaseLock(lockId, voluntaryRelease);
- } else {
- MusicCore.destroyLockRef(lockId);
- }
-
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Total time taken for Zk atomic read:" + (end - start) + " ms");
- }
-
- /**
- *
- * doing an update directly to cassa but through the rest api
- *
- * @param insObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @PUT
- @Path("/cassa/keyspaces/{keyspace}/tables/{tablename}/rows")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public boolean updateTableCassa(JsonInsert insObj, @PathParam("keyspace") String keyspace,
- @PathParam("tablename") String tablename, @Context UriInfo info)
- throws Exception {
- long startTime = System.currentTimeMillis();
- String operationId = UUID.randomUUID().toString();// just for debugging purposes.
- String consistency = insObj.getConsistencyInfo().get("type");
- logger.info(EELFLoggerDelegate.applicationLogger,"--------------Cassandra " + consistency + " update-" + operationId
- + "-------------------------");
- PreparedQueryObject queryObject = new PreparedQueryObject();
- Map<String, Object> valuesMap = insObj.getValues();
- TableMetadata tableInfo = MusicCore.returnColumnMetadata(keyspace, tablename);
- String vectorTs = "'" + Thread.currentThread().getId() + System.currentTimeMillis() + "'";
- String fieldValueString = "vector_ts= ? ,";
- queryObject.addValue(vectorTs);
-
- int counter = 0;
- for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
- Object valueObj = entry.getValue();
- DataType colType = tableInfo.getColumn(entry.getKey()).getType();
- Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- fieldValueString = fieldValueString + entry.getKey() + "= ?";
- queryObject.addValue(valueString);
- if (counter != valuesMap.size() - 1)
- fieldValueString = fieldValueString + ",";
- counter = counter + 1;
- }
-
- // get the row specifier
- String rowSpec = "";
- counter = 0;
- queryObject.appendQueryString("UPDATE " + keyspace + "." + tablename + " ");
- MultivaluedMap<String, String> rowParams = info.getQueryParameters();
- String primaryKey = "";
- for (MultivaluedMap.Entry<String, List<String>> entry : rowParams.entrySet()) {
- String keyName = entry.getKey();
- List<String> valueList = entry.getValue();
- String indValue = valueList.get(0);
- DataType colType = tableInfo.getColumn(entry.getKey()).getType();
- Object formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
- primaryKey = primaryKey + indValue;
- rowSpec = rowSpec + keyName + "= ? ";
- queryObject.addValue(formattedValue);
- if (counter != rowParams.size() - 1)
- rowSpec = rowSpec + " AND ";
- counter = counter + 1;
- }
-
-
- String ttl = insObj.getTtl();
- String timestamp = insObj.getTimestamp();
-
- if ((ttl != null) && (timestamp != null)) {
-
- logger.info(EELFLoggerDelegate.applicationLogger,"both there");
- queryObject.appendQueryString(" USING TTL ? AND TIMESTAMP ?");
- queryObject.addValue(Integer.parseInt(ttl));
- queryObject.addValue(Long.parseLong(timestamp));
- }
-
- if ((ttl != null) && (timestamp == null)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"ONLY TTL there");
- queryObject.appendQueryString(" USING TTL ?");
- queryObject.addValue(Integer.parseInt(ttl));
- }
-
- if ((ttl == null) && (timestamp != null)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"ONLY timestamp there");
- queryObject.appendQueryString(" USING TIMESTAMP ?");
- queryObject.addValue(Long.parseLong(timestamp));
- }
- queryObject.appendQueryString(" SET " + fieldValueString + " WHERE " + rowSpec + ";");
-
- long jsonParseCompletionTime = System.currentTimeMillis();
-
- boolean operationResult = true;
- MusicCore.getDSHandle().executePut(queryObject, insObj.getConsistencyInfo().get("type"));
-
- long actualUpdateCompletionTime = System.currentTimeMillis();
-
- long endTime = System.currentTimeMillis();
-
- String timingString = "Time taken in ms for Cassandra " + consistency + " update-"
- + operationId + ":" + "|total operation time:" + (endTime - startTime)
- + "|json parsing time:" + (jsonParseCompletionTime - startTime)
- + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)
- + "|";
- logger.info(EELFLoggerDelegate.applicationLogger,timingString);
-
- return operationResult;
- }
-}
diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
index 2d1a8836..99c60b30 100755
--- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
@@ -56,6 +56,7 @@ import org.onap.music.datastore.jsonobjects.JsonTable;
import org.onap.music.datastore.jsonobjects.JsonUpdate;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.exceptions.MusicLockingException;
+import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
@@ -159,7 +160,7 @@ public class RestMusicDataAPI {
if (!authMap.isEmpty()) {
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("Error"))).toMap()).build();
+ 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());
@@ -169,7 +170,7 @@ public class RestMusicDataAPI {
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ authMap = MusicCore.authenticate(ns, userId, password, keyspaceName, aid,
"createKeySpace");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGDATA ,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
@@ -183,7 +184,7 @@ public class RestMusicDataAPI {
} else {
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("Error"))).toMap()).build();
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
}
@@ -285,7 +286,7 @@ public class RestMusicDataAPI {
Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
String userId = userCredentials.get(MusicUtil.USERID);
String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password,keyspaceName, aid, "dropKeySpace");
+ Map<String, Object> authMap = MusicCore.authenticate(ns, userId, password,keyspaceName, aid, "dropKeySpace");
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
@@ -362,13 +363,13 @@ public class RestMusicDataAPI {
Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
String userId = userCredentials.get(MusicUtil.USERID);
String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ Map<String, Object> authMap = MusicCore.authenticate(ns, userId, password, keyspace,
aid, "createTable");
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
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("Error"))).toMap()).build();
+ 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
@@ -548,7 +549,7 @@ public class RestMusicDataAPI {
ResultType result = ResultType.FAILURE;
try {
//logger.info("cjc query="+queryObject.getQuery());
- result = MusicCore.nonKeyRelatedPut(queryObject, consistency);
+ result = MusicCore.createTable(keyspace, tablename, queryObject, consistency);
} catch (MusicServiceException ex) {
logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.MUSICSERVICEERROR);
response.status(Status.BAD_REQUEST);
@@ -588,20 +589,20 @@ public class RestMusicDataAPI {
Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
String userId = userCredentials.get(MusicUtil.USERID);
String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,aid, "createIndex");
+ Map<String, Object> authMap = MusicCore.authenticate(ns, userId, password, keyspace,aid, "createIndex");
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
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("Error"))).toMap()).build();
+ return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
MultivaluedMap<String, String> rowParams = info.getQueryParameters();
String indexName = "";
if (rowParams.getFirst("index_name") != null)
indexName = rowParams.getFirst("index_name");
PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString("Create index if not exists " + indexName + " on " + keyspace + "."
+ query.appendQueryString("Create index " + indexName + " if not exists on " + keyspace + "."
+ tablename + " (" + fieldName + ");");
ResultType result = ResultType.FAILURE;
@@ -613,9 +614,9 @@ public class RestMusicDataAPI {
return response.entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
if ( result.equals(ResultType.SUCCESS) ) {
- return response.status(Status.OK).entity(new JsonResponse(result).setMessage("Index Created on " + keyspace+"."+tablename+"."+fieldName).toMap()).build();
+ return response.entity(new JsonResponse(result).setMessage("Index Created on " + keyspace+"."+tablename+"."+fieldName).toMap()).build();
} else {
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(result).setError("Unknown Error in create index.").toMap()).build();
+ return response.entity(new JsonResponse(result).setError("Unknown Error in create index.").toMap()).build();
}
}
@@ -652,7 +653,7 @@ public class RestMusicDataAPI {
Map<String, Object> authMap = null;
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ authMap = MusicCore.authenticate(ns, userId, password, keyspace,
aid, "insertIntoTable");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
@@ -662,7 +663,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
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("Error"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
Map<String, Object> valuesMap = insObj.getValues();
@@ -808,10 +809,6 @@ public class RestMusicDataAPI {
result = MusicCore.atomicPut(keyspace, tablename, primaryKey, queryObject, null);
}
- else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
- result = MusicCore.atomicPutWithDeleteLock(keyspace, tablename, primaryKey, queryObject, null);
-
- }
} catch (Exception ex) {
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();
@@ -862,7 +859,7 @@ public class RestMusicDataAPI {
String password = userCredentials.get(MusicUtil.PASSWORD);
Map<String, Object> authMap;
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ authMap = MusicCore.authenticate(ns, userId, password, keyspace,
aid, "updateTable");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
@@ -872,7 +869,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
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("Error"))).toMap()).build();
+ 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
@@ -991,20 +988,11 @@ public class RestMusicDataAPI {
}
operationResult = MusicCore.criticalPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, lockId, conditionInfo);
- } else if (consistency.equalsIgnoreCase("atomic_delete_lock")) {
- // this function is mainly for the benchmarks
- try {
- operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
- rowId.primarKeyValue, queryObject, conditionInfo);
- } catch (MusicLockingException 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();
- }
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
try {
operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, conditionInfo);
- } catch (MusicLockingException e) {
+ } catch (MusicLockingException | MusicQueryException | 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();
}
@@ -1075,7 +1063,7 @@ public class RestMusicDataAPI {
String password = userCredentials.get(MusicUtil.PASSWORD);
Map<String, Object> authMap = null;
try {
- authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,
+ authMap = MusicCore.authenticate(ns, userId, password, keyspace,
aid, "deleteFromTable");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
@@ -1085,7 +1073,7 @@ public class RestMusicDataAPI {
authMap.remove("aid");
if (!authMap.isEmpty()) {
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("Error"))).toMap()).build();
+ 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);
@@ -1162,11 +1150,7 @@ public class RestMusicDataAPI {
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) {
+ } catch (MusicLockingException | MusicQueryException | 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("Unable to perform Delete operation. Exception from music").toMap()).build();
@@ -1215,12 +1199,12 @@ public class RestMusicDataAPI {
String userId = userCredentials.get(MusicUtil.USERID);
String password = userCredentials.get(MusicUtil.PASSWORD);
Map<String, Object> authMap =
- MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "dropTable");
+ MusicCore.authenticate(ns, userId, password, keyspace, aid, "dropTable");
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
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("Error"))).toMap()).build();
+ 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
@@ -1270,12 +1254,12 @@ public class RestMusicDataAPI {
Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
String userId = userCredentials.get(MusicUtil.USERID);
String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicCore.autheticateUser(ns, userId, password, keyspace,aid, "selectCritical");
+ Map<String, Object> authMap = MusicCore.authenticate(ns, userId, password, keyspace,aid, "selectCritical");
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,"Error while authentication... ", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Error"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
String lockId = selObj.getConsistencyInfo().get("lockId");
@@ -1307,10 +1291,6 @@ public class RestMusicDataAPI {
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
results = MusicCore.atomicGet(keyspace, tablename, rowId.primarKeyValue, queryObject);
}
-
- else if (consistency.equalsIgnoreCase(MusicUtil.ATOMICDELETELOCK)) {
- results = MusicCore.atomicGetWithDeleteLock(keyspace, tablename, rowId.primarKeyValue, queryObject);
- }
if(results!=null && results.getAvailableWithoutFetching() >0) {
return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap()).build();
}
@@ -1353,12 +1333,12 @@ public class RestMusicDataAPI {
String userId = userCredentials.get(MusicUtil.USERID);
String password = userCredentials.get(MusicUtil.PASSWORD);
Map<String, Object> authMap =
- MusicCore.autheticateUser(ns, userId, password, keyspace, aid, "select");
+ MusicCore.authenticate(ns, userId, password, keyspace, aid, "select");
if (authMap.containsKey("aid"))
authMap.remove("aid");
if (!authMap.isEmpty()) {
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("Error"))).toMap()).build();
+ return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
}
PreparedQueryObject queryObject = new PreparedQueryObject();
@@ -1380,7 +1360,7 @@ public class RestMusicDataAPI {
if(results.getAvailableWithoutFetching() >0) {
return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap()).build();
}
- return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).setError("No data found").toMap()).build();
+ return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setError("No data found").toMap()).build();
} catch (MusicServiceException ex) {
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();
diff --git a/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java b/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java
index 895f0abf..c7e8fda1 100644
--- a/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java
@@ -88,28 +88,8 @@ public class RestMusicHealthCheckAPI {
resultMap.put("INACTIVE", "One or more nodes in the Cluster is/are down or not responding.");
return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
-
-
-
}
- @GET
- @Path("/pingZookeeper")
- @ApiOperation(value = "Get Health Status", response = Map.class)
- @Produces(MediaType.APPLICATION_JSON)
- public Response ZKStatus(@Context HttpServletResponse response) {
- logger.info(EELFLoggerDelegate.applicationLogger,"Replying to request for MUSIC Health Check status for Zookeeper");
- Map<String, Object> resultMap = new HashMap<>();
- MusicHealthCheck ZKHealthCheck = new MusicHealthCheck();
- String status = ZKHealthCheck.getZookeeperStatus();
- if(status.equals("ACTIVE")) {
- resultMap.put("ACTIVE", "Zookeeper is Active and Running");
- return Response.status(Status.OK).entity(resultMap).build();
- }else {
- resultMap.put("INACTIVE", "Zookeeper is not responding");
- return Response.status(Status.BAD_REQUEST).entity(resultMap).build();
- }
- }
diff --git a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java
index 70583baa..835dda14 100644
--- a/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java
@@ -40,7 +40,7 @@ import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
-import org.onap.music.lockingservice.MusicLockState;
+import org.onap.music.datastore.MusicLockState;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
@@ -96,7 +96,7 @@ public class RestMusicLocksAPI {
String password = userCredentials.get(MusicUtil.PASSWORD);
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ resultMap = MusicCore.authenticate(ns, userId, password, keyspaceName, aid,
"createLockReference");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
@@ -148,7 +148,7 @@ public class RestMusicLocksAPI {
String password = userCredentials.get(MusicUtil.PASSWORD);
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ resultMap = MusicCore.authenticate(ns, userId, password, keyspaceName, aid,
"accquireLock");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
@@ -198,7 +198,7 @@ public class RestMusicLocksAPI {
String password = userCredentials.get(MusicUtil.PASSWORD);
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ resultMap = MusicCore.authenticate(ns, userId, password, keyspaceName, aid,
"accquireLockWithLease");
if (resultMap.containsKey("aid"))
@@ -245,7 +245,7 @@ public class RestMusicLocksAPI {
String password = userCredentials.get(MusicUtil.PASSWORD);
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ resultMap = MusicCore.authenticate(ns, userId, password, keyspaceName, aid,
"currentLockHolder");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
@@ -291,7 +291,7 @@ public class RestMusicLocksAPI {
}
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ resultMap = MusicCore.authenticate(ns, userId, password, keyspaceName, aid,
"currentLockState");
if (resultMap.containsKey("aid"))
@@ -301,7 +301,7 @@ public class RestMusicLocksAPI {
return response.status(Status.BAD_REQUEST).entity(resultMap).build();
}
- MusicLockState mls = MusicCore.getMusicLockState(lockName);
+ org.onap.music.datastore.MusicLockState mls = MusicCore.getMusicLockState(lockName);
Map<String,Object> returnMap = null;
JsonResponse jsonResponse = new JsonResponse(ResultType.FAILURE).setLock(lockName);
if(mls == null) {
@@ -348,7 +348,7 @@ public class RestMusicLocksAPI {
String password = userCredentials.get(MusicUtil.PASSWORD);
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ resultMap = MusicCore.authenticate(ns, userId, password, keyspaceName, aid,
"unLock");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
@@ -356,8 +356,9 @@ public class RestMusicLocksAPI {
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);
+ String fullyQualifiedKey = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
+ MusicLockState mls = MusicCore.voluntaryReleaseLock(fullyQualifiedKey, lockId);
+
if(mls.getErrorMessage() != null) {
resultMap.put(ResultType.EXCEPTION.getResult(), mls.getErrorMessage());
logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
@@ -405,7 +406,7 @@ public class RestMusicLocksAPI {
String password = userCredentials.get(MusicUtil.PASSWORD);
String keyspaceName = (String) resultMap.get("keyspace");
resultMap.remove("keyspace");
- resultMap = MusicCore.autheticateUser(ns, userId, password, keyspaceName, aid,
+ resultMap = MusicCore.authenticate(ns, userId, password, keyspaceName, aid,
"deleteLock");
if (resultMap.containsKey("aid"))
resultMap.remove("aid");
diff --git a/src/main/java/org/onap/music/rest/RestMusicQAPI.java b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
index 1f6ec24f..8af334c7 100755
--- a/src/main/java/org/onap/music/rest/RestMusicQAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
@@ -34,6 +34,7 @@ import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
+// cjcimport javax.servlet.http.HttpServletResponse;
import org.onap.music.datastore.jsonobjects.JsonDelete;
import org.onap.music.datastore.jsonobjects.JsonInsert;
import org.onap.music.datastore.jsonobjects.JsonTable;
@@ -50,19 +51,22 @@ import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
+// cjc import org.onap.music.main.ReturnType;
import org.onap.music.response.jsonobjects.JsonResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
-
+// import io.swagger.models.Response;
// @Path("/v{version: [0-9]+}/priorityq/")
@Path("{version}/priorityq/")
@Api(value = "Q Api")
public class RestMusicQAPI {
private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicQAPI.class);
+ // private static String xLatestVersion = "X-latestVersion";
/*
+ * private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicDataAPI.class);
* 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";
@@ -104,12 +108,12 @@ public class RestMusicQAPI {
@ApiParam(value = "Key Space", required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name", required = true) @PathParam("qname") String tablename)
throws Exception {
-
+ //logger.info(logger, "cjc before start in q 1** major version=" + version);
ResponseBuilder response = MusicUtil.buildVersionResponse(version, minorVersion, patchVersion);
Map<String, String> fields = tableObj.getFields();
- if (fields == null) {
+ if (fields == null) { // || (!fields.containsKey("order")) ){
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA,
ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
return response.status(Status.BAD_REQUEST)
@@ -186,13 +190,9 @@ public class RestMusicQAPI {
clusteringKey=clusteringKey.replaceAll("[\\(]+","");
clusteringKey=clusteringKey.replaceAll("[\\)]+","");
clusteringKey.trim();
- if (clusteringKey.indexOf(",") == 0) {
- clusteringKey=clusteringKey.substring(1);
- }
+ if (clusteringKey.indexOf(",") == 0) clusteringKey=clusteringKey.substring(1);
clusteringKey.trim();
- if (",".equals(clusteringKey) ) {
- clusteringKey=""; // print error if needed ( ... ),)
- }
+ if (clusteringKey.equals(",") ) clusteringKey=""; // print error if needed ( ... ),)
}
}
@@ -252,11 +252,15 @@ public class RestMusicQAPI {
@ApiParam(value = "Key Space", required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name", required = true) @PathParam("qname") String tablename)
throws Exception {
+ // ,@Context HttpServletResponse response) throws Exception {
+ // Map<String, Object> valuesMap = insObj.getValues();
// check valuesMap.isEmpty and proceed
+ // if(valuesMap.isEmpty() ) {
// response.addHeader(xLatestVersion, MusicUtil.getVersion());
ResponseBuilder response = MusicUtil.buildVersionResponse(version, minorVersion, patchVersion);
if (insObj.getValues().isEmpty()) {
+ // response.status(404);
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA,
ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
@@ -292,11 +296,13 @@ public class RestMusicQAPI {
JsonUpdate updateObj,
@ApiParam(value = "Key Space", required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name", required = true) @PathParam("qname") String tablename,
- @Context UriInfo info) {
+ @Context UriInfo info) throws Exception {
//logger.info(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
+ // ErrorTypes.DATAERROR);
ResponseBuilder response = MusicUtil.buildVersionResponse(version, minorVersion, patchVersion);
if (updateObj.getValues().isEmpty()) {
+ // response.status(404);
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA,
ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
return response.status(Status.BAD_REQUEST)
@@ -341,10 +347,11 @@ public class RestMusicQAPI {
JsonDelete delObj,
@ApiParam(value = "Key Space", required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name", required = true) @PathParam("qname") String tablename,
- @Context UriInfo info) {
+ @Context UriInfo info) throws Exception {
// added checking as per RestMusicDataAPI
ResponseBuilder response = MusicUtil.buildVersionResponse(version, minorVersion, patchVersion);
if (delObj == null) {
+ // response.status(404);
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA,
ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
@@ -396,7 +403,6 @@ public class RestMusicQAPI {
queryObject = new RestMusicDataAPI().selectSpecificQuery(version, minorVersion,
patchVersion, aid, ns, userId, password, keyspace, tablename, info, limit);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "MusicServiceException occured in peek"+ ex);
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.UNKNOWNERROR,
ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST)
@@ -410,7 +416,6 @@ public class RestMusicQAPI {
return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS)
.setDataResult(MusicCore.marshallResults(results)).toMap()).build();
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "MusicServiceException occured in peek"+ ex);
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.UNKNOWNERROR,
ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
return response.status(Status.BAD_REQUEST)
@@ -447,9 +452,11 @@ public class RestMusicQAPI {
@ApiParam(value = "Key Space", required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name", required = true) @PathParam("qname") 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);
*/
/* Map<String ,String> auth = new HashMap<>();
String userId =auth.get(MusicUtil.USERID);
@@ -485,6 +492,8 @@ public class RestMusicQAPI {
@ApiParam(value = "Key Space", required = true) @PathParam("keyspace") String keyspace,
@ApiParam(value = "Table Name", required = true) @PathParam("qname") String tablename)
throws Exception {
+ // @Context HttpServletResponse response) throws Exception {
+ // tabObj never in use & thus no need to verify
return new RestMusicDataAPI().dropTable(version, minorVersion, patchVersion, aid, ns, authorization, keyspace, tablename);
diff --git a/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java b/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java
index b9754f61..a5f2ac49 100644
--- a/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java
@@ -35,6 +35,9 @@ import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
index b75fcd85..fe7f54ae 100644
--- a/src/main/resources/logback.xml
+++ b/src/main/resources/logback.xml
@@ -259,13 +259,12 @@
</logger>
+
+
+
<root level="INFO">
<appender-ref ref="asyncEELF" />
<appender-ref ref="STDOUT" />
</root>
- <!-- Conductor Specific additions to squash WARNING and INFO -->
- <logger name="com.datastax.driver.core.Cluster" level="ERROR"/>
- <logger name="org.onap.music.main.MusicCore" level="ERROR"/>
-
</configuration>
diff --git a/src/test/java/org/onap/music/unittests/CassandraCQL.java b/src/test/java/org/onap/music/unittests/CassandraCQL.java
index a4c250c2..a9cbe109 100644
--- a/src/test/java/org/onap/music/unittests/CassandraCQL.java
+++ b/src/test/java/org/onap/music/unittests/CassandraCQL.java
@@ -45,7 +45,7 @@ import com.datastax.driver.core.exceptions.NoHostAvailableException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
-import org.onap.music.datastore.MusicDataStore;
+import org.onap.music.datastore.CassaDataStore;
import org.onap.music.datastore.PreparedQueryObject;
public class CassandraCQL {
@@ -222,7 +222,7 @@ public class CassandraCQL {
return allPossibleIps;
}
- public static MusicDataStore connectToEmbeddedCassandra() {
+ public static CassaDataStore connectToEmbeddedCassandra() {
Iterator<String> it = getAllPossibleLocalIps().iterator();
String address = "localhost";
@@ -249,7 +249,7 @@ public class CassandraCQL {
}
}
- return new MusicDataStore(cluster, session);
+ return new CassaDataStore(cluster, session);
}
diff --git a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
index 16d2af02..3f7fd3b7 100644
--- a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
@@ -33,7 +33,7 @@ import org.mockito.Mock;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.datastore.MusicDataStore;
+import org.onap.music.datastore.CassaDataStore;
import org.onap.music.datastore.PreparedQueryObject;
import com.datastax.driver.core.DataType;
@@ -44,7 +44,7 @@ import com.datastax.driver.core.TableMetadata;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MusicDataStoreTest {
- static MusicDataStore dataStore;
+ static CassaDataStore dataStore;
static PreparedQueryObject testObject;
@BeforeClass
diff --git a/jar/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java b/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java
index 16d2af02..86774538 100644
--- a/jar/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java
@@ -33,7 +33,8 @@ import org.mockito.Mock;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.datastore.MusicDataStore;
+import org.onap.music.datastore.CassaDataStore;
+import org.onap.music.datastore.CassaLockStore;
import org.onap.music.datastore.PreparedQueryObject;
import com.datastax.driver.core.DataType;
@@ -42,20 +43,21 @@ import com.datastax.driver.core.Row;
import com.datastax.driver.core.TableMetadata;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class MusicDataStoreTest {
+public class MusicLockStoreTest {
- static MusicDataStore dataStore;
+ static CassaDataStore dataStore;
+ static CassaLockStore lockStore;
static PreparedQueryObject testObject;
@BeforeClass
public static void init() {
dataStore = CassandraCQL.connectToEmbeddedCassandra();
+ lockStore = new CassaLockStore(dataStore);
}
@AfterClass
public static void close() throws MusicServiceException, MusicQueryException {
-
testObject = new PreparedQueryObject();
testObject.appendQueryString(CassandraCQL.dropKeyspace);
dataStore.executePut(testObject, "eventual");
@@ -76,10 +78,16 @@ public class MusicDataStoreTest {
}
+
@Test
- public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedInsertQueryObject1();
- boolean result = dataStore.executePut(testObject, "eventual");
+ public void Test_createLockQueue() throws MusicServiceException, MusicQueryException {
+ String keyspace = "testCassa";
+ String table = "employees";
+ /*
+ * above two hard coded since this depends on the keyspace and table created in the
+ * CassandraCQL class. Need to change this..
+ */
+ boolean result = lockStore.createLockQueue(keyspace,table);
assertEquals(true, result);
}
diff --git a/src/test/java/org/onap/music/unittests/TestCassaLockStore.java b/src/test/java/org/onap/music/unittests/TestCassaLockStore.java
new file mode 100644
index 00000000..bf058121
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TestCassaLockStore.java
@@ -0,0 +1,71 @@
+package org.onap.music.unittests;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.onap.music.datastore.CassaLockStore;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.main.MusicCore;
+
+public class TestCassaLockStore {
+
+
+ public static void main(String[] args) {
+
+
+ try {
+ CassaLockStore lockStore = new CassaLockStore();
+ String keyspace = "ks_testLockStore";
+ String table = "table_testLockStore";
+
+ Map<String,Object> replicationInfo = new HashMap<String, Object>();
+ replicationInfo.put("'class'", "'SimpleStrategy'");
+ replicationInfo.put("'replication_factor'", 1);
+
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("CREATE KEYSPACE " + keyspace + " WITH REPLICATION = " + replicationInfo.toString().replaceAll("=", ":"));
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+
+
+ queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("CREATE TABLE " + keyspace + "." + table + " (name text PRIMARY KEY, count varint);");
+ MusicCore.createTable(keyspace, table, queryObject, "eventual");
+
+
+ lockStore.createLockQueue(keyspace, table);
+
+ String lockRefb1 = lockStore.genLockRefandEnQueue(keyspace, table, "bharath");
+
+
+
+ String lockRefc1 = lockStore.genLockRefandEnQueue(keyspace, table, "cat");
+
+ String lockRefc2 = lockStore.genLockRefandEnQueue(keyspace, table, "cat");
+
+
+ assert(lockStore.peekLockQueue(keyspace, table, "cat").equals(lockRefc1));
+
+ assert(!lockStore.peekLockQueue(keyspace, table, "cat").equals(lockRefc2));
+
+
+ assert(lockStore.peekLockQueue(keyspace, table, "bharath").equals(lockRefb1));
+
+
+ lockStore.deQueueLockRef(keyspace, table, "cat", lockRefc1);
+
+ assert(lockStore.peekLockQueue(keyspace, table, "cat").equals(lockRefc2));
+
+ } catch (MusicServiceException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (MusicQueryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+}
diff --git a/src/test/java/org/onap/music/unittests/TestLockStore.java b/src/test/java/org/onap/music/unittests/TestLockStore.java
deleted file mode 100644
index 4dbc7b4f..00000000
--- a/src/test/java/org/onap/music/unittests/TestLockStore.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ============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.unittests;
-
-import org.apache.log4j.Logger;
-import org.onap.music.lockingservice.MusicLockingService;
-
-public class TestLockStore {
- final static Logger logger = Logger.getLogger(TestLockStore.class);
-
- public static void main(String[] args) throws Exception {
- String lockName = "/achristmkllas";
- MusicLockingService ml = new MusicLockingService();
- ml.deleteLock(lockName);
-
-
- logger.info("lockname:" + lockName);
-
- String lockId1 = ml.createLockId(lockName);
- logger.info("lockId1 " + lockId1);
- logger.info(ml.isMyTurn(lockId1));
-
- String lockId2 = ml.createLockId(lockName);
- logger.info("lockId2 " + lockId2);
- logger.info("check " + ml.isMyTurn("$bank$x-94608776321630264-0000000000"));
- logger.info(ml.isMyTurn(lockId2));
-
- // zkClient.unlock(lockId1);
- // logger.info(ml.lock(lockId2));
- // zkClient.unlock(lockId2);
- }
-
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCore.java b/src/test/java/org/onap/music/unittests/TestMusicCore.java
index ed9c2f68..3a28f963 100644
--- a/src/test/java/org/onap/music/unittests/TestMusicCore.java
+++ b/src/test/java/org/onap/music/unittests/TestMusicCore.java
@@ -1,678 +1,81 @@
-/*
- * ============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.unittests;
-import static org.junit.Assert.*;
-import static org.onap.music.main.MusicCore.mDstoreHandle;
-import static org.onap.music.main.MusicCore.mLockHandle;
+import static org.junit.Assert.assertEquals;
+
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.junit.Before;
-import org.junit.Ignore;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.music.exceptions.MusicLockingException;
+import org.junit.runners.MethodSorters;
+import org.onap.music.datastore.CassaDataStore;
+import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.main.MusicCore.Condition;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import com.att.eelf.exception.EELFException;
+
import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Session;
-@RunWith(MockitoJUnitRunner.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestMusicCore {
+
+ static CassaDataStore dataStore;
+ String keyspace = "MusicCoreUnitTestKp";
+ String table = "SampleTable";
- @Mock
- private Condition condition;
-
- @Mock
- private ResultSet rs;
-
- @Mock
- private PreparedQueryObject preparedQueryObject;
-
- @Mock
- private Session session;
-
- @Before
- public void setUp() {
- mLockHandle = Mockito.mock(MusicLockingService.class);
-
- }
-
- @Test
- public void testCreateLockReferenceforvalidlock() {
- Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
- String lockId = MusicCore.createLockReference("test");
- assertEquals("lock", lockId);
- Mockito.verify(mLockHandle).createLockId("/" + "test");
- }
-
-
- @Test
- public void testCreateLockReferencefornullname() {
- Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
- String lockId = MusicCore.createLockReference("x"); //test");
- //System.out.println("cjc exception lockhandle=" + mLockHandle+"lockid="+lockId );
- assertNotEquals("lock", lockId);
- //Mockito.verify(mLockHandle).createLockId("/" + "test");
- }
-
- @Test
- public void testIsTableOrKeySpaceLock() {
- Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1");
- assertTrue(result);
- }
-
- @Test
- public void testIsTableOrKeySpaceLockwithPrimarykey() {
- Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1.pk1");
- assertFalse(result);
- }
-
- @Test
- public void testGetMusicLockState() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(mLockHandle.getLockState("ks1.tb1.pk1")).thenReturn(musicLockState);
- MusicLockState mls = MusicCore.getMusicLockState("ks1.tb1.pk1");
- assertEquals(musicLockState, mls);
- Mockito.verify(mLockHandle).getLockState("ks1.tb1.pk1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrue() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnFalse() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType lock = MusicCore.acquireLock("ks1.ts1", "id1");
- assertEquals(lock.getResult(), ResultType.FAILURE);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
+ @BeforeClass
+ public static void init() {
+ dataStore = CassandraCQL.connectToEmbeddedCassandra();
+ MusicCore.mDstoreHandle = dataStore;
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandHaveLock() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandDontHaveLock() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id2");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
}
- @Test
- public void testAcquireLockifLockRefDoesntExist() throws MusicLockingException {
- Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false);
- ReturnType lock = MusicCore.acquireLock("ks1.ts1", "bs1");
- assertEquals(lock.getResult(), ResultType.FAILURE);
- assertEquals(lock.getMessage(), "Lockid doesn't exist");
- Mockito.verify(mLockHandle).lockIdExists("bs1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLease() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- musicLockState.setLeasePeriod(0);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
+ @AfterClass
+ public static void close() throws MusicServiceException, MusicQueryException {
+ dataStore.close();
+ }
+
+ @Test
+ public void Test1_createKeyspace() throws MusicServiceException, MusicQueryException {
+
+ Map<String,Object> replicationInfo = new HashMap<String, Object>();
+ replicationInfo.put("'class'", "'SimpleStrategy'");
+ replicationInfo.put("'replication_factor'", 1);
+
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE KEYSPACE " + keyspace + " WITH REPLICATION = " + replicationInfo.toString().replaceAll("=", ":"));
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+
+
+ //check with the system table in cassandra
+ queryObject = new PreparedQueryObject();
+ String systemQuery = "SELECT keyspace_name FROM system_schema.keyspaces where keyspace_name='"+keyspace.toLowerCase()+"';";
+ queryObject.appendQueryString(systemQuery);
+ ResultSet rs = dataStore.executeEventualGet(queryObject);
+ assert rs.all().size()> 0;
}
@Test
- public void testAcquireLockWithLeasewithException() throws MusicLockingException {
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "failure");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenThrow(new MusicLockingException());
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLockStatusLOCKED() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLockStatusUNLOCKED() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
-
- }
-
- @Test
- public void testAcquireLockWithLeaseIfNotMyTurn() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testQuorumGet() throws MusicServiceException, MusicQueryException {
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.quorumGet(preparedQueryObject);
- assertNotNull(rs1);
- }
-
- @Test
- public void testGetLockNameFromId() {
- String lockname = MusicCore.getLockNameFromId("lockName$id");
- assertEquals("lockName", lockname);
- }
-
- @Test
- public void testDestroyLockRef() throws NoNodeException {
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicCore.destroyLockRef("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testreleaseLockwithvoluntaryReleaseTrue() throws NoNodeException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicLockState musicLockState1 = MusicCore.releaseLock("id1", true);
- assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testreleaseLockwithvoluntaryReleaseFalse() throws NoNodeException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicLockState musicLockState1 = MusicCore.releaseLock("id1", false);
- assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testDeleteLock() throws MusicLockingException {
- Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1");
- MusicCore.deleteLock("id1");
- Mockito.verify(mLockHandle).deleteLock("/" + "id1");
- }
-
- /*
- * @Test public void testNonKeyRelatedPut() throws Exception { mDstoreHandle =
- * Mockito.mock(MusicDataStore.class); Mockito.when(mDstoreHandle.executePut("qu1",
- * "consistency")).thenReturn(true); Boolean result = MusicCore.nonKeyRelatedPut("qu1",
- * "consistency"); assertTrue(result); Mockito.verify(mDstoreHandle).executePut("qu1",
- * "consistency"); }
- */
-
- @Test
- public void testEventualPutPreparedQuery() throws MusicServiceException, MusicQueryException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true);
- ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
- }
-
- @Test
- public void testEventualPutPreparedQuerywithResultFalse()
- throws MusicServiceException, MusicQueryException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false);
- ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
- //Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, MusicUtil.EVENTUAL);
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithValidLockId()
- throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(condition.testCondition()).thenReturn(true);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
- ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithInvalidLockId() throws MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(condition.testCondition()).thenReturn(false);
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testNonKeyRelatedPutPreparedQuery() throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true);
- ResultType result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency");
- assertEquals(ResultType.SUCCESS, result);
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "consistency");
- }
-
- @Test
- public void testAtomicPutPreparedQuery() throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(condition.testCondition()).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
- ReturnType returnType =
- MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
- }
-
- @Test
- public void testAtomicPutPreparedQuerywithAcquireLockWithLeaseFalse() throws MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType returnType =
- MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- }
-
- @Test
- public void testAtomicGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNotNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
- }
-
- @Test
- public void testAtomicGetPreparedQuerywithAcquireLockWithLeaseFalse()
- throws MusicServiceException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testGetPreparedQuery() throws MusicServiceException, MusicQueryException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- rs = Mockito.mock(ResultSet.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executeEventualGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.get(preparedQueryObject);
- assertNotNull(rs1);
- Mockito.verify(mDstoreHandle).executeEventualGet(preparedQueryObject);
+ public void Test1_createTable() throws MusicServiceException, MusicQueryException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE TABLE " + keyspace + "." + table + " (name text PRIMARY KEY, count varint);");
+ MusicCore.createTable(keyspace, table, queryObject, "eventual");
+
+ //check with the system table in cassandra
+ queryObject = new PreparedQueryObject();
+ String systemQuery = "SELECT table_name FROM system_schema.tables where keyspace_name='"+keyspace.toLowerCase()+"' and table_name='"+table.toLowerCase()+"';";
+ queryObject.appendQueryString(systemQuery);
+ ResultSet rs = dataStore.executeEventualGet(queryObject);
+ assert rs.all().size()> 0;
}
- @Test
- public void testcriticalGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
- assertNotNull(rs1);
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
- }
-
- @Test
- public void testcriticalGetPreparedQuerywithInvalidLockId() throws MusicServiceException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
- assertNull(rs1);
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testAtomicGetPreparedQuerywithDeleteLockWithLeaseFalse()
- throws MusicServiceException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testCondition() throws Exception {
- //Condition conClass = Mockito.mock(Condition.class);
- // boolean ret=true;
- //Mockito.when(conClass.testCondition().thenReturn(ret);
- Map<String, Object> conditionsx=null;
- PreparedQueryObject selectQueryForTheRowx=null;
- try {
- Condition con = new Condition(conditionsx,selectQueryForTheRowx);
- assertTrue(con.testCondition());
- } catch (Exception e) {
- assertFalse(false);
- }
- }
- //getLockingServiceHandl
-
- @Ignore
- @Test(expected = MusicLockingException.class) //("Failed to aquire Locl store handle " + e))
- public void testgetLockingServiceHandle() throws Exception {
- // MusicLockingService mLockHandlex = Mockito.mock(MusicLockingService.class);
- //MusicLockingService mLockHandlea = mLockHandle;
- //mLockHandle=null;
- System.out.println("cjc 0 locking test n");
- // Mockito.when(MusicCore.getLockingServiceHandle()).thenReturn(mLockHandle);
- //mLockHandle=null;
- //System.out.println("cjc 0-1 locking test n");
- MusicLockingService mLockHandlea = mLockHandle;
- mLockHandle=null;
-
- MusicLockingService mLockHandley=null; //MusicCore.getLockingServiceHandle();
- Mockito.when(MusicCore.getLockingServiceHandle()).thenReturn(mLockHandley);
- System.out.println("cjc locking test n");
- mLockHandle=mLockHandlea;
- assertTrue(true);
-
- }
-
- @Test(expected = MusicServiceException.class)
- public void testGetDSHandle() throws MusicServiceException, MusicQueryException {
- // rs = Mockito.mock(ResultSet.class);
- // session = Mockito.mock(Session.class);
- //Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- //Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
-
- MusicDataStore mDstoreHandlea = Mockito.mock(MusicDataStore.class);
- //MusicUtil mMusicUtil=Mockito.mock(MusicUtil.class);
- //System.out.println("cjc 0 getDsHandle");
- Mockito.when(MusicCore.getDSHandle()).thenReturn(mDstoreHandlea);
- // System.out.println("cjc localhost");
- // Mockito.when(mMusicUtil.getMyCassaHost().equals("localhost")).thenReturn(null);
- //System.out.println("cjc 1 localhost");
- // mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
- // } else {
- // mDstoreHandle = new MusicDataStore();
- // }
- assertTrue(true);
- }
-
- //add mocking
- @Ignore
- @Test
- public void testGetDSHandleIp() throws MusicServiceException, MusicQueryException {
- // rs = Mockito.mock(ResultSet.class);
- // session = Mockito.mock(Session.class);
- //Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- //Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
-
- //mDstoreHandle = Mockito.mock(MusicDataStore.class);
- //MusicUtil mMusicUtil=Mockito.mock(MusicUtil.class);
- System.out.println("cjc 0 getDsHandleIP");
- Mockito.when(MusicCore.getDSHandle("1.127.0.1")).thenReturn(mDstoreHandle);
- System.out.println("cjc localhost");
- // Mockito.when(mMusicUtil.getMyCassaHost().equals("localhost")).thenReturn(null);
- System.out.println("cjc 1 localhost IP");
- // mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
- // } else {
- // mDstoreHandle = new MusicDataStore();
- // }
- assertTrue(true);
- }
-
- @Ignore
- @Test
- public void testPureZkCreate() {
- try {
- MusicCore.pureZkCreate("local");
- } catch(NullPointerException e) {
- System.out.println("cjc zkcreate null pointwer exception:"+ e);
- }
- }
-
- @Ignore
- @Test
- public void testPureZkRead() { //String nodeName) {
- byte[] data = MusicCore.pureZkRead("localhost");
- }
-
- //need fixing
- @Ignore
- @Test
- public void testPureZkWrite() { //String nodeName, byte[] data) {
- /*
- long start = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Performing zookeeper write to " + nodeName);
- try {
- getLockingServiceHandle().getzkLockHandle().setNodeData(nodeName, data);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"Performed zookeeper write to " + nodeName);
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the actual zk put:" + (end - start) + " ms");
- */
-
- // mDstoreHandle = Mockito.mock(MusicDataStore.class);
- // rs = Mockito.mock(ResultSet.class);
- // session = Mockito.mock(Session.class);
- //Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
-
- byte[] data= "Testing Zoo Keeper".getBytes();
- MusicCore.pureZkWrite("1.127.0.1", data);
- // assertNotNull(rs1);
- }
-
- @Test
- public void testWhoseTurnIsIt() { //(String lockName) {
-
- /*
- try {
- return getLockingServiceHandle().whoseTurnIsIt("/" + lockName) + "";
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKINGERROR+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- return null;
- */
-
- String lockName="xxx";
- if (MusicCore.whoseTurnIsIt(lockName) != null) assertTrue(true);
-
-
-
- }
-
- @Test
- public void testMarshallResults() {
- Map<String, HashMap<String, Object>> ret=null;
- //ResultSet results =null;
- rs = Mockito.mock(ResultSet.class);
- try {
- ret= MusicCore.marshallResults(rs);
-
- } catch( Exception e ) {
-
- }
-
- if (ret != null) assertTrue(true);
- }
}
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
index d327d0f0..b47c812a 100644
--- a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
+++ b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
@@ -31,9 +31,9 @@ import org.junit.runners.MethodSorters;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
+import org.onap.music.datastore.CassaLockStore;
+import org.onap.music.datastore.MusicLockState;
+import org.onap.music.datastore.MusicLockState.LockStatus;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
@@ -53,8 +53,7 @@ public class TestMusicCoreIntegration {
public static void init() throws Exception {
try {
MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- MusicCore.mLockHandle = new MusicLockingService();
+ MusicCore.mLockHandle = new CassaLockStore(MusicCore.mDstoreHandle);
} catch (Exception e) {
e.printStackTrace();
}
@@ -69,15 +68,14 @@ public class TestMusicCoreIntegration {
MusicCore.eventualPut(testObject);
MusicCore.deleteLock(lockName);
MusicCore.mDstoreHandle.close();
- MusicCore.mLockHandle.getzkLockHandle().close();
- MusicCore.mLockHandle.close();
zkServer.stop();
}
@Test
public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
- MusicCore.mLockHandle = new MusicLockingService();
+ MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
+ MusicCore.mLockHandle = new CassaLockStore(MusicCore.mDstoreHandle);
ResultType result = ResultType.FAILURE;
testObject = new PreparedQueryObject();
testObject.appendQueryString(CassandraCQL.createKeySpace);
@@ -97,24 +95,6 @@ public class TestMusicCoreIntegration {
assertEquals(ResultType.SUCCESS, returnType.getResult());
}
- @Test
- public void Test3_atomicPutWithDeleteLock() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedInsertQueryObject2();
- ReturnType returnType = MusicCore.atomicPutWithDeleteLock("testCassa", "employees",
- "Mr Test two", testObject, null);
- assertEquals(ResultType.SUCCESS, returnType.getResult());
- }
-
- @Test
- public void Test4_atomicGetWithDeleteLock() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedGetQuery();
- ResultSet resultSet = MusicCore.atomicGetWithDeleteLock("testCassa", "employees",
- "Mr Test one", testObject);
- List<Row> rows = resultSet.all();
- assertEquals(1, rows.size());
- }
@Test
public void Test5_atomicGet() throws Exception {
@@ -150,27 +130,8 @@ public class TestMusicCoreIntegration {
MusicLockState musicLockState1 = new MusicLockState(LockStatus.UNLOCKED, "id1");
MusicCore.whoseTurnIsIt(lockName);
MusicLockState mls = MusicCore.getMusicLockState(lockName);
- boolean voluntaryRelease = true;
- MusicLockState mls1 = MusicCore.releaseLock(lockId, voluntaryRelease);
+ MusicLockState mls1 = MusicCore.voluntaryReleaseLock(lockName,lockId);
assertEquals(musicLockState.getLockStatus(), mls.getLockStatus());
assertEquals(musicLockState1.getLockStatus(), mls1.getLockStatus());
}
-
- @Test
- public void Test10_create() {
- MusicCore.pureZkCreate("/nodeName");
- }
-
- @Test
- public void Test11_write() {
- MusicCore.pureZkWrite("nodeName", "I'm Test".getBytes());
- }
-
- @Test
- public void Test12_read() {
- byte[] data = MusicCore.pureZkRead("nodeName");
- String data1 = new String(data);
- assertEquals("I'm Test", data1);
- }
-
}
diff --git a/src/test/java/org/onap/music/unittests/TestRestAdminData.java b/src/test/java/org/onap/music/unittests/TestRestAdminData.java
deleted file mode 100644
index 892a20f6..00000000
--- a/src/test/java/org/onap/music/unittests/TestRestAdminData.java
+++ /dev/null
@@ -1,2244 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.onap.music.main.MusicCore.mLockHandle;
-
-import java.io.File;
-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.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.apache.curator.test.TestingServer;
-import org.apache.http.impl.client.AutoRetryHttpClient;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.mindrot.jbcrypt.BCrypt;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.music.conductor.conditionals.JsonConditional;
-import org.onap.music.conductor.conditionals.MusicConditional;
-import org.onap.music.conductor.conditionals.RestMusicConditionalAPI;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-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.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
-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 org.onap.music.main.ReturnType;
-import org.onap.music.rest.RestMusicAdminAPI;
-import org.onap.music.rest.RestMusicBmAPI;
-import org.onap.music.rest.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicHealthCheckAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import org.onap.music.rest.RestMusicTestAPI;
-import org.onap.music.rest.RestMusicVersionAPI;
-
-import com.datastax.driver.core.ConsistencyLevel;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@RunWith(MockitoJUnitRunner.class)
-public class TestRestAdminData {
-
- RestMusicDataAPI data = new RestMusicDataAPI();
- RestMusicAdminAPI admin = new RestMusicAdminAPI();
- RestMusicLocksAPI lock = new RestMusicLocksAPI();
- static PreparedQueryObject testObject;
- static TestingServer zkServer;
-
- @Mock
- HttpServletResponse http;
-
- @Mock
- UriInfo info;
-
- //* cjc out
- @Mock
- CachingUtil cachUtilMock;
-
- @InjectMocks
- private MusicCore mCore;
- //*/
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testCassa";
- static String tableName = "employees";
- static String tableNameConditional = "Conductor";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = null;
- static String lockId = null;
- static String lockName = "testCassa.employees.sample3";
-
- @BeforeClass
- public static void init() throws Exception {
- try {
- MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- MusicCore.mLockHandle = new MusicLockingService();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
- MusicCore.eventualPut(testObject);
- MusicCore.mDstoreHandle.close();
- MusicCore.mLockHandle.getzkLockHandle().close();
- MusicCore.mLockHandle.close();
- zkServer.stop();
- }
-
- @Test
- public void Test1_createKeyspace() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = "
- + "{'class' : 'SimpleStrategy' , "
- + "'replication_factor': 1} AND DURABLE_WRITES = true");
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "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)\n" + ");");
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString("bbc66ccc-d857-4e90-b1e5-df98a3d40de6")));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestApp1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestUser1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "select uuid from admin.keyspace_master where application_name = ? allow filtering");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- ResultSet rs = MusicCore.get(testObject);
- List<Row> rows = rs.all();
- if (rows.size() > 0) {
- System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));
- }
- }
-
- @Test
- public void Test2_createKeyspace() 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(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspace1() 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(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, 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, authorization,appName, 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,authorization, appName1, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401,response.getStatus());
- }
-
- @Test
- public void Test3_createKeyspace1() 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.createKeySpace("1", "1", "1", null,authorization, "TestApp1",
- jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspaceEmptyAuth() throws Exception {
-
- //MockitoAnnotations.initMocks(this);
- 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(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- //Map<String, Object> m1= new HashMap<>() ;
- //Mockito.when(CachingUtil.verifyOnboarding("x","y","x")).thenReturn(m1);
- //Mockito.when(CachingUtil.verifyOnboarding(appNamex,userId,password).thenReturn(m1));
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- String authDatax = ":"+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- try {
- Response response = data.createKeySpace("1", "1", "1", null,authorizationx, appName, jsonKeyspace, keyspaceName);
- //System.out.println("#######status is " + response.getStatus());
- //System.out.println("Entity" + response.getEntity());
- //assertNotEquals(200,response.getStatus());
- } catch (RuntimeException e ) {
- System.out.println("#######status is runtime exception= " + e);
- }
- }
-
- @Test
- public void Test3_createTable() 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, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
-
- @Test
- public void Test3_createTableClusterOrderBad() 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,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_salary");
- jsonTable.setClusteringOrder("ASC");
- 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, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertNotEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_createTable_withPropertiesNotNull() 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");
- Map<String, Object> properties = new HashMap<>();
- properties.put("comment","Testing prperties not null");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- String tableName_prop=tableName+"_Prop";
- jsonTable.setTableName(tableName_prop);
- jsonTable.setFields(fields);
- jsonTable.setProperties(properties);
-
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName_prop);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_createTable_duplicateTable() 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");
- String tableNameDup=tableName+"X";
- jsonTable.setTableName(tableNameDup);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- System.out.println("#######status for 1st time " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
-
- Response response0 = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- // 400 is the duplicate status found in response
- // Music 113 duplicate testing
- //import static org.junit.Assert.assertNotEquals;
- System.out.println("#######status for 2nd time " + response0.getStatus());
- System.out.println("Entity" + response0.getEntity());
-
- assertFalse("Duplicate table not created for "+tableNameDup, 200==response0.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, wrongAuthorization,
- 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_createTable3() 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, authorization,
- jsonTable, "wrong", tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTable3_with_samePartition_clusteringKeys() 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, emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("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, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test3_createTable3_with_Partition_clusteringKeys() 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");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("uuid");
- 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, authorization,
- jsonTable, keyspaceName, "tableName1");
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- // Improper parenthesis in key field
- @Test
- public void Test3_createTable_badParantesis() throws Exception {
- String tableNameC ="testTable0";
- 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),emp_id)");
- fields.put("emp_id", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id Desc");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(400, response.getStatus());
- assertTrue(200 != response.getStatus());
- }
-
-
- // good clustering key
- @Test
- public void Test3_createTable_1_clusterKey_good() throws Exception {
- String tableNameC ="testTableC1";
- 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),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- // jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- // bad partition key=clustering key
- @Test
- public void Test3_createTable_2_clusterKey_bad() throws Exception {
- String tableNameC ="testTableC2";
- 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),emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 !=response.getStatus());
- }
-
- // good composite partition key,clustering key
- @Test
- public void Test3_createTable_3_partition_clusterKey_good() throws Exception {
- String tableNameC ="testTableC3";
- 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_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- // bad - not all cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_4_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC4";
- 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_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
- // bad - wrong cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_5_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC5";
- 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_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
- // bad - wrong cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_6_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC6";
- 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_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("((uuid,emp_name),emp_id,emp_salary)"); // overridden by
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id desc, emp_salary ASC,uuid desc");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
-
- @Test
- public void Test3_createTableIndex_1() throws Exception {
- String tableNameC ="testTableCinx";
- 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),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"uuid",info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_createTableIndex_badindexname() throws Exception {
- String tableNameC ="testTableCinx";
- 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),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"uuid",info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test3_createTableIndex_wrongindex() throws Exception {
- String tableNameC ="testTableCinx";
- 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),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"id",info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable() 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", "testName");
- values.put("emp_salary", 500);
- 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, authorization, jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable2() 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, authorization,
- 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, wrongAuthorization,
- 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, authorization,
- jsonInsert, keyspaceName, "wrong");
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable5() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("id", "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, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable6() 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_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, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable7() 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", "test2");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable8() 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", "test3");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable9() 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", "test4");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable10() 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", "test5");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "critical");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable11() 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", "test6");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable12() 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", "test7");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- // need mock code to create error for MusicCore methods
- @Test
- public void Test5_updateTableAuthE() throws Exception {
- MockitoAnnotations.initMocks(this);
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test5_updateTableAuthException1() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax = ":";//+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- try {
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- } catch(RuntimeException e) {
- System.out.println("Update table Runtime exception="+e);
- }
- }
-
- @Test
- public void Test5_updateTableAuthEmpty() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax =":"+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- String appNamex="xx";
- try {
- // Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- Response response = data.updateTable("1", "1", "1", "", appNamex,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- } catch(RuntimeException e) {
- System.out.println("Update table Runtime exception="+e);
- }
- }
-
- @Test
- public void Test5_updateTable_wrongauth() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_invalidColumn() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("id", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_ttl() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName8");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTtl("1000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_timsetamp() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName9");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_ttl_timestamp() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName10");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTtl("1000");
- jsonUpdate.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_rowIdEmpty() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- //row.add("emp_name", "testName3");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTtl("1000");
- jsonUpdate.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_conditions() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- Map<String, Object> conditions = new HashMap<>();
- conditions.put("emp_name","testName3");
- row.add("emp_name", "testName3");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_eventual() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "eventual");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_critical() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "critical");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_atomic_delete_lock() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_select() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, 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
- public void Test6_select_withException() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- RestMusicDataAPI spyData = Mockito.spy(RestMusicDataAPI.class);
- Mockito.doThrow(MusicServiceException.class).when(spyData).selectSpecificQuery("v2", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, keyspaceName, tableName, info, -1);
- Response response = spyData.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_select_nodata() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName12");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, 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
- public void Test6_selectCritical_without_lockID() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "critical");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical_with_atomic_delete_lock() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical_with_nodata() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName12");
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_select_all() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();;
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable() 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, authorization,
- 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();
- 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, authorization,
- 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, authorization,
- null, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_columns() 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);
- ArrayList<String> columns = new ArrayList<>();
- columns.add("uuid");
- jsonDelete.setColumns(columns);
- 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, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_conditions() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> conditions = new HashMap<>();
- conditions.put("emp_name","testName3");
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- ArrayList<String> columns = new ArrayList<>();
- jsonDelete.setConditions(conditions);
- 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, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_eventual() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test2");
- consistencyInfo.put("type", "eventual");
- 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, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_critical() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test2");
- consistencyInfo.put("type", "critical");
- 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, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_atomic_delete_lock() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test3");
- consistencyInfo.put("type", "atomic_delete_lock");
- 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, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test7_dropTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
-
- @Test
- public void Test8_deleteKeyspace() 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",
- authorization,appName, keyspaceName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test8_deleteKeyspace1() 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",
- authorization,appName, "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",
- wrongAuthorization, appName, keyspaceName);
- assertEquals(401, 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 = (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"));
- }
-
- @Test
- public void Test6_onboard_duplicate() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Response response = admin.onboardAppWithMusic(jsonOnboard);
- assertEquals(400, response.getStatus());
- }
-
- // Missing appname
- @Test
- public void Test6_onboard1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- 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());
- 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 = (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.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));
- }
-
- @Test
- public void Test7_onboardSearch_empty() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- Response response = admin.getOnboardedInfoSearch(jsonOnboard);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test7_onboardSearch_invalidAid() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- Response response = admin.getOnboardedInfoSearch(jsonOnboard);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test8_onboardUpdate() 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("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");
- 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.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 = (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();
- 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 = (Map<String, Object>) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity();
- @SuppressWarnings("unchecked")
- Map<String, Object> resultMap1 = (Map<String, Object>) resultMap.get("lock");
- lockId = (String) resultMap1.get("lock");
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- @Test
- public void Test4_accquireLock() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.accquireLock(lockId,"1","1",authorization, null, appName).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 = (Map<String, Object>) lock.currentLockHolder(lockName,"1","1",authorization, null, appName).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 = (Map<String, Object>) lock.unLock(lockId,"1","1",authorization, null, appName).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 = (Map<String, Object>) lock.deleteLock(lockName,"1","1", null,authorization, appName).getEntity();
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- // Version api
- @Test
- public void Test1_version( ) {
- RestMusicVersionAPI versionapi = new RestMusicVersionAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Map<String, Object> resultMap = versionapi.version(servletResponse);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- //Music Test Api
- @Test
- public void Test2_testAPI() {
- RestMusicTestAPI musicTest = new RestMusicTestAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Map<String, HashMap<String, String>> resultMap = musicTest.simpleTests(servletResponse);
- assertNotNull(resultMap);
- }
-
- //Music Health Check
- @Test
- public void Test3_HealthCheck_cassandra() {
- String consistency = "ONE";
- RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Response response = healthCheck.cassandraStatus(servletResponse, consistency);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_HealthCheck_cassandra_cosistencyQuorum() {
- String consistency = "QUORUM";
- RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Response response = healthCheck.cassandraStatus(servletResponse, consistency);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_HealthCheck_zookeeper() {
- RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Response response = healthCheck.ZKStatus(servletResponse);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_pureZKcreate() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- bmApi.pureZkCreate("sample");
- }
-
- @Test
- public void Test4_pureZKUpdate() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- bmApi.pureZkCreate("sample1");
- 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", "testName_create");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkUpdate(jsonInsert, "sampleNode1");
- }
-
- @Test
- public void Test4_pureZKGet() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- bmApi.pureZkGet("sample");
- }
-
- @Test
- public void Test5_ZKAtomicPut_atomic() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- 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", "testName_create");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkAtomicPut(jsonInsert, "lockname", "sampleNode1");
- }
-
- @Test
- public void Test5_ZKAtomicPut_atomic_with_delete() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- 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", "testName_create");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkAtomicPut(jsonInsert, "lockname", "sampleNode1");
- }
-
- @Test
- public void Test5_ZKAtomicGet_atomic() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- 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", "testName_create");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkAtomicGet(jsonInsert, "lockname", "sampleNode1");
- }
-
- @Test
- public void Test5_ZKAtomicGet_atomic_with_delete() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- 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", "testName_create");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkAtomicGet(jsonInsert, "lockname", "sampleNode1");
- }
-
- @Test
- public void Test5_updateCassa() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName_create");
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- bmApi.updateTableCassa(jsonInsert, keyspaceName, tableName, info);
- }
-
- // RestMusicConditional
- @Test
- public void Test5_createTable_conditional() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("id", "text");
- fields.put("plans", "Map<text,text>");
- fields.put("PRIMARY KEY", "(id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("id");
- jsonTable.setTableName(tableNameConditional);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableNameConditional);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_insertConditional() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("status", "under-spin-up");
- cond1.put("status", "parked");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_insertConditional_primaryKey_null() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("status", "under-spin-up");
- cond1.put("status", "parked");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_insertConditional_wrongAuth() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("status", "under-spin-up");
- cond1.put("status", "parked");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_updateConditional() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("updated", "new time");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test7_updateConditional_wrongAuth() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("updated", "new time");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_updateConditional_primarykey_null() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("updated", "new time");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-} \ No newline at end of file
diff --git a/jar/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
index febf6c76..e9435ee1 100644
--- a/jar/src/test/java/org/onap/music/unittests/TestRestMusicData.java
+++ b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
@@ -19,6 +19,7 @@ package org.onap.music.unittests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.HashMap;
@@ -37,9 +38,12 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.mindrot.jbcrypt.BCrypt;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.music.datastore.CassaLockStore;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
import org.onap.music.datastore.jsonobjects.JsonInsert;
@@ -48,7 +52,7 @@ import org.onap.music.datastore.jsonobjects.JsonOnboard;
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;
@@ -58,6 +62,7 @@ import org.onap.music.rest.RestMusicLocksAPI;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
+import com.sun.jersey.core.util.Base64;
import com.sun.jersey.core.util.MultivaluedMapImpl;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -76,9 +81,21 @@ public class TestRestMusicData {
@Mock
UriInfo info;
+ //* cjc out
+ @Mock
+ CachingUtil cachUtilMock;
+
+ @InjectMocks
+ private MusicCore mCore;
+ //*/
+
static String appName = "TestApp";
static String userId = "TestUser";
static String password = "TestPassword";
+ static String authData = userId+":"+password;
+ static String wrongAuthData = userId+":"+"pass";
+ static String authorization = new String(Base64.encode(authData.getBytes()));
+ static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
static boolean isAAF = false;
static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
static String keyspaceName = "testCassa";
@@ -90,10 +107,9 @@ public class TestRestMusicData {
@BeforeClass
public static void init() throws Exception {
- try {
+ try {
MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- MusicCore.mLockHandle = new MusicLockingService();
+ MusicCore.mLockHandle = new CassaLockStore(MusicCore.mDstoreHandle);
} catch (Exception e) {
e.printStackTrace();
}
@@ -101,7 +117,6 @@ public class TestRestMusicData {
@AfterClass
public static void tearDownAfterClass() throws Exception {
- System.out.println("After class");
testObject = new PreparedQueryObject();
testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
MusicCore.eventualPut(testObject);
@@ -109,8 +124,6 @@ public class TestRestMusicData {
testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
MusicCore.eventualPut(testObject);
MusicCore.mDstoreHandle.close();
- MusicCore.mLockHandle.getzkLockHandle().close();
- MusicCore.mLockHandle.close();
zkServer.stop();
}
@@ -182,8 +195,7 @@ public class TestRestMusicData {
jsonKeyspace.setKeyspaceName(keyspaceName);
jsonKeyspace.setReplicationInfo(replicationInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null, appName, userId,
- password, jsonKeyspace, keyspaceName);
+ Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, keyspaceName);
System.out.println("#######status is " + response.getStatus());
System.out.println("Entity" + response.getEntity());
assertEquals(200,response.getStatus());
@@ -195,8 +207,7 @@ public class TestRestMusicData {
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);
+ Response response = data.createKeySpace("1", "1", "1", null, authorization,appName, jsonKeyspace, keyspaceName);
System.out.println("#######status is " + response.getStatus());
System.out.println("Entity" + response.getEntity());
assertEquals(400,response.getStatus());
@@ -209,8 +220,7 @@ public class TestRestMusicData {
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);
+ Response response = data.createKeySpace("1", "1", "1", null,authorization, appName1, jsonKeyspace, keyspaceName);
System.out.println("#######status is " + response.getStatus());
System.out.println("Entity" + response.getEntity());
assertEquals(401,response.getStatus());
@@ -229,14 +239,44 @@ public class TestRestMusicData {
jsonKeyspace.setKeyspaceName("TestApp1");
jsonKeyspace.setReplicationInfo(replicationInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null, "TestApp1",
- "TestUser1", password, jsonKeyspace, keyspaceName);
+ Response response = data.createKeySpace("1", "1", "1", null,authorization, "TestApp1",
+ jsonKeyspace, keyspaceName);
System.out.println("#######status is " + response.getStatus());
System.out.println("Entity" + response.getEntity());
- assertEquals(400,response.getStatus());
+ assertEquals(401,response.getStatus());
}
@Test
+ public void Test2_createKeyspaceEmptyAuth() throws Exception {
+
+ //MockitoAnnotations.initMocks(this);
+ 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(keyspaceName);
+ jsonKeyspace.setReplicationInfo(replicationInfo);
+ //Map<String, Object> m1= new HashMap<>() ;
+ //Mockito.when(CachingUtil.verifyOnboarding("x","y","x")).thenReturn(m1);
+ //Mockito.when(CachingUtil.verifyOnboarding(appNamex,userId,password).thenReturn(m1));
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ String authDatax = ":"+password;
+ String authorizationx = new String(Base64.encode(authDatax.getBytes()));
+ try {
+ Response response = data.createKeySpace("1", "1", "1", null,authorizationx, appName, jsonKeyspace, keyspaceName);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertNotEquals(200,response.getStatus());
+ } catch (RuntimeException e ) {
+ System.out.println("#######status is runtime exception= " + e);
+ }
+ }
+
+ @Test
public void Test3_createTable() throws Exception {
JsonTable jsonTable = new JsonTable();
Map<String, String> consistencyInfo = new HashMap<>();
@@ -253,12 +293,103 @@ public class TestRestMusicData {
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,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
+ jsonTable, keyspaceName, tableName);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+
+ @Test
+ public void Test3_createTableClusterOrderBad() 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,emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name,emp_salary");
+ jsonTable.setClusteringOrder("ASC");
+ 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, authorization,
jsonTable, keyspaceName, tableName);
System.out.println("#######status is " + response.getStatus());
System.out.println("Entity" + response.getEntity());
+ assertNotEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void Test3_createTable_withPropertiesNotNull() 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");
+ Map<String, Object> properties = new HashMap<>();
+ properties.put("comment","Testing prperties not null");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ String tableName_prop=tableName+"_Prop";
+ jsonTable.setTableName(tableName_prop);
+ jsonTable.setFields(fields);
+ jsonTable.setProperties(properties);
+
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
+ jsonTable, keyspaceName, tableName_prop);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
assertEquals(200, response.getStatus());
}
+
+ @Test
+ public void Test3_createTable_duplicateTable() 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");
+ String tableNameDup=tableName+"X";
+ jsonTable.setTableName(tableNameDup);
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameDup);
+ System.out.println("#######status for 1st time " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+
+ Response response0 = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameDup);
+ // 400 is the duplicate status found in response
+ // Music 113 duplicate testing
+ //import static org.junit.Assert.assertNotEquals;
+ System.out.println("#######status for 2nd time " + response0.getStatus());
+ System.out.println("Entity" + response0.getEntity());
+
+ assertFalse("Duplicate table not created for "+tableNameDup, 200==response0.getStatus());
+
+ }
// Improper Auth
@Test
@@ -278,7 +409,7 @@ public class TestRestMusicData {
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",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
jsonTable, keyspaceName, tableName);
System.out.println("#######status is " + response.getStatus());
System.out.println("Entity" + response.getEntity());
@@ -287,7 +418,7 @@ public class TestRestMusicData {
// Improper keyspace
@Test
- public void Test3_createTable2() throws Exception {
+ public void Test3_createTable3() throws Exception {
JsonTable jsonTable = new JsonTable();
Map<String, String> consistencyInfo = new HashMap<>();
Map<String, String> fields = new HashMap<>();
@@ -303,14 +434,249 @@ public class TestRestMusicData {
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,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
jsonTable, "wrong", tableName);
System.out.println("#######status is " + response.getStatus());
System.out.println("Entity" + response.getEntity());
assertEquals(401, response.getStatus());
}
+
+ // Improper parenthesis in key field
+ @Test
+ public void Test3_createTable_badParantesis() throws Exception {
+ String tableNameC ="testTable0";
+ 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),emp_id)");
+ fields.put("emp_id", "varint");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_id Desc");
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameC);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ //assertEquals(400, response.getStatus());
+ assertTrue(200 != response.getStatus());
+ }
+
+ // good clustering key
+ @Test
+ public void Test3_createTable_1_clusterKey_good() throws Exception {
+ String tableNameC ="testTableC1";
+ 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),emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ // jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameC);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+ // bad partition key=clustering key
+ @Test
+ public void Test3_createTable_2_clusterKey_bad() throws Exception {
+ String tableNameC ="testTableC2";
+ 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),emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameC);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertTrue(200 !=response.getStatus());
+ }
+
+ // good composite partition key,clustering key
+ @Test
+ public void Test3_createTable_3_partition_clusterKey_good() throws Exception {
+ String tableNameC ="testTableC3";
+ 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_id", "varint");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameC);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+ // bad - not all cols in order by of composite partition key,clustering key
+ @Test
+ public void Test3_createTable_4_clusteringOrder_bad() throws Exception {
+ String tableNameC ="testTableC4";
+ 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_id", "varint");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((emp_name),emp_id,emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameC);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertTrue(200 != response.getStatus());
+ }
+
+ // bad - wrong cols in order by of composite partition key,clustering key
+ @Test
+ public void Test3_createTable_5_clusteringOrder_bad() throws Exception {
+ String tableNameC ="testTableC5";
+ 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_id", "varint");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC");
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameC);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertTrue(200 != response.getStatus());
+ }
+
+ // bad - wrong cols in order by of composite partition key,clustering key
+ @Test
+ public void Test3_createTable_6_clusteringOrder_bad() throws Exception {
+ String tableNameC ="testTableC6";
+ 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_id", "varint");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("((uuid,emp_name),emp_id,emp_salary)"); // overridden by
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_id desc, emp_salary ASC,uuid desc");
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameC);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ assertTrue(200 != response.getStatus());
+ }
+
+
+ // good clustering key, need to pass queryparameter
+ @Test
+ public void Test3_createTableIndex_1() throws Exception {
+ String tableNameC ="testTableCinx";
+ 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),emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ // jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ jsonTable, keyspaceName, tableNameC);
+ System.out.println("#######status is " + response.getStatus());
+ System.out.println("Entity" + response.getEntity());
+ // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
+ // info.setQueryParameters("index_name=inx_uuid");
+ Map<String,String> queryParametersMap =new HashMap<String, String>();
+
+ queryParametersMap.put("index_name","inxuuid");
+ // Mockito.when(info.getQueryParameters()).thenReturn(new MultivaluedMap<String, String>(queryParametersMap));
+ try {
+ response = data.createIndex("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ keyspaceName, tableNameC,"uuid",info);
+ assertEquals(200, response.getStatus());
+ } catch (NullPointerException e) {
+
+ }
+ }
@Test
public void Test4_insertIntoTable() throws Exception {
@@ -327,7 +693,7 @@ public class TestRestMusicData {
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, tableName);
+ appName, authorization, jsonInsert, keyspaceName, tableName);
assertEquals(200, response.getStatus());
}
@@ -346,7 +712,7 @@ public class TestRestMusicData {
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,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
jsonInsert, keyspaceName, tableName);
assertEquals(200, response.getStatus());
}
@@ -367,7 +733,7 @@ public class TestRestMusicData {
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",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
jsonInsert, keyspaceName, tableName);
assertEquals(401, response.getStatus());
}
@@ -388,13 +754,12 @@ public class TestRestMusicData {
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,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
jsonInsert, keyspaceName, "wrong");
assertEquals(400, response.getStatus());
}
-
@Test
public void Test5_updateTable() throws Exception {
JsonUpdate jsonUpdate = new JsonUpdate();
@@ -411,11 +776,99 @@ public class TestRestMusicData {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Mockito.when(info.getQueryParameters()).thenReturn(row);
Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- userId, password, jsonUpdate, keyspaceName, tableName, info);
+ authorization, jsonUpdate, keyspaceName, tableName, info);
+ assertEquals(200, response.getStatus());
+ }
+
+ // need mock code to create error for MusicCore methods
+ @Test
+ public void Test5_updateTableAuthE() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ Map<String, Object> values = new HashMap<>();
+ row.add("emp_name", "testName");
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "atomic");
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+ //add ttl & timestamp
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ //Map<String, Object> m1= new HashMap<>() ;
+ //Mockito.when(MusicCore.autheticateUser(appName,userId,password,keyspaceName,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6","updateTable")).thenReturn(m1);
+ try {
+ Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonUpdate, keyspaceName, tableName, info);
assertEquals(200, response.getStatus());
+ } catch(NullPointerException e) {
+
+ }
+ }
+
+ @Test
+ public void Test5_updateTableAuthException1() throws Exception {
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ Map<String, Object> values = new HashMap<>();
+ row.add("emp_name", "testName");
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "atomic");
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ String authDatax = ":";//+password;
+ String authorizationx = new String(Base64.encode(authDatax.getBytes()));
+ try {
+ Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorizationx, jsonUpdate, keyspaceName, tableName, info);
+ assertEquals(200, response.getStatus());
+ } catch(RuntimeException e) {
+ System.out.println("Update table Runtime exception="+e);
+
+ }
}
@Test
+ public void Test5_updateTableAuthEmpty() throws Exception {
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ Map<String, Object> values = new HashMap<>();
+ row.add("emp_name", "testName");
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "atomic");
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ String authDatax =":"+password;
+ String authorizationx = new String(Base64.encode(authDatax.getBytes()));
+ String appNamex="xx";
+ try {
+ // Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ Response response = data.updateTable("1", "1", "1", "", appNamex,
+ authorizationx, jsonUpdate, keyspaceName, tableName, info);
+ assertEquals(200, response.getStatus());
+ } catch(RuntimeException e) {
+ System.out.println("Update table Runtime exception="+e);
+
+ }
+ }
+
+
+ @Test
public void Test6_select() throws Exception {
JsonSelect jsonSelect = new JsonSelect();
Map<String, String> consistencyInfo = new HashMap<>();
@@ -426,7 +879,7 @@ public class TestRestMusicData {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Mockito.when(info.getQueryParameters()).thenReturn(row);
Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, userId, password, keyspaceName, tableName, info);
+ appName, authorization, 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());
@@ -443,7 +896,7 @@ public class TestRestMusicData {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Mockito.when(info.getQueryParameters()).thenReturn(row);
Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, userId, password, jsonInsert, keyspaceName, tableName,info);
+ appName, authorization, 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());
@@ -460,7 +913,7 @@ public class TestRestMusicData {
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,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
jsonDelete, keyspaceName, tableName, info);
assertEquals(200, response.getStatus());
}
@@ -476,7 +929,7 @@ public class TestRestMusicData {
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,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
jsonDelete, keyspaceName, tableName, info);
assertEquals(400, response.getStatus());
}
@@ -493,7 +946,7 @@ public class TestRestMusicData {
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,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
null, keyspaceName, tableName, info);
assertEquals(400, response.getStatus());
}
@@ -506,11 +959,12 @@ public class TestRestMusicData {
jsonTable.setConsistencyInfo(consistencyInfo);
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Response response = data.dropTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
keyspaceName, tableName);
assertEquals(200, response.getStatus());
}
+
@Test
public void Test8_deleteKeyspace() throws Exception {
JsonKeySpace jsonKeyspace = new JsonKeySpace();
@@ -525,7 +979,7 @@ public class TestRestMusicData {
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);
+ authorization,appName, keyspaceName);
assertEquals(200, response.getStatus());
}
@@ -543,7 +997,7 @@ public class TestRestMusicData {
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);
+ wrongAuthorization, appName, keyspaceName);
assertEquals(401, response.getStatus());
}
@@ -554,7 +1008,7 @@ public class TestRestMusicData {
Map<String, Object> replicationInfo = new HashMap<>();
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, userId, password, keyspaceName);
+ authorization, appName, keyspaceName);
assertEquals(400, response.getStatus());
}
@@ -681,7 +1135,7 @@ public class TestRestMusicData {
@Test
public void Test3_createLockReference() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.createLockReference(lockName,"1","1", null, appName, userId, password).getEntity();
+ Map<String, Object> resultMap = (Map<String, Object>) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity();
@SuppressWarnings("unchecked")
Map<String, Object> resultMap1 = (Map<String, Object>) resultMap.get("lock");
lockId = (String) resultMap1.get("lock");
@@ -691,28 +1145,28 @@ public class TestRestMusicData {
@Test
public void Test4_accquireLock() throws Exception {
Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.accquireLock(lockId,"1","1", null, appName, userId, password).getEntity();
+ Map<String, Object> resultMap = (Map<String, Object>) lock.accquireLock(lockId,"1","1",authorization, null, appName).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 = (Map<String, Object>) lock.currentLockHolder(lockName,"1","1", null, appName, userId, password).getEntity();
+ Map<String, Object> resultMap = (Map<String, Object>) lock.currentLockHolder(lockName,"1","1",authorization, null, appName).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 = (Map<String, Object>) lock.unLock(lockId,"1","1", null, appName, userId, password).getEntity();
+ Map<String, Object> resultMap = (Map<String, Object>) lock.unLock(lockId,"1","1",authorization, null, appName).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 = (Map<String, Object>) lock.deleteLock(lockName,"1","1", null, appName, userId, password).getEntity();
+ Map<String, Object> resultMap = (Map<String, Object>) lock.deleteLock(lockName,"1","1", null,authorization, appName).getEntity();
assertEquals(ResultType.SUCCESS, resultMap.get("status"));
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
index e75835d1..bdc6558a 100644
--- a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
+++ b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
@@ -46,6 +46,7 @@ import org.mindrot.jbcrypt.BCrypt;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.music.datastore.CassaLockStore;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
import org.onap.music.datastore.jsonobjects.JsonInsert;
@@ -55,7 +56,6 @@ import org.onap.music.datastore.jsonobjects.JsonKeySpace;
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.MusicCore;
import org.onap.music.main.MusicUtil;
//import org.onap.music.main.ResultType;
@@ -122,11 +122,9 @@ public class TestRestMusicQAPI {
@BeforeClass
public static void init() throws Exception {
try {
- System.out.println("before class cassandra");
MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- System.out.println("before class zoo");
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- MusicCore.mLockHandle = new MusicLockingService();
+ MusicCore.mLockHandle = new CassaLockStore(MusicCore.mDstoreHandle);
+
// System.out.println("before class keysp");
//resp=data.createKeySpace(majorV,minorV,patchV,aid,appName,userId,password,kspObject,keyspaceName);
//System.out.println("after keyspace="+keyspaceName);
@@ -213,8 +211,6 @@ public class TestRestMusicQAPI {
testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
MusicCore.eventualPut(testObject);
MusicCore.mDstoreHandle.close();
- MusicCore.mLockHandle.getzkLockHandle().close();
- MusicCore.mLockHandle.close();
zkServer.stop();
}
diff --git a/src/test/java/org/onap/music/unittests/TestVotingApp.java b/src/test/java/org/onap/music/unittests/TestVotingApp.java
new file mode 100644
index 00000000..19b10fe8
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TestVotingApp.java
@@ -0,0 +1,115 @@
+package org.onap.music.unittests;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicLockingException;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.main.MusicCore;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+
+/**
+ *
+ */
+public class TestVotingApp
+{
+ String keyspaceName;
+ String tableName;
+
+ public TestVotingApp() throws MusicServiceException {
+ keyspaceName = "VotingAppForMusic"+System.currentTimeMillis();
+ tableName = "votecount";
+ }
+
+ private void initialize() throws MusicServiceException {
+ createVotingKeyspace();
+ System.out.println("Created keyspaces");
+ createVotingTable();
+ System.out.println("Created tables");
+
+ createEntryForCandidate("Popeye");
+ createEntryForCandidate("Judy");
+ createEntryForCandidate("Flash");
+ createEntryForCandidate("Mickey");
+ System.out.println("Created candidates");
+ }
+
+ private void createVotingKeyspace() throws MusicServiceException {
+ Map<String,Object> replicationInfo = new HashMap<String, Object>();
+ replicationInfo.put("'class'", "'SimpleStrategy'");
+ replicationInfo.put("'replication_factor'", 1);
+
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE KEYSPACE " + keyspaceName + " WITH REPLICATION = " + replicationInfo.toString().replaceAll("=", ":"));
+
+ try {
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+ } catch (MusicServiceException e) {
+ throw(e);
+ }
+ }
+
+ private void createVotingTable() throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "CREATE TABLE " + keyspaceName + "." + tableName + " (name text PRIMARY KEY, count int);");
+
+ try {
+ MusicCore.createTable(keyspaceName, tableName, queryObject, "eventual");
+ } catch (MusicServiceException e) {
+ throw (e);
+ }
+ }
+
+ private void createEntryForCandidate(String candidateName) throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "INSERT INTO " + keyspaceName + "." + tableName + " (name, count) "
+ + "VALUES ('"+candidateName+"', 0);");
+
+ MusicCore.nonKeyRelatedPut(queryObject, "eventual");
+ }
+
+
+ private void updateVoteCount(String candidateName, int numVotes) throws MusicLockingException, MusicQueryException, MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString(
+ "UPDATE " + keyspaceName + "." + tableName + " SET count="+numVotes + " where name='"+candidateName+"';");
+ MusicCore.atomicPut(keyspaceName, tableName, candidateName, queryObject, null);
+ }
+
+ private HashMap<String, Integer> readAllVotes() throws MusicServiceException {
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+ queryObject.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName);
+ ResultSet rs = MusicCore.get(queryObject);
+ HashMap<String, Integer> voteCount = new HashMap<String, Integer>();
+ for(Row candidate : rs.all()) {
+ voteCount.put(candidate.getString("name"), candidate.getInt("count"));
+ }
+ return voteCount;
+ }
+
+ public static void main( String[] args ) throws Exception {
+ TestVotingApp tva = new TestVotingApp();
+ tva.initialize();
+
+ tva.updateVoteCount("Popeye",5);
+ tva.updateVoteCount("Judy",9);
+ tva.updateVoteCount("Mickey",8);
+ tva.updateVoteCount("Flash",1);
+ tva.updateVoteCount("Flash",2);
+
+ HashMap<String, Integer> voteCount = tva.readAllVotes();
+ System.out.println(voteCount);
+ assert(voteCount.get("Popeye") == 5);
+ assert(voteCount.get("Judy") == 9);
+ assert(voteCount.get("Mickey") == 8);
+ assert(voteCount.get("Flash") == 2);
+ }
+
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java
deleted file mode 100644
index 7f6af4c5..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 IBM.
- * ===================================================================
- * 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.unittests.jsonobjects;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.onap.music.datastore.jsonobjects.JSONObject;
-
-public class JSONObjectTest {
- private JSONObject jsonObject;
-
- @Before
- public void setUp() {
- jsonObject = new JSONObject();
- }
-
- @Test
- public void testGetSetData() {
- jsonObject.setData("data");
- Assert.assertEquals("data", jsonObject.getData());
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonNotifyClientResponseTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonNotifyClientResponseTest.java
deleted file mode 100644
index 07f4dbb4..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonNotifyClientResponseTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2018 IBM.
- * ===================================================================
- * 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.unittests.jsonobjects;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.onap.music.datastore.jsonobjects.JsonNotifyClientResponse;
-
-public class JsonNotifyClientResponseTest {
- private JsonNotifyClientResponse response;
-
- @Before
- public void setUp() {
- response = new JsonNotifyClientResponse();
- }
-
- @Test
- public void testGetSetMethods() {
- response.setMessage("message");
- response.setStatus("success");
- Assert.assertEquals("message", response.getMessage());
- Assert.assertEquals("success", response.getStatus());
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java
deleted file mode 100644
index ee4d3933..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2018 IBM.
- * ===================================================================
- * 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.unittests.jsonobjects;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.onap.music.datastore.jsonobjects.NameSpace;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class NameSpaceTest {
- private NameSpace nameSpace;
-
- @Before
- public void setUp() {
- nameSpace = new NameSpace();
- }
-
- @Test
- public void testGetSetAdmin() {
- List<String> list = new ArrayList<String>();
- list.add("admin");
- nameSpace.setAdmin(list);
- Assert.assertEquals(list, nameSpace.getAdmin());
- }
-
- @Test
- public void testGetSetName() {
- nameSpace.setName("name");
- Assert.assertEquals("name", nameSpace.getName());
- }
-}
diff --git a/version.properties b/version.properties
index ecd85846..ecb60096 100755..100644
--- a/version.properties
+++ b/version.properties
@@ -4,7 +4,7 @@
major=3
minor=0
-patch=22
+patch=2
base_version=${major}.${minor}.${patch}