Include owner in createLockRef
[music.git] / music-core / 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 javax.ws.rs.core.MultivaluedMap;
29
30 import org.onap.music.datastore.Condition;
31 import org.onap.music.datastore.PreparedQueryObject;
32 import org.onap.music.datastore.jsonobjects.JsonDelete;
33 import org.onap.music.datastore.jsonobjects.JsonIndex;
34 import org.onap.music.datastore.jsonobjects.JsonInsert;
35 import org.onap.music.datastore.jsonobjects.JsonKeySpace;
36 import org.onap.music.datastore.jsonobjects.JsonSelect;
37 import org.onap.music.datastore.jsonobjects.JsonTable;
38 import org.onap.music.datastore.jsonobjects.JsonUpdate;
39 import org.onap.music.exceptions.MusicLockingException;
40 import org.onap.music.exceptions.MusicQueryException;
41 import org.onap.music.exceptions.MusicServiceException;
42 import org.onap.music.lockingservice.cassandra.LockType;
43 import org.onap.music.lockingservice.cassandra.MusicLockState;
44 import org.onap.music.main.ResultType;
45 import org.onap.music.main.ReturnType;
46
47 import com.datastax.driver.core.ResultSet;
48
49 public interface MusicCoreService {
50
51     
52     // Core Music Database Methods
53     
54
55     public ReturnType eventualPut(PreparedQueryObject queryObject);
56     
57     public  ReturnType eventualPut_nb(PreparedQueryObject queryObject,String keyspace,String tablename,String primaryKey);
58
59     public ReturnType criticalPut(String keyspaceName, String tableName, String primaryKey,
60         PreparedQueryObject queryObject, String lockId, Condition conditionInfo);
61
62     public ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency)
63         throws MusicServiceException,MusicQueryException;
64
65     public ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException;
66
67     public ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
68         PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException;
69
70     public ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
71         PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException;
72     
73     public  ResultSet atomicGetWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
74         PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException;
75
76     public ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
77         PreparedQueryObject queryObject, Condition conditionInfo)
78         throws MusicLockingException, MusicQueryException, MusicServiceException;
79
80     public ResultSet criticalGet(String keyspaceName, String tableName, String primaryKey,
81         PreparedQueryObject queryObject, String lockId) throws MusicServiceException;
82
83     // Core Music Locking Service Methods
84
85     /**
86      * Create a lock ref in the music lock store.
87      * Default is write as this is the safest semantically
88      * 
89      * @param fullyQualifiedKey the key to create a lock on
90      * @see {@link #creatLockReference(String, LockType)}
91      */
92     public String createLockReference(String fullyQualifiedKey) throws MusicLockingException; // lock name
93
94     /**
95      * Create a lock ref in the music lock store
96      * @param fullyQualifiedKey the key to create a lock on
97      * @param owner the owner of the lock, for deadlock prevention
98      */
99     public String createLockReference(String fullyQualifiedKey, String owner) throws MusicLockingException;
100     
101     /**
102      * Create a lock ref in the music lock store
103      * @param fullyQualifiedKey the key to create a lock on
104      * @param locktype the type of lock create, see {@link LockType}
105      */
106     public String createLockReference(String fullyQualifiedKey, LockType locktype) throws MusicLockingException;
107     
108     /**
109      * Create a lock ref in the music lock store
110      * @param fullyQualifiedKey the key to create a lock on
111      * @param locktype the type of lock create, see {@link LockType}
112      * @param owner the owner of the lock, for deadlock prevention
113      */
114     public String createLockReference(String fullyQualifiedKey, LockType locktype, String owner) throws MusicLockingException;
115
116     public ReturnType acquireLockWithLease(String key, String lockReference, long leasePeriod)
117         throws MusicLockingException, MusicQueryException, MusicServiceException; // key,lock id,time
118
119     public ReturnType acquireLock(String key, String lockReference)
120         throws MusicLockingException, MusicQueryException, MusicServiceException; // key,lock id
121
122     public ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
123         String consistency) throws MusicServiceException;
124
125     public ResultSet quorumGet(PreparedQueryObject query);
126
127     /**
128      * Gets top of queue for fullyQualifiedKey
129      * @param fullyQualifiedKey
130      * @return
131      */
132     public String whoseTurnIsIt(String fullyQualifiedKey);// lock name
133     
134     /**
135      * Gets the current lockholder(s) for lockName
136      * @param lockName
137      * @return
138      */
139     public List<String> getCurrentLockHolders(String fullyQualifiedKey);
140
141     public void destroyLockRef(String lockId) throws MusicLockingException;
142     
143     public void deleteLock(String lockName) throws MusicLockingException;
144     
145     public ReturnType promoteLock(String lockIdToPromote) throws MusicLockingException;
146     
147     public List<String> getLockQueue(String fullyQualifiedKey)
148         throws MusicServiceException, MusicQueryException, MusicLockingException;
149     
150     public long getLockQueueSize(String fullyQualifiedKey)
151         throws MusicServiceException, MusicQueryException, MusicLockingException;
152
153     public Map<String, Object> validateLock(String lockName);
154
155     public MusicLockState releaseLock(String lockId, boolean voluntaryRelease) throws MusicLockingException;
156
157         public List<String> releaseAllLocksForOwner(String ownerId, String keyspace, String table) throws MusicLockingException, MusicServiceException, MusicQueryException;
158
159     
160     //Methods added for orm
161     
162
163     public ResultType createTable(JsonTable jsonTableObject, String consistencyInfo) throws MusicServiceException,MusicQueryException;
164     
165     public ResultType dropTable(JsonTable jsonTableObject, String consistencyInfo) 
166             throws MusicServiceException,MusicQueryException;
167     
168     public ResultType createKeyspace(JsonKeySpace jsonKeySpaceObject,String consistencyInfo) throws MusicServiceException,MusicQueryException;
169     
170     public ResultType dropKeyspace(JsonKeySpace jsonKeySpaceObject, String consistencyInfo) 
171             throws MusicServiceException,MusicQueryException;
172     
173     public ResultType createIndex(JsonIndex jsonIndexObject, String consistencyInfo) throws MusicServiceException,MusicQueryException;
174     
175     public ResultSet select(JsonSelect jsonSelect, MultivaluedMap<String, String> rowParams) throws MusicServiceException, MusicQueryException;
176     
177     public ResultSet selectCritical(JsonInsert jsonInsertObj, MultivaluedMap<String, String> rowParams) 
178             throws MusicLockingException, MusicQueryException, MusicServiceException;
179     
180     public ReturnType insertIntoTable(JsonInsert jsonInsert) throws MusicLockingException, MusicQueryException, MusicServiceException;
181     
182     public ReturnType updateTable(JsonUpdate jsonUpdateObj,MultivaluedMap<String, String> rowParams) 
183             throws MusicLockingException, MusicQueryException, MusicServiceException;
184     
185     public ReturnType deleteFromTable(JsonDelete jsonDeleteObj,MultivaluedMap<String, String> rowParams) 
186             throws MusicLockingException, MusicQueryException, MusicServiceException;
187
188
189 }