Some bug fixes and Minor Chages.
[music.git] / src / main / java / org / onap / music / service / MusicCoreService.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.service;
24
25 import java.util.List;
26 import java.util.Map;
27
28 import org.onap.music.datastore.PreparedQueryObject;
29 import org.onap.music.exceptions.MusicLockingException;
30 import org.onap.music.exceptions.MusicQueryException;
31 import org.onap.music.exceptions.MusicServiceException;
32 import org.onap.music.lockingservice.cassandra.LockType;
33 import org.onap.music.lockingservice.cassandra.MusicLockState;
34 import org.onap.music.main.ResultType;
35 import org.onap.music.main.ReturnType;
36 import org.onap.music.datastore.*;
37
38 import com.datastax.driver.core.ResultSet;
39
40 public interface MusicCoreService {
41
42     
43     // Core Music Database Methods
44     
45
46     public ReturnType eventualPut(PreparedQueryObject queryObject);
47     
48     public  ReturnType eventualPut_nb(PreparedQueryObject queryObject,String keyspace,String tablename,String primaryKey);
49
50     public ReturnType criticalPut(String keyspaceName, String tableName, String primaryKey,
51         PreparedQueryObject queryObject, String lockId, Condition conditionInfo);
52
53     public ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
54         throws MusicServiceException,MusicQueryException;
55
56     public ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException;
57
58     public ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
59         PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException;
60
61     public ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
62         PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException;
63     
64     public  ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
65         PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException;
66
67     public ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
68         PreparedQueryObject queryObject, Condition conditionInfo)
69         throws MusicLockingException, MusicQueryException, MusicServiceException;
70
71     public ResultSet criticalGet(String keyspaceName, String tableName, String primaryKey,
72         PreparedQueryObject queryObject, String lockId) throws MusicServiceException;
73
74     // Core Music Locking Service Methods
75
76     /**
77      * Create a lock ref in the music lock store.
78      * Default is write as this is the safest semantically
79      * 
80      * @param fullyQualifiedKey the key to create a lock on
81      * @see {@link #creatLockReference(String, LockType)}
82      */
83     public String createLockReference(String fullyQualifiedKey) throws MusicLockingException; // lock name
84
85     /**
86      * Create a lock ref in the music lock store
87      * @param fullyQualifiedKey the key to create a lock on
88      * @param locktype the type of lock create, see {@link LockType}
89      */
90     public String createLockReference(String fullyQualifiedKey, LockType locktype) throws MusicLockingException;
91     
92     public ReturnType acquireLockWithLease(String key, String lockReference, long leasePeriod)
93         throws MusicLockingException, MusicQueryException, MusicServiceException; // key,lock id,time
94
95     public ReturnType acquireLock(String key, String lockReference)
96         throws MusicLockingException, MusicQueryException, MusicServiceException; // key,lock id
97
98     public ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
99         String consistency) throws MusicServiceException;
100
101     public ResultSet quorumGet(PreparedQueryObject query);
102
103     /**
104      * Gets top of queue for fullyQualifiedKey
105      * @param fullyQualifiedKey
106      * @return
107      */
108     public String whoseTurnIsIt(String fullyQualifiedKey);// lock name
109     
110     /**
111      * Gets the current lockholder(s) for lockName
112      * @param lockName
113      * @return
114      */
115     public List<String> getCurrentLockHolders(String fullyQualifiedKey);
116
117     public void destroyLockRef(String lockId) throws MusicLockingException;
118     
119     //public MusicLockState destroyLockRef(String fullyQualifiedKey, String lockReference); // lock name, lock id
120
121     //public MusicLockState voluntaryReleaseLock(String fullyQualifiedKey, String lockReference)
122     //        throws MusicLockingException;// lock name,lock id
123
124     public void deleteLock(String lockName) throws MusicLockingException;
125     
126     //public MusicLockState  forciblyReleaseLock(String fullyQualifiedKey, String lockReference) throws MusicLockingException, MusicServiceException, MusicQueryException;
127
128     public List<String> getLockQueue(String fullyQualifiedKey)
129         throws MusicServiceException, MusicQueryException, MusicLockingException;
130     
131     public long getLockQueueSize(String fullyQualifiedKey)
132         throws MusicServiceException, MusicQueryException, MusicLockingException;
133
134     public Map<String, Object> validateLock(String lockName);
135
136     public MusicLockState releaseLock(String lockId, boolean voluntaryRelease) throws MusicLockingException;
137
138 }