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 org.onap.music.service.impl.MusicCassaCore;
38 import com.datastax.driver.core.ResultSet;
40 public class MusicCore {
42 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
43 private static boolean unitTestRun = true;
45 private static MusicCoreService musicCore = MusicUtil.getMusicCoreService();
46 public static CassaLockStore mLockHandle;
52 * @param fullyQualifiedKey DO NOT RELY ON THIS KEY WORKING. INCLUDE THE KEY IN THE LOCKID.
53 * @param lockId - the full lock id (key + lockRef)
55 * @throws MusicLockingException
56 * @throws MusicQueryException
57 * @throws MusicServiceException
59 public static ReturnType acquireLock(String fullyQualifiedKey, String lockId)
60 throws MusicLockingException, MusicQueryException, MusicServiceException {
61 return musicCore.acquireLock(fullyQualifiedKey, lockId);
64 public static ReturnType acquireLockWithLease(String key, String lockId, long leasePeriod)
65 throws MusicLockingException, MusicQueryException, MusicServiceException {
66 return musicCore.acquireLockWithLease(key, lockId, leasePeriod);
69 public static String createLockReference(String fullyQualifiedKey) throws MusicLockingException {
70 return musicCore.createLockReference(fullyQualifiedKey);
73 public static String createLockReference(String fullyQualifiedKey, LockType locktype) throws MusicLockingException {
74 return musicCore.createLockReference(fullyQualifiedKey, locktype);
77 public static ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
78 String consistency) throws MusicServiceException {
79 return musicCore.createTable(keyspace, table, tableQueryObject, consistency);
82 public static ResultSet quorumGet(PreparedQueryObject query) {
83 return musicCore.quorumGet(query);
87 * Gets the top of queue for fullyQualifiedKey
89 * @param fullyQualifiedKey
92 public static String whoseTurnIsIt(String fullyQualifiedKey) {
93 return musicCore.whoseTurnIsIt(fullyQualifiedKey);
97 * Gets the current lockholder(s) for fullyQualifiedKey
99 * @param fullyQualifiedKey
102 public static List<String> getCurrentLockHolders(String fullyQualifiedKey) {
103 return musicCore.getCurrentLockHolders(fullyQualifiedKey);
106 public static void destroyLockRef(String lockId) throws MusicLockingException {
107 musicCore.destroyLockRef(lockId);
110 public static ReturnType eventualPut(PreparedQueryObject queryObject) {
111 return musicCore.eventualPut(queryObject);
114 public static ReturnType eventualPut_nb(PreparedQueryObject queryObject, String keyspace, String tablename,
116 return musicCore.eventualPut_nb(queryObject, keyspace, tablename, primaryKey);
119 public static ReturnType criticalPut(String keyspace, String table, String primaryKeyValue,
120 PreparedQueryObject queryObject, String lockReference, Condition conditionInfo) {
121 return musicCore.criticalPut(keyspace, table, primaryKeyValue, queryObject, lockReference, conditionInfo);
124 public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
125 throws MusicServiceException {
126 return musicCore.nonKeyRelatedPut(queryObject, consistency);
129 public static ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException {
130 return musicCore.get(queryObject);
133 public static ResultSet criticalGet(String keyspace, String table, String primaryKeyValue,
134 PreparedQueryObject queryObject, String lockReference) throws MusicServiceException {
135 return musicCore.criticalGet(keyspace, table, primaryKeyValue, queryObject, lockReference);
138 public static ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
139 PreparedQueryObject queryObject, Condition conditionInfo)
140 throws MusicLockingException, MusicQueryException, MusicServiceException {
141 return musicCore.atomicPut(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
144 public static ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
145 PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException {
146 return musicCore.atomicGet(keyspaceName, tableName, primaryKey, queryObject);
149 public static List<String> getLockQueue(String fullyQualifiedKey)
150 throws MusicServiceException, MusicQueryException, MusicLockingException {
151 return musicCore.getLockQueue(fullyQualifiedKey);
154 public static long getLockQueueSize(String fullyQualifiedKey)
155 throws MusicServiceException, MusicQueryException, MusicLockingException {
156 return musicCore.getLockQueueSize(fullyQualifiedKey);
159 public static void deleteLock(String lockName) throws MusicLockingException {
160 musicCore.deleteLock(lockName);
163 public static ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
164 PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
165 return musicCore.atomicPutWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
168 public static ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
169 PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
170 return musicCore.atomicGetWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject);
173 public static Map<String, Object> validateLock(String lockName) {
174 return musicCore.validateLock(lockName);
177 public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) throws MusicLockingException {
178 return musicCore.releaseLock(lockId, voluntaryRelease);