1ecb2ee108385d4fd411dacf969027e943e2cded
[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 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 locktype the type of lock create, see {@link LockType}
98      */
99     public String createLockReference(String fullyQualifiedKey, LockType locktype) 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      * @param owner the owner of the lock, for deadlock prevention
106      */
107     public String createLockReference(String fullyQualifiedKey, LockType locktype, String owner) throws MusicLockingException;
108
109     public ReturnType acquireLockWithLease(String key, String lockReference, long leasePeriod)
110         throws MusicLockingException, MusicQueryException, MusicServiceException; // key,lock id,time
111
112     public ReturnType acquireLock(String key, String lockReference)
113         throws MusicLockingException, MusicQueryException, MusicServiceException; // key,lock id
114
115     public ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
116         String consistency) throws MusicServiceException;
117
118     public ResultSet quorumGet(PreparedQueryObject query);
119
120     /**
121      * Gets top of queue for fullyQualifiedKey
122      * @param fullyQualifiedKey
123      * @return
124      */
125     public String whoseTurnIsIt(String fullyQualifiedKey);// lock name
126     
127     /**
128      * Gets the current lockholder(s) for lockName
129      * @param lockName
130      * @return
131      */
132     public List<String> getCurrentLockHolders(String fullyQualifiedKey);
133
134     public void destroyLockRef(String lockId) throws MusicLockingException;
135     
136     //public MusicLockState destroyLockRef(String fullyQualifiedKey, String lockReference); // lock name, lock id
137
138     //public MusicLockState voluntaryReleaseLock(String fullyQualifiedKey, String lockReference)
139     //        throws MusicLockingException;// lock name,lock id
140
141     public void deleteLock(String lockName) throws MusicLockingException;
142     
143     //public MusicLockState  forciblyReleaseLock(String fullyQualifiedKey, String lockReference) throws MusicLockingException, MusicServiceException, MusicQueryException;
144
145     public List<String> getLockQueue(String fullyQualifiedKey)
146         throws MusicServiceException, MusicQueryException, MusicLockingException;
147     
148     public long getLockQueueSize(String fullyQualifiedKey)
149         throws MusicServiceException, MusicQueryException, MusicLockingException;
150
151     public Map<String, Object> validateLock(String lockName);
152
153     public MusicLockState releaseLock(String lockId, boolean voluntaryRelease) throws MusicLockingException;
154
155         public List<String> releaseAllLocksForOwner(String ownerId, String keyspace, String table) throws MusicLockingException, MusicServiceException, MusicQueryException;
156
157     
158     //Methods added for orm
159     
160
161     public ResultType createTable(JsonTable jsonTableObject, String consistencyInfo) throws MusicServiceException,MusicQueryException;
162     
163     public ResultType dropTable(JsonTable jsonTableObject, String consistencyInfo) 
164             throws MusicServiceException,MusicQueryException;
165     
166     public ResultType createKeyspace(JsonKeySpace jsonKeySpaceObject,String consistencyInfo) throws MusicServiceException,MusicQueryException;
167     
168     public ResultType dropKeyspace(JsonKeySpace jsonKeySpaceObject, String consistencyInfo) 
169             throws MusicServiceException,MusicQueryException;
170     
171     public ResultType createIndex(JsonIndex jsonIndexObject, String consistencyInfo) throws MusicServiceException,MusicQueryException;
172     
173     public ResultSet select(JsonSelect jsonSelect, MultivaluedMap<String, String> rowParams) throws MusicServiceException, MusicQueryException;
174     
175     public ResultSet selectCritical(JsonInsert jsonInsertObj, MultivaluedMap<String, String> rowParams) 
176             throws MusicLockingException, MusicQueryException, MusicServiceException;
177     
178     public ReturnType insertIntoTable(JsonInsert jsonInsert) throws MusicLockingException, MusicQueryException, MusicServiceException;
179     
180     public ReturnType updateTable(JsonUpdate jsonUpdateObj,MultivaluedMap<String, String> rowParams) 
181             throws MusicLockingException, MusicQueryException, MusicServiceException;
182     
183     public ReturnType deleteFromTable(JsonDelete jsonDeleteObj,MultivaluedMap<String, String> rowParams) 
184             throws MusicLockingException, MusicQueryException, MusicServiceException;
185
186 }