1f1d6a163c4ef022f6ce4b08fd1b5a2bde00b242
[music.git] / src / main / java / org / onap / music / main / MusicCore.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22
23 package org.onap.music.main;
24
25 import java.util.List;
26 import java.util.Map;
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;
38
39 public class MusicCore {
40
41     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
42     private static MusicCoreService musicCore = MusicUtil.getMusicCoreService();
43     private static CassaLockStore mLockHandle;
44     
45     public static CassaLockStore getmLockHandle() {
46         return mLockHandle;
47     }
48
49     public static void setmLockHandle(CassaLockStore mLockHandleIn) {
50         mLockHandle = mLockHandleIn;
51     }
52
53     /**
54      * Acquire lock
55      * 
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)
58      * @return
59      * @throws MusicLockingException
60      * @throws MusicQueryException
61      * @throws MusicServiceException
62      */
63     public static ReturnType acquireLock(String fullyQualifiedKey, String lockId)
64             throws MusicLockingException, MusicQueryException, MusicServiceException {
65         return musicCore.acquireLock(fullyQualifiedKey, lockId);
66     }
67
68     public static ReturnType acquireLockWithLease(String key, String lockId, long leasePeriod)
69             throws MusicLockingException, MusicQueryException, MusicServiceException {
70         return musicCore.acquireLockWithLease(key, lockId, leasePeriod);
71     }
72
73     public static String createLockReference(String fullyQualifiedKey) throws MusicLockingException {
74         return musicCore.createLockReference(fullyQualifiedKey);
75     }
76
77     public static String createLockReference(String fullyQualifiedKey, LockType locktype) throws MusicLockingException {
78         return musicCore.createLockReference(fullyQualifiedKey, locktype);
79     }
80
81     public static ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
82             String consistency) throws MusicServiceException {
83         return musicCore.createTable(keyspace, table, tableQueryObject, consistency);
84     }
85
86     public static ResultSet quorumGet(PreparedQueryObject query) {
87         return musicCore.quorumGet(query);
88     }
89
90     /**
91      * Gets the top of queue for fullyQualifiedKey
92      * 
93      * @param fullyQualifiedKey
94      * @return
95      */
96     public static String whoseTurnIsIt(String fullyQualifiedKey) {
97         return musicCore.whoseTurnIsIt(fullyQualifiedKey);
98     }
99
100     /**
101      * Gets the current lockholder(s) for fullyQualifiedKey
102      * 
103      * @param fullyQualifiedKey
104      * @return
105      */
106     public static List<String> getCurrentLockHolders(String fullyQualifiedKey) {
107         return musicCore.getCurrentLockHolders(fullyQualifiedKey);
108     }
109
110     public static void destroyLockRef(String lockId) throws MusicLockingException {
111         musicCore.destroyLockRef(lockId);
112     }
113
114     public static ReturnType eventualPut(PreparedQueryObject queryObject) {
115         return musicCore.eventualPut(queryObject);
116     }
117
118     public static ReturnType eventualPut_nb(PreparedQueryObject queryObject, String keyspace, String tablename,
119             String primaryKey) {
120         return musicCore.eventualPut_nb(queryObject, keyspace, tablename, primaryKey);
121     }
122
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);
126     }
127
128     public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
129             throws MusicServiceException,MusicQueryException {
130         return musicCore.nonKeyRelatedPut(queryObject, consistency);
131     }
132
133     public static ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException {
134         return musicCore.get(queryObject);
135     }
136
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);
140     }
141
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);
146     }
147
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);
151     }
152
153     public static List<String> getLockQueue(String fullyQualifiedKey)
154             throws MusicServiceException, MusicQueryException, MusicLockingException {
155         return musicCore.getLockQueue(fullyQualifiedKey);
156     }
157
158     public static long getLockQueueSize(String fullyQualifiedKey)
159             throws MusicServiceException, MusicQueryException, MusicLockingException {
160         return musicCore.getLockQueueSize(fullyQualifiedKey);
161     }
162
163     public static void deleteLock(String lockName) throws MusicLockingException {
164         musicCore.deleteLock(lockName);
165     }
166
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);
170     }
171
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);
175     }
176
177     public static Map<String, Object> validateLock(String lockName) {
178         return musicCore.validateLock(lockName);
179     }
180
181     public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) throws MusicLockingException {
182         return musicCore.releaseLock(lockId, voluntaryRelease);
183     }
184
185
186
187 }