From 46350c084766789ea59e83f1917c57c81d653048 Mon Sep 17 00:00:00 2001 From: "Tschaen, Brendan" Date: Tue, 16 Oct 2018 20:22:35 -0400 Subject: Include Cassandra locking Change-Id: I085acf8336d5f27782ee12768846a5befd3ee60d Issue-ID: MUSIC-148 Signed-off-by: Tschaen, Brendan --- INFO.yaml | 0 README.md | 4 +- WebContent/WEB-INF/web.xml | 5 - distribution/cassandra/Dockerfile | 7 +- distribution/cassandra/cassandra.yaml | 5 +- distribution/cassandra_job/Dockerfile | 9 - distribution/cassandra_job/admin.cql | 17 - distribution/cassandra_job/admin_pw.cql | 2 - distribution/cassandra_job/runcql.sh | 71 - distribution/cassandra_job/test.cql | 2 - docs/architecture.rst | 10 +- docs/authentication.rst | 27 +- docs/configuration.rst | 27 +- docs/index.rst | 12 +- docs/installation.rst | 20 +- docs/logging.rst | 13 +- docs/release-notes.rst | 53 +- docs/setup.rst | 8 +- docs/single.rst | 2 +- docs/swagger.json | 2118 +----------------- example/VotingApp/README.md | 31 + example/VotingApp/pom.xml | 92 + .../VotingApp/src/main/java/main/JsonDelete.java | 61 + .../VotingApp/src/main/java/main/JsonInsert.java | 67 + .../VotingApp/src/main/java/main/JsonKeySpace.java | 58 + .../VotingApp/src/main/java/main/JsonTable.java | 55 + .../src/main/java/main/MusicConnector.java | 76 + example/VotingApp/src/main/java/main/Util.java | 6 + .../VotingApp/src/main/java/main/VotingAppJar.java | 115 + .../src/main/java/main/VotingAppREST.java | 513 +++++ example/VotingAppJar/VotingAppJar/pom.xml | 30 + .../org/onap/music/VotingAppJar/VotingAppJar.java | 115 + .../java/org/onap/music/VotingAppJar/AppTest.java | 38 + examples/VotingApp/README.md | 31 - examples/VotingApp/dependency-reduced-pom.xml | 38 - examples/VotingApp/pom.xml | 122 -- .../VotingApp/src/main/java/main/JsonDelete.java | 61 - .../VotingApp/src/main/java/main/JsonInsert.java | 67 - .../VotingApp/src/main/java/main/JsonKeySpace.java | 58 - .../VotingApp/src/main/java/main/JsonTable.java | 55 - .../src/main/java/main/MusicConnector.java | 76 - examples/VotingApp/src/main/java/main/Util.java | 6 - .../VotingApp/src/main/java/main/VotingApp.java | 513 ----- jar/DO_NOT_EDIT_ANYTHING_IN_THIS_FOLDER.md | 1 - jar/pom.xml | 29 +- jar/src/main/java/LICENSE.txt | 24 - .../org/onap/music/datastore/MusicDataStore.java | 469 ---- .../onap/music/datastore/PreparedQueryObject.java | 79 - .../music/datastore/jsonobjects/AAFResponse.java | 42 - .../music/datastore/jsonobjects/JSONObject.java | 37 - .../music/datastore/jsonobjects/JsonDelete.java | 87 - .../music/datastore/jsonobjects/JsonInsert.java | 122 -- .../music/datastore/jsonobjects/JsonKeySpace.java | 77 - .../datastore/jsonobjects/JsonLeasedLock.java | 52 - .../music/datastore/jsonobjects/JsonOnboard.java | 83 - .../music/datastore/jsonobjects/JsonSelect.java | 59 - .../music/datastore/jsonobjects/JsonTable.java | 117 - .../music/datastore/jsonobjects/JsonUpdate.java | 132 -- .../music/datastore/jsonobjects/NameSpace.java | 47 - .../music/eelf/healthcheck/MusicHealthCheck.java | 175 -- .../music/eelf/logging/EELFLoggerDelegate.java | 354 --- .../music/eelf/logging/format/AppMessages.java | 183 -- .../onap/music/eelf/logging/format/ErrorCodes.java | 106 - .../music/eelf/logging/format/ErrorSeverity.java | 37 - .../onap/music/eelf/logging/format/ErrorTypes.java | 44 - .../music/exceptions/MusicExceptionMapper.java | 53 - .../music/exceptions/MusicLockingException.java | 74 - .../exceptions/MusicPolicyVoilationException.java | 79 - .../onap/music/exceptions/MusicQueryException.java | 89 - .../music/exceptions/MusicServiceException.java | 84 - .../onap/music/lockingservice/LockListener.java | 39 - .../onap/music/lockingservice/MusicLockState.java | 137 -- .../music/lockingservice/MusicLockingService.java | 184 -- .../onap/music/lockingservice/ProtocolSupport.java | 208 -- .../org/onap/music/lockingservice/ZNodeName.java | 118 - .../lockingservice/ZkStatelessLockService.java | 339 --- .../music/lockingservice/ZooKeeperOperation.java | 42 - .../main/java/org/onap/music/main/CachingUtil.java | 420 ---- .../main/java/org/onap/music/main/CipherUtil.java | 269 --- .../java/org/onap/music/main/CronJobManager.java | 47 - .../main/java/org/onap/music/main/MusicCore.java | 992 --------- .../main/java/org/onap/music/main/MusicDigest.java | 78 - .../main/java/org/onap/music/main/MusicUtil.java | 572 ----- .../org/onap/music/main/PropertiesListener.java | 151 -- .../main/java/org/onap/music/main/ResultType.java | 41 - .../main/java/org/onap/music/main/ReturnType.java | 74 - .../music/response/jsonobjects/JsonResponse.java | 265 --- .../org/onap/music/rest/RestMusicAdminAPI.java | 372 ---- .../java/org/onap/music/rest/RestMusicBmAPI.java | 307 --- .../java/org/onap/music/rest/RestMusicDataAPI.java | 1289 ----------- .../onap/music/rest/RestMusicHealthCheckAPI.java | 113 - .../org/onap/music/rest/RestMusicLocksAPI.java | 423 ---- .../java/org/onap/music/rest/RestMusicQAPI.java | 251 --- .../java/org/onap/music/rest/RestMusicTestAPI.java | 67 - .../org/onap/music/rest/RestMusicVersionAPI.java | 63 - jar/src/main/resources/LICENSE.txt | 24 - jar/src/main/resources/Resources.properties | 50 - jar/src/main/resources/cache.ccf | 56 - jar/src/main/resources/logback.xml | 270 --- jar/src/main/resources/project.properties | 4 - jar/src/test/java/LICENSE.txt | 24 - .../org/onap/music/unittests/CassandraCQL.java | 256 --- .../org/onap/music/unittests/JsonResponseTest.java | 83 - .../onap/music/unittests/MusicDataStoreTest.java | 162 -- .../org/onap/music/unittests/MusicUtilTest.java | 207 -- .../org/onap/music/unittests/ResultTypeTest.java | 43 - .../org/onap/music/unittests/ReturnTypeTest.java | 83 - .../org/onap/music/unittests/TestLockStore.java | 53 - .../org/onap/music/unittests/TestMusicCore.java | 489 ----- .../music/unittests/TestMusicCoreIntegration.java | 176 -- .../onap/music/unittests/TestRestMusicData.java | 718 ------- .../unittests/jsonobjects/AAFResponseTest.java | 54 - .../unittests/jsonobjects/JsonDeleteTest.java | 86 - .../unittests/jsonobjects/JsonInsertTest.java | 86 - .../unittests/jsonobjects/JsonKeySpaceTest.java | 72 - .../unittests/jsonobjects/JsonLeasedLockTest.java | 53 - .../unittests/jsonobjects/JsonOnboardTest.java | 78 - .../unittests/jsonobjects/JsonSelectTest.java | 41 - .../music/unittests/jsonobjects/JsonTableTest.java | 99 - .../unittests/jsonobjects/JsonUpdateTest.java | 103 - jar/version.properties | 13 - musictrigger/pom.xml | 158 +- musictrigger/src/MusicTrigger.java | 129 +- pom.xml | 61 +- .../conductor/conditionals/JsonConditional.java | 4 +- .../conductor/conditionals/MusicConditional.java | 47 +- .../conditionals/RestMusicConditionalAPI.java | 4 +- .../org/onap/music/datastore/CassaDataStore.java | 475 +++++ .../org/onap/music/datastore/CassaLockStore.java | 173 ++ .../org/onap/music/datastore/MusicDataStore.java | 483 ----- .../org/onap/music/datastore/MusicLockState.java | 41 + .../onap/music/datastore/PreparedQueryObject.java | 5 + .../jsonobjects/JSONCallbackResponse.java | 89 - .../music/datastore/jsonobjects/JsonCallback.java | 135 -- .../music/datastore/jsonobjects/JsonDelete.java | 4 +- .../music/datastore/jsonobjects/JsonInsert.java | 5 +- .../datastore/jsonobjects/JsonNotification.java | 119 -- .../jsonobjects/JsonNotifyClientResponse.java | 59 - .../music/datastore/jsonobjects/JsonSelect.java | 5 +- .../music/datastore/jsonobjects/JsonUpdate.java | 9 +- .../music/eelf/healthcheck/MusicHealthCheck.java | 31 +- .../onap/music/lockingservice/LockListener.java | 39 - .../onap/music/lockingservice/MusicLockState.java | 140 -- .../music/lockingservice/MusicLockingService.java | 168 -- .../onap/music/lockingservice/ProtocolSupport.java | 210 -- .../org/onap/music/lockingservice/ZNodeName.java | 118 - .../lockingservice/ZkStatelessLockService.java | 363 ---- .../music/lockingservice/ZooKeeperOperation.java | 42 - src/main/java/org/onap/music/main/CachingUtil.java | 75 +- .../java/org/onap/music/main/CronJobManager.java | 94 +- src/main/java/org/onap/music/main/MusicCore.java | 776 +++---- src/main/java/org/onap/music/main/MusicUtil.java | 83 +- .../org/onap/music/main/PropertiesListener.java | 9 - .../java/org/onap/music/main/VotingAppJar.java | 115 + .../music/response/jsonobjects/JsonResponse.java | 9 +- .../org/onap/music/rest/RestMusicAdminAPI.java | 480 +---- .../java/org/onap/music/rest/RestMusicBmAPI.java | 307 --- .../java/org/onap/music/rest/RestMusicDataAPI.java | 76 +- .../onap/music/rest/RestMusicHealthCheckAPI.java | 20 - .../org/onap/music/rest/RestMusicLocksAPI.java | 23 +- .../java/org/onap/music/rest/RestMusicQAPI.java | 35 +- .../org/onap/music/rest/RestMusicVersionAPI.java | 3 + src/main/resources/logback.xml | 7 +- .../org/onap/music/unittests/CassandraCQL.java | 6 +- .../onap/music/unittests/MusicDataStoreTest.java | 4 +- .../onap/music/unittests/MusicLockStoreTest.java | 170 ++ .../onap/music/unittests/TestCassaLockStore.java | 71 + .../org/onap/music/unittests/TestLockStore.java | 53 - .../org/onap/music/unittests/TestMusicCore.java | 711 +------ .../music/unittests/TestMusicCoreIntegration.java | 53 +- .../onap/music/unittests/TestRestAdminData.java | 2244 -------------------- .../onap/music/unittests/TestRestMusicData.java | 1172 ++++++++++ .../onap/music/unittests/TestRestMusicQAPI.java | 10 +- .../org/onap/music/unittests/TestVotingApp.java | 115 + .../unittests/jsonobjects/JSONObjectTest.java | 44 - .../jsonobjects/JsonNotifyClientResponseTest.java | 46 - .../music/unittests/jsonobjects/NameSpaceTest.java | 56 - version.properties | 2 +- 178 files changed, 4373 insertions(+), 23287 deletions(-) delete mode 100644 INFO.yaml delete mode 100644 distribution/cassandra_job/Dockerfile delete mode 100644 distribution/cassandra_job/admin.cql delete mode 100644 distribution/cassandra_job/admin_pw.cql delete mode 100644 distribution/cassandra_job/runcql.sh delete mode 100644 distribution/cassandra_job/test.cql create mode 100644 example/VotingApp/README.md create mode 100644 example/VotingApp/pom.xml create mode 100644 example/VotingApp/src/main/java/main/JsonDelete.java create mode 100644 example/VotingApp/src/main/java/main/JsonInsert.java create mode 100644 example/VotingApp/src/main/java/main/JsonKeySpace.java create mode 100644 example/VotingApp/src/main/java/main/JsonTable.java create mode 100644 example/VotingApp/src/main/java/main/MusicConnector.java create mode 100644 example/VotingApp/src/main/java/main/Util.java create mode 100644 example/VotingApp/src/main/java/main/VotingAppJar.java create mode 100644 example/VotingApp/src/main/java/main/VotingAppREST.java create mode 100644 example/VotingAppJar/VotingAppJar/pom.xml create mode 100644 example/VotingAppJar/VotingAppJar/src/main/java/org/onap/music/VotingAppJar/VotingAppJar.java create mode 100644 example/VotingAppJar/VotingAppJar/src/test/java/org/onap/music/VotingAppJar/AppTest.java delete mode 100644 examples/VotingApp/README.md delete mode 100644 examples/VotingApp/dependency-reduced-pom.xml delete mode 100644 examples/VotingApp/pom.xml delete mode 100644 examples/VotingApp/src/main/java/main/JsonDelete.java delete mode 100644 examples/VotingApp/src/main/java/main/JsonInsert.java delete mode 100644 examples/VotingApp/src/main/java/main/JsonKeySpace.java delete mode 100644 examples/VotingApp/src/main/java/main/JsonTable.java delete mode 100644 examples/VotingApp/src/main/java/main/MusicConnector.java delete mode 100644 examples/VotingApp/src/main/java/main/Util.java delete mode 100644 examples/VotingApp/src/main/java/main/VotingApp.java delete mode 100644 jar/DO_NOT_EDIT_ANYTHING_IN_THIS_FOLDER.md delete mode 100644 jar/src/main/java/LICENSE.txt delete mode 100644 jar/src/main/java/org/onap/music/datastore/MusicDataStore.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/PreparedQueryObject.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/AAFResponse.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/JSONObject.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonInsert.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonKeySpace.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonLeasedLock.java delete mode 100755 jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonOnboard.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonSelect.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/JsonUpdate.java delete mode 100644 jar/src/main/java/org/onap/music/datastore/jsonobjects/NameSpace.java delete mode 100644 jar/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java delete mode 100644 jar/src/main/java/org/onap/music/eelf/logging/EELFLoggerDelegate.java delete mode 100644 jar/src/main/java/org/onap/music/eelf/logging/format/AppMessages.java delete mode 100644 jar/src/main/java/org/onap/music/eelf/logging/format/ErrorCodes.java delete mode 100644 jar/src/main/java/org/onap/music/eelf/logging/format/ErrorSeverity.java delete mode 100644 jar/src/main/java/org/onap/music/eelf/logging/format/ErrorTypes.java delete mode 100644 jar/src/main/java/org/onap/music/exceptions/MusicExceptionMapper.java delete mode 100644 jar/src/main/java/org/onap/music/exceptions/MusicLockingException.java delete mode 100644 jar/src/main/java/org/onap/music/exceptions/MusicPolicyVoilationException.java delete mode 100644 jar/src/main/java/org/onap/music/exceptions/MusicQueryException.java delete mode 100644 jar/src/main/java/org/onap/music/exceptions/MusicServiceException.java delete mode 100644 jar/src/main/java/org/onap/music/lockingservice/LockListener.java delete mode 100644 jar/src/main/java/org/onap/music/lockingservice/MusicLockState.java delete mode 100644 jar/src/main/java/org/onap/music/lockingservice/MusicLockingService.java delete mode 100644 jar/src/main/java/org/onap/music/lockingservice/ProtocolSupport.java delete mode 100644 jar/src/main/java/org/onap/music/lockingservice/ZNodeName.java delete mode 100644 jar/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java delete mode 100644 jar/src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java delete mode 100755 jar/src/main/java/org/onap/music/main/CachingUtil.java delete mode 100644 jar/src/main/java/org/onap/music/main/CipherUtil.java delete mode 100644 jar/src/main/java/org/onap/music/main/CronJobManager.java delete mode 100644 jar/src/main/java/org/onap/music/main/MusicCore.java delete mode 100644 jar/src/main/java/org/onap/music/main/MusicDigest.java delete mode 100755 jar/src/main/java/org/onap/music/main/MusicUtil.java delete mode 100755 jar/src/main/java/org/onap/music/main/PropertiesListener.java delete mode 100644 jar/src/main/java/org/onap/music/main/ResultType.java delete mode 100644 jar/src/main/java/org/onap/music/main/ReturnType.java delete mode 100644 jar/src/main/java/org/onap/music/response/jsonobjects/JsonResponse.java delete mode 100755 jar/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java delete mode 100644 jar/src/main/java/org/onap/music/rest/RestMusicBmAPI.java delete mode 100755 jar/src/main/java/org/onap/music/rest/RestMusicDataAPI.java delete mode 100644 jar/src/main/java/org/onap/music/rest/RestMusicHealthCheckAPI.java delete mode 100644 jar/src/main/java/org/onap/music/rest/RestMusicLocksAPI.java delete mode 100755 jar/src/main/java/org/onap/music/rest/RestMusicQAPI.java delete mode 100644 jar/src/main/java/org/onap/music/rest/RestMusicTestAPI.java delete mode 100644 jar/src/main/java/org/onap/music/rest/RestMusicVersionAPI.java delete mode 100644 jar/src/main/resources/LICENSE.txt delete mode 100644 jar/src/main/resources/Resources.properties delete mode 100644 jar/src/main/resources/cache.ccf delete mode 100644 jar/src/main/resources/logback.xml delete mode 100644 jar/src/main/resources/project.properties delete mode 100644 jar/src/test/java/LICENSE.txt delete mode 100644 jar/src/test/java/org/onap/music/unittests/CassandraCQL.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/JsonResponseTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/MusicUtilTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/ResultTypeTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/ReturnTypeTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/TestLockStore.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/TestMusicCore.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/TestRestMusicData.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java delete mode 100644 jar/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java delete mode 100644 jar/version.properties mode change 100755 => 100644 musictrigger/src/MusicTrigger.java create mode 100644 src/main/java/org/onap/music/datastore/CassaDataStore.java create mode 100644 src/main/java/org/onap/music/datastore/CassaLockStore.java delete mode 100644 src/main/java/org/onap/music/datastore/MusicDataStore.java create mode 100644 src/main/java/org/onap/music/datastore/MusicLockState.java delete mode 100755 src/main/java/org/onap/music/datastore/jsonobjects/JSONCallbackResponse.java delete mode 100755 src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java delete mode 100755 src/main/java/org/onap/music/datastore/jsonobjects/JsonNotification.java delete mode 100644 src/main/java/org/onap/music/datastore/jsonobjects/JsonNotifyClientResponse.java delete mode 100644 src/main/java/org/onap/music/lockingservice/LockListener.java delete mode 100644 src/main/java/org/onap/music/lockingservice/MusicLockState.java delete mode 100644 src/main/java/org/onap/music/lockingservice/MusicLockingService.java delete mode 100644 src/main/java/org/onap/music/lockingservice/ProtocolSupport.java delete mode 100644 src/main/java/org/onap/music/lockingservice/ZNodeName.java delete mode 100644 src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java delete mode 100644 src/main/java/org/onap/music/lockingservice/ZooKeeperOperation.java create mode 100644 src/main/java/org/onap/music/main/VotingAppJar.java delete mode 100644 src/main/java/org/onap/music/rest/RestMusicBmAPI.java create mode 100644 src/test/java/org/onap/music/unittests/MusicLockStoreTest.java create mode 100644 src/test/java/org/onap/music/unittests/TestCassaLockStore.java delete mode 100644 src/test/java/org/onap/music/unittests/TestLockStore.java delete mode 100644 src/test/java/org/onap/music/unittests/TestRestAdminData.java create mode 100644 src/test/java/org/onap/music/unittests/TestRestMusicData.java create mode 100644 src/test/java/org/onap/music/unittests/TestVotingApp.java delete mode 100644 src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java delete mode 100644 src/test/java/org/onap/music/unittests/jsonobjects/JsonNotifyClientResponseTest.java delete mode 100644 src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java mode change 100755 => 100644 version.properties diff --git a/INFO.yaml b/INFO.yaml deleted file mode 100644 index e69de29b..00000000 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 - - - org.onap.music.main.CronJobManager - - music-servlet 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 WITH PASSWORD = '' 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 `_ +.. 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 -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 - Multi-Site Install - 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 + Muili-Site Install 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 - Multi-Site Install +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 `_ CriticalPut is causing HTTP Status 500 – Internal Server Error +:Release Date: yyyy-mm-dd - - `MUSIC-34 `_ CreateTable,InsertIntoTable,UpdateTable,DeleteFromTable,DropTable don't check resource existence - - `MUSIC-35 `_ Onboarding issues - - `MUSIC-36 `_ Test Case failing +**New Features** - - `MUSIC-37 `_ Acquire lock to return more information +One or two sentences explaining the purpose of this Release. +**Bug Fixes** + - `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 `_. + - `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 `_ -- `MUSIC project page `_ -- `Passing Badge information for MUSIC `_ -- `Project Vulnerability Review Table for MUSIC `_ **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 - Multi-Site Install - Authentication + Muili-Site Install + 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 - Multi-Site Install - Authentication + Muili-Site Install + 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/example/VotingApp/README.md b/example/VotingApp/README.md new file mode 100644 index 00000000..bcd37b9b --- /dev/null +++ b/example/VotingApp/README.md @@ -0,0 +1,31 @@ + +The voting app for MUSIC illustrates the features of MUSIC as a +multi-site state management +service. It is a program that +maintains state in MUSIC in the form of a vote-count table that has two columns, the candidateName +and his voteCount. To the external client that is using the voting app to update votes, the +votingApp provides a simple function to update the +votecount of the candidate in an exclusive manner. This is possible because of the locking service +in MUSIC. Since each candidate is a key in MUSIC, the votingapp simply acquires the geo-distributed +lock and only then upates the count. This guarantees correctness even when clients access different +end-points across data centers. Further since state is replicated correctly across data-centers, +even when one of the data centers fail, functioning can continue simply by using the MUSIC end point +in the other data center. + +The main function in the VotingApp.java is emulating clients from different data centers by randomly +chosing MUSIC end points. By updating vote counts +randomly using different MUSIC end points and still receiving the correct total count when doing a +read, the main function indicates the multi-site capability of MUSIC. + + +To run the application, make sure you have onboarded the application using music's admin api. +A curl call using the default values would be: +curl -X POST \ + http://localhost:8080/MUSIC/rest/v2/admin/onboardAppWithMusic \ + -H 'Content-Type: application/json' \ + -d '{ +"appname" : "votingapp", +"userId" : "abc123d", +"password" : "password", +"isAAF" : false +}' diff --git a/example/VotingApp/pom.xml b/example/VotingApp/pom.xml new file mode 100644 index 00000000..87cac6c0 --- /dev/null +++ b/example/VotingApp/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + com.att.reserarch.VoteAppForMUSIC + VoteAppForMUSIC + 0.0.1-SNAPSHOT + + + + + maven2-repository.java.net + Java.net Repository for Maven + http://download.java.net/maven/2/ + default + + + + + + + com.sun.jersey + jersey-server + 1.9 + + + com.sun.jersey + jersey-json + 1.18.1 + + + com.owlike + genson + 0.99 + + + com.sun.jersey + jersey-client + 1.9 + + + + com.sun.jersey + jersey-json + 1.9 + + + + com.sun.jersey + jersey-bundle + 1.18 + + + + com.googlecode.json-simple + json-simple + 1.1 + + + com.datastax.cassandra + cassandra-driver-core + 3.0.0 + + + org.apache.zookeeper + zookeeper + 3.4.6 + + + + + \ No newline at end of file diff --git a/example/VotingApp/src/main/java/main/JsonDelete.java b/example/VotingApp/src/main/java/main/JsonDelete.java new file mode 100644 index 00000000..9b75f875 --- /dev/null +++ b/example/VotingApp/src/main/java/main/JsonDelete.java @@ -0,0 +1,61 @@ +/* + * +This licence applies to all files in this repository unless otherwise specifically +stated inside of the file. + + --------------------------------------------------------------------------- + Copyright (c) 2016 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. + --------------------------------------------------------------------------- + + */ +package main; + +import java.util.ArrayList; +import java.util.Map; + +public class JsonDelete { + + private ArrayList columns = null; + private Map consistencyInfo; + + public Map getConsistencyInfo() { + return consistencyInfo; + } + + public void setConsistencyInfo(Map consistencyInfo) { + this.consistencyInfo = consistencyInfo; + } + + public ArrayList getColumns() { + return columns; + } + public void setColumns(ArrayList columns) { + this.columns = columns; + } + String ttl, timestamp; + + public String getTtl() { + return ttl; + } + public void setTtl(String ttl) { + this.ttl = ttl; + } + public String getTimestamp() { + return timestamp; + } + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } +} diff --git a/example/VotingApp/src/main/java/main/JsonInsert.java b/example/VotingApp/src/main/java/main/JsonInsert.java new file mode 100644 index 00000000..a2099c16 --- /dev/null +++ b/example/VotingApp/src/main/java/main/JsonInsert.java @@ -0,0 +1,67 @@ +/* + * +This licence applies to all files in this repository unless otherwise specifically +stated inside of the file. + + --------------------------------------------------------------------------- + Copyright (c) 2016 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. + --------------------------------------------------------------------------- + + */ +package main; + +import java.util.Map; + +import org.codehaus.jackson.annotate.JsonIgnoreProperties; +public class JsonInsert { + + private Map values; + String ttl, timestamp; + private Map row_specification; + private Map consistencyInfo; + + public Map getConsistencyInfo() { + return consistencyInfo; + } + + public void setConsistencyInfo(Map consistencyInfo) { + this.consistencyInfo = consistencyInfo; + } + + public String getTtl() { + return ttl; + } + public void setTtl(String ttl) { + this.ttl = ttl; + } + public String getTimestamp() { + return timestamp; + } + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + public Map getValues() { + return values; + } + public void setValues(Map values) { + this.values = values; + } + public Map getRow_specification() { + return row_specification; + } + public void setRow_specification(Map row_specification) { + this.row_specification = row_specification; + } +} diff --git a/example/VotingApp/src/main/java/main/JsonKeySpace.java b/example/VotingApp/src/main/java/main/JsonKeySpace.java new file mode 100644 index 00000000..ff7b6c67 --- /dev/null +++ b/example/VotingApp/src/main/java/main/JsonKeySpace.java @@ -0,0 +1,58 @@ +/* + * +This licence applies to all files in this repository unless otherwise specifically +stated inside of the file. + + --------------------------------------------------------------------------- + Copyright (c) 2016 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. + --------------------------------------------------------------------------- + + */ +package main; + +import java.util.Map; + + +public class JsonKeySpace { + private Map replicationInfo; + private String durabilityOfWrites; + private Map consistencyInfo; + + public Map getConsistencyInfo() { + return consistencyInfo; + } + + public void setConsistencyInfo(Map consistencyInfo) { + this.consistencyInfo = consistencyInfo; + } + + public Map getReplicationInfo() { + return replicationInfo; + } + + public void setReplicationInfo(Map replicationInfo) { + this.replicationInfo = replicationInfo; + } + + public String getDurabilityOfWrites() { + return durabilityOfWrites; + } + public void setDurabilityOfWrites(String durabilityOfWrites) { + this.durabilityOfWrites = durabilityOfWrites; + } + + + +} diff --git a/example/VotingApp/src/main/java/main/JsonTable.java b/example/VotingApp/src/main/java/main/JsonTable.java new file mode 100644 index 00000000..66171af2 --- /dev/null +++ b/example/VotingApp/src/main/java/main/JsonTable.java @@ -0,0 +1,55 @@ +/* + * +This licence applies to all files in this repository unless otherwise specifically +stated inside of the file. + + --------------------------------------------------------------------------- + Copyright (c) 2016 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. + --------------------------------------------------------------------------- + + */ +package main; +import java.util.Map; + +public class JsonTable { + private Map fields; + private Map properties; + private Map consistencyInfo; + + + public Map getConsistencyInfo() { + return consistencyInfo; + } + + public void setConsistencyInfo(Map consistencyInfo) { + this.consistencyInfo = consistencyInfo; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + + public Map getFields() { + return fields; + } + + public void setFields(Map fields) { + this.fields = fields; + } +} diff --git a/example/VotingApp/src/main/java/main/MusicConnector.java b/example/VotingApp/src/main/java/main/MusicConnector.java new file mode 100644 index 00000000..d6ed20ba --- /dev/null +++ b/example/VotingApp/src/main/java/main/MusicConnector.java @@ -0,0 +1,76 @@ +/* + * +This licence applies to all files in this repository unless otherwise specifically +stated inside of the file. + + --------------------------------------------------------------------------- + Copyright (c) 2016 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. + --------------------------------------------------------------------------- + + */ +package main; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Random; + +public class MusicConnector { + + //change this to point to relevant cluster + public String[] musicNodes; + + public MusicConnector(String[] musicNodes){ + this.musicNodes = musicNodes; + } + + private String getMusicNodeIp(){ + Random r = new Random(); + int index = r.nextInt(musicNodes.length); + return musicNodes[index]; + } + + public String getMusicNodeURL(){ + String musicurl = "http://"+getMusicNodeIp()+":8080/MUSIC/rest/v2"; + return musicurl; + } + + public boolean isHostUp(String serverAddress) { + Boolean isUp = false; + try { + InetAddress inet = InetAddress.getByName(serverAddress); + isUp = inet.isReachable(1000); + } catch (UnknownHostException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return isUp; + } + + /* + private static String getMusicNodeIp(){ + + //return "54.224.168.13"; + return bigSiteMusicNode; + String serverAddress; + serverAddress = agaveMusicNode; + while(isHostUp(serverAddress) != true) + serverAddress = toggle(serverAddress); + return serverAddress; + }*/ +} diff --git a/example/VotingApp/src/main/java/main/Util.java b/example/VotingApp/src/main/java/main/Util.java new file mode 100644 index 00000000..aefa9a36 --- /dev/null +++ b/example/VotingApp/src/main/java/main/Util.java @@ -0,0 +1,6 @@ +package main; + +public class Util { + public static final String version="1.0.0"; + +} 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 replicationInfo = new HashMap(); + 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/VotingApp/src/main/java/main/VotingAppREST.java b/example/VotingApp/src/main/java/main/VotingAppREST.java new file mode 100644 index 00000000..a7b08368 --- /dev/null +++ b/example/VotingApp/src/main/java/main/VotingAppREST.java @@ -0,0 +1,513 @@ +/* + * +This licence applies to all files in this repository unless otherwise specifically +stated inside of the file. + + --------------------------------------------------------------------------- + Copyright (c) 2016 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. + --------------------------------------------------------------------------- + + */ +package main; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +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.api.client.WebResource.Builder; +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 VotingAppREST { + String keyspaceName; + ArrayList lockNames; + MusicConnector musicHandle; + private final String version="1.0.0"; + + //UPDATE your onboarding information here + String namespace = "votingapp"; + String userId = "abc123d"; + String password = "password"; + + public VotingAppREST(String[] musicIps){ + lockNames = new ArrayList(); + musicHandle = new MusicConnector(musicIps); + bootStrap(); + } + + /** + * Adds MUSIC's authentication headers into the webresource + * @param webResource + */ + private Builder addMusicHeaders(WebResource webResource) { + Builder builder = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON); + if (!namespace.equals("")) { + builder.header("ns", namespace); + } + if (!userId.equals("")) { + builder.header("userId", userId); + } + if (!password.equals("")) { + builder.header("password", password); + } + + return builder; + } + + public void createVotingKeyspace(){ + keyspaceName = "VotingAppForMusic"; + System.out.println("Voting app version "+ version+" ....."); + Map replicationInfo = new HashMap(); + replicationInfo.put("class", "SimpleStrategy"); + replicationInfo.put("replication_factor", 1); + String durabilityOfWrites="false"; + Map consistencyInfo= new HashMap(); + consistencyInfo.put("type", "eventual"); + JsonKeySpace jsonKp = new JsonKeySpace(); + jsonKp.setConsistencyInfo(consistencyInfo); + jsonKp.setDurabilityOfWrites(durabilityOfWrites); + jsonKp.setReplicationInfo(replicationInfo); + + ClientConfig clientConfig = new DefaultClientConfig(); + + clientConfig.getFeatures().put( + JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + + Client client = Client.create(clientConfig); + + WebResource webResource = client + .resource(musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName); + + ClientResponse response = addMusicHeaders(webResource).accept("application/json") + .type("application/json").post(ClientResponse.class, jsonKp); + if (response.getStatus() < 200 || (response.getStatus() > 299 && response.getStatus()!=400)) { //supress keyspace already exists + Map map = response.getEntity(Map.class); + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus() + "- " + map); + } + + } + + public void createVotingTable(){ + Map fields = new HashMap(); + fields.put("name", "text"); + fields.put("count", "varint"); + fields.put("PRIMARY KEY", "(name)"); + + + Map consistencyInfo= new HashMap(); + consistencyInfo.put("type", "eventual"); + + JsonTable jtab = new JsonTable(); + jtab.setFields(fields); + jtab.setConsistencyInfo(consistencyInfo); + + ClientConfig clientConfig = new DefaultClientConfig(); + + clientConfig.getFeatures().put( + JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + + Client client = Client.create(clientConfig); + String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount"; + System.out.println("create url:"+url); + WebResource webResource = client + .resource(url); + + ClientResponse response = addMusicHeaders(webResource).accept("application/json") + .type("application/json").post(ClientResponse.class, jtab); + + System.out.println(response.getEntity(Map.class)); + if (response.getStatus() < 200 || (response.getStatus() > 299 && response.getStatus()!=400)) + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); + + } + private void checkMusicVersion(){ + Client client = Client.create(); + System.out.println(musicHandle.getMusicNodeURL()+"/version"); + + +// System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); + WebResource webResource = client + .resource(musicHandle.getMusicNodeURL()+"/version"); + + + ClientResponse response = addMusicHeaders(webResource) + .accept(MediaType.APPLICATION_JSON).header("Connection", "close").get(ClientResponse.class); + + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + + String output = response.getEntity(Map.class).toString(); + + System.out.println(output); + + } + + private void createEntryForCandidate(String candidateName){ + Map values = new HashMap(); + values.put("name",candidateName ); + values.put("count",0); + + Map consistencyInfo= new HashMap(); + consistencyInfo.put("type", "eventual"); + + JsonInsert jIns = new JsonInsert(); + jIns.setValues(values); + jIns.setConsistencyInfo(consistencyInfo); + ClientConfig clientConfig = new DefaultClientConfig(); + + clientConfig.getFeatures().put( + JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + + Client client = Client.create(clientConfig); + + String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows"; + WebResource webResource = client + .resource(url); + + ClientResponse response = addMusicHeaders(webResource).accept("application/json") + .type("application/json").post(ClientResponse.class, jIns); + + if (response.getStatus() < 200 || response.getStatus() > 299) + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+"url:"+url+" candidate name:"+ candidateName); + + + } + + private String createLock(String lockName){ + Client client = Client.create(); + String msg = musicHandle.getMusicNodeURL()+"/locks/create/"+lockName; + WebResource webResource = client.resource(msg); + System.out.println(msg); + WebResource.Builder wb = addMusicHeaders(webResource).accept(MediaType.APPLICATION_JSON); + + ClientResponse response = wb.post(ClientResponse.class); + + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+"url:"+msg); + } + + Map responseMap = response.getEntity(Map.class); + + String lockid = ((Map) responseMap.get("lock")).get("lock"); +// System.out.println("Server response .... \n"); +// System.out.println(output); + return lockid; + } + + private boolean acquireLock(String lockId){ + Client client = Client.create(); + String msg = musicHandle.getMusicNodeURL()+"/locks/acquire/"+lockId; + System.out.println(msg); + WebResource webResource = client.resource(msg); + + + WebResource.Builder wb = addMusicHeaders(webResource).accept(MediaType.APPLICATION_JSON); + + ClientResponse response = wb.get(ClientResponse.class); + + Map responseMap = response.getEntity(Map.class); + + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+ ":" + responseMap); + } + + System.out.println(responseMap); + Boolean status = responseMap.get("status").equals("SUCCESS"); + System.out.println("Server response .... " + status); + return status; + } + + private void unlock(String lockId){ + Client client = Client.create(); + WebResource webResource = client.resource(musicHandle.getMusicNodeURL()+"/locks/release/"+lockId); + + ClientResponse response = addMusicHeaders(webResource).delete(ClientResponse.class); + + + if (response.getStatus() < 200 || response.getStatus()>299) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + } + + private void updateVoteCountAtomically(String candidateName,int count){ + /*create lock for the candidate. The music API dictates that + * the lock name must be of the form keyspacename.tableName.primaryKeyName + * */ + System.out.println("trying to acquire lock!"); + + String lockName = keyspaceName+".votecount."+candidateName; + lockNames.add(lockName); + String lockId = createLock(lockName); + while(acquireLock(lockId) != true); + + System.out.println("acquired lock!"); + //update candidate entry if you have the lock + Map values = new HashMap(); + values.put("count",count); + + Map consistencyInfo= new HashMap(); + consistencyInfo.put("type", "critical"); + consistencyInfo.put("lockId", lockId); + + JsonInsert jIns = new JsonInsert(); + jIns.setValues(values); + jIns.setConsistencyInfo(consistencyInfo); + ClientConfig clientConfig = new DefaultClientConfig(); + + clientConfig.getFeatures().put( + JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + + Client client = Client.create(clientConfig); + String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows?name="+candidateName; + System.out.println(url); + WebResource webResource = client + .resource(url); + + ClientResponse response = addMusicHeaders(webResource).accept("application/json") + .type("application/json").put(ClientResponse.class, jIns); + + Map map = response.getEntity(Map.class); + + if (response.getStatus() < 200 || response.getStatus() > 299) + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+":"+map); + + //release lock now that the operation is done + unlock(lockId); + + } + + private void deleteCandidateEntryEventually(String candidateName){ + Map consistencyInfo= new HashMap(); + consistencyInfo.put("type", "eventual"); + + JsonDelete jDel = new JsonDelete(); + jDel.setConsistencyInfo(consistencyInfo); + ClientConfig clientConfig = new DefaultClientConfig(); + + clientConfig.getFeatures().put( + JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + + Client client = Client.create(clientConfig); + String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows?name="+candidateName; + System.out.println(url); + WebResource webResource = client + .resource(url); + + ClientResponse response = addMusicHeaders(webResource).accept("application/json") + .type("application/json").delete(ClientResponse.class, jDel); + + if (response.getStatus() < 200 || response.getStatus() > 299) + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+"url:"+url); + + } + + public Map readVoteCountForCandidate(String candidateName){ + ClientConfig clientConfig = new DefaultClientConfig(); + + clientConfig.getFeatures().put( + JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + + Client client = Client.create(clientConfig); + String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows?name="+candidateName; + WebResource webResource = client + .resource(url); + + ClientResponse response = addMusicHeaders(webResource).accept("application/json").get(ClientResponse.class); + + if (response.getStatus() < 200 || response.getStatus() > 299) + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); + + Map output = response.getEntity(Map.class); + return output; + } + + public Map readAllVotes(){ + ClientConfig clientConfig = new DefaultClientConfig(); + + clientConfig.getFeatures().put( + JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + + Client client = Client.create(clientConfig); + String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows"; + WebResource webResource = client + .resource(url); + + ClientResponse response = addMusicHeaders(webResource).accept("application/json").get(ClientResponse.class); + + if (response.getStatus() < 200 || response.getStatus() > 299) + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); + + Map output = response.getEntity(Map.class); + return output; + } + + + /* + * Unable to use this because of the error: + * Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: java.net.ProtocolException: + * HTTP method DELETE doesn't support output. Seems to be a error in the rest java combination according to the interwebs + */ + private void dropKeySpace(){ + Map consistencyInfo= new HashMap(); + consistencyInfo.put("type", "eventual"); + + JsonKeySpace jsonKp = new JsonKeySpace(); + jsonKp.setConsistencyInfo(consistencyInfo); + + ClientConfig clientConfig = new DefaultClientConfig(); + + clientConfig.getFeatures().put( + JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + + Client client = Client.create(clientConfig); + + WebResource webResource = client + .resource(musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName); + + ClientResponse response = addMusicHeaders(webResource).type("application/json") + .delete(ClientResponse.class, jsonKp); + + if (response.getStatus() < 200 || response.getStatus() > 299) + throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); + } + + private void deleteLock(String lockName){ + Client client = Client.create(); + WebResource webResource = client.resource(musicHandle.getMusicNodeURL()+"/locks/delete/"+lockName); + + ClientResponse response = addMusicHeaders(webResource).delete(ClientResponse.class); + + + if (response.getStatus() <200 || response.getStatus()>299) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + } + + private void resetMusic(){ + Client client = Client.create(); + WebResource webResource = client.resource(musicHandle.getMusicNodeURL()+"/reset"); + + ClientResponse response = addMusicHeaders(webResource).delete(ClientResponse.class); + + + if (response.getStatus() != 204) { + throw new RuntimeException("Failed : HTTP error code : " + + response.getStatus()); + } + + } + public void deleteAllLocks(){ + for (String lockName : lockNames) { + deleteLock(lockName); + } + } + + + public void bootStrap(){ + checkMusicVersion(); + createVotingKeyspace(); + + + createVotingTable(); + + + //the next few lines just create an entry in the voting table for all these candidates with vote count as 0 + createEntryForCandidate("Popeye"); + + createEntryForCandidate("Judy"); + + createEntryForCandidate("Flash"); + + createEntryForCandidate("Mickey"); + + } + + public void overAllTests(){ + //update the count atomically + updateVoteCountAtomically("Popeye",5); + + updateVoteCountAtomically("Judy",7); + + updateVoteCountAtomically("Mickey",8); + + updateVoteCountAtomically("Flash",2); + + + //read votecount + System.out.println(readAllVotes()); + + System.out.println(readVoteCountForCandidate("Popeye")); + + System.out.println(readVoteCountForCandidate("Flash")); + + deleteCandidateEntryEventually("Mickey"); + + System.out.println(readAllVotes()); + +// dropKeySpace(); + + deleteAllLocks(); + } + + public void flipTest(){ + checkMusicVersion(); + } + + public static String executeBashScript(String pathToScript, String arg1, String arg2){ + try { + ProcessBuilder pb = new ProcessBuilder(pathToScript,arg1, arg2); + final Process process = pb.start(); + InputStream is = process.getInputStream(); + InputStreamReader isr = new InputStreamReader(is); + BufferedReader br = new BufferedReader(isr); + return br.readLine(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public static void main(String[] args) { + long start = System.currentTimeMillis(); + + if (args.length==0) { + args = new String[]{"localhost"}; + } + for(int i =0; i < 2;++i){ + VotingAppREST vHandle = new VotingAppREST(args); + vHandle.overAllTests(); + + System.out.println("====================================="); + System.out.println("Test no."+i+" completed:"); + } + long diff = System.currentTimeMillis() - start; + System.out.println(diff); + } + + +} \ No newline at end of file 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 @@ + + 4.0.0 + + org.onap.music + VotingAppJar + 0.0.1-SNAPSHOT + jar + + VotingAppJar + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + org.onap.music + MUSIC + 3.0.2 + + + 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 replicationInfo = new HashMap(); + 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/README.md b/examples/VotingApp/README.md deleted file mode 100644 index bcd37b9b..00000000 --- a/examples/VotingApp/README.md +++ /dev/null @@ -1,31 +0,0 @@ - -The voting app for MUSIC illustrates the features of MUSIC as a -multi-site state management -service. It is a program that -maintains state in MUSIC in the form of a vote-count table that has two columns, the candidateName -and his voteCount. To the external client that is using the voting app to update votes, the -votingApp provides a simple function to update the -votecount of the candidate in an exclusive manner. This is possible because of the locking service -in MUSIC. Since each candidate is a key in MUSIC, the votingapp simply acquires the geo-distributed -lock and only then upates the count. This guarantees correctness even when clients access different -end-points across data centers. Further since state is replicated correctly across data-centers, -even when one of the data centers fail, functioning can continue simply by using the MUSIC end point -in the other data center. - -The main function in the VotingApp.java is emulating clients from different data centers by randomly -chosing MUSIC end points. By updating vote counts -randomly using different MUSIC end points and still receiving the correct total count when doing a -read, the main function indicates the multi-site capability of MUSIC. - - -To run the application, make sure you have onboarded the application using music's admin api. -A curl call using the default values would be: -curl -X POST \ - http://localhost:8080/MUSIC/rest/v2/admin/onboardAppWithMusic \ - -H 'Content-Type: application/json' \ - -d '{ -"appname" : "votingapp", -"userId" : "abc123d", -"password" : "password", -"isAAF" : false -}' 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 @@ - - - 4.0.0 - com.att.reserarch.VoteAppForMUSIC - VoteAppForMUSIC - 0.0.1-SNAPSHOT - - - - maven-shade-plugin - - - default-jar - package - - shade - - - - - - main.VotingApp - - - - - - - - - - - maven2-repository.java.net - Java.net Repository for Maven - http://download.java.net/maven/2/ - - - diff --git a/examples/VotingApp/pom.xml b/examples/VotingApp/pom.xml deleted file mode 100644 index 0c85e60b..00000000 --- a/examples/VotingApp/pom.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - 4.0.0 - com.att.reserarch.VoteAppForMUSIC - VoteAppForMUSIC - jar - 0.0.1-SNAPSHOT - - - - - maven2-repository.java.net - Java.net Repository for Maven - http://download.java.net/maven/2/ - default - - - - - - - com.sun.jersey - jersey-server - 1.9 - - - com.sun.jersey - jersey-json - 1.18.1 - - - com.owlike - genson - 0.99 - - - com.sun.jersey - jersey-client - 1.9 - - - - com.sun.jersey - jersey-json - 1.9 - - - - - - com.googlecode.json-simple - json-simple - 1.1 - - - com.datastax.cassandra - cassandra-driver-core - 3.0.0 - - - org.apache.zookeeper - zookeeper - 3.4.6 - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.1 - - - - - - maven-shade-plugin - - - default-jar - package - - shade - - - - - - main.VotingApp - - - - - - - - - - diff --git a/examples/VotingApp/src/main/java/main/JsonDelete.java b/examples/VotingApp/src/main/java/main/JsonDelete.java deleted file mode 100644 index 9b75f875..00000000 --- a/examples/VotingApp/src/main/java/main/JsonDelete.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * -This licence applies to all files in this repository unless otherwise specifically -stated inside of the file. - - --------------------------------------------------------------------------- - Copyright (c) 2016 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. - --------------------------------------------------------------------------- - - */ -package main; - -import java.util.ArrayList; -import java.util.Map; - -public class JsonDelete { - - private ArrayList columns = null; - private Map consistencyInfo; - - public Map getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map consistencyInfo) { - this.consistencyInfo = consistencyInfo; - } - - public ArrayList getColumns() { - return columns; - } - public void setColumns(ArrayList columns) { - this.columns = columns; - } - String ttl, timestamp; - - public String getTtl() { - return ttl; - } - public void setTtl(String ttl) { - this.ttl = ttl; - } - public String getTimestamp() { - return timestamp; - } - public void setTimestamp(String timestamp) { - this.timestamp = timestamp; - } -} diff --git a/examples/VotingApp/src/main/java/main/JsonInsert.java b/examples/VotingApp/src/main/java/main/JsonInsert.java deleted file mode 100644 index a2099c16..00000000 --- a/examples/VotingApp/src/main/java/main/JsonInsert.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * -This licence applies to all files in this repository unless otherwise specifically -stated inside of the file. - - --------------------------------------------------------------------------- - Copyright (c) 2016 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. - --------------------------------------------------------------------------- - - */ -package main; - -import java.util.Map; - -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -public class JsonInsert { - - private Map values; - String ttl, timestamp; - private Map row_specification; - private Map consistencyInfo; - - public Map getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map consistencyInfo) { - this.consistencyInfo = consistencyInfo; - } - - public String getTtl() { - return ttl; - } - public void setTtl(String ttl) { - this.ttl = ttl; - } - public String getTimestamp() { - return timestamp; - } - public void setTimestamp(String timestamp) { - this.timestamp = timestamp; - } - public Map getValues() { - return values; - } - public void setValues(Map values) { - this.values = values; - } - public Map getRow_specification() { - return row_specification; - } - public void setRow_specification(Map row_specification) { - this.row_specification = row_specification; - } -} diff --git a/examples/VotingApp/src/main/java/main/JsonKeySpace.java b/examples/VotingApp/src/main/java/main/JsonKeySpace.java deleted file mode 100644 index ff7b6c67..00000000 --- a/examples/VotingApp/src/main/java/main/JsonKeySpace.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * -This licence applies to all files in this repository unless otherwise specifically -stated inside of the file. - - --------------------------------------------------------------------------- - Copyright (c) 2016 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. - --------------------------------------------------------------------------- - - */ -package main; - -import java.util.Map; - - -public class JsonKeySpace { - private Map replicationInfo; - private String durabilityOfWrites; - private Map consistencyInfo; - - public Map getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map consistencyInfo) { - this.consistencyInfo = consistencyInfo; - } - - public Map getReplicationInfo() { - return replicationInfo; - } - - public void setReplicationInfo(Map replicationInfo) { - this.replicationInfo = replicationInfo; - } - - public String getDurabilityOfWrites() { - return durabilityOfWrites; - } - public void setDurabilityOfWrites(String durabilityOfWrites) { - this.durabilityOfWrites = durabilityOfWrites; - } - - - -} diff --git a/examples/VotingApp/src/main/java/main/JsonTable.java b/examples/VotingApp/src/main/java/main/JsonTable.java deleted file mode 100644 index 66171af2..00000000 --- a/examples/VotingApp/src/main/java/main/JsonTable.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * -This licence applies to all files in this repository unless otherwise specifically -stated inside of the file. - - --------------------------------------------------------------------------- - Copyright (c) 2016 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. - --------------------------------------------------------------------------- - - */ -package main; -import java.util.Map; - -public class JsonTable { - private Map fields; - private Map properties; - private Map consistencyInfo; - - - public Map getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map consistencyInfo) { - this.consistencyInfo = consistencyInfo; - } - - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - - public Map getFields() { - return fields; - } - - public void setFields(Map fields) { - this.fields = fields; - } -} diff --git a/examples/VotingApp/src/main/java/main/MusicConnector.java b/examples/VotingApp/src/main/java/main/MusicConnector.java deleted file mode 100644 index d6ed20ba..00000000 --- a/examples/VotingApp/src/main/java/main/MusicConnector.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * -This licence applies to all files in this repository unless otherwise specifically -stated inside of the file. - - --------------------------------------------------------------------------- - Copyright (c) 2016 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. - --------------------------------------------------------------------------- - - */ -package main; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Random; - -public class MusicConnector { - - //change this to point to relevant cluster - public String[] musicNodes; - - public MusicConnector(String[] musicNodes){ - this.musicNodes = musicNodes; - } - - private String getMusicNodeIp(){ - Random r = new Random(); - int index = r.nextInt(musicNodes.length); - return musicNodes[index]; - } - - public String getMusicNodeURL(){ - String musicurl = "http://"+getMusicNodeIp()+":8080/MUSIC/rest/v2"; - return musicurl; - } - - public boolean isHostUp(String serverAddress) { - Boolean isUp = false; - try { - InetAddress inet = InetAddress.getByName(serverAddress); - isUp = inet.isReachable(1000); - } catch (UnknownHostException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return isUp; - } - - /* - private static String getMusicNodeIp(){ - - //return "54.224.168.13"; - return bigSiteMusicNode; - String serverAddress; - serverAddress = agaveMusicNode; - while(isHostUp(serverAddress) != true) - serverAddress = toggle(serverAddress); - return serverAddress; - }*/ -} diff --git a/examples/VotingApp/src/main/java/main/Util.java b/examples/VotingApp/src/main/java/main/Util.java deleted file mode 100644 index aefa9a36..00000000 --- a/examples/VotingApp/src/main/java/main/Util.java +++ /dev/null @@ -1,6 +0,0 @@ -package main; - -public class Util { - public static final String version="1.0.0"; - -} diff --git a/examples/VotingApp/src/main/java/main/VotingApp.java b/examples/VotingApp/src/main/java/main/VotingApp.java deleted file mode 100644 index e58c324d..00000000 --- a/examples/VotingApp/src/main/java/main/VotingApp.java +++ /dev/null @@ -1,513 +0,0 @@ -/* - * -This licence applies to all files in this repository unless otherwise specifically -stated inside of the file. - - --------------------------------------------------------------------------- - Copyright (c) 2016 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. - --------------------------------------------------------------------------- - - */ -package main; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import javax.ws.rs.core.MediaType; - -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.api.client.WebResource.Builder; -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 { - String keyspaceName; - ArrayList lockNames; - MusicConnector musicHandle; - private final String version="1.0.0"; - - //UPDATE your onboarding information here - String namespace = "votingapp"; - String userId = "abc123d"; - String password = "password"; - - public VotingApp(String[] musicIps){ - lockNames = new ArrayList(); - musicHandle = new MusicConnector(musicIps); - bootStrap(); - } - - /** - * Adds MUSIC's authentication headers into the webresource - * @param webResource - */ - private Builder addMusicHeaders(WebResource webResource) { - Builder builder = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON); - if (!namespace.equals("")) { - builder.header("ns", namespace); - } - if (!userId.equals("")) { - builder.header("userId", userId); - } - if (!password.equals("")) { - builder.header("password", password); - } - - return builder; - } - - public void createVotingKeyspace(){ - keyspaceName = "VotingAppForMusic"; - System.out.println("Voting app version "+ version+" ....."); - Map replicationInfo = new HashMap(); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - String durabilityOfWrites="false"; - Map consistencyInfo= new HashMap(); - consistencyInfo.put("type", "eventual"); - JsonKeySpace jsonKp = new JsonKeySpace(); - jsonKp.setConsistencyInfo(consistencyInfo); - jsonKp.setDurabilityOfWrites(durabilityOfWrites); - jsonKp.setReplicationInfo(replicationInfo); - - ClientConfig clientConfig = new DefaultClientConfig(); - - clientConfig.getFeatures().put( - JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - - Client client = Client.create(clientConfig); - - WebResource webResource = client - .resource(musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName); - - ClientResponse response = addMusicHeaders(webResource).accept("application/json") - .type("application/json").post(ClientResponse.class, jsonKp); - if (response.getStatus() < 200 || (response.getStatus() > 299 && response.getStatus()!=400)) { //supress keyspace already exists - Map map = response.getEntity(Map.class); - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus() + "- " + map); - } - - } - - public void createVotingTable(){ - Map fields = new HashMap(); - fields.put("name", "text"); - fields.put("count", "varint"); - fields.put("PRIMARY KEY", "(name)"); - - - Map consistencyInfo= new HashMap(); - consistencyInfo.put("type", "eventual"); - - JsonTable jtab = new JsonTable(); - jtab.setFields(fields); - jtab.setConsistencyInfo(consistencyInfo); - - ClientConfig clientConfig = new DefaultClientConfig(); - - clientConfig.getFeatures().put( - JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - - Client client = Client.create(clientConfig); - String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount"; - System.out.println("create url:"+url); - WebResource webResource = client - .resource(url); - - ClientResponse response = addMusicHeaders(webResource).accept("application/json") - .type("application/json").post(ClientResponse.class, jtab); - - System.out.println(response.getEntity(Map.class)); - if (response.getStatus() < 200 || (response.getStatus() > 299 && response.getStatus()!=400)) - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); - - } - private void checkMusicVersion(){ - Client client = Client.create(); - System.out.println(musicHandle.getMusicNodeURL()+"/version"); - - -// System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); - WebResource webResource = client - .resource(musicHandle.getMusicNodeURL()+"/version"); - - - ClientResponse response = addMusicHeaders(webResource) - .accept(MediaType.APPLICATION_JSON).header("Connection", "close").get(ClientResponse.class); - - if (response.getStatus() != 200) { - throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); - } - - String output = response.getEntity(Map.class).toString(); - - System.out.println(output); - - } - - private void createEntryForCandidate(String candidateName){ - Map values = new HashMap(); - values.put("name",candidateName ); - values.put("count",0); - - Map consistencyInfo= new HashMap(); - consistencyInfo.put("type", "eventual"); - - JsonInsert jIns = new JsonInsert(); - jIns.setValues(values); - jIns.setConsistencyInfo(consistencyInfo); - ClientConfig clientConfig = new DefaultClientConfig(); - - clientConfig.getFeatures().put( - JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - - Client client = Client.create(clientConfig); - - String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows"; - WebResource webResource = client - .resource(url); - - ClientResponse response = addMusicHeaders(webResource).accept("application/json") - .type("application/json").post(ClientResponse.class, jIns); - - if (response.getStatus() < 200 || response.getStatus() > 299) - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+"url:"+url+" candidate name:"+ candidateName); - - - } - - private String createLock(String lockName){ - Client client = Client.create(); - String msg = musicHandle.getMusicNodeURL()+"/locks/create/"+lockName; - WebResource webResource = client.resource(msg); - System.out.println(msg); - WebResource.Builder wb = addMusicHeaders(webResource).accept(MediaType.APPLICATION_JSON); - - ClientResponse response = wb.post(ClientResponse.class); - - if (response.getStatus() != 200) { - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+"url:"+msg); - } - - Map responseMap = response.getEntity(Map.class); - - String lockid = ((Map) responseMap.get("lock")).get("lock"); -// System.out.println("Server response .... \n"); -// System.out.println(output); - return lockid; - } - - private boolean acquireLock(String lockId){ - Client client = Client.create(); - String msg = musicHandle.getMusicNodeURL()+"/locks/acquire/"+lockId; - System.out.println(msg); - WebResource webResource = client.resource(msg); - - - WebResource.Builder wb = addMusicHeaders(webResource).accept(MediaType.APPLICATION_JSON); - - ClientResponse response = wb.get(ClientResponse.class); - - Map responseMap = response.getEntity(Map.class); - - if (response.getStatus() != 200) { - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+ ":" + responseMap); - } - - System.out.println(responseMap); - Boolean status = responseMap.get("status").equals("SUCCESS"); - System.out.println("Server response .... " + status); - return status; - } - - private void unlock(String lockId){ - Client client = Client.create(); - WebResource webResource = client.resource(musicHandle.getMusicNodeURL()+"/locks/release/"+lockId); - - ClientResponse response = addMusicHeaders(webResource).delete(ClientResponse.class); - - - if (response.getStatus() < 200 || response.getStatus()>299) { - throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); - } - } - - private void updateVoteCountAtomically(String candidateName,int count){ - /*create lock for the candidate. The music API dictates that - * the lock name must be of the form keyspacename.tableName.primaryKeyName - * */ - System.out.println("trying to acquire lock!"); - - String lockName = keyspaceName+".votecount."+candidateName; - lockNames.add(lockName); - String lockId = createLock(lockName); - while(acquireLock(lockId) != true); - - System.out.println("acquired lock!"); - //update candidate entry if you have the lock - Map values = new HashMap(); - values.put("count",count); - - Map consistencyInfo= new HashMap(); - consistencyInfo.put("type", "critical"); - consistencyInfo.put("lockId", lockId); - - JsonInsert jIns = new JsonInsert(); - jIns.setValues(values); - jIns.setConsistencyInfo(consistencyInfo); - ClientConfig clientConfig = new DefaultClientConfig(); - - clientConfig.getFeatures().put( - JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - - Client client = Client.create(clientConfig); - String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows?name="+candidateName; - System.out.println(url); - WebResource webResource = client - .resource(url); - - ClientResponse response = addMusicHeaders(webResource).accept("application/json") - .type("application/json").put(ClientResponse.class, jIns); - - Map map = response.getEntity(Map.class); - - if (response.getStatus() < 200 || response.getStatus() > 299) - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+":"+map); - - //release lock now that the operation is done - unlock(lockId); - - } - - private void deleteCandidateEntryEventually(String candidateName){ - Map consistencyInfo= new HashMap(); - consistencyInfo.put("type", "eventual"); - - JsonDelete jDel = new JsonDelete(); - jDel.setConsistencyInfo(consistencyInfo); - ClientConfig clientConfig = new DefaultClientConfig(); - - clientConfig.getFeatures().put( - JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - - Client client = Client.create(clientConfig); - String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows?name="+candidateName; - System.out.println(url); - WebResource webResource = client - .resource(url); - - ClientResponse response = addMusicHeaders(webResource).accept("application/json") - .type("application/json").delete(ClientResponse.class, jDel); - - if (response.getStatus() < 200 || response.getStatus() > 299) - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()+"url:"+url); - - } - - public Map readVoteCountForCandidate(String candidateName){ - ClientConfig clientConfig = new DefaultClientConfig(); - - clientConfig.getFeatures().put( - JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - - Client client = Client.create(clientConfig); - String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows?name="+candidateName; - WebResource webResource = client - .resource(url); - - ClientResponse response = addMusicHeaders(webResource).accept("application/json").get(ClientResponse.class); - - if (response.getStatus() < 200 || response.getStatus() > 299) - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); - - Map output = response.getEntity(Map.class); - return output; - } - - public Map readAllVotes(){ - ClientConfig clientConfig = new DefaultClientConfig(); - - clientConfig.getFeatures().put( - JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - - Client client = Client.create(clientConfig); - String url = musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName+"/tables/votecount/rows"; - WebResource webResource = client - .resource(url); - - ClientResponse response = addMusicHeaders(webResource).accept("application/json").get(ClientResponse.class); - - if (response.getStatus() < 200 || response.getStatus() > 299) - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); - - Map output = response.getEntity(Map.class); - return output; - } - - - /* - * Unable to use this because of the error: - * Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: java.net.ProtocolException: - * HTTP method DELETE doesn't support output. Seems to be a error in the rest java combination according to the interwebs - */ - private void dropKeySpace(){ - Map consistencyInfo= new HashMap(); - consistencyInfo.put("type", "eventual"); - - JsonKeySpace jsonKp = new JsonKeySpace(); - jsonKp.setConsistencyInfo(consistencyInfo); - - ClientConfig clientConfig = new DefaultClientConfig(); - - clientConfig.getFeatures().put( - JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - - Client client = Client.create(clientConfig); - - WebResource webResource = client - .resource(musicHandle.getMusicNodeURL()+"/keyspaces/"+keyspaceName); - - ClientResponse response = addMusicHeaders(webResource).type("application/json") - .delete(ClientResponse.class, jsonKp); - - if (response.getStatus() < 200 || response.getStatus() > 299) - throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); - } - - private void deleteLock(String lockName){ - Client client = Client.create(); - WebResource webResource = client.resource(musicHandle.getMusicNodeURL()+"/locks/delete/"+lockName); - - ClientResponse response = addMusicHeaders(webResource).delete(ClientResponse.class); - - - if (response.getStatus() <200 || response.getStatus()>299) { - throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); - } - } - - private void resetMusic(){ - Client client = Client.create(); - WebResource webResource = client.resource(musicHandle.getMusicNodeURL()+"/reset"); - - ClientResponse response = addMusicHeaders(webResource).delete(ClientResponse.class); - - - if (response.getStatus() != 204) { - throw new RuntimeException("Failed : HTTP error code : " - + response.getStatus()); - } - - } - public void deleteAllLocks(){ - for (String lockName : lockNames) { - deleteLock(lockName); - } - } - - - public void bootStrap(){ - checkMusicVersion(); - createVotingKeyspace(); - - - createVotingTable(); - - - //the next few lines just create an entry in the voting table for all these candidates with vote count as 0 - createEntryForCandidate("Popeye"); - - createEntryForCandidate("Judy"); - - createEntryForCandidate("Flash"); - - createEntryForCandidate("Mickey"); - - } - - public void overAllTests(){ - //update the count atomically - updateVoteCountAtomically("Popeye",5); - - updateVoteCountAtomically("Judy",7); - - updateVoteCountAtomically("Mickey",8); - - updateVoteCountAtomically("Flash",2); - - - //read votecount - System.out.println(readAllVotes()); - - System.out.println(readVoteCountForCandidate("Popeye")); - - System.out.println(readVoteCountForCandidate("Flash")); - - deleteCandidateEntryEventually("Mickey"); - - System.out.println(readAllVotes()); - -// dropKeySpace(); - - deleteAllLocks(); - } - - public void flipTest(){ - checkMusicVersion(); - } - - public static String executeBashScript(String pathToScript, String arg1, String arg2){ - try { - ProcessBuilder pb = new ProcessBuilder(pathToScript,arg1, arg2); - final Process process = pb.start(); - InputStream is = process.getInputStream(); - InputStreamReader isr = new InputStreamReader(is); - BufferedReader br = new BufferedReader(isr); - return br.readLine(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - - public static void main(String[] args) { - long start = System.currentTimeMillis(); - - if (args.length==0) { - args = new String[]{"localhost"}; - } - for(int i =0; i < 2;++i){ - VotingApp vHandle = new VotingApp(args); - vHandle.overAllTests(); - - System.out.println("====================================="); - System.out.println("Test no."+i+" completed:"); - } - long diff = System.currentTimeMillis() - start; - System.out.println(diff); - } - - -} \ No newline at end of file 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 @@ org.onap.music MUSIC jar - 2.5.7 + 2.5.3 This is the MUSIC REST interface, packaged as a war file. @@ -81,14 +81,12 @@ MUSIC - src/main/java + ../src/main/java src/main/webapp/WEB-INF/classes - src/test/java - target/test-classes validate - src/main/resources + ../src/main/resources true @@ -114,9 +112,6 @@ 1.7 1.7 - - jar/** - @@ -333,24 +328,6 @@ guava 19.0 - - org.mindrot - jbcrypt - 0.4 - - - - commons-codec - commons-codec - 1.9 - - - - org.apache.commons - commons-lang3 - 3.0 - - 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 getAllPossibleLocalIps() { - ArrayList allPossibleIps = new ArrayList(); - try { - Enumeration en = NetworkInterface.getNetworkInterfaces(); - while (en.hasMoreElements()) { - NetworkInterface ni = (NetworkInterface) en.nextElement(); - Enumeration 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 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 condition) throws Exception { - ColumnDefinitions colInfo = row.getColumnDefinitions(); - - for (Map.Entry 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> marshalData(ResultSet results) { - Map> resultMap = - new HashMap>(); - int counter = 0; - for (Row row : results) { - ColumnDefinitions colInfo = row.getColumnDefinitions(); - HashMap resultOutput = new HashMap(); - 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 values; - private StringBuilder query; - - - - /** - * - */ - public PreparedQueryObject() { - - this.values = new ArrayList<>(); - this.query = new StringBuilder(); - } - - /** - * @return - */ - public List 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 ns = null; - - @ApiModelProperty(value = "Namespace value") - public ArrayList getNs() { - return ns; - } - - public void setNs(ArrayList 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 columns = null; - private Map consistencyInfo; - private Map conditions; - String ttl, timestamp; - - - @ApiModelProperty(value = "Conditions") - public Map getConditions() { - return conditions; - } - - public void setConditions(Map conditions) { - this.conditions = conditions; - } - - @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic") - public Map getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map consistencyInfo) { - this.consistencyInfo = consistencyInfo; - } - - @ApiModelProperty(value = "Column values") - public ArrayList getColumns() { - return columns; - } - - public void setColumns(ArrayList 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 values; - private String ttl; - private String timestamp; - private Map row_specification; - private Map 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 getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map 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 getValues() { - return values; - } - - public void setValues(Map values) { - this.values = values; - } - - @ApiModelProperty(value = "Information for selecting specific rows for insert") - public Map getRow_specification() { - return row_specification; - } - - public void setRow_specification(Map 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 replicationInfo; - private String durabilityOfWrites; - private Map consistencyInfo; - - @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic") - public Map getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map consistencyInfo) { - this.consistencyInfo = consistencyInfo; - } - - @ApiModelProperty(value = "Replication information") - public Map getReplicationInfo() { - return replicationInfo; - } - - public void setReplicationInfo(Map 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 consistencyInfo; - - - public Map getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map 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 fields; - private Map properties; - private String primaryKey; - private String sortingKey; - private String clusteringOrder; - private Map consistencyInfo; - - @ApiModelProperty(value = "Consistency level", allowableValues = "eventual,critical,atomic") - public Map getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map consistencyInfo) { - this.consistencyInfo = consistencyInfo; - } - - @ApiModelProperty(value = "Properties") - public Map getProperties() { - return properties; - } - - public void setProperties(Map properties) { - this.properties = properties; - } - - @ApiModelProperty(value = "Fields") - public Map getFields() { - return fields; - } - - public void setFields(Map 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 values; - private String ttl, timestamp; - private Map consistencyInfo; - private Map conditions; - private Map row_specification; - - @ApiModelProperty(value = "Conditions") - public Map getConditions() { - return conditions; - } - - public void setConditions(Map conditions) { - this.conditions = conditions; - } - - @ApiModelProperty(value = "Information for selecting sepcific rows") - public Map getRow_specification() { - return row_specification; - } - - public void setRow_specification(Map 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 getConsistencyInfo() { - return consistencyInfo; - } - - public void setConsistencyInfo(Map 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 getValues() { - return values; - } - - public void setValues(Map 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 admin; - - public List getAdmin() { - return admin; - } - - public String getName() { - return name; - } - - public void setAdmin(List 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 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 { - @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 = 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 getAcl() { - return acl; - } - - /** - * set the acl - * - * @param acl the acl to set to - */ - public void setAcl(List 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, - 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 { - 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 protocol to implement an exclusive write lock or to elect a leader. - *

- * 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. - *

- * 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 = 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 names; - try { - names = zookeeper.getChildren(id, false); - if (names.isEmpty()) - return ""; - SortedSet sortedNames = new TreeSet(); - 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 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 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 sortedNames = new TreeSet(); - for (String name : names) { - sortedNames.add(new ZNodeName(dir + "/" + name)); - } - if (!sortedNames.contains(idName)) - return Boolean.FALSE; - - SortedSet 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 musicCache = JCS.getInstance("musicCache"); - private static CacheAccess> aafCache = JCS.getInstance("aafCache"); - private static CacheAccess appNameCache = JCS.getInstance("appNameCache"); - private static CacheAccess> musicValidateCache = JCS.getInstance("musicValidateCache"); - private static Map userAttempts = new HashMap<>(); - private static Map 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 it = rs.iterator(); - Map 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 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 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 validateRequest(String nameSpace, String userId, - String password, String keyspace, String aid, String operation) { - Map resultMap = new HashMap<>(); - if (!"createKeySpace".equals(operation)) { - if (nameSpace == null) { - resultMap.put("Exception", "Application namespace is mandatory."); - } - } - return resultMap; - - } - - public static Map verifyOnboarding(String ns, String userId, String password) { - Map 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 authenticateAIDUser(String nameSpace, String userId, String password, - String keyspace) { - Map 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 conditions; - PreparedQueryObject selectQueryForTheRow; - - public Condition(Map 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> 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 autheticateUser(String nameSpace, String userId, - String password, String keyspace, String aid, String operation) - throws Exception { - Map 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 validateLock(String lockName) { - Map 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 allIds = new ArrayList<>(); - private static String publicIp = ""; - private static ArrayList 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 getAllIds() { - return allIds; - } - - /** - * - * @param allIds - */ - public static void setAllIds(List allIds) { - MusicUtil.allIds = (ArrayList) allIds; - } - - /** - * - * @return - */ - public static String getPublicIp() { - return publicIp; - } - - /** - * - * @param publicIp - */ - public static void setPublicIp(String publicIp) { - MusicUtil.publicIp = publicIp; - } - - /** - * - * @return - */ - public static List getAllPublicIps() { - return allPublicIps; - } - - /** - * - * @param allPublicIps - */ - public static void setAllPublicIps(List allPublicIps) { - MusicUtil.allPublicIps = (ArrayList) 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 otMap = (Map) 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) valueObj; - default: - return valueObjString; - } - } - - /** - * - * Utility function to parse json map into sql like string - * - * @param jMap - * @param lineDelimiter - * @return - */ - - public static String jsonMaptoSqlString(Map jMap, String lineDelimiter) throws Exception{ - StringBuilder sqlString = new StringBuilder(); - int counter = 0; - for (Map.Entry 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(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(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 toMap() { - Map 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> 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> getDataResult() { - return this.dataResult; - } - - public JsonResponse setDataResult(Map> 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 toMap() { - Map 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 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 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 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 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 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 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 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 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 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 rowParams = info.getQueryParameters(); - String primaryKey = ""; - for (MultivaluedMap.Entry> entry : rowParams.entrySet()) { - String keyName = entry.getKey(); - List 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 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 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 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 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 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 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 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 fields = tableObj.getFields(); - StringBuilder fieldsString = new StringBuilder("(vector_ts text,"); - int counter = 0; - String primaryKey; - for (Map.Entry 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 propertiesMap = tableObj.getProperties(); - StringBuilder propertiesString = new StringBuilder(); - if (propertiesMap != null) { - counter = 0; - for (Map.Entry entry : propertiesMap.entrySet()) { - Object ot = entry.getValue(); - String value = ot + ""; - if (ot instanceof String) { - value = "'" + value + "'"; - } else if (ot instanceof Map) { - @SuppressWarnings("unchecked") - Map otMap = (Map) 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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> entry : rowParams.entrySet()) { - String keyName = entry.getKey(); - List 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 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 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 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 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 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 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 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 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 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 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 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> 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> 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> simpleTests( - @Context HttpServletResponse response) { - response.addHeader("X-latestVersion",MusicUtil.getVersion()); - Map> testMap = new HashMap<>(); - for(int i=0; i < 3; i++){ - HashMap 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 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - - ${logDirectory}/${generalLogName}.log - - ${logDirectory}/${generalLogName}.%i.log.zip - - 1 - 9 - - - 5MB - - - ${applicationLoggerPattern} - - - - - 256 - true - - - - - - ${logDirectory}/${securityLogName}.log - - ${logDirectory}/${securityLogName}.%i.log.zip - - 1 - 9 - - - 5MB - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n - - - - - 256 - 0 - - - - - - - - - - ${logDirectory}/${auditLogName}.log - - ${logDirectory}/${auditLogName}.%i.log.zip - - 1 - 9 - - - 5MB - - - ${auditLoggerPattern} - - - - 256 - - - - - ${logDirectory}/${metricsLogName}.log - - ${logDirectory}/${metricsLogName}.%i.log.zip - - 1 - 9 - - - 5MB - - - - ${metricsLoggerPattern} - - - - - - 256 - - - - - ${logDirectory}/${errorLogName}.log - - ${logDirectory}/${errorLogName}.%i.log.zip - - 1 - 9 - - - 5MB - - - ${errorLoggerPattern} - - - - - 256 - - - - - ${debugLogDirectory}/${debugLogName}.log - - ${debugLogDirectory}/${debugLogName}.%i.log.zip - - 1 - 9 - - - 5MB - - - ${debugLoggerPattern} - - - - - 256 - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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,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 setPreparedInsertValues1() { - - List 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 setPreparedInsertValues2() { - - List 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 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 setPreparedUpdateValues() { - - List preparedUpdateValues = new ArrayList<>(); - String vectorTs = - String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis()); - Map 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 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 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 values = setPreparedUpdateValues(); - if (!values.isEmpty() || values != null) { - for (Object o : values) { - queryobject.addValue(o); - } - } - return queryobject; - - } - - private static ArrayList getAllPossibleLocalIps() { - ArrayList allPossibleIps = new ArrayList(); - try { - Enumeration en = NetworkInterface.getNetworkInterfaces(); - while (en.hasMoreElements()) { - NetworkInterface ni = (NetworkInterface) en.nextElement(); - Enumeration 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 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 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/MusicDataStoreTest.java b/jar/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java deleted file mode 100644 index 16d2af02..00000000 --- a/jar/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java +++ /dev/null @@ -1,162 +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 org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; -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.PreparedQueryObject; - -import com.datastax.driver.core.DataType; -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.Row; -import com.datastax.driver.core.TableMetadata; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class MusicDataStoreTest { - - static MusicDataStore dataStore; - static PreparedQueryObject testObject; - - @BeforeClass - public static void init() { - dataStore = CassandraCQL.connectToEmbeddedCassandra(); - - } - - @AfterClass - public static void close() throws MusicServiceException, MusicQueryException { - - testObject = new PreparedQueryObject(); - testObject.appendQueryString(CassandraCQL.dropKeyspace); - dataStore.executePut(testObject, "eventual"); - dataStore.close(); - - } - - @Test - public void Test1_SetUp() throws MusicServiceException, MusicQueryException { - boolean result = false; - testObject = new PreparedQueryObject(); - testObject.appendQueryString(CassandraCQL.createKeySpace); - result = dataStore.executePut(testObject, "eventual");; - testObject = new PreparedQueryObject(); - testObject.appendQueryString(CassandraCQL.createTableEmployees); - result = dataStore.executePut(testObject, "eventual"); - assertEquals(true, result); - - } - - @Test - public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException { - testObject = CassandraCQL.setPreparedInsertQueryObject1(); - boolean result = dataStore.executePut(testObject, "eventual"); - assertEquals(true, result); - } - - @Test - public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException { - testObject = CassandraCQL.setPreparedInsertQueryObject2(); - boolean result = dataStore.executePut(testObject, "Critical"); - assertEquals(true, result); - } - - @Test - public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException { - testObject = CassandraCQL.setPreparedUpdateQueryObject(); - boolean result = false; - result = dataStore.executePut(testObject, "eventual"); - assertEquals(true, result); - } - - @Test - public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException { - testObject = new PreparedQueryObject(); - testObject.appendQueryString(CassandraCQL.selectALL); - boolean result = false; - int count = 0; - ResultSet output = null; - output = dataStore.executeEventualGet(testObject); - System.out.println(output); - ; - for (Row row : output) { - count++; - System.out.println(row.toString()); - } - if (count == 2) { - result = true; - } - assertEquals(true, result); - } - - @Test - public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException { - testObject = CassandraCQL.setPreparedGetQuery(); - boolean result = false; - int count = 0; - ResultSet output = null; - output = dataStore.executeCriticalGet(testObject); - System.out.println(output); - ; - for (Row row : output) { - count++; - System.out.println(row.toString()); - } - if (count == 1) { - result = true; - } - assertEquals(true, result); - } - - @Test(expected = NullPointerException.class) - public void Test7_exception() { - PreparedQueryObject queryObject = null; - try { - dataStore.executePut(queryObject, "critical"); - } catch (MusicQueryException | MusicServiceException e) { - System.out.println(e.getMessage()); - } - } - - @Test - public void Test8_columnDataType() { - DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName"); - String datatype = data.toString(); - assertEquals("text",datatype); - } - - @Test - public void Test8_columnMetdaData() { - TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees"); - assertNotNull(data); - } -} 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 ids = new ArrayList(); - 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 ips = new ArrayList(); - 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 myMap = new HashMap(); - 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 myMap = new HashMap(); - myMap.put("name","tom"); - assertEquals(MusicUtil.convertToActualDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),myMap); - - } - - @Test - public void testJsonMaptoSqlString() throws Exception { - Map 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 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 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 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/TestRestMusicData.java b/jar/src/test/java/org/onap/music/unittests/TestRestMusicData.java deleted file mode 100644 index febf6c76..00000000 --- a/jar/src/test/java/org/onap/music/unittests/TestRestMusicData.java +++ /dev/null @@ -1,718 +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.assertTrue; -import java.io.File; -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.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.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -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.lockingservice.MusicLockingService; -import org.onap.music.main.MusicCore; -import org.onap.music.main.MusicUtil; -import org.onap.music.main.ResultType; -import org.onap.music.rest.RestMusicAdminAPI; -import org.onap.music.rest.RestMusicDataAPI; -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.MultivaluedMapImpl; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(MockitoJUnitRunner.class) -public class TestRestMusicData { - - RestMusicDataAPI data = new RestMusicDataAPI(); - RestMusicAdminAPI admin = new RestMusicAdminAPI(); - RestMusicLocksAPI lock = new RestMusicLocksAPI(); - static PreparedQueryObject testObject; - static TestingServer zkServer; - - @Mock - HttpServletResponse http; - - @Mock - UriInfo info; - - static String appName = "TestApp"; - static String userId = "TestUser"; - static String password = "TestPassword"; - static boolean isAAF = false; - static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6"); - static String keyspaceName = "testCassa"; - static String tableName = "employees"; - 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 { - System.out.println("After class"); - 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 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 consistencyInfo = new HashMap<>(); - Map 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, appName, userId, - password, jsonKeyspace, keyspaceName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200,response.getStatus()); - } - - @Test - public void Test2_createKeyspace0() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createKeySpace("1", "1", "1", null, appName, userId, - password, jsonKeyspace, keyspaceName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(400,response.getStatus()); - } -//MusicCore.autheticateUser - @Test - public void Test2_createKeyspace01() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - String appName1 = "test"; - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createKeySpace("1", "1", "1", null, appName1, userId, - password, jsonKeyspace, keyspaceName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(401,response.getStatus()); - } - - @Test - public void Test3_createKeyspace1() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map 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, "TestApp1", - "TestUser1", password, jsonKeyspace, keyspaceName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(400,response.getStatus()); - } - - @Test - public void Test3_createTable() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableName); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, - jsonTable, keyspaceName, tableName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200, response.getStatus()); - } - - // Improper Auth - @Test - public void Test3_createTable1() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableName); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, "wrong", - jsonTable, keyspaceName, tableName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(401, response.getStatus()); - } - - // Improper keyspace - @Test - public void Test3_createTable2() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableName); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, - jsonTable, "wrong", tableName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(401, response.getStatus()); - } - - - - @Test - public void Test4_insertIntoTable() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map 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, userId, password, jsonInsert, keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable2() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test1"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, - jsonInsert, keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - // Auth Error - @Test - public void Test4_insertIntoTable3() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test1"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, "wrong", - jsonInsert, keyspaceName, tableName); - assertEquals(401, response.getStatus()); - } - - // Table wrong - @Test - public void Test4_insertIntoTable4() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test1"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, - jsonInsert, keyspaceName, "wrong"); - assertEquals(400, response.getStatus()); - } - - - - @Test - public void Test5_updateTable() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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, - userId, password, jsonUpdate, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_select() throws Exception { - JsonSelect jsonSelect = new JsonSelect(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap 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, userId, password, keyspaceName, tableName, info); - HashMap> map = (HashMap>) response.getEntity(); - HashMap result = map.get("result"); - assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); - } - - @Test - public void Test6_selectCritical() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap 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, userId, password, jsonInsert, keyspaceName, tableName,info); - HashMap> map = (HashMap>) response.getEntity(); - HashMap result = map.get("result"); - assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); - } - - @Test - public void Test6_deleteFromTable() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "test1"); - consistencyInfo.put("type", "atomic"); - jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, - jsonDelete, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - // Values - @Test - public void Test6_deleteFromTable1() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap 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, userId, password, - jsonDelete, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - // delObj - @Test - public void Test6_deleteFromTable2() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "test1"); - consistencyInfo.put("type", "atomic"); - jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, - null, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test7_dropTable() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map 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, userId, password, - keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test8_deleteKeyspace() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - consistencyInfo.put("type", "eventual"); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - jsonKeyspace.setConsistencyInfo(consistencyInfo); - jsonKeyspace.setDurabilityOfWrites("true"); - jsonKeyspace.setKeyspaceName("TestApp1"); - jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, userId, password, keyspaceName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test8_deleteKeyspace2() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - consistencyInfo.put("type", "eventual"); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - jsonKeyspace.setConsistencyInfo(consistencyInfo); - jsonKeyspace.setDurabilityOfWrites("true"); - jsonKeyspace.setKeyspaceName("TestApp1"); - jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, userId, "wrong", keyspaceName); - assertEquals(401, response.getStatus()); - } - - @Test - public void Test8_deleteKeyspace3() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map 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); - assertEquals(400, response.getStatus()); - } - - - - @Test - public void Test6_onboard() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setAppname("TestApp2"); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setUserId("TestUser2"); - jsonOnboard.setPassword("TestPassword2"); - Map resultMap = (Map) admin.onboardAppWithMusic(jsonOnboard).getEntity(); - resultMap.containsKey("success"); - onboardUUID = resultMap.get("Generated AID").toString(); - assertEquals("Your application TestApp2 has been onboarded with MUSIC.", resultMap.get("Success")); - } - // Missing appname - @Test - public void Test6_onboard1() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setUserId("TestUser2"); - jsonOnboard.setPassword("TestPassword2"); - Map resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) admin.getOnboardedInfoSearch(jsonOnboard).getEntity(); - System.out.println("--->" + resultMap.toString()); - resultMap.containsKey("success"); - assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID)); - - } - - @Test - public void Test8_onboardUpdate() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setUserId("TestUser3"); - jsonOnboard.setPassword("TestPassword3"); - jsonOnboard.setAid(onboardUUID); - Map resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) admin.deleteOnboardApp(jsonOnboard).getEntity(); - assertTrue(resultMap.containsKey("Exception")); - } - - @Test - public void Test3_createLockReference() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.createLockReference(lockName,"1","1", null, appName, userId, password).getEntity(); - @SuppressWarnings("unchecked") - Map resultMap1 = (Map) 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 resultMap = (Map) lock.accquireLock(lockId,"1","1", null, appName, userId, password).getEntity(); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } - - @Test - public void Test5_currentLockHolder() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.currentLockHolder(lockName,"1","1", null, appName, userId, password).getEntity(); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } - - @Test - public void Test7_unLock() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.unLock(lockId,"1","1", null, appName, userId, password).getEntity(); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } - - @Test - public void Test8_delete() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.deleteLock(lockName,"1","1", null, appName, userId, password).getEntity(); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } -} \ No newline at end of file diff --git a/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 nsArray = new ArrayList<>(); - ns.setName("tom"); - ArrayList 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 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 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 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 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 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 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 mapSs = new HashMap<>(); - mapSs.put("k1", "one"); - jk.setConsistencyInfo(mapSs); - assertEquals("one",jk.getConsistencyInfo().get("k1")); - } - - @Test - public void testGetReplicationInfo() { - Map 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 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 mapSs = new HashMap<>(); - mapSs.put("k1", "one"); - jt.setConsistencyInfo(mapSs); - assertEquals("one",jt.getConsistencyInfo().get("k1")); - } - - @Test - public void testGetProperties() { - Map properties = new HashMap<>(); - properties.put("k1", "one"); - jt.setProperties(properties); - } - - @Test - public void testGetFields() { - Map 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 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 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 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 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 @@ - 4.0.0 - org.onap.music - musictrigger - jar - 0.1.0 - - org.onap.oparent - oparent - 1.2.0 - - - - UTF-8 - - https://nexus.onap.org - /content/repositories/snapshots/ - /content/repositories/releases/ - /content/repositories/staging/ - /content/sites/site/org/onap/music/${project.version} - - ${maven.build.timestamp} - yyyy.MM.dd.HH.mm - - ${project.version}-${timestamp} - ${project.version}-latest - - - src - - - maven-compiler-plugin - 3.6.1 - - 1.8 - 1.8 - - - - maven-assembly-plugin - - - - fully.qualified.MainClass - - - - jar-with-dependencies - - - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + MusicTrigger + MusicTrigger + jar + 0.1 + + src + + + maven-compiler-plugin + 3.6.1 + + 1.8 + 1.8 + + + + maven-assembly-plugin + + + + fully.qualified.MainClass + + + + jar-with-dependencies + + + + + - - - com.owlike - genson - 0.99 - - - com.sun.jersey - jersey-client - 1.17 - - - com.datastax.cassandra - cassandra-driver-core - 3.0.0 - - - org.cassandraunit - cassandra-unit - 3.3.0.1 - - - commons-codec - commons-codec - 1.11 - - - - - ecomp-releases - Release Repository - ${nexusproxy}/${releaseNexusPath} - - - ecomp-snapshots - Snapshot Repository - ${nexusproxy}/${snapshotNexusPath} - - - - ecomp-site - dav:${nexusproxy}${sitePath} - - - + + + com.owlike + genson + 0.99 + + + com.sun.jersey + jersey-client + 1.17 + + + com.datastax.cassandra + cassandra-driver-core + 3.0.0 + + + org.cassandraunit + cassandra-unit + 3.3.0.1 + + + commons-codec + commons-codec + 1.11 + + + \ No newline at end of file diff --git a/musictrigger/src/MusicTrigger.java b/musictrigger/src/MusicTrigger.java old mode 100755 new mode 100644 index b5894da1..a27a6c40 --- 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 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 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 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 cells = partition.getRow(clt).cells().iterator(); - Iterator 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 cells = partition.getRow(clt).cells().iterator(); + Iterator 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 @@ - - +--> + 4.0.0 org.onap.music MUSIC war - 3.0.22 + 3.0.2 This is the MUSIC REST interface, packaged as a war file. - - org.onap.oparent - oparent - 1.2.0 - - - UTF-8 1.19 2.25.1 2.0.1 - 3.6.0 + 3.4.0 3.4.11 UTF-8 @@ -185,11 +178,7 @@ provided - + ch.qos.logback @@ -219,6 +208,7 @@ 1.0.1-oss + com.datastax.cassandra @@ -226,6 +216,7 @@ ${cassandra.version} + org.apache.zookeeper @@ -239,6 +230,7 @@ + com.sun.jersey @@ -286,6 +278,7 @@ 3.3.0.2 test + org.apache.curator curator-test @@ -312,7 +305,7 @@ io.netty netty-handler - 4.1.30.Final + 4.0.56.Final com.fasterxml.jackson.core @@ -332,18 +325,13 @@ com.google.guava guava + 19.0 org.mindrot jbcrypt 0.4 - - com.owlike - genson - 1.3 - - @@ -398,30 +386,17 @@ - onap/music/cassandra_3_11 - docker_cassandra_sec + onap/music/cassandra_music + docker_cassandra true - ${docker.tag} - ${docker.latest.tag} + 3.0-${timestamp} + 3.0-latest ${project.basedir}/distribution/cassandra - - - onap/music/cassandra_job - docker_cassandra_job - - true - - ${docker.tag} - ${docker.latest.tag} - - ${project.basedir}/distribution/cassandra_job - - - - - 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 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/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java b/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java new file mode 100644 index 00000000..86774538 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java @@ -0,0 +1,170 @@ +/* + * ============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 org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.mockito.Mock; +import org.onap.music.exceptions.MusicQueryException; +import org.onap.music.exceptions.MusicServiceException; + +import org.onap.music.datastore.CassaDataStore; +import org.onap.music.datastore.CassaLockStore; +import org.onap.music.datastore.PreparedQueryObject; + +import com.datastax.driver.core.DataType; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.TableMetadata; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class MusicLockStoreTest { + + 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"); + dataStore.close(); + + } + + @Test + public void Test1_SetUp() throws MusicServiceException, MusicQueryException { + boolean result = false; + testObject = new PreparedQueryObject(); + testObject.appendQueryString(CassandraCQL.createKeySpace); + result = dataStore.executePut(testObject, "eventual");; + testObject = new PreparedQueryObject(); + testObject.appendQueryString(CassandraCQL.createTableEmployees); + result = dataStore.executePut(testObject, "eventual"); + assertEquals(true, result); + + } + + + @Test + 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); + } + + @Test + public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException { + testObject = CassandraCQL.setPreparedInsertQueryObject2(); + boolean result = dataStore.executePut(testObject, "Critical"); + assertEquals(true, result); + } + + @Test + public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException { + testObject = CassandraCQL.setPreparedUpdateQueryObject(); + boolean result = false; + result = dataStore.executePut(testObject, "eventual"); + assertEquals(true, result); + } + + @Test + public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException { + testObject = new PreparedQueryObject(); + testObject.appendQueryString(CassandraCQL.selectALL); + boolean result = false; + int count = 0; + ResultSet output = null; + output = dataStore.executeEventualGet(testObject); + System.out.println(output); + ; + for (Row row : output) { + count++; + System.out.println(row.toString()); + } + if (count == 2) { + result = true; + } + assertEquals(true, result); + } + + @Test + public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException { + testObject = CassandraCQL.setPreparedGetQuery(); + boolean result = false; + int count = 0; + ResultSet output = null; + output = dataStore.executeCriticalGet(testObject); + System.out.println(output); + ; + for (Row row : output) { + count++; + System.out.println(row.toString()); + } + if (count == 1) { + result = true; + } + assertEquals(true, result); + } + + @Test(expected = NullPointerException.class) + public void Test7_exception() { + PreparedQueryObject queryObject = null; + try { + dataStore.executePut(queryObject, "critical"); + } catch (MusicQueryException | MusicServiceException e) { + System.out.println(e.getMessage()); + } + } + + @Test + public void Test8_columnDataType() { + DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName"); + String datatype = data.toString(); + assertEquals("text",datatype); + } + + @Test + public void Test8_columnMetdaData() { + TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees"); + assertNotNull(data); + } +} 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 replicationInfo = new HashMap(); + 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 replicationInfo = new HashMap(); + 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 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> 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 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 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 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 consistencyInfo = new HashMap<>(); - Map 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 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 consistencyInfo = new HashMap<>(); - Map 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 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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> map = (HashMap>) response.getEntity(); - HashMap result = map.get("result"); - assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); - } - - @Test - public void Test6_select_withException() throws Exception { - JsonSelect jsonSelect = new JsonSelect(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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> map = (HashMap>) response.getEntity(); - HashMap result = map.get("result"); - assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); - } - - @Test - public void Test6_selectCritical_without_lockID() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "test1"); - consistencyInfo.put("type", "atomic"); - jsonDelete.setConsistencyInfo(consistencyInfo); - ArrayList 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 consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map conditions = new HashMap<>(); - conditions.put("emp_name","testName3"); - row.add("emp_name", "test1"); - consistencyInfo.put("type", "atomic"); - jsonDelete.setConsistencyInfo(consistencyInfo); - ArrayList 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 consistencyInfo = new HashMap<>(); - MultivaluedMap 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 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) admin.deleteOnboardApp(jsonOnboard).getEntity(); - assertTrue(resultMap.containsKey("Exception")); - } - - @Test - public void Test3_createLockReference() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity(); - @SuppressWarnings("unchecked") - Map resultMap1 = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 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> 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 consistencyInfo = new HashMap<>(); - Map 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 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 consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("id", "text"); - fields.put("plans", "Map"); - 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 tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - 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 tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - 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 tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - 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 tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - 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 tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - 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 tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - 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/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java new file mode 100644 index 00000000..e9435ee1 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/TestRestMusicData.java @@ -0,0 +1,1172 @@ +/* + * ============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.assertTrue; +import java.io.File; +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.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.datastore.CassaLockStore; +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.main.CachingUtil; +import org.onap.music.main.MusicCore; +import org.onap.music.main.MusicUtil; +import org.onap.music.main.ResultType; +import org.onap.music.rest.RestMusicAdminAPI; +import org.onap.music.rest.RestMusicDataAPI; +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) +@RunWith(MockitoJUnitRunner.class) +public class TestRestMusicData { + + 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 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(); + MusicCore.mLockHandle = new CassaLockStore(MusicCore.mDstoreHandle); + } 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(); + 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 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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()); + } + + // Improper parenthesis in key field + @Test + public void Test3_createTable_badParantesis() throws Exception { + String tableNameC ="testTable0"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 queryParametersMap =new HashMap(); + + queryParametersMap.put("index_name","inxuuid"); + // Mockito.when(info.getQueryParameters()).thenReturn(new MultivaluedMap(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 { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 Test5_updateTable() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map 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 consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map 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 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 consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map 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 consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map 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 consistencyInfo = new HashMap<>(); + MultivaluedMap 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> map = (HashMap>) response.getEntity(); + HashMap result = map.get("result"); + assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); + } + + @Test + public void Test6_selectCritical() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap 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> map = (HashMap>) response.getEntity(); + HashMap result = map.get("result"); + assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); + } + + @Test + public void Test6_deleteFromTable() throws Exception { + JsonDelete jsonDelete = new JsonDelete(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap 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 consistencyInfo = new HashMap<>(); + MultivaluedMap 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 consistencyInfo = new HashMap<>(); + MultivaluedMap 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 Test7_dropTable() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 consistencyInfo = new HashMap<>(); + Map 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 Test8_deleteKeyspace3() throws Exception { + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + authorization, appName, keyspaceName); + assertEquals(400, response.getStatus()); + } + + + + @Test + public void Test6_onboard() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setAppname("TestApp2"); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setUserId("TestUser2"); + jsonOnboard.setPassword("TestPassword2"); + Map resultMap = (Map) admin.onboardAppWithMusic(jsonOnboard).getEntity(); + resultMap.containsKey("success"); + onboardUUID = resultMap.get("Generated AID").toString(); + assertEquals("Your application TestApp2 has been onboarded with MUSIC.", resultMap.get("Success")); + } + // Missing appname + @Test + public void Test6_onboard1() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setUserId("TestUser2"); + jsonOnboard.setPassword("TestPassword2"); + Map resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) admin.getOnboardedInfoSearch(jsonOnboard).getEntity(); + System.out.println("--->" + resultMap.toString()); + resultMap.containsKey("success"); + assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID)); + + } + + @Test + public void Test8_onboardUpdate() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setUserId("TestUser3"); + jsonOnboard.setPassword("TestPassword3"); + jsonOnboard.setAid(onboardUUID); + Map resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) admin.deleteOnboardApp(jsonOnboard).getEntity(); + assertTrue(resultMap.containsKey("Exception")); + } + + @Test + public void Test3_createLockReference() throws Exception { + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Map resultMap = (Map) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity(); + @SuppressWarnings("unchecked") + Map resultMap1 = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 resultMap = (Map) 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 replicationInfo = new HashMap(); + 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 readAllVotes() throws MusicServiceException { + PreparedQueryObject queryObject = new PreparedQueryObject(); + queryObject.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName); + ResultSet rs = MusicCore.get(queryObject); + HashMap voteCount = new HashMap(); + 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 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 list = new ArrayList(); - 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 old mode 100755 new mode 100644 index ecd85846..ecb60096 --- a/version.properties +++ b/version.properties @@ -4,7 +4,7 @@ major=3 minor=0 -patch=22 +patch=2 base_version=${major}.${minor}.${patch} -- cgit 1.2.3-korg