Changes Listed below:
[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
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;
38
39 import com.datastax.driver.core.ResultSet;
40
41 public class MusicCore {
42
43     private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCore.class);
44     private static boolean unitTestRun=true;
45     
46     private static MusicCoreService musicCore = MusicUtil.getMusicCoreService();
47     public static CassaLockStore mLockHandle;
48     
49     
50     /**
51      * Acquire lock
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 ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject, 
74         String consistency) throws MusicServiceException {
75         return musicCore.createTable(keyspace, table, tableQueryObject, consistency);
76     }
77     
78     public static ResultSet quorumGet(PreparedQueryObject query) {
79         return musicCore.quorumGet(query);        
80     }
81     
82     public static String whoseTurnIsIt(String fullyQualifiedKey) {
83         return musicCore.whoseTurnIsIt(fullyQualifiedKey);
84     }
85     
86     public static void destroyLockRef(String lockId) throws MusicLockingException {
87         musicCore.destroyLockRef(lockId);
88     }
89     
90     public static ReturnType eventualPut(PreparedQueryObject queryObject) {
91         return musicCore.eventualPut(queryObject);
92     }
93     
94     public  static ReturnType eventualPut_nb(PreparedQueryObject queryObject,String keyspace,
95         String tablename,String primaryKey) {
96         return musicCore.eventualPut_nb(queryObject, keyspace, tablename, primaryKey);
97     }
98     
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);
102     }
103     
104     public static ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency) 
105         throws MusicServiceException {
106         return musicCore.nonKeyRelatedPut(queryObject, consistency);
107     }
108     
109     public static ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException{
110         return musicCore.get(queryObject);
111     }
112     
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);
116     }
117     
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);
122     }
123     
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);
127     }
128     
129     public static List<String> getLockQueue(String fullyQualifiedKey)
130             throws MusicServiceException, MusicQueryException, MusicLockingException {
131         return musicCore.getLockQueue(fullyQualifiedKey);
132     }
133     
134     public static long getLockQueueSize(String fullyQualifiedKey)
135             throws MusicServiceException, MusicQueryException, MusicLockingException {
136         return musicCore.getLockQueueSize(fullyQualifiedKey);
137     }
138
139     public static void deleteLock(String lockName) throws MusicLockingException {
140         musicCore.deleteLock(lockName);
141     }
142     
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);
146     }
147     
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);
151     }
152
153     public static Map<String, Object> validateLock(String lockName) {
154         return musicCore.validateLock(lockName);
155     }
156
157     public static MusicLockState releaseLock(String lockId, boolean voluntaryRelease) throws MusicLockingException {
158         return musicCore.releaseLock(lockId, voluntaryRelease);
159     }
160     
161
162 }