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 org.onap.music.datastore.Condition;
29 import org.onap.music.datastore.PreparedQueryObject;
30 import org.onap.music.eelf.logging.EELFLoggerDelegate;
31 import org.onap.music.exceptions.MusicLockingException;
32 import org.onap.music.exceptions.MusicQueryException;
33 import org.onap.music.exceptions.MusicServiceException;
34 import org.onap.music.lockingservice.cassandra.CassaLockStore;
35 import org.onap.music.lockingservice.cassandra.MusicLockState;
36 import org.onap.music.service.MusicCoreService;
37 import org.onap.music.service.impl.MusicCassaCore;
39 import com.datastax.driver.core.ResultSet;
41 public class MusicCore {
43 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
44 private static boolean unitTestRun=true;
46 private static MusicCoreService musicCore = MusicUtil.getMusicCoreService();
47 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) {
70 return musicCore.createLockReference(fullyQualifiedKey);
73 public static ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
74 String consistency) throws MusicServiceException {
75 return musicCore.createTable(keyspace, table, tableQueryObject, consistency);
78 public static ResultSet quorumGet(PreparedQueryObject query) {
79 return musicCore.quorumGet(query);
82 public static String whoseTurnIsIt(String fullyQualifiedKey) {
83 return musicCore.whoseTurnIsIt(fullyQualifiedKey);
86 public static void destroyLockRef(String lockId) {
87 musicCore.destroyLockRef(lockId);
90 public static ReturnType eventualPut(PreparedQueryObject queryObject) {
91 return musicCore.eventualPut(queryObject);
94 public static ReturnType eventualPut_nb(PreparedQueryObject queryObject,String keyspace,
95 String tablename,String primaryKey) {
96 return musicCore.eventualPut_nb(queryObject, keyspace, tablename, primaryKey);
99 public static ReturnType criticalPut(String keyspace, String table, String primaryKeyValue,
100 PreparedQueryObject queryObject, String lockReference, Condition conditionInfo) {
101 return musicCore.criticalPut(keyspace, table, primaryKeyValue, queryObject, lockReference, conditionInfo);
104 public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
105 throws MusicServiceException {
106 return musicCore.nonKeyRelatedPut(queryObject, consistency);
109 public static ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException{
110 return musicCore.get(queryObject);
113 public static ResultSet criticalGet(String keyspace, String table, String primaryKeyValue,
114 PreparedQueryObject queryObject, String lockReference) throws MusicServiceException {
115 return musicCore.criticalGet(keyspace, table, primaryKeyValue, queryObject,lockReference);
118 public static ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
119 PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException,
120 MusicQueryException,MusicServiceException {
121 return musicCore.atomicPut(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
124 public static ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
125 PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException {
126 return musicCore.atomicGet(keyspaceName, tableName, primaryKey, queryObject);
129 public static List<String> getLockQueue(String fullyQualifiedKey)
130 throws MusicServiceException, MusicQueryException, MusicLockingException {
131 return musicCore.getLockQueue(fullyQualifiedKey);
134 public static long getLockQueueSize(String fullyQualifiedKey)
135 throws MusicServiceException, MusicQueryException, MusicLockingException {
136 return musicCore.getLockQueueSize(fullyQualifiedKey);
139 public static void deleteLock(String lockName) throws MusicLockingException {
140 musicCore.deleteLock(lockName);
143 public static ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName,
144 String primaryKey, PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException {
145 return musicCore.atomicPutWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject, conditionInfo);
148 public static ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
149 PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException {
150 return musicCore.atomicGetWithDeleteLock(keyspaceName, tableName, primaryKey, queryObject);
153 public static Map<String, Object> validateLock(String lockName) {
154 return musicCore.validateLock(lockName);
157 public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) {
158 return musicCore.releaseLock(lockId, voluntaryRelease);