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;
27 import org.onap.music.datastore.Condition;
28 import org.onap.music.datastore.PreparedQueryObject;
29 import org.onap.music.eelf.logging.EELFLoggerDelegate;
30 import org.onap.music.exceptions.MusicLockingException;
31 import org.onap.music.exceptions.MusicQueryException;
32 import org.onap.music.exceptions.MusicServiceException;
33 import org.onap.music.lockingservice.cassandra.CassaLockStore;
34 import org.onap.music.lockingservice.cassandra.LockType;
35 import org.onap.music.lockingservice.cassandra.MusicLockState;
36 import org.onap.music.service.MusicCoreService;
37 import com.datastax.driver.core.ResultSet;
39 public class MusicCore {
41 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
42 private static MusicCoreService musicCore = MusicUtil.getMusicCoreService();
43 private static CassaLockStore mLockHandle;
45 public static CassaLockStore getmLockHandle() {
49 public static void setmLockHandle(CassaLockStore mLockHandleIn) {
50 mLockHandle = mLockHandleIn;
56 * @param fullyQualifiedKey DO NOT RELY ON THIS KEY WORKING. INCLUDE THE KEY IN THE LOCKID.
57 * @param lockId - the full lock id (key + lockRef)
59 * @throws MusicLockingException
60 * @throws MusicQueryException
61 * @throws MusicServiceException
63 public static ReturnType acquireLock(String fullyQualifiedKey, String lockId)
64 throws MusicLockingException, MusicQueryException, MusicServiceException {
65 return musicCore.acquireLock(fullyQualifiedKey, lockId);
68 public static ReturnType acquireLockWithLease(String key, String lockId, long leasePeriod)
69 throws MusicLockingException, MusicQueryException, MusicServiceException {
70 return musicCore.acquireLockWithLease(key, lockId, leasePeriod);
73 public static String createLockReference(String fullyQualifiedKey) throws MusicLockingException {
74 return musicCore.createLockReference(fullyQualifiedKey);
77 public static String createLockReference(String fullyQualifiedKey, LockType locktype) throws MusicLockingException {
78 return musicCore.createLockReference(fullyQualifiedKey, locktype);
81 public static ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
82 String consistency) throws MusicServiceException {
83 return musicCore.createTable(keyspace, table, tableQueryObject, consistency);
86 public static ResultSet quorumGet(PreparedQueryObject query) {
87 return musicCore.quorumGet(query);
91 * Gets the top of queue for fullyQualifiedKey
93 * @param fullyQualifiedKey
96 public static String whoseTurnIsIt(String fullyQualifiedKey) {
97 return musicCore.whoseTurnIsIt(fullyQualifiedKey);
101 * Gets the current lockholder(s) for fullyQualifiedKey
103 * @param fullyQualifiedKey
106 public static List<String> getCurrentLockHolders(String fullyQualifiedKey) {
107 return musicCore.getCurrentLockHolders(fullyQualifiedKey);
110 public static void destroyLockRef(String lockId) throws MusicLockingException {
111 musicCore.destroyLockRef(lockId);
114 public static ReturnType eventualPut(PreparedQueryObject queryObject) {
115 return musicCore.eventualPut(queryObject);
118 public static ReturnType eventualPut_nb(PreparedQueryObject queryObject, String keyspace, String tablename,
120 return musicCore.eventualPut_nb(queryObject, keyspace, tablename, primaryKey);
123 public static ReturnType criticalPut(String keyspace, String table, String primaryKeyValue,
124 PreparedQueryObject queryObject, String lockReference, Condition conditionInfo) {
125 return musicCore.criticalPut(keyspace, table, primaryKeyValue, queryObject, lockReference, conditionInfo);
128 public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
129 throws MusicServiceException,MusicQueryException {
130 return musicCore.nonKeyRelatedPut(queryObject, consistency);
133 public static ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException {
134 return musicCore.get(queryObject);
137 public static ResultSet criticalGet(String keyspace, String table, String primaryKeyValue,
138 PreparedQueryObject queryObject, String lockReference) throws MusicServiceException {
139 return musicCore.criticalGet(keyspace, table, primaryKeyValue, queryObject, lockReference);
142 public static ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
143 PreparedQueryObject queryObject, Condition conditionInfo)
144 throws MusicLockingException, MusicQueryException, MusicServiceException {
145 return musicCore.atomicPut(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
148 public static ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
149 PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException {
150 return musicCore.atomicGet(keyspaceName, tableName, primaryKey, queryObject);
153 public static List<String> getLockQueue(String fullyQualifiedKey)
154 throws MusicServiceException, MusicQueryException, MusicLockingException {
155 return musicCore.getLockQueue(fullyQualifiedKey);
158 public static long getLockQueueSize(String fullyQualifiedKey)
159 throws MusicServiceException, MusicQueryException, MusicLockingException {
160 return musicCore.getLockQueueSize(fullyQualifiedKey);
163 public static void deleteLock(String lockName) throws MusicLockingException {
164 musicCore.deleteLock(lockName);
167 public static ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
168 PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
169 return musicCore.atomicPutWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
172 public static ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
173 PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
174 return musicCore.atomicGetWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject);
177 public static Map<String, Object> validateLock(String lockName) {
178 return musicCore.validateLock(lockName);
181 public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) throws MusicLockingException {
182 return musicCore.releaseLock(lockId, voluntaryRelease);