2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
6 * ===================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music.main;
25 import java.util.List;
28 import javax.ws.rs.core.MultivaluedMap;
30 import org.onap.music.datastore.Condition;
31 import org.onap.music.datastore.PreparedQueryObject;
32 import org.onap.music.datastore.jsonobjects.JsonDelete;
33 import org.onap.music.datastore.jsonobjects.JsonIndex;
34 import org.onap.music.datastore.jsonobjects.JsonInsert;
35 import org.onap.music.datastore.jsonobjects.JsonKeySpace;
36 import org.onap.music.datastore.jsonobjects.JsonSelect;
37 import org.onap.music.datastore.jsonobjects.JsonTable;
38 import org.onap.music.datastore.jsonobjects.JsonUpdate;
39 import org.onap.music.eelf.logging.EELFLoggerDelegate;
40 import org.onap.music.exceptions.MusicLockingException;
41 import org.onap.music.exceptions.MusicQueryException;
42 import org.onap.music.exceptions.MusicServiceException;
43 import org.onap.music.lockingservice.cassandra.CassaLockStore;
44 import org.onap.music.lockingservice.cassandra.LockType;
45 import org.onap.music.lockingservice.cassandra.MusicLockState;
46 import org.onap.music.service.MusicCoreService;
48 import com.datastax.driver.core.ResultSet;
50 public class MusicCore {
52 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
53 private static MusicCoreService musicCore = MusicUtil.getMusicCoreService();
54 private static CassaLockStore mLockHandle;
56 public static CassaLockStore getmLockHandle() {
60 public static void setmLockHandle(CassaLockStore mLockHandleIn) {
61 mLockHandle = mLockHandleIn;
67 * @param fullyQualifiedKey DO NOT RELY ON THIS KEY WORKING. INCLUDE THE KEY IN THE LOCKID.
68 * @param lockId - the full lock id (key + lockRef)
70 * @throws MusicLockingException
71 * @throws MusicQueryException
72 * @throws MusicServiceException
74 public static ReturnType acquireLock(String fullyQualifiedKey, String lockId)
75 throws MusicLockingException, MusicQueryException, MusicServiceException {
76 return musicCore.acquireLock(fullyQualifiedKey, lockId);
79 public static ReturnType acquireLockWithLease(String key, String lockId, long leasePeriod)
80 throws MusicLockingException, MusicQueryException, MusicServiceException {
81 return musicCore.acquireLockWithLease(key, lockId, leasePeriod);
84 public static String createLockReferenceAtomic(String fullyQualifiedKey) throws MusicLockingException {
85 return musicCore.createLockReferenceAtomic(fullyQualifiedKey);
88 public static String createLockReference(String fullyQualifiedKey, String owner) throws MusicLockingException {
89 return musicCore.createLockReference(fullyQualifiedKey, owner);
92 public static String createLockReferenceAtomic(String fullyQualifiedKey, LockType locktype) throws MusicLockingException {
93 return musicCore.createLockReferenceAtomic(fullyQualifiedKey, locktype);
96 public static String createLockReference(String fullyQualifiedKey, LockType locktype, String owner) throws MusicLockingException {
97 return musicCore.createLockReference(fullyQualifiedKey, locktype, owner);
100 public static ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
101 String consistency) throws MusicServiceException {
102 return musicCore.createTable(keyspace, table, tableQueryObject, consistency);
105 public static ResultSet quorumGet(PreparedQueryObject query) {
106 return musicCore.quorumGet(query);
110 * Gets the top of queue for fullyQualifiedKey
112 * @param fullyQualifiedKey
115 public static String whoseTurnIsIt(String fullyQualifiedKey) {
116 return musicCore.whoseTurnIsIt(fullyQualifiedKey);
120 * Gets the current lockholder(s) for fullyQualifiedKey
122 * @param fullyQualifiedKey
125 public static List<String> getCurrentLockHolders(String fullyQualifiedKey) {
126 return musicCore.getCurrentLockHolders(fullyQualifiedKey);
129 public static ReturnType promoteLock(String lockIdToPromote) throws MusicLockingException {
130 return musicCore.promoteLock(lockIdToPromote);
133 public static void destroyLockRef(String lockId) throws MusicLockingException {
134 musicCore.destroyLockRef(lockId);
137 public static ReturnType eventualPut(PreparedQueryObject queryObject) {
138 return musicCore.eventualPut(queryObject);
141 public static ReturnType eventualPut_nb(PreparedQueryObject queryObject, String keyspace, String tablename,
143 return musicCore.eventualPut_nb(queryObject, keyspace, tablename, primaryKey);
146 public static ReturnType criticalPut(String keyspace, String table, String primaryKeyValue,
147 PreparedQueryObject queryObject, String lockReference, Condition conditionInfo) {
148 return musicCore.criticalPut(keyspace, table, primaryKeyValue, queryObject, lockReference, conditionInfo);
151 public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
152 throws MusicServiceException,MusicQueryException {
153 return musicCore.nonKeyRelatedPut(queryObject, consistency);
156 public static ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException {
157 return musicCore.get(queryObject);
160 public static ResultSet criticalGet(String keyspace, String table, String primaryKeyValue,
161 PreparedQueryObject queryObject, String lockReference) throws MusicServiceException {
162 return musicCore.criticalGet(keyspace, table, primaryKeyValue, queryObject, lockReference);
165 public static ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
166 PreparedQueryObject queryObject, Condition conditionInfo)
167 throws MusicLockingException, MusicQueryException, MusicServiceException {
168 return musicCore.atomicPut(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
171 public static ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
172 PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException {
173 return musicCore.atomicGet(keyspaceName, tableName, primaryKey, queryObject);
176 public static List<String> getLockQueue(String fullyQualifiedKey)
177 throws MusicServiceException, MusicQueryException, MusicLockingException {
178 return musicCore.getLockQueue(fullyQualifiedKey);
181 public static long getLockQueueSize(String fullyQualifiedKey)
182 throws MusicServiceException, MusicQueryException, MusicLockingException {
183 return musicCore.getLockQueueSize(fullyQualifiedKey);
186 public static void deleteLock(String lockName) throws MusicLockingException {
187 musicCore.deleteLock(lockName);
190 public static ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
191 PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
192 return musicCore.atomicPutWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
195 public static ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
196 PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
197 return musicCore.atomicGetWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject);
200 public static Map<String, Object> validateLock(String lockName) {
201 return musicCore.validateLock(lockName);
204 public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) throws MusicLockingException {
205 return musicCore.releaseLock(lockId, voluntaryRelease);
208 public static List<String> releaseAllLocksForOwner(String ownerId, String keyspace, String table) throws MusicLockingException, MusicServiceException, MusicQueryException {
209 return musicCore.releaseAllLocksForOwner(ownerId, keyspace, table);
212 //Added changes for orm implementation.
214 public static ResultType createKeyspace(JsonKeySpace jsonKeySpaceObject, String consistencyInfo)
215 throws MusicServiceException, MusicQueryException {
216 return musicCore.createKeyspace(jsonKeySpaceObject,consistencyInfo);
219 public static ResultType dropKeyspace(JsonKeySpace josnKeyspaceObject, String consistencyInfo)
220 throws MusicServiceException,MusicQueryException {
221 return musicCore.dropKeyspace(josnKeyspaceObject, consistencyInfo);
224 public static ResultType createTable(JsonTable jsonTableObject,String consistencyInfo)
225 throws MusicServiceException,MusicQueryException {
226 return musicCore.createTable(jsonTableObject, consistencyInfo);
229 public static ResultType dropTable(JsonTable jsonTableObject, String consistencyInfo)
230 throws MusicServiceException, MusicQueryException {
231 return musicCore.dropTable(jsonTableObject, consistencyInfo);
234 public static ResultType createIndex(JsonIndex jsonIndexObject, String consistencyInfo)
235 throws MusicServiceException,MusicQueryException {
236 return musicCore.createIndex(jsonIndexObject, consistencyInfo);
239 public static ResultSet select(JsonSelect jsonSelect, MultivaluedMap<String, String> rowParams)
240 throws MusicServiceException, MusicQueryException{
241 return musicCore.select(jsonSelect, rowParams);
244 public static ResultSet selectCritical(JsonInsert jsonInsertObj, MultivaluedMap<String, String> rowParams)
245 throws MusicLockingException, MusicQueryException, MusicServiceException{
246 return musicCore.selectCritical(jsonInsertObj, rowParams);
250 public static ReturnType insertIntoTable(JsonInsert jsonInsert) throws MusicLockingException, MusicQueryException, MusicServiceException{
251 return musicCore.insertIntoTable(jsonInsert);
254 public static ReturnType updateTable(JsonUpdate jsonUpdateObj,MultivaluedMap<String, String> rowParams)
255 throws MusicLockingException, MusicQueryException, MusicServiceException{
256 return musicCore.updateTable(jsonUpdateObj, rowParams);
259 public static ReturnType deleteFromTable(JsonDelete jsonDeleteObj,MultivaluedMap<String, String> rowParams)
260 throws MusicLockingException, MusicQueryException, MusicServiceException{
261 return musicCore.deleteFromTable(jsonDeleteObj,rowParams);