CADI and a few small updates.
[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 org.onap.music.service.impl.MusicCassaCore;
38 import com.datastax.driver.core.ResultSet;
39
40 public class MusicCore {
41
42     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
43     private static boolean unitTestRun = true;
44
45     private static MusicCoreService musicCore = MusicUtil.getMusicCoreService();
46     public static CassaLockStore mLockHandle;
47
48
49     /**
50      * Acquire lock
51      * 
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)
54      * @return
55      * @throws MusicLockingException
56      * @throws MusicQueryException
57      * @throws MusicServiceException
58      */
59     public static ReturnType acquireLock(String fullyQualifiedKey, String lockId)
60             throws MusicLockingException, MusicQueryException, MusicServiceException {
61         return musicCore.acquireLock(fullyQualifiedKey, lockId);
62     }
63
64     public static ReturnType acquireLockWithLease(String key, String lockId, long leasePeriod)
65             throws MusicLockingException, MusicQueryException, MusicServiceException {
66         return musicCore.acquireLockWithLease(key, lockId, leasePeriod);
67     }
68
69     public static String createLockReference(String fullyQualifiedKey) throws MusicLockingException {
70         return musicCore.createLockReference(fullyQualifiedKey);
71     }
72
73     public static String createLockReference(String fullyQualifiedKey, LockType locktype) throws MusicLockingException {
74         return musicCore.createLockReference(fullyQualifiedKey, locktype);
75     }
76
77     public static ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
78             String consistency) throws MusicServiceException {
79         return musicCore.createTable(keyspace, table, tableQueryObject, consistency);
80     }
81
82     public static ResultSet quorumGet(PreparedQueryObject query) {
83         return musicCore.quorumGet(query);
84     }
85
86     /**
87      * Gets the top of queue for fullyQualifiedKey
88      * 
89      * @param fullyQualifiedKey
90      * @return
91      */
92     public static String whoseTurnIsIt(String fullyQualifiedKey) {
93         return musicCore.whoseTurnIsIt(fullyQualifiedKey);
94     }
95
96     /**
97      * Gets the current lockholder(s) for fullyQualifiedKey
98      * 
99      * @param fullyQualifiedKey
100      * @return
101      */
102     public static List<String> getCurrentLockHolders(String fullyQualifiedKey) {
103         return musicCore.getCurrentLockHolders(fullyQualifiedKey);
104     }
105
106     public static void destroyLockRef(String lockId) throws MusicLockingException {
107         musicCore.destroyLockRef(lockId);
108     }
109
110     public static ReturnType eventualPut(PreparedQueryObject queryObject) {
111         return musicCore.eventualPut(queryObject);
112     }
113
114     public static ReturnType eventualPut_nb(PreparedQueryObject queryObject, String keyspace, String tablename,
115             String primaryKey) {
116         return musicCore.eventualPut_nb(queryObject, keyspace, tablename, primaryKey);
117     }
118
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);
122     }
123
124     public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
125             throws MusicServiceException {
126         return musicCore.nonKeyRelatedPut(queryObject, consistency);
127     }
128
129     public static ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException {
130         return musicCore.get(queryObject);
131     }
132
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);
136     }
137
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);
142     }
143
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);
147     }
148
149     public static List<String> getLockQueue(String fullyQualifiedKey)
150             throws MusicServiceException, MusicQueryException, MusicLockingException {
151         return musicCore.getLockQueue(fullyQualifiedKey);
152     }
153
154     public static long getLockQueueSize(String fullyQualifiedKey)
155             throws MusicServiceException, MusicQueryException, MusicLockingException {
156         return musicCore.getLockQueueSize(fullyQualifiedKey);
157     }
158
159     public static void deleteLock(String lockName) throws MusicLockingException {
160         musicCore.deleteLock(lockName);
161     }
162
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);
166     }
167
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);
171     }
172
173     public static Map<String, Object> validateLock(String lockName) {
174         return musicCore.validateLock(lockName);
175     }
176
177     public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) throws MusicLockingException {
178         return musicCore.releaseLock(lockId, voluntaryRelease);
179     }
180
181 }