943f4ca81e3fad32eef316602245ee9a95df130e
[music.git] / src / main / java / org / onap / music / rest / RestMusicLocksAPI.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.rest;
24
25 import java.util.Map;
26
27 import javax.ws.rs.Consumes;
28 import javax.ws.rs.DELETE;
29 import javax.ws.rs.GET;
30 import javax.ws.rs.HeaderParam;
31 import javax.ws.rs.POST;
32 import javax.ws.rs.Path;
33 import javax.ws.rs.PathParam;
34 import javax.ws.rs.Produces;
35 import javax.ws.rs.core.MediaType;
36 import javax.ws.rs.core.Response;
37 import javax.ws.rs.core.Response.ResponseBuilder;
38 import javax.ws.rs.core.Response.Status;
39
40 import org.onap.music.authentication.MusicAAFAuthentication;
41 import org.onap.music.authentication.MusicAuthenticator;
42 import org.onap.music.authentication.MusicAuthenticator.Operation;
43 import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
44 import org.onap.music.eelf.logging.EELFLoggerDelegate;
45 import org.onap.music.eelf.logging.format.AppMessages;
46 import org.onap.music.eelf.logging.format.ErrorSeverity;
47 import org.onap.music.eelf.logging.format.ErrorTypes;
48 import org.onap.music.lockingservice.cassandra.MusicLockState;
49 import org.onap.music.main.MusicCore;
50 import org.onap.music.main.MusicUtil;
51 import org.onap.music.main.ResultType;
52 import org.onap.music.main.ReturnType;
53 import org.onap.music.response.jsonobjects.JsonResponse;
54
55 import io.swagger.annotations.Api;
56 import io.swagger.annotations.ApiOperation;
57 import io.swagger.annotations.ApiParam;
58
59
60 @Path("/v2/locks/")
61 @Api(value="Lock Api")
62 public class RestMusicLocksAPI {
63
64     private EELFLoggerDelegate logger =EELFLoggerDelegate.getLogger(RestMusicLocksAPI.class);
65     private static final String XMINORVERSION = "X-minorVersion";
66     private static final String XPATCHVERSION = "X-patchVersion";
67     private static final String VERSION = "v2";
68     
69     private MusicAuthenticator authenticator = new MusicAAFAuthentication();
70
71     /**
72      * Puts the requesting process in the q for this lock. The corresponding
73      * node will be created if it did not already exist
74      * 
75      * @param lockName
76      * @return
77      * @throws Exception 
78      */
79     @POST
80     @Path("/create/{lockname}")
81     @ApiOperation(value = "Create Lock",
82         notes = "Puts the requesting process in the q for this lock." +
83         " The corresponding lock will be created if it did not already exist." +
84         " Lock Name is the \"key\" of the form keyspaceName.tableName.rowId",
85         response = Map.class)
86     @Produces(MediaType.APPLICATION_JSON)    
87     public Response createLockReference(
88             @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
89             @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
90             @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
91             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
92             @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
93             @ApiParam(value = "Application namespace",
94                             required = true) @HeaderParam("ns") String ns) throws Exception{
95         try {
96         ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
97         Map<String, Object> resultMap = MusicCore.validateLock(lockName);
98         if (resultMap.containsKey("Error")) {
99             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
100             response.status(Status.BAD_REQUEST);
101             return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(resultMap.get("Error"))).toMap()).build();
102         }
103         String keyspaceName = (String) resultMap.get("keyspace");
104         EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspaceName+" ) ");
105         
106         if (!authenticator.authenticateUser(ns, authorization, keyspaceName, aid, Operation.CREATE_LOCKREF)) {
107             return response.status(Status.UNAUTHORIZED)
108                     .entity(new JsonResponse(ResultType.FAILURE)
109                             .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
110                             .toMap()).build();
111         }
112         
113         ResultType status = ResultType.SUCCESS;
114         String lockId = MusicCore.createLockReference(lockName);
115         
116         if (lockId == null) { 
117             status = ResultType.FAILURE; 
118             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.LOCKINGERROR  ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
119             return response.status(Status.BAD_REQUEST).entity(new JsonResponse(status).setError("Lock Id is null").toMap()).build();
120         }
121         return response.status(Status.OK).entity(new JsonResponse(status).setLock(lockId).toMap()).build();
122         } finally {
123             EELFLoggerDelegate.mdcRemove("keyspace");
124         }
125     }
126
127     /**
128      * 
129      * Checks if the node is in the top of the queue and hence acquires the lock
130      * 
131      * @param lockId
132      * @return
133      * @throws Exception 
134      */
135     @GET
136     @Path("/acquire/{lockreference}")
137     @ApiOperation(value = "Aquire Lock", 
138         notes = "Checks if the node is in the top of the queue and hence acquires the lock",
139         response = Map.class)
140     @Produces(MediaType.APPLICATION_JSON)    
141     public Response accquireLock(
142             @ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId,
143             @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
144             @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
145             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
146             @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
147             @ApiParam(value = "Application namespace",
148                             required = true) @HeaderParam("ns") String ns) throws Exception{
149         try { 
150         ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
151         Map<String, Object> resultMap = MusicCore.validateLock(lockId);
152         if (resultMap.containsKey("Error")) {
153             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
154             response.status(Status.BAD_REQUEST);
155             return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(resultMap.get("Error"))).toMap()).build();
156         }
157         
158         String keyspaceName = (String) resultMap.get("keyspace");
159         EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspaceName+" ) ");
160         
161         if (!authenticator.authenticateUser(ns, authorization, keyspaceName, aid, Operation.ACQUIRE_LOCK)) {
162             return response.status(Status.UNAUTHORIZED)
163                     .entity(new JsonResponse(ResultType.FAILURE)
164                             .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
165                             .toMap()).build();
166         }
167         
168         try {
169             String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
170             ReturnType lockStatus = MusicCore.acquireLock(lockName,lockId);
171             if ( lockStatus.getResult().equals(ResultType.SUCCESS)) {
172                 response.status(Status.OK);
173             } else {
174                 response.status(Status.BAD_REQUEST);
175             }
176             return response.entity(new JsonResponse(lockStatus.getResult()).setLock(lockId).setMessage(lockStatus.getMessage()).toMap()).build();
177         } catch (Exception e) {
178             logger.error(EELFLoggerDelegate.errorLogger,AppMessages.INVALIDLOCK + lockId, ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
179             return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Unable to aquire lock").toMap()).build();
180         }
181         } finally {
182             EELFLoggerDelegate.mdcRemove("keyspace");
183         }
184     }
185     
186
187
188     
189     @POST
190     @Path("/acquire-with-lease/{lockreference}")
191     @ApiOperation(value = "Aquire Lock with Lease", response = Map.class)
192     @Consumes(MediaType.APPLICATION_JSON)
193     @Produces(MediaType.APPLICATION_JSON)    
194     public Response accquireLockWithLease(JsonLeasedLock lockObj, 
195             @ApiParam(value="Lock Reference",required=true) @PathParam("lockreference") String lockId,
196             @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
197             @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
198             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
199             @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
200             @ApiParam(value = "Application namespace",
201                             required = true) @HeaderParam("ns") String ns) throws Exception{
202         try {
203         ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
204         Map<String, Object> resultMap = MusicCore.validateLock(lockId);
205         if (resultMap.containsKey("Error")) {
206             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
207             response.status(Status.BAD_REQUEST);
208             return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(resultMap.get("Error"))).toMap()).build();
209         }
210         String keyspaceName = (String) resultMap.get("keyspace");
211         EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspaceName+" ) ");
212         resultMap.remove("keyspace");
213         if (!authenticator.authenticateUser(ns, authorization, keyspaceName, aid, Operation.ACQUIRE_LOCK)) {
214             return response.status(Status.UNAUTHORIZED)
215                     .entity(new JsonResponse(ResultType.FAILURE)
216                             .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
217                             .toMap()).build();
218         }
219         
220         String lockName = lockId.substring(lockId.indexOf('$')+1, lockId.lastIndexOf('$'));
221         ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, lockObj.getLeasePeriod());
222         if ( lockLeaseStatus.getResult().equals(ResultType.SUCCESS)) {
223             response.status(Status.OK);
224         } else {
225             response.status(Status.BAD_REQUEST);
226         }
227         return response.entity(new JsonResponse(lockLeaseStatus.getResult()).setLock(lockName)
228                                     .setMessage(lockLeaseStatus.getMessage())
229                                     .setLockLease(String.valueOf(lockObj.getLeasePeriod())).toMap()).build();
230         } finally {
231             EELFLoggerDelegate.mdcRemove("keyspace");
232         }
233     } 
234     
235
236     @GET
237     @Path("/enquire/{lockname}")
238     @ApiOperation(value = "Get Lock Holder", 
239         notes = "Gets the current Lock Holder",
240         response = Map.class)
241     @Produces(MediaType.APPLICATION_JSON)    
242     public Response currentLockHolder(
243             @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
244             @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
245             @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
246             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
247             @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
248             @ApiParam(value = "Application namespace",
249                             required = true) @HeaderParam("ns") String ns) throws Exception{
250         try {
251         ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
252         Map<String, Object> resultMap = MusicCore.validateLock(lockName);
253         if (resultMap.containsKey("Error")) {
254             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
255             response.status(Status.BAD_REQUEST);
256             return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(resultMap.get("Error"))).toMap()).build();
257         }
258
259         String keyspaceName = (String) resultMap.get("keyspace");
260         EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspaceName+" ) ");
261         resultMap.remove("keyspace");
262         if (!authenticator.authenticateUser(ns, authorization, keyspaceName, aid, Operation.CURRENT_LOCK)) {
263             return response.status(Status.UNAUTHORIZED)
264                     .entity(new JsonResponse(ResultType.FAILURE)
265                             .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
266                             .toMap()).build();
267         }
268         
269         String who = MusicCore.whoseTurnIsIt(lockName);
270         ResultType status = ResultType.SUCCESS;
271         String error = "";
272         if ( who == null ) { 
273             status = ResultType.FAILURE; 
274             error = "There was a problem getting the lock holder";
275             logger.error(EELFLoggerDelegate.errorLogger,"There was a problem getting the lock holder", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
276             return response.status(Status.BAD_REQUEST).entity(new JsonResponse(status).setError(error).setLock(lockName).setLockHolder(who).toMap()).build();
277         }
278         return response.status(Status.OK).entity(new JsonResponse(status).setError(error).setLock(lockName).setLockHolder(who).toMap()).build();
279         } finally {
280             EELFLoggerDelegate.mdcRemove("keyspace");
281         }
282     }
283
284     @GET
285     @Path("/{lockname}")
286     @ApiOperation(value = "Lock State",
287         notes = "Returns current Lock State and Holder.",
288         response = Map.class)
289     @Produces(MediaType.APPLICATION_JSON)    
290     public Response currentLockState(
291             @ApiParam(value="Lock Name",required=true) @PathParam("lockname") String lockName,
292             @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
293             @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
294             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
295             @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
296             @ApiParam(value = "Application namespace",
297                             required = true) @HeaderParam("ns") String ns) throws Exception{
298         try {
299         ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
300         Map<String, Object> resultMap = MusicCore.validateLock(lockName);
301         if (resultMap.containsKey("Error")) {
302             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
303             response.status(Status.BAD_REQUEST);
304             return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(resultMap.get("Error"))).toMap()).build();
305         }
306         String keyspaceName = (String) resultMap.get("keyspace");
307         EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspaceName+" ) ");
308         resultMap.remove("keyspace");
309         if (!authenticator.authenticateUser(ns, authorization, keyspaceName, aid, Operation.CURRENT_LOCK)) {
310             return response.status(Status.UNAUTHORIZED)
311                     .entity(new JsonResponse(ResultType.FAILURE)
312                             .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
313                             .toMap()).build();
314         }
315         
316         String who = MusicCore.whoseTurnIsIt(lockName);
317         ResultType status = ResultType.SUCCESS;
318         String error = "";
319         if ( who == null ) { 
320             status = ResultType.FAILURE; 
321             error = "There was a problem getting the lock holder";
322             logger.error(EELFLoggerDelegate.errorLogger,"There was a problem getting the lock holder", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
323             return response.status(Status.BAD_REQUEST).entity(new JsonResponse(status).setError(error).setLock(lockName).setLockHolder(who).toMap()).build();
324         }
325         return response.status(Status.OK).entity(new JsonResponse(status).setError(error).setLock(lockName).setLockHolder(who).toMap()).build();
326         } finally {
327             EELFLoggerDelegate.mdcRemove("keyspace");
328         } 
329         
330         //MusicLockState mls = MusicZKCore.getMusicLockState(lockName);
331 //        Map<String,Object> returnMap = null;
332 //        JsonResponse jsonResponse = new JsonResponse(ResultType.FAILURE).setLock(lockName);
333 //        if(mls == null) {
334 //            jsonResponse.setError("");
335 //            jsonResponse.setMessage("No lock object created yet..");
336 //            logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
337 //            return response.status(Status.BAD_REQUEST).entity(jsonResponse.toMap()).build();
338 //        } else { 
339 //            jsonResponse.setStatus(ResultType.SUCCESS);
340 //            jsonResponse.setLockStatus(mls.getLockStatus());
341 //            jsonResponse.setLockHolder(mls.getLockHolder());
342 //            return response.status(Status.OK).entity(jsonResponse.toMap()).build();
343 //        }
344
345     }
346
347     /**
348      * 
349      * deletes the process from the zk queue
350      * 
351      * @param lockId
352      * @throws Exception 
353      */
354     @DELETE
355     @Path("/release/{lockreference}")
356     @ApiOperation(value = "Release Lock",
357         notes = "deletes the process from the zk queue",
358         response = Map.class)
359     @Produces(MediaType.APPLICATION_JSON)    
360     public Response unLock(@PathParam("lockreference") String lockId,
361             @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
362             @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
363             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
364             @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
365             @ApiParam(value = "Application namespace",
366                             required = true) @HeaderParam("ns") String ns) throws Exception{
367         try {
368         ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
369         Map<String, Object> resultMap = MusicCore.validateLock(lockId);
370         if (resultMap.containsKey("Error")) {
371             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
372             response.status(Status.BAD_REQUEST);
373             return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(resultMap.get("Error"))).toMap()).build();
374         }
375
376         String keyspaceName = (String) resultMap.get("keyspace");
377         EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspaceName+" ) ");
378         resultMap.remove("keyspace");
379         if (!authenticator.authenticateUser(ns, authorization, keyspaceName, aid, Operation.DELETE_LOCK)) {
380             return response.status(Status.UNAUTHORIZED)
381                     .entity(new JsonResponse(ResultType.FAILURE)
382                             .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
383                             .toMap()).build();
384         }
385         
386         boolean voluntaryRelease = true; 
387         MusicLockState mls = MusicCore.releaseLock(lockId,voluntaryRelease);
388         if(mls.getErrorMessage() != null) {
389             resultMap.put(ResultType.EXCEPTION.getResult(), mls.getErrorMessage());
390             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.INCORRECTDATA  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
391             return response.status(Status.BAD_REQUEST).entity(resultMap).build();
392         }
393         Map<String,Object> returnMap = null;
394         if (mls.getLockStatus() == MusicLockState.LockStatus.UNLOCKED) {
395             returnMap = new JsonResponse(ResultType.SUCCESS).setLock(lockId)
396                                 .setLockStatus(mls.getLockStatus()).toMap();
397             response.status(Status.OK);
398         }
399         if (mls.getLockStatus() == MusicLockState.LockStatus.LOCKED) {
400             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.LOCKINGERROR  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
401             returnMap = new JsonResponse(ResultType.FAILURE).setLock(lockId)
402                                 .setLockStatus(mls.getLockStatus()).toMap();
403             response.status(Status.BAD_REQUEST);
404         }
405         return response.entity(returnMap).build();
406         } finally {
407             EELFLoggerDelegate.mdcRemove("keyspace");
408         }
409     }
410
411     /**
412      * 
413      * @param lockName
414      * @throws Exception 
415      */
416     @DELETE
417     @Path("/delete/{lockname}")
418     @ApiOperation(value = "Delete Lock", response = Map.class)
419     @Produces(MediaType.APPLICATION_JSON)    
420     public Response deleteLock(@PathParam("lockname") String lockName,
421             @ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
422             @ApiParam(value = "Patch Version",required = false) @HeaderParam(XPATCHVERSION) String patchVersion,
423             @ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
424             @ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization,
425             @ApiParam(value = "Application namespace",
426                             required = true) @HeaderParam("ns") String ns) throws Exception{
427         try {
428         ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
429         Map<String, Object> resultMap = MusicCore.validateLock(lockName);
430         if (resultMap.containsKey("Error")) {
431             logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR  ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
432             response.status(Status.BAD_REQUEST);
433             return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(resultMap.get("Error"))).toMap()).build();
434         }
435
436         String keyspaceName = (String) resultMap.get("keyspace");
437         EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspaceName+" ) ");
438         resultMap.remove("keyspace");
439         if (!authenticator.authenticateUser(ns, authorization, keyspaceName, aid, Operation.DELETE_LOCK)) {
440             return response.status(Status.UNAUTHORIZED)
441                     .entity(new JsonResponse(ResultType.FAILURE)
442                             .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
443                             .toMap()).build();
444         }
445         
446         try{
447             MusicCore.deleteLock(lockName);
448         }catch (Exception e) {
449             return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
450         }
451         return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).toMap()).build();
452         } finally {
453             EELFLoggerDelegate.mdcRemove("keyspace");
454         }
455     }
456
457 }